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

[LogsUI] Add analysis results screen #43471

Merged
merged 54 commits into from
Aug 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
de0499e
Add empty analysis tab
weltenwort Aug 8, 2019
8d06a54
Merge branch 'master' into logs-ui-add-analysis-tab
weltenwort Aug 8, 2019
0ba9cca
Add ml capabilities check
weltenwort Aug 8, 2019
84248c2
Add job status checking functionality
Kerry350 Aug 8, 2019
31be96e
Add a loading page for the job status check
Kerry350 Aug 9, 2019
6c0bac5
Change types / change method for deriving space ID / change setup req…
Kerry350 Aug 9, 2019
98a9fa9
Use new structure
Kerry350 Aug 9, 2019
02f926e
Merge remote-tracking branch 'upstream/master' into logs-ui-add-analy…
Kerry350 Aug 12, 2019
c5ea53e
Merge remote-tracking branch 'felix-fork/logs-ui-add-analysis-tab' in…
Kerry350 Aug 12, 2019
823e0b0
Add a loading page
Kerry350 Aug 12, 2019
4547b12
Initial timeRange URL state hookup
Kerry350 Aug 12, 2019
0854d52
Hook up params to data fetching
Kerry350 Aug 12, 2019
c0becdc
Fleshing out EUI structure
Kerry350 Aug 12, 2019
6d98b38
Merge remote-tracking branch 'upstream/master' into logs-ui-add-analy…
Kerry350 Aug 13, 2019
ac15cc0
Change tab syntax
Kerry350 Aug 13, 2019
7aff31c
i18n translate message prop
Kerry350 Aug 13, 2019
0178427
Merge remote-tracking branch 'felix-fork/logs-ui-add-analysis-tab' in…
Kerry350 Aug 13, 2019
5cd5ba4
Fix import
Kerry350 Aug 13, 2019
2778e3a
Merge remote-tracking branch 'felix-fork/logs-ui-add-analysis-tab' in…
Kerry350 Aug 13, 2019
f59b27f
Add structural visual components
Kerry350 Aug 13, 2019
7b3e6a8
Split section in to independent component
Kerry350 Aug 13, 2019
1a31ae5
Real loading and no data states
Kerry350 Aug 13, 2019
163be1e
Add initial chart rendering (WIP)
Kerry350 Aug 13, 2019
526bacf
Merge remote-tracking branch 'upstream/master' into 42771-log-rate-re…
Kerry350 Aug 14, 2019
80ba0c3
Tick formatting for x axis
Kerry350 Aug 14, 2019
e662f48
Merge remote-tracking branch 'upstream/master' into 42771-log-rate-re…
Kerry350 Aug 14, 2019
d046237
Add series styling, tickFormatter etc
Kerry350 Aug 14, 2019
0fc4232
Base bucketDuration on time range for a sensible number of data point…
Kerry350 Aug 14, 2019
e244903
Add auto refresh
Kerry350 Aug 14, 2019
23e0cee
Adjust bucketDuration algorithm
Kerry350 Aug 15, 2019
2fc8486
Add some dark theme support
Kerry350 Aug 15, 2019
368d6fc
Call the functions
Kerry350 Aug 15, 2019
c197b06
Extract chart helpers
Kerry350 Aug 15, 2019
43532b0
Merge remote-tracking branch 'upstream/master' into 42771-log-rate-re…
Kerry350 Aug 15, 2019
a6891f0
Amend io-ts types
Kerry350 Aug 15, 2019
48d237a
i18n translations
Kerry350 Aug 15, 2019
546e537
Add types for graph data
Kerry350 Aug 15, 2019
d914f92
Merge remote-tracking branch 'upstream/master' into 42771-log-rate-re…
Kerry350 Aug 16, 2019
a9f7b3f
Merge remote-tracking branch 'upstream/master' into 42771-log-rate-re…
Kerry350 Aug 16, 2019
a32fa03
Allow ability to toggle model bounds
Kerry350 Aug 16, 2019
47876bf
Add anomaly series
Kerry350 Aug 16, 2019
1f1aab6
Format date correctly
Kerry350 Aug 16, 2019
bb459ac
Add anomalies detected text
Kerry350 Aug 16, 2019
b64992d
Merge remote-tracking branch 'upstream/master' into 42771-log-rate-re…
Kerry350 Aug 19, 2019
7529792
Simplify syntax
Kerry350 Aug 19, 2019
bc0300a
Merge remote-tracking branch 'upstream/master' into 42771-log-rate-re…
Kerry350 Aug 19, 2019
7429cff
Update title
Kerry350 Aug 19, 2019
be69bd6
Render panel within a page
Kerry350 Aug 19, 2019
243c5b8
Merge remote-tracking branch 'upstream/master' into 42771-log-rate-re…
Kerry350 Aug 20, 2019
a4c19d4
Add ability to switch between chart and table view
Kerry350 Aug 20, 2019
e7ccfb9
Merge remote-tracking branch 'upstream/master' into 42771-log-rate-re…
Kerry350 Aug 21, 2019
8c96675
Fix typechecking errors
Kerry350 Aug 21, 2019
a4764d1
Merge remote-tracking branch 'upstream/master' into 42771-log-rate-re…
Kerry350 Aug 22, 2019
2245d82
Add a Beta badge to the analysis tab
Kerry350 Aug 22, 2019
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 @@ -10,7 +10,7 @@ import { Route } from 'react-router-dom';
import euiStyled from '../../../../../common/eui_styled_components';

interface TabConfiguration {
title: string;
title: string | React.ReactNode;
path: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
export * from './log_analysis_capabilities';
export * from './log_analysis_jobs';
export * from './log_analysis_results';
export * from './log_analysis_results_url_state';
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,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,34 @@
*/

import createContainer from 'constate-latest';
import { useMemo } from 'react';
import { useMemo, useEffect } from 'react';

import { useLogEntryRate } from './log_entry_rate';

export const useLogAnalysisResults = ({ sourceId }: { sourceId: string }) => {
const { isLoading: isLoadingLogEntryRate, logEntryRate } = useLogEntryRate({ sourceId });
export const useLogAnalysisResults = ({
sourceId,
startTime,
endTime,
bucketDuration = 15 * 60 * 1000,
}: {
sourceId: string;
startTime: number;
endTime: number;
bucketDuration?: number;
}) => {
const { isLoading: isLoadingLogEntryRate, logEntryRate, getLogEntryRate } = useLogEntryRate({
sourceId,
startTime,
endTime,
bucketDuration,
});

const isLoading = useMemo(() => isLoadingLogEntryRate, [isLoadingLogEntryRate]);

useEffect(() => {
getLogEntryRate();
}, [sourceId, startTime, endTime, bucketDuration]);

return {
isLoading,
logEntryRate,
Expand Down
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,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@ import { useTrackedPromise } from '../../../utils/use_tracked_promise';

type LogEntryRateResults = GetLogEntryRateSuccessResponsePayload['data'];

export const useLogEntryRate = ({ sourceId }: { sourceId: string }) => {
export const useLogEntryRate = ({
sourceId,
startTime,
endTime,
bucketDuration,
}: {
sourceId: string;
startTime: number;
endTime: number;
bucketDuration: number;
}) => {
const [logEntryRate, setLogEntryRate] = useState<LogEntryRateResults | null>(null);

const [getLogEntryRateRequest, getLogEntryRate] = useTrackedPromise(
Expand All @@ -31,12 +41,12 @@ export const useLogEntryRate = ({ sourceId }: { sourceId: string }) => {
body: JSON.stringify(
getLogEntryRateRequestPayloadRT.encode({
data: {
sourceId, // TODO: get from hook arguments
sourceId,
timeRange: {
startTime: Date.now(), // TODO: get from hook arguments
endTime: Date.now() + 1000 * 60 * 60, // TODO: get from hook arguments
startTime,
endTime,
},
bucketDuration: 15 * 60 * 1000, // TODO: get from hook arguments
bucketDuration,
},
})
),
Expand All @@ -50,7 +60,7 @@ export const useLogEntryRate = ({ sourceId }: { sourceId: string }) => {
setLogEntryRate(data);
},
},
[sourceId]
[sourceId, startTime, endTime, bucketDuration]
);

const isLoading = useMemo(() => getLogEntryRateRequest.state === 'pending', [
Expand Down
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;
};
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const AnalysisPage = () => {
) : isSetupRequired ? (
<AnalysisSetupContent />
) : (
<AnalysisResultsContent />
<AnalysisResultsContent sourceId={sourceId} />
)}
</ColumnarPage>
</AnalysisPageProviders>
Expand Down
Loading