Alert search, filtering, and incidents
Keep gives product workflows one way to find, narrow, count, and act on alerts. The backend applies tenant-scoped queries to recent alert records, adds enrichment and incident context, and returns data for alert feeds, saved presets, incident views, and automation.
This page extends Alert lifecycle with the read and action paths after alert storage. It complements Alert ingestion and deduplication, which explains how external signals become the alert records searched here.
Query model
Alert result queries
The home/…/alerts.py alert query endpoint accepts a CEL expression, page size, offset, and sort options. It returns the matching page with the total match count, then adds incident data before it sends the result to clients. A query without a limit still reports the count but does not return alert rows.
The query path uses the most recent alert record for each fingerprint as the feed view. It scopes results to the tenant and to the configured recent-alert limit. The default page size is 1,000, and the hard limit is 50,000 alerts.
This diagram shows how a product query becomes a paged alert result.
flowchart LR
A[Feed or workflow query] --> B[CEL and sort input]
B --> C[Tenant-scoped alert query]
C --> D[Rows and total count]
D --> E[Incident context]
E --> F[Alert DTO page]
References: keep/…/alerts.py• L195-250 keep/…/alerts.py• L233-444 keep/…/query.py• L5-16
Search queries
The home/…/alerts.py search endpoint serves saved or direct searches through a PresetSearchQuery. That query carries both a CEL form and an SQL form so the same product search can use the internal database path or the search index path.
The search engine selects its mode per tenant. It uses the internal path when the search index is not enabled. In a multi-tenant deployment, a tenant can select the search-index path through its search setting. Search results are ordered by most recent receipt and limited by the query.
The request also accepts a non-negative timeframe. The internal path adds that timeframe to the CEL expression. Invalid CEL returns a client error with the parse location instead of a partial result.
References: keep/…/alerts.py• L1293-1331 keep/…/search_alert.py• L6-17 keep/…/preset.py• L65-74 keep/…/searchengine.py• L17-55 keep/…/searchengine.py• L84-182
Filtering and facets
CEL filtering
CEL, the Common Expression Language used for alert filters, lets product workflows match alert fields and nested payload fields. Supported patterns include equality, ranges, logical operators, list membership, null checks, and string tests such as contains and startsWith.
The query layer maps common alert fields to stored alert data. This includes severity, status, source, provider identity, timestamps, fingerprints, counters, dismissal state, and incident fields. Other event and enrichment fields can also take part in a query when their values are available.
References: keep/…/alerts.py• L42-178 keep/…/alerts.py• L233-318 tests/test_search_alerts.py• L220-314 tests/…/test_filtering_sort_search_on_alerts.py• L262-341
Facet filtering
Facets provide value lists and match counts for interactive filters. The alert feed exposes static facets for severity, status, source, incident, and dismissal, plus tenant-defined facets created from alert fields. Clients first load facet definitions, then request options for the current CEL context so each option count reflects the active result set.
Facet queries use the same tenant and incident rules as alert queries. A field list endpoint helps clients offer fields for new facets. The UI keeps selected values that reach zero matches visible so a user can clear a filter without losing its context.
References: keep/…/alerts.py• L94-192 keep/…/alerts.py• L180-216 keep/…/alerts.py• L447-513 keep/…/facet.py• L7-40 keep-ui/…/hooks.tsx• L20-115
Counts and presets
Paginated counts
home/…/alerts.py returns count separately from results. The count represents all rows that match the tenant, time, CEL, and incident conditions, while limit and offset control only the returned page. This lets a feed show page controls and lets other workflows show a count without loading every alert.
The alert count query uses distinct alert identities when incident joins could produce more than one row for an alert. The result still respects the recent-alert hard limit and returns an empty page when the requested offset is outside that range.
References: keep/…/alerts.py• L224-250 keep/…/alerts.py• L321-377 keep/…/alerts.py• L380-444
Preset counts
Presets are saved alert views. A preset stores its query and can also define whether its count should represent all matching alerts or only firing alerts. The search engine evaluates each preset and sets its count for navigation and preset badges.
Noisy presets use the same match set to decide whether current alert activity should produce noise. Dismissed and deleted alerts do not make a preset noisy, even when they match its query. Preset alert requests expose which search mode produced the result so product behavior can be understood for a tenant.
References: keep/…/preset.py• L42-74 keep/…/preset.py• L421-479 keep/…/searchengine.py• L184-274 keep-ui/…/useAlertsTableData.ts• L236-350
Dismissal
Alert dismissal
Alert dismissal is an enrichment on the alert fingerprint rather than removal of the alert record. The product can dismiss one or more alerts forever or until a selected time, add a comment, and restore a dismissed alert. A dismissal marked for disposal on a new alert applies to the current alert state and can be replaced when the same fingerprint receives a new alert.
The alert model exposes dismissed and dismissUntil. While a timed dismissal is still valid, the result reports the alert as dismissed. A dismissal also maps the alert status to suppressed. When the time ends, the system clears the dismissal and temporary suppression state, records an audit event, and refreshes search and client views.
References: keep/…/alert.py• L63-109 keep/…/alert.py• L215-238 keep/…/alerts.py• L831-1041 keep-ui/…/alert-dismiss-modal.tsx• L81-123 keep/…/dismissal_expiry_bl.py• L22-131
Error alert dismissal
Processing errors use a separate error-alert view. The backend returns undelivered raw events that are not yet dismissed. A write request can dismiss one error by ID or all error alerts for the tenant, and the UI reloads the error list after the action.
This flow does not change the normal alert dismissal fields. It closes an operational queue for events that Keep could not process, while the original event and error message remain available for review.
References: keep/…/alerts.py• L1417-1517 keep/…/db.py• L5865-5899 keep/…/alert.py• L63-73 keep-ui/…/useAlerts.ts• L130-154
Incident relationships
Incident-aware alert queries
Alerts can belong to one or more incidents through their fingerprint. Alert queries can filter on incident identity, visibility, and name. For the alert feed, incident predicates use incidents that are currently firing; after the query, the response adds the linked incident data used by the alert detail and grouping views.
This rule gives operators a useful distinction: an alert can have historical incident links but count as having no active incident when all linked incidents are closed. The query count follows the same incident condition as the returned rows.
References: keep/…/alerts.py• L76-97 keep/…/alerts.py• L233-318 keep/…/db.py• L3865-3896 tests/test_search_alerts.py• L1490-1644
Incident alert views
An incident has its own paged alert view. The incident endpoint returns linked alerts and link metadata, with an option to include alerts that are not linked. Incident list queries can also filter by incident fields or alert fields and can return incident counts for the current page conditions.
Changes to incident membership refresh the search index and notify clients. The alert feed and incident pages can therefore converge on the same relationship after an alert is added to or removed from an incident.
References: keep/…/incidents.py• L125-208 keep/…/incidents.py• L542-592 keep/…/incidents.py• L687-731 keep/…/incidents.py• L192-306 keep/…/incidents_bl.py• L127-189
Incident status effects
Incident status and alert status are related but separate. When an incident is acknowledged or resolved, the incident workflow can apply the matching status to its alerts. When alert status changes, the system checks the incident's resolve rule and can resolve the incident when its required alerts are resolved.
The supported resolve rules are first alert, last alert, or all alerts. This relationship is why alert enrichment can affect incident state and why incident pages must refresh after bulk alert actions.
References: keep/…/incidents_bl.py• L432-476 keep/…/incidents_bl.py• L478-552 keep/…/alerts.py• L1008-1033 keep/…/incident.py• L51-75
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the CEL field map aligned with both alert event fields and enrichment fields. A field that is returned in an alert DTO but is not mapped cannot be used by server-side filters or facet options.
- Keep the internal CEL form and the search-index SQL form semantically equivalent. Presets depend on both forms when tenants use different search modes.
- Keep the count query aligned with the row query when adding a join. Incident links can multiply rows unless the count uses the same distinct identity rule.
- Preserve the
dismissedanddismissUntilcontract across alert enrichment, timed-expiry processing, search indexing, and client refresh events. - Treat active incident filtering and historical incident display as separate contracts. A change to incident status rules can alter both alert counts and the meaning of
incident.id == null. - Keep facet option queries under the same tenant and allowed-resource scope as the main alert or incident query.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Invalid CEL in an alert query or facet option query | The request cannot produce a safe filtered result | Return a client error from CEL parsing and show the query error instead of using a partial filter |
| Incident joins create duplicate alert rows | The feed or count shows inflated results | Use distinct alert identities when incident fields take part in the query |
| Search index and internal query forms drift apart | The same preset returns different alerts for different tenants | Test equivalent CEL and SQL searches against both search modes |
| A timed dismissal expires without its status being cleared | An alert stays hidden or suppressed after its dismissal period | Clear dismissed, dismissUntil, and temporary suppressed state during expiry processing |
| A requested offset is beyond the alert hard limit | The client gets an empty page even when the total count is non-zero | Keep pagination and hard-limit behavior visible in the response contract |
| An incident membership change is not propagated to search and clients | Alert feeds and incident pages show stale links | Re-index affected alerts and send the incident-change refresh signal |
Key files
| File | Why to read it |
|---|---|
| keep/…/alerts.py | Defines the alert query, search, facet, enrichment, and error-dismissal interfaces. |
| keep/…/alerts.py | Defines the shared alert filter, sort, count, incident-join, and facet query rules. |
| keep/…/searchengine.py | Explains the choice between internal search and the search-index path, plus preset counts and noise state. |
| keep/…/search_alert.py and keep/…/query.py | Defines the request shapes for preset search and paginated alert queries. |
| keep/…/dismissal_expiry_bl.py | Shows how timed dismissals return to the normal alert state. |
| keep/…/incidents.py | Defines incident list filters and the paged incident-alert relationship view. |
| keep/…/incidents.py | Defines incident query behavior, alert-field filters, counts, and facets. |
| keep/…/incidents_bl.py | Shows how incident membership and status changes reach search, clients, and alert state. |
| keep-ui/…/useAlertsTableData.ts | Shows how the product combines search, time range, facets, sorting, paging, and refresh signals. |
| keep-ui/…/alert-dismiss-modal.tsx | Shows the user-facing forever, timed, restore, and comment dismissal actions. |