From 96fdb3ee5e3b4b95026b1c619b68aec252f076f0 Mon Sep 17 00:00:00 2001 From: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> Date: Mon, 11 Dec 2023 15:52:55 -0500 Subject: [PATCH] update prometheus.blackbox.exporter target name from a label to attribute Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> --- .../prometheus/exporter/blackbox/blackbox.go | 2 +- .../exporter/blackbox/blackbox_test.go | 30 ++++++++++++------ .../internal/build/blackbox_exporter.go | 3 +- .../testdata-v2/integrations_v2.river | 3 +- .../staticconvert/testdata/integrations.river | 3 +- .../writing-exporter-flow-components.md | 3 +- .../prometheus.exporter.blackbox.md | 18 +++++++---- docs/sources/flow/release-notes.md | 31 +++++++++++++++++++ 8 files changed, 71 insertions(+), 22 deletions(-) diff --git a/component/prometheus/exporter/blackbox/blackbox.go b/component/prometheus/exporter/blackbox/blackbox.go index 0388560443a8..62c3981e82a0 100644 --- a/component/prometheus/exporter/blackbox/blackbox.go +++ b/component/prometheus/exporter/blackbox/blackbox.go @@ -67,7 +67,7 @@ var DefaultArguments = Arguments{ // BlackboxTarget defines a target to be used by the exporter. type BlackboxTarget struct { - Name string `river:",label"` + Name string `river:"name,attr"` Target string `river:"address,attr"` Module string `river:"module,attr,optional"` Labels map[string]string `river:"labels,attr,optional"` diff --git a/component/prometheus/exporter/blackbox/blackbox_test.go b/component/prometheus/exporter/blackbox/blackbox_test.go index 6a4e9dab0d15..540e7a3c5086 100644 --- a/component/prometheus/exporter/blackbox/blackbox_test.go +++ b/component/prometheus/exporter/blackbox/blackbox_test.go @@ -16,11 +16,13 @@ import ( func TestUnmarshalRiver(t *testing.T) { riverCfg := ` config_file = "modules.yml" - target "target_a" { + target { + name = "target_a" address = "http://example.com" module = "http_2xx" } - target "target_b" { + target { + name = "target_b" address = "http://grafana.com" module = "http_2xx" } @@ -44,11 +46,13 @@ func TestUnmarshalRiverWithInlineConfig(t *testing.T) { riverCfg := ` config = "{ modules: { http_2xx: { prober: http, timeout: 5s } } }" - target "target_a" { + target { + name = "target_a" address = "http://example.com" module = "http_2xx" } - target "target_b" { + target { + name = "target_b" address = "http://grafana.com" module = "http_2xx" } @@ -77,11 +81,13 @@ func TestUnmarshalRiverWithInlineConfigYaml(t *testing.T) { riverCfg := ` config = "modules:\n http_2xx:\n prober: http\n timeout: 5s\n" - target "target_a" { + target { + name = "target_a" address = "http://example.com" module = "http_2xx" } - target "target_b" { + target { + name = "target_b" address = "http://grafana.com" module = "http_2xx" } @@ -117,7 +123,8 @@ func TestUnmarshalRiverWithInvalidConfig(t *testing.T) { ` config = "{ modules: { http_2xx: { prober: http, timeout: 5s }" - target "target_a" { + target { + name = "target_a" address = "http://example.com" module = "http_2xx" } @@ -129,7 +136,8 @@ func TestUnmarshalRiverWithInvalidConfig(t *testing.T) { ` config = "{ module: { http_2xx: { prober: http, timeout: 5s } } }" - target "target_a" { + target { + name = "target_a" address = "http://example.com" module = "http_2xx" } @@ -142,7 +150,8 @@ func TestUnmarshalRiverWithInvalidConfig(t *testing.T) { config_file = "config" config = "{ modules: { http_2xx: { prober: http, timeout: 5s } } }" - target "target_a" { + target { + name = "target_a" address = "http://example.com" module = "http_2xx" } @@ -152,7 +161,8 @@ func TestUnmarshalRiverWithInvalidConfig(t *testing.T) { { "Define neither config nor config_file", ` - target "target_a" { + target { + name = "target_a" address = "http://example.com" module = "http_2xx" } diff --git a/converter/internal/staticconvert/internal/build/blackbox_exporter.go b/converter/internal/staticconvert/internal/build/blackbox_exporter.go index 5282f9440b34..70007319ae1b 100644 --- a/converter/internal/staticconvert/internal/build/blackbox_exporter.go +++ b/converter/internal/staticconvert/internal/build/blackbox_exporter.go @@ -5,7 +5,6 @@ import ( "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" @@ -57,7 +56,7 @@ func toBlackboxTargets(blackboxTargets []blackbox_exporter.BlackboxTarget) black func toBlackboxTarget(target blackbox_exporter.BlackboxTarget) blackbox.BlackboxTarget { return blackbox.BlackboxTarget{ - Name: common.SanitizeIdentifierPanics(target.Name), + Name: target.Name, Target: target.Target, Module: target.Module, } diff --git a/converter/internal/staticconvert/testdata-v2/integrations_v2.river b/converter/internal/staticconvert/testdata-v2/integrations_v2.river index 3580c4767151..a746197e2bfa 100644 --- a/converter/internal/staticconvert/testdata-v2/integrations_v2.river +++ b/converter/internal/staticconvert/testdata-v2/integrations_v2.river @@ -474,7 +474,8 @@ prometheus.scrape "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" { + target { + name = "example" address = "http://example.com" module = "http_2xx" } diff --git a/converter/internal/staticconvert/testdata/integrations.river b/converter/internal/staticconvert/testdata/integrations.river index 68a04d198066..261ef76f228b 100644 --- a/converter/internal/staticconvert/testdata/integrations.river +++ b/converter/internal/staticconvert/testdata/integrations.river @@ -41,7 +41,8 @@ prometheus.scrape "integrations_apache_http" { 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" { + target { + name = "example" address = "http://example.com" module = "http_2xx" } diff --git a/docs/developer/writing-exporter-flow-components.md b/docs/developer/writing-exporter-flow-components.md index 20afa6264a35..59dfda0ab4e1 100644 --- a/docs/developer/writing-exporter-flow-components.md +++ b/docs/developer/writing-exporter-flow-components.md @@ -39,7 +39,8 @@ The river config would look like this: prometheus.exporter.blackbox "example" { config_file = "blackbox_modules.yml" - target "example" { + target { + name = "example" address = "http://example.com" module = "http_2xx" } diff --git a/docs/sources/flow/reference/components/prometheus.exporter.blackbox.md b/docs/sources/flow/reference/components/prometheus.exporter.blackbox.md index f509061417dd..53696e8d753f 100644 --- a/docs/sources/flow/reference/components/prometheus.exporter.blackbox.md +++ b/docs/sources/flow/reference/components/prometheus.exporter.blackbox.md @@ -18,7 +18,8 @@ The `prometheus.exporter.blackbox` component embeds ```river prometheus.exporter.blackbox "LABEL" { - target "example" { + target { + name = "EXAMPLE_NAME" address = "EXAMPLE_ADDRESS" } } @@ -60,10 +61,11 @@ The following blocks are supported inside the definition of ### target block The `target` block defines an individual blackbox target. -The `target` block may be specified multiple times to define multiple targets. The label of the block is required and will be used in the target's `job` label. +The `target` block may be specified multiple times to define multiple targets. | Name | Type | Description | Default | Required | | --------- | ---------------- | ----------------------------------- | ------- | -------- | +| `name` | `string` | The target's job label. | | yes | | `address` | `string` | The address of the target to probe. | | yes | | `module` | `string` | Blackbox module to use to probe. | `""` | no | | `labels` | `map(string)` | Labels to add to the target. | | no | @@ -103,12 +105,14 @@ The `config_file` argument is used to define which `blackbox_exporter` modules t prometheus.exporter.blackbox "example" { config_file = "blackbox_modules.yml" - target "example" { + target { + name = "example" address = "http://example.com" module = "http_2xx" } - target "grafana" { + target { + name = "grafana" address = "http://grafana.com" module = "http_2xx" labels = { @@ -149,12 +153,14 @@ This example is the same above with using an embedded configuration: prometheus.exporter.blackbox "example" { config = "{ modules: { http_2xx: { prober: http, timeout: 5s } } }" - target "example" { + target { + name = "example" address = "http://example.com" module = "http_2xx" } - target "grafana" { + target { + name = "grafana" address = "http://grafana.com" module = "http_2xx" labels = { diff --git a/docs/sources/flow/release-notes.md b/docs/sources/flow/release-notes.md index ce731376aaed..7b07872a45d3 100644 --- a/docs/sources/flow/release-notes.md +++ b/docs/sources/flow/release-notes.md @@ -29,6 +29,37 @@ Other release notes for the different {{< param "PRODUCT_ROOT_NAME" >}} variants [release-notes-operator]: {{< relref "../operator/release-notes.md" >}} {{% /admonition %}} +## v0.39 + +### Breaking change: `prometheus.exporter.blackbox` config format update + +The config for `prometheus.exporter.blackbox` has been updated so that the name +of a `target` block is passed in from argument rather than a label on the block. +This will allow less restrictive values to be passed to the exporter. + +Before: +```river +prometheus.exporter.blackbox "example" { + config_file = "blackbox_modules.yml" + + target "grafana" { + address = "http://grafana.com" + } +} +``` + +After: +```river +prometheus.exporter.blackbox "example" { + config_file = "blackbox_modules.yml" + + target { + name = "grafana" + address = "http://grafana.com" + } +} +``` + ## v0.38 ### Breaking change: `otelcol.exporter.jaeger` component removed