Skip to content

Commit

Permalink
[cmd/opampsupervisor] support headers configuration for own telemetry (
Browse files Browse the repository at this point in the history
…#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]>
  • Loading branch information
codeboten authored Jan 24, 2025
1 parent bb6e0ef commit 5cde352
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 14 deletions.
27 changes: 27 additions & 0 deletions .chloggen/codeboten_add-support-for-headers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: opampsupervisor

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: add support for headers configuration for reporting own telemetry

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [37353]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
19 changes: 8 additions & 11 deletions cmd/opampsupervisor/supervisor/supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -869,19 +869,16 @@ func (s *Supervisor) setupOwnMetrics(_ context.Context, settings *protobufs.Tele
} else {
s.logger.Debug("Enabling own metrics pipeline in the config")

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

err = s.ownTelemetryTemplate.Execute(
&cfg,
map[string]any{
"PrometheusPort": port,
"MetricsEndpoint": settings.DestinationEndpoint,
},
)
if settings.Headers != nil {
data["MetricsHeaders"] = settings.Headers.Headers
}

err := s.ownTelemetryTemplate.Execute(&cfg, data)
if err != nil {
s.logger.Error("Could not setup own metrics", zap.Error(err))
return
Expand Down
21 changes: 18 additions & 3 deletions cmd/opampsupervisor/supervisor/supervisor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,13 @@ func Test_onMessage(t *testing.T) {
},
},
OwnMetricsConnSettings: &protobufs.TelemetryConnectionSettings{
DestinationEndpoint: "http://localhost:4318",
DestinationEndpoint: "http://127.0.0.1:4318",
Headers: &protobufs.Headers{
Headers: []*protobufs.Header{
{Key: "testkey", Value: "testval"},
{Key: "testkey2", Value: "testval2"},
},
},
},
})

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

configChanged := s.setupOwnMetrics(context.Background(), &protobufs.TelemetryConnectionSettings{
DestinationEndpoint: "localhost",
DestinationEndpoint: "http://127.0.0.1:4318",
Headers: &protobufs.Headers{
Headers: []*protobufs.Header{
{Key: "testkey", Value: "testval"},
{Key: "testkey2", Value: "testval2"},
},
},
})

expectedOwnMetricsSection := `
Expand All @@ -1137,7 +1149,10 @@ service:
exporter:
otlp:
protocol: http/protobuf
endpoint: localhost
endpoint: http://127.0.0.1:4318
headers:
"testkey": "testval"
"testkey2": "testval2"
`

assert.True(t, configChanged)
Expand Down
6 changes: 6 additions & 0 deletions cmd/opampsupervisor/supervisor/templates/owntelemetry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ service:
otlp:
protocol: http/protobuf
endpoint: {{.MetricsEndpoint}}
{{- if .MetricsHeaders}}
headers:
{{- range $k := .MetricsHeaders}}
"{{$k.Key}}": "{{$k.Value}}"
{{- end}}
{{- end}}

0 comments on commit 5cde352

Please sign in to comment.