Skip to content

Commit

Permalink
wire up the agent integration for the static converter (#5545)
Browse files Browse the repository at this point in the history
* wire up the agent integration for the static converter

Signed-off-by: erikbaranowski <[email protected]>

---------

Signed-off-by: erikbaranowski <[email protected]>
  • Loading branch information
erikbaranowski authored Oct 19, 2023
1 parent b5429c3 commit f4e6ac4
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 26 additions & 0 deletions converter/internal/staticconvert/internal/build/agent_exporter.go
Original file line number Diff line number Diff line change
@@ -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{}
}
3 changes: 3 additions & 0 deletions converter/internal/staticconvert/internal/build/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down
26 changes: 20 additions & 6 deletions converter/internal/staticconvert/testdata/integrations.river
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"

Expand Down
2 changes: 2 additions & 0 deletions converter/internal/staticconvert/testdata/integrations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions converter/internal/staticconvert/testdata/sanitize.diags
Original file line number Diff line number Diff line change
@@ -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.
(Warning) The converter does not support converting the provided metrics wal_directory config: Use the run command flag --storage.path for Flow mode instead.
47 changes: 47 additions & 0 deletions converter/internal/staticconvert/testdata/sanitize.river
Original file line number Diff line number Diff line change
Expand Up @@ -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 { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 0 additions & 2 deletions converter/internal/staticconvert/testdata/unsupported.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ metrics:
- targets: ['localhost:9099']

integrations:
agent:
enabled: true
mssql:
enabled: true
scrape_integration: false
Expand Down
2 changes: 2 additions & 0 deletions converter/internal/staticconvert/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit f4e6ac4

Please sign in to comment.