Skip to content

Commit

Permalink
feat!(exporter/blackbox): use required name attr instead label for ta…
Browse files Browse the repository at this point in the history
…rget block (#5945)

* feat!(exporter/blackbox): use required name attr instead label for target block

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

---------

Signed-off-by: hainenber <[email protected]>
  • Loading branch information
hainenber authored Dec 12, 2023
1 parent 3c7f8c0 commit 8c0f6de
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 25 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ internal API changes are not present.
Main (unreleased)
-----------------

### Breaking changes

- The `target` block in `prometheus.exporter.blackbox` requires a mandatory `name`
argument instead of a block label. (@hainenber)

### Enhancements

- Flow Windows service: Support environment variables. (@jkroepke)
Expand Down
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
46 changes: 33 additions & 13 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 @@ -35,7 +37,7 @@ func TestUnmarshalRiver(t *testing.T) {
require.Contains(t, "target_a", args.Targets[0].Name)
require.Contains(t, "http://example.com", args.Targets[0].Target)
require.Contains(t, "http_2xx", args.Targets[0].Module)
require.Contains(t, "target_b", args.Targets[1].Name)
require.Contains(t, "target-b", args.Targets[1].Name)
require.Contains(t, "http://grafana.com", args.Targets[1].Target)
require.Contains(t, "http_2xx", args.Targets[1].Module)
}
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 All @@ -68,7 +72,7 @@ func TestUnmarshalRiverWithInlineConfig(t *testing.T) {
require.Contains(t, "target_a", args.Targets[0].Name)
require.Contains(t, "http://example.com", args.Targets[0].Target)
require.Contains(t, "http_2xx", args.Targets[0].Module)
require.Contains(t, "target_b", args.Targets[1].Name)
require.Contains(t, "target-b", args.Targets[1].Name)
require.Contains(t, "http://grafana.com", args.Targets[1].Target)
require.Contains(t, "http_2xx", args.Targets[1].Module)
}
Expand All @@ -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 All @@ -101,7 +107,7 @@ func TestUnmarshalRiverWithInlineConfigYaml(t *testing.T) {
require.Contains(t, "target_a", args.Targets[0].Name)
require.Contains(t, "http://example.com", args.Targets[0].Target)
require.Contains(t, "http_2xx", args.Targets[0].Module)
require.Contains(t, "target_b", args.Targets[1].Name)
require.Contains(t, "target-b", args.Targets[1].Name)
require.Contains(t, "http://grafana.com", args.Targets[1].Target)
require.Contains(t, "http_2xx", args.Targets[1].Module)
}
Expand All @@ -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,13 +161,24 @@ 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"
}
`,
`config or config_file must be set`,
},
{
"Specify label for target block instead of name attribute",
`
target "target_a" {
address = "http://example.com"
module = "http_2xx"
}
`,
`2:4: block "target" does not support specifying labels`,
},
}
for _, tt := range tests {
t.Run(tt.testname, func(t *testing.T) {
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 @@ -507,7 +507,8 @@ faro.receiver "integrations_app_agent_receiver" {
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"
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` attribute is required and will be used in the target's `job` label.

| Name | Type | Description | Default | Required |
| --------- | ---------------- | ----------------------------------- | ------- | -------- |
| `name` | `string` | The name of the target to probe. | | 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
41 changes: 41 additions & 0 deletions docs/sources/flow/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,47 @@ Other release notes for the different {{< param "PRODUCT_ROOT_NAME" >}} variants
[release-notes-operator]: {{< relref "../operator/release-notes.md" >}}
{{% /admonition %}}


## v0.39

### Breaking change: label for `target` block in `prometheus.exporter.blackbox` is removed

Previously in `prometheus.exporter.blackbox`, the `target` block requires a label which is used in job's name.
In this version, user needs to be specify `name` attribute instead, which allow less restrictive naming.

Old configuration example:

```river
prometheus.exporter.blackbox "example" {
config_file = "blackbox_modules.yml"
target "grafana" {
address = "http://grafana.com"
module = "http_2xx"
labels = {
"env": "dev",
}
}
}
```

New configuration example:

```river
prometheus.exporter.blackbox "example" {
config_file = "blackbox_modules.yml"
target {
name = "grafana"
address = "http://grafana.com"
module = "http_2xx"
labels = {
"env": "dev",
}
}
}
```

## v0.38

### Breaking change: `otelcol.exporter.jaeger` component removed
Expand Down

0 comments on commit 8c0f6de

Please sign in to comment.