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

[ResponseOps][Alerting] Decouple feature IDs from consumers #183756

Draft
wants to merge 151 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 148 commits
Commits
Show all changes
151 commits
Select commit Hold shift + click to select a range
ed3015e
Change the schema of the alerting feature privilege
cnasikas May 17, 2024
82a1a65
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas May 18, 2024
c8ec120
Change augmentRuleTypesWithAuthorization to use consumers instead of …
cnasikas May 18, 2024
1a02609
Support legacy consumers
cnasikas May 18, 2024
55f91fd
Fixes in rule filtering
cnasikas May 20, 2024
b3cea58
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas May 20, 2024
5184d21
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas May 23, 2024
3b7c89f
Change new schema
cnasikas May 23, 2024
b1a0a63
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas May 30, 2024
8b5fd17
Filter out rule types with no registered consumers
cnasikas May 31, 2024
ac46730
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Jul 5, 2024
c88e147
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Jul 12, 2024
b69bff1
Refactor the way the AlertingAuthorization object is created
cnasikas Jul 12, 2024
e7363b1
Add the alerts consumers to all rule types
cnasikas Jul 12, 2024
e1b9845
Fix async type errors
cnasikas Jul 12, 2024
41e5491
Add test for alerting authorization object creation
cnasikas Jul 12, 2024
a2b73f9
Add tests and support filtering
cnasikas Jul 13, 2024
0bb255b
Add more tests
cnasikas Jul 16, 2024
4c0c828
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Jul 16, 2024
736a63e
Finalize alerting auth unit tests and functionality
cnasikas Jul 16, 2024
0a6261e
Fix types
cnasikas Jul 17, 2024
c4094d0
Fix tests
cnasikas Jul 17, 2024
516ac6c
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Jul 17, 2024
83a8d41
Fix ML alerting registration
cnasikas Jul 18, 2024
c3b93c8
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Jul 18, 2024
05f858e
Fix stack alerts tests
cnasikas Jul 18, 2024
7578b2b
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Jul 18, 2024
835315f
Merge branch 'poc_decouple_consumers_feature_ids' of github.com:cnasi…
cnasikas Jul 18, 2024
c28823b
Fix more types
cnasikas Jul 18, 2024
9915f67
Show rule types with alerts consumer in o11y
cnasikas Jul 18, 2024
7a66de3
Fix session_view tests
cnasikas Jul 18, 2024
87e0ef2
Fix types and linting errors
cnasikas Jul 18, 2024
0251d48
Fix rule_registry tests
cnasikas Jul 18, 2024
9f84b35
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Jul 19, 2024
4ff4c02
Fix stack_alerts tests
cnasikas Jul 19, 2024
1bd6287
Fix functional tests alerting registration
cnasikas Jul 19, 2024
5d8065f
Fix triggers_actions_ui unit tests
cnasikas Jul 19, 2024
df5ed40
Improve error handling when constructing the AlertingAuthorization class
cnasikas Jul 19, 2024
291b016
Fix types with rule client
cnasikas Jul 20, 2024
14cd879
Fix more integration tests and types
cnasikas Jul 20, 2024
9a4ddc0
Fix alerting integration tests
cnasikas Jul 21, 2024
9c6d2cc
Fix infra e2e tests
cnasikas Jul 22, 2024
85ccea0
Fix triggers_actions_ui tests
cnasikas Jul 22, 2024
6f65625
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Jul 22, 2024
0c50971
Fix types
cnasikas Jul 22, 2024
49570ae
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Jul 22, 2024
44cc854
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Jul 27, 2024
5140a06
Switch authorization and search strategy to rule type ids
cnasikas Jul 27, 2024
c2371d0
Fix usage of alerting authorization methods
cnasikas Jul 28, 2024
3d89a36
Delete _feature_ids route
cnasikas Jul 28, 2024
cca6966
Switch rule registry routes to use ruleTypeIds instead of featureIds
cnasikas Jul 28, 2024
52b472b
Change UI to use rule type IDs
cnasikas Jul 28, 2024
8ac5324
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Jul 29, 2024
42c734a
Move rule types to a package
cnasikas Jul 30, 2024
a5335df
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Jul 31, 2024
e19424d
Fix types after merge
cnasikas Jul 31, 2024
cc944b0
Use the new isSiemRuleType util
cnasikas Jul 31, 2024
c8fcf38
Use fetchAlertsFields to use rule type IDs
cnasikas Jul 31, 2024
50c2812
Fix stack management types
cnasikas Jul 31, 2024
fb38a4c
Revert uptime file
cnasikas Jul 31, 2024
e40682c
Fix types to start
cnasikas Jul 31, 2024
90a225a
Fix cases
cnasikas Jul 31, 2024
af70fd4
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Aug 1, 2024
4efcced
Fix types and tests
cnasikas Aug 1, 2024
11d50be
Fix rule registry integration tests
cnasikas Aug 1, 2024
824c3b1
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Aug 2, 2024
22cbb1e
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Aug 3, 2024
d37760b
Improve search strategy alert handling
cnasikas Aug 4, 2024
885d158
Fix search strategy integration tests
cnasikas Aug 4, 2024
f155d55
Merge branch 'poc_decouple_consumers_feature_ids' of github.com:cnasi…
cnasikas Aug 4, 2024
2f8c646
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Sep 2, 2024
c68f141
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Sep 16, 2024
01fa579
Fix tests and types
cnasikas Sep 17, 2024
f69402e
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Sep 18, 2024
9389991
Fix types and unit tests
cnasikas Sep 18, 2024
218eb3e
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Sep 18, 2024
b47ab8d
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Sep 19, 2024
cb84ab4
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Sep 19, 2024
fcc6a48
Fix arguments of getAuthorizedAlertsIndices
cnasikas Sep 20, 2024
f18ed29
Fix alerting integration tests
cnasikas Sep 20, 2024
e353051
Merge branch 'poc_decouple_consumers_feature_ids' of github.com:cnasi…
cnasikas Sep 20, 2024
3f1fc68
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Sep 20, 2024
1c19bed
Remove alerts consumer for security rule types
cnasikas Sep 21, 2024
d2bb1d0
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Sep 21, 2024
fdefdb6
Add o11y schema
cnasikas Sep 21, 2024
c9a347e
Fix getAlertsIndexRoute query schema
cnasikas Sep 22, 2024
fcb0cb7
Fix issues when detecting siem rule types
cnasikas Sep 22, 2024
cc2da8f
Merge branch 'poc_decouple_consumers_feature_ids' of github.com:cnasi…
cnasikas Sep 22, 2024
b7a68a2
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Sep 22, 2024
8f4f1e0
Fix test imports
cnasikas Sep 23, 2024
fa0439f
Change _aggregate API to use ruleTypeIds
cnasikas Sep 26, 2024
4532eff
Add support of rule_type_ids in the Find API
cnasikas Sep 27, 2024
4129b93
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Sep 27, 2024
fdd178a
[CI] Auto-commit changed files from 'node scripts/capture_oas_snapsho…
kibanamachine Sep 27, 2024
1d5f50f
Fix find API integration tests
cnasikas Sep 29, 2024
e09a12c
Remove unecessary ruleTypeIds props
cnasikas Sep 29, 2024
c27937f
Use the ruleTypeIds filter in the search strategy
cnasikas Sep 29, 2024
29b3b8d
Use the ruleTypeIds filter in the alerts client
cnasikas Sep 29, 2024
c1be282
Make rule type ID optional again
cnasikas Sep 30, 2024
46097ff
Fix find URLs
cnasikas Sep 30, 2024
6005315
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Sep 30, 2024
00db4c3
Merge branch 'poc_decouple_consumers_feature_ids' of github.com:cnasi…
cnasikas Sep 30, 2024
e0a9061
[CI] Auto-commit changed files from 'make api-docs && make api-docs-s…
kibanamachine Sep 30, 2024
bd2827f
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Oct 1, 2024
45fd8e4
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Oct 2, 2024
bdc95c5
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Oct 2, 2024
ddefd3b
Support filtering by consumers in the aggregate API
cnasikas Oct 3, 2024
8589fb5
Support filtering by consumers while aggregating in the UI
cnasikas Oct 3, 2024
b342221
Support filtering by consumers in the find API
cnasikas Oct 4, 2024
60fa3aa
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Oct 4, 2024
34bbac8
Merge branch 'poc_decouple_consumers_feature_ids' of github.com:cnasi…
cnasikas Oct 5, 2024
d2d9c27
Support filtering by consumers while finding rules in the UI
cnasikas Oct 6, 2024
a0b9b02
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Oct 6, 2024
b284fda
Add type filters back
cnasikas Oct 6, 2024
301559e
Add stack rules to o11y
cnasikas Oct 6, 2024
ed02cad
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Oct 9, 2024
b59577d
Support filtering by consumers in the search strategy
cnasikas Oct 10, 2024
60292a6
Add discover consumer to stack feature for es query rule type
cnasikas Oct 10, 2024
e55e4e7
Fix issues with find rules filtering
cnasikas Oct 10, 2024
0430634
Pass the consumers to the alerts table
cnasikas Oct 10, 2024
de75f29
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Oct 10, 2024
eaf3376
Update alert as data client to support filtering by consumers
cnasikas Oct 10, 2024
3d9038d
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Oct 11, 2024
d2e83a0
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Oct 12, 2024
bb93726
Update to UI to use consumers for RAC APIs
cnasikas Oct 13, 2024
4a03696
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Oct 13, 2024
f5adf3e
Fix aggregation filtering bug
cnasikas Oct 13, 2024
e0aff95
Fix search strategy empty response
cnasikas Oct 13, 2024
5ca68f4
Make the stack alerts table work with the new changes
cnasikas Oct 14, 2024
06b3f74
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Oct 14, 2024
cd61a88
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Oct 15, 2024
cfdb8a9
Fix merging conflicts
cnasikas Oct 15, 2024
ef72303
Initialize auth class without auth for 404 space errors
cnasikas Oct 15, 2024
ffbf250
Fix tests
cnasikas Oct 15, 2024
31af86c
Filiter also by the alerts consumer in o11y apps
cnasikas Oct 15, 2024
9870997
Fix integration tests
cnasikas Oct 15, 2024
21201f1
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Oct 16, 2024
c0a3b79
Fix security solution cypress tests
cnasikas Oct 16, 2024
8e33dcc
Fix cypress rule snoozing test
cnasikas Oct 16, 2024
8fe6190
Use rule type IDs instead of a single rule type ID in the alerts sear…
cnasikas Oct 16, 2024
963f4e9
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Oct 16, 2024
005375d
Fix privileges unit test
cnasikas Oct 17, 2024
a200984
fix: update deprecated privileges API integration tests to account fo…
azasypkin Oct 17, 2024
24ec594
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Oct 18, 2024
c33aaad
Merge branch 'poc_decouple_consumers_feature_ids' of github.com:cnasi…
cnasikas Oct 18, 2024
1f1ce53
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Oct 18, 2024
9618c26
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Oct 18, 2024
16cdf79
Fix i18n
cnasikas Oct 18, 2024
0ad199b
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Oct 19, 2024
b0892c6
Nits, fixes, and tests
cnasikas Oct 19, 2024
ba9bba3
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Oct 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 0 additions & 12 deletions oas_docs/bundle.json
Original file line number Diff line number Diff line change
Expand Up @@ -5484,18 +5484,6 @@
"schema": {
"type": "string"
}
},
{
"in": "query",
"name": "filter_consumers",
"required": false,
"schema": {
"items": {
"description": "List of consumers to filter.",
"type": "string"
},
"type": "array"
}
}
],
"responses": {
Expand Down
12 changes: 0 additions & 12 deletions oas_docs/bundle.serverless.json
Original file line number Diff line number Diff line change
Expand Up @@ -5484,18 +5484,6 @@
"schema": {
"type": "string"
}
},
{
"in": "query",
"name": "filter_consumers",
"required": false,
"schema": {
"items": {
"description": "List of consumers to filter.",
"type": "string"
},
"type": "array"
}
}
],
"responses": {
Expand Down
8 changes: 0 additions & 8 deletions oas_docs/output/kibana.serverless.staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4500,14 +4500,6 @@ paths:
required: false
schema:
type: string
- in: query
name: filter_consumers
required: false
schema:
items:
description: List of consumers to filter.
type: string
type: array
responses:
'200':
content:
Expand Down
8 changes: 0 additions & 8 deletions oas_docs/output/kibana.serverless.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4500,14 +4500,6 @@ paths:
required: false
schema:
type: string
- in: query
name: filter_consumers
required: false
schema:
items:
description: List of consumers to filter.
type: string
type: array
responses:
'200':
content:
Expand Down
8 changes: 0 additions & 8 deletions oas_docs/output/kibana.staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4881,14 +4881,6 @@ paths:
required: false
schema:
type: string
- in: query
name: filter_consumers
required: false
schema:
items:
description: List of consumers to filter.
type: string
type: array
responses:
'200':
content:
Expand Down
8 changes: 0 additions & 8 deletions oas_docs/output/kibana.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4881,14 +4881,6 @@ paths:
required: false
schema:
type: string
- in: query
name: filter_consumers
required: false
schema:
items:
description: List of consumers to filter.
type: string
type: array
responses:
'200':
content:
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-alerting-types/search_strategy_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/

import type { IEsSearchRequest, IEsSearchResponse } from '@kbn/search-types';
import type { ValidFeatureId } from '@kbn/rule-data-utils';
import type {
MappingRuntimeFields,
QueryDslFieldAndFormat,
Expand All @@ -18,7 +17,8 @@ import type {
import type { Alert } from './alert_type';

export type RuleRegistrySearchRequest = IEsSearchRequest & {
featureIds: ValidFeatureId[];
ruleTypeIds: string[];
consumers?: string[];
fields?: QueryDslFieldAndFormat[];
query?: Pick<QueryDslQueryContainer, 'bool' | 'ids'>;
sort?: SortCombinations[];
Expand Down
Copy link
Member Author

Choose a reason for hiding this comment

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

I am not sure why this was generated.

Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/
// ---------------------------------- WARNING ----------------------------------
// this file was generated, and should not be edited by hand
// ---------------------------------- WARNING ----------------------------------
import * as rt from 'io-ts';
import { Either } from 'fp-ts/lib/Either';
import { AlertSchema } from './alert_schema';
import { EcsSchema } from './ecs_schema';
const ISO_DATE_PATTERN = /^d{4}-d{2}-d{2}Td{2}:d{2}:d{2}.d{3}Z$/;
export const IsoDateString = new rt.Type<string, string, unknown>(
'IsoDateString',
rt.string.is,
(input, context): Either<rt.Errors, string> => {
if (typeof input === 'string' && ISO_DATE_PATTERN.test(input)) {
return rt.success(input);
} else {
return rt.failure(input, context);
}
},
rt.identity
);
export type IsoDateStringC = typeof IsoDateString;
export const schemaUnknown = rt.unknown;
export const schemaUnknownArray = rt.array(rt.unknown);
export const schemaString = rt.string;
export const schemaStringArray = rt.array(schemaString);
export const schemaNumber = rt.number;
export const schemaNumberArray = rt.array(schemaNumber);
export const schemaDate = rt.union([IsoDateString, schemaNumber]);
export const schemaDateArray = rt.array(schemaDate);
export const schemaDateRange = rt.partial({
gte: schemaDate,
lte: schemaDate,
});
export const schemaDateRangeArray = rt.array(schemaDateRange);
export const schemaStringOrNumber = rt.union([schemaString, schemaNumber]);
export const schemaStringOrNumberArray = rt.array(schemaStringOrNumber);
export const schemaBoolean = rt.boolean;
export const schemaBooleanArray = rt.array(schemaBoolean);
const schemaGeoPointCoords = rt.type({
type: schemaString,
coordinates: schemaNumberArray,
});
const schemaGeoPointString = schemaString;
const schemaGeoPointLatLon = rt.type({
lat: schemaNumber,
lon: schemaNumber,
});
const schemaGeoPointLocation = rt.type({
location: schemaNumberArray,
});
const schemaGeoPointLocationString = rt.type({
location: schemaString,
});
export const schemaGeoPoint = rt.union([
schemaGeoPointCoords,
schemaGeoPointString,
schemaGeoPointLatLon,
schemaGeoPointLocation,
schemaGeoPointLocationString,
]);
export const schemaGeoPointArray = rt.array(schemaGeoPoint);
// prettier-ignore
const ObservabilityThresholdAlertRequired = rt.type({
});
// prettier-ignore
const ObservabilityThresholdAlertOptional = rt.partial({
'kibana.alert.context': schemaUnknown,
'kibana.alert.evaluation.threshold': schemaStringOrNumber,
'kibana.alert.evaluation.value': schemaStringOrNumber,
'kibana.alert.evaluation.values': schemaStringOrNumberArray,
'kibana.alert.group': rt.array(
rt.partial({
field: schemaStringArray,
value: schemaStringArray,
})
),
});

// prettier-ignore
export const ObservabilityThresholdAlertSchema = rt.intersection([ObservabilityThresholdAlertRequired, ObservabilityThresholdAlertOptional, AlertSchema, EcsSchema]);
// prettier-ignore
export type ObservabilityThresholdAlert = rt.TypeOf<typeof ObservabilityThresholdAlertSchema>;
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import { groupingSearchResponse } from '../mocks/grouping_query.mock';
import { useAlertsGroupingState } from '../contexts/alerts_grouping_context';
import { I18nProvider } from '@kbn/i18n-react';
import {
mockFeatureIds,
mockRuleTypeIds,
mockConsumers,
mockDate,
mockGroupingProps,
mockGroupingId,
Expand Down Expand Up @@ -146,7 +147,8 @@ describe('AlertsGrouping', () => {
expect.objectContaining({
params: {
aggregations: {},
featureIds: mockFeatureIds,
ruleTypeIds: mockRuleTypeIds,
consumers: mockConsumers,
groupByField: 'kibana.alert.rule.name',
filters: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const AlertsGroupingInternal = <T extends BaseAlertsGroupAggregations>(
const {
groupingId,
services,
featureIds,
ruleTypeIds,
defaultGroupingOptions,
defaultFilters,
globalFilters,
Expand All @@ -79,7 +79,7 @@ const AlertsGroupingInternal = <T extends BaseAlertsGroupAggregations>(
const { grouping, updateGrouping } = useAlertsGroupingState(groupingId);

const { dataView } = useAlertsDataView({
featureIds,
ruleTypeIds,
dataViewsService: dataViews,
http,
toasts: notifications.toasts,
Expand Down Expand Up @@ -252,7 +252,7 @@ const typedMemo: <T>(c: T) => T = memo;
*
* return (
* <AlertsGrouping<YourAggregationsType>
* featureIds={[...]}
* ruleTypeIds={[...]}
* globalQuery={{ query: ..., language: 'kql' }}
* globalFilters={...}
* from={...}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ const mockGroupingLevelProps: Omit<AlertsGroupingLevelProps, 'children'> = {
describe('AlertsGroupingLevel', () => {
let buildEsQuerySpy: jest.SpyInstance;

beforeEach(() => {
jest.clearAllMocks();
});

beforeAll(() => {
buildEsQuerySpy = jest.spyOn(buildEsQueryModule, 'buildEsQuery');
});
Expand Down Expand Up @@ -119,4 +123,58 @@ describe('AlertsGroupingLevel', () => {
Object.keys(groupingSearchResponse.aggregations)
);
});

it('should calls useGetAlertsGroupAggregationsQuery with correct props', () => {
render(
<AlertsGroupingLevel {...mockGroupingLevelProps}>
{() => <span data-test-subj="grouping-level" />}
</AlertsGroupingLevel>
);

expect(mockUseGetAlertsGroupAggregationsQuery.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
Object {
"enabled": true,
"http": Object {
"get": [MockFunction],
},
"params": Object {
"aggregations": Object {},
"consumers": Array [
"stackAlerts",
],
"filters": Array [
Object {
"bool": Object {
"filter": Array [],
"must": Array [],
"must_not": Array [],
"should": Array [],
},
},
Object {
"range": Object {
"kibana.alert.time_range": Object {
"gte": "2020-07-07T08:20:18.966Z",
"lte": "2020-07-08T08:20:18.966Z",
},
},
},
],
"groupByField": "selectedGroup",
"pageIndex": 0,
"pageSize": 10,
"ruleTypeIds": Array [
".es-query",
],
},
"toasts": Object {
"addDanger": [MockFunction],
},
},
],
]
`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ const DEFAULT_FILTERS: Filter[] = [];
const typedMemo: <T>(c: T) => T = memo;
export const AlertsGroupingLevel = typedMemo(
<T extends BaseAlertsGroupAggregations>({
featureIds,
ruleTypeIds,
consumers,
defaultFilters = DEFAULT_FILTERS,
from,
getGrouping,
Expand Down Expand Up @@ -86,7 +87,8 @@ export const AlertsGroupingLevel = typedMemo(

const aggregationsQuery = useMemo<UseGetAlertsGroupAggregationsQueryProps['params']>(() => {
return {
featureIds,
ruleTypeIds,
consumers,
groupByField: selectedGroup,
aggregations: getAggregationsByGroupingField(selectedGroup)?.reduce(
(acc, val) => Object.assign(acc, val),
Expand All @@ -107,12 +109,13 @@ export const AlertsGroupingLevel = typedMemo(
pageSize,
};
}, [
featureIds,
consumers,
filters,
from,
getAggregationsByGroupingField,
pageIndex,
pageSize,
ruleTypeIds,
selectedGroup,
to,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
*/

import React from 'react';
import { AlertConsumers } from '@kbn/rule-data-utils';
import { AlertsGroupingProps } from '../types';

export const mockGroupingId = 'test';

export const mockFeatureIds = [AlertConsumers.STACK_ALERTS];
export const mockRuleTypeIds = ['.es-query'];
export const mockConsumers = ['stackAlerts'];

export const mockDate = {
from: '2020-07-07T08:20:18.966Z',
Expand All @@ -30,7 +30,8 @@ export const mockOptions = [
export const mockGroupingProps: Omit<AlertsGroupingProps, 'children'> = {
...mockDate,
groupingId: mockGroupingId,
featureIds: mockFeatureIds,
ruleTypeIds: mockRuleTypeIds,
consumers: mockConsumers,
defaultGroupingOptions: mockOptions,
getAggregationsByGroupingField: () => [],
getGroupStats: () => [{ title: 'Stat', component: <span /> }],
Expand Down
Loading