-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[Logs UI] [Alerting] "Group by" functionality #68250
Merged
Merged
Changes from 28 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
a02b17d
Server side (executor) support for group by
Kerry350 dd92f5f
Add UI functionality
Kerry350 2f9f6cd
Ensure array entries
Kerry350 4246222
Merge remote-tracking branch 'upstream/master' into 67465-logs-alert-…
Kerry350 7563fac
Merge remote-tracking branch 'upstream/master' into 67465-logs-alert-…
Kerry350 9be25e6
Merge remote-tracking branch 'upstream/master' into 67465-logs-alert-…
Kerry350 b773abe
Amend current executor tests
Kerry350 8726524
Merge branch 'master' into 67465-logs-alert-group-by
elasticmachine 7461571
Merge remote-tracking branch 'upstream/master' into 67465-logs-alert-…
Kerry350 54d0144
Merge remote-tracking branch 'upstream/master' into 67465-logs-alert-…
Kerry350 c9ef022
Server side amendments
Kerry350 27296a9
Client side changes
Kerry350 b29ee1a
Merge remote-tracking branch 'upstream/master' into 67465-logs-alert-…
Kerry350 3901a07
Ensure "more than" is handled and ensure correct component is exporte…
Kerry350 0ceb3fe
Remove hit total capping due to document count total dependency
Kerry350 f0e11f6
Spread aggs properly
Kerry350 7806cf3
Alter handling of composite aggs
Kerry350 971e4bd
Merge remote-tracking branch 'upstream/master' into 67465-logs-alert-…
Kerry350 c9e56a2
Add response runtime type check
Kerry350 16608ee
Fix type to account for undefined group_key
Kerry350 b4bcde8
Merge remote-tracking branch 'upstream/master' into 67465-logs-alert-…
Kerry350 8bc54ff
Use separate functions for grouped and ungrouped ES queries
Kerry350 8093dca
Cast a wider net for group results and add "must" filters to a sub ag…
Kerry350 0ae6fe3
Merge remote-tracking branch 'upstream/master' into 67465-logs-alert-…
Kerry350 c40d459
Merge remote-tracking branch 'upstream/master' into 67465-logs-alert-…
Kerry350 aed4063
Merge remote-tracking branch 'upstream/master' into 67465-logs-alert-…
Kerry350 902bd37
Amend executor tests
Kerry350 8cae6b6
Ensure inner filtering scopes back to unpadded range
Kerry350 b67ad73
Merge remote-tracking branch 'upstream/master' into 67465-logs-alert-…
Kerry350 b50de34
Update x-pack/plugins/infra/server/lib/alerting/log_threshold/log_thr…
Kerry350 34bbece
Update x-pack/plugins/infra/server/lib/alerting/log_threshold/log_thr…
Kerry350 827071d
Review changes
Kerry350 1b4b99f
Merge branch '67465-logs-alert-group-by' of github.com:Kerry350/kiban…
Kerry350 a6dfeb6
Tweak filtering of fields (remove searchable requirement)
Kerry350 17b49f8
Update x-pack/plugins/infra/public/components/alerting/logs/expressio…
Kerry350 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
x-pack/plugins/infra/common/utils/elasticsearch_runtime_types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import * as rt from 'io-ts'; | ||
|
||
export const commonSearchSuccessResponseFieldsRT = rt.type({ | ||
_shards: rt.type({ | ||
total: rt.number, | ||
successful: rt.number, | ||
skipped: rt.number, | ||
failed: rt.number, | ||
}), | ||
timed_out: rt.boolean, | ||
took: rt.number, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...ugins/infra/public/components/alerting/shared/group_by_expression/group_by_expression.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React, { useState, useMemo } from 'react'; | ||
import { IFieldType } from 'src/plugins/data/public'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { | ||
EuiPopoverTitle, | ||
EuiFlexItem, | ||
EuiFlexGroup, | ||
EuiPopover, | ||
EuiExpression, | ||
} from '@elastic/eui'; | ||
import { GroupBySelector } from './selector'; | ||
|
||
interface Props { | ||
selectedGroups?: string[]; | ||
fields: IFieldType[]; | ||
onChange: (groupBy: string[]) => void; | ||
label?: string; | ||
} | ||
|
||
const DEFAULT_GROUP_BY_LABEL = i18n.translate('xpack.infra.alerting.alertFlyout.groupByLabel', { | ||
defaultMessage: 'Group By', | ||
}); | ||
|
||
const EVERYTHING_PLACEHOLDER = i18n.translate( | ||
'xpack.infra.alerting.alertFlyout.groupBy.placeholder', | ||
{ | ||
defaultMessage: 'Nothing (ungrouped)', | ||
} | ||
); | ||
|
||
export const GroupByExpression: React.FC<Props> = ({ | ||
selectedGroups = [], | ||
fields, | ||
label, | ||
onChange, | ||
}) => { | ||
const [isPopoverOpen, setIsPopoverOpen] = useState(false); | ||
|
||
const expressionValue = useMemo(() => { | ||
return selectedGroups.length > 0 ? selectedGroups.join(', ') : EVERYTHING_PLACEHOLDER; | ||
}, [selectedGroups]); | ||
|
||
const labelProp = label ?? DEFAULT_GROUP_BY_LABEL; | ||
|
||
return ( | ||
<EuiFlexGroup gutterSize="s"> | ||
<EuiFlexItem grow={false}> | ||
<EuiPopover | ||
id="groupByExpression" | ||
button={ | ||
<EuiExpression | ||
description={labelProp} | ||
uppercase={true} | ||
value={expressionValue} | ||
isActive={isPopoverOpen} | ||
onClick={() => setIsPopoverOpen(true)} | ||
/> | ||
} | ||
isOpen={isPopoverOpen} | ||
closePopover={() => setIsPopoverOpen(false)} | ||
ownFocus | ||
panelPaddingSize="s" | ||
anchorPosition="downLeft" | ||
> | ||
<div style={{ zIndex: 11000 }}> | ||
<EuiPopoverTitle>{labelProp}</EuiPopoverTitle> | ||
<GroupBySelector | ||
selectedGroups={selectedGroups} | ||
onChange={onChange} | ||
fields={fields} | ||
label={labelProp} | ||
placeholder={EVERYTHING_PLACEHOLDER} | ||
/> | ||
</div> | ||
</EuiPopover> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
); | ||
}; |
56 changes: 56 additions & 0 deletions
56
x-pack/plugins/infra/public/components/alerting/shared/group_by_expression/selector.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { EuiComboBox } from '@elastic/eui'; | ||
import React, { useCallback, useMemo } from 'react'; | ||
import { IFieldType } from 'src/plugins/data/public'; | ||
|
||
interface Props { | ||
selectedGroups?: string[]; | ||
onChange: (groupBy: string[]) => void; | ||
fields: IFieldType[]; | ||
label: string; | ||
placeholder: string; | ||
} | ||
|
||
export const GroupBySelector = ({ | ||
onChange, | ||
fields, | ||
selectedGroups = [], | ||
label, | ||
placeholder, | ||
}: Props) => { | ||
const handleChange = useCallback( | ||
(selectedOptions: Array<{ label: string }>) => { | ||
const groupBy = selectedOptions.map((option) => option.label); | ||
onChange(groupBy); | ||
}, | ||
[onChange] | ||
); | ||
|
||
const formattedSelectedGroups = useMemo(() => { | ||
return selectedGroups.map((group) => ({ label: group })); | ||
}, [selectedGroups]); | ||
|
||
const options = useMemo(() => { | ||
return fields.filter((field) => field.aggregatable).map((field) => ({ label: field.name })); | ||
}, [fields]); | ||
|
||
return ( | ||
<div style={{ minWidth: '300px' }}> | ||
<EuiComboBox | ||
placeholder={placeholder} | ||
aria-label={label} | ||
fullWidth | ||
singleSelection={false} | ||
selectedOptions={formattedSelectedGroups} | ||
options={options} | ||
onChange={handleChange} | ||
isClearable={true} | ||
/> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that this is handled outside of the selector, do we want to allow other types than just
string
in here?And could you help me understand why the fields have to be searchable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any idea about this? 😇