Skip to content

Commit 10eced4

Browse files
authored
feat(observability): add logs and traces retentions days (#1032)
* feat(observability): add logs and traces retentions days * feat(observability): add inputs to acceptance test * feat(observability): add inputs to example * feat(observability): fix docs * feat(observability): fix ModifyPlan checks after review * feat(observability): fix acceptance test max values * feat(observability): fix lint issues * feat(observability): apply suggestion
1 parent e4e2e55 commit 10eced4

File tree

8 files changed

+366
-5
lines changed

8 files changed

+366
-5
lines changed

docs/data-sources/observability_instance.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ data "stackit_observability_instance" "example" {
4242
- `jaeger_traces_url` (String)
4343
- `jaeger_ui_url` (String)
4444
- `logs_push_url` (String) Specifies URL for pushing logs.
45+
- `logs_retention_days` (Number) Specifies for how many days the logs are kept. Default is set to `7`.
4546
- `logs_url` (String) Specifies Logs URL.
4647
- `metrics_push_url` (String) Specifies URL for pushing metrics.
4748
- `metrics_retention_days` (Number) Specifies for how many days the raw metrics are kept. Default is set to `90`.
@@ -54,6 +55,7 @@ data "stackit_observability_instance" "example" {
5455
- `plan_id` (String) The Observability plan ID.
5556
- `plan_name` (String) Specifies the Observability plan. E.g. `Observability-Monitoring-Medium-EU01`.
5657
- `targets_url` (String) Specifies Targets URL.
58+
- `traces_retention_days` (Number) Specifies for how many days the traces are kept. Default is set to `7`.
5759
- `zipkin_spans_url` (String)
5860

5961
<a id="nestedatt--alert_config"></a>

docs/resources/observability_instance.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ Observability instance resource schema. Must have a `region` specified in the pr
1616
resource "stackit_observability_instance" "example" {
1717
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
1818
name = "example-instance"
19-
plan_name = "Observability-Monitoring-Medium-EU01"
19+
plan_name = "Observability-Starter-EU01"
2020
acl = ["1.1.1.1/32", "2.2.2.2/32"]
21+
logs_retention_days = 30
22+
traces_retention_days = 30
2123
metrics_retention_days = 90
2224
metrics_retention_days_5m_downsampling = 90
2325
metrics_retention_days_1h_downsampling = 90
@@ -43,10 +45,12 @@ import {
4345

4446
- `acl` (Set of String) The access control list for this instance. Each entry is an IP address range that is permitted to access, in CIDR notation.
4547
- `alert_config` (Attributes) Alert configuration for the instance. (see [below for nested schema](#nestedatt--alert_config))
48+
- `logs_retention_days` (Number) Specifies for how many days the logs are kept. Default is set to `7`.
4649
- `metrics_retention_days` (Number) Specifies for how many days the raw metrics are kept. Default is set to `90`.
4750
- `metrics_retention_days_1h_downsampling` (Number) Specifies for how many days the 1h downsampled metrics are kept. must be less than the value of the 5m downsampling retention. Default is set to `90`.
4851
- `metrics_retention_days_5m_downsampling` (Number) Specifies for how many days the 5m downsampled metrics are kept. must be less than the value of the general retention. Default is set to `90`.
4952
- `parameters` (Map of String) Additional parameters.
53+
- `traces_retention_days` (Number) Specifies for how many days the traces are kept. Default is set to `7`.
5054

5155
### Read-Only
5256

examples/resources/stackit_observability_instance/resource.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
resource "stackit_observability_instance" "example" {
22
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
33
name = "example-instance"
4-
plan_name = "Observability-Monitoring-Medium-EU01"
4+
plan_name = "Observability-Starter-EU01"
55
acl = ["1.1.1.1/32", "2.2.2.2/32"]
6+
logs_retention_days = 30
7+
traces_retention_days = 30
68
metrics_retention_days = 90
79
metrics_retention_days_5m_downsampling = 90
810
metrics_retention_days_1h_downsampling = 90

stackit/internal/services/observability/instance/datasource.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,14 @@ func (d *instanceDataSource) Schema(_ context.Context, _ datasource.SchemaReques
132132
Computed: true,
133133
Sensitive: true,
134134
},
135+
"traces_retention_days": schema.Int64Attribute{
136+
Description: "Specifies for how many days the traces are kept. Default is set to `7`.",
137+
Computed: true,
138+
},
139+
"logs_retention_days": schema.Int64Attribute{
140+
Description: "Specifies for how many days the logs are kept. Default is set to `7`.",
141+
Computed: true,
142+
},
135143
"metrics_retention_days": schema.Int64Attribute{
136144
Description: "Specifies for how many days the raw metrics are kept. Default is set to `90`.",
137145
Computed: true,
@@ -454,6 +462,44 @@ func (d *instanceDataSource) Read(ctx context.Context, req datasource.ReadReques
454462
if resp.Diagnostics.HasError() {
455463
return
456464
}
465+
466+
// Handle Logs Retentions
467+
logsRetentionResp, err := d.client.GetLogsConfigs(ctx, instanceId, projectId).Execute()
468+
if err != nil {
469+
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading instance", fmt.Sprintf("Calling API to get logs retention: %v", err))
470+
return
471+
}
472+
473+
err = mapLogsRetentionField(logsRetentionResp, &model)
474+
if err != nil {
475+
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading instance", fmt.Sprintf("Processing API response for the logs retention: %v", err))
476+
return
477+
}
478+
479+
diags = setLogsRetentions(ctx, &resp.State, &model)
480+
resp.Diagnostics.Append(diags...)
481+
if resp.Diagnostics.HasError() {
482+
return
483+
}
484+
485+
// Handle Traces Retentions
486+
tracesRetentionResp, err := d.client.GetTracesConfigs(ctx, instanceId, projectId).Execute()
487+
if err != nil {
488+
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading instance", fmt.Sprintf("Calling API to get traces retention: %v", err))
489+
return
490+
}
491+
492+
err = mapTracesRetentionField(tracesRetentionResp, &model)
493+
if err != nil {
494+
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading instance", fmt.Sprintf("Processing API response for the traces retention: %v", err))
495+
return
496+
}
497+
498+
diags = setTracesRetentions(ctx, &resp.State, &model)
499+
resp.Diagnostics.Append(diags...)
500+
if resp.Diagnostics.HasError() {
501+
return
502+
}
457503
}
458504

459505
// There are plans where no alert matchers and receivers are present e.g. like Observability-Metrics-Endpoint-100k-EU01

0 commit comments

Comments
 (0)