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

[CLOUDGA-24745] Add support for integration type VICTORIAMETRICS #133

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 18 additions & 0 deletions docs/data-sources/integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ data "ybm_integration" "example_name" {
- `grafana_spec` (Attributes) The specifications of a Grafana integration. (see [below for nested schema](#nestedatt--grafana_spec))
- `is_valid` (Boolean) Signifies whether the integration configuration is valid or not
- `project_id` (String) The ID of the project this integration belongs to.
- `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))
- `type` (String) Defines different exporter destination types.
- `victoriametrics_spec` (Attributes) The specifications of a VictoriaMetrics integration. (see [below for nested schema](#nestedatt--victoriametrics_spec))

<a id="nestedatt--datadog_spec"></a>
### Nested Schema for `datadog_spec`
Expand Down Expand Up @@ -74,6 +76,14 @@ Read-Only:
- `zone` (String) Grafana Zone.


<a id="nestedatt--prometheus_spec"></a>
### Nested Schema for `prometheus_spec`

Read-Only:

- `endpoint` (String) Prometheus OTLP endpoint URL e.g. http://prometheus.yourcompany.com/api/v1/otlp


<a id="nestedatt--sumologic_spec"></a>
### Nested Schema for `sumologic_spec`

Expand All @@ -82,3 +92,11 @@ Read-Only:
- `access_id` (String, Sensitive) Sumo Logic Access Key ID
- `access_key` (String, Sensitive) Sumo Logic Access Key
- `installation_token` (String, Sensitive) A Sumo Logic installation token to export telemetry to Grafana with


<a id="nestedatt--victoriametrics_spec"></a>
### Nested Schema for `victoriametrics_spec`

Read-Only:

- `endpoint` (String) VictoriaMetrics OTLP endpoint URL e.g. http://my-victoria-metrics-endpoint/opentelemetry
9 changes: 9 additions & 0 deletions docs/resources/integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ resource "ybm_integration" "sumologic" {
- `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))
- `victoriametrics_spec` (Attributes) The specifications of a VictoriaMetrics integration. (see [below for nested schema](#nestedatt--victoriametrics_spec))

### Read-Only

Expand Down Expand Up @@ -133,3 +134,11 @@ Required:
- `access_id` (String, Sensitive) Sumo Logic Access Key ID
- `access_key` (String, Sensitive) Sumo Logic Access Key
- `installation_token` (String, Sensitive) A Sumo Logic installation token to export telemetry to Grafana with


<a id="nestedatt--victoriametrics_spec"></a>
### Nested Schema for `victoriametrics_spec`

Required:

- `endpoint` (String) VictoriaMetrics OTLP endpoint URL e.g. http://my-victoria-metrics-endpoint/opentelemetry
30 changes: 30 additions & 0 deletions managed/data_source_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,28 @@ func (r dataSourceIntegrationType) GetSchema(_ context.Context) (tfsdk.Schema, d
},
}),
},
"prometheus_spec": {
Description: "The specifications of a Prometheus integration.",
Computed: true,
Attributes: tfsdk.SingleNestedAttributes(map[string]tfsdk.Attribute{
"endpoint": {
Description: "Prometheus OTLP endpoint URL e.g. http://prometheus.yourcompany.com/api/v1/otlp",
Type: types.StringType,
Computed: true,
},
}),
},
"victoriametrics_spec": {
Description: "The specifications of a VictoriaMetrics integration.",
Computed: true,
Attributes: tfsdk.SingleNestedAttributes(map[string]tfsdk.Attribute{
"endpoint": {
Description: "VictoriaMetrics OTLP endpoint URL e.g. http://my-victoria-metrics-endpoint/opentelemetry",
Type: types.StringType,
Computed: true,
},
}),
},
"grafana_spec": {
Description: "The specifications of a Grafana integration.",
Computed: true,
Expand Down Expand Up @@ -281,6 +303,14 @@ func dataSourceTelemetryProviderRead(accountId string, projectId string, configN
ApiKey: types.String{Value: configSpec.DatadogSpec.Get().ApiKey},
Site: types.String{Value: configSpec.DatadogSpec.Get().Site},
}
case openapiclient.TELEMETRYPROVIDERTYPEENUM_PROMETHEUS:
tp.PrometheusSpec = &PrometheusSpec{
Endpoint: types.String{Value: configSpec.PrometheusSpec.Get().Endpoint},
}
case openapiclient.TELEMETRYPROVIDERTYPEENUM_VICTORIAMETRICS:
tp.VictoriaMetricsSpec = &VictoriaMetricsSpec{
Endpoint: types.String{Value: configSpec.VictoriametricsSpec.Get().Endpoint},
}
case openapiclient.TELEMETRYPROVIDERTYPEENUM_GRAFANA:
grafanaSpec := configSpec.GetGrafanaSpec()
tp.GrafanaSpec = &GrafanaSpec{
Expand Down
27 changes: 16 additions & 11 deletions managed/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ type PrometheusSpec struct {
Endpoint types.String `tfsdk:"endpoint"`
}

type VictoriaMetricsSpec struct {
Endpoint types.String `tfsdk:"endpoint"`
}

type GrafanaSpec struct {
AccessTokenPolicy types.String `tfsdk:"access_policy_token"`
Zone types.String `tfsdk:"zone"`
Expand Down Expand Up @@ -352,17 +356,18 @@ type LogSettings struct {
}

type TelemetryProvider struct {
AccountID types.String `tfsdk:"account_id"`
ProjectID types.String `tfsdk:"project_id"`
ConfigID types.String `tfsdk:"config_id"`
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"`
IsValid types.Bool `tfsdk:"is_valid"`
AccountID types.String `tfsdk:"account_id"`
ProjectID types.String `tfsdk:"project_id"`
ConfigID types.String `tfsdk:"config_id"`
ConfigName types.String `tfsdk:"config_name"`
Type types.String `tfsdk:"type"`
DataDogSpec *DataDogSpec `tfsdk:"datadog_spec"`
PrometheusSpec *PrometheusSpec `tfsdk:"prometheus_spec"`
VictoriaMetricsSpec *VictoriaMetricsSpec `tfsdk:"victoriametrics_spec"`
GrafanaSpec *GrafanaSpec `tfsdk:"grafana_spec"`
SumoLogicSpec *SumoLogicSpec `tfsdk:"sumologic_spec"`
GoogleCloudSpec *GCPServiceAccount `tfsdk:"googlecloud_spec"`
IsValid types.Bool `tfsdk:"is_valid"`
}

type LogConfig struct {
Expand Down
32 changes: 30 additions & 2 deletions managed/resource_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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", "PROMETHEUS")},
Validators: []tfsdk.AttributeValidator{stringvalidator.OneOf("DATADOG", "GRAFANA", "SUMOLOGIC", "GOOGLECLOUD", "PROMETHEUS", "VICTORIAMETRICS")},
},
"is_valid": {
Description: "Signifies whether the integration configuration is valid or not",
Expand Down Expand Up @@ -92,6 +92,18 @@ func (r resourceIntegrationType) getSchemaAttributes() map[string]tfsdk.Attribut
},
}),
},
"victoriametrics_spec": {
Description: "The specifications of a VictoriaMetrics integration.",
Optional: true,
Validators: onlyContainsPath("victoriametrics_spec"),
Attributes: tfsdk.SingleNestedAttributes(map[string]tfsdk.Attribute{
"endpoint": {
Description: "VictoriaMetrics OTLP endpoint URL e.g. http://my-victoria-metrics-endpoint/opentelemetry",
Type: types.StringType,
Required: true,
},
}),
},
"grafana_spec": {
Description: "The specifications of a Grafana integration.",
Optional: true,
Expand Down Expand Up @@ -212,7 +224,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", "prometheus_spec"}
allPaths := []string{"datadog_spec", "grafana_spec", "sumologic_spec", "googlecloud_spec", "prometheus_spec", "victoriametrics_spec"}
var validators []tfsdk.AttributeValidator

for _, specPath := range allPaths {
Expand Down Expand Up @@ -240,6 +252,7 @@ func getIntegrationPlan(ctx context.Context, plan tfsdk.Plan, tp *TelemetryProvi
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("victoriametrics_spec"), &tp.VictoriaMetricsSpec)...)
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)...)
Expand All @@ -256,6 +269,8 @@ func getIDsFromIntegrationState(ctx context.Context, state tfsdk.State, tp *Tele
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_VICTORIAMETRICS):
state.GetAttribute(ctx, path.Root("victoriametrics_spec"), &tp.VictoriaMetricsSpec)
case string(openapiclient.TELEMETRYPROVIDERTYPEENUM_GRAFANA):
state.GetAttribute(ctx, path.Root("grafana_spec"), &tp.GrafanaSpec)
case string(openapiclient.TELEMETRYPROVIDERTYPEENUM_SUMOLOGIC):
Expand Down Expand Up @@ -330,6 +345,15 @@ func (r resourceIntegration) Create(ctx context.Context, req tfsdk.CreateResourc
return
}
telemetryProviderSpec.SetPrometheusSpec(*openapiclient.NewPrometheusTelemetryProviderSpec(plan.PrometheusSpec.Endpoint.Value))
case openapiclient.TELEMETRYPROVIDERTYPEENUM_VICTORIAMETRICS:
if plan.VictoriaMetricsSpec == nil {
resp.Diagnostics.AddError(
"victoriametrics_spec is required for type VICTORIAMETRICS",
"victoriametrics_spec is required when telemetry sink is VICTORIAMETRICS. Please include this field in the resource",
)
return
}
telemetryProviderSpec.SetVictoriametricsSpec(*openapiclient.NewVictoriaMetricsTelemetryProviderSpec(plan.VictoriaMetricsSpec.Endpoint.Value))
case openapiclient.TELEMETRYPROVIDERTYPEENUM_GRAFANA:
if plan.GrafanaSpec == nil {
resp.Diagnostics.AddError(
Expand Down Expand Up @@ -460,6 +484,10 @@ func resourceTelemetryProviderRead(accountId string, projectId string, configID
tp.PrometheusSpec = &PrometheusSpec{
Endpoint: types.String{Value: userProvidedTpDetails.PrometheusSpec.Endpoint.Value},
}
case openapiclient.TELEMETRYPROVIDERTYPEENUM_VICTORIAMETRICS:
tp.VictoriaMetricsSpec = &VictoriaMetricsSpec{
Endpoint: types.String{Value: configSpec.VictoriametricsSpec.Get().Endpoint},
}
case openapiclient.TELEMETRYPROVIDERTYPEENUM_GRAFANA:
grafanaSpec := configSpec.GetGrafanaSpec()
tp.GrafanaSpec = &GrafanaSpec{
Expand Down
Loading