Skip to content

Commit b65fbbd

Browse files
authored
fix instance key in exporters (#3356)
* fix instance key in exporters * Add notes on using `prometheus.exporter` components in clustered Alloy instances * Call out the change in the changelog. * Improve wording. * Move the note * Improve wording * PR feedback for docs * PR feedback: add warning if potentially misusing exporters * feedback
1 parent bdb0ca4 commit b65fbbd

File tree

61 files changed

+259
-146
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+259
-146
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ internal API changes are not present.
1010
Main (unreleased)
1111
-----------------
1212

13+
### Breaking changes
14+
15+
- `prometheus.exporter.blackbox`, `prometheus.exporter.snmp` and `prometheus.exporter.statsd` now use the component ID instead of the hostname as
16+
their `instance` label in their exported metrics. This is a consequence of a bug fix that could lead to a missing data when using the exporter
17+
with clustering. If you would like to retain the previous behaviour, you can use `discovery.relabel` with `action = "replace"` rule to
18+
set the `instance` label to `sys.env("HOSTNAME")`. (@thampiotr)
19+
1320
### Features
1421

1522
- (_Experimental_) Additions to experimental `database_observability.mysql` component:

docs/sources/reference/components/prometheus/prometheus.exporter.cadvisor.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ title: prometheus.exporter.cadvisor
1414

1515
The `prometheus.exporter.cadvisor` component collects container metrics using [cAdvisor](https://github.com/google/cadvisor).
1616

17+
{{< docs/shared lookup="reference/components/exporter-clustering-warning.md" source="alloy" version="<ALLOY_VERSION>" >}}
18+
1719
## Usage
1820

1921
```alloy

docs/sources/reference/components/prometheus/prometheus.exporter.process.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ title: prometheus.exporter.process
1414

1515
The `prometheus.exporter.process` component embeds the [`process_exporter`](https://github.com/ncabatoff/process-exporter) for collecting process stats from `/proc`.
1616

17+
{{< docs/shared lookup="reference/components/exporter-clustering-warning.md" source="alloy" version="<ALLOY_VERSION>" >}}
18+
1719
## Usage
1820

1921
```alloy

docs/sources/reference/components/prometheus/prometheus.exporter.self.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ title: prometheus.exporter.self
1414

1515
The `prometheus.exporter.self` component collects and exposes metrics about {{< param "PRODUCT_NAME" >}} itself.
1616

17+
{{< docs/shared lookup="reference/components/exporter-clustering-warning.md" source="alloy" version="<ALLOY_VERSION>" >}}
18+
1719
## Usage
1820

1921
```alloy

docs/sources/reference/components/prometheus/prometheus.exporter.unix.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ For more information on collectors, refer to the [`collectors-list`](#collectors
1919

2020
You can specify multiple `prometheus.exporter.unix` components by giving them different labels.
2121

22+
{{< docs/shared lookup="reference/components/exporter-clustering-warning.md" source="alloy" version="<ALLOY_VERSION>" >}}
23+
2224
## Usage
2325

2426
```alloy

docs/sources/reference/components/prometheus/prometheus.exporter.windows.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ The `include` and `exclude` arguments are preferred going forward.
2424

2525
[windows_exporter]: https://github.com/prometheus-community/windows_exporter/tree/{{< param "PROM_WIN_EXP_VERSION" >}}
2626

27+
{{< docs/shared lookup="reference/components/exporter-clustering-warning.md" source="alloy" version="<ALLOY_VERSION>" >}}
28+
2729
## Usage
2830

2931
```alloy
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
canonical: https://grafana.com/docs/alloy/latest/shared/reference/components/exporter-clustering-warning/
3+
description: Shared content, exporter clustering warning
4+
headless: true
5+
---
6+
7+
{{< admonition type="note" >}}
8+
We do not recommend using this exporter with [clustering](../../../../get-started/clustering/) enabled.
9+
10+
The default `instance` label set by this exporter is the hostname of the machine running {{< param "PRODUCT_NAME" >}}.
11+
{{< param "PRODUCT_NAME" >}} clustering uses consistent hashing to distribute targets across the instances.
12+
This requires the discovered targets to be the same and have the same labels across all cluster instances.
13+
14+
If you do need to use this component in a cluster, use a dedicated `prometheus.scrape` component that's used to scrape
15+
this exporter and doesn't have clustering enabled. Alternatively, use `discovery.relabel` to set the `instance` label to a
16+
value that is the same across all cluster instances.
17+
{{< /admonition >}}

internal/component/prometheus/exporter/apache/apache.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ func init() {
1919
})
2020
}
2121

22-
func createExporter(opts component.Options, args component.Arguments, defaultInstanceKey string) (integrations.Integration, string, error) {
22+
func createExporter(opts component.Options, args component.Arguments) (integrations.Integration, string, error) {
2323
a := args.(Arguments)
24+
defaultInstanceKey := opts.ID // if cannot resolve instance key, use the component ID
2425
return integrations.NewIntegrationWithInstanceKey(opts.Logger, a.Convert(), defaultInstanceKey)
2526
}
2627

internal/component/prometheus/exporter/azure/azure.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ func init() {
1919
})
2020
}
2121

22-
func createExporter(opts component.Options, args component.Arguments, defaultInstanceKey string) (integrations.Integration, string, error) {
22+
func createExporter(opts component.Options, args component.Arguments) (integrations.Integration, string, error) {
2323
a := args.(Arguments)
24+
defaultInstanceKey := opts.ID // if cannot resolve instance key, use the component ID
2425
return integrations.NewIntegrationWithInstanceKey(opts.Logger, a.Convert(), defaultInstanceKey)
2526
}
2627

internal/component/prometheus/exporter/blackbox/blackbox.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ func init() {
2929
})
3030
}
3131

32-
func createExporter(opts component.Options, args component.Arguments, defaultInstanceKey string) (integrations.Integration, string, error) {
32+
func createExporter(opts component.Options, args component.Arguments) (integrations.Integration, string, error) {
3333
a := args.(Arguments)
34+
defaultInstanceKey := opts.ID // if cannot resolve instance key, use the component ID
3435
return integrations.NewIntegrationWithInstanceKey(opts.Logger, a.Convert(), defaultInstanceKey)
3536
}
3637

0 commit comments

Comments
 (0)