Skip to content

Comments

Handle is_partial in ES|QL query responses in Elasticsearch query rule#228118

Merged
ersin-erdal merged 14 commits intoelastic:mainfrom
ersin-erdal:209408-handle-is-partial
Jul 23, 2025
Merged

Handle is_partial in ES|QL query responses in Elasticsearch query rule#228118
ersin-erdal merged 14 commits intoelastic:mainfrom
ersin-erdal:209408-handle-is-partial

Conversation

@ersin-erdal
Copy link
Contributor

@ersin-erdal ersin-erdal commented Jul 16, 2025

Resolves: #209408

This PR adds a handler to check is_partial flag returned by the ES|QL query requests.

When an ES|QL query returns is_partial: true, we set the rule status to warning, which shows a warning on the UI. See the below screenshot.

To verify:

Change the line 85 const isPartial = response.is_partial ?? false; in this PR to const isPartial = true to mimic is_partial: true response.

Create an Elasticsearch query rule with ES|QL, make it return some results.
I used the below query to create test data.

POST /test-index/_bulk?refresh
{"index":{}}
{"@timestamp":"2025-07-15T00:30:17-05:00","message":"40.135.0.0 - - [30/Apr/2020:14:30:17 -0500] \"GET /images/hm_bg.jpg HTTP/1.0\" 200 24736"}
{"index":{}}
{"@timestamp":"2025-07-15T01:30:53-05:00","message":"232.0.0.0 - - [30/Apr/2020:14:30:53 -0500] \"GET /images/hm_bg.jpg HTTP/1.0\" 200 24736"}

Then test the above cases, by making the rule return some or zero results (Set the time window to 5 seconds or 5 days), and by changing the group options:
Create an alert if matches are found and Create an alert for each row

Screenshot 2025-07-16 at 17 48 05

@ersin-erdal ersin-erdal added release_note:skip Skip the PR/issue when compiling release notes backport:skip This PR does not require backporting Team:ResponseOps Platform ResponseOps team (formerly the Cases and Alerting teams) t// labels Jul 16, 2025
@ersin-erdal ersin-erdal marked this pull request as ready for review July 16, 2025 16:52
@ersin-erdal ersin-erdal requested a review from a team as a code owner July 16, 2025 16:52
@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops (Team:ResponseOps)

@pmuellr
Copy link
Contributor

pmuellr commented Jul 17, 2025

  • if Create an alert if matches are found is selected and no records returned, it fails the rule
  • if Create an alert if matches are found is selected and some records returned, it sets rule status to warning, which shows a warning on the UI. See the below screenshot.

Is there a precedent for failing the rule if no records are returned - like are we doing something similar somewhere else in Kibana? It seems slightly odd, maybe confusing, that in these cases, it either fails or succeeds with a warning, depending on how data came back (none or anything)

@ymao1
Copy link
Contributor

ymao1 commented Jul 17, 2025

Is there a precedent for failing the rule if no records are returned - like are we doing something similar somewhere else in Kibana? It seems slightly odd, maybe confusing, that in these cases, it either fails or succeeds with a warning, depending on how data came back (none or anything)

Yea I think for the DSL and KQL rule types, we show the partial results warning even if there are no hits returned and don't throw

@ymao1
Copy link
Contributor

ymao1 commented Jul 17, 2025

Must be based on @mikecote's comments from the issue:

#209408 (comment)

@mikecote Is it a requirement to be failing the rule run for partial empty results? Should we be doing it for KQL and DSL as well?

@mikecote
Copy link
Contributor

mikecote commented Jul 18, 2025

@mikecote Is it a requirement to be failing the rule run for partial empty results? Should we be doing it for KQL and DSL as well?

@ymao1 Not a requirement, it was just a thought. Warning is perfectly fine and we can revisit if ever it's not sufficient. Consistency makes sense as well.

@ersin-erdal
Copy link
Contributor Author

I removed the error throwing part, just sets the status to warning.

@ymao1 ymao1 added the ci:cloud-deploy Create or update a Cloud deployment label Jul 21, 2025
Copy link
Contributor

@ymao1 ymao1 left a comment

Choose a reason for hiding this comment

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

PR works as described. Wondering if there's a way to get a more detailed warning message? It looks like the detection ES|QL rule pulls a message from the response.clusters object if it exists: #223198

@ersin-erdal
Copy link
Contributor Author

PR works as described. Wondering if there's a way to get a more detailed warning message? It looks like the detection ES|QL rule pulls a message from the response.clusters object if it exists: #223198

Added the same details here too. I didn't add a check for the failure messages since getting is_partial is enough to show the message and it fallbacks to empty array.

Copy link
Contributor

@ymao1 ymao1 left a comment

Choose a reason for hiding this comment

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

LGTM. Left one nit about the warning wording.

return i18n.translate('xpack.stackAlerts.esQuery.partialResultsWarning', {
defaultMessage:
'The query returned partial results. Some clusters may have been skipped due to timeouts or other issues. Failures: {failures}',
values: { failures: JSON.stringify(shardFailures) },
Copy link
Contributor

Choose a reason for hiding this comment

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

since failures can be an empty array, it would be nice to optionally show Failures: in the message since then the warning will look incomplete. So if we can't extract any useful message from the details, it will just show The query returned partial results. Some clusters may have been skipped due to timeouts or other issues.

@elasticmachine
Copy link
Contributor

elasticmachine commented Jul 23, 2025

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
stackAlerts 27 29 +2
Unknown metric groups

API count

id before after diff
stackAlerts 27 29 +2

History

@ersin-erdal ersin-erdal merged commit 0b7c71b into elastic:main Jul 23, 2025
12 checks passed
kertal pushed a commit to kertal/kibana that referenced this pull request Jul 25, 2025
elastic#228118)

Resolves: elastic#209408

This PR adds a handler to check `is_partial` flag returned by the ES|QL
query requests.

When an ES|QL query returns `is_partial: true`, we set the rule status
to warning, which shows a warning on the UI. See the below screenshot.

## To verify:

Change the [line 85
](https://github.com/elastic/kibana/pull/228118/files#diff-9b17d68f85f149658c205635c0034104276c12506390ca823ec281323240e390R85)`const
isPartial = response.is_partial ?? false;` in this PR to `const
isPartial = true` to mimic `is_partial: true` response.

Create an Elasticsearch query rule with ES|QL, make it return some
results.
I used the below query to create test data.

```
POST /test-index/_bulk?refresh
{"index":{}}
{"@timestamp":"2025-07-15T00:30:17-05:00","message":"40.135.0.0 - - [30/Apr/2020:14:30:17 -0500] \"GET /images/hm_bg.jpg HTTP/1.0\" 200 24736"}
{"index":{}}
{"@timestamp":"2025-07-15T01:30:53-05:00","message":"232.0.0.0 - - [30/Apr/2020:14:30:53 -0500] \"GET /images/hm_bg.jpg HTTP/1.0\" 200 24736"}
```

Then test the above cases, by making the rule return some or zero
results (`Set the time window` to 5 seconds or 5 days), and by changing
the group options:
`Create an alert if matches are found` and `Create an alert for each
row`

<img width="996" height="629" alt="Screenshot 2025-07-16 at 17 48 05"
src="https://github.com/user-attachments/assets/a131e06d-0710-49ca-b1d3-efd9234de27c"
/>

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
eokoneyo pushed a commit to eokoneyo/kibana that referenced this pull request Jul 31, 2025
elastic#228118)

Resolves: elastic#209408

This PR adds a handler to check `is_partial` flag returned by the ES|QL
query requests.

When an ES|QL query returns `is_partial: true`, we set the rule status
to warning, which shows a warning on the UI. See the below screenshot.

## To verify:

Change the [line 85
](https://github.com/elastic/kibana/pull/228118/files#diff-9b17d68f85f149658c205635c0034104276c12506390ca823ec281323240e390R85)`const
isPartial = response.is_partial ?? false;` in this PR to `const
isPartial = true` to mimic `is_partial: true` response.

Create an Elasticsearch query rule with ES|QL, make it return some
results.
I used the below query to create test data.

```
POST /test-index/_bulk?refresh
{"index":{}}
{"@timestamp":"2025-07-15T00:30:17-05:00","message":"40.135.0.0 - - [30/Apr/2020:14:30:17 -0500] \"GET /images/hm_bg.jpg HTTP/1.0\" 200 24736"}
{"index":{}}
{"@timestamp":"2025-07-15T01:30:53-05:00","message":"232.0.0.0 - - [30/Apr/2020:14:30:53 -0500] \"GET /images/hm_bg.jpg HTTP/1.0\" 200 24736"}
```

Then test the above cases, by making the rule return some or zero
results (`Set the time window` to 5 seconds or 5 days), and by changing
the group options:
`Create an alert if matches are found` and `Create an alert for each
row`

<img width="996" height="629" alt="Screenshot 2025-07-16 at 17 48 05"
src="https://github.com/user-attachments/assets/a131e06d-0710-49ca-b1d3-efd9234de27c"
/>

---------

Co-authored-by: kibanamachine <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 PR does not require backporting ci:cloud-deploy Create or update a Cloud deployment release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Platform ResponseOps team (formerly the Cases and Alerting teams) t// v9.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ResponseOps] Elasticsearch Query rule: handle is_partial in ES|QL queries

6 participants