Skip to content

Conversation

b-deam
Copy link
Member

@b-deam b-deam commented May 9, 2024

Firstly let me caveat this PR with the fact that WRT to Go or TF providers:
image

So please review very carefully. I tried to be comprehensive in my own testing locally by trying to cause conflicting IDs, updating/destroying etc.

I tested this locally using this sample file:

terraform {
  required_providers {
    elasticstack = {
      source = "elastic/elasticstack"
    }
  }
}

provider "elasticstack" {
  elasticsearch {
    username  = "elastic"
    password  = "changeme"
    endpoints = ["https://localhost:9200"]
    insecure  = true
  }
  kibana {
    username  = "elastic"
    password  = "changeme"
    endpoints = ["https://localhost:5601"]
    insecure  = true
  }
}


resource "elasticstack_kibana_slo" "test_one" {
  name        = "My Test SLO 1"
  description = "My SLO description 1"
  // no slo_id set
  kql_custom_indicator {
    index           = "kibana_sample_data_logs"
    good            = "hour_of_day > 3"
    total           = "*"
    timestamp_field = "@timestamp"
  }

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

  tags = ["test-1"]
}

resource "elasticstack_kibana_slo" "test_two" {
  name        = "My Test SLO 2"
  description = "My SLO description 2"
  slo_id          = "my-test-slo-2"
  kql_custom_indicator {
    index           = "kibana_sample_data_log"
    good            = "hour_of_day > 100"
    total           = "*"
    timestamp_field = "@timestamp"
  }

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

  tags = ["test-2"]
}

resource "elasticstack_kibana_slo" "test_two_conflict" {
  name        = "My Test SLO 3"
  description = "My SLO description 3"
  // Conflicting ID results in 500 back from Kibana
  // Doesn't appear to be a way to ensure uniqueness across resources
  // https://github.com/hashicorp/terraform-plugin-sdk/issues/224
  slo_id          = "my-test-slo-2"
  kql_custom_indicator {
    index           = "kibana_sample_data_log"
    good            = "hour_of_day > 1"
    total           = "*"
    timestamp_field = "@timestamp"
  }

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

  tags = ["test-2"]
}

Fixes #621

Relates (I think) to:

@b-deam b-deam added bug Something isn't working help wanted Extra attention is needed Kibana Kibana related APIs go Pull requests that update Go code labels May 9, 2024
@b-deam b-deam requested a review from wandergeek May 9, 2024 03:04
@b-deam b-deam self-assigned this May 9, 2024
Copy link
Member

@tobio tobio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Can you add an entry to CHANGELOG.md for this one.

It might be worthwhile adding an acceptance test explicitly setting the ID?

@b-deam b-deam requested a review from tobio May 9, 2024 05:13
tobio
tobio previously approved these changes May 9, 2024
Copy link
Member

@tobio tobio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Co-authored-by: Toby Brain <tobio85@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working go Pull requests that update Go code help wanted Extra attention is needed Kibana Kibana related APIs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] SLO does not honor the ID field
2 participants