Skip to content

Restore Heartbeat monitor state in OTel mode - #16902

Merged
belimawr merged 40 commits into
elastic:mainfrom
belimawr:heartbeat-monitor-state-16284
Oct 22, 2026
Merged

belimawr merged 40 commits into
elastic:mainfrom
belimawr:heartbeat-monitor-state-16284

Conversation

@belimawr

@belimawr belimawr commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Restore Heartbeat monitor state in OTel mode
Configure output-scoped Elasticsearch authentication for Heartbeat receivers and delegate
transport settings to beatsauth.

Assisted-by: Cursor, Model: GPT-5.6 Sol (High)
Assisted-by: Cursor, Model: Gemini 3.8 Flash (High)

Why is it important?

Fixes #16284

Checklist

  • I have read and understood the pull request guidelines of this project.
  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in ./changelog/fragments using the changelog tool
  • I have added an integration test or an E2E test

## Disruptive User Impact

How to test this PR locally

Run the tests

go test -count=1 -run="TestGetBeatsAuthExtensionConfig|TestHeartbeatElasticsearchAuth" ./internal/pkg/otel/translate/
go test -count=1 ./internal/pkg/otel/translate/

Manual test

Runtime precondition

This Heartbeat defaults to the process runtime. Force OTel runtime via
Fleet policy override:
In Fleet UI go to: -> Settings -> Advanced internal YAML settings
and add the following snippet:

agent.internal.runtime:
  heartbeat:
    default: otel

Kibana and Elastic Agent setup

Example URLs assume you're using Elastic-Package

  1. Start a webserver to use as target for the monitor, for example python -m http.server.
  2. Create a dedicated Fleet agent policy with the default Elasticsearch output.
  3. Apply the runtime override above and wait for the Agent to receive the new policy revision.
  4. Enroll a local Elastic Agent build in that policy.
  5. Create a Synthetics private location bound to that policy:
  1. Create an HTTP Synthetics monitor on the private location.
  • Go to: https://localhost:5601/app/synthetics/add-monitor
  • Select "HTTP" as monitor type
  • In URL enter the URL of your webserver
  • Select the private location you created in the previous step
  • Change the frequency to 10s
  • Click "Run test" to make sure the monitor is working
  • Save/Create the monitor
  • You'll land in the monitors page, click on your monitor and copy its ID from the URL (the last element of the URL path)

Reproduction

Run the following query in Dev Tools, replacing <monitor-id> by the monitor ID you copied.

POST synthetics-http*/_search?filter_path=hits.hits._source
{
  "size": 1,
  "_source": [
    "agent.id",
    "monitor.id",
    "observer.name",
    "state.id",
    "state.started_at",
    "state.checks"
  ],
  "sort": [{"@timestamp": {"order": "desc"}}],
  "query": {
    "bool": {
      "filter": [
        {"term": {"monitor.id": "<monitor-id>"}},
        {"exists": {"field": "state.id"}}
      ]
    }
  }
}

Record the result:

  • state.checks: ever-increasing number of checks.
  • state.id: the persisted Heartbeat state ID.
  • state.started_at: the time of the first check.

Restart Elastic Agent, for example on Linux: sudo systemctl restart elastic-agent.

Run the query again. state.checks must have increased; state.id and
state.started_at must be unchanged.

Related issues

Questions to ask yourself

  • How are we going to support this in production?
  • How are we going to measure its adoption?
  • How are we going to debug this?
  • What are the metrics I should take care of?
  • ...

@belimawr belimawr self-assigned this Sep 29, 2026
@belimawr belimawr added the Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team label Sep 29, 2026
@mergify

mergify Bot commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

This pull request does not have a backport label. Could you fix it @belimawr? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-./d./d is the label that automatically backports 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.

Assisted-by: gpt-5.6-sol-high
@belimawr belimawr added the backport-9.5 Automated backport to the 9.5 branch label Sep 29, 2026
@mergify

mergify Bot commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

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 heartbeat-monitor-state-16284 upstream/heartbeat-monitor-state-16284
git merge upstream/main
git push upstream heartbeat-monitor-state-16284

@belimawr belimawr changed the title Heartbeat monitor state 16284 [DO NOT MERGE] Restore Heartbeat monitor state in OTel mode Sep 30, 2026
@mergify

mergify Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

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 heartbeat-monitor-state-16284 upstream/heartbeat-monitor-state-16284
git merge upstream/main
git push upstream heartbeat-monitor-state-16284

@belimawr

Copy link
Copy Markdown
Member Author

@ebeahan I double checked and this PR, the way it is, fixes the parity gap #2 mentioned in #16130.

When this PR gets merged #16284 will be fully fixed and #16130 partially fixed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Configuration and authentication mismatches can prevent state restoration and disrupt Elasticsearch publishing.

4 open issues
What changed in this PR

This PR aims to restore Heartbeat monitor-state continuity across restarts in Elastic Agent’s OTel runtime.

Changes:

  • Connects Heartbeat receivers to output-scoped beatsauth configuration.
  • Adds Elasticsearch endpoint, authentication, and Cloud ID translation.
  • Extends unit and integration coverage for authentication and restored state.
File Description
testing/​integration/​ess/​heartbeat_monitoring_test.go Checks state continuity and counters after restarts.
internal/​pkg/​otel/​translate/​testdata/​certs/​client-unencrypted.key Adds a TLS test fixture.
internal/​pkg/​otel/​translate/​output_elasticsearch.go Translates endpoints and authentication into beatsauth settings.
internal/​pkg/​otel/​translate/​output_elasticsearch_test.go Tests authentication, Cloud ID, and transport translation.
internal/​pkg/​otel/​translate/​otelconfig.go Adds Heartbeat’s authentication-extension reference.
internal/​pkg/​otel/​translate/​otelconfig_test.go Updates receiver and extension expectations.
changelog/​fragments/​1790701465-restore-heartbeat-monitor-state-in-otel-mode.yaml Records the intended restoration fix.

Review effort: Balanced

Assisted-by: gpt-5.6-sol-high
Assisted-by: gpt-5.6-sol-high
Assisted-by: gpt-5.6-sol-high
Assisted-by: gpt-5.6-sol-high
@infra-vault-gh-plugin-prod

Copy link
Copy Markdown

💛 Build succeeded, but was flaky

Failed CI Steps

History

cc @belimawr

@belimawr belimawr added backport-skip and removed backport-9.5 Automated backport to the 9.5 branch labels Oct 21, 2026
@belimawr
belimawr requested review from samuelvl and swiatekm October 21, 2026 18:57
@mergify

mergify Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@khushijain21
khushijain21 self-requested a review October 22, 2026 13:22
@belimawr
belimawr merged commit fe0cdc3 into elastic:main Oct 22, 2026
38 checks passed
@belimawr belimawr added backport-9.6 Automated backport to the 9.6 branch and removed backport-skip labels Oct 26, 2026
belimawr added a commit that referenced this pull request Oct 27, 2026
…17568)

Restore Heartbeat monitor state in OTel mode
Configure output-scoped Elasticsearch authentication for Heartbeat receivers and delegate
transport settings to beatsauth.

Assisted-by: Cursor, Model: GPT-5.6 Terra & Sol (High)
Assisted-by: Cursor, Model: Gemini 3.8 Flash (High)
(cherry picked from commit fe0cdc3)

# Conflicts:
#	internal/pkg/otel/translate/otelconfig_test.go

Assisted-by: gpt-5.6-terra-high

---------

Co-authored-by: Tiago Queiroz <tiago.queiroz@elastic.co>
khushijain21 added a commit that referenced this pull request Nov 20, 2026
…18106)

Cloud ID resolution was added to the Elasticsearch output translation in
#16902 only because Beats supports it. Elastic Agent never resolved
cloud_id for the process runtime and does not document it, so a config
that worked under the OTel runtime would break after falling back to the
process runtime. It first shipped in 9.6 and is not known to be in use.

Removing it also drops the copy of the output config that resolution
required, along with the queue write-back that kept the copy in sync.

Assisted-By: Cursor

Co-authored-by: Cursor <cursoragent@cursor.com>
khushijain21 added a commit that referenced this pull request Nov 20, 2026
…18106) (#18126)

Cloud ID resolution was added to the Elasticsearch output translation in
#16902 only because Beats supports it. Elastic Agent never resolved
cloud_id for the process runtime and does not document it, so a config
that worked under the OTel runtime would break after falling back to the
process runtime. It first shipped in 9.6 and is not known to be in use.

Removing it also drops the copy of the output config that resolution
required, along with the queue write-back that kept the copy in sync.

Assisted-By: Cursor


(cherry picked from commit 934da63)

Co-authored-by: Khushi Jain <khushi.jain@elastic.co>
Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-9.6 Automated backport to the 9.6 branch Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Elasticsearch monitor-state restoration is bypassed

5 participants