Repository navigation
[9.6](backport #54846) Install a no-op monitor state loader in heartbeat receiver when no Elasticsearch client is available - #54961
Open
mergify[bot] wants to merge 1 commit into
Open
mergify[bot] wants to merge 1 commit into
mergify[bot] wants to merge 1 commit into
Conversation
…asticsearch client is available (#54846) * heartbeat: let hosts install a no-op monitor state loader Heartbeat defers every monitor state load when its monitors come over the control protocol, so that state loads wait for the Elasticsearch client the output unit used to bring. A host that knows no such client is coming had no way to say so, and monitors had to wait out the 15s deferral. Add WithoutStateLoader next to WithElasticsearchStateLoader, so a host can install the no-op loader and let monitors start with no prior state right away. Assisted-By: Claude Opus 5 <noreply@anthropic.com> * x-pack/heartbeat/hbreceiver: don't wait 15s for a state loader that isn't coming A Heartbeat receiver that takes its monitors over the control protocol gets a state loader that is deferred for 15s. In a Heartbeat process that wait ends when the output unit arrives and the Elasticsearch client is built from it. The receiver registers no output reloader on purpose, so the only thing that ends the wait is the start hook installing the Elasticsearch loader from monitor_state.elasticsearch. When that setting is absent, as with a non-Elasticsearch exporter, or the client cannot be built, every monitor state load blocked until the deferral timed out and the first events were held back by 15s. Install the no-op loader on both of those paths, so monitors start with no prior state instead of waiting. The hook now takes the installer as an interface, which keeps the nil Heartbeat case explicit in the factory and lets the tests assert which loader each path installs. Assisted-By: Claude Opus 5 <noreply@anthropic.com> * x-pack/heartbeat/hbreceiver: bound the time to the first monitor event TestReceiverWithControlProtocol only waited for events with a 90s budget, so the 15s monitor state deferral it used to hit was invisible in the test apart from its runtime. Assert the first event arrives within 10s, which is loose enough for slow CI and well below the deferral, so that wait coming back fails the test. Assisted-By: Claude Opus 5 <noreply@anthropic.com> (cherry picked from commit 5bcc68e)
Contributor
🤖 GitHub commentsJust comment with:
|
Contributor
Author
|
Tick the box to add this pull request to the merge queue (same as
|
|
Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane) |
Contributor
|
Dependency review finished without posting an analysis comment. If you expected a review, push a new commit to this pull request (or close and reopen it) to try again. Workflow run: https://github.com/elastic/beats/actions/runs/45884676484 |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the Heartbeat OTel receiver gets its monitors over the control protocol, Heartbeat gives them a "deferred" state loader. It blocks every state load until it is replaced, or until a 15s timeout. In the receiver, the only thing that replaces it is the Elasticsearch state loader. If no Elasticsearch client is configured, or one can't be built, nothing opens it. Every monitor then waits the full 15s before its first event goes out.
If there is no Elasticsearch state loader to install, install a no-op one instead. It reports "no prior state" right away, so monitors start immediately.
Heartbeat.WithoutStateLoader()inheartbeat/beater/heartbeat.go. It atomically replaces the deferred loader withmonitorstate.NilStateLoader.x-pack/heartbeat/hbreceiver/elasticsearch_auth.go,beatsAuthStartHooknow calls it on every path that doesn't install an Elasticsearch loader: an emptymonitor_state.elasticsearchreference, and a failure to build the ES client (still best-effort, so startup isn't blocked).beatsAuthStartHooktakes a smallstateLoaderInstallerinterface instead of*beater.Heartbeat, so it can be tested with a fake.heartbeatCreator.stateLoaders()returns a true nil interface when no Heartbeat was created, and the hook handles that case.Proposed commit message
Install a no-op monitor state loader in heartbeat receiver when no Elasticsearch client is available
Heartbeat uses a deferred state loader when monitors arrive over the control protocol. It blocks every state load until it is replaced, or until a 15s timeout. In the OTel receiver, the start hook is the only thing that replaces it, and it did so only when an Elasticsearch client was built. Without one, the first run of each monitor waited out the timeout.
Add
Heartbeat.WithoutStateLoaderand call it from the receiver start hook on every path that doesn't install an Elasticsearch loader, so monitors start without prior state right away.Checklist
[ ] I have made corresponding changes to the documentation[ ] I have made corresponding change to the default configuration files[ ] I have added an entry in./changelog/fragmentsusing the changelog tool.How to test this PR locally
TestReceiverWithControlProtocolnow also requires the first monitor event within 10s, well below the 15s deferred timeout.Related issues
Use cases
monitor_state.elasticsearch: monitors publish their first event immediately.This is an automatic backport of pull request #54846 done by [Mergify](https://mergify.com).