[9.2](backport #49502) Metricbeat: Remove global path reference#49591
Open
mergify[bot] wants to merge 1 commit into9.2from
Open
[9.2](backport #49502) Metricbeat: Remove global path reference#49591mergify[bot] wants to merge 1 commit into9.2from
mergify[bot] wants to merge 1 commit into9.2from
Conversation
* 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
Contributor
Author
|
Cherry-pick of 4666186 has failed: 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 |
Contributor
🤖 GitHub commentsJust comment with:
|
Contributor
|
Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane) |
Contributor
Author
|
This pull request has not been merged yet. Could you please review and merge it @orestisfl? 🙏 |
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.
Proposed commit message
Remove the global
paths.Pathssingleton fallback fromBaseMetricSet.GetPath()in metricbeat.GetPath()previously fell back to the globalpaths.Pathssingleton when the instance'spathsfield was nil. All production callers already set paths viaNewModule/newBaseMetricSets, so this only affects test code that constructsBaseMetricSetdirectly without paths.An
exhaustructlint rule is added scoped tomb.BaseMetricSetto prevent future direct struct literal construction that omits required fields likepaths. Existing construction sites are annotated withnolint:exhaustructwhere justified.This is part of the larger effort to eliminate global path state from the beats codebase.
Checklist
I have made corresponding changes to the documentationI have made corresponding change to the default configuration filesstresstest.shscript to run them under stress conditions and race detector to verify their stability.I have added an entry in./changelog/fragmentsusing 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/...Related issues
This is an automatic backport of pull request #49502 done by [Mergify](https://mergify.com).