-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ML] Explain log rate spikes: Page setup (#132121)
Builds out UI/code boilerplate necessary before we start implementing the feature's own UI on a dedicated page. - Updates navigation to bring up data view/saved search selection before moving on to the explain log spike rates page. The bar chart race demo page was moved to the aiops/single_endpoint_streaming_demo url. It is kept in this PR so we have two different pages + API endpoints that use streaming. With this still in place it's easier to update the streaming code to be more generic and reusable. - The url/page aiops/explain_log_rate_spikes has been added with some dummy request that slowly streams a data view's fields to the client. This page will host the actual UI to be brought over from the PoC in follow ups to this PR. - The structure to embed aiops plugin pages in the ml plugin has been simplified. Instead of a lot of custom code to load the components at runtime in the aiops plugin itself, this now uses React lazy loading with Suspense, similar to how we load Vega charts in other places. We no longer initialize the aiops client side code during startup of the plugin itself and augment it, instead we statically import components and pass on props/contexts from the ml plugin. - The code to handle streaming chunks on the client side in stream_fetch.ts/use_stream_fetch_reducer.ts has been improved to make better use of TS generics so for a given API endpoint it's able to return the appropriate coresponding return data type and only allows to use the supported reducer actions for that endpoint. Buffering client side actions has been tweaked to handle state updates more quickly if updates from the server are stalling.
- Loading branch information
Showing
46 changed files
with
1,203 additions
and
481 deletions.
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
34 changes: 34 additions & 0 deletions
34
x-pack/plugins/aiops/common/api/explain_log_rate_spikes.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,34 @@ | ||
/* | ||
* 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 { schema, TypeOf } from '@kbn/config-schema'; | ||
|
||
export const aiopsExplainLogRateSpikesSchema = schema.object({ | ||
/** The index to query for log rate spikes */ | ||
index: schema.string(), | ||
}); | ||
|
||
export type AiopsExplainLogRateSpikesSchema = TypeOf<typeof aiopsExplainLogRateSpikesSchema>; | ||
|
||
export const API_ACTION_NAME = { | ||
ADD_FIELDS: 'add_fields', | ||
} as const; | ||
export type ApiActionName = typeof API_ACTION_NAME[keyof typeof API_ACTION_NAME]; | ||
|
||
interface ApiActionAddFields { | ||
type: typeof API_ACTION_NAME.ADD_FIELDS; | ||
payload: string[]; | ||
} | ||
|
||
export function addFieldsAction(payload: string[]): ApiActionAddFields { | ||
return { | ||
type: API_ACTION_NAME.ADD_FIELDS, | ||
payload, | ||
}; | ||
} | ||
|
||
export type AiopsExplainLogRateSpikesApiAction = ApiActionAddFields; |
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
34 changes: 0 additions & 34 deletions
34
x-pack/plugins/aiops/public/components/explain_log_rate_spikes.tsx
This file was deleted.
Oops, something went wrong.
49 changes: 49 additions & 0 deletions
49
x-pack/plugins/aiops/public/components/explain_log_rate_spikes/explain_log_rate_spikes.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,49 @@ | ||
/* | ||
* 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 React, { useEffect, FC } from 'react'; | ||
|
||
import { EuiBadge, EuiSpacer, EuiText } from '@elastic/eui'; | ||
|
||
import type { DataView } from '@kbn/data-views-plugin/public'; | ||
|
||
import { useStreamFetchReducer } from '../../hooks/use_stream_fetch_reducer'; | ||
|
||
import { initialState, streamReducer } from './stream_reducer'; | ||
|
||
/** | ||
* ExplainLogRateSpikes props require a data view. | ||
*/ | ||
export interface ExplainLogRateSpikesProps { | ||
/** The data view to analyze. */ | ||
dataView: DataView; | ||
} | ||
|
||
export const ExplainLogRateSpikes: FC<ExplainLogRateSpikesProps> = ({ dataView }) => { | ||
const { start, data, isRunning } = useStreamFetchReducer( | ||
'/internal/aiops/explain_log_rate_spikes', | ||
streamReducer, | ||
initialState, | ||
{ index: dataView.title } | ||
); | ||
|
||
useEffect(() => { | ||
start(); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
||
return ( | ||
<EuiText> | ||
<h2>{dataView.title}</h2> | ||
<p>{isRunning ? 'Loading fields ...' : 'Loaded all fields.'}</p> | ||
<EuiSpacer size="xs" /> | ||
{data.fields.map((field) => ( | ||
<EuiBadge>{field}</EuiBadge> | ||
))} | ||
</EuiText> | ||
); | ||
}; |
13 changes: 13 additions & 0 deletions
13
x-pack/plugins/aiops/public/components/explain_log_rate_spikes/index.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,13 @@ | ||
/* | ||
* 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 type { ExplainLogRateSpikesProps } from './explain_log_rate_spikes'; | ||
import { ExplainLogRateSpikes } from './explain_log_rate_spikes'; | ||
|
||
// required for dynamic import using React.lazy() | ||
// eslint-disable-next-line import/no-default-export | ||
export default ExplainLogRateSpikes; |
Oops, something went wrong.