Skip to content

Commit

Permalink
update prometheus.blackbox.exporter target name from a label to attri…
Browse files Browse the repository at this point in the history
…bute

Signed-off-by: erikbaranowski <[email protected]>
  • Loading branch information
erikbaranowski committed Dec 11, 2023
1 parent a2badce commit 96fdb3e
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 22 deletions.
2 changes: 1 addition & 1 deletion component/prometheus/exporter/blackbox/blackbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
30 changes: 20 additions & 10 deletions component/prometheus/exporter/blackbox/blackbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand All @@ -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"
}
Expand Down Expand Up @@ -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"
}
Expand Down Expand Up @@ -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"
}
Expand All @@ -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"
}
Expand All @@ -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"
}
Expand All @@ -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"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
3 changes: 2 additions & 1 deletion converter/internal/staticconvert/testdata/integrations.river
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
3 changes: 2 additions & 1 deletion docs/developer/writing-exporter-flow-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ The `prometheus.exporter.blackbox` component embeds

```river
prometheus.exporter.blackbox "LABEL" {
target "example" {
target {
name = "EXAMPLE_NAME"
address = "EXAMPLE_ADDRESS"
}
}
Expand Down Expand Up @@ -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 |
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 = {
Expand Down
31 changes: 31 additions & 0 deletions docs/sources/flow/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 96fdb3e

Please sign in to comment.