From e257a569dcc041651fa2989c670441cade720844 Mon Sep 17 00:00:00 2001 From: Erik Baranowski <39704712+erikbaranowski@users.noreply.github.com> Date: Mon, 6 Nov 2023 12:00:44 -0500 Subject: [PATCH] Converter static v2 3rd set of integrations (#5698) * wire up blackbox exporter for integrations v2 converter Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> * wire up cadvisor integration v2 for converter Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> * wire up cloudwatch exporter for integrations v2 converter Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> * wire up consul exporter for integrations v2 converter Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> * wire up dnsmasq exporter for integrations v2 converter Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> * wire up elasticsearch exporter for integrations v2 converter Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> * wire up gcp exporter for integrations v2 converter Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> * wire up github exporter for integrations v2 converter Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> * wire up kafka exporter for integrations v2 converter Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> * wire up memcached exporter for integrations v2 converter Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> * wire up mongodb exporter for integrations v2 converter Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> * wire up mssql exporter for integrations v2 exporter Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> * wire up mysql exporter for integrations v2 converter Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> * wire up node exporter for integrations v2 converter Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> * wire up oracledb exporter for integrations v2 converter Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> * wire up postgres exporter for integrations v2 converter Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> * wire up process exporter for integrations v2 converter Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> * wire up redis exporter for integrations v2 converter Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> * wire up snmp exporter for integrations v2 converter Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> * wire up snowflake exporter for integrations v2 converter Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> * wire up squid exporter for integration v2 converter Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> * wire up statsd exporter for integrations v2 converter Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> * wire up windows exporter for integrations v2 converter Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> * fix up windows test after running it in local windows --------- Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> --- .../internal/build/blackbox_exporter.go | 28 +- .../staticconvert/internal/build/builder.go | 95 +++-- .../internal/build/cadvisor_exporter.go | 13 +- .../internal/build/cloudwatch_exporter.go | 14 +- .../internal/build/consul_exporter.go | 14 +- .../internal/build/dnsmasq_exporter.go | 14 +- .../internal/build/elasticsearch_exporter.go | 14 +- .../internal/build/gcp_exporter.go | 14 +- .../internal/build/github_exporter.go | 14 +- .../internal/build/kafka_exporter.go | 14 +- .../internal/build/memcached_exporter.go | 13 +- .../internal/build/mongodb_exporter.go | 14 +- .../internal/build/mssql_exporter.go | 14 +- .../internal/build/mysqld_exporter.go | 14 +- .../internal/build/node_exporter.go | 11 +- .../internal/build/oracledb_exporter.go | 14 +- .../internal/build/postgres_exporter.go | 14 +- .../internal/build/process_exporter.go | 14 +- .../internal/build/redis_exporter.go | 14 +- .../internal/build/snmp_exporter.go | 60 ++- .../internal/build/snowflake_exporter.go | 14 +- .../internal/build/squid_exporter.go | 14 +- .../internal/build/statsd_exporter.go | 13 +- .../internal/build/windows_exporter.go | 14 +- .../staticconvert/staticconvert_test.go | 1 + .../testdata-v2/integrations_v2.river | 386 ++++++++++++++++++ .../testdata-v2/integrations_v2.yaml | 175 +++++++- .../testdata-v2_windows/integrations_v2.diags | 1 + .../testdata-v2_windows/integrations_v2.river | 24 ++ .../testdata-v2_windows/integrations_v2.yaml | 11 + .../staticconvert/testdata/integrations.river | 4 +- converter/internal/staticconvert/validate.go | 25 ++ .../v2/blackbox_exporter/blackbox_exporter.go | 20 +- 33 files changed, 824 insertions(+), 294 deletions(-) create mode 100644 converter/internal/staticconvert/testdata-v2_windows/integrations_v2.diags create mode 100644 converter/internal/staticconvert/testdata-v2_windows/integrations_v2.river create mode 100644 converter/internal/staticconvert/testdata-v2_windows/integrations_v2.yaml diff --git a/converter/internal/staticconvert/internal/build/blackbox_exporter.go b/converter/internal/staticconvert/internal/build/blackbox_exporter.go index 5ab772e8ee60..5282f9440b34 100644 --- a/converter/internal/staticconvert/internal/build/blackbox_exporter.go +++ b/converter/internal/staticconvert/internal/build/blackbox_exporter.go @@ -1,26 +1,19 @@ package build import ( - "fmt" "time" "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/blackbox" "github.com/grafana/agent/converter/internal/common" "github.com/grafana/agent/pkg/integrations/blackbox_exporter" + blackbox_exporter_v2 "github.com/grafana/agent/pkg/integrations/v2/blackbox_exporter" "github.com/grafana/river/rivertypes" ) func (b *IntegrationsConfigBuilder) appendBlackboxExporter(config *blackbox_exporter.Config) discovery.Exports { args := toBlackboxExporter(config) - compLabel := common.LabelForParts(b.globalCtx.LabelPrefix, config.Name()) - b.f.Body().AppendBlock(common.NewBlockWithOverride( - []string{"prometheus", "exporter", "blackbox"}, - compLabel, - args, - )) - - return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.blackbox.%s.targets", compLabel)) + return b.appendExporterBlock(args, config.Name(), nil, "blackbox") } func toBlackboxExporter(config *blackbox_exporter.Config) *blackbox.Arguments { @@ -35,6 +28,23 @@ func toBlackboxExporter(config *blackbox_exporter.Config) *blackbox.Arguments { } } +func (b *IntegrationsConfigBuilder) appendBlackboxExporterV2(config *blackbox_exporter_v2.Config) discovery.Exports { + args := toBlackboxExporterV2(config) + return b.appendExporterBlock(args, config.Name(), config.Common.InstanceKey, "blackbox") +} + +func toBlackboxExporterV2(config *blackbox_exporter_v2.Config) *blackbox.Arguments { + return &blackbox.Arguments{ + ConfigFile: config.BlackboxConfigFile, + Config: rivertypes.OptionalSecret{ + IsSecret: false, + Value: string(config.BlackboxConfig), + }, + Targets: toBlackboxTargets(config.BlackboxTargets), + ProbeTimeoutOffset: time.Duration(config.ProbeTimeoutOffset), + } +} + func toBlackboxTargets(blackboxTargets []blackbox_exporter.BlackboxTarget) blackbox.TargetBlock { var targetBlock blackbox.TargetBlock diff --git a/converter/internal/staticconvert/internal/build/builder.go b/converter/internal/staticconvert/internal/build/builder.go index 5a0c19a90f3a..07a2b7a000ce 100644 --- a/converter/internal/staticconvert/internal/build/builder.go +++ b/converter/internal/staticconvert/internal/build/builder.go @@ -39,8 +39,10 @@ import ( "github.com/grafana/agent/pkg/integrations/statsd_exporter" agent_exporter_v2 "github.com/grafana/agent/pkg/integrations/v2/agent" apache_exporter_v2 "github.com/grafana/agent/pkg/integrations/v2/apache_http" + blackbox_exporter_v2 "github.com/grafana/agent/pkg/integrations/v2/blackbox_exporter" common_v2 "github.com/grafana/agent/pkg/integrations/v2/common" "github.com/grafana/agent/pkg/integrations/v2/metricsutils" + snmp_exporter_v2 "github.com/grafana/agent/pkg/integrations/v2/snmp_exporter" "github.com/grafana/agent/pkg/integrations/windows_exporter" "github.com/grafana/river/scanner" "github.com/grafana/river/token/builder" @@ -105,53 +107,53 @@ func (b *IntegrationsConfigBuilder) appendV1Integrations() { case *apache_http.Config: exports = b.appendApacheExporter(itg) case *node_exporter.Config: - exports = b.appendNodeExporter(itg) + exports = b.appendNodeExporter(itg, nil) case *blackbox_exporter.Config: exports = b.appendBlackboxExporter(itg) case *cloudwatch_exporter.Config: - exports = b.appendCloudwatchExporter(itg) + exports = b.appendCloudwatchExporter(itg, nil) case *consul_exporter.Config: - exports = b.appendConsulExporter(itg) + exports = b.appendConsulExporter(itg, nil) case *dnsmasq_exporter.Config: - exports = b.appendDnsmasqExporter(itg) + exports = b.appendDnsmasqExporter(itg, nil) case *elasticsearch_exporter.Config: - exports = b.appendElasticsearchExporter(itg) + exports = b.appendElasticsearchExporter(itg, nil) case *gcp_exporter.Config: - exports = b.appendGcpExporter(itg) + exports = b.appendGcpExporter(itg, nil) case *github_exporter.Config: - exports = b.appendGithubExporter(itg) + exports = b.appendGithubExporter(itg, nil) case *kafka_exporter.Config: - exports = b.appendKafkaExporter(itg) + exports = b.appendKafkaExporter(itg, nil) case *memcached_exporter.Config: - exports = b.appendMemcachedExporter(itg) + exports = b.appendMemcachedExporter(itg, nil) case *mongodb_exporter.Config: - exports = b.appendMongodbExporter(itg) + exports = b.appendMongodbExporter(itg, nil) case *mssql_exporter.Config: - exports = b.appendMssqlExporter(itg) + exports = b.appendMssqlExporter(itg, nil) case *mysqld_exporter.Config: - exports = b.appendMysqldExporter(itg) + exports = b.appendMysqldExporter(itg, nil) case *oracledb_exporter.Config: - exports = b.appendOracledbExporter(itg) + exports = b.appendOracledbExporter(itg, nil) case *postgres_exporter.Config: - exports = b.appendPostgresExporter(itg) + exports = b.appendPostgresExporter(itg, nil) case *process_exporter.Config: - exports = b.appendProcessExporter(itg) + exports = b.appendProcessExporter(itg, nil) case *redis_exporter.Config: - exports = b.appendRedisExporter(itg) + exports = b.appendRedisExporter(itg, nil) case *snmp_exporter.Config: exports = b.appendSnmpExporter(itg) case *snowflake_exporter.Config: - exports = b.appendSnowflakeExporter(itg) + exports = b.appendSnowflakeExporter(itg, nil) case *squid_exporter.Config: - exports = b.appendSquidExporter(itg) + exports = b.appendSquidExporter(itg, nil) case *statsd_exporter.Config: - exports = b.appendStatsdExporter(itg) + exports = b.appendStatsdExporter(itg, nil) case *windows_exporter.Config: - exports = b.appendWindowsExporter(itg) + exports = b.appendWindowsExporter(itg, nil) case *azure_exporter.Config: exports = b.appendAzureExporter(itg, nil) case *cadvisor.Config: - exports = b.appendCadvisorExporter(itg) + exports = b.appendCadvisorExporter(itg, nil) } if len(exports.Targets) > 0 { @@ -205,11 +207,59 @@ func (b *IntegrationsConfigBuilder) appendV2Integrations() { case *apache_exporter_v2.Config: exports = b.appendApacheExporterV2(itg) commonConfig = itg.Common + case *blackbox_exporter_v2.Config: + exports = b.appendBlackboxExporterV2(itg) + commonConfig = itg.Common + case *snmp_exporter_v2.Config: + exports = b.appendSnmpExporterV2(itg) + commonConfig = itg.Common case *metricsutils.ConfigShim: commonConfig = itg.Common switch v1_itg := itg.Orig.(type) { case *azure_exporter.Config: exports = b.appendAzureExporter(v1_itg, itg.Common.InstanceKey) + case *cadvisor.Config: + exports = b.appendCadvisorExporter(v1_itg, itg.Common.InstanceKey) + case *cloudwatch_exporter.Config: + exports = b.appendCloudwatchExporter(v1_itg, itg.Common.InstanceKey) + case *consul_exporter.Config: + exports = b.appendConsulExporter(v1_itg, itg.Common.InstanceKey) + case *dnsmasq_exporter.Config: + exports = b.appendDnsmasqExporter(v1_itg, itg.Common.InstanceKey) + case *elasticsearch_exporter.Config: + exports = b.appendElasticsearchExporter(v1_itg, itg.Common.InstanceKey) + case *gcp_exporter.Config: + exports = b.appendGcpExporter(v1_itg, itg.Common.InstanceKey) + case *github_exporter.Config: + exports = b.appendGithubExporter(v1_itg, itg.Common.InstanceKey) + case *kafka_exporter.Config: + exports = b.appendKafkaExporter(v1_itg, itg.Common.InstanceKey) + case *memcached_exporter.Config: + exports = b.appendMemcachedExporter(v1_itg, itg.Common.InstanceKey) + case *mongodb_exporter.Config: + exports = b.appendMongodbExporter(v1_itg, itg.Common.InstanceKey) + case *mssql_exporter.Config: + exports = b.appendMssqlExporter(v1_itg, itg.Common.InstanceKey) + case *mysqld_exporter.Config: + exports = b.appendMysqldExporter(v1_itg, itg.Common.InstanceKey) + case *node_exporter.Config: + exports = b.appendNodeExporter(v1_itg, itg.Common.InstanceKey) + case *oracledb_exporter.Config: + exports = b.appendOracledbExporter(v1_itg, itg.Common.InstanceKey) + case *postgres_exporter.Config: + exports = b.appendPostgresExporter(v1_itg, itg.Common.InstanceKey) + case *process_exporter.Config: + exports = b.appendProcessExporter(v1_itg, itg.Common.InstanceKey) + case *redis_exporter.Config: + exports = b.appendRedisExporter(v1_itg, itg.Common.InstanceKey) + case *snowflake_exporter.Config: + exports = b.appendSnowflakeExporter(v1_itg, itg.Common.InstanceKey) + case *squid_exporter.Config: + exports = b.appendSquidExporter(v1_itg, itg.Common.InstanceKey) + case *statsd_exporter.Config: + exports = b.appendStatsdExporter(v1_itg, itg.Common.InstanceKey) + case *windows_exporter.Config: + exports = b.appendWindowsExporter(v1_itg, itg.Common.InstanceKey) } } @@ -235,11 +285,10 @@ func (b *IntegrationsConfigBuilder) appendExporterV2(commonConfig *common_v2.Met commonConfig.ApplyDefaults(b.cfg.Integrations.ConfigV2.Metrics.Autoscrape) scrapeConfig := prom_config.DefaultScrapeConfig scrapeConfig.JobName = b.formatJobName(name, commonConfig.InstanceKey) - scrapeConfig.RelabelConfigs = commonConfig.Autoscrape.RelabelConfigs + scrapeConfig.RelabelConfigs = append(commonConfig.Autoscrape.RelabelConfigs, relabelConfigs...) scrapeConfig.MetricRelabelConfigs = commonConfig.Autoscrape.MetricRelabelConfigs scrapeConfig.ScrapeInterval = commonConfig.Autoscrape.ScrapeInterval scrapeConfig.ScrapeTimeout = commonConfig.Autoscrape.ScrapeTimeout - scrapeConfig.RelabelConfigs = relabelConfigs scrapeConfigs := []*prom_config.ScrapeConfig{&scrapeConfig} diff --git a/converter/internal/staticconvert/internal/build/cadvisor_exporter.go b/converter/internal/staticconvert/internal/build/cadvisor_exporter.go index 04d414c14cd0..dbedebfb2967 100644 --- a/converter/internal/staticconvert/internal/build/cadvisor_exporter.go +++ b/converter/internal/staticconvert/internal/build/cadvisor_exporter.go @@ -1,25 +1,16 @@ package build import ( - "fmt" "time" "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/cadvisor" - "github.com/grafana/agent/converter/internal/common" cadvisor_integration "github.com/grafana/agent/pkg/integrations/cadvisor" ) -func (b *IntegrationsConfigBuilder) appendCadvisorExporter(config *cadvisor_integration.Config) discovery.Exports { +func (b *IntegrationsConfigBuilder) appendCadvisorExporter(config *cadvisor_integration.Config, instanceKey *string) discovery.Exports { args := toCadvisorExporter(config) - compLabel := common.LabelForParts(b.globalCtx.LabelPrefix, config.Name()) - b.f.Body().AppendBlock(common.NewBlockWithOverride( - []string{"prometheus", "exporter", "cadvisor"}, - compLabel, - args, - )) - - return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.cadvisor.%s.targets", compLabel)) + return b.appendExporterBlock(args, config.Name(), instanceKey, "cadvisor") } func toCadvisorExporter(config *cadvisor_integration.Config) *cadvisor.Arguments { diff --git a/converter/internal/staticconvert/internal/build/cloudwatch_exporter.go b/converter/internal/staticconvert/internal/build/cloudwatch_exporter.go index 2afdd0170756..0d13d8a1c53d 100644 --- a/converter/internal/staticconvert/internal/build/cloudwatch_exporter.go +++ b/converter/internal/staticconvert/internal/build/cloudwatch_exporter.go @@ -1,24 +1,14 @@ package build import ( - "fmt" - "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/cloudwatch" - "github.com/grafana/agent/converter/internal/common" "github.com/grafana/agent/pkg/integrations/cloudwatch_exporter" ) -func (b *IntegrationsConfigBuilder) appendCloudwatchExporter(config *cloudwatch_exporter.Config) discovery.Exports { +func (b *IntegrationsConfigBuilder) appendCloudwatchExporter(config *cloudwatch_exporter.Config, instanceKey *string) discovery.Exports { args := toCloudwatchExporter(config) - compLabel := common.LabelForParts(b.globalCtx.LabelPrefix, config.Name()) - b.f.Body().AppendBlock(common.NewBlockWithOverride( - []string{"prometheus", "exporter", "cloudwatch"}, - compLabel, - args, - )) - - return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.cloudwatch.%s.targets", compLabel)) + return b.appendExporterBlock(args, config.Name(), instanceKey, "cloudwatch") } func toCloudwatchExporter(config *cloudwatch_exporter.Config) *cloudwatch.Arguments { diff --git a/converter/internal/staticconvert/internal/build/consul_exporter.go b/converter/internal/staticconvert/internal/build/consul_exporter.go index 3b6ba2f74018..89d0221ff400 100644 --- a/converter/internal/staticconvert/internal/build/consul_exporter.go +++ b/converter/internal/staticconvert/internal/build/consul_exporter.go @@ -1,24 +1,14 @@ package build import ( - "fmt" - "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/consul" - "github.com/grafana/agent/converter/internal/common" "github.com/grafana/agent/pkg/integrations/consul_exporter" ) -func (b *IntegrationsConfigBuilder) appendConsulExporter(config *consul_exporter.Config) discovery.Exports { +func (b *IntegrationsConfigBuilder) appendConsulExporter(config *consul_exporter.Config, instanceKey *string) discovery.Exports { args := toConsulExporter(config) - compLabel := common.LabelForParts(b.globalCtx.LabelPrefix, config.Name()) - b.f.Body().AppendBlock(common.NewBlockWithOverride( - []string{"prometheus", "exporter", "consul"}, - compLabel, - args, - )) - - return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.consul.%s.targets", compLabel)) + return b.appendExporterBlock(args, config.Name(), instanceKey, "consul") } func toConsulExporter(config *consul_exporter.Config) *consul.Arguments { diff --git a/converter/internal/staticconvert/internal/build/dnsmasq_exporter.go b/converter/internal/staticconvert/internal/build/dnsmasq_exporter.go index df46fe453987..fa2a5e43a9bf 100644 --- a/converter/internal/staticconvert/internal/build/dnsmasq_exporter.go +++ b/converter/internal/staticconvert/internal/build/dnsmasq_exporter.go @@ -1,24 +1,14 @@ package build import ( - "fmt" - "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/dnsmasq" - "github.com/grafana/agent/converter/internal/common" "github.com/grafana/agent/pkg/integrations/dnsmasq_exporter" ) -func (b *IntegrationsConfigBuilder) appendDnsmasqExporter(config *dnsmasq_exporter.Config) discovery.Exports { +func (b *IntegrationsConfigBuilder) appendDnsmasqExporter(config *dnsmasq_exporter.Config, instanceKey *string) discovery.Exports { args := toDnsmasqExporter(config) - compLabel := common.LabelForParts(b.globalCtx.LabelPrefix, config.Name()) - b.f.Body().AppendBlock(common.NewBlockWithOverride( - []string{"prometheus", "exporter", "dnsmasq"}, - compLabel, - args, - )) - - return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.dnsmasq.%s.targets", compLabel)) + return b.appendExporterBlock(args, config.Name(), instanceKey, "dnsmasq") } func toDnsmasqExporter(config *dnsmasq_exporter.Config) *dnsmasq.Arguments { diff --git a/converter/internal/staticconvert/internal/build/elasticsearch_exporter.go b/converter/internal/staticconvert/internal/build/elasticsearch_exporter.go index 6d874048dba2..97022a1f182f 100644 --- a/converter/internal/staticconvert/internal/build/elasticsearch_exporter.go +++ b/converter/internal/staticconvert/internal/build/elasticsearch_exporter.go @@ -1,24 +1,14 @@ package build import ( - "fmt" - "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/elasticsearch" - "github.com/grafana/agent/converter/internal/common" "github.com/grafana/agent/pkg/integrations/elasticsearch_exporter" ) -func (b *IntegrationsConfigBuilder) appendElasticsearchExporter(config *elasticsearch_exporter.Config) discovery.Exports { +func (b *IntegrationsConfigBuilder) appendElasticsearchExporter(config *elasticsearch_exporter.Config, instanceKey *string) discovery.Exports { args := toElasticsearchExporter(config) - compLabel := common.LabelForParts(b.globalCtx.LabelPrefix, config.Name()) - b.f.Body().AppendBlock(common.NewBlockWithOverride( - []string{"prometheus", "exporter", "elasticsearch"}, - compLabel, - args, - )) - - return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.elasticsearch.%s.targets", compLabel)) + return b.appendExporterBlock(args, config.Name(), instanceKey, "elasticsearch") } func toElasticsearchExporter(config *elasticsearch_exporter.Config) *elasticsearch.Arguments { diff --git a/converter/internal/staticconvert/internal/build/gcp_exporter.go b/converter/internal/staticconvert/internal/build/gcp_exporter.go index 954b67943210..a864c416fae7 100644 --- a/converter/internal/staticconvert/internal/build/gcp_exporter.go +++ b/converter/internal/staticconvert/internal/build/gcp_exporter.go @@ -1,24 +1,14 @@ package build import ( - "fmt" - "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/gcp" - "github.com/grafana/agent/converter/internal/common" "github.com/grafana/agent/pkg/integrations/gcp_exporter" ) -func (b *IntegrationsConfigBuilder) appendGcpExporter(config *gcp_exporter.Config) discovery.Exports { +func (b *IntegrationsConfigBuilder) appendGcpExporter(config *gcp_exporter.Config, instanceKey *string) discovery.Exports { args := toGcpExporter(config) - compLabel := common.LabelForParts(b.globalCtx.LabelPrefix, config.Name()) - b.f.Body().AppendBlock(common.NewBlockWithOverride( - []string{"prometheus", "exporter", "gcp"}, - compLabel, - args, - )) - - return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.gcp.%s.targets", compLabel)) + return b.appendExporterBlock(args, config.Name(), instanceKey, "gcp") } func toGcpExporter(config *gcp_exporter.Config) *gcp.Arguments { diff --git a/converter/internal/staticconvert/internal/build/github_exporter.go b/converter/internal/staticconvert/internal/build/github_exporter.go index d2b228de38a0..4fcc4d4e0e10 100644 --- a/converter/internal/staticconvert/internal/build/github_exporter.go +++ b/converter/internal/staticconvert/internal/build/github_exporter.go @@ -1,25 +1,15 @@ package build import ( - "fmt" - "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/github" - "github.com/grafana/agent/converter/internal/common" "github.com/grafana/agent/pkg/integrations/github_exporter" "github.com/grafana/river/rivertypes" ) -func (b *IntegrationsConfigBuilder) appendGithubExporter(config *github_exporter.Config) discovery.Exports { +func (b *IntegrationsConfigBuilder) appendGithubExporter(config *github_exporter.Config, instanceKey *string) discovery.Exports { args := toGithubExporter(config) - compLabel := common.LabelForParts(b.globalCtx.LabelPrefix, config.Name()) - b.f.Body().AppendBlock(common.NewBlockWithOverride( - []string{"prometheus", "exporter", "github"}, - compLabel, - args, - )) - - return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.github.%s.targets", compLabel)) + return b.appendExporterBlock(args, config.Name(), instanceKey, "github") } func toGithubExporter(config *github_exporter.Config) *github.Arguments { diff --git a/converter/internal/staticconvert/internal/build/kafka_exporter.go b/converter/internal/staticconvert/internal/build/kafka_exporter.go index cf47bba409ff..25310e35a5f4 100644 --- a/converter/internal/staticconvert/internal/build/kafka_exporter.go +++ b/converter/internal/staticconvert/internal/build/kafka_exporter.go @@ -1,24 +1,14 @@ package build import ( - "fmt" - "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/kafka" - "github.com/grafana/agent/converter/internal/common" "github.com/grafana/agent/pkg/integrations/kafka_exporter" ) -func (b *IntegrationsConfigBuilder) appendKafkaExporter(config *kafka_exporter.Config) discovery.Exports { +func (b *IntegrationsConfigBuilder) appendKafkaExporter(config *kafka_exporter.Config, instanceKey *string) discovery.Exports { args := toKafkaExporter(config) - compLabel := common.LabelForParts(b.globalCtx.LabelPrefix, config.Name()) - b.f.Body().AppendBlock(common.NewBlockWithOverride( - []string{"prometheus", "exporter", "kafka"}, - compLabel, - args, - )) - - return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.kafka.%s.targets", compLabel)) + return b.appendExporterBlock(args, config.Name(), instanceKey, "kafka") } func toKafkaExporter(config *kafka_exporter.Config) *kafka.Arguments { diff --git a/converter/internal/staticconvert/internal/build/memcached_exporter.go b/converter/internal/staticconvert/internal/build/memcached_exporter.go index a9f179c04b4a..e43afdb7d4c0 100644 --- a/converter/internal/staticconvert/internal/build/memcached_exporter.go +++ b/converter/internal/staticconvert/internal/build/memcached_exporter.go @@ -1,24 +1,15 @@ package build import ( - "fmt" - "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/memcached" "github.com/grafana/agent/converter/internal/common" "github.com/grafana/agent/pkg/integrations/memcached_exporter" ) -func (b *IntegrationsConfigBuilder) appendMemcachedExporter(config *memcached_exporter.Config) discovery.Exports { +func (b *IntegrationsConfigBuilder) appendMemcachedExporter(config *memcached_exporter.Config, instanceKey *string) discovery.Exports { args := toMemcachedExporter(config) - compLabel := common.LabelForParts(b.globalCtx.LabelPrefix, config.Name()) - b.f.Body().AppendBlock(common.NewBlockWithOverride( - []string{"prometheus", "exporter", "memcached"}, - compLabel, - args, - )) - - return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.memcached.%s.targets", compLabel)) + return b.appendExporterBlock(args, config.Name(), instanceKey, "memcached") } func toMemcachedExporter(config *memcached_exporter.Config) *memcached.Arguments { diff --git a/converter/internal/staticconvert/internal/build/mongodb_exporter.go b/converter/internal/staticconvert/internal/build/mongodb_exporter.go index 88b2e075be92..59e7da771809 100644 --- a/converter/internal/staticconvert/internal/build/mongodb_exporter.go +++ b/converter/internal/staticconvert/internal/build/mongodb_exporter.go @@ -1,25 +1,15 @@ package build import ( - "fmt" - "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/mongodb" - "github.com/grafana/agent/converter/internal/common" "github.com/grafana/agent/pkg/integrations/mongodb_exporter" "github.com/grafana/river/rivertypes" ) -func (b *IntegrationsConfigBuilder) appendMongodbExporter(config *mongodb_exporter.Config) discovery.Exports { +func (b *IntegrationsConfigBuilder) appendMongodbExporter(config *mongodb_exporter.Config, instanceKey *string) discovery.Exports { args := toMongodbExporter(config) - compLabel := common.LabelForParts(b.globalCtx.LabelPrefix, config.Name()) - b.f.Body().AppendBlock(common.NewBlockWithOverride( - []string{"prometheus", "exporter", "mongodb"}, - compLabel, - args, - )) - - return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.mongodb.%s.targets", compLabel)) + return b.appendExporterBlock(args, config.Name(), instanceKey, "mongodb") } func toMongodbExporter(config *mongodb_exporter.Config) *mongodb.Arguments { diff --git a/converter/internal/staticconvert/internal/build/mssql_exporter.go b/converter/internal/staticconvert/internal/build/mssql_exporter.go index 8615d6c74182..f6154a65c913 100644 --- a/converter/internal/staticconvert/internal/build/mssql_exporter.go +++ b/converter/internal/staticconvert/internal/build/mssql_exporter.go @@ -1,25 +1,15 @@ package build import ( - "fmt" - "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/mssql" - "github.com/grafana/agent/converter/internal/common" mssql_exporter "github.com/grafana/agent/pkg/integrations/mssql" "github.com/grafana/river/rivertypes" ) -func (b *IntegrationsConfigBuilder) appendMssqlExporter(config *mssql_exporter.Config) discovery.Exports { +func (b *IntegrationsConfigBuilder) appendMssqlExporter(config *mssql_exporter.Config, instanceKey *string) discovery.Exports { args := toMssqlExporter(config) - compLabel := common.LabelForParts(b.globalCtx.LabelPrefix, config.Name()) - b.f.Body().AppendBlock(common.NewBlockWithOverride( - []string{"prometheus", "exporter", "mssql"}, - compLabel, - args, - )) - - return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.mssql.%s.targets", compLabel)) + return b.appendExporterBlock(args, config.Name(), instanceKey, "mssql") } func toMssqlExporter(config *mssql_exporter.Config) *mssql.Arguments { diff --git a/converter/internal/staticconvert/internal/build/mysqld_exporter.go b/converter/internal/staticconvert/internal/build/mysqld_exporter.go index 52d6670be9dd..51b3a20a8dcc 100644 --- a/converter/internal/staticconvert/internal/build/mysqld_exporter.go +++ b/converter/internal/staticconvert/internal/build/mysqld_exporter.go @@ -1,25 +1,15 @@ package build import ( - "fmt" - "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/mysql" - "github.com/grafana/agent/converter/internal/common" "github.com/grafana/agent/pkg/integrations/mysqld_exporter" "github.com/grafana/river/rivertypes" ) -func (b *IntegrationsConfigBuilder) appendMysqldExporter(config *mysqld_exporter.Config) discovery.Exports { +func (b *IntegrationsConfigBuilder) appendMysqldExporter(config *mysqld_exporter.Config, instanceKey *string) discovery.Exports { args := toMysqldExporter(config) - compLabel := common.LabelForParts(b.globalCtx.LabelPrefix, config.Name()) - b.f.Body().AppendBlock(common.NewBlockWithOverride( - []string{"prometheus", "exporter", "mysql"}, - compLabel, - args, - )) - - return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.mysql.%s.targets", compLabel)) + return b.appendExporterBlock(args, config.Name(), instanceKey, "mysql") } func toMysqldExporter(config *mysqld_exporter.Config) *mysql.Arguments { diff --git a/converter/internal/staticconvert/internal/build/node_exporter.go b/converter/internal/staticconvert/internal/build/node_exporter.go index 9fad26b460ff..3e896d3b1013 100644 --- a/converter/internal/staticconvert/internal/build/node_exporter.go +++ b/converter/internal/staticconvert/internal/build/node_exporter.go @@ -3,19 +3,12 @@ package build import ( "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/unix" - "github.com/grafana/agent/converter/internal/common" "github.com/grafana/agent/pkg/integrations/node_exporter" ) -func (b *IntegrationsConfigBuilder) appendNodeExporter(config *node_exporter.Config) discovery.Exports { +func (b *IntegrationsConfigBuilder) appendNodeExporter(config *node_exporter.Config, instanceKey *string) discovery.Exports { args := toNodeExporter(config) - b.f.Body().AppendBlock(common.NewBlockWithOverride( - []string{"prometheus", "exporter", "unix"}, - "default", - args, - )) - - return common.NewDiscoveryExports("prometheus.exporter.unix.default.targets") + return b.appendExporterBlock(args, config.Name(), instanceKey, "unix") } func toNodeExporter(config *node_exporter.Config) *unix.Arguments { diff --git a/converter/internal/staticconvert/internal/build/oracledb_exporter.go b/converter/internal/staticconvert/internal/build/oracledb_exporter.go index e1ad64c2404a..c786bd3b2d5d 100644 --- a/converter/internal/staticconvert/internal/build/oracledb_exporter.go +++ b/converter/internal/staticconvert/internal/build/oracledb_exporter.go @@ -1,25 +1,15 @@ package build import ( - "fmt" - "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/oracledb" - "github.com/grafana/agent/converter/internal/common" "github.com/grafana/agent/pkg/integrations/oracledb_exporter" "github.com/grafana/river/rivertypes" ) -func (b *IntegrationsConfigBuilder) appendOracledbExporter(config *oracledb_exporter.Config) discovery.Exports { +func (b *IntegrationsConfigBuilder) appendOracledbExporter(config *oracledb_exporter.Config, instanceKey *string) discovery.Exports { args := toOracledbExporter(config) - compLabel := common.LabelForParts(b.globalCtx.LabelPrefix, config.Name()) - b.f.Body().AppendBlock(common.NewBlockWithOverride( - []string{"prometheus", "exporter", "oracledb"}, - compLabel, - args, - )) - - return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.oracledb.%s.targets", compLabel)) + return b.appendExporterBlock(args, config.Name(), instanceKey, "oracledb") } func toOracledbExporter(config *oracledb_exporter.Config) *oracledb.Arguments { diff --git a/converter/internal/staticconvert/internal/build/postgres_exporter.go b/converter/internal/staticconvert/internal/build/postgres_exporter.go index 863999bdadb8..2fe110311011 100644 --- a/converter/internal/staticconvert/internal/build/postgres_exporter.go +++ b/converter/internal/staticconvert/internal/build/postgres_exporter.go @@ -1,25 +1,15 @@ package build import ( - "fmt" - "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/postgres" - "github.com/grafana/agent/converter/internal/common" "github.com/grafana/agent/pkg/integrations/postgres_exporter" "github.com/grafana/river/rivertypes" ) -func (b *IntegrationsConfigBuilder) appendPostgresExporter(config *postgres_exporter.Config) discovery.Exports { +func (b *IntegrationsConfigBuilder) appendPostgresExporter(config *postgres_exporter.Config, instanceKey *string) discovery.Exports { args := toPostgresExporter(config) - compLabel := common.LabelForParts(b.globalCtx.LabelPrefix, config.Name()) - b.f.Body().AppendBlock(common.NewBlockWithOverride( - []string{"prometheus", "exporter", "postgres"}, - compLabel, - args, - )) - - return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.postgres.%s.targets", compLabel)) + return b.appendExporterBlock(args, config.Name(), instanceKey, "postgres") } func toPostgresExporter(config *postgres_exporter.Config) *postgres.Arguments { diff --git a/converter/internal/staticconvert/internal/build/process_exporter.go b/converter/internal/staticconvert/internal/build/process_exporter.go index 2172865c2c0c..1224deca7849 100644 --- a/converter/internal/staticconvert/internal/build/process_exporter.go +++ b/converter/internal/staticconvert/internal/build/process_exporter.go @@ -1,24 +1,14 @@ package build import ( - "fmt" - "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/process" - "github.com/grafana/agent/converter/internal/common" "github.com/grafana/agent/pkg/integrations/process_exporter" ) -func (b *IntegrationsConfigBuilder) appendProcessExporter(config *process_exporter.Config) discovery.Exports { +func (b *IntegrationsConfigBuilder) appendProcessExporter(config *process_exporter.Config, instanceKey *string) discovery.Exports { args := toProcessExporter(config) - compLabel := common.LabelForParts(b.globalCtx.LabelPrefix, config.Name()) - b.f.Body().AppendBlock(common.NewBlockWithOverride( - []string{"prometheus", "exporter", "process"}, - compLabel, - args, - )) - - return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.process.%s.targets", compLabel)) + return b.appendExporterBlock(args, config.Name(), instanceKey, "process") } func toProcessExporter(config *process_exporter.Config) *process.Arguments { diff --git a/converter/internal/staticconvert/internal/build/redis_exporter.go b/converter/internal/staticconvert/internal/build/redis_exporter.go index dc87a0293723..56e497807b9e 100644 --- a/converter/internal/staticconvert/internal/build/redis_exporter.go +++ b/converter/internal/staticconvert/internal/build/redis_exporter.go @@ -1,25 +1,15 @@ package build import ( - "fmt" - "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/redis" - "github.com/grafana/agent/converter/internal/common" "github.com/grafana/agent/pkg/integrations/redis_exporter" "github.com/grafana/river/rivertypes" ) -func (b *IntegrationsConfigBuilder) appendRedisExporter(config *redis_exporter.Config) discovery.Exports { +func (b *IntegrationsConfigBuilder) appendRedisExporter(config *redis_exporter.Config, instanceKey *string) discovery.Exports { args := toRedisExporter(config) - compLabel := common.LabelForParts(b.globalCtx.LabelPrefix, config.Name()) - b.f.Body().AppendBlock(common.NewBlockWithOverride( - []string{"prometheus", "exporter", "redis"}, - compLabel, - args, - )) - - return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.redis.%s.targets", compLabel)) + return b.appendExporterBlock(args, config.Name(), instanceKey, "redis") } func toRedisExporter(config *redis_exporter.Config) *redis.Arguments { diff --git a/converter/internal/staticconvert/internal/build/snmp_exporter.go b/converter/internal/staticconvert/internal/build/snmp_exporter.go index 6d03c27cce69..9b56c2fbd89b 100644 --- a/converter/internal/staticconvert/internal/build/snmp_exporter.go +++ b/converter/internal/staticconvert/internal/build/snmp_exporter.go @@ -1,26 +1,18 @@ package build import ( - "fmt" - "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/snmp" "github.com/grafana/agent/converter/internal/common" "github.com/grafana/agent/pkg/integrations/snmp_exporter" + snmp_exporter_v2 "github.com/grafana/agent/pkg/integrations/v2/snmp_exporter" "github.com/grafana/river/rivertypes" snmp_config "github.com/prometheus/snmp_exporter/config" ) func (b *IntegrationsConfigBuilder) appendSnmpExporter(config *snmp_exporter.Config) discovery.Exports { args := toSnmpExporter(config) - compLabel := common.LabelForParts(b.globalCtx.LabelPrefix, config.Name()) - b.f.Body().AppendBlock(common.NewBlockWithOverride( - []string{"prometheus", "exporter", "snmp"}, - compLabel, - args, - )) - - return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.snmp.%s.targets", compLabel)) + return b.appendExporterBlock(args, config.Name(), nil, "snmp") } func toSnmpExporter(config *snmp_exporter.Config) *snmp.Arguments { @@ -65,3 +57,51 @@ func toSnmpExporter(config *snmp_exporter.Config) *snmp.Arguments { }, } } + +func (b *IntegrationsConfigBuilder) appendSnmpExporterV2(config *snmp_exporter_v2.Config) discovery.Exports { + args := toSnmpExporterV2(config) + return b.appendExporterBlock(args, config.Name(), config.Common.InstanceKey, "snmp") +} + +func toSnmpExporterV2(config *snmp_exporter_v2.Config) *snmp.Arguments { + targets := make([]snmp.SNMPTarget, len(config.SnmpTargets)) + for i, t := range config.SnmpTargets { + targets[i] = snmp.SNMPTarget{ + Name: common.SanitizeIdentifierPanics(t.Name), + Target: t.Target, + Module: t.Module, + Auth: t.Auth, + WalkParams: t.WalkParams, + } + } + + walkParams := make([]snmp.WalkParam, len(config.WalkParams)) + index := 0 + for name, p := range config.WalkParams { + retries := 0 + if p.Retries != nil { + retries = *p.Retries + } + + walkParams[index] = snmp.WalkParam{ + Name: common.SanitizeIdentifierPanics(name), + MaxRepetitions: p.MaxRepetitions, + Retries: retries, + Timeout: p.Timeout, + UseUnconnectedUDPSocket: p.UseUnconnectedUDPSocket, + } + index++ + } + + return &snmp.Arguments{ + ConfigFile: config.SnmpConfigFile, + Config: rivertypes.OptionalSecret{}, + Targets: targets, + WalkParams: walkParams, + ConfigStruct: snmp_config.Config{ + Auths: config.SnmpConfig.Auths, + Modules: config.SnmpConfig.Modules, + Version: config.SnmpConfig.Version, + }, + } +} diff --git a/converter/internal/staticconvert/internal/build/snowflake_exporter.go b/converter/internal/staticconvert/internal/build/snowflake_exporter.go index 34f605564c35..ed0f10ff1c1e 100644 --- a/converter/internal/staticconvert/internal/build/snowflake_exporter.go +++ b/converter/internal/staticconvert/internal/build/snowflake_exporter.go @@ -1,25 +1,15 @@ package build import ( - "fmt" - "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/snowflake" - "github.com/grafana/agent/converter/internal/common" "github.com/grafana/agent/pkg/integrations/snowflake_exporter" "github.com/grafana/river/rivertypes" ) -func (b *IntegrationsConfigBuilder) appendSnowflakeExporter(config *snowflake_exporter.Config) discovery.Exports { +func (b *IntegrationsConfigBuilder) appendSnowflakeExporter(config *snowflake_exporter.Config, instanceKey *string) discovery.Exports { args := toSnowflakeExporter(config) - compLabel := common.LabelForParts(b.globalCtx.LabelPrefix, config.Name()) - b.f.Body().AppendBlock(common.NewBlockWithOverride( - []string{"prometheus", "exporter", "snowflake"}, - compLabel, - args, - )) - - return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.snowflake.%s.targets", compLabel)) + return b.appendExporterBlock(args, config.Name(), instanceKey, "snowflake") } func toSnowflakeExporter(config *snowflake_exporter.Config) *snowflake.Arguments { diff --git a/converter/internal/staticconvert/internal/build/squid_exporter.go b/converter/internal/staticconvert/internal/build/squid_exporter.go index c275b0dd04a6..4283f4ebe0f9 100644 --- a/converter/internal/staticconvert/internal/build/squid_exporter.go +++ b/converter/internal/staticconvert/internal/build/squid_exporter.go @@ -1,25 +1,15 @@ package build import ( - "fmt" - "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/squid" - "github.com/grafana/agent/converter/internal/common" "github.com/grafana/agent/pkg/integrations/squid_exporter" "github.com/grafana/river/rivertypes" ) -func (b *IntegrationsConfigBuilder) appendSquidExporter(config *squid_exporter.Config) discovery.Exports { +func (b *IntegrationsConfigBuilder) appendSquidExporter(config *squid_exporter.Config, instanceKey *string) discovery.Exports { args := toSquidExporter(config) - compLabel := common.LabelForParts(b.globalCtx.LabelPrefix, config.Name()) - b.f.Body().AppendBlock(common.NewBlockWithOverride( - []string{"prometheus", "exporter", "squid"}, - compLabel, - args, - )) - - return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.squid.%s.targets", compLabel)) + return b.appendExporterBlock(args, config.Name(), instanceKey, "squid") } func toSquidExporter(config *squid_exporter.Config) *squid.Arguments { diff --git a/converter/internal/staticconvert/internal/build/statsd_exporter.go b/converter/internal/staticconvert/internal/build/statsd_exporter.go index 719ce2baf73b..3756a876b8a6 100644 --- a/converter/internal/staticconvert/internal/build/statsd_exporter.go +++ b/converter/internal/staticconvert/internal/build/statsd_exporter.go @@ -1,29 +1,20 @@ package build import ( - "fmt" - "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/statsd" "github.com/grafana/agent/converter/diag" - "github.com/grafana/agent/converter/internal/common" "github.com/grafana/agent/pkg/integrations/statsd_exporter" ) -func (b *IntegrationsConfigBuilder) appendStatsdExporter(config *statsd_exporter.Config) discovery.Exports { +func (b *IntegrationsConfigBuilder) appendStatsdExporter(config *statsd_exporter.Config, instanceKey *string) discovery.Exports { args := toStatsdExporter(config) - compLabel := common.LabelForParts(b.globalCtx.LabelPrefix, config.Name()) - b.f.Body().AppendBlock(common.NewBlockWithOverride( - []string{"prometheus", "exporter", "statsd"}, - compLabel, - args, - )) if config.MappingConfig != nil { b.diags.Add(diag.SeverityLevelError, "mapping_config is not supported in statsd_exporter integrations config") } - return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.statsd.%s.targets", compLabel)) + return b.appendExporterBlock(args, config.Name(), instanceKey, "statsd") } func toStatsdExporter(config *statsd_exporter.Config) *statsd.Arguments { diff --git a/converter/internal/staticconvert/internal/build/windows_exporter.go b/converter/internal/staticconvert/internal/build/windows_exporter.go index bfd9fb771155..100a8761ccfc 100644 --- a/converter/internal/staticconvert/internal/build/windows_exporter.go +++ b/converter/internal/staticconvert/internal/build/windows_exporter.go @@ -1,24 +1,14 @@ package build import ( - "fmt" - "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/windows" - "github.com/grafana/agent/converter/internal/common" "github.com/grafana/agent/pkg/integrations/windows_exporter" ) -func (b *IntegrationsConfigBuilder) appendWindowsExporter(config *windows_exporter.Config) discovery.Exports { +func (b *IntegrationsConfigBuilder) appendWindowsExporter(config *windows_exporter.Config, instanceKey *string) discovery.Exports { args := toWindowsExporter(config) - compLabel := common.LabelForParts(b.globalCtx.LabelPrefix, config.Name()) - b.f.Body().AppendBlock(common.NewBlockWithOverride( - []string{"prometheus", "exporter", "windows"}, - compLabel, - args, - )) - - return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.windows.%s.targets", compLabel)) + return b.appendExporterBlock(args, config.Name(), instanceKey, "windows") } func toWindowsExporter(config *windows_exporter.Config) *windows.Arguments { diff --git a/converter/internal/staticconvert/staticconvert_test.go b/converter/internal/staticconvert/staticconvert_test.go index d283164e4453..f85e880b37d8 100644 --- a/converter/internal/staticconvert/staticconvert_test.go +++ b/converter/internal/staticconvert/staticconvert_test.go @@ -15,5 +15,6 @@ func TestConvert(t *testing.T) { if runtime.GOOS == "windows" { test_common.TestDirectory(t, "testdata_windows", ".yaml", true, []string{}, staticconvert.Convert) + test_common.TestDirectory(t, "testdata-v2_windows", ".yaml", true, []string{"-enable-features", "integrations-next"}, staticconvert.Convert) } } diff --git a/converter/internal/staticconvert/testdata-v2/integrations_v2.river b/converter/internal/staticconvert/testdata-v2/integrations_v2.river index c0e2acba450b..f3d134cdc79a 100644 --- a/converter/internal/staticconvert/testdata-v2/integrations_v2.river +++ b/converter/internal/staticconvert/testdata-v2/integrations_v2.river @@ -33,6 +33,354 @@ prometheus.scrape "integrations_azure2" { job_name = "integrations/azure2" } +prometheus.exporter.cadvisor "integrations_cadvisor" { + store_container_labels = false +} + +prometheus.scrape "integrations_cadvisor" { + targets = prometheus.exporter.cadvisor.integrations_cadvisor.targets + forward_to = [prometheus.remote_write.metrics_default.receiver] + job_name = "integrations/cadvisor" +} + +prometheus.exporter.cloudwatch "integrations_cloudwatch_exporter" { + sts_region = "us-east-2" + fips_disabled = false + + discovery { + regions = ["us-east-2"] + custom_tags = {} + search_tags = {} + type = "AWS/EC2" + + metric { + name = "CPUUtilization" + statistics = ["Average"] + period = "5m0s" + nil_to_zero = false + } + + metric { + name = "NetworkPacketsIn" + statistics = ["Average"] + period = "5m0s" + } + nil_to_zero = true + } + + static "single_ec2_instance" { + regions = ["us-east-2"] + custom_tags = {} + namespace = "AWS/EC2" + dimensions = { + InstanceId = "i-0e43cee369aa44b52", + } + + metric { + name = "CPUUtilization" + statistics = ["Average"] + period = "5m0s" + nil_to_zero = false + } + + metric { + name = "NetworkPacketsIn" + statistics = ["Average"] + period = "5m0s" + } + nil_to_zero = true + } + + decoupled_scraping { } +} + +prometheus.scrape "integrations_cloudwatch" { + targets = prometheus.exporter.cloudwatch.integrations_cloudwatch_exporter.targets + forward_to = [prometheus.remote_write.metrics_default.receiver] + job_name = "integrations/cloudwatch" +} + +prometheus.exporter.consul "integrations_consul_exporter" { } + +prometheus.scrape "integrations_consul" { + targets = prometheus.exporter.consul.integrations_consul_exporter.targets + forward_to = [prometheus.remote_write.metrics_default.receiver] + job_name = "integrations/consul" +} + +prometheus.exporter.dnsmasq "integrations_dnsmasq_exporter" { + address = "dnsmasq-a:53" +} + +discovery.relabel "integrations_dnsmasq" { + targets = prometheus.exporter.dnsmasq.integrations_dnsmasq_exporter.targets + + rule { + source_labels = ["__address__"] + target_label = "instance" + replacement = "dnsmasq-a" + } +} + +prometheus.scrape "integrations_dnsmasq" { + targets = discovery.relabel.integrations_dnsmasq.output + forward_to = [prometheus.remote_write.metrics_default.receiver] + job_name = "integrations/dnsmasq" +} + +prometheus.exporter.elasticsearch "integrations_elasticsearch_exporter" { } + +prometheus.scrape "integrations_elasticsearch" { + targets = prometheus.exporter.elasticsearch.integrations_elasticsearch_exporter.targets + forward_to = [prometheus.remote_write.metrics_default.receiver] + job_name = "integrations/elasticsearch" +} + +prometheus.exporter.gcp "integrations_gcp_exporter" { + project_ids = [""] + metrics_prefixes = ["loadbalancing.googleapis.com/https/request_bytes_count", "loadbalancing.googleapis.com/https/total_latencies"] + extra_filters = ["loadbalancing.googleapis.com:resource.labels.backend_target_name=\"sample-value\""] +} + +prometheus.scrape "integrations_gcp" { + targets = prometheus.exporter.gcp.integrations_gcp_exporter.targets + forward_to = [prometheus.remote_write.metrics_default.receiver] + job_name = "integrations/gcp" +} + +prometheus.exporter.github "integrations_github_exporter" { + repositories = ["grafana/agent", "grafana/agent-modules"] + api_token = "ABCDEFGH-1234-ABCD-1234-ABCDEFGHIJKL" +} + +prometheus.scrape "integrations_github" { + targets = prometheus.exporter.github.integrations_github_exporter.targets + forward_to = [prometheus.remote_write.metrics_default.receiver] + job_name = "integrations/github" +} + +prometheus.exporter.kafka "integrations_kafka_exporter" { } + +prometheus.scrape "integrations_kafka" { + targets = prometheus.exporter.kafka.integrations_kafka_exporter.targets + forward_to = [prometheus.remote_write.metrics_default.receiver] + job_name = "integrations/kafka" +} + +prometheus.exporter.memcached "integrations_memcached_exporter" { + address = "memcached-a:53" +} + +discovery.relabel "integrations_memcached" { + targets = prometheus.exporter.memcached.integrations_memcached_exporter.targets + + rule { + source_labels = ["__address__"] + target_label = "instance" + replacement = "memcached-a" + } +} + +prometheus.scrape "integrations_memcached" { + targets = discovery.relabel.integrations_memcached.output + forward_to = [prometheus.remote_write.metrics_default.receiver] + job_name = "integrations/memcached" +} + +prometheus.exporter.mongodb "integrations_mongodb_exporter" { + mongodb_uri = "mongodb://mongodb-a:27017" + direct_connect = true +} + +discovery.relabel "integrations_mongodb" { + targets = prometheus.exporter.mongodb.integrations_mongodb_exporter.targets + + rule { + source_labels = ["__address__"] + target_label = "service_name" + replacement = "replicaset1-node1" + } + + rule { + source_labels = ["__address__"] + target_label = "mongodb_cluster" + replacement = "prod-cluster" + } +} + +prometheus.scrape "integrations_mongodb" { + targets = discovery.relabel.integrations_mongodb.output + forward_to = [prometheus.remote_write.metrics_default.receiver] + job_name = "integrations/mongodb" +} + +prometheus.exporter.mssql "integrations_mssql" { + connection_string = "sqlserver://:@:" +} + +prometheus.scrape "integrations_mssql" { + targets = prometheus.exporter.mssql.integrations_mssql.targets + forward_to = [prometheus.remote_write.metrics_default.receiver] + job_name = "integrations/mssql" +} + +prometheus.exporter.mysql "integrations_mysqld_exporter" { + data_source_name = "root@(server-a:3306)/" +} + +discovery.relabel "integrations_mysql" { + targets = prometheus.exporter.mysql.integrations_mysqld_exporter.targets + + rule { + source_labels = ["__address__"] + target_label = "instance" + replacement = "server-a" + } +} + +prometheus.scrape "integrations_mysql" { + targets = discovery.relabel.integrations_mysql.output + forward_to = [prometheus.remote_write.metrics_default.receiver] + job_name = "integrations/mysql" +} + +prometheus.exporter.unix "integrations_node_exporter" { } + +discovery.relabel "integrations_node_exporter" { + targets = prometheus.exporter.unix.integrations_node_exporter.targets + + rule { + source_labels = ["__address__"] + target_label = "__param_id" + } + + rule { + source_labels = ["__param_id"] + target_label = "thermostat" + } + + rule { + target_label = "__address__" + replacement = "localhost:8099" + } +} + +prometheus.scrape "integrations_node_exporter" { + targets = discovery.relabel.integrations_node_exporter.output + forward_to = [prometheus.relabel.integrations_node_exporter.receiver] + job_name = "integrations/node_exporter" +} + +prometheus.relabel "integrations_node_exporter" { + forward_to = [prometheus.remote_write.metrics_default.receiver] + + rule { + source_labels = ["__metric_address1__"] + target_label = "__metric_param_target1" + } + + rule { + source_labels = ["__metric_address2__"] + target_label = "__metric_param_target2" + } +} + +prometheus.exporter.oracledb "integrations_oracledb" { + connection_string = "oracle://user:password@localhost:1521/orcl.localnet" +} + +prometheus.scrape "integrations_oracledb" { + targets = prometheus.exporter.oracledb.integrations_oracledb.targets + forward_to = [prometheus.remote_write.metrics_default.receiver] + job_name = "integrations/oracledb" +} + +prometheus.exporter.postgres "integrations_postgres_exporter" { + data_source_names = ["postgres://postgres:password@localhost:5432/postgres?sslmode=disable"] +} + +discovery.relabel "integrations_postgres" { + targets = prometheus.exporter.postgres.integrations_postgres_exporter.targets + + rule { + source_labels = ["__address__"] + target_label = "instance" + replacement = "postgres-a" + } +} + +prometheus.scrape "integrations_postgres" { + targets = discovery.relabel.integrations_postgres.output + forward_to = [prometheus.remote_write.metrics_default.receiver] + job_name = "integrations/postgres" +} + +prometheus.exporter.process "integrations_process_exporter" { + matcher { + name = "{{.Comm}}" + cmdline = [".+"] + } +} + +prometheus.scrape "integrations_process" { + targets = prometheus.exporter.process.integrations_process_exporter.targets + forward_to = [prometheus.remote_write.metrics_default.receiver] + job_name = "integrations/process" +} + +prometheus.exporter.redis "integrations_redis_exporter" { + redis_addr = "redis-2:6379" + export_key_values = false +} + +discovery.relabel "integrations_redis" { + targets = prometheus.exporter.redis.integrations_redis_exporter.targets + + rule { + source_labels = ["__address__"] + target_label = "instance" + replacement = "redis-2" + } +} + +prometheus.scrape "integrations_redis" { + targets = discovery.relabel.integrations_redis.output + forward_to = [prometheus.remote_write.metrics_default.receiver] + job_name = "integrations/redis" +} + +prometheus.exporter.snowflake "integrations_snowflake" { + account_name = "XXXXXXX-YYYYYYY" + username = "snowflake-user" + password = "snowflake-pass" + warehouse = "SNOWFLAKE_WAREHOUSE" +} + +prometheus.scrape "integrations_snowflake" { + targets = prometheus.exporter.snowflake.integrations_snowflake.targets + forward_to = [prometheus.remote_write.metrics_default.receiver] + job_name = "integrations/snowflake" +} + +prometheus.exporter.squid "integrations_squid" { + address = "localhost:3128" +} + +prometheus.scrape "integrations_squid" { + targets = prometheus.exporter.squid.integrations_squid.targets + forward_to = [prometheus.remote_write.metrics_default.receiver] + job_name = "integrations/squid" + scrape_timeout = "1m0s" +} + +prometheus.exporter.statsd "integrations_statsd_exporter" { } + +prometheus.scrape "integrations_statsd" { + targets = prometheus.exporter.statsd.integrations_statsd_exporter.targets + forward_to = [prometheus.remote_write.metrics_default.receiver] + job_name = "integrations/statsd" +} + prometheus.exporter.agent "integrations_agent" { } discovery.relabel "integrations_agent" { @@ -90,3 +438,41 @@ prometheus.scrape "integrations_apache2" { forward_to = [prometheus.remote_write.metrics_default.receiver] job_name = "integrations/apache2" } + +prometheus.exporter.blackbox "integrations_blackbox" { + config = "modules:\n http_2xx:\n prober: http\n timeout: 5s\n http:\n method: POST\n headers:\n Content-Type: application/json\n body: '{}'\n preferred_ip_protocol: ip4\n" + + target "example" { + address = "http://example.com" + module = "http_2xx" + } + probe_timeout_offset = "0s" +} + +prometheus.scrape "integrations_blackbox" { + targets = prometheus.exporter.blackbox.integrations_blackbox.targets + forward_to = [prometheus.remote_write.metrics_default.receiver] + job_name = "integrations/blackbox" +} + +prometheus.exporter.snmp "integrations_snmp" { + target "network_switch_1" { + address = "192.168.1.2" + module = "if_mib" + auth = "public" + walk_params = "public" + } + + target "network_router_2" { + address = "192.168.1.3" + module = "mikrotik" + auth = "private" + walk_params = "private" + } +} + +prometheus.scrape "integrations_snmp" { + targets = prometheus.exporter.snmp.integrations_snmp.targets + forward_to = [prometheus.remote_write.metrics_default.receiver] + job_name = "integrations/snmp" +} diff --git a/converter/internal/staticconvert/testdata-v2/integrations_v2.yaml b/converter/internal/staticconvert/testdata-v2/integrations_v2.yaml index 057609597a56..d533977c6a9f 100644 --- a/converter/internal/staticconvert/testdata-v2/integrations_v2.yaml +++ b/converter/internal/staticconvert/testdata-v2/integrations_v2.yaml @@ -31,4 +31,177 @@ integrations: - "subId" resource_type: "Microsoft.Dashboard/grafana" metrics: - - "HttpRequestCount" \ No newline at end of file + - "HttpRequestCount" + blackbox: + blackbox_targets: + - name: example + address: http://example.com + module: http_2xx + blackbox_config: + modules: + http_2xx: + prober: http + timeout: 5s + http: + method: POST + headers: + Content-Type: application/json + body: '{}' + preferred_ip_protocol: "ip4" + cadvisor: + store_container_labels: false + cloudwatch_configs: + - sts_region: us-east-2 + discovery: + jobs: + - type: AWS/EC2 + regions: + - us-east-2 + nil_to_zero: true + metrics: + - name: CPUUtilization + period: 5m + statistics: + - Average + nil_to_zero: false + - name: NetworkPacketsIn + period: 5m + statistics: + - Average + static: + - name: single_ec2_instance + regions: + - us-east-2 + namespace: AWS/EC2 + dimensions: + - name: InstanceId + value: i-0e43cee369aa44b52 + nil_to_zero: true + metrics: + - name: CPUUtilization + period: 5m + statistics: + - Average + nil_to_zero: false + - name: NetworkPacketsIn + period: 5m + statistics: + - Average + consul_configs: + - autoscrape: + metrics_instance: "default" + dnsmasq_configs: + - dnsmasq_address: dnsmasq-a:53 + autoscrape: + relabel_configs: + - source_labels: [__address__] + target_label: instance + replacement: dnsmasq-a + elasticsearch_configs: + - autoscrape: + metrics_instance: "default" + gcp_configs: + - project_ids: + - + metrics_prefixes: + - loadbalancing.googleapis.com/https/request_bytes_count + - loadbalancing.googleapis.com/https/total_latencies + extra_filters: + - loadbalancing.googleapis.com:resource.labels.backend_target_name="sample-value" + github_configs: + - api_token: ABCDEFGH-1234-ABCD-1234-ABCDEFGHIJKL + repositories: + - grafana/agent + - grafana/agent-modules + kafka_configs: + - autoscrape: + metrics_instance: "default" + memcached_configs: + - memcached_address: memcached-a:53 + autoscrape: + relabel_configs: + - source_labels: [__address__] + target_label: instance + replacement: memcached-a + mongodb_configs: + - mongodb_uri: mongodb://mongodb-a:27017 + autoscrape: + relabel_configs: + - source_labels: [__address__] + target_label: service_name + replacement: 'replicaset1-node1' + - source_labels: [__address__] + target_label: mongodb_cluster + replacement: 'prod-cluster' + mssql_configs: + - connection_string: sqlserver://:@: + mysql_configs: + - data_source_name: root@(server-a:3306)/ + autoscrape: + relabel_configs: + - source_labels: [__address__] + target_label: instance + replacement: server-a + node_exporter: + autoscrape: + relabel_configs: + - source_labels: [__address__] + target_label: __param_id + - source_labels: [__param_id] + target_label: thermostat + - target_label: __address__ + replacement: localhost:8099 + metric_relabel_configs: + - source_labels: [__metric_address1__] + target_label: __metric_param_target1 + - source_labels: [__metric_address2__] + target_label: __metric_param_target2 + oracledb_configs: + - connection_string: oracle://user:password@localhost:1521/orcl.localnet + postgres_configs: + - data_source_names: + - postgres://postgres:password@localhost:5432/postgres?sslmode=disable + autoscrape: + relabel_configs: + - source_labels: [__address__] + target_label: instance + replacement: postgres-a + process: + process_names: + - name: "{{.Comm}}" + cmdline: + - '.+' + redis_configs: + - redis_addr: "redis-2:6379" + export_key_values: false + autoscrape: + relabel_configs: + - source_labels: [__address__] + target_label: instance + replacement: redis-2 + snmp: + snmp_targets: + - name: network_switch_1 + address: 192.168.1.2 + module: if_mib + walk_params: public + auth: public + - name: network_router_2 + address: 192.168.1.3 + module: mikrotik + walk_params: private + auth: private + snowflake_configs: + - account_name: XXXXXXX-YYYYYYY + username: snowflake-user + password: snowflake-pass + warehouse: SNOWFLAKE_WAREHOUSE + role: ACCOUNTADMIN + squid_configs: + - address: localhost:3128 + autoscrape: + scrape_interval: 1m + scrape_timeout: 1m + statsd: + autoscrape: + metrics_instance: "default" \ No newline at end of file diff --git a/converter/internal/staticconvert/testdata-v2_windows/integrations_v2.diags b/converter/internal/staticconvert/testdata-v2_windows/integrations_v2.diags new file mode 100644 index 000000000000..a4a05d1a3b58 --- /dev/null +++ b/converter/internal/staticconvert/testdata-v2_windows/integrations_v2.diags @@ -0,0 +1 @@ +(Warning) Please review your agent command line flags and ensure they are set in your Flow mode config file where necessary. \ No newline at end of file diff --git a/converter/internal/staticconvert/testdata-v2_windows/integrations_v2.river b/converter/internal/staticconvert/testdata-v2_windows/integrations_v2.river new file mode 100644 index 000000000000..e01818b3faad --- /dev/null +++ b/converter/internal/staticconvert/testdata-v2_windows/integrations_v2.river @@ -0,0 +1,24 @@ +prometheus.remote_write "metrics_default" { + endpoint { + name = "default-8be96f" + url = "http://localhost:9009/api/prom/push" + + queue_config { } + + metadata_config { } + } +} + +prometheus.exporter.windows "integrations_windows_exporter" { + exchange { } + + network { + exclude = ".+" + } +} + +prometheus.scrape "integrations_windows" { + targets = prometheus.exporter.windows.integrations_windows_exporter.targets + forward_to = [prometheus.remote_write.metrics_default.receiver] + job_name = "integrations/windows" +} diff --git a/converter/internal/staticconvert/testdata-v2_windows/integrations_v2.yaml b/converter/internal/staticconvert/testdata-v2_windows/integrations_v2.yaml new file mode 100644 index 000000000000..da2e8b44c3c7 --- /dev/null +++ b/converter/internal/staticconvert/testdata-v2_windows/integrations_v2.yaml @@ -0,0 +1,11 @@ +metrics: + global: + remote_write: + - url: http://localhost:9009/api/prom/push + configs: + - name: default + +integrations: + windows: + autoscrape: + metrics_instance: "default" \ No newline at end of file diff --git a/converter/internal/staticconvert/testdata/integrations.river b/converter/internal/staticconvert/testdata/integrations.river index 274fd0e737e2..1fc2e1867c1e 100644 --- a/converter/internal/staticconvert/testdata/integrations.river +++ b/converter/internal/staticconvert/testdata/integrations.river @@ -387,10 +387,10 @@ prometheus.scrape "integrations_mysqld_exporter" { } } -prometheus.exporter.unix "default" { } +prometheus.exporter.unix "integrations_node_exporter" { } discovery.relabel "integrations_node_exporter" { - targets = prometheus.exporter.unix.default.targets + targets = prometheus.exporter.unix.integrations_node_exporter.targets rule { source_labels = ["__address__"] diff --git a/converter/internal/staticconvert/validate.go b/converter/internal/staticconvert/validate.go index b79760a69b49..eed0b8c57717 100644 --- a/converter/internal/staticconvert/validate.go +++ b/converter/internal/staticconvert/validate.go @@ -35,7 +35,9 @@ import ( v2 "github.com/grafana/agent/pkg/integrations/v2" agent_exporter_v2 "github.com/grafana/agent/pkg/integrations/v2/agent" apache_exporter_v2 "github.com/grafana/agent/pkg/integrations/v2/apache_http" + blackbox_exporter_v2 "github.com/grafana/agent/pkg/integrations/v2/blackbox_exporter" "github.com/grafana/agent/pkg/integrations/v2/metricsutils" + snmp_exporter_v2 "github.com/grafana/agent/pkg/integrations/v2/snmp_exporter" "github.com/grafana/agent/pkg/integrations/windows_exporter" "github.com/grafana/agent/pkg/logs" "github.com/grafana/agent/pkg/metrics" @@ -164,9 +166,32 @@ func validateIntegrationsV2(integrationsConfig *v2.SubsystemOptions) diag.Diagno switch itg := integration.(type) { case *agent_exporter_v2.Config: case *apache_exporter_v2.Config: + case *blackbox_exporter_v2.Config: + case *snmp_exporter_v2.Config: case *metricsutils.ConfigShim: switch v1_itg := itg.Orig.(type) { case *azure_exporter.Config: + case *cadvisor.Config: + case *cloudwatch_exporter.Config: + case *consul_exporter.Config: + case *dnsmasq_exporter.Config: + case *elasticsearch_exporter.Config: + case *gcp_exporter.Config: + case *github_exporter.Config: + case *kafka_exporter.Config: + case *memcached_exporter.Config: + case *mongodb_exporter.Config: + case *mssql_exporter.Config: + case *mysqld_exporter.Config: + case *node_exporter.Config: + case *oracledb_exporter.Config: + case *postgres_exporter.Config: + case *process_exporter.Config: + case *redis_exporter.Config: + case *snowflake_exporter.Config: + case *squid_exporter.Config: + case *statsd_exporter.Config: + case *windows_exporter.Config: default: diags.Add(diag.SeverityLevelError, fmt.Sprintf("The converter does not support converting the provided %s integration.", v1_itg.Name())) } diff --git a/pkg/integrations/v2/blackbox_exporter/blackbox_exporter.go b/pkg/integrations/v2/blackbox_exporter/blackbox_exporter.go index 5c21c35447c3..5c2791aaaae1 100644 --- a/pkg/integrations/v2/blackbox_exporter/blackbox_exporter.go +++ b/pkg/integrations/v2/blackbox_exporter/blackbox_exporter.go @@ -5,7 +5,9 @@ import ( "github.com/grafana/agent/pkg/integrations/blackbox_exporter" integrations_v2 "github.com/grafana/agent/pkg/integrations/v2" "github.com/grafana/agent/pkg/integrations/v2/common" + "github.com/grafana/agent/pkg/util" blackbox_config "github.com/prometheus/blackbox_exporter/config" + "gopkg.in/yaml.v3" ) // DefaultConfig holds the default settings for the blackbox_exporter integration. @@ -18,7 +20,7 @@ var DefaultConfig = Config{ type Config struct { BlackboxConfigFile string `yaml:"config_file,omitempty"` BlackboxTargets []blackbox_exporter.BlackboxTarget `yaml:"blackbox_targets"` - BlackboxConfig blackbox_config.Config `yaml:"blackbox_config,omitempty"` + BlackboxConfig util.RawYAML `yaml:"blackbox_config,omitempty"` ProbeTimeoutOffset float64 `yaml:"probe_timeout_offset,omitempty"` Common common.MetricsConfig `yaml:",inline"` @@ -30,7 +32,13 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error { *c = DefaultConfig type plain Config - return unmarshal((*plain)(c)) + err := unmarshal((*plain)(c)) + if err != nil { + return err + } + + var blackbox_config blackbox_config.Config + return yaml.Unmarshal(c.BlackboxConfig, &blackbox_config) } // Name returns the name of the integration. @@ -58,7 +66,13 @@ func init() { // NewIntegration creates a new blackbox integration. func (c *Config) NewIntegration(log log.Logger, globals integrations_v2.Globals) (integrations_v2.Integration, error) { - modules, err := blackbox_exporter.LoadBlackboxConfig(log, c.BlackboxConfigFile, c.BlackboxTargets, &c.BlackboxConfig) + var blackbox_config blackbox_config.Config + err := yaml.Unmarshal(c.BlackboxConfig, &blackbox_config) + if err != nil { + return nil, err + } + + modules, err := blackbox_exporter.LoadBlackboxConfig(log, c.BlackboxConfigFile, c.BlackboxTargets, &blackbox_config) if err != nil { return nil, err }