Skip to content

Commit

Permalink
Require that instance_uid is ULID (#116)
Browse files Browse the repository at this point in the history
Implements spec change open-telemetry/opamp-spec#116
  • Loading branch information
tigrannajaryan authored Aug 2, 2022
1 parent 3d4cbdc commit 0ded8e0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
11 changes: 11 additions & 0 deletions client/clientimpl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,17 @@ func TestConnectNoServer(t *testing.T) {
})
}

func TestInvalidInstanceId(t *testing.T) {
testClients(t, func(t *testing.T, client OpAMPClient) {
settings := createNoServerSettings()
prepareClient(t, &settings, client)
settings.InstanceUid = "invalidid"

err := client.Start(context.Background(), settings)
assert.Error(t, err)
})
}

func TestOnConnectFail(t *testing.T) {
testClients(t, func(t *testing.T, client OpAMPClient) {
var connectErr atomic.Value
Expand Down
5 changes: 5 additions & 0 deletions client/internal/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package internal
import (
"errors"

"github.com/oklog/ulid/v2"
"github.com/open-telemetry/opamp-go/protobufs"
)

Expand Down Expand Up @@ -69,6 +70,10 @@ func (h *SenderCommon) SetInstanceUid(instanceUid string) error {
return errors.New("cannot set instance uid to empty value")
}

if _, err := ulid.ParseStrict(instanceUid); err != nil {
return err
}

h.nextMessage.Update(
func(msg *protobufs.AgentToServer) {
msg.InstanceUid = instanceUid
Expand Down

0 comments on commit 0ded8e0

Please sign in to comment.