-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[extension/opamp] Make reported service.instance.id always match Collector resource attributes #46495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[extension/opamp] Make reported service.instance.id always match Collector resource attributes #46495
Changes from 10 commits
729fef4
e42a245
184d973
6e8a8d1
dcdef68
23d4123
3800815
2ab8dff
3d79558
cbc4513
de9055a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # Use this changelog template to create an entry for release notes. | ||
|
|
||
| # One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
| change_type: 'bug_fix' | ||
|
|
||
| # The name of the component, or a single word describing the area of concern, (e.g. receiver/filelog) | ||
| component: extension/opamp | ||
|
|
||
| # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
| note: Decorrelate `service.instance.id` and OpAMP `instance_uid` | ||
|
|
||
| # Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
| issues: [46495] | ||
|
|
||
| # (Optional) One or more lines of additional information to render under the primary note. | ||
| # These lines will be padded with 2 spaces and then inserted directly into the document. | ||
| # Use pipe (|) for multiline entries. | ||
| subtext: | | ||
| Previously: | ||
| - the `service.instance.id` reported in the AgentDescription was based on the OpAMP instance UID | ||
| - the instance UID was typically set based on the `service.instance.id` from the Collector resource attributes | ||
| - it could be overriden using the `instance_uid` configuration of the OpAMP extension | ||
|
|
||
| This meant that the reported `service.instance.id` did not always match the Collector resource attributes, | ||
| which is a problem for correlation, and that server implementations got used to the typical case of | ||
| `service.instance.id` and `instance_uid` matching, despite there being no guarantee of this. | ||
|
|
||
| Now: | ||
| - the reported value of `service.instance.id` always matches the Collector resource attributes | ||
| - the instance UID is either taken from the `instance_uid` configuration or generated randomly. | ||
|
|
||
| This means that the two values can never be expected to match, unless both configurations are explicitly set to the same value. | ||
| That is what the OpAMP supervisor does, which means its behavior is unaffected. | ||
|
|
||
|
|
||
| # If your change doesn't affect end users or the exported elements of any package, | ||
| # you should instead start your pull request title with [chore] or use the "Skip Changelog" label. | ||
| # Optional: The change log or logs in which this entry should be included. | ||
| # e.g. '[user]' or '[user, api]' | ||
| # Include 'user' if the change is relevant to end users. | ||
| # Include 'api' if there is a change to a library API. | ||
| # Default: '[user]' | ||
| change_logs: [user] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,3 +13,6 @@ extensions: | |
|
|
||
| service: | ||
| extensions: [opamp] | ||
| telemetry: | ||
| resource: | ||
| "service.instance.id": "{{.InstanceUid}}" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,9 +56,10 @@ type opampAgent struct { | |
| cfg *Config | ||
| logger *zap.Logger | ||
|
|
||
| agentType string | ||
| agentVersion string | ||
| resourceAttrs map[string]string | ||
| agentType string | ||
| agentVersion string | ||
| agentInstanceID string | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am confused by why we have 2 fields now
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From what I understood through the changelog entry, It sounds a bit confusing, yes. Maybe we could have a comment explaining why these two fields with very similar names exist?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The two concepts have always had confusingly similar names to be honest, but I can rename the fields and add comments if that makes things clearer. Note that the change Tigran suggested earlier makes it so that they won't usually match. They will only match if the user (or the supervisor) manually sets both (with the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I ended up renaming
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, renaming definitely helps understand what's going on. I think this is the desirable behavior now. Can you please also describe in a bit more details in the PR description the impact of the change. The description you have in changelog subtext is great, I think it can be used in the PR description too. |
||
| resourceAttrs map[string]string | ||
|
|
||
| instanceID uuid.UUID | ||
|
|
||
|
|
@@ -296,25 +297,27 @@ func newOpampAgent(cfg *Config, set extension.Settings) (*opampAgent, error) { | |
| agentVersion = sv.AsString() | ||
| } | ||
|
|
||
| uid, err := uuid.NewV7() | ||
| if err != nil { | ||
| return nil, fmt.Errorf("could not generate uuidv7: %w", err) | ||
| agentInstanceID := "" | ||
|
|
||
| if sid, ok := set.Resource.Attributes().Get(string(conventions.ServiceInstanceIDKey)); ok { | ||
| agentInstanceID = sid.Str() | ||
| } | ||
|
|
||
| var uid uuid.UUID | ||
| if cfg.InstanceUID != "" { | ||
| var err error | ||
| uid, err = parseInstanceIDString(cfg.InstanceUID) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("could not parse configured instance id: %w", err) | ||
| } | ||
| } else { | ||
| sid, ok := set.Resource.Attributes().Get(string(conventions.ServiceInstanceIDKey)) | ||
| if ok { | ||
| uid, err = uuid.Parse(sid.AsString()) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| var err error | ||
| uid, err = uuid.NewV7() | ||
| if err != nil { | ||
| return nil, fmt.Errorf("could not generate uuidv7: %w", err) | ||
| } | ||
| } | ||
|
|
||
| resourceAttrs := make(map[string]string, set.Resource.Attributes().Len()) | ||
| set.Resource.Attributes().Range(func(k string, v pcommon.Value) bool { | ||
| resourceAttrs[k] = v.Str() | ||
|
|
@@ -327,6 +330,7 @@ func newOpampAgent(cfg *Config, set extension.Settings) (*opampAgent, error) { | |
| logger: set.Logger, | ||
| agentType: agentType, | ||
| agentVersion: agentVersion, | ||
| agentInstanceID: agentInstanceID, | ||
| instanceID: uid, | ||
| capabilities: cfg.Capabilities, | ||
| opampClient: opampClient, | ||
|
|
@@ -377,7 +381,7 @@ func (o *opampAgent) createAgentDescription() error { | |
| description := getOSDescription(o.logger) | ||
|
|
||
| ident := []*protobufs.KeyValue{ | ||
| stringKeyValue(string(conventions.ServiceInstanceIDKey), o.instanceID.String()), | ||
| stringKeyValue(string(conventions.ServiceInstanceIDKey), o.agentInstanceID), | ||
| stringKeyValue(string(conventions.ServiceNameKey), o.agentType), | ||
| stringKeyValue(string(conventions.ServiceVersionKey), o.agentVersion), | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this removed? Looks weird. I think we should assert on some expected service instance ID here, no?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, you're right. I removed it because the test was failing and I thought it was testing the extension (in which case we expect the instance ID to be random), but since this seems to be for the supervisor I would expect it to match the instance UID...
The usual error seems to be "could not get bootstrap info from the Collector: collector's OpAMP client never connected to the Supervisor", which I can't easily relate to any of my changes. I've been trying to debug these tests for a while but I'm honestly somewhat at a loss, mostly because all the useful logic happens in a different process, so the debugger never gets attached. Do you have advice on where the discrepancy could come from?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried some stuff locally and I hit a similar problem to you, @jade-guiton-dd. I could run only this specific test with
go test -tags=e2e -run 'TestSupervisorAgentDescriptionConfigApplies' -count=1 -v .(in thecmd/opampsupervisorfolder) though.It seems like
require.Subsetends up comparing values withreflect.DeepEqual(see https://github.com/stretchr/testify/blob/v1.11.1/assert/assertions.go#L71) and I think the protobuf types might somehow be interfering with the comparison now, but I don't understand why.I did some local changes to convert
[]*protobufs.Keyvalueto amap[string]stringand I got a proper test failure due to mismatch in expected values:When I run the test above with the assertion that this PR removed on the
service.instance.idplus this patch applied I get this:Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, so that confirms that the supervisor is not properly setting
service.instance.idat the Collector level.I originally assumed it did because of this template, but after looking deeper into it, I'm not actually sure how
ResourceAttributesis filled. It definitely contains the explicitly-specified values fromagent.description.identifying_attributes, but I'm not sure ifservice.instance.idis ever added in there.So I guess there are two options:
service.instance.idis always set to the OpAMP instance UID, which would require modifying the code to make sure the resource attribute is always overwrittenUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since for some reason the test is still failing for me locally, I tried pushing a new version with a modified
composeExtraTelemetryConfigthat adds the test line back in and always setsservice.instance.idto the instance UID (unless explicitly set ins.agentDescription)Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I figured it out.
service.instance.idis becausecomposeExtraTelemetryConfigis not called when composing the configuration for the bootstrap Collector. So I instead decided to set the attribute directly insidetemplates/opampextension.yaml. This seems to fix the test, which is also simplified a bit from the patch you suggested above. I am assuming this will compose gracefully with the "extra telemetry" configuration.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome. I'm happy that this is fixed and that you could use a simpler patch 😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will do a full review pass in a bit. Great work!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@douglascamata did you find the time to review this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ll find some time to check it out later today or tomorrow. 👍