Skip to content

Commit

Permalink
Converter sync exporter job names (grafana#5974)
Browse files Browse the repository at this point in the history
* Wire up support for converting integrations-next configs to flow.

Include a mechanism for passing command line flags to the converter
from the old format.

Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com>

* sync job name for static to flow converter using a relabel rule

Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com>

* fix up a windows test after trying in windows locally

---------

Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com>
  • Loading branch information
erikbaranowski committed Dec 15, 2023
1 parent a215d1b commit fadf21f
Show file tree
Hide file tree
Showing 6 changed files with 478 additions and 35 deletions.
23 changes: 23 additions & 0 deletions converter/internal/staticconvert/internal/build/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ func (b *IntegrationsConfigBuilder) appendExporter(commonConfig *int_config.Comm
relabelConfigs = append(relabelConfigs, relabelConfig)
}

if relabelConfig := b.getJobRelabelConfig(name, commonConfig.RelabelConfigs); relabelConfig != nil {
relabelConfigs = append(relabelConfigs, b.getJobRelabelConfig(name, commonConfig.RelabelConfigs))
}

scrapeConfig := prom_config.DefaultScrapeConfig
scrapeConfig.JobName = b.formatJobName(name, nil)
scrapeConfig.RelabelConfigs = append(commonConfig.RelabelConfigs, relabelConfigs...)
Expand Down Expand Up @@ -309,6 +313,10 @@ func (b *IntegrationsConfigBuilder) appendExporterV2(commonConfig *common_v2.Met
relabelConfigs = append(relabelConfigs, relabelConfig)
}

if relabelConfig := b.getJobRelabelConfig(name, commonConfig.Autoscrape.RelabelConfigs); relabelConfig != nil {
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 Expand Up @@ -394,3 +402,18 @@ func (b *IntegrationsConfigBuilder) appendExporterBlock(args component.Arguments

return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.%s.%s.targets", exporterName, compLabel))
}

func (b *IntegrationsConfigBuilder) getJobRelabelConfig(name string, relabelConfigs []*relabel.Config) *relabel.Config {
// Don't add a job relabel if that label is already targeted
for _, relabelConfig := range relabelConfigs {
if relabelConfig.TargetLabel == "job" {
return nil
}
}

defaultConfig := relabel.DefaultRelabelConfig
relabelConfig := &defaultConfig
relabelConfig.TargetLabel = "job"
relabelConfig.Replacement = "integrations/" + name
return relabelConfig
}
Loading

0 comments on commit fadf21f

Please sign in to comment.