From 948e548e7819122c0c769a3dcf74c90fe4c29d5f Mon Sep 17 00:00:00 2001 From: bhupendray-yb Date: Wed, 20 Nov 2024 17:50:51 +0530 Subject: [PATCH 1/3] [CLOUDGA-22303] Add support for integration type PROMETHEUS --- managed/models.go | 5 +++++ managed/resource_integration.go | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/managed/models.go b/managed/models.go index 0a64a8f..d0b18b2 100644 --- a/managed/models.go +++ b/managed/models.go @@ -278,6 +278,10 @@ type DataDogSpec struct { ApiKey types.String `tfsdk:"api_key"` } +type PrometheusSpec struct { + Endpoint types.String `tfsdk:"endpoint"` +} + type GrafanaSpec struct { AccessTokenPolicy types.String `tfsdk:"access_policy_token"` Zone types.String `tfsdk:"zone"` @@ -354,6 +358,7 @@ type TelemetryProvider struct { ConfigName types.String `tfsdk:"config_name"` Type types.String `tfsdk:"type"` DataDogSpec *DataDogSpec `tfsdk:"datadog_spec"` + PrometheusSpec *PrometheusSpec `tfsdk:"prometheus_spec"` GrafanaSpec *GrafanaSpec `tfsdk:"grafana_spec"` SumoLogicSpec *SumoLogicSpec `tfsdk:"sumologic_spec"` GoogleCloudSpec *GCPServiceAccount `tfsdk:"googlecloud_spec"` diff --git a/managed/resource_integration.go b/managed/resource_integration.go index 685c182..2c60b3b 100644 --- a/managed/resource_integration.go +++ b/managed/resource_integration.go @@ -55,7 +55,7 @@ func (r resourceIntegrationType) getSchemaAttributes() map[string]tfsdk.Attribut Description: "Defines different exporter destination types.", Type: types.StringType, Required: true, - Validators: []tfsdk.AttributeValidator{stringvalidator.OneOf("DATADOG", "GRAFANA", "SUMOLOGIC", "GOOGLECLOUD")}, + Validators: []tfsdk.AttributeValidator{stringvalidator.OneOf("DATADOG", "GRAFANA", "SUMOLOGIC", "GOOGLECLOUD", "PROMETHEUS")}, }, "is_valid": { Description: "Signifies whether the integration configuration is valid or not", @@ -80,6 +80,18 @@ func (r resourceIntegrationType) getSchemaAttributes() map[string]tfsdk.Attribut }, }), }, + "prometheus_spec": { + Description: "The specifications of a Prometheus integration.", + Optional: true, + Validators: onlyContainsPath("prometheus_spec"), + Attributes: tfsdk.SingleNestedAttributes(map[string]tfsdk.Attribute{ + "endpoint": { + Description: "Prometheus OTLP endpoint URL", + Type: types.StringType, + Required: true, + }, + }), + }, "grafana_spec": { Description: "The specifications of a Grafana integration.", Optional: true, @@ -200,7 +212,7 @@ func (r resourceIntegrationType) getSchemaAttributes() map[string]tfsdk.Attribut } func onlyContainsPath(requiredPath string) []tfsdk.AttributeValidator { - allPaths := []string{"datadog_spec", "grafana_spec", "sumologic_spec", "googlecloud_spec"} + allPaths := []string{"datadog_spec", "grafana_spec", "sumologic_spec", "googlecloud_spec", "prometheus_spec"} var validators []tfsdk.AttributeValidator for _, specPath := range allPaths { @@ -227,6 +239,7 @@ func getIntegrationPlan(ctx context.Context, plan tfsdk.Plan, tp *TelemetryProvi diags.Append(plan.GetAttribute(ctx, path.Root("config_name"), &tp.ConfigName)...) diags.Append(plan.GetAttribute(ctx, path.Root("type"), &tp.Type)...) diags.Append(plan.GetAttribute(ctx, path.Root("datadog_spec"), &tp.DataDogSpec)...) + diags.Append(plan.GetAttribute(ctx, path.Root("prometheus_spec"), &tp.PrometheusSpec)...) diags.Append(plan.GetAttribute(ctx, path.Root("grafana_spec"), &tp.GrafanaSpec)...) diags.Append(plan.GetAttribute(ctx, path.Root("sumologic_spec"), &tp.SumoLogicSpec)...) diags.Append(plan.GetAttribute(ctx, path.Root("googlecloud_spec"), &tp.GoogleCloudSpec)...) @@ -241,6 +254,8 @@ func getIDsFromIntegrationState(ctx context.Context, state tfsdk.State, tp *Tele switch tp.Type.Value { case string(openapiclient.TELEMETRYPROVIDERTYPEENUM_DATADOG): state.GetAttribute(ctx, path.Root("datadog_spec"), &tp.DataDogSpec) + case string(openapiclient.TELEMETRYPROVIDERTYPEENUM_PROMETHEUS): + state.GetAttribute(ctx, path.Root("prometheus_spec"), &tp.PrometheusSpec) case string(openapiclient.TELEMETRYPROVIDERTYPEENUM_GRAFANA): state.GetAttribute(ctx, path.Root("grafana_spec"), &tp.GrafanaSpec) case string(openapiclient.TELEMETRYPROVIDERTYPEENUM_SUMOLOGIC): @@ -306,6 +321,15 @@ func (r resourceIntegration) Create(ctx context.Context, req tfsdk.CreateResourc return } telemetryProviderSpec.SetDatadogSpec(*openapiclient.NewDatadogTelemetryProviderSpec(plan.DataDogSpec.ApiKey.Value, plan.DataDogSpec.Site.Value)) + case openapiclient.TELEMETRYPROVIDERTYPEENUM_PROMETHEUS: + if plan.PrometheusSpec == nil { + resp.Diagnostics.AddError( + "prometheus_spec is required for type PROMETHEUS", + "prometheus_spec is required when telemetry sink is PROMETHEUS. Please include this field in the resource", + ) + return + } + telemetryProviderSpec.SetPrometheusSpec(*openapiclient.NewPrometheusTelemetryProviderSpec(plan.PrometheusSpec.Endpoint.Value)) case openapiclient.TELEMETRYPROVIDERTYPEENUM_GRAFANA: if plan.GrafanaSpec == nil { resp.Diagnostics.AddError( @@ -432,6 +456,10 @@ func resourceTelemetryProviderRead(accountId string, projectId string, configID ApiKey: userProvidedTpDetails.DataDogSpec.ApiKey, Site: types.String{Value: configSpec.DatadogSpec.Get().Site}, } + case openapiclient.TELEMETRYPROVIDERTYPEENUM_PROMETHEUS: + tp.PrometheusSpec = &PrometheusSpec{ + Endpoint: types.String{Value: userProvidedTpDetails.PrometheusSpec.Endpoint.Value}, + } case openapiclient.TELEMETRYPROVIDERTYPEENUM_GRAFANA: grafanaSpec := configSpec.GetGrafanaSpec() tp.GrafanaSpec = &GrafanaSpec{ From 98770d8ccbaf71d6555f25befd417933b5c9aee8 Mon Sep 17 00:00:00 2001 From: bhupendray-yb Date: Wed, 20 Nov 2024 18:58:36 +0530 Subject: [PATCH 2/3] [CLOUDGA-22303] Add docs --- docs/resources/integration.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/resources/integration.md b/docs/resources/integration.md index f5cb291..f953a8c 100644 --- a/docs/resources/integration.md +++ b/docs/resources/integration.md @@ -66,6 +66,7 @@ resource "ybm_integration" "sumologic" { - `datadog_spec` (Attributes) The specifications of a Datadog integration. (see [below for nested schema](#nestedatt--datadog_spec)) - `googlecloud_spec` (Attributes) The specifications of a Google Cloud integration. (see [below for nested schema](#nestedatt--googlecloud_spec)) - `grafana_spec` (Attributes) The specifications of a Grafana integration. (see [below for nested schema](#nestedatt--grafana_spec)) +- `prometheus_spec` (Attributes) The specifications of a Prometheus integration. (see [below for nested schema](#nestedatt--prometheus_spec)) - `sumologic_spec` (Attributes) The specifications of a Sumo Logic integration. (see [below for nested schema](#nestedatt--sumologic_spec)) ### Read-Only @@ -116,6 +117,14 @@ Required: - `zone` (String) Grafana Zone. + +### Nested Schema for `prometheus_spec` + +Required: + +- `endpoint` (String) Prometheus OTLP endpoint URL + + ### Nested Schema for `sumologic_spec` From 767262b7f64caf734eceb4b222a509e5e948e235 Mon Sep 17 00:00:00 2001 From: bhupendray-yb Date: Fri, 22 Nov 2024 14:23:16 +0530 Subject: [PATCH 3/3] [CLOUDGA-22303] improve description of endpoint --- docs/resources/integration.md | 2 +- managed/resource_integration.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/resources/integration.md b/docs/resources/integration.md index f953a8c..f65d77d 100644 --- a/docs/resources/integration.md +++ b/docs/resources/integration.md @@ -122,7 +122,7 @@ Required: Required: -- `endpoint` (String) Prometheus OTLP endpoint URL +- `endpoint` (String) Prometheus OTLP endpoint URL e.g. http://prometheus.yourcompany.com/api/v1/otlp diff --git a/managed/resource_integration.go b/managed/resource_integration.go index 2c60b3b..b4d4a61 100644 --- a/managed/resource_integration.go +++ b/managed/resource_integration.go @@ -86,7 +86,7 @@ func (r resourceIntegrationType) getSchemaAttributes() map[string]tfsdk.Attribut Validators: onlyContainsPath("prometheus_spec"), Attributes: tfsdk.SingleNestedAttributes(map[string]tfsdk.Attribute{ "endpoint": { - Description: "Prometheus OTLP endpoint URL", + Description: "Prometheus OTLP endpoint URL e.g. http://prometheus.yourcompany.com/api/v1/otlp", Type: types.StringType, Required: true, },