Skip to content

Conversation

@VihasMakwana
Copy link
Contributor

@VihasMakwana VihasMakwana commented Nov 23, 2025

This PR updates add_docker_metadata to log the error instead of returning it.

Relates elastic/elastic-agent#11171

@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Nov 23, 2025
@github-actions
Copy link
Contributor

🤖 GitHub comments

Just comment with:

  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)

@mergify
Copy link
Contributor

mergify bot commented Nov 23, 2025

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @VihasMakwana? 🙏.
For such, you'll need to label your PR with:

  • The upcoming major version of the Elastic Stack
  • The upcoming minor version of the Elastic Stack (if you're not pushing a breaking change)

To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-8./d is the label to automatically backport to the 8./d branch. /d is the digit
  • backport-active-all is the label that automatically backports to all active branches.
  • backport-active-8 is the label that automatically backports to all active minor branches for the 8 major.
  • backport-active-9 is the label that automatically backports to all active minor branches for the 9 major.

@VihasMakwana VihasMakwana force-pushed the bump-elastic-autodiscover branch from 5ab64ef to f5e92f8 Compare November 23, 2025 16:57
@VihasMakwana VihasMakwana added Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team backport-8.19 Automated backport to the 8.19 branch backport-9.2 Automated backport to the 9.2 branch labels Nov 23, 2025
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Nov 23, 2025
@VihasMakwana VihasMakwana marked this pull request as ready for review November 24, 2025 06:57
@VihasMakwana VihasMakwana requested a review from a team as a code owner November 24, 2025 06:57
@elasticmachine
Copy link
Contributor

Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane)

@VihasMakwana VihasMakwana requested a review from a team as a code owner November 24, 2025 08:55
@mergify
Copy link
Contributor

mergify bot commented Nov 24, 2025

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b bump-elastic-autodiscover upstream/bump-elastic-autodiscover
git merge upstream/main
git push upstream bump-elastic-autodiscover

@cmacknz
Copy link
Member

cmacknz commented Nov 24, 2025

This should have a change entry

@cmacknz
Copy link
Member

cmacknz commented Nov 24, 2025

Looking closer at elastic/elastic-agent-autodiscover#145

It seems like the add_docker_metadata already attempts to treat not having docker as non-fatal, but it doesn't handle errors from Start the way it does from New and it should:

watcher, err := watcherConstructor(log, config.Host, config.TLS, config.MatchShortID)
if err != nil {
dockerAvailable = false
log.Debugf("%v: docker environment not detected: %+v", processorName, err)
} else {
dockerAvailable = true
log.Debugf("%v: docker environment detected", processorName)
if err = watcher.Start(); err != nil {
return nil, fmt.Errorf("failed to start watcher: %w", err)
}
}

Elastic Agent does this properly for example

https://github.com/elastic/elastic-agent/blob/36a2197f33d0260f09be1b19437af995f57a6218/internal/pkg/composable/providers/docker/docker.go#L52-L56

I'm not sure we need elastic/elastic-agent-autodiscover#145 to fix this, we should continue returning an error, and then at the call site log+ignore it.

@cmacknz
Copy link
Member

cmacknz commented Nov 24, 2025

if err := watcher.Start(); err != nil {
return nil, errWrap(err)
}

This change will make the beats docker auto-discovery provider continue even if it can't start the docker watcher, which will probably make it sit there silently not working.

This has to be explicitly configured from what I can tell so I'm not sure we want to change this globally, just fix add_docker_metadata's handling of Start errors:
https://www.elastic.co/docs/reference/beats/filebeat/configuration-autodiscover#_docker_2

@VihasMakwana VihasMakwana changed the title bump elastic-agent-autodiscover [add_docker_metadata] log the error instead of returning it Nov 24, 2025
@VihasMakwana
Copy link
Contributor Author

@cmacknz Could you take a look when you're back?

@VihasMakwana VihasMakwana requested a review from cmacknz November 24, 2025 18:41
@cmacknz
Copy link
Member

cmacknz commented Nov 24, 2025

A couple suggestions on wording but the change otherwise LGTM

@VihasMakwana VihasMakwana requested a review from cmacknz November 24, 2025 18:54
cmacknz
cmacknz previously approved these changes Nov 24, 2025
@cmacknz cmacknz dismissed their stale review November 24, 2025 19:28

Missing a test

@cmacknz
Copy link
Member

cmacknz commented Nov 24, 2025

Hit approve too early, we should add a test for this case. There is already a test for the no docker case before Start:

func TestInitializationNoDocker(t *testing.T) {
var testConfig = config.NewConfig()
testConfig.SetString("host", -1, "unix:///var/run42/docker.sock")
p, err := buildDockerMetadataProcessor(logp.L(), testConfig, docker.NewWatcher)
assert.NoError(t, err, "initializing add_docker_metadata processor")
input := mapstr.M{}
result, err := p.Run(&beat.Event{Fields: input})
assert.NoError(t, err, "processing an event")
assert.Equal(t, mapstr.M{}, result.Fields)
}

There is already a mock watcher in there which is probably what you have to modify to also test the start case.

@VihasMakwana
Copy link
Contributor Author

@cmacknz Done!

@VihasMakwana VihasMakwana requested a review from cmacknz November 25, 2025 05:30
@VihasMakwana
Copy link
Contributor Author

CI is green on elastic-agent with this PR: elastic/elastic-agent#11374

@VihasMakwana VihasMakwana merged commit 04732ce into main Nov 25, 2025
205 of 208 checks passed
@VihasMakwana VihasMakwana deleted the bump-elastic-autodiscover branch November 25, 2025 16:55
mergify bot pushed a commit that referenced this pull request Nov 25, 2025
* go.mod and notice

* go.mod and notice

* prometheus

* fix watcher.Start()

* changelog

* dockerAvailable false

* comments

* unit test

(cherry picked from commit 04732ce)
mergify bot pushed a commit that referenced this pull request Nov 25, 2025
* go.mod and notice

* go.mod and notice

* prometheus

* fix watcher.Start()

* changelog

* dockerAvailable false

* comments

* unit test

(cherry picked from commit 04732ce)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-8.19 Automated backport to the 8.19 branch backport-9.2 Automated backport to the 9.2 branch skip-changelog Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants