Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SLO support to provider #385

Merged
merged 47 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
05cba56
add generated client and temporary spec file
wandergeek Jul 14, 2023
1a90362
add docs and examples
wandergeek Jul 14, 2023
834d5b8
Add SLO support
wandergeek Jul 14, 2023
b39cb3b
Tweak generator make target
wandergeek Jul 14, 2023
0decee0
appease linters
wandergeek Jul 14, 2023
a19f31c
generate docs
wandergeek Jul 14, 2023
819c84b
remove cursing from source file :'(
wandergeek Jul 14, 2023
2e7a8dc
Update internal/clients/kibana/slo_test.go
wandergeek Jul 14, 2023
143897a
Update to latest spec
wandergeek Aug 7, 2023
022dde8
Create auth context for each generated client
wandergeek Aug 7, 2023
f5e7c06
Fix up error handling in slo kibana client
wandergeek Aug 7, 2023
97ec307
Use budgetingmethod type and add groupby to model
wandergeek Aug 7, 2023
2ff23e6
Fix switch type linting error
wandergeek Aug 7, 2023
9b52da3
Add min/max to appropriate fields in the schema
wandergeek Aug 7, 2023
218bcb2
Use slice literals where possible
wandergeek Aug 7, 2023
2e3a781
Use proper composite ID for resources
wandergeek Aug 7, 2023
3ecf293
Make settings nullable
wandergeek Aug 7, 2023
062ecfb
Add groupby
wandergeek Aug 7, 2023
d436121
Fix up budgetingMethod getter/setter
wandergeek Aug 7, 2023
4935bef
Fix up indicator getter/setter and add new indicator types
wandergeek Aug 7, 2023
e031ee6
Add additional tests for new indicators and optional settings
wandergeek Aug 7, 2023
2c06135
Merge remote-tracking branch 'origin/O11Y-236-add-slo-pr-2' into O11Y…
wandergeek Aug 7, 2023
811c59f
Recreate resources if they don't exist
wandergeek Aug 8, 2023
377a160
Force slo response to have all fields
wandergeek Aug 8, 2023
562a239
Handle computed settings stanza from API
wandergeek Aug 8, 2023
c97c4cf
Make custom indicator types unsupported for now
wandergeek Aug 8, 2023
1410574
Add more tests for computed settings
wandergeek Aug 8, 2023
3722452
regen docs
wandergeek Aug 8, 2023
a0cce18
remove comment
wandergeek Aug 8, 2023
f66bd22
remove another comment
wandergeek Aug 8, 2023
dccb2f4
upgrade stack version to 8.9.0
wandergeek Aug 8, 2023
45030d2
upgrade stack to 8.9.0 and quietly remove any dangling container name…
wandergeek Aug 9, 2023
59e6500
fix copy pasta error in api client auth
wandergeek Aug 9, 2023
827303a
Merge branch 'main' into O11Y-236-add-slo-pr-2
wandergeek Aug 9, 2023
f6fd73c
Use kibana spec from kibana repo rather than static file
wandergeek Aug 11, 2023
c51850f
add success test with proper data
wandergeek Aug 11, 2023
f643ace
use switch instead of if statements for resourceRead
wandergeek Aug 11, 2023
2d4e55b
Use scoped functions for tests
wandergeek Aug 11, 2023
22a3115
Merge remote-tracking branch 'origin/O11Y-236-add-slo-pr-2' into O11Y…
wandergeek Aug 11, 2023
246d471
temporarily hack spec file and regen to work around bug in API
wandergeek Aug 14, 2023
f2d71cf
add new indicator types, split indicators into own objects
wandergeek Aug 14, 2023
39dddf6
generate docs
wandergeek Aug 14, 2023
cf8c760
add some tests for config failures
wandergeek Aug 15, 2023
b3a45b1
Add docs for all indicator types
wandergeek Aug 15, 2023
04d257c
prevent a nil deref when client gets a nil response from an unavailab…
wandergeek Aug 15, 2023
4079d5a
Merge branch 'main' into O11Y-236-add-slo-pr-2
wandergeek Aug 15, 2023
88ff081
Update internal/clients/kibana/slo.go
wandergeek Aug 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ SWAGGER_VERSION ?= 8.7

GOVERSION ?= 1.19

STACK_VERSION ?= 8.6.0
STACK_VERSION ?= 8.9.0

ELASTICSEARCH_NAME ?= terraform-elasticstack-es
ELASTICSEARCH_ENDPOINTS ?= http://$(ELASTICSEARCH_NAME):9200
Expand Down Expand Up @@ -84,6 +84,7 @@ docker-testacc: docker-elasticsearch docker-kibana ## Run acceptance tests in th

.PHONY: docker-elasticsearch
docker-elasticsearch: docker-network ## Start Elasticsearch single node cluster in docker container
@ docker rm -f $(ELASTICSEARCH_NAME) &> /dev/null || true
@ $(call retry, 5, if ! docker ps --format '{{.Names}}' | grep -w $(ELASTICSEARCH_NAME) > /dev/null 2>&1 ; then \
docker run -d \
--memory $(ELASTICSEARCH_MEM) \
Expand All @@ -103,6 +104,7 @@ docker-elasticsearch: docker-network ## Start Elasticsearch single node cluster

.PHONY: docker-kibana
docker-kibana: docker-network docker-elasticsearch set-kibana-password ## Start Kibana node in docker container
@ docker rm -f $(KIBANA_NAME) &> /dev/null || true
@ $(call retry, 5, if ! docker ps --format '{{.Names}}' | grep -w $(KIBANA_NAME) > /dev/null 2>&1 ; then \
docker run -d \
-p 5601:5601 \
Expand Down Expand Up @@ -258,16 +260,18 @@ generate-connectors-client: tools ## generate Kibana connectors client

.PHONY: generate-slo-client
generate-slo-client: tools ## generate Kibana slo client
@ docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate \
-i https://raw.githubusercontent.com/elastic/kibana/master/x-pack/plugins/observability/docs/openapi/slo/bundled.yaml \
--skip-validate-spec \
@ rm -rf generated/slo
@ docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli:v7.0.0-beta generate \
-i /local/generated/slo-spec.yml \
--git-repo-id terraform-provider-elasticstack \
--git-user-id elastic \
-p isGoSubmodule=true \
-p packageName=slo \
-p generateInterfaces=true \
-p useOneOfDiscriminatorLookup=true \
-g go \
-o /local/generated/slo
-o /local/generated/slo \
--type-mappings=float32=float64
@ rm -rf generated/slo/go.mod generated/slo/go.sum generated/slo/test
@ go fmt ./generated/...

Expand Down
143 changes: 143 additions & 0 deletions docs/resources/kibana_slo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
---
subcategory: "Kibana"
layout: ""
page_title: "Elasticstack: elasticstack_kibana_slo Resource"
description: |-
Creates or updates a Kibana SLO.
---

# Resource: elasticstack_kibana_slo

Creates or updates a Kibana SLO. UPDATE WITH LINK HERE

## Example Usage

```terraform
provider "elasticstack" {
elasticsearch {
username = "elastic"
password = "password"
endpoints = ["http://localhost:9200"]
}
}

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
}
}

time_window {
duration = "1w"
isCalendar = true
}

budgetingMethod = "timeslices"

objective {
target = 0.999
timesliceTarget = 0.95
timesliceWindow = "5m"
}

settings {
syncDelay = "5m"
frequency = "1m"
}
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### 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.
- `description` (String) A description for the SLO.
- `indicator` (Block List, Min: 1, Max: 1) (see [below for nested schema](#nestedblock--indicator))
- `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))

### Optional

- `group_by` (String) Optional group by field to use to generate an SLO per distinct value.
- `id` (String) An ID (8 and 36 characters). If omitted, a UUIDv1 will be generated server-side.
- `settings` (Block List, Max: 1) The default settings should be sufficient for most users, but if needed, these properties can be overwritten. (see [below for nested schema](#nestedblock--settings))
- `space_id` (String) An identifier for the space. If space_id is not provided, the default space is used.

<a id="nestedblock--indicator"></a>
### Nested Schema for `indicator`

Required:

- `params` (Block List, Min: 1, Max: 1) (see [below for nested schema](#nestedblock--indicator--params))
- `type` (String)

<a id="nestedblock--indicator--params"></a>
### Nested Schema for `indicator.params`

Required:

- `index` (String)

Optional:

- `environment` (String)
- `filter` (String)
- `good` (String)
- `service` (String)
- `threshold` (Number)
- `timestamp_field` (String)
- `total` (String)
- `transaction_name` (String)
- `transaction_type` (String)



<a id="nestedblock--objective"></a>
### Nested Schema for `objective`

Required:

- `target` (Number)

Optional:

- `timeslice_target` (Number)
- `timeslice_window` (String)


<a id="nestedblock--time_window"></a>
### Nested Schema for `time_window`

Required:

- `duration` (String)
- `type` (String)


<a id="nestedblock--settings"></a>
### Nested Schema for `settings`

Optional:

- `frequency` (String)
- `sync_delay` (String)

## Import

Import is supported using the following syntax:

```shell
terraform import elasticstack_kibana_slo.my_slo <space id>/<slo id>
```
1 change: 1 addition & 0 deletions examples/resources/elasticstack_kibana_slo/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import elasticstack_kibana_slo.my_slo <space id>/<slo id>
41 changes: 41 additions & 0 deletions examples/resources/elasticstack_kibana_slo/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
provider "elasticstack" {
elasticsearch {
username = "elastic"
password = "password"
endpoints = ["http://localhost:9200"]
}
}

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
}
}

time_window {
duration = "1w"
isCalendar = true
}

budgetingMethod = "timeslices"

objective {
target = 0.999
timesliceTarget = 0.95
timesliceWindow = "5m"
}

settings {
syncDelay = "5m"
frequency = "1m"
}
}
Loading