From b3a45b1c57e0ab82fc3e58783c07a5b8ee36e212 Mon Sep 17 00:00:00 2001 From: Nick Clark Date: Tue, 15 Aug 2023 11:45:54 +1000 Subject: [PATCH] Add docs for all indicator types --- docs/resources/kibana_slo.md | 192 +++++++++++++++--- .../elasticstack_kibana_slo/resource.tf | 186 ++++++++++++++--- internal/kibana/slo.go | 9 +- templates/resources/kibana_slo.md.tmpl | 2 +- 4 files changed, 331 insertions(+), 58 deletions(-) diff --git a/docs/resources/kibana_slo.md b/docs/resources/kibana_slo.md index 275846780..9f0fe181c 100644 --- a/docs/resources/kibana_slo.md +++ b/docs/resources/kibana_slo.md @@ -8,51 +8,187 @@ description: |- # Resource: elasticstack_kibana_slo -Creates or updates a Kibana SLO. UPDATE WITH LINK HERE +Creates or updates a Kibana SLO. See the [Kibana SLO docs](https://www.elastic.co/guide/en/observability/current/slo.html) and [dev docs](https://github.com/elastic/kibana/blob/main/x-pack/plugins/observability/dev_docs/slo.md) for more information. ## Example Usage ```terraform provider "elasticstack" { - elasticsearch { - username = "elastic" - password = "password" - endpoints = ["http://localhost:9200"] + elasticsearch {} + kibana {} +} + +resource "elasticstack_kibana_slo" "auth_server_latency" { + name = "Auth server latency" + description = "Ensures auth server is responding in time" + + apm_latency_indicator { + environment = "production" + service = "auth" + transaction_type = "request" + transaction_name = "GET /auth" + index = "metrics-apm*" + threshold = 500 + } + + time_window { + duration = "7d" + type = "rolling" } + + budgeting_method = "timeslices" + + objective { + target = 0.95 + timeslice_target = 0.95 + timeslice_window = "5m" + } + + settings { + sync_delay = "5m" + frequency = "5m" + } + } -resource "elasticstack_kibana_slo" "test_slo" { - name = "%s" - description = "my kewl SLO" - indicator { - type = "sli.apm.transactionDuration" - params = { - environment = "production" - service = "my-service" - transactionType = "request" - transactionName = "GET /sup/dawg" - index = "my-index" - threshold = 500 - } +resource "elasticstack_kibana_slo" "auth_server_availability" { + name = "Auth server latency" + description = "Ensures auth server is responding in time" + + apm_availability_indicator { + environment = "production" + service = "my-service" + transaction_type = "request" + transaction_name = "GET /sup/dawg" + index = "metrics-apm*" + } + + time_window { + duration = "7d" + type = "rolling" + } + + budgeting_method = "timeslices" + + objective { + target = 0.95 + timeslice_target = 0.95 + timeslice_window = "5m" + } + + settings { + sync_delay = "5m" + frequency = "5m" + } + +} + +resource "elasticstack_kibana_slo" "custom_kql" { + name = "custom kql" + description = "custom kql" + + kql_custom_indicator { + index = "my-index" + good = "latency < 300" + total = "*" + filter = "labels.groupId: group-0" + timestamp_field = "custom_timestamp" } time_window { - duration = "1w" - isCalendar = true + duration = "7d" + type = "rolling" } - budgetingMethod = "timeslices" + budgeting_method = "timeslices" objective { - target = 0.999 - timesliceTarget = 0.95 - timesliceWindow = "5m" + target = 0.95 + timeslice_target = 0.95 + timeslice_window = "5m" } settings { - syncDelay = "5m" - frequency = "1m" + sync_delay = "5m" + frequency = "5m" + } + +} + +//Available from 8.10.0 +resource "elasticstack_kibana_slo" "custom_histogram" { + name = "custom histogram" + description = "custom histogram" + + histogram_custom_indicator { + index = "my-index" + good { + field = "test" + aggregation = "value_count" + filter = "latency < 300" + } + total { + field = "test" + aggregation = "value_count" + } + filter = "labels.groupId: group-0" + timestamp_field = "custom_timestamp" } + + time_window { + duration = "7d" + type = "rolling" + } + + budgeting_method = "timeslices" + + objective { + target = 0.95 + timeslice_target = 0.95 + timeslice_window = "5m" + } + +} + +//Available from 8.10.0 +resource "elasticstack_kibana_slo" "custom_metric" { + name = "custom kql" + description = "custom kql" + + metric_custom_indicator { + index = "my-index" + good { + metrics { + name = "A" + aggregation = "sum" + field = "processor.processed" + } + equation = "A" + } + + total { + metrics { + name = "A" + aggregation = "sum" + field = "processor.accepted" + } + equation = "A" + } + } + + time_window { + duration = "7d" + type = "rolling" + } + + budgeting_method = "timeslices" + + objective { + target = 0.95 + timeslice_target = 0.95 + timeslice_window = "5m" + } + } ``` @@ -61,11 +197,11 @@ resource "elasticstack_kibana_slo" "test_slo" { ### Required -- `budgeting_method` (String) An occurrences budgeting method uses the number of good and total events during the time window. A timeslices budgeting method uses the number of good slices and total slices during the time window. A slice is an arbitrary time window (smaller than the overall SLO time window) that is either considered good or bad, calculated from the timeslice threshold and the ratio of good over total events that happened during the slice window. A budgeting method is required and must be either occurrences or timeslices. +- `budgeting_method` (String) An `occurrences` budgeting method uses the number of good and total events during the time window. A `timeslices` budgeting method uses the number of good slices and total slices during the time window. A slice is an arbitrary time window (smaller than the overall SLO time window) that is either considered good or bad, calculated from the timeslice threshold and the ratio of good over total events that happened during the slice window. A budgeting method is required and must be either occurrences or timeslices. - `description` (String) A description for the SLO. - `name` (String) The name of the SLO. - `objective` (Block List, Min: 1, Max: 1) The target objective is the value the SLO needs to meet during the time window. If a timeslices budgeting method is used, we also need to define the timesliceTarget which can be different than the overall SLO target. (see [below for nested schema](#nestedblock--objective)) -- `time_window` (Block List, Min: 1, Max: 1) Currently support calendar aligned and rolling time windows. Any duration greater than 1 day can be used: days, weeks, months, quarters, years. Rolling time window requires a duration, e.g. 1w for one week, and isRolling: true. SLOs defined with such time window, will only consider the SLI data from the last duration period as a moving window. Calendar aligned time window requires a duration, limited to 1M for monthly or 1w for weekly, and isCalendar: true. (see [below for nested schema](#nestedblock--time_window)) +- `time_window` (Block List, Min: 1, Max: 1) Currently support `calendarAligned` and `rolling` time windows. Any duration greater than 1 day can be used: days, weeks, months, quarters, years. Rolling time window requires a duration, e.g. `1w` for one week, and type: `rolling`. SLOs defined with such time window, will only consider the SLI data from the last duration period as a moving window. Calendar aligned time window requires a duration, limited to `1M` for monthly or `1w` for weekly, and type: `calendarAligned`. (see [below for nested schema](#nestedblock--time_window)) ### Optional diff --git a/examples/resources/elasticstack_kibana_slo/resource.tf b/examples/resources/elasticstack_kibana_slo/resource.tf index f50910c5a..28200c08e 100644 --- a/examples/resources/elasticstack_kibana_slo/resource.tf +++ b/examples/resources/elasticstack_kibana_slo/resource.tf @@ -1,41 +1,177 @@ provider "elasticstack" { - elasticsearch { - username = "elastic" - password = "password" - endpoints = ["http://localhost:9200"] + elasticsearch {} + kibana {} +} + +resource "elasticstack_kibana_slo" "auth_server_latency" { + name = "Auth server latency" + description = "Ensures auth server is responding in time" + + apm_latency_indicator { + environment = "production" + service = "auth" + transaction_type = "request" + transaction_name = "GET /auth" + index = "metrics-apm*" + threshold = 500 + } + + time_window { + duration = "7d" + type = "rolling" + } + + budgeting_method = "timeslices" + + objective { + target = 0.95 + timeslice_target = 0.95 + timeslice_window = "5m" + } + + settings { + sync_delay = "5m" + frequency = "5m" } + } -resource "elasticstack_kibana_slo" "test_slo" { - name = "%s" - description = "my kewl SLO" - indicator { - type = "sli.apm.transactionDuration" - params = { - environment = "production" - service = "my-service" - transactionType = "request" - transactionName = "GET /sup/dawg" - index = "my-index" - threshold = 500 - } +resource "elasticstack_kibana_slo" "auth_server_availability" { + name = "Auth server latency" + description = "Ensures auth server is responding in time" + + apm_availability_indicator { + environment = "production" + service = "my-service" + transaction_type = "request" + transaction_name = "GET /sup/dawg" + index = "metrics-apm*" + } + + time_window { + duration = "7d" + type = "rolling" + } + + budgeting_method = "timeslices" + + objective { + target = 0.95 + timeslice_target = 0.95 + timeslice_window = "5m" + } + + settings { + sync_delay = "5m" + frequency = "5m" + } + +} + +resource "elasticstack_kibana_slo" "custom_kql" { + name = "custom kql" + description = "custom kql" + + kql_custom_indicator { + index = "my-index" + good = "latency < 300" + total = "*" + filter = "labels.groupId: group-0" + timestamp_field = "custom_timestamp" } time_window { - duration = "1w" - isCalendar = true + duration = "7d" + type = "rolling" } - budgetingMethod = "timeslices" + budgeting_method = "timeslices" objective { - target = 0.999 - timesliceTarget = 0.95 - timesliceWindow = "5m" + target = 0.95 + timeslice_target = 0.95 + timeslice_window = "5m" } settings { - syncDelay = "5m" - frequency = "1m" + sync_delay = "5m" + frequency = "5m" } + +} + +//Available from 8.10.0 +resource "elasticstack_kibana_slo" "custom_histogram" { + name = "custom histogram" + description = "custom histogram" + + histogram_custom_indicator { + index = "my-index" + good { + field = "test" + aggregation = "value_count" + filter = "latency < 300" + } + total { + field = "test" + aggregation = "value_count" + } + filter = "labels.groupId: group-0" + timestamp_field = "custom_timestamp" + } + + time_window { + duration = "7d" + type = "rolling" + } + + budgeting_method = "timeslices" + + objective { + target = 0.95 + timeslice_target = 0.95 + timeslice_window = "5m" + } + +} + +//Available from 8.10.0 +resource "elasticstack_kibana_slo" "custom_metric" { + name = "custom kql" + description = "custom kql" + + metric_custom_indicator { + index = "my-index" + good { + metrics { + name = "A" + aggregation = "sum" + field = "processor.processed" + } + equation = "A" + } + + total { + metrics { + name = "A" + aggregation = "sum" + field = "processor.accepted" + } + equation = "A" + } + } + + time_window { + duration = "7d" + type = "rolling" + } + + budgeting_method = "timeslices" + + objective { + target = 0.95 + timeslice_target = 0.95 + timeslice_window = "5m" + } + } diff --git a/internal/kibana/slo.go b/internal/kibana/slo.go index 3758c0958..58c6a67cd 100644 --- a/internal/kibana/slo.go +++ b/internal/kibana/slo.go @@ -198,8 +198,9 @@ func ResourceSlo() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "aggregation": { - Type: schema.TypeString, - Required: true, + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{"value_count", "range"}, false), }, "field": { Type: schema.TypeString, @@ -330,7 +331,7 @@ func ResourceSlo() *schema.Resource { }, }, "time_window": { - Description: "Currently support calendar aligned and rolling time windows. Any duration greater than 1 day can be used: days, weeks, months, quarters, years. Rolling time window requires a duration, e.g. 1w for one week, and isRolling: true. SLOs defined with such time window, will only consider the SLI data from the last duration period as a moving window. Calendar aligned time window requires a duration, limited to 1M for monthly or 1w for weekly, and isCalendar: true.", + Description: "Currently support `calendarAligned` and `rolling` time windows. Any duration greater than 1 day can be used: days, weeks, months, quarters, years. Rolling time window requires a duration, e.g. `1w` for one week, and type: `rolling`. SLOs defined with such time window, will only consider the SLI data from the last duration period as a moving window. Calendar aligned time window requires a duration, limited to `1M` for monthly or `1w` for weekly, and type: `calendarAligned`.", Type: schema.TypeList, Required: true, MinItems: 1, @@ -349,7 +350,7 @@ func ResourceSlo() *schema.Resource { }, }, "budgeting_method": { - Description: "An occurrences budgeting method uses the number of good and total events during the time window. A timeslices budgeting method uses the number of good slices and total slices during the time window. A slice is an arbitrary time window (smaller than the overall SLO time window) that is either considered good or bad, calculated from the timeslice threshold and the ratio of good over total events that happened during the slice window. A budgeting method is required and must be either occurrences or timeslices.", + Description: "An `occurrences` budgeting method uses the number of good and total events during the time window. A `timeslices` budgeting method uses the number of good slices and total slices during the time window. A slice is an arbitrary time window (smaller than the overall SLO time window) that is either considered good or bad, calculated from the timeslice threshold and the ratio of good over total events that happened during the slice window. A budgeting method is required and must be either occurrences or timeslices.", Type: schema.TypeString, Required: true, ValidateFunc: validation.StringInSlice([]string{"occurrences", "timeslices"}, false), diff --git a/templates/resources/kibana_slo.md.tmpl b/templates/resources/kibana_slo.md.tmpl index 5f479fa98..c88772104 100644 --- a/templates/resources/kibana_slo.md.tmpl +++ b/templates/resources/kibana_slo.md.tmpl @@ -8,7 +8,7 @@ description: |- # Resource: elasticstack_kibana_slo -Creates or updates a Kibana SLO. UPDATE WITH LINK HERE +Creates or updates a Kibana SLO. See the [Kibana SLO docs](https://www.elastic.co/guide/en/observability/current/slo.html) and [dev docs](https://github.com/elastic/kibana/blob/main/x-pack/plugins/observability/dev_docs/slo.md) for more information. ## Example Usage