Skip to content

Commit f65a485

Browse files
[CLOUDGA-24745] Add support for integration type VICTORIAMETRICS (#133)
[CLOUDGA-24745] Add support for integration type VICTORIAMETRICS Implement data-source for prometheus & victoriametrics
1 parent 6ebab8e commit f65a485

File tree

5 files changed

+103
-13
lines changed

5 files changed

+103
-13
lines changed

docs/data-sources/integration.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ data "ybm_integration" "example_name" {
3333
- `grafana_spec` (Attributes) The specifications of a Grafana integration. (see [below for nested schema](#nestedatt--grafana_spec))
3434
- `is_valid` (Boolean) Signifies whether the integration configuration is valid or not
3535
- `project_id` (String) The ID of the project this integration belongs to.
36+
- `prometheus_spec` (Attributes) The specifications of a Prometheus integration. (see [below for nested schema](#nestedatt--prometheus_spec))
3637
- `sumologic_spec` (Attributes) The specifications of a Sumo Logic integration. (see [below for nested schema](#nestedatt--sumologic_spec))
3738
- `type` (String) Defines different exporter destination types.
39+
- `victoriametrics_spec` (Attributes) The specifications of a VictoriaMetrics integration. (see [below for nested schema](#nestedatt--victoriametrics_spec))
3840

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

7678

79+
<a id="nestedatt--prometheus_spec"></a>
80+
### Nested Schema for `prometheus_spec`
81+
82+
Read-Only:
83+
84+
- `endpoint` (String) Prometheus OTLP endpoint URL e.g. http://prometheus.yourcompany.com/api/v1/otlp
85+
86+
7787
<a id="nestedatt--sumologic_spec"></a>
7888
### Nested Schema for `sumologic_spec`
7989

@@ -82,3 +92,11 @@ Read-Only:
8292
- `access_id` (String, Sensitive) Sumo Logic Access Key ID
8393
- `access_key` (String, Sensitive) Sumo Logic Access Key
8494
- `installation_token` (String, Sensitive) A Sumo Logic installation token to export telemetry to Grafana with
95+
96+
97+
<a id="nestedatt--victoriametrics_spec"></a>
98+
### Nested Schema for `victoriametrics_spec`
99+
100+
Read-Only:
101+
102+
- `endpoint` (String) VictoriaMetrics OTLP endpoint URL e.g. http://my-victoria-metrics-endpoint/opentelemetry

docs/resources/integration.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ resource "ybm_integration" "sumologic" {
6868
- `grafana_spec` (Attributes) The specifications of a Grafana integration. (see [below for nested schema](#nestedatt--grafana_spec))
6969
- `prometheus_spec` (Attributes) The specifications of a Prometheus integration. (see [below for nested schema](#nestedatt--prometheus_spec))
7070
- `sumologic_spec` (Attributes) The specifications of a Sumo Logic integration. (see [below for nested schema](#nestedatt--sumologic_spec))
71+
- `victoriametrics_spec` (Attributes) The specifications of a VictoriaMetrics integration. (see [below for nested schema](#nestedatt--victoriametrics_spec))
7172

7273
### Read-Only
7374

@@ -133,3 +134,11 @@ Required:
133134
- `access_id` (String, Sensitive) Sumo Logic Access Key ID
134135
- `access_key` (String, Sensitive) Sumo Logic Access Key
135136
- `installation_token` (String, Sensitive) A Sumo Logic installation token to export telemetry to Grafana with
137+
138+
139+
<a id="nestedatt--victoriametrics_spec"></a>
140+
### Nested Schema for `victoriametrics_spec`
141+
142+
Required:
143+
144+
- `endpoint` (String) VictoriaMetrics OTLP endpoint URL e.g. http://my-victoria-metrics-endpoint/opentelemetry

managed/data_source_integration.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,28 @@ func (r dataSourceIntegrationType) GetSchema(_ context.Context) (tfsdk.Schema, d
7070
},
7171
}),
7272
},
73+
"prometheus_spec": {
74+
Description: "The specifications of a Prometheus integration.",
75+
Computed: true,
76+
Attributes: tfsdk.SingleNestedAttributes(map[string]tfsdk.Attribute{
77+
"endpoint": {
78+
Description: "Prometheus OTLP endpoint URL e.g. http://prometheus.yourcompany.com/api/v1/otlp",
79+
Type: types.StringType,
80+
Computed: true,
81+
},
82+
}),
83+
},
84+
"victoriametrics_spec": {
85+
Description: "The specifications of a VictoriaMetrics integration.",
86+
Computed: true,
87+
Attributes: tfsdk.SingleNestedAttributes(map[string]tfsdk.Attribute{
88+
"endpoint": {
89+
Description: "VictoriaMetrics OTLP endpoint URL e.g. http://my-victoria-metrics-endpoint/opentelemetry",
90+
Type: types.StringType,
91+
Computed: true,
92+
},
93+
}),
94+
},
7395
"grafana_spec": {
7496
Description: "The specifications of a Grafana integration.",
7597
Computed: true,
@@ -281,6 +303,14 @@ func dataSourceTelemetryProviderRead(accountId string, projectId string, configN
281303
ApiKey: types.String{Value: configSpec.DatadogSpec.Get().ApiKey},
282304
Site: types.String{Value: configSpec.DatadogSpec.Get().Site},
283305
}
306+
case openapiclient.TELEMETRYPROVIDERTYPEENUM_PROMETHEUS:
307+
tp.PrometheusSpec = &PrometheusSpec{
308+
Endpoint: types.String{Value: configSpec.PrometheusSpec.Get().Endpoint},
309+
}
310+
case openapiclient.TELEMETRYPROVIDERTYPEENUM_VICTORIAMETRICS:
311+
tp.VictoriaMetricsSpec = &VictoriaMetricsSpec{
312+
Endpoint: types.String{Value: configSpec.VictoriametricsSpec.Get().Endpoint},
313+
}
284314
case openapiclient.TELEMETRYPROVIDERTYPEENUM_GRAFANA:
285315
grafanaSpec := configSpec.GetGrafanaSpec()
286316
tp.GrafanaSpec = &GrafanaSpec{

managed/models.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,10 @@ type PrometheusSpec struct {
282282
Endpoint types.String `tfsdk:"endpoint"`
283283
}
284284

285+
type VictoriaMetricsSpec struct {
286+
Endpoint types.String `tfsdk:"endpoint"`
287+
}
288+
285289
type GrafanaSpec struct {
286290
AccessTokenPolicy types.String `tfsdk:"access_policy_token"`
287291
Zone types.String `tfsdk:"zone"`
@@ -352,17 +356,18 @@ type LogSettings struct {
352356
}
353357

354358
type TelemetryProvider struct {
355-
AccountID types.String `tfsdk:"account_id"`
356-
ProjectID types.String `tfsdk:"project_id"`
357-
ConfigID types.String `tfsdk:"config_id"`
358-
ConfigName types.String `tfsdk:"config_name"`
359-
Type types.String `tfsdk:"type"`
360-
DataDogSpec *DataDogSpec `tfsdk:"datadog_spec"`
361-
PrometheusSpec *PrometheusSpec `tfsdk:"prometheus_spec"`
362-
GrafanaSpec *GrafanaSpec `tfsdk:"grafana_spec"`
363-
SumoLogicSpec *SumoLogicSpec `tfsdk:"sumologic_spec"`
364-
GoogleCloudSpec *GCPServiceAccount `tfsdk:"googlecloud_spec"`
365-
IsValid types.Bool `tfsdk:"is_valid"`
359+
AccountID types.String `tfsdk:"account_id"`
360+
ProjectID types.String `tfsdk:"project_id"`
361+
ConfigID types.String `tfsdk:"config_id"`
362+
ConfigName types.String `tfsdk:"config_name"`
363+
Type types.String `tfsdk:"type"`
364+
DataDogSpec *DataDogSpec `tfsdk:"datadog_spec"`
365+
PrometheusSpec *PrometheusSpec `tfsdk:"prometheus_spec"`
366+
VictoriaMetricsSpec *VictoriaMetricsSpec `tfsdk:"victoriametrics_spec"`
367+
GrafanaSpec *GrafanaSpec `tfsdk:"grafana_spec"`
368+
SumoLogicSpec *SumoLogicSpec `tfsdk:"sumologic_spec"`
369+
GoogleCloudSpec *GCPServiceAccount `tfsdk:"googlecloud_spec"`
370+
IsValid types.Bool `tfsdk:"is_valid"`
366371
}
367372

368373
type LogConfig struct {

managed/resource_integration.go

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (r resourceIntegrationType) getSchemaAttributes() map[string]tfsdk.Attribut
5555
Description: "Defines different exporter destination types.",
5656
Type: types.StringType,
5757
Required: true,
58-
Validators: []tfsdk.AttributeValidator{stringvalidator.OneOf("DATADOG", "GRAFANA", "SUMOLOGIC", "GOOGLECLOUD", "PROMETHEUS")},
58+
Validators: []tfsdk.AttributeValidator{stringvalidator.OneOf("DATADOG", "GRAFANA", "SUMOLOGIC", "GOOGLECLOUD", "PROMETHEUS", "VICTORIAMETRICS")},
5959
},
6060
"is_valid": {
6161
Description: "Signifies whether the integration configuration is valid or not",
@@ -92,6 +92,18 @@ func (r resourceIntegrationType) getSchemaAttributes() map[string]tfsdk.Attribut
9292
},
9393
}),
9494
},
95+
"victoriametrics_spec": {
96+
Description: "The specifications of a VictoriaMetrics integration.",
97+
Optional: true,
98+
Validators: onlyContainsPath("victoriametrics_spec"),
99+
Attributes: tfsdk.SingleNestedAttributes(map[string]tfsdk.Attribute{
100+
"endpoint": {
101+
Description: "VictoriaMetrics OTLP endpoint URL e.g. http://my-victoria-metrics-endpoint/opentelemetry",
102+
Type: types.StringType,
103+
Required: true,
104+
},
105+
}),
106+
},
95107
"grafana_spec": {
96108
Description: "The specifications of a Grafana integration.",
97109
Optional: true,
@@ -212,7 +224,7 @@ func (r resourceIntegrationType) getSchemaAttributes() map[string]tfsdk.Attribut
212224
}
213225

214226
func onlyContainsPath(requiredPath string) []tfsdk.AttributeValidator {
215-
allPaths := []string{"datadog_spec", "grafana_spec", "sumologic_spec", "googlecloud_spec", "prometheus_spec"}
227+
allPaths := []string{"datadog_spec", "grafana_spec", "sumologic_spec", "googlecloud_spec", "prometheus_spec", "victoriametrics_spec"}
216228
var validators []tfsdk.AttributeValidator
217229

218230
for _, specPath := range allPaths {
@@ -240,6 +252,7 @@ func getIntegrationPlan(ctx context.Context, plan tfsdk.Plan, tp *TelemetryProvi
240252
diags.Append(plan.GetAttribute(ctx, path.Root("type"), &tp.Type)...)
241253
diags.Append(plan.GetAttribute(ctx, path.Root("datadog_spec"), &tp.DataDogSpec)...)
242254
diags.Append(plan.GetAttribute(ctx, path.Root("prometheus_spec"), &tp.PrometheusSpec)...)
255+
diags.Append(plan.GetAttribute(ctx, path.Root("victoriametrics_spec"), &tp.VictoriaMetricsSpec)...)
243256
diags.Append(plan.GetAttribute(ctx, path.Root("grafana_spec"), &tp.GrafanaSpec)...)
244257
diags.Append(plan.GetAttribute(ctx, path.Root("sumologic_spec"), &tp.SumoLogicSpec)...)
245258
diags.Append(plan.GetAttribute(ctx, path.Root("googlecloud_spec"), &tp.GoogleCloudSpec)...)
@@ -256,6 +269,8 @@ func getIDsFromIntegrationState(ctx context.Context, state tfsdk.State, tp *Tele
256269
state.GetAttribute(ctx, path.Root("datadog_spec"), &tp.DataDogSpec)
257270
case string(openapiclient.TELEMETRYPROVIDERTYPEENUM_PROMETHEUS):
258271
state.GetAttribute(ctx, path.Root("prometheus_spec"), &tp.PrometheusSpec)
272+
case string(openapiclient.TELEMETRYPROVIDERTYPEENUM_VICTORIAMETRICS):
273+
state.GetAttribute(ctx, path.Root("victoriametrics_spec"), &tp.VictoriaMetricsSpec)
259274
case string(openapiclient.TELEMETRYPROVIDERTYPEENUM_GRAFANA):
260275
state.GetAttribute(ctx, path.Root("grafana_spec"), &tp.GrafanaSpec)
261276
case string(openapiclient.TELEMETRYPROVIDERTYPEENUM_SUMOLOGIC):
@@ -330,6 +345,15 @@ func (r resourceIntegration) Create(ctx context.Context, req tfsdk.CreateResourc
330345
return
331346
}
332347
telemetryProviderSpec.SetPrometheusSpec(*openapiclient.NewPrometheusTelemetryProviderSpec(plan.PrometheusSpec.Endpoint.Value))
348+
case openapiclient.TELEMETRYPROVIDERTYPEENUM_VICTORIAMETRICS:
349+
if plan.VictoriaMetricsSpec == nil {
350+
resp.Diagnostics.AddError(
351+
"victoriametrics_spec is required for type VICTORIAMETRICS",
352+
"victoriametrics_spec is required when telemetry sink is VICTORIAMETRICS. Please include this field in the resource",
353+
)
354+
return
355+
}
356+
telemetryProviderSpec.SetVictoriametricsSpec(*openapiclient.NewVictoriaMetricsTelemetryProviderSpec(plan.VictoriaMetricsSpec.Endpoint.Value))
333357
case openapiclient.TELEMETRYPROVIDERTYPEENUM_GRAFANA:
334358
if plan.GrafanaSpec == nil {
335359
resp.Diagnostics.AddError(
@@ -460,6 +484,10 @@ func resourceTelemetryProviderRead(accountId string, projectId string, configID
460484
tp.PrometheusSpec = &PrometheusSpec{
461485
Endpoint: types.String{Value: userProvidedTpDetails.PrometheusSpec.Endpoint.Value},
462486
}
487+
case openapiclient.TELEMETRYPROVIDERTYPEENUM_VICTORIAMETRICS:
488+
tp.VictoriaMetricsSpec = &VictoriaMetricsSpec{
489+
Endpoint: types.String{Value: configSpec.VictoriametricsSpec.Get().Endpoint},
490+
}
463491
case openapiclient.TELEMETRYPROVIDERTYPEENUM_GRAFANA:
464492
grafanaSpec := configSpec.GetGrafanaSpec()
465493
tp.GrafanaSpec = &GrafanaSpec{

0 commit comments

Comments
 (0)