-
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.
[LogsUI] Add analysis results screen (#43471)
* Add empty analysis tab * Add ml capabilities check * Add job status checking functionality * Add a loading page for the job status check * Change types / change method for deriving space ID / change setup requirement filtering check * Use new structure * Add a loading page * Initial timeRange URL state hookup * Hook up params to data fetching * Fleshing out EUI structure * Change tab syntax * i18n translate message prop * Fix import * Add structural visual components * Split section in to independent component * Real loading and no data states * Add initial chart rendering (WIP) * Tick formatting for x axis * Add series styling, tickFormatter etc * Base bucketDuration on time range for a sensible number of data points (naieve version) * Add auto refresh * Adjust bucketDuration algorithm * Add some dark theme support * Call the functions * Extract chart helpers * Amend io-ts types * i18n translations * Add types for graph data * Allow ability to toggle model bounds * Add anomaly series * Format date correctly * Add anomalies detected text * Simplify syntax * Update title * Render panel within a page * Add ability to switch between chart and table view * Fix typechecking errors * Add a Beta badge to the analysis tab
- Loading branch information
Showing
14 changed files
with
824 additions
and
18 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
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
71 changes: 71 additions & 0 deletions
71
...gins/infra/public/containers/logs/log_analysis/log_analysis_graph_data/log_entry_rate.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,71 @@ | ||
/* | ||
* 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 { useMemo } from 'react'; | ||
import { GetLogEntryRateSuccessResponsePayload } from '../../../../../common/http_api/log_analysis'; | ||
|
||
interface LogRateAreaSeriesDataPoint { | ||
x: number; | ||
min: number | null; | ||
max: number | null; | ||
} | ||
type LogRateAreaSeries = LogRateAreaSeriesDataPoint[]; | ||
type LogRateLineSeriesDataPoint = [number, number | null]; | ||
type LogRateLineSeries = LogRateLineSeriesDataPoint[]; | ||
type LogRateAnomalySeriesDataPoint = [number, number]; | ||
type LogRateAnomalySeries = LogRateAnomalySeriesDataPoint[]; | ||
|
||
export const useLogEntryRateGraphData = ({ | ||
data, | ||
}: { | ||
data: GetLogEntryRateSuccessResponsePayload['data'] | null; | ||
}) => { | ||
const areaSeries: LogRateAreaSeries = useMemo(() => { | ||
if (!data || (data && data.histogramBuckets && !data.histogramBuckets.length)) { | ||
return []; | ||
} | ||
return data.histogramBuckets.reduce((acc: any, bucket) => { | ||
acc.push({ | ||
x: bucket.startTime, | ||
min: bucket.modelLowerBoundStats.min, | ||
max: bucket.modelUpperBoundStats.max, | ||
}); | ||
return acc; | ||
}, []); | ||
}, [data]); | ||
|
||
const lineSeries: LogRateLineSeries = useMemo(() => { | ||
if (!data || (data && data.histogramBuckets && !data.histogramBuckets.length)) { | ||
return []; | ||
} | ||
return data.histogramBuckets.reduce((acc: any, bucket) => { | ||
acc.push([bucket.startTime, bucket.logEntryRateStats.avg]); | ||
return acc; | ||
}, []); | ||
}, [data]); | ||
|
||
const anomalySeries: LogRateAnomalySeries = useMemo(() => { | ||
if (!data || (data && data.histogramBuckets && !data.histogramBuckets.length)) { | ||
return []; | ||
} | ||
return data.histogramBuckets.reduce((acc: any, bucket) => { | ||
if (bucket.anomalies.length > 0) { | ||
bucket.anomalies.forEach(anomaly => { | ||
acc.push([anomaly.startTime, anomaly.actualLogEntryRate]); | ||
}); | ||
return acc; | ||
} else { | ||
return acc; | ||
} | ||
}, []); | ||
}, [data]); | ||
|
||
return { | ||
areaSeries, | ||
lineSeries, | ||
anomalySeries, | ||
}; | ||
}; |
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
54 changes: 54 additions & 0 deletions
54
...gacy/plugins/infra/public/containers/logs/log_analysis/log_analysis_results_url_state.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,54 @@ | ||
/* | ||
* 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 moment from 'moment'; | ||
import { useEffect } from 'react'; | ||
import * as rt from 'io-ts'; | ||
import { useUrlState } from '../../../utils/use_url_state'; | ||
import { timeRangeRT } from '../../../../common/http_api/shared/time_range'; | ||
|
||
const autoRefreshRT = rt.union([rt.boolean, rt.undefined]); | ||
const urlTimeRangeRT = rt.union([timeRangeRT, rt.undefined]); | ||
|
||
const TIME_RANGE_URL_STATE_KEY = 'timeRange'; | ||
const AUTOREFRESH_URL_STATE_KEY = 'autoRefresh'; | ||
|
||
export const useLogAnalysisResultsUrlState = () => { | ||
const [timeRange, setTimeRange] = useUrlState({ | ||
defaultState: { | ||
startTime: moment | ||
.utc() | ||
.subtract(2, 'weeks') | ||
.valueOf(), | ||
endTime: moment.utc().valueOf(), | ||
}, | ||
decodeUrlState: (value: unknown) => urlTimeRangeRT.decode(value).getOrElse(undefined), | ||
encodeUrlState: urlTimeRangeRT.encode, | ||
urlStateKey: TIME_RANGE_URL_STATE_KEY, | ||
}); | ||
|
||
useEffect(() => { | ||
setTimeRange(timeRange); | ||
}, []); | ||
|
||
const [autoRefreshEnabled, setAutoRefresh] = useUrlState({ | ||
defaultState: false, | ||
decodeUrlState: (value: unknown) => autoRefreshRT.decode(value).getOrElse(undefined), | ||
encodeUrlState: autoRefreshRT.encode, | ||
urlStateKey: AUTOREFRESH_URL_STATE_KEY, | ||
}); | ||
|
||
useEffect(() => { | ||
setAutoRefresh(autoRefreshEnabled); | ||
}, []); | ||
|
||
return { | ||
timeRange, | ||
setTimeRange, | ||
autoRefreshEnabled, | ||
setAutoRefresh, | ||
}; | ||
}; |
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
20 changes: 20 additions & 0 deletions
20
x-pack/legacy/plugins/infra/public/pages/logs/analysis/chart_helpers/index.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,20 @@ | ||
/* | ||
* 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 chrome from 'ui/chrome'; | ||
import { SpecId, Theme, LIGHT_THEME, DARK_THEME } from '@elastic/charts'; | ||
|
||
export const getColorsMap = (color: string, specId: SpecId) => { | ||
const map = new Map(); | ||
map.set({ colorValues: [], specId }, color); | ||
return map; | ||
}; | ||
|
||
export const isDarkMode = () => chrome.getUiSettingsClient().get('theme:darkMode'); | ||
|
||
export const getChartTheme = (): Theme => { | ||
return isDarkMode() ? DARK_THEME : LIGHT_THEME; | ||
}; |
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.