diff --git a/CHANGELOG.md b/CHANGELOG.md index 39f33d3ee221..7532bbbc6114 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,8 @@ Main (unreleased) - Fixed some converter diagnostics so they show as warnings rather than errors. Improve clarity for various diagnostics. (@erikbaranowski) +- Wire up the agent exporter integration for the static converter. (@erikbaranowski) + - Allow the usage of encodings other than UTF8 to be used with environment variable expansion. (@mattdurham) - Fixed an issue where native histogram time series were being dropped silently. (@krajorama) diff --git a/converter/internal/staticconvert/internal/build/agent_exporter.go b/converter/internal/staticconvert/internal/build/agent_exporter.go new file mode 100644 index 000000000000..019bcd02cee9 --- /dev/null +++ b/converter/internal/staticconvert/internal/build/agent_exporter.go @@ -0,0 +1,26 @@ +package build + +import ( + "fmt" + + "github.com/grafana/agent/component/discovery" + "github.com/grafana/agent/component/prometheus/exporter/agent" + "github.com/grafana/agent/converter/internal/common" + agent_exporter "github.com/grafana/agent/pkg/integrations/agent" +) + +func (b *IntegrationsV1ConfigBuilder) appendAgentExporter(config *agent_exporter.Config) discovery.Exports { + args := toAgentExporter(config) + compLabel := common.LabelForParts(b.globalCtx.LabelPrefix, config.Name()) + b.f.Body().AppendBlock(common.NewBlockWithOverride( + []string{"prometheus", "exporter", "agent"}, + compLabel, + args, + )) + + return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.agent.%s.targets", compLabel)) +} + +func toAgentExporter(config *agent_exporter.Config) *agent.Arguments { + return &agent.Arguments{} +} diff --git a/converter/internal/staticconvert/internal/build/builder.go b/converter/internal/staticconvert/internal/build/builder.go index 939592a6a2b2..74b20784ff8d 100644 --- a/converter/internal/staticconvert/internal/build/builder.go +++ b/converter/internal/staticconvert/internal/build/builder.go @@ -8,6 +8,7 @@ import ( "github.com/grafana/agent/converter/diag" "github.com/grafana/agent/converter/internal/prometheusconvert" "github.com/grafana/agent/pkg/config" + agent_exporter "github.com/grafana/agent/pkg/integrations/agent" "github.com/grafana/agent/pkg/integrations/apache_http" "github.com/grafana/agent/pkg/integrations/azure_exporter" "github.com/grafana/agent/pkg/integrations/blackbox_exporter" @@ -79,6 +80,8 @@ func (b *IntegrationsV1ConfigBuilder) appendIntegrations() { var exports discovery.Exports switch itg := integration.Config.(type) { + case *agent_exporter.Config: + exports = b.appendAgentExporter(itg) case *apache_http.Config: exports = b.appendApacheExporter(itg) case *node_exporter.Config: diff --git a/converter/internal/staticconvert/testdata/integrations.river b/converter/internal/staticconvert/testdata/integrations.river index ed8c76bc6147..274fd0e737e2 100644 --- a/converter/internal/staticconvert/testdata/integrations.river +++ b/converter/internal/staticconvert/testdata/integrations.river @@ -1,11 +1,9 @@ -prometheus.exporter.apache "integrations_apache_http" { - scrape_uri = "http://0.0.0.0/server-status?auto" -} +prometheus.exporter.agent "integrations_agent" { } -prometheus.scrape "integrations_apache_http" { - targets = prometheus.exporter.apache.integrations_apache_http.targets +prometheus.scrape "integrations_agent" { + targets = prometheus.exporter.agent.integrations_agent.targets forward_to = [prometheus.remote_write.integrations.receiver] - job_name = "integrations/apache_http" + job_name = "integrations/agent" tls_config { ca_file = "/something7.cert" @@ -24,6 +22,22 @@ prometheus.remote_write "integrations" { } } +prometheus.exporter.apache "integrations_apache_http" { + scrape_uri = "http://0.0.0.0/server-status?auto" +} + +prometheus.scrape "integrations_apache_http" { + targets = prometheus.exporter.apache.integrations_apache_http.targets + forward_to = [prometheus.remote_write.integrations.receiver] + job_name = "integrations/apache_http" + + tls_config { + ca_file = "/something7.cert" + cert_file = "/something8.cert" + key_file = "/something9.cert" + } +} + 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" diff --git a/converter/internal/staticconvert/testdata/integrations.yaml b/converter/internal/staticconvert/testdata/integrations.yaml index afa2ed1046c5..a57b0f808024 100644 --- a/converter/internal/staticconvert/testdata/integrations.yaml +++ b/converter/internal/staticconvert/testdata/integrations.yaml @@ -9,6 +9,8 @@ integrations: cert_file: "/something8.cert" key_file: "/something9.cert" scrape_integrations: true + agent: + enabled: true apache_http: enabled: true scrape_uri: http://0.0.0.0/server-status?auto diff --git a/converter/internal/staticconvert/testdata/sanitize.diags b/converter/internal/staticconvert/testdata/sanitize.diags index 484554168237..d02def1345ed 100644 --- a/converter/internal/staticconvert/testdata/sanitize.diags +++ b/converter/internal/staticconvert/testdata/sanitize.diags @@ -1,3 +1,2 @@ (Warning) Please review your agent command line flags and ensure they are set in your Flow mode config file where necessary. -(Warning) The converter does not support converting the provided metrics wal_directory config: Use the run command flag --storage.path for Flow mode instead. -(Error) The converter does not support converting the provided agent integration. \ No newline at end of file +(Warning) The converter does not support converting the provided metrics wal_directory config: Use the run command flag --storage.path for Flow mode instead. \ No newline at end of file diff --git a/converter/internal/staticconvert/testdata/sanitize.river b/converter/internal/staticconvert/testdata/sanitize.river index 17984e110f61..38dabad4a85c 100644 --- a/converter/internal/staticconvert/testdata/sanitize.river +++ b/converter/internal/staticconvert/testdata/sanitize.river @@ -101,3 +101,50 @@ loki.write "logs_integrations" { } external_labels = {} } + +prometheus.exporter.agent "integrations_agent" { } + +discovery.relabel "integrations_agent" { + targets = prometheus.exporter.agent.integrations_agent.targets + + rule { + source_labels = ["agent_hostname"] + target_label = "instance" + } + + rule { + target_label = "job" + replacement = "integrations/agent-check" + } +} + +prometheus.scrape "integrations_agent" { + targets = discovery.relabel.integrations_agent.output + forward_to = [prometheus.relabel.integrations_agent.receiver] + job_name = "integrations/agent" +} + +prometheus.relabel "integrations_agent" { + forward_to = [prometheus.remote_write.integrations.receiver] + + rule { + source_labels = ["__name__"] + regex = "(prometheus_target_.*|prometheus_sd_discovered_targets|agent_build.*|agent_wal_samples_appended_total|process_start_time_seconds)" + action = "keep" + } +} + +prometheus.remote_write "integrations" { + endpoint { + url = "https://region.grafana.net/api/prom/push" + + basic_auth { + username = "id" + password = "token" + } + + queue_config { } + + metadata_config { } + } +} diff --git a/converter/internal/staticconvert/testdata/unsupported.diags b/converter/internal/staticconvert/testdata/unsupported.diags index 7fde45c4ed71..98330af73da4 100644 --- a/converter/internal/staticconvert/testdata/unsupported.diags +++ b/converter/internal/staticconvert/testdata/unsupported.diags @@ -4,7 +4,6 @@ (Error) The converter does not support converting the provided grpc_tls_config server config: flow mode does not have a gRPC server to configure. (Error) The converter does not support converting the provided prefer_server_cipher_suites server config. (Warning) The converter does not support converting the provided metrics wal_directory config: Use the run command flag --storage.path for Flow mode instead. -(Error) The converter does not support converting the provided agent integration. (Warning) disabled integrations do nothing and are not included in the output: node_exporter. (Error) The converter does not support converting the provided traces config. (Error) The converter does not support converting the provided agent_management config. \ No newline at end of file diff --git a/converter/internal/staticconvert/testdata/unsupported.yaml b/converter/internal/staticconvert/testdata/unsupported.yaml index 3a2c004c5238..11613e49b356 100644 --- a/converter/internal/staticconvert/testdata/unsupported.yaml +++ b/converter/internal/staticconvert/testdata/unsupported.yaml @@ -21,8 +21,6 @@ metrics: - targets: ['localhost:9099'] integrations: - agent: - enabled: true mssql: enabled: true scrape_integration: false diff --git a/converter/internal/staticconvert/validate.go b/converter/internal/staticconvert/validate.go index 13a583456b68..2e9623dbca25 100644 --- a/converter/internal/staticconvert/validate.go +++ b/converter/internal/staticconvert/validate.go @@ -6,6 +6,7 @@ import ( "github.com/grafana/agent/converter/diag" "github.com/grafana/agent/converter/internal/common" "github.com/grafana/agent/pkg/config" + agent_exporter "github.com/grafana/agent/pkg/integrations/agent" "github.com/grafana/agent/pkg/integrations/apache_http" "github.com/grafana/agent/pkg/integrations/azure_exporter" "github.com/grafana/agent/pkg/integrations/blackbox_exporter" @@ -106,6 +107,7 @@ func validateIntegrations(integrationsConfig config.VersionedIntegrations) diag. } switch itg := integration.Config.(type) { + case *agent_exporter.Config: case *apache_http.Config: case *node_exporter.Config: case *blackbox_exporter.Config: