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

Fixed an issue in the static config converter where exporter instance… #5782

Merged
merged 1 commit into from
Nov 15, 2023
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ Main (unreleased)
resulting in remote write sending the exemplar first and Prometheus failing to ingest it due to missing
series. (@krajorama)

- Fixed an issue in the static config converter where exporter instance values
were not being mapped when translating to flow. (@erikbaranowski)

v0.37.4 (2023-11-06)
-----------------

Expand Down
21 changes: 20 additions & 1 deletion converter/internal/staticconvert/internal/build/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,19 @@ func (b *IntegrationsConfigBuilder) appendV1Integrations() {
}

func (b *IntegrationsConfigBuilder) appendExporter(commonConfig *int_config.Common, name string, extraTargets []discovery.Target) {
var relabelConfigs []*relabel.Config
if commonConfig.InstanceKey != nil {
defaultConfig := relabel.DefaultRelabelConfig
relabelConfig := &defaultConfig
relabelConfig.TargetLabel = "instance"
relabelConfig.Replacement = *commonConfig.InstanceKey

relabelConfigs = append(relabelConfigs, relabelConfig)
}

scrapeConfig := prom_config.DefaultScrapeConfig
scrapeConfig.JobName = b.formatJobName(name, nil)
scrapeConfig.RelabelConfigs = commonConfig.RelabelConfigs
scrapeConfig.RelabelConfigs = append(commonConfig.RelabelConfigs, relabelConfigs...)
scrapeConfig.MetricRelabelConfigs = commonConfig.MetricRelabelConfigs
scrapeConfig.HTTPClientConfig.TLSConfig = b.cfg.Integrations.ConfigV1.TLSConfig

Expand Down Expand Up @@ -282,6 +292,15 @@ func (b *IntegrationsConfigBuilder) appendExporterV2(commonConfig *common_v2.Met
relabelConfigs = append(relabelConfigs, relabelConfig)
}

if commonConfig.InstanceKey != nil {
defaultConfig := relabel.DefaultRelabelConfig
relabelConfig := &defaultConfig
relabelConfig.TargetLabel = "instance"
relabelConfig.Replacement = *commonConfig.InstanceKey

relabelConfigs = append(relabelConfigs, relabelConfig)
}

commonConfig.ApplyDefaults(b.cfg.Integrations.ConfigV2.Metrics.Autoscrape)
scrapeConfig := prom_config.DefaultScrapeConfig
scrapeConfig.JobName = b.formatJobName(name, commonConfig.InstanceKey)
Expand Down
38 changes: 35 additions & 3 deletions converter/internal/staticconvert/testdata-v2/integrations_v2.river
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,17 @@ prometheus.exporter.azure "integrations_azure1" {
metrics = ["HttpRequestCount"]
}

discovery.relabel "integrations_azure1" {
targets = prometheus.exporter.azure.integrations_azure1.targets

rule {
target_label = "instance"
replacement = "azure1"
}
}

prometheus.scrape "integrations_azure1" {
targets = prometheus.exporter.azure.integrations_azure1.targets
targets = discovery.relabel.integrations_azure1.output
forward_to = [prometheus.remote_write.metrics_default.receiver]
job_name = "integrations/azure1"
}
Expand All @@ -27,8 +36,17 @@ prometheus.exporter.azure "integrations_azure2" {
metrics = ["HttpRequestCount"]
}

discovery.relabel "integrations_azure2" {
targets = prometheus.exporter.azure.integrations_azure2.targets

rule {
target_label = "instance"
replacement = "azure2"
}
}

prometheus.scrape "integrations_azure2" {
targets = prometheus.exporter.azure.integrations_azure2.targets
targets = discovery.relabel.integrations_azure2.output
forward_to = [prometheus.remote_write.metrics_default.receiver]
job_name = "integrations/azure2"
}
Expand Down Expand Up @@ -409,8 +427,17 @@ prometheus.exporter.apache "integrations_apache1" {
insecure = true
}

discovery.relabel "integrations_apache1" {
targets = prometheus.exporter.apache.integrations_apache1.targets

rule {
target_label = "instance"
replacement = "apache1"
}
}

prometheus.scrape "integrations_apache1" {
targets = prometheus.exporter.apache.integrations_apache1.targets
targets = discovery.relabel.integrations_apache1.output
forward_to = [prometheus.remote_write.metrics_default.receiver]
job_name = "integrations/apache1"
}
Expand All @@ -431,6 +458,11 @@ discovery.relabel "integrations_apache2" {
target_label = "test_label_2"
replacement = "test_label_value_2"
}

rule {
target_label = "instance"
replacement = "apache2"
}
}

prometheus.scrape "integrations_apache2" {
Expand Down
16 changes: 15 additions & 1 deletion converter/internal/staticconvert/testdata/integrations.river
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,11 @@ discovery.relabel "integrations_mongodb_exporter" {
target_label = "mongodb_cluster"
replacement = "prod-cluster"
}

rule {
target_label = "instance"
replacement = "instance-key-value"
}
}

prometheus.scrape "integrations_mongodb_exporter" {
Expand All @@ -349,8 +354,17 @@ prometheus.exporter.mssql "integrations_mssql" {
connection_string = "sqlserver://<USERNAME>:<PASSWORD>@<HOST>:<PORT>"
}

discovery.relabel "integrations_mssql" {
targets = prometheus.exporter.mssql.integrations_mssql.targets

rule {
target_label = "instance"
replacement = "instance-key-value"
}
}

prometheus.scrape "integrations_mssql" {
targets = prometheus.exporter.mssql.integrations_mssql.targets
targets = discovery.relabel.integrations_mssql.output
forward_to = [prometheus.remote_write.integrations.receiver]
job_name = "integrations/mssql"

Expand Down
2 changes: 2 additions & 0 deletions converter/internal/staticconvert/testdata/integrations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ integrations:
mongodb_exporter:
enabled: true
mongodb_uri: mongodb://mongodb-a:27017
instance: 'instance-key-value'
relabel_configs:
- source_labels: [__address__]
target_label: service_name
Expand All @@ -116,6 +117,7 @@ integrations:
replacement: 'prod-cluster'
mssql:
enabled: true
instance: 'instance-key-value'
connection_string: sqlserver://<USERNAME>:<PASSWORD>@<HOST>:<PORT>
mysqld_exporter:
enabled: true
Expand Down