Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpAMP Agent Extension #16594

Merged
merged 70 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
df750c9
opamp agent extension, hello world
portertech Dec 2, 2022
952cff6
opamp agent extension, agent id and description
portertech Dec 2, 2022
185e8c3
opamp agent extension, update agent id
portertech Dec 2, 2022
27740ad
opamp agent extension, compose effective config
portertech Dec 2, 2022
fc6beb3
opamp agent extension, start and shutdown
portertech Dec 2, 2022
c816932
opamp agent extension, changelog
portertech Dec 2, 2022
9b4e0da
opamp agent extension, config doc nit
portertech Dec 2, 2022
9a2619b
opamp agent extension, improved uid validation, use shutdown ctx
portertech Dec 29, 2022
3437a4a
opamp agent extension, removed ReportsEffectiveConfig capability
portertech Aug 3, 2023
5d6b34b
Merge branch 'main' into feature/opamp-extension
portertech Aug 3, 2023
c8a8c3e
opamp agent extension, upgraded collector to v0.82.0 and opamp-go to …
portertech Aug 3, 2023
029360a
Merge branch 'main' into feature/opamp-extension
portertech Aug 8, 2023
48428d2
Merge branch 'main' into feature/opamp-extension
portertech Sep 28, 2023
92f1488
opamp agent extension, dropped unnecessary logger interface
portertech Sep 28, 2023
859736d
opamp agent extension, report agent status capability
portertech Sep 28, 2023
c3ae9e6
opamp agent extension, go 1.20
portertech Sep 28, 2023
390621e
opamp agent extension, use buildinfo and resource
portertech Sep 28, 2023
3d6d560
opamp agent extension, attempt to get agent type and version from
portertech Sep 29, 2023
1659320
opamp agent extension, support http client settings
portertech Sep 29, 2023
924ed2d
opamp agent extension, apply http headers and tls
portertech Sep 29, 2023
fe2278d
Merge branch 'main' into feature/opamp-extension
portertech Sep 29, 2023
9f86052
Merge branch 'main' into feature/opamp-extension
portertech Sep 29, 2023
911382d
opamp agent extension, metadata.yaml
portertech Sep 29, 2023
afce5a6
opamp agent extension, github codeowners and readme
portertech Sep 29, 2023
6f36984
opamp agent extension, github issue templates
portertech Sep 29, 2023
8d78a13
opamp agent extension, added to versions.yaml
portertech Sep 29, 2023
a2f32ab
opamp agent extension, pr make commands
portertech Sep 29, 2023
ee3e513
opamp agent extension, make checkdoc
portertech Sep 29, 2023
524bccc
Merge branch 'main' into feature/opamp-extension
portertech Sep 29, 2023
5ea9924
Update extension/opampextension/opamp_agent.go
portertech Oct 3, 2023
cd17ed1
opamp agent extension, update todos to reference #27293
portertech Oct 3, 2023
198e84d
Update extension/opampextension/opamp_agent.go
portertech Oct 3, 2023
0489a97
Update extension/opampextension/opamp_agent.go
portertech Oct 3, 2023
ca1d1d5
opamp agent extension, use LoadTLSConfig()
portertech Oct 3, 2023
52d83f1
opamp agent extension, return on new agent identity parse error
portertech Oct 3, 2023
84f6ec2
Update extension/opampextension/factory_test.go
portertech Oct 3, 2023
1b17172
Update extension/opampextension/config_test.go
portertech Oct 3, 2023
00d7b67
opamp agent extension, config instance_uid is optional
portertech Oct 3, 2023
e5c5c64
opamp agent extension, mutually exclusive instance uid, more attribut…
portertech Oct 3, 2023
72229c3
Update extension/opampextension/factory_test.go
portertech Oct 3, 2023
8743c3a
opamp agent extension, align with supervisor config
portertech Oct 3, 2023
e84b7fd
opamp agent extension, use semconv for identifying attributes
portertech Oct 3, 2023
096e856
opamp agent extension, added basic configuration and status to readme
portertech Oct 3, 2023
db3530b
Merge branch 'main' into feature/opamp-extension
portertech Oct 4, 2023
25e78ff
Merge branch 'main' into feature/opamp-extension
portertech Oct 5, 2023
61492fb
Merge branch 'main' into feature/opamp-extension
portertech Oct 6, 2023
572614a
opamp extension, service id uuid to agent ulid
portertech Oct 13, 2023
ec237bc
Merge branch 'main' into feature/opamp-extension
portertech Oct 13, 2023
30273a9
opamp agent extension, updated collector dep and license headers
portertech Oct 13, 2023
6f9b304
opamp agent extension, header opaque strings and lint fixes
portertech Oct 13, 2023
2b39482
Merge branch 'main' into feature/opamp-extension
portertech Oct 19, 2023
05ec3a2
opamp agent extension, gofmt for lint errors
portertech Oct 19, 2023
50c78af
opamp agent extension, go mod tidy and lint fix
portertech Oct 20, 2023
d277c16
opamp agent extension, component upgrade and lint fixes
portertech Oct 20, 2023
b581611
opamp agent extension, go mod tidy
portertech Oct 21, 2023
5ab82c2
Merge branch 'main' into feature/opamp-extension
portertech Oct 21, 2023
c271773
opamp agent extension, attempt to make the linter happy
portertech Oct 21, 2023
8c86826
Merge branch 'main' into feature/opamp-extension
portertech Oct 23, 2023
c6b3c39
opamp agent extension, collector bump and lint fix
portertech Oct 23, 2023
a340f99
opamp agent extension, one more collector version bump
portertech Oct 23, 2023
1f33f74
opamp agent extension, go mod tidy
portertech Oct 23, 2023
f3968e6
opamp agent extension, make gendependabot
portertech Oct 23, 2023
2d41a78
Merge branch 'main' into feature/opamp-extension
portertech Oct 24, 2023
301b838
opamp agent extension, make gendependabot
portertech Oct 24, 2023
02ff11f
Merge branch 'main' into feature/opamp-extension
portertech Oct 24, 2023
86351c5
Update extension/opampextension/opamp_agent.go
portertech Oct 25, 2023
2204190
Merge branch 'main' into feature/opamp-extension
portertech Oct 25, 2023
c3aaddb
opamp agent extension, use semconv os.type and host.arch as attributes
portertech Oct 25, 2023
3688953
opamp agent extension, make gendependabot
portertech Oct 25, 2023
4555060
Merge branch 'main' into feature/opamp-extension
portertech Oct 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .chloggen/add-opamp-agent-extension.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: new_component
portertech marked this conversation as resolved.
Show resolved Hide resolved

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add a new extension that implements an OpAMP agent for reporting the collector's health and effective configuration.

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

# (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 extension/opampextension/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../Makefile.Common
42 changes: 42 additions & 0 deletions extension/opampextension/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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 opampextension

import (
"errors"

"go.opentelemetry.io/collector/config"
)

// Config has the configuration for the opamp extension.
type Config struct {
config.ExtensionSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct

// Endpoint is the OpAMP server URL. Transport based on the scheme of the URL.
Endpoint string `mapstructure:"endpoint"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to explore if we can use HTTPClientSettings here. That will give us the ability to specify a bunch of client-side settings (headers, TLS, auth, etc). I don't know though if it works with WebSocket.
It probably is not going to help much since we can't use HTTPClientSettings.ToClient() anyway (and that is the most useful part of HTTPClientSettings), unless we somehow modify the OpAMP Client implementation to accept a pre-built HTTP Client.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest using the HTTPClientSettings that way auth is provided for free.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using HTTPClientSettings feels cumbersome and perhaps its going to be problematic. StartSettings (https://github.com/open-telemetry/opamp-go/blob/main/client/types/startsettings.go#L11) has me doing things like: 924ed2d. Also, most of the settings will go unused, which could be confusing since they will pass validation.


// InstanceUID is a ULID formatted as a 26 character string in canonical
// representation. Auto-generated on start if missing.
InstanceUID string `mapstructure:"instance_uid"`
}

// Validate checks if the extension configuration is valid
func (cfg *Config) Validate() error {
// no need to validate less than 0 case for uint64
if len(cfg.InstanceUID) > 26 {
portertech marked this conversation as resolved.
Show resolved Hide resolved
return errors.New("instance_uid has more than 26 characters")
}
return nil
}
56 changes: 56 additions & 0 deletions extension/opampextension/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// 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 opampextension

import (
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/confmap/confmaptest"
)

func TestUnmarshalDefaultConfig(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
assert.NoError(t, component.UnmarshalConfig(confmap.New(), cfg))
assert.Equal(t, factory.CreateDefaultConfig(), cfg)
}

func TestUnmarshalConfig(t *testing.T) {
cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
require.NoError(t, err)
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
assert.NoError(t, component.UnmarshalConfig(cm, cfg))
assert.Equal(t,
&Config{
ExtensionSettings: config.NewExtensionSettings(component.NewID(typeStr)),
Endpoint: "wss://127.0.0.1:4320/v1/opamp",
InstanceUID: "01BX5ZZKBKACTAV9WEVGEMMVRZ",
}, cfg)
}

func TestConfigValidate(t *testing.T) {
cfg := &Config{InstanceUID: "01BX5ZZKBKACTAV9WEVGEMMVRZFAIL"}
err := cfg.Validate()
require.Error(t, err)
assert.Equal(t, "instance_uid has more than 26 characters", err.Error())
}
portertech marked this conversation as resolved.
Show resolved Hide resolved
41 changes: 41 additions & 0 deletions extension/opampextension/factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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 opampextension

import (
"context"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config"
)

const (
// The value of extension "type" in configuration.
typeStr = "opamp"
)

portertech marked this conversation as resolved.
Show resolved Hide resolved
func NewFactory() component.ExtensionFactory {
return component.NewExtensionFactory(typeStr, createDefaultConfig, createExtension, component.StabilityLevelBeta)
}

func createDefaultConfig() component.ExtensionConfig {
return &Config{
ExtensionSettings: config.NewExtensionSettings(component.NewID(typeStr)),
}
}

func createExtension(_ context.Context, set component.ExtensionCreateSettings, cfg component.ExtensionConfig) (component.Extension, error) {
return newOpampAgent(cfg.(*Config), set.Logger)
}
44 changes: 44 additions & 0 deletions extension/opampextension/factory_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// 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 opampextension

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config"
)

func TestFactory_CreateDefaultConfig(t *testing.T) {
cfg := createDefaultConfig()
portertech marked this conversation as resolved.
Show resolved Hide resolved
assert.Equal(t, &Config{ExtensionSettings: config.NewExtensionSettings(component.NewID(typeStr))}, cfg)

assert.NoError(t, componenttest.CheckConfigStruct(cfg))
ext, err := createExtension(context.Background(), componenttest.NewNopExtensionCreateSettings(), cfg)
require.NoError(t, err)
require.NotNil(t, ext)
}

func TestFactory_CreateExtension(t *testing.T) {
cfg := createDefaultConfig().(*Config)
portertech marked this conversation as resolved.
Show resolved Hide resolved
ext, err := createExtension(context.Background(), componenttest.NewNopExtensionCreateSettings(), cfg)
require.NoError(t, err)
require.NotNil(t, ext)
}
44 changes: 44 additions & 0 deletions extension/opampextension/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module github.com/open-telemetry/opentelemetry-collector-contrib/extension/opampextension

go 1.18
portertech marked this conversation as resolved.
Show resolved Hide resolved

require (
github.com/stretchr/testify v1.8.1
go.opentelemetry.io/collector v0.66.1-0.20221202180633-b3e9d209d368
go.opentelemetry.io/collector/component v0.66.1-0.20221202180633-b3e9d209d368
go.uber.org/zap v1.24.0
)

require (
github.com/cenkalti/backoff/v4 v4.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/knadh/koanf v1.4.4 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/oklog/ulid/v2 v2.1.0 // indirect
github.com/open-telemetry/opamp-go v0.5.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.opentelemetry.io/collector/confmap v0.0.0-20221201172708-2bdff61fa52a // indirect
go.opentelemetry.io/collector/consumer v0.66.0 // indirect
go.opentelemetry.io/collector/featuregate v0.66.0 // indirect
go.opentelemetry.io/collector/pdata v0.66.0 // indirect
go.opentelemetry.io/otel v1.11.1 // indirect
go.opentelemetry.io/otel/metric v0.33.0 // indirect
go.opentelemetry.io/otel/trace v1.11.1 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
golang.org/x/sys v0.2.0 // indirect
golang.org/x/text v0.4.0 // indirect
google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa // indirect
google.golang.org/grpc v1.51.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading