Skip to content

Commit

Permalink
[ResponseOps][Alerts] Migrate alerts fetching to TanStack Query (elas…
Browse files Browse the repository at this point in the history
…tic#186978)

## Summary

Implements a new `useSearchAlertsQuery` hook based on TanStack Query to
replace the `useFetchAlerts` hook, following [this organizational
logic](elastic#186448 (comment)).

This PR focuses mainly on the fetching logic itself, leaving the
surrounding API surface mostly unchanged since it will be likely
addressed in subsequent PRs.

## To verify

1. Create rules that fire alerts in different solutions
2. Check that the alerts table usages work correctly ({O11y, Security,
Stack} alerts and rule details pages, ...)
1. Check that the alerts displayed in the table are coherent with the
solution, KQL query, time filter, pagination
    2. Check that pagination changes are reflected in the table
3. Check that changing the query when in pages > 0 resets the pagination
to the first page

Closes point 1 of elastic#186448
Should fix elastic#171738

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
umbopepato and kibanamachine authored Jul 25, 2024
1 parent 76237d8 commit bd3032b
Show file tree
Hide file tree
Showing 68 changed files with 1,381 additions and 1,231 deletions.
13 changes: 7 additions & 6 deletions packages/kbn-alerting-types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
* Side Public License, v 1.
*/

export * from './builtin_action_groups_types';
export * from './rule_type_types';
export * from './action_group_types';
export * from './action_variable';
export * from './alert_type';
export * from './rule_notify_when_type';
export * from './r_rule_types';
export * from './rule_types';
export * from './alerting_framework_health_types';
export * from './action_variable';
export * from './builtin_action_groups_types';
export * from './circuit_breaker_message_header';
export * from './r_rule_types';
export * from './rule_notify_when_type';
export * from './search_strategy_types';
export * from './rule_type_types';
export * from './rule_types';
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { TechnicalRuleDataFieldName, ValidFeatureId } from '@kbn/rule-data-utils';
import { IEsSearchRequest, IEsSearchResponse } from '@kbn/search-types';

import type { IEsSearchRequest, IEsSearchResponse } from '@kbn/search-types';
import type { ValidFeatureId } from '@kbn/rule-data-utils';
import type {
MappingRuntimeFields,
QueryDslFieldAndFormat,
QueryDslQueryContainer,
SortCombinations,
} from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type { Alert } from './alert_type';

export type RuleRegistrySearchRequest = IEsSearchRequest & {
featureIds: ValidFeatureId[];
Expand All @@ -27,20 +30,10 @@ export interface RuleRegistrySearchRequestPagination {
pageSize: number;
}

export interface BasicFields {
_id: string;
_index: string;
}
export type EcsFieldsResponse = BasicFields & {
[Property in TechnicalRuleDataFieldName]?: string[];
} & {
[x: string]: unknown[];
};

export interface RuleRegistryInspect {
dsl: string[];
}

export interface RuleRegistrySearchResponse extends IEsSearchResponse<EcsFieldsResponse> {
export interface RuleRegistrySearchResponse extends IEsSearchResponse<Alert> {
inspect?: RuleRegistryInspect;
}
3 changes: 2 additions & 1 deletion packages/kbn-alerting-types/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@kbn/rule-data-utils",
"@kbn/rrule",
"@kbn/core",
"@kbn/es-query"
"@kbn/es-query",
"@kbn/search-types"
]
}
Loading

0 comments on commit bd3032b

Please sign in to comment.