Skip to content

Commit 7f6d0d2

Browse files
iamrajivclayton-cornelldehaansa
authored
feat: Add prometheus.echo component for local metrics inspection (#4105)
* add echo * add test * add changelog * use prometheus expfmt encoder * add doc * Update docs/sources/reference/components/prometheus/prometheus.echo.md Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com> * Update docs/sources/reference/components/prometheus/prometheus.echo.md Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com> * Update docs/sources/reference/components/prometheus/prometheus.echo.md Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com> * Update docs/sources/reference/components/prometheus/prometheus.echo.md Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com> * Update docs/sources/reference/components/prometheus/prometheus.echo.md Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com> * Update docs/sources/reference/components/prometheus/prometheus.echo.md Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com> * Update docs/sources/reference/components/prometheus/prometheus.echo.md Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com> * Fix build issues * Appease linter and regenerate things --------- Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com> Co-authored-by: Sam DeHaan <sam.dehaan@grafana.com>
1 parent 27a5717 commit 7f6d0d2

File tree

11 files changed

+883
-0
lines changed

11 files changed

+883
-0
lines changed

.github/ISSUE_TEMPLATE/blank.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ body:
144144
- otelcol.receiver.vcenter
145145
- otelcol.receiver.zipkin
146146
- otelcol.storage.file
147+
- prometheus.echo
147148
- prometheus.enrich
148149
- prometheus.exporter.apache
149150
- prometheus.exporter.azure

.github/ISSUE_TEMPLATE/bug_report.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ body:
144144
- otelcol.receiver.vcenter
145145
- otelcol.receiver.zipkin
146146
- otelcol.storage.file
147+
- prometheus.echo
147148
- prometheus.enrich
148149
- prometheus.exporter.apache
149150
- prometheus.exporter.azure

.github/ISSUE_TEMPLATE/docs.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ body:
147147
- otelcol.receiver.vcenter
148148
- otelcol.receiver.zipkin
149149
- otelcol.storage.file
150+
- prometheus.echo
150151
- prometheus.enrich
151152
- prometheus.exporter.apache
152153
- prometheus.exporter.azure

.github/ISSUE_TEMPLATE/feature_request.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ body:
144144
- otelcol.receiver.vcenter
145145
- otelcol.receiver.zipkin
146146
- otelcol.storage.file
147+
- prometheus.echo
147148
- prometheus.enrich
148149
- prometheus.exporter.apache
149150
- prometheus.exporter.azure

.github/ISSUE_TEMPLATE/proposal.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ body:
144144
- otelcol.receiver.vcenter
145145
- otelcol.receiver.zipkin
146146
- otelcol.storage.file
147+
- prometheus.echo
147148
- prometheus.enrich
148149
- prometheus.exporter.apache
149150
- prometheus.exporter.azure

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Main (unreleased)
2424

2525
- Add htpasswd file based authentication for `otelcol.auth.basic` (@pkarakal)
2626

27+
- Add `prometheus.echo` component for local inspection of Prometheus metrics. The component writes received metrics to stdout in Prometheus exposition format, enabling easier debugging and testing of metrics flow. (@iamrajiv)
28+
2729
### Enhancements
2830

2931
- update promtail converter to use `file_match` block for `loki.source.file` instead of going through `local.file_match`. (@kalleep)

docs/sources/reference/compatibility/_index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ The following components, grouped by namespace, _export_ Prometheus `MetricsRece
187187
{{< /collapse >}}
188188

189189
{{< collapse title="prometheus" >}}
190+
- [prometheus.echo](../components/prometheus/prometheus.echo)
190191
- [prometheus.enrich](../components/prometheus/prometheus.enrich)
191192
- [prometheus.relabel](../components/prometheus/prometheus.relabel)
192193
- [prometheus.remote_write](../components/prometheus/prometheus.remote_write)
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
---
2+
canonical: https://grafana.com/docs/alloy/latest/reference/components/prometheus/prometheus.echo/
3+
description: Learn about prometheus.echo
4+
labels:
5+
stage: general-availability
6+
products:
7+
- oss
8+
title: prometheus.echo
9+
---
10+
11+
# `prometheus.echo`
12+
13+
The `prometheus.echo` component receives Prometheus metrics and writes them to stdout in Prometheus exposition format.
14+
This component is useful for debugging and testing the flow of metrics through a pipeline, allowing you to see exactly what metrics are being received at a particular point in your configuration.
15+
16+
## Usage
17+
18+
```alloy
19+
prometheus.echo "<LABEL>" {
20+
}
21+
```
22+
23+
## Arguments
24+
25+
You can use the following arguments with `prometheus.echo`:
26+
27+
| Name | Type | Description | Default | Required |
28+
| -------- | -------- | --------------------------------------------------------------- | ------- | -------- |
29+
| `format` | `string` | The output format for metrics. Must be `text` or `openmetrics`. | `text` | no |
30+
31+
The `format` argument controls how metrics are encoded when written to stdout:
32+
33+
* `text` - Uses the Prometheus text exposition format (default).
34+
* `openmetrics` - Uses the OpenMetrics text format.
35+
36+
## Blocks
37+
38+
The `prometheus.echo` component doesn't support any blocks. You can configure this component with arguments.
39+
40+
## Exported fields
41+
42+
The following fields are exported and can be referenced by other components:
43+
44+
| Name | Type | Description |
45+
| ---------- | ----------------- | --------------------------------------------------------- |
46+
| `receiver` | `MetricsReceiver` | A value that other components can use to send metrics to. |
47+
48+
## Component health
49+
50+
`prometheus.echo` is only reported as unhealthy if given an invalid configuration.
51+
In those cases, exported fields retain their last healthy values.
52+
53+
## Debug information
54+
55+
`prometheus.echo` doesn't expose any component-specific debug information.
56+
57+
## Debug metrics
58+
59+
`prometheus.echo` doesn't expose any component-specific debug metrics.
60+
61+
## Example
62+
63+
This example creates a metrics generation and inspection pipeline:
64+
65+
```alloy
66+
prometheus.exporter.unix "default" {
67+
}
68+
69+
prometheus.scrape "demo" {
70+
targets = prometheus.exporter.unix.default.targets
71+
forward_to = [prometheus.echo.debug.receiver]
72+
}
73+
74+
prometheus.echo "debug" {
75+
format = "text"
76+
}
77+
```
78+
79+
In this example:
80+
81+
1. The `prometheus.exporter.unix` component exposes system metrics.
82+
1. The `prometheus.scrape` component scrapes those metrics.
83+
1. The `prometheus.echo` component receives the scraped metrics and writes them to stdout in Prometheus text format.
84+
85+
When you run this configuration, you'll see the metrics being written to stdout, which is useful to:
86+
87+
* Debug metric collection issues
88+
* Verify metric labels and values
89+
* Test metric transformations
90+
* Understand the structure of metrics in your pipeline
91+
92+
### Example with OpenMetrics format
93+
94+
```alloy
95+
prometheus.scrape "demo" {
96+
targets = [
97+
{"__address__" = "localhost:9090"},
98+
]
99+
forward_to = [prometheus.echo.debug.receiver]
100+
}
101+
102+
prometheus.echo "debug" {
103+
format = "openmetrics"
104+
}
105+
```
106+
107+
This example outputs metrics using the OpenMetrics format instead of the traditional Prometheus text format.
108+
109+
<!-- START GENERATED COMPATIBLE COMPONENTS -->
110+
111+
## Compatible components
112+
113+
`prometheus.echo` has exports that can be consumed by the following components:
114+
115+
- Components that consume [Prometheus `MetricsReceiver`](../../../compatibility/#prometheus-metricsreceiver-consumers)
116+
117+
{{< admonition type="note" >}}
118+
Connecting some components may not be sensible or components may require further configuration to make the connection work correctly.
119+
Refer to the linked documentation for more details.
120+
{{< /admonition >}}
121+
122+
<!-- END GENERATED COMPATIBLE COMPONENTS -->

internal/component/all/all.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ import (
127127
_ "github.com/grafana/alloy/internal/component/otelcol/receiver/vcenter" // Import otelcol.receiver.vcenter
128128
_ "github.com/grafana/alloy/internal/component/otelcol/receiver/zipkin" // Import otelcol.receiver.zipkin
129129
_ "github.com/grafana/alloy/internal/component/otelcol/storage/file" // Import otelcol.storage.file
130+
_ "github.com/grafana/alloy/internal/component/prometheus/echo" // Import prometheus.echo
130131
_ "github.com/grafana/alloy/internal/component/prometheus/enrich" // Import prometheus.enrich
131132
_ "github.com/grafana/alloy/internal/component/prometheus/exporter/apache" // Import prometheus.exporter.apache
132133
_ "github.com/grafana/alloy/internal/component/prometheus/exporter/azure" // Import prometheus.exporter.azure

0 commit comments

Comments
 (0)