-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[ResponseOps] Execution log - data grid component, date picker, and status filter #128183
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
Merged
JiaweiWu
merged 20 commits into
elastic:main
from
JiaweiWu:issue-126841-event-log-data-grid
Mar 28, 2022
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
1cb6695
Event log and alerts tab in rule summary
JiaweiWu a4f80e7
Fix tests
JiaweiWu b9b0af7
Event log implementation in rule summary page
JiaweiWu 344a0fa
Unit testing
JiaweiWu 458b9d7
run lint
JiaweiWu ccc13d3
rule event log unit tests
JiaweiWu d16d09f
Load execution API unit test
JiaweiWu b3674ef
With bulk rule api test update
JiaweiWu 598d49e
Fix lint
JiaweiWu 7a318ca
Address comments
JiaweiWu 9b5f0a2
Fix feature flag test
JiaweiWu 983c9be
Merge branch 'main' into issue-126841-event-log-data-grid
kibanamachine 0cf9a23
Fix import type linting
JiaweiWu 726d79a
Integration test and fixed lint
JiaweiWu 96bc5e9
Merge branch 'main' into issue-126841-event-log-data-grid
kibanamachine 6c022d7
Lazy load execution log list
JiaweiWu 20d5e8b
Merge branch 'main' into issue-126841-event-log-data-grid
kibanamachine dac8f66
Bump up triggers_actions_ui limits.yml size to 100kbs
JiaweiWu 7ba91c3
Fix merge conflicts
JiaweiWu 1c26f51
Address comments
JiaweiWu 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 hidden or 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 hidden or 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,40 @@ | ||
| /* | ||
| * 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; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| export const executionLogSortableColumns = [ | ||
| 'timestamp', | ||
| 'execution_duration', | ||
| 'total_search_duration', | ||
| 'es_search_duration', | ||
| 'schedule_delay', | ||
| 'num_triggered_actions', | ||
| ] as const; | ||
|
|
||
| export type ExecutionLogSortFields = typeof executionLogSortableColumns[number]; | ||
|
|
||
| export interface IExecutionLog { | ||
| id: string; | ||
| timestamp: string; | ||
| duration_ms: number; | ||
| status: string; | ||
| message: string; | ||
| num_active_alerts: number; | ||
| num_new_alerts: number; | ||
| num_recovered_alerts: number; | ||
| num_triggered_actions: number; | ||
| num_succeeded_actions: number; | ||
| num_errored_actions: number; | ||
| total_search_duration_ms: number; | ||
| es_search_duration_ms: number; | ||
| schedule_delay_ms: number; | ||
| timed_out: boolean; | ||
| } | ||
|
|
||
| export interface IExecutionLogResult { | ||
| total: number; | ||
| data: IExecutionLog[]; | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
96 changes: 96 additions & 0 deletions
96
...iggers_actions_ui/public/application/lib/rule_api/load_execution_log_aggregations.test.ts
This file contains hidden or 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,96 @@ | ||
| /* | ||
| * 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; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import { httpServiceMock } from '../../../../../../../src/core/public/mocks'; | ||
| import { loadExecutionLogAggregations, SortField } from './load_execution_log_aggregations'; | ||
|
|
||
| const http = httpServiceMock.createStartContract(); | ||
|
|
||
| const mockResponse = { | ||
| data: [ | ||
| { | ||
| duration_ms: 50, | ||
| es_search_duration_ms: 1, | ||
| id: '13af2138-1c9d-4d34-95c1-c25fbfbb8eeb', | ||
| message: "rule executed: .index-threshold:c8f2ccb0-aac4-11ec-a5ae-2101bb96406d: 'test'", | ||
| num_active_alerts: 0, | ||
| num_errored_actions: 0, | ||
| num_new_alerts: 0, | ||
| num_recovered_alerts: 0, | ||
| num_succeeded_actions: 0, | ||
| num_triggered_actions: 0, | ||
| schedule_delay_ms: 1623, | ||
| status: 'success', | ||
| timed_out: false, | ||
| timestamp: '2022-03-23T16:17:53.482Z', | ||
| total_search_duration_ms: 4, | ||
| }, | ||
| ], | ||
| total: 5, | ||
| }; | ||
|
|
||
| describe('loadExecutionLogAggregations', () => { | ||
| test('should call load execution log aggregation API', async () => { | ||
| http.get.mockResolvedValueOnce(mockResponse); | ||
|
|
||
| const sortTimestamp = { | ||
| timestamp: { | ||
| order: 'asc', | ||
| }, | ||
| } as SortField; | ||
|
|
||
| const result = await loadExecutionLogAggregations({ | ||
| id: 'test-id', | ||
| dateStart: '2022-03-23T16:17:53.482Z', | ||
| dateEnd: '2022-03-23T16:17:53.482Z', | ||
| filter: ['success', 'unknown'], | ||
| perPage: 10, | ||
| page: 0, | ||
| sort: [sortTimestamp], | ||
| http, | ||
| }); | ||
|
|
||
| expect(result).toEqual({ | ||
| ...mockResponse, | ||
| data: [ | ||
| { | ||
| execution_duration: 50, | ||
| es_search_duration: 1, | ||
| id: '13af2138-1c9d-4d34-95c1-c25fbfbb8eeb', | ||
| message: "rule executed: .index-threshold:c8f2ccb0-aac4-11ec-a5ae-2101bb96406d: 'test'", | ||
| num_active_alerts: 0, | ||
| num_errored_actions: 0, | ||
| num_new_alerts: 0, | ||
| num_recovered_alerts: 0, | ||
| num_succeeded_actions: 0, | ||
| num_triggered_actions: 0, | ||
| schedule_delay: 1623, | ||
| status: 'success', | ||
| timed_out: false, | ||
| timestamp: '2022-03-23T16:17:53.482Z', | ||
| total_search_duration: 4, | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
| expect(http.get.mock.calls[0]).toMatchInlineSnapshot(` | ||
| Array [ | ||
| "/internal/alerting/rule/test-id/_execution_log", | ||
| Object { | ||
| "query": Object { | ||
| "date_end": "2022-03-23T16:17:53.482Z", | ||
| "date_start": "2022-03-23T16:17:53.482Z", | ||
| "filter": "success OR unknown", | ||
| "page": 1, | ||
| "per_page": 10, | ||
| "sort": "[{\\"timestamp\\":{\\"order\\":\\"asc\\"}}]", | ||
| }, | ||
| }, | ||
| ] | ||
| `); | ||
| }); | ||
| }); |
97 changes: 97 additions & 0 deletions
97
...ns/triggers_actions_ui/public/application/lib/rule_api/load_execution_log_aggregations.ts
This file contains hidden or 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,97 @@ | ||
| /* | ||
| * 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; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| /* eslint-disable @typescript-eslint/naming-convention */ | ||
|
|
||
| import { HttpSetup } from 'kibana/public'; | ||
| import type { SortOrder } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; | ||
| import { INTERNAL_BASE_ALERTING_API_PATH } from '../../constants'; | ||
|
|
||
| import { | ||
| IExecutionLogResult, | ||
| IExecutionLog, | ||
| ExecutionLogSortFields, | ||
| } from '../../../../../alerting/common'; | ||
| import { AsApiContract, RewriteRequestCase } from '../../../../../actions/common'; | ||
|
|
||
| const getRenamedLog = (data: IExecutionLog) => { | ||
| const { | ||
| duration_ms, | ||
| total_search_duration_ms, | ||
| es_search_duration_ms, | ||
| schedule_delay_ms, | ||
| ...rest | ||
| } = data; | ||
|
|
||
| return { | ||
| execution_duration: data.duration_ms, | ||
| total_search_duration: data.total_search_duration_ms, | ||
| es_search_duration: data.es_search_duration_ms, | ||
| schedule_delay: data.schedule_delay_ms, | ||
| ...rest, | ||
| }; | ||
| }; | ||
|
|
||
| const rewriteBodyRes: RewriteRequestCase<IExecutionLogResult> = ({ data, total }: any) => ({ | ||
| data: data.map((log: IExecutionLog) => getRenamedLog(log)), | ||
| total, | ||
| }); | ||
|
|
||
| const getFilter = (filter: string[] | undefined) => { | ||
| if (!filter || !filter.length) { | ||
| return; | ||
| } | ||
| return filter.join(' OR '); | ||
| }; | ||
|
|
||
| export type SortField = Record< | ||
| ExecutionLogSortFields, | ||
| { | ||
| order: SortOrder; | ||
| } | ||
| >; | ||
|
|
||
| export interface LoadExecutionLogAggregationsProps { | ||
| id: string; | ||
| dateStart: string; | ||
| dateEnd?: string; | ||
| filter?: string[]; | ||
| perPage?: number; | ||
| page?: number; | ||
| sort?: SortField[]; | ||
| } | ||
|
|
||
| export const loadExecutionLogAggregations = async ({ | ||
| id, | ||
| http, | ||
| dateStart, | ||
| dateEnd, | ||
| filter, | ||
| perPage = 10, | ||
| page = 0, | ||
| sort = [], | ||
| }: LoadExecutionLogAggregationsProps & { http: HttpSetup }) => { | ||
| const sortField: any[] = sort; | ||
|
|
||
| const result = await http.get<AsApiContract<IExecutionLogResult>>( | ||
| `${INTERNAL_BASE_ALERTING_API_PATH}/rule/${id}/_execution_log`, | ||
| { | ||
| query: { | ||
| date_start: dateStart, | ||
| date_end: dateEnd, | ||
| filter: getFilter(filter), | ||
| per_page: perPage, | ||
| // Need to add the + 1 for pages because APIs are 1 indexed, | ||
| // whereas data grid sorts are 0 indexed. | ||
| page: page + 1, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably worth adding a comment explaining why we have to add 1 - honestly, I don't know why the API works this way when it just subtracts |
||
| sort: sortField.length ? JSON.stringify(sortField) : undefined, | ||
| }, | ||
| } | ||
| ); | ||
|
|
||
| return rewriteBodyRes(result); | ||
| }; | ||
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.
Uh oh!
There was an error while loading. Please reload this page.