Skip to content

Commit 279752c

Browse files
djaglowskimx-psi
andauthored
[service/internal/graph] Measure telemetry as it is passed between pipeline components (#12812)
Depends on #12856 Resolves #12676 This is a reboot of #11311, incorporating metrics defined in the [component telemetry RFC](https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/rfcs/component-universal-telemetry.md) and attributes added in #12617. The basic pattern is: - When building any pipeline component which produces data, wrap the "next consumer" with instrumentation to measure the number of items being passed. This wrapped consumer is then passed into the constructor of the component. - When building any pipeline component which consumes data, wrap the component itself. This wrapped consumer is saved onto the graph node so that it can be retrieved during graph assembly. --------- Co-authored-by: Pablo Baeyens <[email protected]>
1 parent 4ca0f18 commit 279752c

28 files changed

+1309
-137
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: service
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Add item count metrics defined in Pipeline Component Telemetry RFC
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [12812]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext: |
19+
See [Pipeline Component Telemetry RFC](https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/rfcs/component-universal-telemetry.md) for more details:
20+
- `otelcol.receiver.produced.items`
21+
- `otelcol.processor.consumed.items`
22+
- `otelcol.processor.produced.items`
23+
- `otelcol.connector.consumed.items`
24+
- `otelcol.connector.produced.items`
25+
- `otelcol.exporter.consumed.items`
26+
27+
# Optional: The change log or logs in which this entry should be included.
28+
# e.g. '[user]' or '[user, api]'
29+
# Include 'user' if the change is relevant to end users.
30+
# Include 'api' if there is a change to a library API.
31+
# Default: '[user]'
32+
change_logs: []

cmd/mdatagen/internal/metric.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ type Metric struct {
5959

6060
// Attributes is the list of attributes that the metric emits.
6161
Attributes []AttributeName `mapstructure:"attributes"`
62+
63+
// Override the default prefix for the metric name.
64+
Prefix string `mapstructure:"prefix"`
6265
}
6366

6467
type Stability struct {

cmd/mdatagen/internal/templates/documentation.md.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
{{- $metricName := . }}
3939
{{- $metric := $metricName | telemetryInfo -}}
4040

41-
### otelcol_{{ $metricName }}
41+
### {{ if $metric.Prefix -}}{{ $metric.Prefix }}{{- else -}}otelcol_{{- end -}}{{ $metricName }}
4242

4343
{{ $metric.Description }}{{ $metric.Stability }}
4444

cmd/mdatagen/internal/templates/telemetry.go.tmpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,11 @@ func NewTelemetryBuilder(settings component.TelemetrySettings, options ...Teleme
136136

137137
{{- range $name, $metric := .Telemetry.Metrics }}
138138
builder.{{ $name.Render }}, err = builder.meter.{{ $metric.Data.Instrument }}(
139+
{{ if $metric.Prefix -}}
140+
"{{ $metric.Prefix }}{{ $name }}",
141+
{{ else -}}
139142
"otelcol_{{ $name }}",
143+
{{ end -}}
140144
metric.WithDescription("{{ $metric.Description }}{{ $metric.Stability }}"),
141145
metric.WithUnit("{{ $metric.Unit }}"),
142146
{{ if eq $metric.Data.Type "Histogram" -}}

cmd/mdatagen/internal/templates/telemetrytest.go.tmpl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ return set
3232

3333
func AssertEqual{{ $name.Render }}(t *testing.T, tt *componenttest.Telemetry, dps []metricdata.{{- if eq $metric.Data.Type "Histogram" }} {{$metric.Data.Type}} {{- end }}DataPoint[{{ $metric.Data.BasicType }}], opts ...metricdatatest.Option) {
3434
want := metricdata.Metrics{
35+
{{ if $metric.Prefix -}}
36+
Name: "{{ $metric.Prefix }}{{ $name }}",
37+
{{ else -}}
3538
Name: "otelcol_{{ $name }}",
39+
{{ end -}}
3640
Description: "{{ $metric.Description }}{{ $metric.Stability }}",
3741
Unit: "{{ $metric.Unit }}",
3842
Data: metricdata.{{ $metric.Data.Type }}[{{ $metric.Data.BasicType }}]{
@@ -45,7 +49,11 @@ func AssertEqual{{ $name.Render }}(t *testing.T, tt *componenttest.Telemetry, dp
4549
DataPoints: dps,
4650
},
4751
}
52+
{{ if $metric.Prefix -}}
53+
got, err := tt.GetMetric("{{ $metric.Prefix }}{{ $name }}")
54+
{{ else -}}
4855
got, err := tt.GetMetric("otelcol_{{ $name }}")
56+
{{ end -}}
4957
require.NoError(t, err)
5058
metricdatatest.AssertEqual(t, want, got, opts...)
5159
}

service/documentation.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,30 @@
66

77
The following telemetry is emitted by this component.
88

9+
### otelcol.connector.consumed.items
10+
11+
Number of items passed to the connector.
12+
13+
| Unit | Metric Type | Value Type | Monotonic |
14+
| ---- | ----------- | ---------- | --------- |
15+
| {item} | Sum | Int | true |
16+
17+
### otelcol.connector.produced.items
18+
19+
Number of items emitted from the connector.
20+
21+
| Unit | Metric Type | Value Type | Monotonic |
22+
| ---- | ----------- | ---------- | --------- |
23+
| {item} | Sum | Int | true |
24+
25+
### otelcol.exporter.consumed.items
26+
27+
Number of items passed to the exporter.
28+
29+
| Unit | Metric Type | Value Type | Monotonic |
30+
| ---- | ----------- | ---------- | --------- |
31+
| {item} | Sum | Int | true |
32+
933
### otelcol_process_cpu_seconds
1034

1135
Total CPU user and system time in seconds [alpha]
@@ -53,3 +77,27 @@ Uptime of the process [alpha]
5377
| Unit | Metric Type | Value Type | Monotonic |
5478
| ---- | ----------- | ---------- | --------- |
5579
| s | Sum | Double | true |
80+
81+
### otelcol.processor.consumed.items
82+
83+
Number of items passed to the processor.
84+
85+
| Unit | Metric Type | Value Type | Monotonic |
86+
| ---- | ----------- | ---------- | --------- |
87+
| {item} | Sum | Int | true |
88+
89+
### otelcol.processor.produced.items
90+
91+
Number of items emitted from the processor.
92+
93+
| Unit | Metric Type | Value Type | Monotonic |
94+
| ---- | ----------- | ---------- | --------- |
95+
| {item} | Sum | Int | true |
96+
97+
### otelcol.receiver.produced.items
98+
99+
Number of items emitted from the receiver.
100+
101+
| Unit | Metric Type | Value Type | Monotonic |
102+
| ---- | ----------- | ---------- | --------- |
103+
| {item} | Sum | Int | true |

0 commit comments

Comments
 (0)