Skip to content

Commit 6381497

Browse files
authored
Add support for timeslice metrics indicator (#1195)
* Add support for timeslice metrics indicator * Add support for the resource based on OpenAPI docs. * Add tests * Generate docs * Add type to client Signed-off-by: lloydmeta <[email protected]>
1 parent 77c15d2 commit 6381497

File tree

9 files changed

+817
-0
lines changed

9 files changed

+817
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## [Unreleased]
22

3+
- Add support for `timeslice_metric_indicator` in `elasticstack_kibana_slo` ([#1195](https://github.com/elastic/terraform-provider-elasticstack/pull/1195))
4+
35
## [0.11.16] - 2025-07-09
46

57
- Add `headers` for the provider connection ([#1057](https://github.com/elastic/terraform-provider-elasticstack/pull/1057))

docs/resources/kibana_slo.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,41 @@ resource "elasticstack_kibana_slo" "custom_metric" {
190190
timeslice_window = "5m"
191191
}
192192
193+
}
194+
195+
//Available from 8.12.0
196+
resource "elasticstack_kibana_slo" "timeslice_metric" {
197+
name = "timeslice metric"
198+
description = "timeslice metric"
199+
200+
timeslice_metric_indicator {
201+
index = "my-index"
202+
timestamp_field = "@timestamp"
203+
metric {
204+
metrics {
205+
name = "A"
206+
aggregation = "sum"
207+
field = "latency"
208+
}
209+
equation = "A"
210+
comparator = "GT"
211+
threshold = 100
212+
}
213+
}
214+
215+
time_window {
216+
duration = "7d"
217+
type = "rolling"
218+
}
219+
220+
budgeting_method = "timeslices"
221+
222+
objective {
223+
target = 0.95
224+
timeslice_target = 0.95
225+
timeslice_window = "5m"
226+
}
227+
193228
}
194229
```
195230

@@ -216,6 +251,7 @@ resource "elasticstack_kibana_slo" "custom_metric" {
216251
- `slo_id` (String) An ID (8 and 36 characters). If omitted, a UUIDv1 will be generated server-side.
217252
- `space_id` (String) An identifier for the space. If space_id is not provided, the default space is used.
218253
- `tags` (List of String) The tags for the SLO.
254+
- `timeslice_metric_indicator` (Block List, Max: 1) Defines a timeslice metric indicator for SLO. (see [below for nested schema](#nestedblock--timeslice_metric_indicator))
219255

220256
### Read-Only
221257

@@ -405,6 +441,44 @@ Optional:
405441
- `frequency` (String)
406442
- `sync_delay` (String)
407443

444+
445+
<a id="nestedblock--timeslice_metric_indicator"></a>
446+
### Nested Schema for `timeslice_metric_indicator`
447+
448+
Required:
449+
450+
- `index` (String)
451+
- `metric` (Block List, Min: 1, Max: 1) (see [below for nested schema](#nestedblock--timeslice_metric_indicator--metric))
452+
- `timestamp_field` (String)
453+
454+
Optional:
455+
456+
- `filter` (String)
457+
458+
<a id="nestedblock--timeslice_metric_indicator--metric"></a>
459+
### Nested Schema for `timeslice_metric_indicator.metric`
460+
461+
Required:
462+
463+
- `comparator` (String)
464+
- `equation` (String)
465+
- `metrics` (Block List, Min: 1) (see [below for nested schema](#nestedblock--timeslice_metric_indicator--metric--metrics))
466+
- `threshold` (Number)
467+
468+
<a id="nestedblock--timeslice_metric_indicator--metric--metrics"></a>
469+
### Nested Schema for `timeslice_metric_indicator.metric.metrics`
470+
471+
Required:
472+
473+
- `aggregation` (String) The aggregation type for this metric. One of: sum, avg, min, max, value_count, percentile, doc_count. Determines which other fields are required:
474+
- `name` (String) The unique name for this metric. Used as a variable in the equation field.
475+
476+
Optional:
477+
478+
- `field` (String) Field to aggregate. Required for aggregations: sum, avg, min, max, value_count, percentile. Must NOT be set for doc_count.
479+
- `filter` (String) Optional KQL filter for this metric. Supported for all aggregations except doc_count.
480+
- `percentile` (Number) Percentile value (e.g., 99). Required if aggregation is 'percentile'. Must NOT be set for other aggregations.
481+
408482
## Import
409483

410484
Import is supported using the following syntax:

examples/resources/elasticstack_kibana_slo/resource.tf

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,38 @@ resource "elasticstack_kibana_slo" "custom_metric" {
176176
}
177177

178178
}
179+
180+
//Available from 8.12.0
181+
resource "elasticstack_kibana_slo" "timeslice_metric" {
182+
name = "timeslice metric"
183+
description = "timeslice metric"
184+
185+
timeslice_metric_indicator {
186+
index = "my-index"
187+
timestamp_field = "@timestamp"
188+
metric {
189+
metrics {
190+
name = "A"
191+
aggregation = "sum"
192+
field = "latency"
193+
}
194+
equation = "A"
195+
comparator = "GT"
196+
threshold = 100
197+
}
198+
}
199+
200+
time_window {
201+
duration = "7d"
202+
type = "rolling"
203+
}
204+
205+
budgeting_method = "timeslices"
206+
207+
objective {
208+
target = 0.95
209+
timeslice_target = 0.95
210+
timeslice_window = "5m"
211+
}
212+
213+
}

generated/slo-spec.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,18 @@ components:
969969
description: List of metrics with their name, aggregation type, and field.
970970
type: array
971971
items:
972+
discriminator:
973+
propertyName: aggregation
974+
mapping:
975+
percentile: '#/components/schemas/timeslice_metric_percentile_metric'
976+
doc_count: '#/components/schemas/timeslice_metric_doc_count_metric'
977+
sum: '#/components/schemas/timeslice_metric_basic_metric_with_field'
978+
avg: '#/components/schemas/timeslice_metric_basic_metric_with_field'
979+
min: '#/components/schemas/timeslice_metric_basic_metric_with_field'
980+
max: '#/components/schemas/timeslice_metric_basic_metric_with_field'
981+
std_deviation: '#/components/schemas/timeslice_metric_basic_metric_with_field'
982+
last_value: '#/components/schemas/timeslice_metric_basic_metric_with_field'
983+
cardinality: '#/components/schemas/timeslice_metric_basic_metric_with_field'
972984
anyOf:
973985
- $ref: '#/components/schemas/timeslice_metric_basic_metric_with_field'
974986
- $ref: '#/components/schemas/timeslice_metric_percentile_metric'

generated/slo/api/openapi.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,6 +1705,18 @@ components:
17051705
- $ref: '#/components/schemas/timeslice_metric_basic_metric_with_field'
17061706
- $ref: '#/components/schemas/timeslice_metric_percentile_metric'
17071707
- $ref: '#/components/schemas/timeslice_metric_doc_count_metric'
1708+
discriminator:
1709+
mapping:
1710+
percentile: '#/components/schemas/timeslice_metric_percentile_metric'
1711+
doc_count: '#/components/schemas/timeslice_metric_doc_count_metric'
1712+
sum: '#/components/schemas/timeslice_metric_basic_metric_with_field'
1713+
avg: '#/components/schemas/timeslice_metric_basic_metric_with_field'
1714+
min: '#/components/schemas/timeslice_metric_basic_metric_with_field'
1715+
max: '#/components/schemas/timeslice_metric_basic_metric_with_field'
1716+
std_deviation: '#/components/schemas/timeslice_metric_basic_metric_with_field'
1717+
last_value: '#/components/schemas/timeslice_metric_basic_metric_with_field'
1718+
cardinality: '#/components/schemas/timeslice_metric_basic_metric_with_field'
1719+
propertyName: aggregation
17081720
indicator_properties_timeslice_metric_params_metric:
17091721
description: |
17101722
An object defining the metrics, equation, and threshold to determine if it's a good slice or not

generated/slo/model_indicator_properties_timeslice_metric_params_metric_metrics_inner.go

Lines changed: 199 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/clients/kibana/slo.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ func responseIndicatorToCreateSloRequestIndicator(s slo.SloResponseIndicator) (s
156156
case *slo.IndicatorPropertiesHistogram:
157157
ret.IndicatorPropertiesHistogram = ind
158158

159+
case *slo.IndicatorPropertiesTimesliceMetric:
160+
ret.IndicatorPropertiesTimesliceMetric = ind
161+
159162
default:
160163
return ret, fmt.Errorf("unknown indicator type: %T", ind)
161164
}

0 commit comments

Comments
 (0)