Skip to content

[9.3](backport #49502) Metricbeat: Remove global path reference#49592

Open
mergify[bot] wants to merge 1 commit into9.3from
mergify/bp/9.3/pr-49502
Open

[9.3](backport #49502) Metricbeat: Remove global path reference#49592
mergify[bot] wants to merge 1 commit into9.3from
mergify/bp/9.3/pr-49502

Conversation

@mergify
Copy link
Contributor

@mergify mergify bot commented Mar 23, 2026

Proposed commit message

Remove the global paths.Paths singleton fallback from BaseMetricSet.GetPath() in metricbeat.

GetPath() previously fell back to the global paths.Paths singleton when the instance's paths field was nil. All production callers already set paths via NewModule/newBaseMetricSets, so this only affects test code that constructs BaseMetricSet directly without paths.

An exhaustruct lint rule is added scoped to mb.BaseMetricSet to prevent future direct struct literal construction that omits required fields like paths. Existing construction sites are annotated with nolint:exhaustruct where justified.

This is part of the larger effort to eliminate global path state from the beats codebase.

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.

How to test this PR locally

# Run the linter to verify exhaustruct rule catches uninitialized BaseMetricSet
golangci-lint run --enable-only exhaustruct ./metricbeat/...
  1. Run metricbeat integration tests

Related issues


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

* Remove global paths.Paths fallback in metricbeat BaseMetricSet.GetPath

Replace the paths.Paths global fallback with paths.New() which returns
default paths based on the binary directory. All production callers
already set paths via NewModule, so this only affects test code that
constructs BaseMetricSet directly without paths.

Relates: elastic/ingest-dev#6243

* Add exhaustruct lint rule for BaseMetricSet

Enable the exhaustruct linter scoped to mb.BaseMetricSet to prevent
direct struct literal construction without setting all fields. This
catches cases where paths (or other fields) are accidentally omitted.

Existing construction sites are annotated with nolint:exhaustruct:
- builders.go: the single production site (hostData/registration set
  after construction)
- lightmetricset_test.go: test only needs a subset of fields
- prometheus/openmetrics collector tests: only need filter fields

Relates: elastic/ingest-dev#6243

* Remove explicit panic

* Reject nil paths in NewModule instead of allowing silent nil propagation

(cherry picked from commit 4666186)

# Conflicts:
#	metricbeat/mb/mb.go
@mergify mergify bot requested review from a team as code owners March 23, 2026 08:20
@mergify mergify bot requested review from VihasMakwana and faec and removed request for a team March 23, 2026 08:20
@mergify
Copy link
Contributor Author

mergify bot commented Mar 23, 2026

Cherry-pick of 4666186 has failed:

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

You are currently cherry-picking commit 4666186b7.
  (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:
	modified:   .golangci.yml
	modified:   metricbeat/mb/builders.go
	modified:   metricbeat/mb/lightmetricset_test.go
	modified:   metricbeat/mb/mb_test.go
	modified:   metricbeat/module/openmetrics/collector/collector_test.go
	modified:   metricbeat/module/prometheus/collector/collector_test.go

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   metricbeat/mb/mb.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

@github-actions
Copy link
Contributor

🤖 GitHub comments

Just comment with:

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

@github-actions github-actions bot added bug Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team Team:Obs-InfraObs Label for the Observability Infrastructure Monitoring team skip-changelog labels Mar 23, 2026
@elasticmachine
Copy link
Contributor

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

@mergify
Copy link
Contributor Author

mergify bot commented Mar 23, 2026

This pull request has not been merged yet. Could you please review and merge it @orestisfl? 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug skip-changelog Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team Team:Obs-InfraObs Label for the Observability Infrastructure Monitoring team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants