Skip to content

Commit 0ad467d

Browse files
authored
Add the ability to set headers in the opamp bridge config (#2413)
* add headers to bridge config and include test for parsing config from yaml * headers to own type and make translation method a method on the headers type * rename file to headers.go, s/ToHttpHeader/ToHTTPHeader * add changelog * add copyright header
1 parent 36a4933 commit 0ad467d

File tree

6 files changed

+91
-0
lines changed

6 files changed

+91
-0
lines changed
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
2+
change_type: enhancement
3+
4+
# The name of the component, or a single word describing the area of concern, (e.g. operator, target allocator, github action)
5+
component: bridge
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: adds request headers to the opamp bridge config
9+
10+
# One or more tracking issues related to the change
11+
issues: [2410]
12+
13+
# (Optional) One or more lines of additional information to render under the primary note.
14+
# These lines will be padded with 2 spaces and then inserted directly into the document.
15+
# Use pipe (|) for multiline entries.
16+
subtext:

cmd/operator-opamp-bridge/agent/agent.go

+1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ func (agent *Agent) Start() error {
146146
agent.startTime = uint64(agent.clock.Now().UnixNano())
147147
settings := types.StartSettings{
148148
OpAMPServerURL: agent.config.Endpoint,
149+
Header: agent.config.Headers.ToHTTPHeader(),
149150
InstanceUid: agent.instanceId.String(),
150151
Callbacks: types.CallbacksStruct{
151152
OnConnectFunc: agent.onConnect,

cmd/operator-opamp-bridge/config/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ type Config struct {
9494
// ComponentsAllowed is a list of allowed OpenTelemetry components for each pipeline type (receiver, processor, etc.)
9595
ComponentsAllowed map[string][]string `yaml:"componentsAllowed,omitempty"`
9696
Endpoint string `yaml:"endpoint"`
97+
Headers Headers `yaml:"headers,omitempty"`
9798
Capabilities map[Capability]bool `yaml:"capabilities"`
9899
HeartbeatInterval time.Duration `yaml:"heartbeatInterval,omitempty"`
99100
Name string `yaml:"name,omitempty"`

cmd/operator-opamp-bridge/config/config_test.go

+29
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,35 @@ func TestLoad(t *testing.T) {
135135
return assert.ErrorContains(t, err, "error unmarshaling YAML", i...)
136136
},
137137
},
138+
{
139+
name: "base case with headers",
140+
args: args{
141+
file: "./testdata/agentwithheaders.yaml",
142+
},
143+
want: &Config{
144+
RootLogger: logr.Discard(),
145+
Endpoint: "ws://127.0.0.1:4320/v1/opamp",
146+
Headers: map[string]string{
147+
"authentication": "access-12345-token",
148+
"my-header-key": "my-header-value",
149+
},
150+
Capabilities: map[Capability]bool{
151+
AcceptsRemoteConfig: true,
152+
ReportsEffectiveConfig: true,
153+
ReportsOwnTraces: true,
154+
ReportsOwnMetrics: true,
155+
ReportsOwnLogs: true,
156+
AcceptsOpAMPConnectionSettings: true,
157+
AcceptsOtherConnectionSettings: true,
158+
AcceptsRestartCommand: true,
159+
ReportsHealth: true,
160+
ReportsRemoteConfig: true,
161+
AcceptsPackages: false,
162+
ReportsPackageStatuses: false,
163+
},
164+
},
165+
wantErr: assert.NoError,
166+
},
138167
}
139168
for _, tt := range tests {
140169
t.Run(tt.name, func(t *testing.T) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright The OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package config
16+
17+
import "net/http"
18+
19+
type Headers map[string]string
20+
21+
func (h Headers) ToHTTPHeader() http.Header {
22+
newMap := make(map[string][]string)
23+
for key, value := range h {
24+
newMap[key] = []string{value}
25+
}
26+
return newMap
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
endpoint: ws://127.0.0.1:4320/v1/opamp
2+
headers:
3+
authentication: "access-12345-token"
4+
my-header-key: "my-header-value"
5+
capabilities:
6+
AcceptsRemoteConfig: true
7+
ReportsEffectiveConfig: true
8+
AcceptsPackages: false
9+
ReportsPackageStatuses: false
10+
ReportsOwnTraces: true
11+
ReportsOwnMetrics: true
12+
ReportsOwnLogs: true
13+
AcceptsOpAMPConnectionSettings: true
14+
AcceptsOtherConnectionSettings: true
15+
AcceptsRestartCommand: true
16+
ReportsHealth: true
17+
ReportsRemoteConfig: true

0 commit comments

Comments
 (0)