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

Set from & to as optional args in @kbn/grouping #213212

Merged
merged 1 commit into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -15,7 +15,10 @@ import { groupingBucket } from '../../mocks';

const testProps: GroupingQueryArgs = {
additionalFilters: [],
from: '2022-12-28T15:35:32.871Z',
timeRange: {
from: '2022-12-28T15:35:32.871Z',
to: '2023-02-23T06:59:59.999Z',
},
groupByField: 'host.name',
statsAggregations: [
{
Expand Down Expand Up @@ -59,7 +62,6 @@ const testProps: GroupingQueryArgs = {
runtimeMappings: {},
uniqueValue: 'whatAGreatAndUniqueValue',
size: 25,
to: '2023-02-23T06:59:59.999Z',
};
describe('group selector', () => {
beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,15 @@ export const MAX_QUERY_SIZE = 10000;

export const getGroupingQuery = ({
additionalFilters = [],
from,
groupByField,
pageNumber,
rootAggregations,
runtimeMappings,
size = DEFAULT_GROUP_BY_FIELD_SIZE,
sort,
statsAggregations,
to,
uniqueValue,
timeRange,
}: GroupingQueryArgs): GroupingQuery => ({
size: 0,
runtime_mappings: {
Expand Down Expand Up @@ -104,14 +103,18 @@ export const getGroupingQuery = ({
bool: {
filter: [
...additionalFilters,
{
range: {
'@timestamp': {
gte: from,
lte: to,
},
},
},
...(timeRange
? [
{
range: {
'@timestamp': {
gte: timeRange.from,
lte: timeRange.to,
},
},
},
]
: []),
],
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export type NamedAggregation = Record<string, estypes.AggregationsAggregationCon

export interface GroupingQueryArgs {
additionalFilters: BoolAgg[];
from: string;
groupByField: string;
rootAggregations?: NamedAggregation[];
runtimeMappings?: RunTimeMappings;
Expand All @@ -42,7 +41,10 @@ export interface GroupingQueryArgs {
size?: number;
sort?: Array<{ [category: string]: { order: 'asc' | 'desc' } }>;
statsAggregations?: NamedAggregation[];
to: string;
timeRange?: {
from: string;
to: string;
};
}

export interface MainAggregation extends NamedAggregation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,10 @@ export const useLatestFindingsGrouping = ({
additionalFilters: query ? [query, additionalFilters] : [additionalFilters],
groupByField: currentSelectedGroup,
uniqueValue,
from: `now-${CDR_3RD_PARTY_RETENTION_POLICY}`,
to: 'now',
timeRange: {
from: `now-${CDR_3RD_PARTY_RETENTION_POLICY}`,
to: 'now',
},
pageNumber: activePageIndex * pageSize,
size: pageSize,
sort: [{ groupByField: { order: 'desc' } }, { complianceScore: { order: 'asc' } }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,10 @@ export const useLatestVulnerabilitiesGrouping = ({
additionalFilters: query ? [query, additionalFilters] : [additionalFilters],
groupByField: currentSelectedGroup,
uniqueValue,
from: `now-${CDR_3RD_PARTY_RETENTION_POLICY}`,
to: 'now',
timeRange: {
from: `now-${CDR_3RD_PARTY_RETENTION_POLICY}`,
to: 'now',
},
pageNumber: activePageIndex * pageSize,
size: pageSize,
sort: [{ groupByField: { order: 'desc' } }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ export const getAlertsGroupingQuery = ({
}: AlertsGroupingQueryParams) =>
getGroupingQuery({
additionalFilters,
from,
timeRange: {
from,
to,
},
groupByField: selectedGroup,
statsAggregations: !isNoneGroup([selectedGroup])
? getAggregationsByGroupField(selectedGroup)
Expand All @@ -45,7 +48,6 @@ export const getAlertsGroupingQuery = ({
uniqueValue,
size: pageSize,
sort: [{ unitsCount: { order: 'desc' } }],
to,
});

const getAggregationsByGroupField = (field: string): NamedAggregation[] => {
Expand Down