Skip to content

Commit ecab38e

Browse files
portertechdjaglowskitigrannajaryan
authored andcommitted
OpAMP Agent Extension (open-telemetry#16594)
See [design document](https://docs.google.com/document/d/1KtH5atZQUs9Achbce6LiOaJxLbksNJenvgvyKLsJrkc/edit#heading=h.ioikt02qpy5f). Depends on: - [Implement ability for extensions to be notified about effective configuration opentelemetry-collector#6596](open-telemetry/opentelemetry-collector#6596) - [Make service.instance.id and other telemetry attributes available to extensions opentelemetry-collector#6599](open-telemetry/opentelemetry-collector#6599) Closes open-telemetry#16618 --------- Signed-off-by: Sean Porter <[email protected]> Co-authored-by: Daniel Jaglowski <[email protected]> Co-authored-by: Tigran Najaryan <[email protected]>
1 parent b7cd52e commit ecab38e

21 files changed

+1109
-11
lines changed
Lines changed: 16 additions & 0 deletions
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: new_component
3+
4+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
5+
component: extension/opampextension
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: Add a new extension that implements an OpAMP agent for reporting the collector's health and effective configuration.
9+
10+
# One or more tracking issues related to the change
11+
issues: [16462]
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:

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ extension/observer/ecstaskobserver/ @open-te
108108
extension/observer/hostobserver/ @open-telemetry/collector-contrib-approvers @MovieStoreGuy
109109
extension/observer/k8sobserver/ @open-telemetry/collector-contrib-approvers @rmfitzpatrick @dmitryax
110110
extension/oidcauthextension/ @open-telemetry/collector-contrib-approvers @jpkrohling
111+
extension/opampextension/ @open-telemetry/collector-contrib-approvers @portertech @evan-bradley @tigrannajaryan
111112
extension/pprofextension/ @open-telemetry/collector-contrib-approvers @MovieStoreGuy
112113
extension/sigv4authextension/ @open-telemetry/collector-contrib-approvers @Aneurysm9 @erichsueh3
113114
extension/storage/ @open-telemetry/collector-contrib-approvers @dmitryax @atoulme @djaglowski

.github/ISSUE_TEMPLATE/bug_report.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ body:
100100
- extension/observer/hostobserver
101101
- extension/observer/k8sobserver
102102
- extension/oidcauth
103+
- extension/opamp
103104
- extension/pprof
104105
- extension/sigv4auth
105106
- extension/storage

.github/ISSUE_TEMPLATE/feature_request.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ body:
9494
- extension/observer/hostobserver
9595
- extension/observer/k8sobserver
9696
- extension/oidcauth
97+
- extension/opamp
9798
- extension/pprof
9899
- extension/sigv4auth
99100
- extension/storage

.github/ISSUE_TEMPLATE/other.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ body:
9494
- extension/observer/hostobserver
9595
- extension/observer/k8sobserver
9696
- extension/oidcauth
97+
- extension/opamp
9798
- extension/pprof
9899
- extension/sigv4auth
99100
- extension/storage

.github/dependabot.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ updates:
88
interval: "weekly"
99
day: "wednesday"
1010
- package-ecosystem: "gomod"
11-
directory: "/cmd/githubgen"
11+
directory: "/cmd/otelcontribcol"
12+
schedule:
13+
interval: "weekly"
14+
day: "wednesday"
15+
- package-ecosystem: "gomod"
16+
directory: "/cmd/oteltestbedcol"
1217
schedule:
1318
interval: "weekly"
1419
day: "wednesday"
@@ -302,11 +307,6 @@ updates:
302307
schedule:
303308
interval: "weekly"
304309
day: "wednesday"
305-
- package-ecosystem: "gomod"
306-
directory: "/extension/encoding/jaegerencodingextension"
307-
schedule:
308-
interval: "weekly"
309-
day: "wednesday"
310310
- package-ecosystem: "gomod"
311311
directory: "/extension/headerssetterextension"
312312
schedule:
@@ -1012,11 +1012,6 @@ updates:
10121012
schedule:
10131013
interval: "weekly"
10141014
day: "wednesday"
1015-
- package-ecosystem: "gomod"
1016-
directory: "/receiver/splunkenterprisereceiver"
1017-
schedule:
1018-
interval: "weekly"
1019-
day: "wednesday"
10201015
- package-ecosystem: "gomod"
10211016
directory: "/receiver/splunkhecreceiver"
10221017
schedule:
@@ -1067,6 +1062,11 @@ updates:
10671062
schedule:
10681063
interval: "weekly"
10691064
day: "wednesday"
1065+
- package-ecosystem: "gomod"
1066+
directory: "/receiver/webhookeventreceiver"
1067+
schedule:
1068+
interval: "weekly"
1069+
day: "wednesday"
10701070
- package-ecosystem: "gomod"
10711071
directory: "/receiver/windowseventlogreceiver"
10721072
schedule:

extension/opampextension/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include ../../Makefile.Common

extension/opampextension/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# OpAMP Agent Extension
2+
<!-- status autogenerated section -->
3+
| Status | |
4+
| ------------- |-----------|
5+
| Stability | [development] |
6+
| Distributions | [] |
7+
| Issues | [![Open issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aopen%20label%3Aextension%2Fopamp%20&label=open&color=orange&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aopen+is%3Aissue+label%3Aextension%2Fopamp) [![Closed issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aclosed%20label%3Aextension%2Fopamp%20&label=closed&color=blue&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aclosed+is%3Aissue+label%3Aextension%2Fopamp) |
8+
| [Code Owners](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#becoming-a-code-owner) | [@portertech](https://www.github.com/portertech), [@evan-bradley](https://www.github.com/evan-bradley), [@tigrannajaryan](https://www.github.com/tigrannajaryan) |
9+
10+
[development]: https://github.com/open-telemetry/opentelemetry-collector#development
11+
<!-- end autogenerated section -->
12+
13+
## Configuration
14+
15+
The following settings are required:
16+
17+
- `server`: The OpAMP server connection settings.
18+
- `ws`: The OpAMP websocket transport settings.
19+
- `endpoint` (no default): The OpAMP server websocket endpoint (URL).
20+
21+
The following settings are optional:
22+
23+
- `server`: The OpAMP server connection settings.
24+
- `ws`: The OpAMP websocket transport settings.
25+
- `tls`: TLS settings.
26+
- `headers`: HTTP headers to set.
27+
- `instance_uid`: A ULID formatted as a 26 character string in canonical
28+
representation. Auto-generated on start if missing. Setting this ensures the
29+
instance UID remains constant across process restarts.
30+
31+
### Example
32+
33+
``` yaml
34+
extensions:
35+
opamp:
36+
server:
37+
ws:
38+
endpoint: wss://127.0.0.1:4320/v1/opamp
39+
```
40+
41+
## Status
42+
43+
This OpenTelemetry OpAMP agent extension is intended to support the [OpAMP
44+
Supervisor][supervisor].
45+
46+
[supervisor]: https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/cmd/opampsupervisor

extension/opampextension/config.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package opampextension // import "github.com/open-telemetry/opentelemetry-collector-contrib/extension/opampextension"
5+
6+
import (
7+
"errors"
8+
9+
"github.com/oklog/ulid/v2"
10+
"go.opentelemetry.io/collector/config/configopaque"
11+
"go.opentelemetry.io/collector/config/configtls"
12+
)
13+
14+
// Config contains the configuration for the opamp extension. Trying to mirror
15+
// the OpAMP supervisor config for some consistency.
16+
type Config struct {
17+
Server *OpAMPServer `mapstructure:"server"`
18+
19+
// InstanceUID is a ULID formatted as a 26 character string in canonical
20+
// representation. Auto-generated on start if missing.
21+
InstanceUID string `mapstructure:"instance_uid"`
22+
}
23+
24+
// OpAMPServer contains the OpAMP transport configuration.
25+
type OpAMPServer struct {
26+
WS *OpAMPWebsocket `mapstructure:"ws"`
27+
}
28+
29+
// OpAMPWebsocket contains the OpAMP websocket transport configuration.
30+
type OpAMPWebsocket struct {
31+
Endpoint string `mapstructure:"endpoint"`
32+
TLSSetting configtls.TLSClientSetting `mapstructure:"tls,omitempty"`
33+
Headers map[string]configopaque.String `mapstructure:"headers,omitempty"`
34+
}
35+
36+
// Validate checks if the extension configuration is valid
37+
func (cfg *Config) Validate() error {
38+
if cfg.Server.WS.Endpoint == "" {
39+
return errors.New("opamp server websocket endpoint must be provided")
40+
}
41+
42+
if cfg.InstanceUID != "" {
43+
_, err := ulid.ParseStrict(cfg.InstanceUID)
44+
if err != nil {
45+
return errors.New("opamp instance_uid is invalid")
46+
}
47+
}
48+
49+
return nil
50+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package opampextension
5+
6+
import (
7+
"path/filepath"
8+
"testing"
9+
10+
"github.com/stretchr/testify/assert"
11+
"github.com/stretchr/testify/require"
12+
"go.opentelemetry.io/collector/component"
13+
"go.opentelemetry.io/collector/confmap"
14+
"go.opentelemetry.io/collector/confmap/confmaptest"
15+
)
16+
17+
func TestUnmarshalDefaultConfig(t *testing.T) {
18+
factory := NewFactory()
19+
cfg := factory.CreateDefaultConfig()
20+
assert.NoError(t, component.UnmarshalConfig(confmap.New(), cfg))
21+
assert.Equal(t, factory.CreateDefaultConfig(), cfg)
22+
}
23+
24+
func TestUnmarshalConfig(t *testing.T) {
25+
cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
26+
require.NoError(t, err)
27+
factory := NewFactory()
28+
cfg := factory.CreateDefaultConfig()
29+
assert.NoError(t, component.UnmarshalConfig(cm, cfg))
30+
assert.Equal(t,
31+
&Config{
32+
Server: &OpAMPServer{
33+
WS: &OpAMPWebsocket{
34+
Endpoint: "wss://127.0.0.1:4320/v1/opamp",
35+
},
36+
},
37+
InstanceUID: "01BX5ZZKBKACTAV9WEVGEMMVRZ",
38+
}, cfg)
39+
}
40+
41+
func TestConfigValidate(t *testing.T) {
42+
cfg := &Config{
43+
Server: &OpAMPServer{
44+
WS: &OpAMPWebsocket{},
45+
},
46+
}
47+
err := cfg.Validate()
48+
assert.Equal(t, "opamp server websocket endpoint must be provided", err.Error())
49+
cfg.Server.WS.Endpoint = "wss://127.0.0.1:4320/v1/opamp"
50+
assert.NoError(t, cfg.Validate())
51+
cfg.InstanceUID = "01BX5ZZKBKACTAV9WEVGEMMVRZFAIL"
52+
err = cfg.Validate()
53+
require.Error(t, err)
54+
assert.Equal(t, "opamp instance_uid is invalid", err.Error())
55+
cfg.InstanceUID = "01BX5ZZKBKACTAV9WEVGEMMVRZ"
56+
require.NoError(t, cfg.Validate())
57+
}

0 commit comments

Comments
 (0)