Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Stack Monitoring] Prevent exceptions in rule when no data present #131332

Merged

Conversation

miltonhultgren
Copy link
Contributor

Fixes #120111

When there is no data, the aggregations property of the ES response is omitted. When we then try to destructure that to get the buckets we run into a null pointer exception.
This PR simply adds a check to each affected rule to see if there are aggregations on the response object, if not we return early.

As a follow up we need decide how to inform the user that these rules are doing nothing (just eating CPU) until some data is present or they are disabled.

@miltonhultgren miltonhultgren added release_note:fix Team:Infra Monitoring UI - DEPRECATED DEPRECATED - Label for the Infra Monitoring UI team. Use Team:obs-ux-infra_services Feature:Stack Monitoring v8.3.0 labels May 2, 2022
@miltonhultgren miltonhultgren requested a review from a team as a code owner May 2, 2022 14:48
@elasticmachine
Copy link
Contributor

Pinging @elastic/infra-monitoring-ui (Team:Infra Monitoring UI)

if (!response.aggregations) {
return stats;
}

// @ts-expect-error declare aggegations type explicitly
const { buckets: remoteClusterBuckets = [] } = response.aggregations?.remote_clusters;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we have that new check above, do we still need to keep the question mark here response.aggregations??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, will change that!

Copy link
Contributor

@crespocarlos crespocarlos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🙌

@crespocarlos
Copy link
Contributor

LGTM : ! Better even would be if response could be properly typed in the future

@crespocarlos crespocarlos reopened this May 9, 2022
@miltonhultgren
Copy link
Contributor Author

@elasticmachine merge upstream

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@miltonhultgren miltonhultgren merged commit 5398394 into elastic:main May 12, 2022
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label May 12, 2022
Bamieh pushed a commit to Bamieh/kibana that referenced this pull request May 16, 2022
…lastic#131332)

* [Stack Monitoring] Prevent exceptions in rule when no data present (elastic#120111)

* Remove optional chaining

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Stack Monitoring release_note:fix Team:Infra Monitoring UI - DEPRECATED DEPRECATED - Label for the Infra Monitoring UI team. Use Team:obs-ux-infra_services v8.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stack Monitoring rule types failing due to empty buckets
5 participants