Skip to content

[9.4](backport #51591) remove global paths from metricbeat#51778

Merged
leehinman merged 2 commits into
9.4from
mergify/bp/9.4/pr-51591
Jul 9, 2026
Merged

[9.4](backport #51591) remove global paths from metricbeat#51778
leehinman merged 2 commits into
9.4from
mergify/bp/9.4/pr-51591

Conversation

@mergify

@mergify mergify Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Proposed commit message

This change removes the use of global/singleton path state from Metricbeat and replaces it with per-instance paths, fixing a bug where multiple Metricbeat receivers could share the same data store.

Problem

Metricbeat was using global paths.Paths (a package-level singleton) when resolving file paths like the SQL cursor data store. In receiver mode, multiple Metricbeat instances share the same process, so they would all resolve to the same data path, causing them to share state incorrectly.

Changes

  • metricbeat/mb/mb.go: Added a Paths *paths.Path field to BaseModule so each module carries its own path instance.
  • metricbeat/mb/builders.go: Threaded the *paths.Path parameter through newBaseModuleFromConfig so it is assigned to the BaseModule at construction time.
  • metricbeat/mb/lightmetricset.go: Updated LightMetricSet.baseModule() to pass the metric set's path to newBaseModuleFromConfig.
  • x-pack/libbeat/cmd/instance/beat.go: Simplified NewBeatForReceiver by removing the filebeat-specific branch for path initialization — both filebeat and metricbeat now use the same path initialization path, constructing a fresh paths.Path instance per beat.
  • x-pack/metricbeat/module/sql/module.go: Replaced paths.Resolve(paths.Data, "sql-cursor") (global) with m.Paths.Resolve(paths.Data, "sql-cursor") (per-instance), so each SQL module instance resolves its own data directory.

Checklist

  • 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. Where relevant, I have used the stresstest.sh script to run them under stress conditions and race detector to verify their stability.
  • I have added an entry in ./changelog/fragments using the changelog tool.

Disruptive User Impact

None. Stand alone Metricbeat will function as before, only metricbeat receiver will have multiple beat instances in the same process. This change will allow the sql module to have unique data path per beat instance.

How to test this PR locally

cd x-pack/metricbeat/module/sql
go test .

Related issues

Use cases

Screenshots

Logs


This is an automatic backport of pull request #51591 done by [Mergify](https://mergify.com).

* remove global paths from metricbeat

* x-pack/metricbeat/sql: migrate cursor tests off the global paths singleton

---------

Co-authored-by: Orestis Floros <orestis.floros@elastic.co>
(cherry picked from commit 37f3d26)

# Conflicts:
#	metricbeat/mb/builders.go
#	x-pack/libbeat/cmd/instance/beat.go
#	x-pack/metricbeat/module/sql/query/query_test.go
@mergify mergify Bot added backport conflicts There is a conflict in the backported pull request labels Jul 7, 2026
@mergify mergify Bot requested review from a team as code owners July 7, 2026 12:40
@mergify mergify Bot added backport conflicts There is a conflict in the backported pull request labels Jul 7, 2026
@mergify mergify Bot requested review from khushijain21 and leehinman and removed request for a team July 7, 2026 12:40
@mergify

mergify Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Cherry-pick of 37f3d26 has failed:

On branch mergify/bp/9.4/pr-51591
Your branch is up to date with 'origin/9.4'.

You are currently cherry-picking commit 37f3d269d.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	new file:   changelog/fragments/1782499306-remove-global-paths-from-metricbeat.yaml
	modified:   metricbeat/mb/lightmetricset.go
	modified:   metricbeat/mb/lightmetricset_test.go
	modified:   metricbeat/mb/mb.go
	modified:   metricbeat/mb/mb_test.go
	modified:   x-pack/metricbeat/module/sql/module.go
	modified:   x-pack/metricbeat/module/sql/module_test.go
	modified:   x-pack/metricbeat/module/sql/query/cursor/store_test.go
	modified:   x-pack/metricbeat/module/sql/query/cursor_integration_test.go
	modified:   x-pack/metricbeat/module/sql/query/query_integration_test.go

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   metricbeat/mb/builders.go
	both modified:   x-pack/libbeat/cmd/instance/beat.go
	both modified:   x-pack/metricbeat/module/sql/query/query_test.go

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

@botelastic botelastic Bot added the needs_team Indicates that the issue/PR needs a Team:* label label Jul 7, 2026
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

🤖 GitHub comments

Just comment with:

  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)
  • /test : Run the Buildkite pipeline.

@github-actions github-actions Bot added the Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team label Jul 7, 2026
@botelastic botelastic Bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Jul 7, 2026
@infra-vault-gh-plugin-prod

Copy link
Copy Markdown

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

@mergify mergify Bot mentioned this pull request Jul 7, 2026
6 tasks
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

TL;DR

Both failed Buildkite jobs stopped in pre-commit run --all-files because the PR head still contains unresolved cherry-pick conflict markers in three files. Resolve those conflict blocks with the 9.4 branch API, then rerun pre-commit.

Remediation

  • In metricbeat/mb/builders.go:61, keep the 9.4 NewModule(config, r, p, logger) signature and resolve the call as newBaseModuleFromConfig(config, logger, p) so the new per-instance paths are passed without referencing undefined info.
  • In x-pack/libbeat/cmd/instance/beat.go:116, remove the conflict block and initialize a fresh paths.Path once for all receivers: cfg.Unpack, paths.New(), p.InitPaths(&partialConfig.Path), then b.Info.Paths = p.
  • In x-pack/metricbeat/module/sql/query/query_test.go:170, use the 9.4 call form mb.NewModule(c, mb.Registry, beatPaths, logptest.NewTestingLogger(t, "")) in the helper sites; do not use beat.Info on this branch.
  • Validate with pre-commit run --all-files and cd x-pack/metricbeat/module/sql && go test ..
Investigation details

Root Cause

This is a backport conflict, not a flaky test or infrastructure issue. The Buildkite pre-commit hook found literal merge-conflict markers in the PR head:

  • x-pack/libbeat/cmd/instance/beat.go:116, x-pack/libbeat/cmd/instance/beat.go:130, x-pack/libbeat/cmd/instance/beat.go:133
  • metricbeat/mb/builders.go:61, metricbeat/mb/builders.go:63, metricbeat/mb/builders.go:65
  • x-pack/metricbeat/module/sql/query/query_test.go:170, x-pack/metricbeat/module/sql/query/query_test.go:172, x-pack/metricbeat/module/sql/query/query_test.go:175

The incoming change also references the newer mb.NewModule(..., beat.Info{...}) shape, while the PR head on 9.4 still has func NewModule(config *conf.C, r *Register, p *paths.Path, logger *logp.Logger). The conflict resolution should therefore thread p/logger through the existing 9.4 signature instead of taking the incoming beat.Info hunk verbatim.

Evidence

check for merge conflicts................................................Failed
- hook id: check-merge-conflict
- exit code: 1

x-pack/libbeat/cmd/instance/beat.go:116: Merge conflict string '<<<<<<<' found
x-pack/libbeat/cmd/instance/beat.go:130: Merge conflict string '=======' found
x-pack/libbeat/cmd/instance/beat.go:133: Merge conflict string '>>>>>>>' found
metricbeat/mb/builders.go:61: Merge conflict string '<<<<<<<' found
metricbeat/mb/builders.go:63: Merge conflict string '=======' found
metricbeat/mb/builders.go:65: Merge conflict string '>>>>>>>' found
x-pack/metricbeat/module/sql/query/query_test.go:170: Merge conflict string '<<<<<<<' found
x-pack/metricbeat/module/sql/query/query_test.go:172: Merge conflict string '=======' found
x-pack/metricbeat/module/sql/query/query_test.go:175: Merge conflict string '>>>>>>>' found

The PR head also shows x-pack/metricbeat/module/sql/query/query_test.go:170-175 split between the old paths.New() call and the incoming beat.Info{Paths: beatPaths, Logger: ...} call.

Verification

Not run locally: the failure is fully explained by the pre-commit merge-conflict check and the PR ref content, and the local workspace is not checked out at the PR head.


What is this? | From workflow: PR Buildkite Detective

Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not.

@leehinman leehinman merged commit ff972ff into 9.4 Jul 9, 2026
134 checks passed
@leehinman leehinman deleted the mergify/bp/9.4/pr-51591 branch July 9, 2026 01:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport conflicts There is a conflict in the backported pull request 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.

1 participant