[metricbeat/zookeeper] Fix potential panics and remove unused code in server module
Proposed commit message
This PR improves the robustness of the Zookeeper server by adding proper bounds checking to prevent potential index-out-of-range panics, removes unused regex variables, and adds test coverage for edge cases.
- Bug Fixes:
- Added bounds checking for versionCapturer.FindStringSubmatch() results before accessing the capture group, preventing panic on malformed version lines
- Added bounds checking for dateCapturer.FindStringSubmatch() results before accessing the capture group, preventing panic on malformed date lines
- Fixed off-by-one error in mode line parsing: changed len(modeSplit) < 1 to len(modeSplit) < 2 since the code accesses modeSplit[1]
- Code Cleanup:
- Removed 4 unused regex variables: ipCapturer, thatNumberCapturer, portCapturer, dataCapturer
Checklist
- [x] My code follows the style guidelines of this project
- [x] 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.shscript to run them under stress conditions and race detector to verify their stability. - [x] I have added an entry in
./changelog/fragmentsusing the changelog tool.
:robot: GitHub comments
Just comment with:
rundocs-build: Re-trigger the docs validation. (use unformatted text in the comment!)
This pull request does not have a backport label. If this is a bug or security fix, could you label this PR @shmsr? 🙏. For such, you'll need to label your PR with:
- The upcoming major version of the Elastic Stack
- The upcoming minor version of the Elastic Stack (if you're not pushing a breaking change)
To fixup this pull request, you need to add the backport labels for the needed branches, such as:
backport-8./dis the label to automatically backport to the8./dbranch./dis the digitbackport-active-allis the label that automatically backports to all active branches.backport-active-8is the label that automatically backports to all active minor branches for the 8 major.backport-active-9is the label that automatically backports to all active minor branches for the 9 major.
@mykola-elastic Could you please review this as well?
@mergifyio backport 8.19 9.1 9.2 9.3
backport 8.19 9.1 9.2 9.3
❌ No backport have been created
- #48127 [8.19](backport #47915) [metricbeat/zookeeper] Fix potential panics and remove unused code in server module has been created for branch
8.19 - #48128 [9.1](backport #47915) [metricbeat/zookeeper] Fix potential panics and remove unused code in server module has been created for branch
9.1 - #48129 [9.2](backport #47915) [metricbeat/zookeeper] Fix potential panics and remove unused code in server module has been created for branch
9.2 - Backport to branch
9.3failed
GitHub error: Branch not found