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

Converter static v2 3rd set of integrations #5698

Merged
merged 24 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
eff4917
wire up blackbox exporter for integrations v2 converter
erikbaranowski Nov 2, 2023
706b5bd
wire up cadvisor integration v2 for converter
erikbaranowski Nov 2, 2023
a8b1a6a
wire up cloudwatch exporter for integrations v2 converter
erikbaranowski Nov 2, 2023
4b41fc0
wire up consul exporter for integrations v2 converter
erikbaranowski Nov 2, 2023
cb6961d
wire up dnsmasq exporter for integrations v2 converter
erikbaranowski Nov 2, 2023
2447691
wire up elasticsearch exporter for integrations v2 converter
erikbaranowski Nov 2, 2023
77d0f47
wire up gcp exporter for integrations v2 converter
erikbaranowski Nov 2, 2023
4a508a1
wire up github exporter for integrations v2 converter
erikbaranowski Nov 2, 2023
539ab1e
wire up kafka exporter for integrations v2 converter
erikbaranowski Nov 3, 2023
5234f70
wire up memcached exporter for integrations v2 converter
erikbaranowski Nov 3, 2023
2b7206e
wire up mongodb exporter for integrations v2 converter
erikbaranowski Nov 3, 2023
30f1c7c
wire up mssql exporter for integrations v2 exporter
erikbaranowski Nov 3, 2023
aec7552
wire up mysql exporter for integrations v2 converter
erikbaranowski Nov 3, 2023
0eb469b
wire up node exporter for integrations v2 converter
erikbaranowski Nov 3, 2023
4dcf932
wire up oracledb exporter for integrations v2 converter
erikbaranowski Nov 3, 2023
37e5b9b
wire up postgres exporter for integrations v2 converter
erikbaranowski Nov 3, 2023
f3fa683
wire up process exporter for integrations v2 converter
erikbaranowski Nov 3, 2023
49afc32
wire up redis exporter for integrations v2 converter
erikbaranowski Nov 3, 2023
a6a819a
wire up snmp exporter for integrations v2 converter
erikbaranowski Nov 3, 2023
a68baf3
wire up snowflake exporter for integrations v2 converter
erikbaranowski Nov 3, 2023
83d2559
wire up squid exporter for integration v2 converter
erikbaranowski Nov 3, 2023
971fec3
wire up statsd exporter for integrations v2 converter
erikbaranowski Nov 3, 2023
ce82442
wire up windows exporter for integrations v2 converter
erikbaranowski Nov 3, 2023
af8c62a
fix up windows test after running it in local windows
erikbaranowski Nov 3, 2023
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
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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

Expand Down
95 changes: 72 additions & 23 deletions converter/internal/staticconvert/internal/build/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}

Expand All @@ -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...)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this fixed a potential bug where I was overwriting the value instead of appending.

scrapeConfig.MetricRelabelConfigs = commonConfig.Autoscrape.MetricRelabelConfigs
scrapeConfig.ScrapeInterval = commonConfig.Autoscrape.ScrapeInterval
scrapeConfig.ScrapeTimeout = commonConfig.Autoscrape.ScrapeTimeout
scrapeConfig.RelabelConfigs = relabelConfigs

scrapeConfigs := []*prom_config.ScrapeConfig{&scrapeConfig}

Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
14 changes: 2 additions & 12 deletions converter/internal/staticconvert/internal/build/consul_exporter.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
14 changes: 2 additions & 12 deletions converter/internal/staticconvert/internal/build/gcp_exporter.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Loading