Skip to content

[Streams][SigEvents] Add background task for significant events query generation#248608

Merged
cesco-f merged 27 commits intoelastic:mainfrom
cesco-f:sig-events-queries-task
Jan 13, 2026
Merged

[Streams][SigEvents] Add background task for significant events query generation#248608
cesco-f merged 27 commits intoelastic:mainfrom
cesco-f:sig-events-queries-task

Conversation

@cesco-f
Copy link
Contributor

@cesco-f cesco-f commented Jan 12, 2026

It closes https://github.com/elastic/streams-program/issues/708.

Summary

This PR introduces a background task-based approach for significant events query generation with dedicated _status and _task endpoints.

Changes

Backend

Task Definition

  • Added significant_events_queries_generation task definition that handles LLM-based generation of significant event queries as a background task
  • Integrated with telemetry for tracking generation events

API Endpoints

  • GET /api/streams/{name}/significant_events/_status - Check the status of the generation task (handles stale detection, returns task results)
  • POST /api/streams/{name}/significant_events/_task - Manage task lifecycle with a discriminated union body:
    • action: 'schedule' - Schedule a new generation task with from, to, connectorId, sampleDocsSize, and systems parameters
    • action: 'cancel' - Cancel an in-progress task
    • action: 'acknowledge' - Acknowledge a completed task

Frontend

  • Added useSignificantEventsApi hook methods for task management (getGenerationTask, scheduleGenerationTask, cancelGenerationTask, acknowledgeGenerationTask)
  • Updated AddSignificantEventFlyout to work with the task-based generation flow
Screen.Recording.2026-01-09.at.16.53.35.mov

@cesco-f cesco-f added release_note:enhancement backport:skip This PR does not require backporting Feature:SigEvents Significant events feature, related to streams and rules/alerts (RnA) labels Jan 12, 2026
@github-actions github-actions bot added the author:actionable-obs PRs authored by the actionable obs team label Jan 12, 2026
@cesco-f
Copy link
Contributor Author

cesco-f commented Jan 12, 2026

/ci

@cesco-f cesco-f marked this pull request as ready for review January 12, 2026 10:46
@cesco-f cesco-f requested review from a team as code owners January 12, 2026 10:46
@elastic-vault-github-plugin-prod elastic-vault-github-plugin-prod bot requested a review from a team as a code owner January 12, 2026 11:00
@cesco-f
Copy link
Contributor Author

cesco-f commented Jan 12, 2026

/ci

@cesco-f cesco-f force-pushed the sig-events-queries-task branch from 663ca3e to 93fb7d2 Compare January 12, 2026 13:45
@miltonhultgren
Copy link
Contributor

There's two things I'd like to see in this PR:

  1. When the task is in progress and I refresh the page, I would like to see the button have a spinner to show that generation is still happening
  2. If the task has completed, when I refresh that page and click the button, I would like to see the results of the previous task, rather than schedule a new task that I have to wait for.

Do you think it will be a lot of effort to change the code to this?

@cesco-f
Copy link
Contributor Author

cesco-f commented Jan 12, 2026

There's two things I'd like to see in this PR:

  1. When the task is in progress and I refresh the page, I would like to see the button have a spinner to show that generation is still happening
  2. If the task has completed, when I refresh that page and click the button, I would like to see the results of the previous task, rather than schedule a new task that I have to wait for.

Do you think it will be a lot of effort to change the code to this?

  1. What button are you referring to?
  2. If the task is completed and you refresh the page you can see the results of the previous task, not sure if I'm understanding correctly.

In progress task:

Screen.Recording.2026-01-12.at.16.24.31.mov

Task completed:

Screen.Recording.2026-01-12.at.16.24.59.mov

@miltonhultgren
Copy link
Contributor

miltonhultgren commented Jan 12, 2026

@cesco-f Okay so:

  1. I would expect the "+ Significant events" button to show loading state there
  2. If you test this same flow from an empty state then it works differently (since it's different buttons being shown)

@cesco-f
Copy link
Contributor Author

cesco-f commented Jan 12, 2026

@cesco-f Okay so:

  1. I would expect the "+ Significant events" button to show loading state there
  2. If you test this same flow from an empty state then it works differently (since it's different buttons being shown)

Aren't we getting rid of this view? Does it make sense to invest more time to improve the UX?

@cesco-f cesco-f removed request for a team and mdbirnstiehl January 12, 2026 16:38
@cesco-f cesco-f requested a review from a team as a code owner January 12, 2026 19:02
@miltonhultgren
Copy link
Contributor

@cesco-f You're right, ignore me, perfectionism is a hard habit to beat!

@elasticmachine
Copy link
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #41 / Actions and Triggers app create alert should show KEEP command warning when creating a ES query rule with ESQL

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
@kbn/streams-schema 233 237 +4

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
streamsApp 1.5MB 1.5MB +848.0B
Unknown metric groups

API count

id before after diff
@kbn/streams-schema 240 244 +4

History

Copy link
Contributor

@pmuellr pmuellr left a comment

Choose a reason for hiding this comment

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

LGTM

@cesco-f cesco-f merged commit 01ee4de into elastic:main Jan 13, 2026
13 checks passed
@cesco-f cesco-f deleted the sig-events-queries-task branch January 13, 2026 15:41
smith pushed a commit to smith/kibana that referenced this pull request Jan 16, 2026
… generation (elastic#248608)

It closes elastic/streams-program#708.

## Summary

This PR introduces a background task-based approach for significant
events query generation with dedicated `_status` and `_task` endpoints.

## Changes

### Backend

**Task Definition**
- Added `significant_events_queries_generation` task definition that
handles LLM-based generation of significant event queries as a
background task
- Integrated with telemetry for tracking generation events

**API Endpoints**
- `GET /api/streams/{name}/significant_events/_status` - Check the
status of the generation task (handles stale detection, returns task
results)
- `POST /api/streams/{name}/significant_events/_task` - Manage task
lifecycle with a discriminated union body:
- `action: 'schedule'` - Schedule a new generation task with `from`,
`to`, `connectorId`, `sampleDocsSize`, and `systems` parameters
  - `action: 'cancel'` - Cancel an in-progress task
  - `action: 'acknowledge'` - Acknowledge a completed task

### Frontend

- Added `useSignificantEventsApi` hook methods for task management
(`getGenerationTask`, `scheduleGenerationTask`, `cancelGenerationTask`,
`acknowledgeGenerationTask`)
- Updated `AddSignificantEventFlyout` to work with the task-based
generation flow



https://github.com/user-attachments/assets/64f82260-7108-4fcc-95e7-3330c644600a

---------

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

author:actionable-obs PRs authored by the actionable obs team backport:skip This PR does not require backporting Feature:SigEvents Significant events feature, related to streams and rules/alerts (RnA) release_note:enhancement v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants