Skip to content

Commit 3d79558

Browse files
Set service.instance.id in opampextension.yaml instead so it's present during bootstrap + fix TestSupervisorAgentDescriptionConfigApplies
1 parent 2ab8dff commit 3d79558

3 files changed

Lines changed: 24 additions & 27 deletions

File tree

cmd/opampsupervisor/e2e_test.go

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,36 +1234,32 @@ func TestSupervisorAgentDescriptionConfigApplies(t *testing.T) {
12341234
t.Fatal("Failed to get agent description after 5 seconds")
12351235
}
12361236

1237-
expectedDescription := &protobufs.AgentDescription{
1238-
IdentifyingAttributes: []*protobufs.KeyValue{
1239-
stringKeyValue("client.id", "my-client-id"),
1240-
stringKeyValue("service.name", command),
1241-
stringKeyValue("service.version", version),
1242-
stringKeyValue("service.instance.id", uuid.UUID(ad.InstanceUid).String()),
1243-
},
1244-
NonIdentifyingAttributes: []*protobufs.KeyValue{
1245-
stringKeyValue("env", "prod"),
1246-
stringKeyValue("host.arch", runtime.GOARCH),
1247-
stringKeyValue("host.name", host),
1248-
stringKeyValue("os.type", runtime.GOOS),
1249-
},
1237+
expectedIdentifyingAttributes := map[string]string{
1238+
"client.id": "my-client-id",
1239+
"service.instance.id": uuid.UUID(ad.InstanceUid).String(),
1240+
"service.name": command,
1241+
"service.version": version,
12501242
}
1251-
1252-
require.Subset(t, ad.AgentDescription.IdentifyingAttributes, expectedDescription.IdentifyingAttributes)
1253-
require.Subset(t, ad.AgentDescription.NonIdentifyingAttributes, expectedDescription.NonIdentifyingAttributes)
1243+
expectedNonIdentifyingAttributes := map[string]string{
1244+
"env": "prod",
1245+
"host.arch": runtime.GOARCH,
1246+
"host.name": host,
1247+
"os.type": runtime.GOOS,
1248+
}
1249+
actualIdentifyingAttributes := keyValuesToStringMap(ad.AgentDescription.IdentifyingAttributes)
1250+
require.Subset(t, actualIdentifyingAttributes, expectedIdentifyingAttributes)
1251+
actualNonIdentifyingAttributes := keyValuesToStringMap(ad.AgentDescription.NonIdentifyingAttributes)
1252+
require.Subset(t, actualNonIdentifyingAttributes, expectedNonIdentifyingAttributes)
12541253

12551254
time.Sleep(250 * time.Millisecond)
12561255
}
12571256

1258-
func stringKeyValue(key, val string) *protobufs.KeyValue {
1259-
return &protobufs.KeyValue{
1260-
Key: key,
1261-
Value: &protobufs.AnyValue{
1262-
Value: &protobufs.AnyValue_StringValue{
1263-
StringValue: val,
1264-
},
1265-
},
1257+
func keyValuesToStringMap(kvs []*protobufs.KeyValue) map[string]string {
1258+
out := make(map[string]string, len(kvs))
1259+
for _, kv := range kvs {
1260+
out[kv.Key] = kv.Value.GetStringValue()
12661261
}
1262+
return out
12671263
}
12681264

12691265
// Creates a Collector config that reads and writes logs to files and provides

cmd/opampsupervisor/supervisor/supervisor.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,9 +1156,7 @@ func (s *Supervisor) composeOwnTelemetryConfig() []byte {
11561156

11571157
func (s *Supervisor) composeExtraTelemetryConfig() []byte {
11581158
var cfg bytes.Buffer
1159-
resourceAttrs := map[string]string{
1160-
"service.instance.id": s.persistentState.InstanceID.String(),
1161-
}
1159+
resourceAttrs := map[string]string{}
11621160
ad := s.agentDescription.Load().(*protobufs.AgentDescription)
11631161
for _, attr := range ad.IdentifyingAttributes {
11641162
resourceAttrs[attr.Key] = attr.Value.GetStringValue()

cmd/opampsupervisor/supervisor/templates/opampextension.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ extensions:
1313

1414
service:
1515
extensions: [opamp]
16+
telemetry:
17+
resource:
18+
"service.instance.id": "{{.InstanceUid}}"

0 commit comments

Comments
 (0)