Skip to content

Commit

Permalink
OpAMP agent type, version, and UID from collector resource and buildi…
Browse files Browse the repository at this point in the history
…nfo (#1260)

* opamp agent type and version from collector resource and buildinfo

Signed-off-by: Sean Porter <[email protected]>

* changelog entry for #1260

Signed-off-by: Sean Porter <[email protected]>

* upgrade collector components to 0.86.0

Signed-off-by: Sean Porter <[email protected]>

---------

Signed-off-by: Sean Porter <[email protected]>
  • Loading branch information
portertech authored Oct 3, 2023
1 parent dab924b commit 02c72a4
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 25 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- chore: update otelcol core to `v0.86.0` [#1264]
- chore(ci): build fips binary w/ glibc 2.26 [#1257]
- feat(opampextension): opamp agent type, version, and uid from collector resource and build info [#1260]

### Fixed

Expand All @@ -28,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

[#1249]: https://github.com/SumoLogic/sumologic-otel-collector/pull/1249
[#1257]: https://github.com/SumoLogic/sumologic-otel-collector/pull/1257
[#1260]: https://github.com/SumoLogic/sumologic-otel-collector/pull/1260
[#1264]: https://github.com/SumoLogic/sumologic-otel-collector/pull/1264
[#1265]: https://github.com/SumoLogic/sumologic-otel-collector/pull/1265
[#1268]: https://github.com/SumoLogic/sumologic-otel-collector/pull/1268
Expand Down
2 changes: 1 addition & 1 deletion pkg/extension/opampextension/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ func createDefaultConfig() component.Config {
}

func createExtension(_ context.Context, set extension.CreateSettings, cfg component.Config) (extension.Extension, error) {
return newOpampAgent(cfg.(*Config), set.Logger)
return newOpampAgent(cfg.(*Config), set.Logger, set.BuildInfo, set.Resource)
}
3 changes: 2 additions & 1 deletion pkg/extension/opampextension/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ require (
go.opentelemetry.io/collector/config/confighttp v0.86.0
go.opentelemetry.io/collector/confmap v0.86.0
go.opentelemetry.io/collector/extension v0.86.0
go.opentelemetry.io/collector/pdata v1.0.0-rcv0015
go.opentelemetry.io/collector/semconv v0.86.0
go.uber.org/zap v1.26.0
)

Expand Down Expand Up @@ -57,7 +59,6 @@ require (
go.opentelemetry.io/collector/config/internal v0.86.0 // indirect
go.opentelemetry.io/collector/extension/auth v0.86.0 // indirect
go.opentelemetry.io/collector/featuregate v1.0.0-rcv0015 // indirect
go.opentelemetry.io/collector/pdata v1.0.0-rcv0015 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.44.0 // indirect
go.opentelemetry.io/otel v1.18.0 // indirect
go.opentelemetry.io/otel/metric v1.18.0 // indirect
Expand Down
11 changes: 2 additions & 9 deletions pkg/extension/opampextension/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ github.com/knadh/koanf/providers/rawbytes v0.1.0 h1:dpzgu2KO6uf6oCb4aP05KDmKmAmI
github.com/knadh/koanf/providers/rawbytes v0.1.0/go.mod h1:mMTB1/IcJ/yE++A2iEZbY1MLygX7vttU+C+S/YmPu9c=
github.com/knadh/koanf/v2 v2.0.1 h1:1dYGITt1I23x8cfx8ZnldtezdyaZtfAuRtIFOiRzK7g=
github.com/knadh/koanf/v2 v2.0.1/go.mod h1:ZeiIlIDXTE7w1lMT6UVcNiRAS2/rCeLn/GdLNvY1Dus=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4=
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
Expand All @@ -60,8 +58,6 @@ github.com/mitchellh/mapstructure v1.5.1-0.20220423185008-bf980b35cac4 h1:BpfhmL
github.com/mitchellh/mapstructure v1.5.1-0.20220423185008-bf980b35cac4/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/oklog/ulid/v2 v2.1.0 h1:+9lhoxAP56we25tyYETBBY1YLA2SaoLvUFgrP2miPJU=
github.com/oklog/ulid/v2 v2.1.0/go.mod h1:rcEKHmBBKfef9DhnvX7y1HZBYxjXb0cP5ExxNsTT1QQ=
github.com/open-telemetry/opamp-go v0.5.0 h1:2YFbb6G4qBkq3yTRdVb5Nfz9hKHW/ldUyex352e1J7g=
Expand All @@ -71,14 +67,12 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw=
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rs/cors v1.10.0 h1:62NOS1h+r8p1mW6FM0FSB0exioXLhd/sh15KpjWBZ+8=
github.com/rs/cors v1.10.0/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
github.com/shirou/gopsutil/v3 v3.23.8 h1:xnATPiybo6GgdRoC4YoGnxXZFRc3dqQTGi73oLvvBrE=
github.com/shirou/gopsutil/v3 v3.23.8/go.mod h1:7hmCaBn+2ZwaZOr6jmPBZDfawwMGuo1id3C6aM8EDqQ=
github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM=
github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ=
github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU=
github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
Expand Down Expand Up @@ -115,7 +109,6 @@ go.opentelemetry.io/collector/config/internal v0.86.0 h1:r4LnOMxXmnKwAMaSX16bPe1
go.opentelemetry.io/collector/config/internal v0.86.0/go.mod h1:42VsQ/1kP2qnvzjNi+dfNP+KyCFRADejyrJ8m2GVL3M=
go.opentelemetry.io/collector/confmap v0.86.0 h1:u3qXVuIz2cmH/rb2teX0Ft/OKYHgObv1e4OQ2UXqxrE=
go.opentelemetry.io/collector/confmap v0.86.0/go.mod h1:vJms49x98lXUR7Mj6/28eXV+Otn3dDQpc+Znvex9Z84=
go.opentelemetry.io/collector/consumer v0.86.0 h1:8AL9I30tJV01KfcSaa+8DTiARIiUDA8o2p7yQoSFUCs=
go.opentelemetry.io/collector/extension v0.86.0 h1:oXnZarkh1aBgnr/U3JSj/lPpBJUquOQ3DHMXXP4Jacc=
go.opentelemetry.io/collector/extension v0.86.0/go.mod h1:EPAloXQ+48577GvHTP5wGDvV4OyHPuldvM+2rYbM/fw=
go.opentelemetry.io/collector/extension/auth v0.86.0 h1:VwKbeElL8sBnvRDC565EWOw4ixMG/t0oXjIphNsRszU=
Expand All @@ -124,6 +117,8 @@ go.opentelemetry.io/collector/featuregate v1.0.0-rcv0015 h1:Wv8JFRUD01MwWkhZwF85
go.opentelemetry.io/collector/featuregate v1.0.0-rcv0015/go.mod h1:fLmJMf1AoHttkF8p5oJAc4o5ZpHu8yO5XYJ7gbLCLzo=
go.opentelemetry.io/collector/pdata v1.0.0-rcv0015 h1:8PzrQFk3oKiT1Sd5EmNEcagdMyt1KcBy5/OyF5He5gY=
go.opentelemetry.io/collector/pdata v1.0.0-rcv0015/go.mod h1:I1PqyHJlsXjANC73tp43nDId7/jiv82NoZZ6uS0xdwM=
go.opentelemetry.io/collector/semconv v0.86.0 h1:bLlPe/JYNjQHo744cqi7iIEybuLv+M5DntUwQPTrvZo=
go.opentelemetry.io/collector/semconv v0.86.0/go.mod h1:j/8THcqVxFna1FpvA2zYIsUperEtOaRaqoLYIN4doWw=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.44.0 h1:KfYpVmrjI7JuToy5k8XV3nkapjWx48k4E4JOtVstzQI=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.44.0/go.mod h1:SeQhzAEccGVZVEy7aH87Nh0km+utSpo1pTv6eMMop48=
go.opentelemetry.io/otel v1.18.0 h1:TgVozPGZ01nHyDZxK5WGPFB9QexeTMXEH7+tIClWfzs=
Expand All @@ -132,7 +127,6 @@ go.opentelemetry.io/otel/metric v1.18.0 h1:JwVzw94UYmbx3ej++CwLUQZxEODDj/pOuTCvz
go.opentelemetry.io/otel/metric v1.18.0/go.mod h1:nNSpsVDjWGfb7chbRLUNW+PBNdcSTHD4Uu5pfFMOI0k=
go.opentelemetry.io/otel/trace v1.18.0 h1:NY+czwbHbmndxojTEKiSMHkG2ClNH2PwmcHrdo0JY10=
go.opentelemetry.io/otel/trace v1.18.0/go.mod h1:T2+SGJGuYZY3bjj5rgh/hN7KIrlpWC5nS8Mjvzckz+0=
go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo=
Expand Down Expand Up @@ -182,7 +176,6 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
33 changes: 29 additions & 4 deletions pkg/extension/opampextension/opamp_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import (
"github.com/open-telemetry/opamp-go/client"
"github.com/open-telemetry/opamp-go/client/types"
"github.com/open-telemetry/opamp-go/protobufs"
"go.opentelemetry.io/collector/pdata/pcommon"
semconv "go.opentelemetry.io/collector/semconv/v1.18.0"

"github.com/SumoLogic/sumologic-otel-collector/pkg/extension/sumologicextension"
)
Expand Down Expand Up @@ -227,8 +229,31 @@ func (o *opampAgent) watchCredentials(ctx context.Context, callback func(ctx con
return nil
}

func newOpampAgent(cfg *Config, logger *zap.Logger) (*opampAgent, error) {
uid := ulid.Make() // TODO: Replace with https://github.com/open-telemetry/opentelemetry-collector/issues/6599
func newOpampAgent(cfg *Config, logger *zap.Logger, build component.BuildInfo, res pcommon.Resource) (*opampAgent, error) {
agentType := build.Command

sn, ok := res.Attributes().Get(semconv.AttributeServiceName)
if ok {
agentType = sn.AsString()
}

agentVersion := build.Version

sv, ok := res.Attributes().Get(semconv.AttributeServiceVersion)
if ok {
agentVersion = sv.AsString()
}

uid := ulid.Make()

sid, ok := res.Attributes().Get(semconv.AttributeServiceInstanceID)
if ok {
puid, err := ulid.Parse(sid.AsString())
if err != nil {
return nil, err
}
uid = puid
}

if cfg.InstanceUID != "" {
puid, err := ulid.Parse(cfg.InstanceUID)
Expand All @@ -241,8 +266,8 @@ func newOpampAgent(cfg *Config, logger *zap.Logger) (*opampAgent, error) {
agent := &opampAgent{
cfg: cfg,
logger: logger,
agentType: "io.opentelemetry.collector",
agentVersion: "1.0.0", // TODO: Replace with actual collector version info.
agentType: agentType,
agentVersion: agentVersion,
instanceId: uid,
}

Expand Down
40 changes: 30 additions & 10 deletions pkg/extension/opampextension/opamp_agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,44 @@ import (
"github.com/oklog/ulid/v2"
"github.com/open-telemetry/opamp-go/protobufs"
"github.com/stretchr/testify/assert"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/extension/extensiontest"
semconv "go.opentelemetry.io/collector/semconv/v1.18.0"
)

func TestNewOpampAgent(t *testing.T) {
cfg := createDefaultConfig()
set := extensiontest.NewNopCreateSettings()
o, err := newOpampAgent(cfg.(*Config), set.Logger)
set.BuildInfo = component.BuildInfo{Version: "test version", Command: "otelcoltest"}
o, err := newOpampAgent(cfg.(*Config), set.Logger, set.BuildInfo, set.Resource)
assert.NoError(t, err)
assert.Equal(t, o.agentType, "otelcoltest")
assert.Equal(t, o.agentVersion, "test version")
assert.NotEmpty(t, o.instanceId.String())
assert.Empty(t, o.effectiveConfig)
assert.Nil(t, o.agentDescription)
}

func TestNewOpampAgentAttributes(t *testing.T) {
cfg := createDefaultConfig()
set := extensiontest.NewNopCreateSettings()
set.BuildInfo = component.BuildInfo{Version: "test version", Command: "otelcoltest"}
set.Resource.Attributes().PutStr(semconv.AttributeServiceName, "otelcol-sumo")
set.Resource.Attributes().PutStr(semconv.AttributeServiceVersion, "sumo.0")
set.Resource.Attributes().PutStr(semconv.AttributeServiceInstanceID, "01BX5ZZKBKACTAV9WEVGEMMVRZ")
o, err := newOpampAgent(cfg.(*Config), set.Logger, set.BuildInfo, set.Resource)
assert.NoError(t, err)
assert.Equal(t, o.agentType, "otelcol-sumo")
assert.Equal(t, o.agentVersion, "sumo.0")
assert.Equal(t, o.instanceId.String(), "01BX5ZZKBKACTAV9WEVGEMMVRZ")
}

func TestCreateAgentDescription(t *testing.T) {
cfg := createDefaultConfig()
set := extensiontest.NewNopCreateSettings()
o, err := newOpampAgent(cfg.(*Config), set.Logger)
o, err := newOpampAgent(cfg.(*Config), set.Logger, set.BuildInfo, set.Resource)
assert.NoError(t, err)

assert.Nil(t, o.agentDescription)
Expand All @@ -51,7 +71,7 @@ func TestCreateAgentDescription(t *testing.T) {
func TestLoadEffectiveConfig(t *testing.T) {
cfg := createDefaultConfig()
set := extensiontest.NewNopCreateSettings()
o, err := newOpampAgent(cfg.(*Config), set.Logger)
o, err := newOpampAgent(cfg.(*Config), set.Logger, set.BuildInfo, set.Resource)
assert.NoError(t, err)

assert.Empty(t, o.effectiveConfig)
Expand All @@ -64,7 +84,7 @@ func TestLoadEffectiveConfig(t *testing.T) {
func TestSaveEffectiveConfig(t *testing.T) {
cfg := createDefaultConfig()
set := extensiontest.NewNopCreateSettings()
o, err := newOpampAgent(cfg.(*Config), set.Logger)
o, err := newOpampAgent(cfg.(*Config), set.Logger, set.BuildInfo, set.Resource)
assert.NoError(t, err)

f, err := os.CreateTemp("", "opamp-remote-config.yaml")
Expand All @@ -77,7 +97,7 @@ func TestSaveEffectiveConfig(t *testing.T) {
func TestUpdateAgentIdentity(t *testing.T) {
cfg := createDefaultConfig()
set := extensiontest.NewNopCreateSettings()
o, err := newOpampAgent(cfg.(*Config), set.Logger)
o, err := newOpampAgent(cfg.(*Config), set.Logger, set.BuildInfo, set.Resource)
assert.NoError(t, err)

olduid := o.instanceId
Expand All @@ -93,7 +113,7 @@ func TestUpdateAgentIdentity(t *testing.T) {
func TestComposeEffectiveConfig(t *testing.T) {
cfg := createDefaultConfig()
set := extensiontest.NewNopCreateSettings()
o, err := newOpampAgent(cfg.(*Config), set.Logger)
o, err := newOpampAgent(cfg.(*Config), set.Logger, set.BuildInfo, set.Resource)
assert.NoError(t, err)

ec := o.composeEffectiveConfig()
Expand All @@ -103,7 +123,7 @@ func TestComposeEffectiveConfig(t *testing.T) {
func TestApplyRemoteConfig(t *testing.T) {
cfg := createDefaultConfig()
set := extensiontest.NewNopCreateSettings()
o, err := newOpampAgent(cfg.(*Config), set.Logger)
o, err := newOpampAgent(cfg.(*Config), set.Logger, set.BuildInfo, set.Resource)
assert.NoError(t, err)

assert.Empty(t, o.effectiveConfig)
Expand Down Expand Up @@ -133,7 +153,7 @@ func TestShutdown(t *testing.T) {
cfg := createDefaultConfig().(*Config)
cfg.HTTPClientSettings.Auth = nil
set := extensiontest.NewNopCreateSettings()
o, err := newOpampAgent(cfg, set.Logger)
o, err := newOpampAgent(cfg, set.Logger, set.BuildInfo, set.Resource)
assert.NoError(t, err)

// Shutdown with no OpAMP client
Expand All @@ -144,7 +164,7 @@ func TestStart(t *testing.T) {
cfg := createDefaultConfig().(*Config)
cfg.HTTPClientSettings.Auth = nil
set := extensiontest.NewNopCreateSettings()
o, err := newOpampAgent(cfg, set.Logger)
o, err := newOpampAgent(cfg, set.Logger, set.BuildInfo, set.Resource)
assert.NoError(t, err)

assert.NoError(t, o.Start(context.Background(), componenttest.NewNopHost()))
Expand All @@ -154,7 +174,7 @@ func TestReload(t *testing.T) {
cfg := createDefaultConfig().(*Config)
cfg.HTTPClientSettings.Auth = nil
set := extensiontest.NewNopCreateSettings()
o, err := newOpampAgent(cfg, set.Logger)
o, err := newOpampAgent(cfg, set.Logger, set.BuildInfo, set.Resource)
assert.NoError(t, err)

ctx := context.Background()
Expand Down

0 comments on commit 02c72a4

Please sign in to comment.