Skip to content

Commit 5cde352

Browse files
authored
[cmd/opampsupervisor] support headers configuration for own telemetry (#37353)
This updates the configuration for reporting the collector's own telemetry to utilize the headers configuration passed in via opamp Follows #37346 --------- Signed-off-by: Alex Boten <[email protected]>
1 parent bb6e0ef commit 5cde352

File tree

4 files changed

+59
-14
lines changed

4 files changed

+59
-14
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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. filelogreceiver)
7+
component: opampsupervisor
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: add support for headers configuration for reporting own telemetry
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [37353]
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+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: []

cmd/opampsupervisor/supervisor/supervisor.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -869,19 +869,16 @@ func (s *Supervisor) setupOwnMetrics(_ context.Context, settings *protobufs.Tele
869869
} else {
870870
s.logger.Debug("Enabling own metrics pipeline in the config")
871871

872-
port, err := s.findRandomPort()
873-
if err != nil {
874-
s.logger.Error("Could not setup own metrics", zap.Error(err))
875-
return
872+
data := map[string]any{
873+
"MetricsEndpoint": settings.DestinationEndpoint,
874+
"MetricsHeaders": []protobufs.Header{},
876875
}
877876

878-
err = s.ownTelemetryTemplate.Execute(
879-
&cfg,
880-
map[string]any{
881-
"PrometheusPort": port,
882-
"MetricsEndpoint": settings.DestinationEndpoint,
883-
},
884-
)
877+
if settings.Headers != nil {
878+
data["MetricsHeaders"] = settings.Headers.Headers
879+
}
880+
881+
err := s.ownTelemetryTemplate.Execute(&cfg, data)
885882
if err != nil {
886883
s.logger.Error("Could not setup own metrics", zap.Error(err))
887884
return

cmd/opampsupervisor/supervisor/supervisor_test.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,13 @@ func Test_onMessage(t *testing.T) {
357357
},
358358
},
359359
OwnMetricsConnSettings: &protobufs.TelemetryConnectionSettings{
360-
DestinationEndpoint: "http://localhost:4318",
360+
DestinationEndpoint: "http://127.0.0.1:4318",
361+
Headers: &protobufs.Headers{
362+
Headers: []*protobufs.Header{
363+
{Key: "testkey", Value: "testval"},
364+
{Key: "testkey2", Value: "testval2"},
365+
},
366+
},
361367
},
362368
})
363369

@@ -1125,7 +1131,13 @@ func TestSupervisor_setupOwnMetrics(t *testing.T) {
11251131
require.NoError(t, err)
11261132

11271133
configChanged := s.setupOwnMetrics(context.Background(), &protobufs.TelemetryConnectionSettings{
1128-
DestinationEndpoint: "localhost",
1134+
DestinationEndpoint: "http://127.0.0.1:4318",
1135+
Headers: &protobufs.Headers{
1136+
Headers: []*protobufs.Header{
1137+
{Key: "testkey", Value: "testval"},
1138+
{Key: "testkey2", Value: "testval2"},
1139+
},
1140+
},
11291141
})
11301142

11311143
expectedOwnMetricsSection := `
@@ -1137,7 +1149,10 @@ service:
11371149
exporter:
11381150
otlp:
11391151
protocol: http/protobuf
1140-
endpoint: localhost
1152+
endpoint: http://127.0.0.1:4318
1153+
headers:
1154+
"testkey": "testval"
1155+
"testkey2": "testval2"
11411156
`
11421157

11431158
assert.True(t, configChanged)

cmd/opampsupervisor/supervisor/templates/owntelemetry.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@ service:
88
otlp:
99
protocol: http/protobuf
1010
endpoint: {{.MetricsEndpoint}}
11+
{{- if .MetricsHeaders}}
12+
headers:
13+
{{- range $k := .MetricsHeaders}}
14+
"{{$k.Key}}": "{{$k.Value}}"
15+
{{- end}}
16+
{{- end}}

0 commit comments

Comments
 (0)