Report the admin API error when collecting group lags - #349
Open
omlahore wants to merge 1 commit into
Open
Conversation
collectConsumerGroupLagsAdminAPI ignored the error from ListAllConsumerGroupOffsetsAdminAPI, which returns a nil map alongside it. The range over that nil map is a no-op, so a failed admin call returned isOk true and simply emitted no consumer group lag metrics rather than reporting the failure. err was also reassigned inside the loop, so the original value could not have been checked later. Follows the same shape as collect_broker_info.go: log with zap.Error and return false.
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.
collectConsumerGroupLagsAdminAPIdrops the error fromListAllConsumerGroupOffsetsAdminAPI:ListAllConsumerGroupOffsetsAdminAPIreturnsnil, fmt.Errorf("failed to list groupsRes: %w", err)whenlistConsumerGroupsCachedfails (minion/consumer_group_offsets.go:22). Ranging over that nil map is a no-op, so the function falls through toreturn isOkwithisOkstilltrue.The effect is that a failed admin call is reported as a successful scrape that happens to contain no consumer group lag metrics, rather than as a failure. For an exporter that is the wrong way round: alerts built on
kafka_consumergroup_group_lagstop firing instead of the scrape going unhealthy.erris also reassigned a few lines down inside the loop (err = kerr.ErrorForCode(...)), so the original value could not have been checked later even in principle. staticcheck flags it as SA4006.The fix follows the shape already used in
collect_broker_info.go:12: log withzap.Errorand return false.Verified:
go build ./...passes,gofmt -lclean, and SA4006 is gone under bothGOOS=linuxandGOOS=darwin.prometheus/has no test files, so there was nothing to extend.