Skip to content

Commit

Permalink
Add the ability to set headers in the opamp bridge config (open-telem…
Browse files Browse the repository at this point in the history
…etry#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
  • Loading branch information
jdcrouse authored and changexd committed Dec 5, 2023
1 parent d08896e commit 869c1f0
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 1 deletion.
16 changes: 16 additions & 0 deletions .chloggen/opamp-bridge-headers-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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. operator, target allocator, github action)
component: bridge

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: adds request headers to the opamp bridge config

# One or more tracking issues related to the change
issues: [2410]

# (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:
1 change: 1 addition & 0 deletions cmd/operator-opamp-bridge/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func (agent *Agent) Start() error {
agent.startTime = uint64(agent.clock.Now().UnixNano())
settings := types.StartSettings{
OpAMPServerURL: agent.config.Endpoint,
Header: agent.config.Headers.ToHTTPHeader(),
InstanceUid: agent.instanceId.String(),
Callbacks: types.CallbacksStruct{
OnConnectFunc: agent.onConnect,
Expand Down
1 change: 1 addition & 0 deletions cmd/operator-opamp-bridge/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ type Config struct {
// ComponentsAllowed is a list of allowed OpenTelemetry components for each pipeline type (receiver, processor, etc.)
ComponentsAllowed map[string][]string `yaml:"componentsAllowed,omitempty"`
Endpoint string `yaml:"endpoint"`
Headers Headers `yaml:"headers,omitempty"`
Capabilities map[Capability]bool `yaml:"capabilities"`
HeartbeatInterval time.Duration `yaml:"heartbeatInterval,omitempty"`
Name string `yaml:"name,omitempty"`
Expand Down
29 changes: 29 additions & 0 deletions cmd/operator-opamp-bridge/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,35 @@ func TestLoad(t *testing.T) {
return assert.ErrorContains(t, err, "error unmarshaling YAML", i...)
},
},
{
name: "base case with headers",
args: args{
file: "./testdata/agentwithheaders.yaml",
},
want: &Config{
RootLogger: logr.Discard(),
Endpoint: "ws://127.0.0.1:4320/v1/opamp",
Headers: map[string]string{
"authentication": "access-12345-token",
"my-header-key": "my-header-value",
},
Capabilities: map[Capability]bool{
AcceptsRemoteConfig: true,
ReportsEffectiveConfig: true,
ReportsOwnTraces: true,
ReportsOwnMetrics: true,
ReportsOwnLogs: true,
AcceptsOpAMPConnectionSettings: true,
AcceptsOtherConnectionSettings: true,
AcceptsRestartCommand: true,
ReportsHealth: true,
ReportsRemoteConfig: true,
AcceptsPackages: false,
ReportsPackageStatuses: false,
},
},
wantErr: assert.NoError,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
27 changes: 27 additions & 0 deletions cmd/operator-opamp-bridge/config/headers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package config

import "net/http"

type Headers map[string]string

func (h Headers) ToHTTPHeader() http.Header {
newMap := make(map[string][]string)
for key, value := range h {
newMap[key] = []string{value}
}
return newMap
}
17 changes: 17 additions & 0 deletions cmd/operator-opamp-bridge/config/testdata/agentwithheaders.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
endpoint: ws://127.0.0.1:4320/v1/opamp
headers:
authentication: "access-12345-token"
my-header-key: "my-header-value"
capabilities:
AcceptsRemoteConfig: true
ReportsEffectiveConfig: true
AcceptsPackages: false
ReportsPackageStatuses: false
ReportsOwnTraces: true
ReportsOwnMetrics: true
ReportsOwnLogs: true
AcceptsOpAMPConnectionSettings: true
AcceptsOtherConnectionSettings: true
AcceptsRestartCommand: true
ReportsHealth: true
ReportsRemoteConfig: true
2 changes: 1 addition & 1 deletion config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ kind: Kustomization
images:
- name: controller
newName: ghcr.io/darren_wang/opentelemetry-operator/opentelemetry-operator
newTag: 0.87.0-81-g4cc1f21
newTag: 0.89.0-33-ga38f309

0 comments on commit 869c1f0

Please sign in to comment.