[9.4](backport #50498) fix: Safeguard closing nil channels in azure metrics module#50512
Open
mergify[bot] wants to merge 2 commits into9.4from
Open
[9.4](backport #50498) fix: Safeguard closing nil channels in azure metrics module#50512mergify[bot] wants to merge 2 commits into9.4from
mergify[bot] wants to merge 2 commits into9.4from
Conversation
* fix: Safeguard closing nil channels in azure metrics module * add changelog (cherry picked from commit caea6ba)
|
Pinging @elastic/obs-ds-hosted-services (Team:obs-ds-hosted-services) |
6 tasks
Contributor
🤖 GitHub commentsJust comment with:
|
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.
In
x-pack/metricbeat/module/azure,BatchClient.InitResourcescould panicwith
panic: close of nil channelwhenever every configuredresourceentry returned zero resources from the Azure API (e.g. a
resource_query: "resourceType eq 'Microsoft.ContainerInstance/containerGroups'"on a subscription that has no Container Instances).
WHAT:
MetricDefinitionsChanandErrorChanin
InitResourcesso it only runs when those channels were actuallycreated during the resource-config loop.
does_not_panic_when_all_resource_configs_return_an_empty_list)covering the empty-list + nil-error path that reproduces the panic on
the unfixed code.
WHY:
MetricDefinitionsChan/ErrorChanare created lazily inside theresource-config loop, only after the empty-list
continuecheck. Whenevery
resourceConfigreturned an empty list, both channels stayednil(their initial value fromNewBatchClient) but the closergoroutine launched unconditionally at the end of the function still
ran, calling
close(nil)and crashing the Metricbeat process.Checklist
I have made corresponding changes to the documentationI have made corresponding change to the default configuration files./changelog/fragmentsusing the changelog tool.Disruptive User Impact
None. It prevents a potential panic
How to test this PR locally
Unit test :
Without the fix the new subtest crashes the test binary with
panic: close of nil channelatclient_batch.go:144. With the fixthe full subtest passes.
End-to-end repro:
Before this PR Metricbeat panics on the first refresh; after this PR
it logs the per-config "No resources returned" error and proceeds.
Related issues
Logs
Production stack trace (pre-fix) reproduced by the new unit test: