From f37e810d7f066d92c6165dbe1d6c5e875a5a9282 Mon Sep 17 00:00:00 2001 From: Brandon Johnson Date: Thu, 24 Oct 2024 08:50:34 -0400 Subject: [PATCH] deps: Upgrade opamp v0.17.0 (#1906) * update opamp to v0.14.0 * properly handle agent ID * Pass to bindplane with header specifying format * Bump opamp-go to v0.17.0 * bump to opamp-go v0.17.0 * add reports heartbeat capability * Add tests for agent ID parsing * lint * Remove reports heartbeat capability --- cmd/collector/main.go | 30 ++- cmd/collector/main_test.go | 32 +-- go.mod | 4 +- go.sum | 8 +- opamp/config.go | 110 +++++++- opamp/config_test.go | 246 ++++++++++++++---- opamp/mocks/mock_opamp_client.go | 5 + opamp/mocks/mock_packages_state_provider.go | 10 +- opamp/observiq/identity.go | 4 +- opamp/observiq/identity_test.go | 22 +- opamp/observiq/observiq_client.go | 17 +- opamp/observiq/observiq_client_test.go | 29 ++- .../observiq_packages_state_provider.go | 2 +- .../observiq_packages_state_provider_test.go | 2 +- opamp/observiq/reload_funcs_test.go | 10 +- 15 files changed, 415 insertions(+), 116 deletions(-) diff --git a/cmd/collector/main.go b/cmd/collector/main.go index 72017e812..01a988e59 100644 --- a/cmd/collector/main.go +++ b/cmd/collector/main.go @@ -24,12 +24,12 @@ import ( "strconv" _ "time/tzdata" + "github.com/google/uuid" "github.com/observiq/bindplane-agent/collector" "github.com/observiq/bindplane-agent/internal/logging" "github.com/observiq/bindplane-agent/internal/service" "github.com/observiq/bindplane-agent/internal/version" "github.com/observiq/bindplane-agent/opamp" - "github.com/oklog/ulid/v2" "github.com/spf13/pflag" "go.uber.org/zap" "gopkg.in/yaml.v3" @@ -179,9 +179,19 @@ func checkManagerConfig(configPath *string) error { return statErr } - newConfig.AgentID, ok = os.LookupEnv(agentIDENV) - if !ok { - newConfig.AgentID = ulid.Make().String() + if envString, ok := os.LookupEnv(agentIDENV); ok { + var err error + newConfig.AgentID, err = opamp.ParseAgentID(envString) + if err != nil { + return fmt.Errorf("invalid agent ID in env %q: %w", agentIDENV, err) + } + } else { + u, err := uuid.NewV7() + if err != nil { + return fmt.Errorf("new uuidv7: %w", err) + } + + newConfig.AgentID = opamp.AgentIDFromUUID(u) } if sk, ok := os.LookupEnv(secretkeyENV); ok { @@ -231,12 +241,18 @@ func ensureIdentity(configPath string) error { return fmt.Errorf("unable to interpret config file: %w", err) } - // If the AgentID is not a ULID (legacy ID or empty) then we need to generate a ULID as the AgentID. - if _, err := ulid.Parse(candidateConfig.AgentID); err == nil { + // If the AgentID is empty then we need to generate a new ID as the AgentID. + if candidateConfig.AgentID != opamp.EmptyAgentID { return nil } - candidateConfig.AgentID = ulid.Make().String() + u, err := uuid.NewV7() + if err != nil { + return fmt.Errorf("new uuidv7: %w", err) + } + + candidateConfig.AgentID = opamp.AgentIDFromUUID(u) + newBytes, err := yaml.Marshal(candidateConfig) if err != nil { return fmt.Errorf("failed to marshal sanitized config: %w", err) diff --git a/cmd/collector/main_test.go b/cmd/collector/main_test.go index b91fd5e97..6f8cf7e7c 100644 --- a/cmd/collector/main_test.go +++ b/cmd/collector/main_test.go @@ -17,7 +17,6 @@ package main import ( "errors" "fmt" - "io/ioutil" "os" "path/filepath" "runtime" @@ -30,6 +29,14 @@ import ( "gopkg.in/yaml.v3" ) +// Must is a helper function for tests that panics if there is an error creating the object of type T +func Must[T any](t T, err error) T { + if err != nil { + panic(err) + } + return t +} + func TestGetDefaultCollectorConfigPathENV(t *testing.T) { fakeConfigPath := "./fake/path/config.yaml" @@ -99,7 +106,7 @@ func TestCheckManagerConfigNoFile(t *testing.T) { t.Setenv(agentNameENV, "agent name") - t.Setenv(agentIDENV, "agent ID") + t.Setenv(agentIDENV, "01HX2DWEQZ045KQR3VG0EYEZ94") t.Setenv(secretkeyENV, "secretKey") @@ -113,7 +120,7 @@ func TestCheckManagerConfigNoFile(t *testing.T) { actual, _ := opamp.ParseConfig(manager) expected := &opamp.Config{ Endpoint: "0.0.0.0", - AgentID: "agent ID", + AgentID: Must(opamp.ParseAgentID("01HX2DWEQZ045KQR3VG0EYEZ94")), AgentName: new(string), SecretKey: new(string), Labels: new(string), @@ -244,15 +251,12 @@ func TestManagerConfigNoAgentIDWillSet(t *testing.T) { err := checkManagerConfig(&manager) require.NoError(t, err) - cfgBytes, err := ioutil.ReadFile(manager) + cfgBytes, err := os.ReadFile(manager) require.NoError(t, err) var config opamp.Config require.NoError(t, yaml.Unmarshal(cfgBytes, &config)) - require.NotEmpty(t, config.AgentID) - ulidID, err := ulid.Parse(config.AgentID) - require.NoError(t, err) - require.NotEmpty(t, ulidID) + require.NotEqual(t, opamp.EmptyAgentID, config.AgentID) } // TestManagerConfigWillNotOverwriteCurrentAgentID tests that if the agent ID is a ULID it will not overwrite it @@ -260,7 +264,7 @@ func TestManagerConfigWillNotOverwriteCurrentAgentID(t *testing.T) { tmpDir := t.TempDir() manager := filepath.Join(tmpDir, "manager.yaml") - id := ulid.Make().String() + id := ulid.Make() data := []byte(fmt.Sprintf(` --- agent_id: %s @@ -269,12 +273,12 @@ agent_id: %s err := checkManagerConfig(&manager) require.NoError(t, err) - cfgBytes, err := ioutil.ReadFile(manager) + cfgBytes, err := os.ReadFile(manager) require.NoError(t, err) var config opamp.Config require.NoError(t, yaml.Unmarshal(cfgBytes, &config)) - require.Equal(t, config.AgentID, id) + require.Equal(t, config.AgentID.String(), id.String()) } // TestManagerConfigWillUpdateLegacyAgentID tests that if the agent ID is a Legacy ID (UUID format) it will overwrite with a new ULID @@ -291,14 +295,12 @@ agent_id: %s err := checkManagerConfig(&manager) require.NoError(t, err) - cfgBytes, err := ioutil.ReadFile(manager) + cfgBytes, err := os.ReadFile(manager) require.NoError(t, err) var config opamp.Config require.NoError(t, yaml.Unmarshal(cfgBytes, &config)) - _, err = ulid.Parse(config.AgentID) - require.NoError(t, err) - require.NotEqual(t, config.AgentID, legacyID) + require.NotEqual(t, opamp.EmptyAgentID, config.AgentID) } func TestManagerConfigWillErrorOnInvalidOpAmpConfig(t *testing.T) { diff --git a/go.mod b/go.mod index e1c7ba572..9fa0a4ff0 100644 --- a/go.mod +++ b/go.mod @@ -36,7 +36,7 @@ require ( github.com/observiq/bindplane-agent/receiver/sapnetweaverreceiver v1.63.0 github.com/observiq/bindplane-agent/receiver/telemetrygeneratorreceiver v1.63.0 github.com/oklog/ulid/v2 v2.1.0 - github.com/open-telemetry/opamp-go v0.14.0 + github.com/open-telemetry/opamp-go v0.17.0 github.com/open-telemetry/opentelemetry-collector-contrib/connector/countconnector v0.111.0 github.com/open-telemetry/opentelemetry-collector-contrib/connector/routingconnector v0.111.0 github.com/open-telemetry/opentelemetry-collector-contrib/connector/servicegraphconnector v0.111.0 @@ -592,7 +592,7 @@ require ( github.com/googleapis/gax-go/v2 v2.13.0 // indirect github.com/gophercloud/gophercloud v1.13.0 // indirect github.com/gorilla/mux v1.8.1 // indirect - github.com/gorilla/websocket v1.5.1 // indirect + github.com/gorilla/websocket v1.5.3 // indirect github.com/gosnmp/gosnmp v1.38.0 // indirect github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc // indirect github.com/grobie/gomemcache v0.0.0-20230213081705-239240bbc445 // indirect diff --git a/go.sum b/go.sum index 6092a8bf9..ad0f03a00 100644 --- a/go.sum +++ b/go.sum @@ -1511,8 +1511,8 @@ github.com/gorilla/sessions v1.2.1 h1:DHd3rPN5lE3Ts3D8rKkQ8x/0kqfeNmBAaiSi+o7Fsg github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= -github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= +github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= +github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gosnmp/gosnmp v1.38.0 h1:I5ZOMR8kb0DXAFg/88ACurnuwGwYkXWq3eLpJPHMEYc= github.com/gosnmp/gosnmp v1.38.0/go.mod h1:FE+PEZvKrFz9afP9ii1W3cprXuVZ17ypCcyyfYuu5LY= github.com/grafana/loki/pkg/push v0.0.0-20240514112848-a1b1eeb09583 h1:dN3eF1S5fvVu2l9WoqYSvmNmPK8Uh2vjE4yUsBq80l4= @@ -1914,8 +1914,8 @@ github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y github.com/onsi/gomega v1.13.0/go.mod h1:lRk9szgn8TxENtWd0Tp4c3wjlRfMTMH27I+3Je41yGY= github.com/onsi/gomega v1.33.1 h1:dsYjIxxSR755MDmKVsaFQTE22ChNBcuuTWgkUDSubOk= github.com/onsi/gomega v1.33.1/go.mod h1:U4R44UsT+9eLIaYRB2a5qajjtQYn0hauxvRm16AVYg0= -github.com/open-telemetry/opamp-go v0.14.0 h1:KoziIK+wsFojhUXNTkCSTnCPf0eCMqFAaccOs0HrWIY= -github.com/open-telemetry/opamp-go v0.14.0/go.mod h1:XOGCigljsLSTZ8FfLwvat0M1QDj3conIIgRa77BWrKs= +github.com/open-telemetry/opamp-go v0.17.0 h1:3R4+B/6Sy8mknLBbzO3gqloqwTT02rCSRcr4ac2B124= +github.com/open-telemetry/opamp-go v0.17.0/go.mod h1:SGDhUoAx7uGutO4ENNMQla/tiSujxgZmMPJXIOPGBdk= github.com/open-telemetry/opentelemetry-collector-contrib/connector/countconnector v0.111.0 h1:YRtg8O1y//TsNeVaQcorIL6ha0NnTKdma9Tux8pfklg= github.com/open-telemetry/opentelemetry-collector-contrib/connector/countconnector v0.111.0/go.mod h1:izISYDkhEvgYXi/8gQAJvXxkFThk5AvN5M5FdCmxtyA= github.com/open-telemetry/opentelemetry-collector-contrib/connector/datadogconnector v0.111.0 h1:GZgIPUBQisxljpN9hLHD4X8eNUBOXZFP+4s3Hwn5YY4= diff --git a/opamp/config.go b/opamp/config.go index a1c2d36e1..f42a43f82 100644 --- a/opamp/config.go +++ b/opamp/config.go @@ -24,6 +24,9 @@ import ( "path/filepath" "time" + "github.com/google/uuid" + "github.com/oklog/ulid/v2" + "github.com/open-telemetry/opamp-go/client/types" "gopkg.in/yaml.v3" ) @@ -47,11 +50,116 @@ var ( errInvalidCAFile = "failed to read TLS CA file" ) +type agentIDType string + +const ( + agentIDTypeULID agentIDType = "ULID" + agentIDTypeUUID agentIDType = "UUID" +) + +// AgentID represents the ID of the agent +type AgentID struct { + by [16]byte + idType agentIDType + orig string +} + +// EmptyAgentID represents an empty/unset agent ID. +var EmptyAgentID = AgentID{} + +// ParseAgentID parses an agent ID from the given string +func ParseAgentID(s string) (AgentID, error) { + switch len(s) { + case 26: + // length 26 strings can't be UUID, so they must be ULID + u, err := ulid.Parse(s) + if err != nil { + return AgentID{}, fmt.Errorf("parse ulid: %w", err) + } + return AgentID{ + by: u, + idType: agentIDTypeULID, + orig: s, + }, nil + + default: + // Try parsing as a UUID. There are a couple forms of UUID supported for parsing, so they may be a couple different + // lengths + u, err := uuid.Parse(s) + if err != nil { + return AgentID{}, fmt.Errorf("parse uuid: %w", err) + } + return AgentID{ + by: u, + idType: agentIDTypeUUID, + orig: s, + }, nil + } +} + +// AgentIDFromUUID creates an agent ID from a generated UUID. +// See ParseAgentID for parsing a UUID string. +func AgentIDFromUUID(u uuid.UUID) AgentID { + return AgentID{ + by: u, + idType: agentIDTypeUUID, + orig: u.String(), + } +} + +// String returns a string representation of the agent ID +func (a AgentID) String() string { + return a.orig +} + +// OpAMPInstanceUID returns the opamp representation of the agent ID +func (a AgentID) OpAMPInstanceUID() types.InstanceUid { + return types.InstanceUid(a.by) +} + +// Type returns the string type of the agent ID (ULID, UUID) as it should +// be reported to BindPlane. +func (a AgentID) Type() string { + return string(a.idType) +} + +// MarshalYAML implements the yaml.Marshaler interface +func (a AgentID) MarshalYAML() (any, error) { + return a.String(), nil +} + +// UnmarshalYAML implements the yaml.Unmarshaler interface +func (a *AgentID) UnmarshalYAML(unmarshal func(any) error) error { + var s string + + err := unmarshal(&s) + if err != nil { + return err + } + + if s == "" { + // Empty string = keep the 0 value + return nil + } + + u, err := ParseAgentID(s) + if err != nil { + // In order to maintain backwards compatability, we don't error here. + // Instead, in main, we will regenerate a new agent ID + *a = EmptyAgentID + return nil + } + + *a = AgentID(u) + + return nil +} + // Config contains the configuration for the collector to communicate with an OpAmp enabled platform. type Config struct { Endpoint string `yaml:"endpoint"` SecretKey *string `yaml:"secret_key,omitempty"` - AgentID string `yaml:"agent_id"` + AgentID AgentID `yaml:"agent_id"` TLS *TLSConfig `yaml:"tls_config,omitempty"` // Updatable fields diff --git a/opamp/config_test.go b/opamp/config_test.go index 393586098..597ebc1f0 100644 --- a/opamp/config_test.go +++ b/opamp/config_test.go @@ -22,10 +22,23 @@ import ( "path/filepath" "testing" + "github.com/google/uuid" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "gopkg.in/yaml.v3" ) +// Must is a helper function for tests that panics if there is an error creating the object of type T +func Must[T any](t T, err error) T { + if err != nil { + panic(err) + } + return t +} + +var testAgentIDString = "01HX2DWEQZ045KQR3VG0EYEZ94" +var testAgentID = Must(ParseAgentID(testAgentIDString)) + func TestToTLS(t *testing.T) { invalidCAFile := "/some/bad/file-ca.crt" invalidKeyFile := "/some/bad/file.key" @@ -240,13 +253,13 @@ func TestParseConfig(t *testing.T) { { desc: "Successful Full Parse", testFunc: func(t *testing.T) { - configContents := ` + configContents := fmt.Sprintf(` endpoint: localhost:1234 secret_key: b92222ee-a1fc-4bb1-98db-26de3448541b -agent_id: 8321f735-a52c-4f49-aca9-66f9266c5fe5 +agent_id: %s labels: "one=foo,two=bar" agent_name: "My Agent" -` +`, testAgentIDString) tmpDir := t.TempDir() configPath := filepath.Join(tmpDir, "manager.yml") @@ -257,7 +270,7 @@ agent_name: "My Agent" expectedConfig := &Config{ Endpoint: "localhost:1234", SecretKey: &secretKeyContents, - AgentID: "8321f735-a52c-4f49-aca9-66f9266c5fe5", + AgentID: testAgentID, Labels: &labelsContents, AgentName: &agentNameContents, } @@ -270,10 +283,10 @@ agent_name: "My Agent" { desc: "Successful Partial Parse", testFunc: func(t *testing.T) { - configContents := ` + configContents := fmt.Sprintf(` endpoint: localhost:1234 -agent_id: 8321f735-a52c-4f49-aca9-66f9266c5fe5 -` +agent_id: %s +`, testAgentIDString) tmpDir := t.TempDir() configPath := filepath.Join(tmpDir, "manager.yml") @@ -284,7 +297,7 @@ agent_id: 8321f735-a52c-4f49-aca9-66f9266c5fe5 expectedConfig := &Config{ Endpoint: "localhost:1234", SecretKey: nil, - AgentID: "8321f735-a52c-4f49-aca9-66f9266c5fe5", + AgentID: testAgentID, Labels: nil, AgentName: nil, } @@ -297,15 +310,15 @@ agent_id: 8321f735-a52c-4f49-aca9-66f9266c5fe5 { desc: "Successful Full Parse with TLS Insecure Skip Verify", testFunc: func(t *testing.T) { - configContents := ` + configContents := fmt.Sprintf(` endpoint: localhost:1234 secret_key: b92222ee-a1fc-4bb1-98db-26de3448541b -agent_id: 8321f735-a52c-4f49-aca9-66f9266c5fe5 +agent_id: %s labels: "one=foo,two=bar" agent_name: "My Agent" tls_config: insecure_skip_verify: true -` +`, testAgentIDString) tmpDir := t.TempDir() configPath := filepath.Join(tmpDir, "manager.yml") @@ -316,7 +329,7 @@ tls_config: expectedConfig := &Config{ Endpoint: "localhost:1234", SecretKey: &secretKeyContents, - AgentID: "8321f735-a52c-4f49-aca9-66f9266c5fe5", + AgentID: testAgentID, Labels: &labelsContents, AgentName: &agentNameContents, TLS: &TLSConfig{ @@ -332,15 +345,15 @@ tls_config: { desc: "Successful Full Parse with TLS Secure Root CA", testFunc: func(t *testing.T) { - configContents := ` + configContents := fmt.Sprintf(` endpoint: localhost:1234 secret_key: b92222ee-a1fc-4bb1-98db-26de3448541b -agent_id: 8321f735-a52c-4f49-aca9-66f9266c5fe5 +agent_id: %s labels: "one=foo,two=bar" agent_name: "My Agent" tls_config: insecure_skip_verify: false -` +`, testAgentIDString) tmpDir := t.TempDir() configPath := filepath.Join(tmpDir, "manager.yml") @@ -351,7 +364,7 @@ tls_config: expectedConfig := &Config{ Endpoint: "localhost:1234", SecretKey: &secretKeyContents, - AgentID: "8321f735-a52c-4f49-aca9-66f9266c5fe5", + AgentID: testAgentID, Labels: &labelsContents, AgentName: &agentNameContents, TLS: &TLSConfig{ @@ -373,7 +386,7 @@ tls_config: configContents := ` endpoint: localhost:1234 secret_key: b92222ee-a1fc-4bb1-98db-26de3448541b -agent_id: 8321f735-a52c-4f49-aca9-66f9266c5fe5 +agent_id: 01HX2DWEQZ045KQR3VG0EYEZ94 labels: "one=foo,two=bar" agent_name: "My Agent" tls_config: @@ -403,13 +416,13 @@ tls_config: configContents := fmt.Sprintf(` endpoint: localhost:1234 secret_key: b92222ee-a1fc-4bb1-98db-26de3448541b -agent_id: 8321f735-a52c-4f49-aca9-66f9266c5fe5 +agent_id: %s labels: "one=foo,two=bar" agent_name: "My Agent" tls_config: insecure_skip_verify: false ca_file: %s -`, caPath) +`, testAgentIDString, caPath) err = os.WriteFile(configPath, []byte(configContents), os.ModePerm) require.NoError(t, err) @@ -417,7 +430,7 @@ tls_config: expectedConfig := &Config{ Endpoint: "localhost:1234", SecretKey: &secretKeyContents, - AgentID: "8321f735-a52c-4f49-aca9-66f9266c5fe5", + AgentID: testAgentID, Labels: &labelsContents, AgentName: &agentNameContents, TLS: &TLSConfig{ @@ -440,7 +453,7 @@ tls_config: configContents := ` endpoint: localhost:1234 secret_key: b92222ee-a1fc-4bb1-98db-26de3448541b -agent_id: 8321f735-a52c-4f49-aca9-66f9266c5fe5 +agent_id: 01HX2DWEQZ045KQR3VG0EYEZ94 labels: "one=foo,two=bar" agent_name: "My Agent" tls_config: @@ -471,7 +484,7 @@ tls_config: configContents := fmt.Sprintf(` endpoint: localhost:1234 secret_key: b92222ee-a1fc-4bb1-98db-26de3448541b -agent_id: 8321f735-a52c-4f49-aca9-66f9266c5fe5 +agent_id: 01HX2DWEQZ045KQR3VG0EYEZ94 labels: "one=foo,two=bar" agent_name: "My Agent" tls_config: @@ -502,7 +515,7 @@ tls_config: configContents := fmt.Sprintf(` endpoint: localhost:1234 secret_key: b92222ee-a1fc-4bb1-98db-26de3448541b -agent_id: 8321f735-a52c-4f49-aca9-66f9266c5fe5 +agent_id: 01HX2DWEQZ045KQR3VG0EYEZ94 labels: "one=foo,two=bar" agent_name: "My Agent" tls_config: @@ -533,7 +546,7 @@ tls_config: configContents := fmt.Sprintf(` endpoint: localhost:1234 secret_key: b92222ee-a1fc-4bb1-98db-26de3448541b -agent_id: 8321f735-a52c-4f49-aca9-66f9266c5fe5 +agent_id: 01HX2DWEQZ045KQR3VG0EYEZ94 labels: "one=foo,two=bar" agent_name: "My Agent" tls_config: @@ -563,7 +576,7 @@ tls_config: configContents := fmt.Sprintf(` endpoint: localhost:1234 secret_key: b92222ee-a1fc-4bb1-98db-26de3448541b -agent_id: 8321f735-a52c-4f49-aca9-66f9266c5fe5 +agent_id: 01HX2DWEQZ045KQR3VG0EYEZ94 labels: "one=foo,two=bar" agent_name: "My Agent" tls_config: @@ -598,14 +611,14 @@ tls_config: configContents := fmt.Sprintf(` endpoint: localhost:1234 secret_key: b92222ee-a1fc-4bb1-98db-26de3448541b -agent_id: 8321f735-a52c-4f49-aca9-66f9266c5fe5 +agent_id: %s labels: "one=foo,two=bar" agent_name: "My Agent" tls_config: insecure_skip_verify: false key_file: %s cert_file: %s -`, keyPath, certPath) +`, testAgentIDString, keyPath, certPath) err = os.WriteFile(configPath, []byte(configContents), os.ModePerm) require.NoError(t, err) @@ -613,7 +626,7 @@ tls_config: expectedConfig := &Config{ Endpoint: "localhost:1234", SecretKey: &secretKeyContents, - AgentID: "8321f735-a52c-4f49-aca9-66f9266c5fe5", + AgentID: testAgentID, Labels: &labelsContents, AgentName: &agentNameContents, TLS: &TLSConfig{ @@ -650,14 +663,14 @@ func TestCmpUpdatableFields(t *testing.T) { baseCfg: Config{ Endpoint: "ws://localhost:1234", SecretKey: &secretKeyContents, - AgentID: "20ce90b8-506c-4a3b-8134-21aa8d526e03", + AgentID: testAgentID, Labels: &labelsOne, AgentName: &nameOne, }, compare: Config{ Endpoint: "ws://localhost:1234", SecretKey: &secretKeyContents, - AgentID: "20ce90b8-506c-4a3b-8134-21aa8d526e03", + AgentID: testAgentID, Labels: &labelsOne, AgentName: &nameOne, }, @@ -668,14 +681,14 @@ func TestCmpUpdatableFields(t *testing.T) { baseCfg: Config{ Endpoint: "ws://localhost:1234", SecretKey: &secretKeyContents, - AgentID: "20ce90b8-506c-4a3b-8134-21aa8d526e03", + AgentID: testAgentID, Labels: &labelsOne, AgentName: &nameOne, }, compare: Config{ Endpoint: "ws://some.host.com", SecretKey: nil, - AgentID: "d71cb88c-a4d3-4992-8bc8-d82702fdcb21", + AgentID: EmptyAgentID, Labels: &labelsOne, AgentName: &nameOne, }, @@ -686,14 +699,14 @@ func TestCmpUpdatableFields(t *testing.T) { baseCfg: Config{ Endpoint: "ws://localhost:1234", SecretKey: &secretKeyContents, - AgentID: "20ce90b8-506c-4a3b-8134-21aa8d526e03", + AgentID: testAgentID, Labels: &labelsOne, AgentName: nil, }, compare: Config{ Endpoint: "ws://localhost:1234", SecretKey: &secretKeyContents, - AgentID: "20ce90b8-506c-4a3b-8134-21aa8d526e03", + AgentID: testAgentID, Labels: &labelsOne, AgentName: nil, }, @@ -704,14 +717,14 @@ func TestCmpUpdatableFields(t *testing.T) { baseCfg: Config{ Endpoint: "ws://localhost:1234", SecretKey: &secretKeyContents, - AgentID: "20ce90b8-506c-4a3b-8134-21aa8d526e03", + AgentID: testAgentID, Labels: &labelsOne, AgentName: nil, }, compare: Config{ Endpoint: "ws://localhost:1234", SecretKey: &secretKeyContents, - AgentID: "20ce90b8-506c-4a3b-8134-21aa8d526e03", + AgentID: testAgentID, Labels: &labelsTwo, AgentName: nil, }, @@ -722,14 +735,14 @@ func TestCmpUpdatableFields(t *testing.T) { baseCfg: Config{ Endpoint: "ws://localhost:1234", SecretKey: &secretKeyContents, - AgentID: "20ce90b8-506c-4a3b-8134-21aa8d526e03", + AgentID: testAgentID, Labels: nil, AgentName: &nameOne, }, compare: Config{ Endpoint: "ws://localhost:1234", SecretKey: &secretKeyContents, - AgentID: "20ce90b8-506c-4a3b-8134-21aa8d526e03", + AgentID: testAgentID, Labels: nil, AgentName: &nameOne, }, @@ -740,14 +753,14 @@ func TestCmpUpdatableFields(t *testing.T) { baseCfg: Config{ Endpoint: "ws://localhost:1234", SecretKey: &secretKeyContents, - AgentID: "20ce90b8-506c-4a3b-8134-21aa8d526e03", + AgentID: testAgentID, Labels: nil, AgentName: &nameOne, }, compare: Config{ Endpoint: "ws://localhost:1234", SecretKey: &secretKeyContents, - AgentID: "20ce90b8-506c-4a3b-8134-21aa8d526e03", + AgentID: testAgentID, Labels: nil, AgentName: &nameTwo, }, @@ -758,14 +771,14 @@ func TestCmpUpdatableFields(t *testing.T) { baseCfg: Config{ Endpoint: "ws://localhost:1234", SecretKey: &secretKeyContents, - AgentID: "20ce90b8-506c-4a3b-8134-21aa8d526e03", + AgentID: testAgentID, Labels: &labelsOne, AgentName: nil, }, compare: Config{ Endpoint: "ws://localhost:1234", SecretKey: &secretKeyContents, - AgentID: "20ce90b8-506c-4a3b-8134-21aa8d526e03", + AgentID: testAgentID, Labels: nil, AgentName: nil, }, @@ -776,14 +789,14 @@ func TestCmpUpdatableFields(t *testing.T) { baseCfg: Config{ Endpoint: "ws://localhost:1234", SecretKey: &secretKeyContents, - AgentID: "20ce90b8-506c-4a3b-8134-21aa8d526e03", + AgentID: testAgentID, Labels: nil, AgentName: nil, }, compare: Config{ Endpoint: "ws://localhost:1234", SecretKey: &secretKeyContents, - AgentID: "20ce90b8-506c-4a3b-8134-21aa8d526e03", + AgentID: testAgentID, Labels: &labelsTwo, AgentName: nil, }, @@ -845,7 +858,7 @@ func TestConfigCopy(t *testing.T) { cfg := Config{ Endpoint: "ws://localhost:1234", SecretKey: &secretKeyContents, - AgentID: "20ce90b8-506c-4a3b-8134-21aa8d526e03", + AgentID: testAgentID, Labels: &labelsContents, AgentName: &agentNameContents, TLS: &tlscfg, @@ -854,3 +867,146 @@ func TestConfigCopy(t *testing.T) { copyCfg := cfg.Copy() require.Equal(t, cfg, *copyCfg) } + +func TestParseAgentID(t *testing.T) { + testCases := []struct { + name string + id string + expected AgentID + expectedErr string + }{ + { + name: "Valid ULID", + id: "01J9RQ8V3ZT95MRH05DKJA3KSM", + expected: AgentID{ + by: [16]byte{0x1, 0x92, 0x71, 0x74, 0x6c, 0x7f, 0xd2, 0x4b, 0x4c, 0x44, 0x5, 0x6c, 0xe4, 0xa1, 0xcf, 0x34}, + idType: agentIDTypeULID, + orig: "01J9RQ8V3ZT95MRH05DKJA3KSM", + }, + }, + { + name: "Valid UUID", + id: "01927175-7a98-7585-94ce-cc833ee7735d", + expected: AgentID{ + by: [16]byte{0x1, 0x92, 0x71, 0x75, 0x7a, 0x98, 0x75, 0x85, 0x94, 0xce, 0xcc, 0x83, 0x3e, 0xe7, 0x73, 0x5d}, + idType: agentIDTypeUUID, + orig: "01927175-7a98-7585-94ce-cc833ee7735d", + }, + }, + { + name: "Invalid ULID", + id: "A1J9RQ8V3ZT95MRH05DKJA3KSM", + expectedErr: "parse ulid:", + }, + { + name: "Invalid UUID", + id: "01927175-7a98-7585-94ce-cc833ee7735l", + expectedErr: "parse uuid:", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + id, err := ParseAgentID(tc.id) + if tc.expectedErr != "" { + require.ErrorContains(t, err, tc.expectedErr) + return + } + + require.Equal(t, tc.expected, id) + }) + } +} + +func TestAgentIDFromUUID(t *testing.T) { + id := AgentIDFromUUID(Must(uuid.Parse("01927175-7a98-7585-94ce-cc833ee7735d"))) + require.Equal(t, AgentID{ + by: [16]byte{0x1, 0x92, 0x71, 0x75, 0x7a, 0x98, 0x75, 0x85, 0x94, 0xce, 0xcc, 0x83, 0x3e, 0xe7, 0x73, 0x5d}, + idType: agentIDTypeUUID, + orig: "01927175-7a98-7585-94ce-cc833ee7735d", + }, id) +} + +func TestAgentID_String(t *testing.T) { + uuidID := Must(ParseAgentID("01927175-7a98-7585-94ce-cc833ee7735d")) + ulidID := Must(ParseAgentID("01J9RQ8V3ZT95MRH05DKJA3KSM")) + + require.Equal(t, "01927175-7a98-7585-94ce-cc833ee7735d", uuidID.String()) + require.Equal(t, "01J9RQ8V3ZT95MRH05DKJA3KSM", ulidID.String()) +} + +func TestAgentID_OpAMPInstanceUID(t *testing.T) { + uuidID := Must(ParseAgentID("01927175-7a98-7585-94ce-cc833ee7735d")) + ulidID := Must(ParseAgentID("01J9RQ8V3ZT95MRH05DKJA3KSM")) + + require.EqualValues(t, + [16]byte{0x1, 0x92, 0x71, 0x75, 0x7a, 0x98, 0x75, 0x85, 0x94, 0xce, 0xcc, 0x83, 0x3e, 0xe7, 0x73, 0x5d}, + uuidID.OpAMPInstanceUID(), + ) + + require.EqualValues(t, + [16]byte{0x1, 0x92, 0x71, 0x74, 0x6c, 0x7f, 0xd2, 0x4b, 0x4c, 0x44, 0x5, 0x6c, 0xe4, 0xa1, 0xcf, 0x34}, + ulidID.OpAMPInstanceUID(), + ) +} + +func TestAgentID_Type(t *testing.T) { + uuidID := Must(ParseAgentID("01927175-7a98-7585-94ce-cc833ee7735d")) + ulidID := Must(ParseAgentID("01J9RQ8V3ZT95MRH05DKJA3KSM")) + + require.EqualValues(t, agentIDTypeUUID, uuidID.Type()) + require.EqualValues(t, agentIDTypeULID, ulidID.Type()) +} + +func TestAgentID_MarshalYaml(t *testing.T) { + uuidID := Must(ParseAgentID("01927175-7a98-7585-94ce-cc833ee7735d")) + ulidID := Must(ParseAgentID("01J9RQ8V3ZT95MRH05DKJA3KSM")) + + uuidYaml, err := yaml.Marshal(uuidID) + require.NoError(t, err) + require.Equal(t, "01927175-7a98-7585-94ce-cc833ee7735d\n", string(uuidYaml)) + + ulidYaml, err := yaml.Marshal(ulidID) + require.NoError(t, err) + require.Equal(t, "01J9RQ8V3ZT95MRH05DKJA3KSM\n", string(ulidYaml)) +} + +func TestAgentID_UnmarshalYaml(t *testing.T) { + t.Run("UUID", func(t *testing.T) { + var uuidAgentID AgentID + err := yaml.Unmarshal([]byte("01927175-7a98-7585-94ce-cc833ee7735d"), &uuidAgentID) + require.NoError(t, err) + require.Equal(t, AgentID{ + by: [16]byte{0x1, 0x92, 0x71, 0x75, 0x7a, 0x98, 0x75, 0x85, 0x94, 0xce, 0xcc, 0x83, 0x3e, 0xe7, 0x73, 0x5d}, + idType: agentIDTypeUUID, + orig: "01927175-7a98-7585-94ce-cc833ee7735d", + }, uuidAgentID) + }) + + t.Run("ULID", func(t *testing.T) { + var ulidAgentID AgentID + err := yaml.Unmarshal([]byte("01J9RQ8V3ZT95MRH05DKJA3KSM"), &ulidAgentID) + require.NoError(t, err) + require.Equal(t, AgentID{ + by: [16]byte{0x1, 0x92, 0x71, 0x74, 0x6c, 0x7f, 0xd2, 0x4b, 0x4c, 0x44, 0x5, 0x6c, 0xe4, 0xa1, 0xcf, 0x34}, + idType: agentIDTypeULID, + orig: "01J9RQ8V3ZT95MRH05DKJA3KSM", + }, ulidAgentID) + }) + + t.Run("Invalid ID", func(t *testing.T) { + // Invalid IDs will give an empty ID instead of an error, so the + // ID can be regenerated from the partially read config. + var invalidID AgentID + err := yaml.Unmarshal([]byte("Invalid"), &invalidID) + require.NoError(t, err) + require.Equal(t, EmptyAgentID, invalidID) + }) + + t.Run("Empty ID", func(t *testing.T) { + var emptyID AgentID + err := yaml.Unmarshal([]byte(`""`), &emptyID) + require.NoError(t, err) + require.Equal(t, EmptyAgentID, emptyID) + }) +} diff --git a/opamp/mocks/mock_opamp_client.go b/opamp/mocks/mock_opamp_client.go index ed888f089..82d8342ec 100644 --- a/opamp/mocks/mock_opamp_client.go +++ b/opamp/mocks/mock_opamp_client.go @@ -120,6 +120,11 @@ func (_m *MockOpAMPClient) SetCustomCapabilities(customCapabilities *protobufs.C return r0 } +// SetFlags provides a mock function with given fields: flags +func (_m *MockOpAMPClient) SetFlags(flags protobufs.AgentToServerFlags) { + _m.Called(flags) +} + // SetHealth provides a mock function with given fields: health func (_m *MockOpAMPClient) SetHealth(health *protobufs.ComponentHealth) error { ret := _m.Called(health) diff --git a/opamp/mocks/mock_packages_state_provider.go b/opamp/mocks/mock_packages_state_provider.go index 6b0fc7e6c..e795c1a37 100644 --- a/opamp/mocks/mock_packages_state_provider.go +++ b/opamp/mocks/mock_packages_state_provider.go @@ -256,17 +256,17 @@ func (_m *MockPackagesStateProvider) SetPackageState(packageName string, state t return r0 } -// UpdateContent provides a mock function with given fields: ctx, packageName, data, contentHash -func (_m *MockPackagesStateProvider) UpdateContent(ctx context.Context, packageName string, data io.Reader, contentHash []byte) error { - ret := _m.Called(ctx, packageName, data, contentHash) +// UpdateContent provides a mock function with given fields: ctx, packageName, data, contentHash, signature +func (_m *MockPackagesStateProvider) UpdateContent(ctx context.Context, packageName string, data io.Reader, contentHash []byte, signature []byte) error { + ret := _m.Called(ctx, packageName, data, contentHash, signature) if len(ret) == 0 { panic("no return value specified for UpdateContent") } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, string, io.Reader, []byte) error); ok { - r0 = rf(ctx, packageName, data, contentHash) + if rf, ok := ret.Get(0).(func(context.Context, string, io.Reader, []byte, []byte) error); ok { + r0 = rf(ctx, packageName, data, contentHash, signature) } else { r0 = ret.Error(0) } diff --git a/opamp/observiq/identity.go b/opamp/observiq/identity.go index c0f3b2147..13a7846a2 100644 --- a/opamp/observiq/identity.go +++ b/opamp/observiq/identity.go @@ -25,7 +25,7 @@ import ( // identity contains identifying information about the Collector type identity struct { - agentID string + agentID opamp.AgentID agentName *string serviceName string version string @@ -92,7 +92,7 @@ func (i identity) Copy() *identity { func (i *identity) ToAgentDescription() *protobufs.AgentDescription { identifyingAttributes := []*protobufs.KeyValue{ - opamp.StringKeyValue("service.instance.id", i.agentID), + opamp.StringKeyValue("service.instance.id", i.agentID.String()), opamp.StringKeyValue("service.name", i.serviceName), opamp.StringKeyValue("service.version", i.version), } diff --git a/opamp/observiq/identity_test.go b/opamp/observiq/identity_test.go index ef7dcd76b..487fd26ef 100644 --- a/opamp/observiq/identity_test.go +++ b/opamp/observiq/identity_test.go @@ -25,6 +25,16 @@ import ( "go.uber.org/zap" ) +// Must is a helper function for tests that panics if there is an error creating the object of type T +func Must[T any](t T, err error) T { + if err != nil { + panic(err) + } + return t +} + +var testAgentID = Must(opamp.ParseAgentID("01HX2DWEQZ045KQR3VG0EYEZ94")) + func Test_newIdentity(t *testing.T) { secretKeyContents := "b92222ee-a1fc-4bb1-98db-26de3448541b" labelsContents := "one=foo,two=bar" @@ -33,7 +43,7 @@ func Test_newIdentity(t *testing.T) { cfg := opamp.Config{ Endpoint: "ws://localhost:1234", SecretKey: &secretKeyContents, - AgentID: "8321f735-a52c-4f49-aca9-66f9266c5fe5", + AgentID: testAgentID, Labels: &labelsContents, AgentName: &agentNameContents, } @@ -70,7 +80,7 @@ func TestToAgentDescription(t *testing.T) { { desc: "Missing Agent Name and labels", ident: &identity{ - agentID: "4322d8d1-f3e0-46db-b68d-b01a4689ef19", + agentID: testAgentID, agentName: nil, serviceName: "com.observiq.collector", version: "v1.2.3", @@ -83,7 +93,7 @@ func TestToAgentDescription(t *testing.T) { }, expected: &protobufs.AgentDescription{ IdentifyingAttributes: []*protobufs.KeyValue{ - opamp.StringKeyValue("service.instance.id", "4322d8d1-f3e0-46db-b68d-b01a4689ef19"), + opamp.StringKeyValue("service.instance.id", testAgentID.String()), opamp.StringKeyValue("service.name", "com.observiq.collector"), opamp.StringKeyValue("service.version", "v1.2.3"), opamp.StringKeyValue("service.instance.name", "my-linux-box"), @@ -100,7 +110,7 @@ func TestToAgentDescription(t *testing.T) { { desc: "With Agent Name and labels", ident: &identity{ - agentID: "4322d8d1-f3e0-46db-b68d-b01a4689ef19", + agentID: testAgentID, agentName: &agentNameContents, serviceName: "com.observiq.collector", version: "v1.2.3", @@ -113,7 +123,7 @@ func TestToAgentDescription(t *testing.T) { }, expected: &protobufs.AgentDescription{ IdentifyingAttributes: []*protobufs.KeyValue{ - opamp.StringKeyValue("service.instance.id", "4322d8d1-f3e0-46db-b68d-b01a4689ef19"), + opamp.StringKeyValue("service.instance.id", testAgentID.String()), opamp.StringKeyValue("service.name", "com.observiq.collector"), opamp.StringKeyValue("service.version", "v1.2.3"), opamp.StringKeyValue("service.instance.name", agentNameContents), @@ -142,7 +152,7 @@ func Test_identityCopy(t *testing.T) { labelsContents := "one=foo,two=bar" agentNameContents := "My Agent" ident := &identity{ - agentID: "4322d8d1-f3e0-46db-b68d-b01a4689ef19", + agentID: testAgentID, agentName: &agentNameContents, serviceName: "com.observiq.collector", version: "v1.2.3", diff --git a/opamp/observiq/observiq_client.go b/opamp/observiq/observiq_client.go index 9c250425d..f14fb12a2 100644 --- a/opamp/observiq/observiq_client.go +++ b/opamp/observiq/observiq_client.go @@ -109,7 +109,7 @@ func NewClient(args *NewClientArgs) (opamp.Client, error) { } reportManager := report.GetManager() - if err := reportManager.SetClient(report.NewAgentClient(args.Config.AgentID, args.Config.SecretKey, tlsCfg)); err != nil { + if err := reportManager.SetClient(report.NewAgentClient(args.Config.AgentID.String(), args.Config.SecretKey, tlsCfg)); err != nil { // Error should never happen as we only error if a nil client is sent return nil, fmt.Errorf("failed to set client on report manager: %w", err) } @@ -219,15 +219,16 @@ func (c *Client) Connect(ctx context.Context) error { settings := types.StartSettings{ OpAMPServerURL: c.currentConfig.Endpoint, Header: http.Header{ - "Authorization": []string{fmt.Sprintf("Secret-Key %s", c.currentConfig.GetSecretKey())}, - "User-Agent": []string{fmt.Sprintf("observiq-otel-collector/%s", version.Version())}, - "OpAMP-Version": []string{opamp.Version()}, - "Agent-ID": []string{c.ident.agentID}, - "Agent-Version": []string{version.Version()}, - "Agent-Hostname": []string{c.ident.hostname}, + "Authorization": []string{fmt.Sprintf("Secret-Key %s", c.currentConfig.GetSecretKey())}, + "User-Agent": []string{fmt.Sprintf("observiq-otel-collector/%s", version.Version())}, + "OpAMP-Version": []string{opamp.Version()}, + "Agent-ID": []string{c.ident.agentID.String()}, + "Agent-Version": []string{version.Version()}, + "Agent-Hostname": []string{c.ident.hostname}, + "X-Bindplane-Agent-Id-Format": []string{c.ident.agentID.Type()}, }, TLSConfig: tlsCfg, - InstanceUid: c.ident.agentID, + InstanceUid: c.ident.agentID.OpAMPInstanceUID(), Callbacks: types.CallbacksStruct{ OnConnectFunc: c.onConnectHandler, OnConnectFailedFunc: c.onConnectFailedHandler, diff --git a/opamp/observiq/observiq_client_test.go b/opamp/observiq/observiq_client_test.go index afc216e6d..9c26a7467 100644 --- a/opamp/observiq/observiq_client_test.go +++ b/opamp/observiq/observiq_client_test.go @@ -52,7 +52,7 @@ func TestNewClient(t *testing.T) { desc: "Bad URL Scheme", config: opamp.Config{ Endpoint: "http://localhost:1234", - AgentID: "b24181a8-bc16-4ec1-b3af-ca6f7b669af8", + AgentID: testAgentID, }, expectedErr: ErrUnsupportedURL, }, @@ -60,7 +60,7 @@ func TestNewClient(t *testing.T) { desc: "Invalid Endpoint", config: opamp.Config{ Endpoint: "\t\t\t", - AgentID: "b24181a8-bc16-4ec1-b3af-ca6f7b669af8", + AgentID: testAgentID, }, expectedErr: errors.New("net/url: invalid control character in URL"), }, @@ -68,7 +68,7 @@ func TestNewClient(t *testing.T) { desc: "Bad TLS Config", config: opamp.Config{ Endpoint: "ws://localhost:1234", - AgentID: "b24181a8-bc16-4ec1-b3af-ca6f7b669af8", + AgentID: testAgentID, TLS: &opamp.TLSConfig{ CAFile: &badCAFile, }, @@ -79,7 +79,7 @@ func TestNewClient(t *testing.T) { desc: "Valid Config", config: opamp.Config{ Endpoint: "ws://localhost:1234", - AgentID: "b24181a8-bc16-4ec1-b3af-ca6f7b669af8", + AgentID: testAgentID, SecretKey: &secretKey, }, expectedErr: nil, @@ -294,7 +294,7 @@ func TestClientConnect(t *testing.T) { c := &Client{ opampClient: mockOpAmpClient, logger: zap.NewNop(), - ident: &identity{agentID: "a69dcef0-0261-4f4f-9ac0-a483af42a6ba"}, + ident: &identity{agentID: testAgentID}, configManager: nil, collector: mockCollector, currentConfig: opamp.Config{ @@ -346,7 +346,7 @@ func TestClientConnect(t *testing.T) { c := &Client{ opampClient: mockOpAmpClient, logger: zap.NewNop(), - ident: &identity{agentID: "a69dcef0-0261-4f4f-9ac0-a483af42a6ba"}, + ident: &identity{agentID: testAgentID}, configManager: nil, collector: mockCollector, currentConfig: opamp.Config{ @@ -384,7 +384,7 @@ func TestClientConnect(t *testing.T) { opampClient: mockOpAmpClient, logger: zap.NewNop(), ident: &identity{ - agentID: "a69dcef0-0261-4f4f-9ac0-a483af42a6ba", + agentID: testAgentID, hostname: "my.localnet", }, configManager: nil, @@ -399,15 +399,16 @@ func TestClientConnect(t *testing.T) { expectedSettings := types.StartSettings{ OpAMPServerURL: c.currentConfig.Endpoint, Header: http.Header{ - "Authorization": []string{fmt.Sprintf("Secret-Key %s", c.currentConfig.GetSecretKey())}, - "User-Agent": []string{fmt.Sprintf("observiq-otel-collector/%s", version.Version())}, - "OpAMP-Version": []string{opamp.Version()}, - "Agent-ID": []string{c.ident.agentID}, - "Agent-Version": []string{version.Version()}, - "Agent-Hostname": []string{c.ident.hostname}, + "Authorization": []string{fmt.Sprintf("Secret-Key %s", c.currentConfig.GetSecretKey())}, + "User-Agent": []string{fmt.Sprintf("observiq-otel-collector/%s", version.Version())}, + "OpAMP-Version": []string{opamp.Version()}, + "Agent-ID": []string{c.ident.agentID.String()}, + "Agent-Version": []string{version.Version()}, + "Agent-Hostname": []string{c.ident.hostname}, + "X-Bindplane-Agent-Id-Format": []string{"ULID"}, }, TLSConfig: nil, - InstanceUid: c.ident.agentID, + InstanceUid: c.ident.agentID.OpAMPInstanceUID(), Callbacks: types.CallbacksStruct{ OnConnectFunc: c.onConnectHandler, OnConnectFailedFunc: c.onConnectFailedHandler, diff --git a/opamp/observiq/observiq_packages_state_provider.go b/opamp/observiq/observiq_packages_state_provider.go index 7500d1ebf..8fd2c41b5 100644 --- a/opamp/observiq/observiq_packages_state_provider.go +++ b/opamp/observiq/observiq_packages_state_provider.go @@ -98,7 +98,7 @@ func (p *packagesStateProvider) FileContentHash(_ string) ([]byte, error) { } // UpdateContent not implemented so returns an error with this info -func (p *packagesStateProvider) UpdateContent(_ context.Context, _ string, _ io.Reader, _ []byte) error { +func (p *packagesStateProvider) UpdateContent(_ context.Context, _ string, _ io.Reader, _, _ []byte) error { p.logger.Debug("Update package content") return errors.New("method not implemented: PackageStateProvider UpdateContent") diff --git a/opamp/observiq/observiq_packages_state_provider_test.go b/opamp/observiq/observiq_packages_state_provider_test.go index ac0eb6600..634019f39 100644 --- a/opamp/observiq/observiq_packages_state_provider_test.go +++ b/opamp/observiq/observiq_packages_state_provider_test.go @@ -248,7 +248,7 @@ func TestUpdateContent(t *testing.T) { } var r io.Reader - err := p.UpdateContent(context.TODO(), "name", r, []byte("hash")) + err := p.UpdateContent(context.TODO(), "name", r, []byte("hash"), []byte("signature")) assert.ErrorContains(t, err, "method not implemented") }, diff --git a/opamp/observiq/reload_funcs_test.go b/opamp/observiq/reload_funcs_test.go index 42ae6b615..2c40756e1 100644 --- a/opamp/observiq/reload_funcs_test.go +++ b/opamp/observiq/reload_funcs_test.go @@ -59,7 +59,7 @@ func Test_managerReload(t *testing.T) { client := &Client{ currentConfig: opamp.Config{ Endpoint: "ws://localhost:1234", - AgentID: "d4691426-b0bb-41f7-84a8-320a9ec0ea2e", + AgentID: testAgentID, }, } reloadFunc := managerReload(client, managerFilePath) @@ -85,7 +85,7 @@ func Test_managerReload(t *testing.T) { currConfig := &opamp.Config{ Endpoint: "ws://localhost:1234", - AgentID: "d4691426-b0bb-41f7-84a8-320a9ec0ea2e", + AgentID: testAgentID, } mockOpAmpClient := mocks.NewMockOpAMPClient(t) @@ -110,7 +110,7 @@ func Test_managerReload(t *testing.T) { agentName := "name" newConfig := &opamp.Config{ Endpoint: "ws://localhost:1234", - AgentID: "d4691426-b0bb-41f7-84a8-320a9ec0ea2e", + AgentID: testAgentID, AgentName: &agentName, } @@ -140,7 +140,7 @@ func Test_managerReload(t *testing.T) { currConfig := &opamp.Config{ Endpoint: "ws://localhost:1234", - AgentID: "d4691426-b0bb-41f7-84a8-320a9ec0ea2e", + AgentID: testAgentID, } expectedErr := errors.New("oops") @@ -165,7 +165,7 @@ func Test_managerReload(t *testing.T) { agentName := "name" newConfig := &opamp.Config{ Endpoint: "ws://localhost:1234", - AgentID: "d4691426-b0bb-41f7-84a8-320a9ec0ea2e", + AgentID: testAgentID, AgentName: &agentName, }