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

Merged
merged 213 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 201 commits
Commits
Show all changes
213 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
cddb402
Update snapshots
cnasikas Oct 20, 2024
3bea3f5
Nits, fixes, and tests - part 2
cnasikas Oct 20, 2024
0c5fabd
Remove o11y checks in the consumer dropdown
cnasikas Oct 21, 2024
a42d662
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Oct 21, 2024
a41e4a3
Use constant for rule types when registering o11y serverless feature …
cnasikas Oct 21, 2024
ad42ff1
Zip es data files
cnasikas Oct 21, 2024
31d2091
Fix cases deduction of owner
cnasikas Oct 21, 2024
1c87365
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Oct 22, 2024
c11de49
Fix es query integration tests
cnasikas Oct 22, 2024
4d8afa9
Update auth snapshots
cnasikas Oct 22, 2024
b5d3015
Fix types
cnasikas Oct 22, 2024
a3faee6
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Oct 23, 2024
11a171a
Fix find API conflicts
cnasikas Oct 23, 2024
ec97660
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Oct 26, 2024
5ad2a2c
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Oct 28, 2024
4292a9b
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Nov 1, 2024
10de2bf
Create authorization class after initialization
cnasikas Nov 1, 2024
6b8f1e7
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Nov 4, 2024
2de3d0d
Merge branch 'main' into poc_decouple_consumers_feature_ids
pborgonovi Nov 5, 2024
339de48
Merge branch 'main' into poc_decouple_consumers_feature_ids
pborgonovi Nov 5, 2024
9e8e407
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Nov 6, 2024
1e100de
Merge branch 'poc_decouple_consumers_feature_ids' of github.com:cnasi…
cnasikas Nov 6, 2024
c30b3e4
fix: remove special handling of the Alerting actions for the deprecat…
azasypkin Nov 6, 2024
2b48809
Merge branch 'main' into poc_decouple_consumers_feature_ids
pborgonovi Nov 6, 2024
3ef8d84
Fix integration tests
cnasikas Nov 7, 2024
25738a4
Fix synthetics rule types
cnasikas Nov 7, 2024
65312aa
Feature plugin PR feedback
cnasikas Nov 7, 2024
93f5962
Merge branch 'poc_decouple_consumers_feature_ids' of github.com:cnasi…
cnasikas Nov 7, 2024
1cf5ecc
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Nov 8, 2024
2112262
Fix i18n
cnasikas Nov 8, 2024
734b9a2
Add comment to explain instatiation of the auth class with empty data…
cnasikas Nov 8, 2024
5162350
Remove unecessary async from validateRuleAndCreateFakeRequest
cnasikas Nov 8, 2024
f188d6a
Add test for multiple consumers in the alerting action builder
cnasikas Nov 8, 2024
66ca6c4
Fix types after merge
cnasikas Nov 8, 2024
a70077a
Update authorization snapshots
cnasikas Nov 8, 2024
77dbef8
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Nov 11, 2024
8f9381a
Hide consumer selection in serverless
cnasikas Nov 11, 2024
ce8db3c
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Nov 12, 2024
d666a2f
Use variables for metric enum
cnasikas Nov 12, 2024
e3c4a60
Rename stack rule type constants
cnasikas Nov 12, 2024
887a58d
Filter only for the currnet rule in the alert history component
cnasikas Nov 12, 2024
3c0b3cc
Use the constant for uptime exported by @kbn/rule-data-utils
cnasikas Nov 12, 2024
ed6b9c6
Fix internal/rac/alerts/find request schema
cnasikas Nov 12, 2024
00b50fd
Get all o11y indices in the investigation app
cnasikas Nov 12, 2024
3bd91a6
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Nov 14, 2024
850ef24
Restore filter_consumers query param
cnasikas Nov 14, 2024
46b978e
Show ML alerts with alerts consumer
cnasikas Nov 14, 2024
c39f011
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Nov 17, 2024
911a41b
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Nov 18, 2024
7564ac5
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Nov 19, 2024
52c76c9
Fix types
cnasikas Nov 19, 2024
3f3a91f
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Nov 20, 2024
b8dc926
Revert test file in security solution
cnasikas Nov 20, 2024
fa2a75b
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Nov 25, 2024
c0d43f8
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Nov 26, 2024
1ed4c79
Fix types
cnasikas Nov 26, 2024
6d984e0
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Dec 2, 2024
9432aa3
Fix arguments in getAuthorizedAlertsIndices
cnasikas Dec 2, 2024
643e04f
Fix alerting types
cnasikas Dec 2, 2024
7758052
PR feedback
cnasikas Dec 2, 2024
e7afb8e
Fix types in security solution
cnasikas Dec 2, 2024
a0c2dab
Merge branch 'main' into poc_decouple_consumers_feature_ids
cnasikas Dec 3, 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
  •  
  •  
  •  
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.

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 do not understand why this was generated. Any ideas?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure why this was generated for this PR. This is auto-generating an alerts schema for the observability.threshold alert context, which is defined here:

and added quite a while ago

It looks like the test

is using the /api/alerting/rule_types API so perhaps there was a bug before that prevented this rule type from being returned in the API?

Copy link
Contributor

Choose a reason for hiding this comment

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

yea, i just tried it out and on main, I'm not getting the observability.rules.custom_threshold in the /api/alerting/rule_types response so it seems like something in this PR fixed that.

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
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ export const getQuery = ({
selectedGroup,
uniqueValue,
timeRange,
featureIds,
ruleTypeIds,
}: {
selectedGroup: string;
uniqueValue: string;
timeRange: { from: string; to: string };
featureIds: string[];
ruleTypeIds: string[];
}) => ({
_source: false,
aggs: {
Expand Down Expand Up @@ -52,7 +52,7 @@ export const getQuery = ({
},
},
},
feature_ids: featureIds,
rule_type_ids: ruleTypeIds,
query: {
bool: {
filter: [
Expand Down
9 changes: 6 additions & 3 deletions packages/kbn-alerts-grouping/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/

import type { Filter, Query } from '@kbn/es-query';
import { ValidFeatureId } from '@kbn/rule-data-utils';
import type { NotificationsStart } from '@kbn/core-notifications-browser';
import type { DataViewsServicePublic } from '@kbn/data-views-plugin/public/types';
import type { HttpSetup } from '@kbn/core-http-browser';
Expand Down Expand Up @@ -63,9 +62,13 @@ export interface AlertsGroupingProps<
*/
defaultGroupingOptions: GroupOption[];
/**
* The alerting feature ids this grouping covers
* The alerting rule type ids this grouping covers
*/
featureIds: ValidFeatureId[];
ruleTypeIds: string[];
/**
* The alerting consumers this grouping covers
*/
consumers?: string[];
/**
* Time filter start
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,5 +289,6 @@ function getAlertType(actionVariables: ActionVariables): RuleType {
producer: ALERTING_FEATURE_ID,
minimumLicenseRequired: 'basic',
enabledInLicense: true,
category: 'my-category',
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { AlertFilterControls, AlertFilterControlsProps } from './alert_filter_controls';
import { AlertConsumers } from '@kbn/rule-data-utils';
import { DEFAULT_CONTROLS } from './constants';
import { useAlertsDataView } from '../common/hooks/use_alerts_data_view';
import { FilterGroup } from './filter_group';
Expand Down Expand Up @@ -56,7 +55,7 @@ const ControlGroupRenderer = (() => (

describe('AlertFilterControls', () => {
const props: AlertFilterControlsProps = {
featureIds: [AlertConsumers.STACK_ALERTS],
ruleTypeIds: ['.es-query'],
defaultControls: DEFAULT_CONTROLS,
dataViewSpec: {
id: 'alerts-filters-dv',
Expand Down
Loading