From 35bbf17725443159ad46dd14822075afc36d5062 Mon Sep 17 00:00:00 2001 From: Jason Rhodes Date: Fri, 21 Mar 2025 10:41:53 -0400 Subject: [PATCH 1/4] Add optional preventInitialBackfill for SLO API Docs for this option are here: https://www.elastic.co/docs/api/doc/serverless/operation/operation-createsloop#operation-createsloop-body-application-json-settings-preventinitialbackfill --- internal/kibana/slo.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/kibana/slo.go b/internal/kibana/slo.go index ce8c6bd8c..6b0a12b56 100644 --- a/internal/kibana/slo.go +++ b/internal/kibana/slo.go @@ -457,6 +457,11 @@ func getSchema() map[string]*schema.Schema { Optional: true, Computed: true, }, + "preventInitialBackfill": { + Description: "Prevents the underlying ES transform from attempting to backfill data on start, which can sometimes be resource-intensive or time-consuming and unnecessary", + Type: schema.BoolAttribute, + Optional: true, + } }, }, }, From 0c2442a4f8baf8bf9a095c33f39e19dbdbfa7096 Mon Sep 17 00:00:00 2001 From: Jason Rhodes Date: Fri, 21 Mar 2025 10:48:55 -0400 Subject: [PATCH 2/4] Correct new field to use snake_case --- internal/kibana/slo.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/kibana/slo.go b/internal/kibana/slo.go index 6b0a12b56..e0396421c 100644 --- a/internal/kibana/slo.go +++ b/internal/kibana/slo.go @@ -457,7 +457,7 @@ func getSchema() map[string]*schema.Schema { Optional: true, Computed: true, }, - "preventInitialBackfill": { + "prevent_initial_backfill": { Description: "Prevents the underlying ES transform from attempting to backfill data on start, which can sometimes be resource-intensive or time-consuming and unnecessary", Type: schema.BoolAttribute, Optional: true, From 5a9411ce3ac8f405b9d8f9c937c2704d2493294c Mon Sep 17 00:00:00 2001 From: Jason Rhodes Date: Fri, 21 Mar 2025 11:27:40 -0400 Subject: [PATCH 3/4] Adds further settings management I think the generated settings model found at generated/slo/model_settings.go is still missing a final component here, but that file is generated by OpenAPI so we probably have a change to make in our open API docs, or we need to re-run the generation script there? --- internal/kibana/slo.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/internal/kibana/slo.go b/internal/kibana/slo.go index e0396421c..4e6bb01ff 100644 --- a/internal/kibana/slo.go +++ b/internal/kibana/slo.go @@ -513,6 +513,14 @@ func getOrNilFloat(path string, d *schema.ResourceData) *float64 { return nil } +func getOrNilBool(path string, d *schema.ResourceData) *bool { + if v, ok := d.GetOk(path); ok { + b := v.(bool) + return &b + } + return nil +} + func getSloFromResourceData(d *schema.ResourceData) (models.Slo, diag.Diagnostics) { var diags diag.Diagnostics @@ -655,8 +663,9 @@ func getSloFromResourceData(d *schema.ResourceData) (models.Slo, diag.Diagnostic } settings := slo.Settings{ - SyncDelay: getOrNilString("settings.0.sync_delay", d), - Frequency: getOrNilString("settings.0.frequency", d), + SyncDelay: getOrNilString("settings.0.sync_delay", d), + Frequency: getOrNilString("settings.0.frequency", d), + PreventInitialBackfill: getOrNilBool("settings.0.prevent_initial_backfill", d), } budgetingMethod := slo.BudgetingMethod(d.Get("budgeting_method").(string)) @@ -909,8 +918,9 @@ func resourceSloRead(ctx context.Context, d *schema.ResourceData, meta interface if err := d.Set("settings", []interface{}{ map[string]interface{}{ - "sync_delay": s.Settings.SyncDelay, - "frequency": s.Settings.Frequency, + "sync_delay": s.Settings.SyncDelay, + "frequency": s.Settings.Frequency, + "prevent_initial_backfill": s.Settings.PreventInitialBackfill, }, }); err != nil { return diag.FromErr(err) From b3fc86e30826f00ec461e41a5fd1748c5e720395 Mon Sep 17 00:00:00 2001 From: Jason Rhodes Date: Fri, 21 Mar 2025 11:36:38 -0400 Subject: [PATCH 4/4] Proper gofmt --- internal/kibana/slo.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/kibana/slo.go b/internal/kibana/slo.go index 4e6bb01ff..2b817a370 100644 --- a/internal/kibana/slo.go +++ b/internal/kibana/slo.go @@ -458,10 +458,10 @@ func getSchema() map[string]*schema.Schema { Computed: true, }, "prevent_initial_backfill": { - Description: "Prevents the underlying ES transform from attempting to backfill data on start, which can sometimes be resource-intensive or time-consuming and unnecessary", - Type: schema.BoolAttribute, - Optional: true, - } + Description: "Prevents the underlying ES transform from attempting to backfill data on start, which can sometimes be resource-intensive or time-consuming and unnecessary", + Type: schema.TypeBool, + Optional: true, + }, }, }, }, @@ -663,8 +663,8 @@ func getSloFromResourceData(d *schema.ResourceData) (models.Slo, diag.Diagnostic } settings := slo.Settings{ - SyncDelay: getOrNilString("settings.0.sync_delay", d), - Frequency: getOrNilString("settings.0.frequency", d), + SyncDelay: getOrNilString("settings.0.sync_delay", d), + Frequency: getOrNilString("settings.0.frequency", d), PreventInitialBackfill: getOrNilBool("settings.0.prevent_initial_backfill", d), } @@ -918,8 +918,8 @@ func resourceSloRead(ctx context.Context, d *schema.ResourceData, meta interface if err := d.Set("settings", []interface{}{ map[string]interface{}{ - "sync_delay": s.Settings.SyncDelay, - "frequency": s.Settings.Frequency, + "sync_delay": s.Settings.SyncDelay, + "frequency": s.Settings.Frequency, "prevent_initial_backfill": s.Settings.PreventInitialBackfill, }, }); err != nil {