-
Notifications
You must be signed in to change notification settings - Fork 99
Be-very defensive when it comes to updating local_metadata. #5783
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
Changes from 6 commits
2ebecc8
96fa69b
c50065b
114e494
53c6e41
c6795ad
a8bcecd
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,45 @@ | ||
| # REQUIRED | ||
| # Kind can be one of: | ||
| # - breaking-change: a change to previously-documented behavior | ||
| # - deprecation: functionality that is being removed in a later release | ||
| # - bug-fix: fixes a problem in a previous version | ||
| # - enhancement: extends functionality but does not break or fix existing behavior | ||
| # - feature: new functionality | ||
| # - known-issue: problems that we are aware of in a given version | ||
| # - security: impacts on the security of a product or a user’s deployment. | ||
| # - upgrade: important information for someone upgrading from a prior version | ||
| # - other: does not fit into any of the other categories | ||
| kind: bug-fix | ||
|
|
||
| # REQUIRED for all kinds | ||
| # Change summary; a 80ish characters long description of the change. | ||
| summary: fix issue prevent checkin local_metadata from being updated | ||
|
|
||
| # REQUIRED for breaking-change, deprecation, known-issue | ||
| # Long description; in case the summary is not enough to describe the change | ||
| # this field accommodate a description without length limits. | ||
| # description: | ||
|
|
||
| # REQUIRED for breaking-change, deprecation, known-issue | ||
| # impact: | ||
|
|
||
| # REQUIRED for breaking-change, deprecation, known-issue | ||
| # action: | ||
|
|
||
| # REQUIRED for all kinds | ||
| # Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc. | ||
| component: fleet-server | ||
|
|
||
| # AUTOMATED | ||
| # OPTIONAL to manually add other PR URLs | ||
| # PR URL: A link the PR that added the changeset. | ||
| # If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added. | ||
| # NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number. | ||
| # Please provide it if you are adding a fragment for a different PR. | ||
| # pr: https://github.com/owner/repo/1234 | ||
|
|
||
| # AUTOMATED | ||
| # OPTIONAL to manually add other issue URLs | ||
| # Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of). | ||
| # If not present is automatically filled by the tooling with the issue linked to the PR number. | ||
| # issue: https://github.com/owner/repo/1234 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1037,30 +1037,36 @@ func parseMeta(zlog zerolog.Logger, agent *model.Agent, req *CheckinRequest) ([] | |
| return nil, nil | ||
| } | ||
|
|
||
| // Check for empty string - not valid metadata | ||
| if str, ok := reqLocalMeta.(string); ok && strings.TrimSpace(str) == "" { | ||
| zlog.Warn().Msg("local metadata empty; won't update metadata") | ||
| return nil, nil | ||
| } | ||
|
|
||
| // Deserialize the agent's metadata copy | ||
| var agentLocalMeta interface{} | ||
| if err := json.Unmarshal(agent.LocalMetadata, &agentLocalMeta); err != nil { | ||
| return nil, fmt.Errorf("parseMeta local: %w", err) | ||
| if agent.LocalMetadata != nil { | ||
|
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. Just curious, why is this 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. Because this actually would fail if the |
||
| if err := json.Unmarshal(agent.LocalMetadata, &agentLocalMeta); err != nil { | ||
| // if it has metadata in the document it has to be JSON or the mapping is incorrect | ||
| return nil, fmt.Errorf("parseMeta local: %w", err) | ||
| } | ||
| } | ||
|
|
||
| var outMeta []byte | ||
|
|
||
| // Compare the deserialized meta structures and return the bytes to update if different | ||
| if !reflect.DeepEqual(reqLocalMeta, agentLocalMeta) { | ||
|
|
||
| zlog.Trace(). | ||
| RawJSON("oldLocalMeta", agent.LocalMetadata). | ||
| RawJSON("newLocalMeta", req.LocalMetadata). | ||
| Msg("local metadata not equal") | ||
| // Compare the deserialized meta structures, already the same means no update needs to occur. | ||
| if reflect.DeepEqual(reqLocalMeta, agentLocalMeta) { | ||
| return nil, nil | ||
| } | ||
|
|
||
| zlog.Info(). | ||
| RawJSON("req.LocalMeta", req.LocalMetadata). | ||
| Msg("applying new local metadata") | ||
| zlog.Trace(). | ||
| RawJSON("oldLocalMeta", agent.LocalMetadata). | ||
| RawJSON("newLocalMeta", req.LocalMetadata). | ||
| Msg("local metadata not equal") | ||
|
|
||
| outMeta = req.LocalMetadata | ||
| } | ||
| zlog.Info(). | ||
| RawJSON("req.LocalMeta", req.LocalMetadata). | ||
| Msg("applying new local metadata") | ||
|
|
||
| return outMeta, nil | ||
| return req.LocalMetadata, nil | ||
| } | ||
|
|
||
| func parseComponents(zlog zerolog.Logger, agent *model.Agent, req *CheckinRequest) ([]byte, *[]string, error) { | ||
|
|
||
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.
sounds weird, should it be fix issue preventing?