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-24744] Add support for integration type VICTORIAMETRICS #275

Merged
merged 1 commit 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
14 changes: 14 additions & 0 deletions cmd/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ func init() {
createIntegrationCmd.Flags().StringToString("prometheus-spec", nil, `Configuration for prometheus.
Please provide key value pairs as follows:
endpoint=<prometheus-otlp-endpoint-url>`)
createIntegrationCmd.Flags().StringToString("victoriametrics-spec", nil, `Configuration for victoriametrics.
Please provide key value pairs as follows:
endpoint=<victoriametrics-otlp-endpoint-url>`)

if util.IsFeatureFlagEnabled(util.GOOGLECLOUD_INTEGRATION) {
createIntegrationCmd.Flags().String("googlecloud-cred-filepath", "", `Filepath for Google Cloud service account credentials.
Expand Down Expand Up @@ -219,6 +222,17 @@ func setIntegrationConfiguration(cmd *cobra.Command, IntegrationName string, sin
}
prometheusSpec := ybmclient.NewPrometheusTelemetryProviderSpec(endpoint)
IntegrationSpec.SetPrometheusSpec(*prometheusSpec)
case ybmclient.TELEMETRYPROVIDERTYPEENUM_VICTORIAMETRICS:
if !cmd.Flags().Changed("victoriametrics-spec") {
return nil, fmt.Errorf("victoriametrics-spec is required for victoriametrics sink")
}
victoriametricsSpecs, _ := cmd.Flags().GetStringToString("victoriametrics-spec")
endpoint := victoriametricsSpecs["endpoint"]
if len(endpoint) < 1 {
return nil, fmt.Errorf("endpoint is a required field for victoriametrics-spec")
}
victoriametricsSpec := ybmclient.NewVictoriaMetricsTelemetryProviderSpec(endpoint)
IntegrationSpec.SetVictoriametricsSpec(*victoriametricsSpec)
case ybmclient.TELEMETRYPROVIDERTYPEENUM_GRAFANA:
if !cmd.Flags().Changed("grafana-spec") {
return nil, fmt.Errorf("grafana-spec is required for grafana sink")
Expand Down
39 changes: 39 additions & 0 deletions cmd/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,45 @@ ID Name Type Endpoint

})

Context("When type is VictoriaMetrics", func() {
It("should create the config", func() {
statusCode = 200
err := loadJson("./test/fixtures/metrics-exporter-victoriametrics.json", &responseIntegration)
Expect(err).ToNot(HaveOccurred())
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest(http.MethodPost, "/api/public/v1/accounts/340af43a-8a7c-4659-9258-4876fd6a207b/projects/78d4459c-0f45-47a5-899a-45ddf43eba6e/telemetry-providers"),
ghttp.RespondWithJSONEncodedPtr(&statusCode, responseIntegration),
),
)
cmd := exec.Command(compiledCLIPath, "integration", "create", "--config-name", "test", "--type", "victoriametrics", "--victoriametrics-spec", "endpoint=http://victoriametrics.yourcompany.com")
session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
session.Wait(2)
Expect(session.Out).Should(gbytes.Say(`The Integration test has been created
ID Name Type Endpoint
9e3fabbc-849c-4a77-bdb2-9422e712e7dc test VICTORIAMETRICS http://victoriametrics.yourcompany.com`))
session.Kill()
})
It("should return error when arg victoriametrics-spec not set", func() {
cmd := exec.Command(compiledCLIPath, "integration", "create", "--config-name", "test", "--type", "victoriametrics")
session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
session.Wait(2)
Expect(session.Err).Should(gbytes.Say("victoriametrics-spec is required for victoriametrics sink"))
session.Kill()
})
It("should return error when field endpoint not set", func() {
cmd := exec.Command(compiledCLIPath, "integration", "create", "--config-name", "test", "--type", "victoriametrics", "--victoriametrics-spec", "invalid-key=val")
session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
session.Wait(2)
Expect(session.Err).Should(gbytes.Say("(?m:endpoint is a required field for victoriametrics-spec$)"))
session.Kill()
})

})

Context("When type is Grafana", func() {
It("should create the config", func() {
statusCode = 200
Expand Down
19 changes: 19 additions & 0 deletions cmd/test/fixtures/metrics-exporter-victoriametrics.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"data": {
"spec": {
"name": "test",
"type": "VICTORIAMETRICS",
"victoriametrics_spec": {
"endpoint": "http://victoriametrics.yourcompany.com"
}
},
"info": {
"id": "9e3fabbc-849c-4a77-bdb2-9422e712e7dc",
"cluster_ids": [],
"metadata": {
"created_on": "2023-08-24T06:41:16.145Z",
"updated_on": "2023-08-24T06:41:16.145Z"
}
}
}
}
39 changes: 24 additions & 15 deletions internal/formatter/telemetry_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import (

const defaultIntegrationListing = "table {{.ID}}\t{{.Name}}\t{{.Type}}"
const defaultIntegrationDataDog = "table {{.ID}}\t{{.Name}}\t{{.Type}}\t{{.Site}}\t{{.ApiKey}}"
const defaultIntegrationPrometheus = "table {{.ID}}\t{{.Name}}\t{{.Type}}\t{{.Endpoint}}"
const defaultIntegrationPrometheus = "table {{.ID}}\t{{.Name}}\t{{.Type}}\t{{.PrometheusEndpoint}}"
const defaultIntegrationVictoriaMetrics = "table {{.ID}}\t{{.Name}}\t{{.Type}}\t{{.VictoriaMetricsEndpoint}}"
const defaultIntegrationGrafana = "table {{.ID}}\t{{.Name}}\t{{.Type}}\t{{.Zone}}\t{{.AccessTokenPolicy}}\t{{.InstanceId}}\t{{.OrgSlug}}"
const defaultIntegrationSumologic = "table {{.ID}}\t{{.Name}}\t{{.Type}}\t{{.AccessKey}}\t{{.AccessID}}\t{{.InstallationToken}}"

Expand All @@ -44,6 +45,8 @@ func NewIntegrationFormat(source string, providerType string) Format {
format = defaultIntegrationDataDog
case string(ybmclient.TELEMETRYPROVIDERTYPEENUM_PROMETHEUS):
format = defaultIntegrationPrometheus
case string(ybmclient.TELEMETRYPROVIDERTYPEENUM_VICTORIAMETRICS):
format = defaultIntegrationVictoriaMetrics
case string(ybmclient.TELEMETRYPROVIDERTYPEENUM_GRAFANA):
format = defaultIntegrationGrafana
case string(ybmclient.TELEMETRYPROVIDERTYPEENUM_SUMOLOGIC):
Expand All @@ -61,19 +64,20 @@ func NewIntegrationFormat(source string, providerType string) Format {
func NewIntegrationContext() *IntegrationContext {
IntegrationCtx := IntegrationContext{}
IntegrationCtx.Header = SubHeaderContext{
"Name": nameHeader,
"ID": "ID",
"Type": "Type",
"Site": "Site",
"ApiKey": "ApiKey",
"InstanceId": "InstanceId",
"OrgSlug": "OrgSlug",
"AccessTokenPolicy": "Access Token Policy",
"Zone": "Zone",
"InstallationToken": "InstallationToken",
"AccessID": "Access ID",
"AccessKey": "Access Key",
"Endpoint": "Endpoint",
"Name": nameHeader,
"ID": "ID",
"Type": "Type",
"Site": "Site",
"ApiKey": "ApiKey",
"InstanceId": "InstanceId",
"OrgSlug": "OrgSlug",
"AccessTokenPolicy": "Access Token Policy",
"Zone": "Zone",
"InstallationToken": "InstallationToken",
"AccessID": "Access ID",
"AccessKey": "Access Key",
"PrometheusEndpoint": "Endpoint",
"VictoriaMetricsEndpoint": "Endpoint",
}
return &IntegrationCtx
}
Expand Down Expand Up @@ -155,6 +159,11 @@ func IntegrationShortenKey(key string, stringLen int) string {
}

// Prometheus
func (tp *IntegrationContext) Endpoint() string {
func (tp *IntegrationContext) PrometheusEndpoint() string {
return tp.tp.Spec.GetPrometheusSpec().Endpoint
}

// Victoria Metrics
func (tp *IntegrationContext) VictoriaMetricsEndpoint() string {
return tp.tp.Spec.GetVictoriametricsSpec().Endpoint
}