Skip to content

Commit 934c1d8

Browse files
authored
bump opamp go to v0.15.0 (#3159)
* bump opamp go to v0.15.0 * Fix test * update makefile to build with image * remove image pull policy * pin version for bridge test server
1 parent e133eee commit 934c1d8

File tree

9 files changed

+44
-26
lines changed

9 files changed

+44
-26
lines changed

Makefile

+13-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ TARGETALLOCATOR_IMG ?= ${IMG_PREFIX}/${TARGETALLOCATOR_IMG_REPO}:$(addprefix v,$
3535
OPERATOROPAMPBRIDGE_IMG_REPO ?= operator-opamp-bridge
3636
OPERATOROPAMPBRIDGE_IMG ?= ${IMG_PREFIX}/${OPERATOROPAMPBRIDGE_IMG_REPO}:$(addprefix v,${VERSION})
3737

38+
BRIDGETESTSERVER_IMG_REPO ?= e2e-test-app-bridge-server
39+
BRIDGETESTSERVER_IMG ?= ${IMG_PREFIX}/${BRIDGETESTSERVER_IMG_REPO}:ve2e
40+
3841
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
3942
ifeq (,$(shell go env GOBIN))
4043
GOBIN=$(shell go env GOPATH)/bin
@@ -316,7 +319,7 @@ e2e-upgrade: undeploy chainsaw
316319
$(CHAINSAW) test --test-dir ./tests/e2e-upgrade
317320

318321
.PHONY: prepare-e2e
319-
prepare-e2e: chainsaw set-image-controller add-image-targetallocator add-image-opampbridge container container-target-allocator container-operator-opamp-bridge start-kind cert-manager install-metrics-server install-targetallocator-prometheus-crds load-image-all deploy
322+
prepare-e2e: chainsaw set-image-controller add-image-targetallocator add-image-opampbridge container container-target-allocator container-operator-opamp-bridge container-bridge-test-server start-kind cert-manager install-metrics-server install-targetallocator-prometheus-crds load-image-all deploy
320323

321324
.PHONY: scorecard-tests
322325
scorecard-tests: operator-sdk
@@ -354,6 +357,11 @@ container-operator-opamp-bridge: GOOS = linux
354357
container-operator-opamp-bridge: operator-opamp-bridge
355358
docker build -t ${OPERATOROPAMPBRIDGE_IMG} cmd/operator-opamp-bridge
356359

360+
.PHONY: container-bridge-test-server
361+
container-bridge-test-server: GOOS = linux
362+
container-bridge-test-server:
363+
docker build -t ${BRIDGETESTSERVER_IMG} tests/test-e2e-apps/bridge-server
364+
357365
.PHONY: start-kind
358366
start-kind: kind
359367
ifeq (true,$(START_KIND_CLUSTER))
@@ -370,7 +378,7 @@ install-targetallocator-prometheus-crds:
370378
./hack/install-targetallocator-prometheus-crds.sh
371379

372380
.PHONY: load-image-all
373-
load-image-all: load-image-operator load-image-target-allocator load-image-operator-opamp-bridge
381+
load-image-all: load-image-operator load-image-target-allocator load-image-operator-opamp-bridge load-image-bridge-test-server
374382

375383
.PHONY: load-image-operator
376384
load-image-operator: container kind
@@ -389,6 +397,9 @@ else
389397
$(MAKE) container-target-allocator-push
390398
endif
391399

400+
.PHONY: load-image-bridge-test-server
401+
load-image-bridge-test-server: container-bridge-test-server kind
402+
$(KIND) load --name $(KIND_CLUSTER_NAME) docker-image ${BRIDGETESTSERVER_IMG}
392403

393404
.PHONY: load-image-operator-opamp-bridge
394405
load-image-operator-opamp-bridge: container-operator-opamp-bridge kind

cmd/operator-opamp-bridge/agent/agent.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"time"
2323

2424
"github.com/go-logr/logr"
25-
"github.com/oklog/ulid/v2"
25+
"github.com/google/uuid"
2626
"github.com/open-telemetry/opamp-go/client"
2727
"github.com/open-telemetry/opamp-go/client/types"
2828
"github.com/open-telemetry/opamp-go/protobufs"
@@ -44,7 +44,7 @@ type Agent struct {
4444
startTime uint64
4545
lastHash []byte
4646

47-
instanceId ulid.ULID
47+
instanceId uuid.UUID
4848
agentDescription *protobufs.AgentDescription
4949
remoteConfigStatus *protobufs.RemoteConfigStatus
5050

@@ -211,7 +211,7 @@ func (agent *Agent) Start() error {
211211
settings := types.StartSettings{
212212
OpAMPServerURL: agent.config.Endpoint,
213213
Header: agent.config.Headers.ToHTTPHeader(),
214-
InstanceUid: agent.instanceId.String(),
214+
InstanceUid: types.InstanceUid(agent.instanceId),
215215
Callbacks: types.CallbacksStruct{
216216
OnConnectFunc: agent.onConnect,
217217
OnConnectFailedFunc: agent.onConnectFailed,
@@ -274,7 +274,7 @@ func (agent *Agent) runHeartbeat() {
274274

275275
// updateAgentIdentity receives a new instanced Id from the remote server and updates the agent's instanceID field.
276276
// The meter will be reinitialized by the onMessage function.
277-
func (agent *Agent) updateAgentIdentity(instanceId ulid.ULID) {
277+
func (agent *Agent) updateAgentIdentity(instanceId uuid.UUID) {
278278
agent.logger.V(3).Info("Agent identity is being changed",
279279
"old instanceId", agent.instanceId.String(),
280280
"new instanceid", instanceId.String())
@@ -416,12 +416,12 @@ func (agent *Agent) onMessage(ctx context.Context, msg *types.MessageData) {
416416
// The instance id is updated prior to the meter initialization so that the new meter will report using the updated
417417
// instanceId.
418418
if msg.AgentIdentification != nil {
419-
newInstanceId, err := ulid.Parse(msg.AgentIdentification.NewInstanceUid)
419+
uid, err := uuid.FromBytes(msg.AgentIdentification.NewInstanceUid)
420420
if err != nil {
421421
agent.logger.Error(err, "couldn't parse instance UID")
422422
return
423423
}
424-
agent.updateAgentIdentity(newInstanceId)
424+
agent.updateAgentIdentity(uid)
425425
}
426426

427427
if msg.OwnMetricsConnSettings != nil {

cmd/operator-opamp-bridge/agent/agent_test.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@ package agent
1616

1717
import (
1818
"context"
19-
"crypto/rand"
2019
"fmt"
2120
"os"
2221
"sort"
2322
"testing"
2423
"time"
2524

2625
"github.com/go-logr/logr"
27-
"github.com/oklog/ulid/v2"
26+
"github.com/google/uuid"
2827
"github.com/open-telemetry/opamp-go/client"
2928
"github.com/open-telemetry/opamp-go/client/types"
3029
"github.com/open-telemetry/opamp-go/protobufs"
@@ -883,15 +882,20 @@ func Test_CanUpdateIdentity(t *testing.T) {
883882
defer agent.Shutdown()
884883
require.NoError(t, err, "should be able to start agent")
885884
previousInstanceId := agent.instanceId.String()
886-
entropy := ulid.Monotonic(rand.Reader, 0)
887-
newId := ulid.MustNew(ulid.MaxTime(), entropy)
885+
newId, err := uuid.NewV7()
886+
require.NoError(t, err)
887+
marshalledId, err := newId.MarshalBinary()
888+
require.NoError(t, err)
888889
agent.onMessage(context.Background(), &types.MessageData{
889890
AgentIdentification: &protobufs.AgentIdentification{
890-
NewInstanceUid: newId.String(),
891+
NewInstanceUid: marshalledId,
891892
},
892893
})
893894
assert.NotEqual(t, previousInstanceId, newId.String())
894895
assert.Equal(t, agent.instanceId, newId)
896+
parsedUUID, err := uuid.FromBytes(marshalledId)
897+
require.NoError(t, err)
898+
assert.Equal(t, newId, parsedUUID)
895899
}
896900

897901
func getMessageDataFromConfigFile(filemap map[string]string) (*types.MessageData, error) {

cmd/operator-opamp-bridge/config/config.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package config
1616

1717
import (
18-
"crypto/rand"
1918
"errors"
2019
"fmt"
2120
"io/fs"
@@ -25,7 +24,7 @@ import (
2524
"time"
2625

2726
"github.com/go-logr/logr"
28-
"github.com/oklog/ulid/v2"
27+
"github.com/google/uuid"
2928
opampclient "github.com/open-telemetry/opamp-go/client"
3029
"github.com/open-telemetry/opamp-go/protobufs"
3130
"github.com/spf13/pflag"
@@ -186,9 +185,13 @@ func keyValuePair(key string, value string) *protobufs.KeyValue {
186185
}
187186
}
188187

189-
func (c *Config) GetNewInstanceId() ulid.ULID {
190-
entropy := ulid.Monotonic(rand.Reader, 0)
191-
return ulid.MustNew(ulid.Timestamp(time.Now()), entropy)
188+
func (c *Config) GetNewInstanceId() uuid.UUID {
189+
u, err := uuid.NewV7()
190+
if err != nil {
191+
// This really should never happen and if it does we should fail.
192+
panic(err)
193+
}
194+
return u
192195
}
193196

194197
func (c *Config) RemoteConfigEnabled() bool {

cmd/operator-opamp-bridge/metrics/reporter.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"time"
2323

2424
"github.com/go-logr/logr"
25-
"github.com/oklog/ulid/v2"
25+
"github.com/google/uuid"
2626
"github.com/open-telemetry/opamp-go/protobufs"
2727
"github.com/shirou/gopsutil/process"
2828
"go.opentelemetry.io/otel/attribute"
@@ -53,7 +53,7 @@ type MetricReporter struct {
5353
// NewMetricReporter creates an OTLP/HTTP client to the destination address supplied by the server.
5454
// TODO: do more validation on the endpoint, allow for gRPC.
5555
// TODO: set global provider and add more metrics to be reported.
56-
func NewMetricReporter(logger logr.Logger, dest *protobufs.TelemetryConnectionSettings, agentType string, agentVersion string, instanceId ulid.ULID) (*MetricReporter, error) {
56+
func NewMetricReporter(logger logr.Logger, dest *protobufs.TelemetryConnectionSettings, agentType string, agentVersion string, instanceId uuid.UUID) (*MetricReporter, error) {
5757

5858
if dest.DestinationEndpoint == "" {
5959
return nil, fmt.Errorf("metric destination must specify DestinationEndpoint")

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ require (
1717
github.com/mitchellh/mapstructure v1.5.0
1818
github.com/oklog/run v1.1.0
1919
github.com/oklog/ulid/v2 v2.1.0
20-
github.com/open-telemetry/opamp-go v0.14.0
20+
github.com/open-telemetry/opamp-go v0.15.0
2121
github.com/openshift/api v0.0.0-20240124164020-e2ce40831f2e
2222
github.com/operator-framework/operator-lib v0.14.0
2323
github.com/prometheus-operator/prometheus-operator v0.75.0

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,8 @@ github.com/onsi/ginkgo/v2 v2.17.2 h1:7eMhcy3GimbsA3hEnVKdw/PQM9XN9krpKVXsZdph0/g
499499
github.com/onsi/ginkgo/v2 v2.17.2/go.mod h1:nP2DPOQoNsQmsVyv5rDA8JkXQoCs6goXIvr/PRJ1eCc=
500500
github.com/onsi/gomega v1.33.1 h1:dsYjIxxSR755MDmKVsaFQTE22ChNBcuuTWgkUDSubOk=
501501
github.com/onsi/gomega v1.33.1/go.mod h1:U4R44UsT+9eLIaYRB2a5qajjtQYn0hauxvRm16AVYg0=
502-
github.com/open-telemetry/opamp-go v0.14.0 h1:KoziIK+wsFojhUXNTkCSTnCPf0eCMqFAaccOs0HrWIY=
503-
github.com/open-telemetry/opamp-go v0.14.0/go.mod h1:XOGCigljsLSTZ8FfLwvat0M1QDj3conIIgRa77BWrKs=
502+
github.com/open-telemetry/opamp-go v0.15.0 h1:X2TWhEsGQ8GP7Uos3Ic9v/1aFUqoECZXKS7xAF5HqsA=
503+
github.com/open-telemetry/opamp-go v0.15.0/go.mod h1:QyPeN56JXlcZt5yG5RMdZ50Ju+zMFs1Ihy/hwHyF8Oo=
504504
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
505505
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
506506
github.com/opencontainers/image-spec v1.0.2 h1:9yCKha/T5XdGtO0q9Q9a6T5NUCsTn/DrBg0D7ufOcFM=

tests/e2e-opampbridge/opampbridge/00-install.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ spec:
1414
spec:
1515
containers:
1616
- name: e2e-test-app-bridge-server
17-
image: ghcr.io/open-telemetry/opentelemetry-operator/e2e-test-app-bridge-server:main
17+
image: ghcr.io/open-telemetry/opentelemetry-operator/e2e-test-app-bridge-server:ve2e
1818
ports:
1919
- containerPort: 4320
2020
- containerPort: 4321

tests/test-e2e-apps/bridge-server/opampsrv/opampsrv.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ func (srv *Server) onMessage(ctx context.Context, conn types.Connection, msg *pr
110110
instanceId = data.InstanceId(u.Bytes())
111111
} else if len(msg.InstanceUid) == 16 {
112112
// This is a 16 byte, new style UID.
113-
if parsedId, err := uuid.Parse(string(msg.InstanceUid)); err != nil {
114-
srv.logger.Errorf(ctx, "Cannot parse UUID %s: %v", string(msg.InstanceUid), err)
113+
if parsedId, err := uuid.FromBytes(msg.InstanceUid); err != nil {
114+
srv.logger.Errorf(ctx, "Cannot parse UUID %s: %v", msg.InstanceUid, err)
115115
return response
116116
} else {
117117
instanceId = data.InstanceId(parsedId)

0 commit comments

Comments
 (0)