Skip to content

fix: prevent index out of range panic in Datadog and Prometheus providers - #1982

Open
okarin1511 wants to merge 1 commit into
fluxcd:mainfrom
okarin1511:fix/metrics-provider-index-bounds
Open

okarin1511 wants to merge 1 commit into
fluxcd:mainfrom
okarin1511:fix/metrics-provider-index-bounds

Conversation

@okarin1511

Copy link
Copy Markdown

Fixes #1981

Summary

  • Datadog: RunQuery checks len(vs) < 1 but accesses vs[1]. Changed to len(vs) < 2 so a pointlist pair with only a timestamp (no value) returns ErrNoValuesFound instead of panicking.
  • Prometheus: RunQuery accesses v.Value[1] without a bounds check. Added len(v.Value) < 2 guard that skips malformed results, letting the existing ErrNoValuesFound path handle it.

Test plan

  • Added test case single_element_pointlist_pair for Datadog — verifies a pointlist entry with one element returns ErrNoValuesFound instead of panicking
  • Added test case malformed_value_array for Prometheus — verifies an empty value array returns ErrNoValuesFound instead of panicking
  • All existing tests pass

…ders

The Datadog provider checks len(vs) < 1 but accesses vs[1], which
panics when the pointlist pair contains only a timestamp without a
value. Fix by checking len(vs) < 2.

The Prometheus provider accesses v.Value[1] without a bounds check,
which panics if the API returns a malformed value array with fewer
than two elements. Fix by skipping results with insufficient elements.

Signed-off-by: Aseem Khandekar <69676297+okarin1511@users.noreply.github.com>

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Datadog and Prometheus providers can panic on malformed metric responses

1 participant