Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
15132ab
Save group information dynamically
maryam-saeidi Nov 7, 2024
718c6bd
Add api integration test
maryam-saeidi May 1, 2025
8647557
Fix type
maryam-saeidi May 1, 2025
d8d9cb7
Update test snapshot
maryam-saeidi May 1, 2025
8b8d28e
Fix unit test
maryam-saeidi May 1, 2025
7622d18
Merge branch 'main' into 183248-dynamically-mapped-groups
maryam-saeidi May 2, 2025
ad70485
Update test snapshot
maryam-saeidi May 2, 2025
5e2da34
Merge branch 'main' into 183248-dynamically-mapped-groups
maryam-saeidi May 2, 2025
ee893ef
Merge branch 'main' into 183248-dynamically-mapped-groups
maryam-saeidi May 6, 2025
4cc0fee
Merge branch 'main' into 183248-dynamically-mapped-groups
maryam-saeidi May 6, 2025
4914700
Fix type
maryam-saeidi May 7, 2025
39d0d3a
Merge branch 'main' into 183248-dynamically-mapped-groups
maryam-saeidi May 7, 2025
e80b47f
Avoid parsing instanceId and get the group by fields directly from th…
maryam-saeidi May 12, 2025
975b9d0
Merge branch 'main' into 183248-dynamically-mapped-groups
maryam-saeidi May 12, 2025
2acbf5c
Bring back getGroupByObject
maryam-saeidi May 12, 2025
b8a7317
Bring back getFormattedGroupBy and fix test
maryam-saeidi May 12, 2025
ea59e63
Add context.grouping to the API integration tests
maryam-saeidi May 12, 2025
c03baf0
Fix test type
maryam-saeidi May 12, 2025
b7dfcfd
Merge branch 'main' into 183248-dynamically-mapped-groups
maryam-saeidi May 15, 2025
6da4ea4
Change type
maryam-saeidi May 15, 2025
fe89380
Merge branch 'main' into 183248-dynamically-mapped-groups
maryam-saeidi May 16, 2025
16b5066
Merge branch 'main' into 183248-dynamically-mapped-groups
maryam-saeidi May 19, 2025
81b23f7
Merge branch 'main' into 183248-dynamically-mapped-groups
maryam-saeidi May 22, 2025
6b77e4f
Merge branch 'main' into 183248-dynamically-mapped-groups
maryam-saeidi May 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
ALERT_EVALUATION_THRESHOLD,
ALERT_EVALUATION_VALUE,
ALERT_EVALUATION_VALUES,
ALERT_GROUPING,
ALERT_GROUP,
ALERT_GROUP_FIELD,
ALERT_GROUP_VALUE,
Expand All @@ -31,6 +32,12 @@ export const legacyExperimentalFieldMap = {
required: false,
array: true,
},
[ALERT_GROUPING]: {
Comment thread
maryam-saeidi marked this conversation as resolved.
type: 'object',
dynamic: true,
array: false,
required: false,
},
[ALERT_GROUP]: {
type: 'object',
array: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const ObservabilityApmAlertOptional = rt.partial({
value: schemaStringArray,
})
),
'kibana.alert.grouping': schemaUnknown,
Comment thread
maryam-saeidi marked this conversation as resolved.
labels: schemaUnknown,
'processor.event': schemaString,
'service.environment': schemaString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const ObservabilityLogsAlertOptional = rt.partial({
value: schemaStringArray,
})
),
'kibana.alert.grouping': schemaUnknown,
});

// prettier-ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const ObservabilityMetricsAlertOptional = rt.partial({
value: schemaStringArray,
})
),
'kibana.alert.grouping': schemaUnknown,
});

// prettier-ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const ObservabilitySloAlertOptional = rt.partial({
value: schemaStringArray,
})
),
'kibana.alert.grouping': schemaUnknown,
'slo.id': schemaString,
'slo.instanceId': schemaString,
'slo.revision': schemaStringOrNumber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const ObservabilityThresholdAlertOptional = rt.partial({
value: schemaStringArray,
})
),
'kibana.alert.grouping': schemaUnknown,
});

// prettier-ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ const ObservabilityUptimeAlertOptional = rt.partial({
value: schemaStringArray,
})
),
'kibana.alert.grouping': schemaUnknown,
labels: schemaUnknown,
'location.id': schemaStringArray,
'location.name': schemaStringArray,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const ALERT_EVALUATION_THRESHOLD = `${ALERT_NAMESPACE}.evaluation.threshold` as
const ALERT_EVALUATION_VALUE = `${ALERT_NAMESPACE}.evaluation.value` as const;
const ALERT_CONTEXT = `${ALERT_NAMESPACE}.context` as const;
const ALERT_EVALUATION_VALUES = `${ALERT_NAMESPACE}.evaluation.values` as const;
const ALERT_GROUPING = `${ALERT_NAMESPACE}.grouping` as const;
const ALERT_GROUP = `${ALERT_NAMESPACE}.group` as const;
const ALERT_GROUP_FIELD = `${ALERT_GROUP}.field` as const;
const ALERT_GROUP_VALUE = `${ALERT_GROUP}.value` as const;
Expand Down Expand Up @@ -134,6 +135,7 @@ const fields = {
ALERT_EVALUATION_THRESHOLD,
ALERT_EVALUATION_VALUE,
ALERT_EVALUATION_VALUES,
ALERT_GROUPING,
ALERT_GROUP,
ALERT_GROUP_FIELD,
ALERT_GROUP_VALUE,
Expand Down Expand Up @@ -209,6 +211,7 @@ export {
ALERT_EVALUATION_VALUE,
ALERT_CONTEXT,
ALERT_EVALUATION_VALUES,
ALERT_GROUPING,
ALERT_GROUP,
ALERT_GROUP_FIELD,
ALERT_GROUP_VALUE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@
*/

export { getEcsGroups } from './src/get_ecs_groups';
export { getGroupByObject, getFormattedGroupBy } from './src/group_by_object_utils';
export {
unflattenGrouping,
getFormattedGroups,
getFormattedGroupBy,
getGroupByObject,
} from './src/group_by_object_utils';
export type { Group, FieldsObject } from './src/types';
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,51 @@
* 2.0.
*/

import { getFormattedGroupBy, getGroupByObject } from './group_by_object_utils';
import {
getFormattedGroups,
unflattenGrouping,
getGroupByObject,
getFormattedGroupBy,
} from './group_by_object_utils';

describe('getFormattedGroups', () => {
it('should format groupBy correctly for empty input', () => {
expect(getFormattedGroups()).toBeUndefined();
});

it('should format groupBy correctly for multiple groups', () => {
expect(
getFormattedGroups({
'host.name': 'host-0',
'host.mac': '00-00-5E-00-53-23',
tags: 'event-0',
'container.name': 'container-name',
})
).toEqual([
{ field: 'host.name', value: 'host-0' },
{ field: 'host.mac', value: '00-00-5E-00-53-23' },
{ field: 'tags', value: 'event-0' },
{ field: 'container.name', value: 'container-name' },
]);
});
});

describe('unflattenGrouping', () => {
it('should return undefined when there is no grouping', () => {
expect(unflattenGrouping()).toBeUndefined();
});

it('should return an object containing groups for one groupBy field', () => {
expect(unflattenGrouping({ 'host.name': 'host-0' })).toEqual({ host: { name: 'host-0' } });
});

it('should return an object containing groups for multiple groupBy fields', () => {
expect(unflattenGrouping({ 'host.name': 'host-0', 'container.id': 'container-0' })).toEqual({
container: { id: 'container-0' },
host: { name: 'host-0' },
});
});
});

describe('getFormattedGroupBy', () => {
it('should format groupBy correctly for empty input', () => {
Expand Down Expand Up @@ -53,10 +97,6 @@ describe('getFormattedGroupBy', () => {
});

describe('getGroupByObject', () => {
it('should return empty object for undefined groupBy', () => {
expect(getFormattedGroupBy(undefined, new Set<string>())).toEqual({});
});

it('should return an object containing groups for one groupBy field', () => {
expect(getGroupByObject('host.name', new Set(['host-0', 'host-1']))).toEqual({
'host-0': { host: { name: 'host-0' } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import { unflattenObject } from '@kbn/object-utils';
import { Group } from './types';

// TODO: Remove after updating the group logic in the log threshold rule
// https://github.com/elastic/kibana/issues/220006
export const getGroupByObject = (
groupBy: string | string[] | undefined,
groupValueSet: Set<string>
Expand All @@ -28,6 +30,16 @@ export const getGroupByObject = (
return groupKeyValueMappingsObject;
};

export const unflattenGrouping = (
grouping?: Record<string, string> | undefined
): Record<string, any> | undefined => {
if (grouping) {
return unflattenObject(grouping);
}
};

// TODO: Remove after updating the group logic in the log threshold rule
// https://github.com/elastic/kibana/issues/220006
export const getFormattedGroupBy = (
groupBy: string | string[] | undefined,
groupSet: Set<string>
Expand All @@ -46,3 +58,14 @@ export const getFormattedGroupBy = (
}
return groupByKeysObjectMapping;
};

export const getFormattedGroups = (grouping?: Record<string, string>): Group[] | undefined => {
const groups: Group[] = [];
if (grouping) {
const groupKeys = Object.keys(grouping);
groupKeys.forEach((group) => {
groups.push({ field: group, value: grouping[group] });
});
}
return groups.length ? groups : undefined;
};
Loading