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

[Logs UI] Add expandable rows with category examples #54586

Merged
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
298d547
Add category examples route
weltenwort Jan 9, 2020
59b37bc
Show examples in category table row expansions
weltenwort Jan 10, 2020
7d58cd2
Use `transport.request` fallback to query ml jobs
weltenwort Feb 3, 2020
fc75abf
Prepare log rows and columns for re-use
weltenwort Feb 4, 2020
a751fd9
Render example message using log stream components
weltenwort Feb 4, 2020
ba2b552
Introduce a stricter wrapping mode for the examples
weltenwort Feb 4, 2020
551df33
Add example loading indicators
weltenwort Feb 4, 2020
2645faf
Add example loading failure message with retry option
weltenwort Feb 4, 2020
eaceb39
Remove mismatching log message background color
weltenwort Feb 5, 2020
687bdfb
Merge branch 'master' into logs-ui-categorization-add-examples
weltenwort Feb 6, 2020
75e4f4c
Add dataset column to examples and align columns
weltenwort Feb 11, 2020
e82cc54
Merge branch 'master' into logs-ui-categorization-add-examples
weltenwort Feb 11, 2020
b668695
Merge branch 'master' into logs-ui-categorization-add-examples
weltenwort Feb 11, 2020
704e123
Remove unused translations via autofix
weltenwort Feb 11, 2020
3074c48
Merge branch 'master' into logs-ui-categorization-add-examples
weltenwort Feb 28, 2020
40bbbac
Merge branch 'master' into logs-ui-categorization-add-examples
weltenwort Mar 2, 2020
422dfea
Display per-dataset anomaly scores and ML links
weltenwort Mar 3, 2020
182098d
Adjust dataset column width in example rows
weltenwort Mar 3, 2020
55db708
Add message for empty example response
weltenwort Mar 3, 2020
ff6521e
Merge branch 'master' into logs-ui-categorization-add-examples
weltenwort Mar 3, 2020
6e23015
Merge branch 'master' into logs-ui-categorization-add-examples
elasticmachine Mar 5, 2020
38c6e42
Merge branch 'master' into logs-ui-categorization-add-examples
elasticmachine Mar 5, 2020
0544202
Merge branch 'master' into logs-ui-categorization-add-examples
weltenwort Mar 9, 2020
3e818cd
Merge branch 'master' into logs-ui-categorization-add-examples
weltenwort Mar 11, 2020
aea5ece
Use new link helper hook for dataset ml link
weltenwort Mar 11, 2020
e283dc8
Correctly read dataset from sample message documents
weltenwort Mar 11, 2020
1b0e3ee
Rename 'original' to 'pre-wrapped' wrap mode
weltenwort Mar 11, 2020
f52e407
Merge branch 'master' into logs-ui-categorization-add-examples
elasticmachine Mar 11, 2020
90cbc6f
Merge branch 'master' into logs-ui-categorization-add-examples
elasticmachine Mar 11, 2020
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 @@ -6,4 +6,5 @@

export * from './log_entry_categories';
export * from './log_entry_category_datasets';
export * from './log_entry_category_examples';
export * from './log_entry_rate';
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,16 @@ export const logEntryCategoryHistogramRT = rt.type({

export type LogEntryCategoryHistogram = rt.TypeOf<typeof logEntryCategoryHistogramRT>;

export const logEntryCategoryDatasetRT = rt.type({
name: rt.string,
maximumAnomalyScore: rt.number,
});

export type LogEntryCategoryDataset = rt.TypeOf<typeof logEntryCategoryDatasetRT>;

export const logEntryCategoryRT = rt.type({
categoryId: rt.number,
datasets: rt.array(rt.string),
datasets: rt.array(logEntryCategoryDatasetRT),
histograms: rt.array(logEntryCategoryHistogramRT),
logEntryCount: rt.number,
maximumAnomalyScore: rt.number,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* 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';

import {
badRequestErrorRT,
forbiddenErrorRT,
timeRangeRT,
routeTimingMetadataRT,
} from '../../shared';

export const LOG_ANALYSIS_GET_LOG_ENTRY_CATEGORY_EXAMPLES_PATH =
'/api/infra/log_analysis/results/log_entry_category_examples';

/**
* request
*/

export const getLogEntryCategoryExamplesRequestPayloadRT = rt.type({
data: rt.type({
// the category to fetch the examples for
categoryId: rt.number,
// the number of examples to fetch
exampleCount: rt.number,
// the id of the source configuration
sourceId: rt.string,
// the time range to fetch the category examples from
timeRange: timeRangeRT,
}),
});

export type GetLogEntryCategoryExamplesRequestPayload = rt.TypeOf<
typeof getLogEntryCategoryExamplesRequestPayloadRT
>;

/**
* response
*/

const logEntryCategoryExampleRT = rt.type({
dataset: rt.string,
message: rt.string,
timestamp: rt.number,
});

export type LogEntryCategoryExample = rt.TypeOf<typeof logEntryCategoryExampleRT>;

export const getLogEntryCategoryExamplesSuccessReponsePayloadRT = rt.intersection([
rt.type({
data: rt.type({
examples: rt.array(logEntryCategoryExampleRT),
}),
}),
rt.partial({
timing: routeTimingMetadataRT,
}),
]);

export type GetLogEntryCategoryExamplesSuccessResponsePayload = rt.TypeOf<
typeof getLogEntryCategoryExamplesSuccessReponsePayloadRT
>;

export const getLogEntryCategoryExamplesResponsePayloadRT = rt.union([
getLogEntryCategoryExamplesSuccessReponsePayloadRT,
badRequestErrorRT,
forbiddenErrorRT,
]);

export type GetLogEntryCategoryExamplesReponsePayload = rt.TypeOf<
typeof getLogEntryCategoryExamplesResponsePayloadRT
>;
7 changes: 7 additions & 0 deletions x-pack/plugins/infra/common/log_analysis/job_parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,10 @@ export const jobSourceConfigurationRT = rt.type({
});

export type JobSourceConfiguration = rt.TypeOf<typeof jobSourceConfigurationRT>;

export const jobCustomSettingsRT = rt.partial({
job_revision: rt.number,
logs_source_config: rt.partial(jobSourceConfigurationRT.props),
});

export type JobCustomSettings = rt.TypeOf<typeof jobCustomSettingsRT>;
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,10 @@ export const formatAnomalyScore = (score: number) => {
export const getFriendlyNameForPartitionId = (partitionId: string) => {
return partitionId !== '' ? partitionId : 'unknown';
};

export const compareDatasetsByMaximumAnomalyScore = <
Dataset extends { maximumAnomalyScore: number }
>(
firstDataset: Dataset,
secondDataset: Dataset
) => firstDataset.maximumAnomalyScore - secondDataset.maximumAnomalyScore;
7 changes: 7 additions & 0 deletions x-pack/plugins/infra/public/components/basic_table/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* 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.
*/

export * from './row_expansion_button';
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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 { EuiButtonIcon } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import React, { useCallback } from 'react';

export const RowExpansionButton = <Item extends any>({
isExpanded,
item,
onCollapse,
onExpand,
}: {
isExpanded: boolean;
item: Item;
onCollapse: (item: Item) => void;
onExpand: (item: Item) => void;
}) => {
const handleClick = useCallback(() => (isExpanded ? onCollapse(item) : onExpand(item)), [
isExpanded,
item,
onCollapse,
onExpand,
]);

return (
<EuiButtonIcon
onClick={handleClick}
aria-label={isExpanded ? collapseAriaLabel : expandAriaLabel}
iconType={isExpanded ? 'arrowUp' : 'arrowDown'}
/>
);
};

const collapseAriaLabel = i18n.translate('xpack.infra.table.collapseRowLabel', {
defaultMessage: 'Collapse',
});

const expandAriaLabel = i18n.translate('xpack.infra.table.expandRowLabel', {
defaultMessage: 'Expand',
});
4 changes: 3 additions & 1 deletion x-pack/plugins/infra/public/components/formatted_time.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ const getFormattedTime = (
return userFormat ? moment(time).format(userFormat) : moment(time).format(fallbackFormat);
};

export type TimeFormat = 'dateTime' | 'time';

interface UseFormattedTimeOptions {
format?: 'dateTime' | 'time';
format?: TimeFormat;
fallbackFormat?: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export const AnalyzeInMlButton: React.FunctionComponent<{
<EuiButton
fill={false}
size="s"
href={getPartitionSpecificSingleMetricViewerLink(pathname, jobId, partition, timeRange)}
href={getEntitySpecificSingleMetricViewerLink(pathname, jobId, timeRange, {
'event.dataset': partition,
})}
>
{buttonLabel}
</EuiButton>
Expand Down Expand Up @@ -70,11 +72,11 @@ const getOverallAnomalyExplorerLink = (pathname: string, jobId: string, timeRang
});
};

const getPartitionSpecificSingleMetricViewerLink = (
export const getEntitySpecificSingleMetricViewerLink = (
pathname: string,
jobId: string,
partition: string,
timeRange: TimeRange
timeRange: TimeRange,
entities: Record<string, string>
) => {
const { from, to } = convertTimeRangeToParams(timeRange);

Expand All @@ -91,7 +93,7 @@ const getPartitionSpecificSingleMetricViewerLink = (

const _a = encode({
mlTimeSeriesExplorer: {
entities: { 'event.dataset': partition },
entities,
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

export { LogEntryColumn, LogEntryColumnWidths, useColumnWidths } from './log_entry_column';
export { LogEntryFieldColumn } from './log_entry_field_column';
export { LogEntryMessageColumn } from './log_entry_message_column';
export { LogEntryRowWrapper } from './log_entry_row';
export { LogEntryTimestampColumn } from './log_entry_timestamp_column';
export { ScrollableLogTextStreamView } from './scrollable_log_text_stream_view';
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { useMemo } from 'react';

import { euiStyled } from '../../../../../observability/public';
import { TextScale } from '../../../../common/log_text_scale';
import {
LogColumnConfiguration,
isMessageLogColumnConfiguration,
isTimestampLogColumnConfiguration,
LogColumnConfiguration,
} from '../../../utils/source_configuration';
import { useFormattedTime, TimeFormat } from '../../formatted_time';
import { useMeasuredCharacterDimensions } from './text_styles';

const DATE_COLUMN_SLACK_FACTOR = 1.1;
const FIELD_COLUMN_MIN_WIDTH_CHARACTERS = 10;
Expand Down Expand Up @@ -100,3 +105,33 @@ export const getColumnWidths = (
},
}
);

/**
* This hook calculates the column widths based on the given configuration. It
* depends on the `CharacterDimensionsProbe` it returns being rendered so it can
* measure the monospace character size.
*/
export const useColumnWidths = ({
columnConfigurations,
scale,
timeFormat = 'time',
}: {
columnConfigurations: LogColumnConfiguration[];
scale: TextScale;
timeFormat?: TimeFormat;
}) => {
const { CharacterDimensionsProbe, dimensions } = useMeasuredCharacterDimensions(scale);
const referenceTime = useMemo(() => Date.now(), []);
const formattedCurrentDate = useFormattedTime(referenceTime, { format: timeFormat });
const columnWidths = useMemo(
() => getColumnWidths(columnConfigurations, dimensions.width, formattedCurrentDate.length),
[columnConfigurations, dimensions.width, formattedCurrentDate]
);
return useMemo(
() => ({
columnWidths,
CharacterDimensionsProbe,
}),
[columnWidths, CharacterDimensionsProbe]
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('LogEntryFieldColumn', () => {
isActiveHighlight={false}
isHighlighted={false}
isHovered={false}
isWrapped={false}
wrapMode="original"
/>,
{ wrappingComponent: EuiThemeProvider } as any // https://github.com/DefinitelyTyped/DefinitelyTyped/issues/36075
);
Expand Down Expand Up @@ -58,7 +58,7 @@ describe('LogEntryFieldColumn', () => {
isActiveHighlight={false}
isHighlighted={false}
isHovered={false}
isWrapped={false}
wrapMode="original"
/>,
{ wrappingComponent: EuiThemeProvider } as any // https://github.com/DefinitelyTyped/DefinitelyTyped/issues/36075
);
Expand All @@ -80,7 +80,7 @@ describe('LogEntryFieldColumn', () => {
isActiveHighlight={false}
isHighlighted={false}
isHovered={false}
isWrapped={false}
wrapMode="original"
/>,
{ wrappingComponent: EuiThemeProvider } as any // https://github.com/DefinitelyTyped/DefinitelyTyped/issues/36075
);
Expand Down
Loading