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

[ML] AIOps Log Rate Analysis: improve explanation of log rate spike/dip #186342

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,11 @@ export const LogRateAnalysisResults: FC<LogRateAnalysisResultsProps> = ({
);
const [shouldStart, setShouldStart] = useState(false);
const [toggleIdSelected, setToggleIdSelected] = useState(resultsGroupedOffId);
const [skippedColumns, setSkippedColumns] = useState<ColumnNames[]>(['p-value']);
const [skippedColumns, setSkippedColumns] = useState<ColumnNames[]>([
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to the changes in this PR, but I think it would be a nice enhancement to persist the user's choice of selected columns to e.g. local storage. I found myself adding in Baseline and Deviation rates for display every time I reran an analysis.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added as an item to #181111.

'p-value',
'Baseline rate',
Copy link
Contributor

@peteharverson peteharverson Jun 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alvarezmelissa87 @walterra what do you think about showing the Baseline and Deviation rate columns by default, and hiding the Doc count? I like to see these columns in combination with the 'Log rate change' column. Although in the grouped view, Doc count makes sense as the new columns don't have values.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 I think that could work but we'd need all 3 showing up since the groups table and expanded row hare the same column controls. Might need to think about it a bit more if we want to make them independent.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to leave it as it is, with baseline and deviation rate hidden by default. The more I think about it, the less I like the idea of adding two extra numeric columns into the table in the default view.

'Deviation rate',
]);

const onGroupResultsToggle = (optionId: string) => {
setToggleIdSelected(optionId);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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 { i18n } from '@kbn/i18n';
import { LOG_RATE_ANALYSIS_TYPE } from '@kbn/aiops-log-rate-analysis';

export function getLogRateChange(
analysisType: typeof LOG_RATE_ANALYSIS_TYPE[keyof typeof LOG_RATE_ANALYSIS_TYPE],
baselineBucketRate: number,
deviationBucketRate: number
) {
const logRateChange =
baselineBucketRate > 0
? analysisType === LOG_RATE_ANALYSIS_TYPE.SPIKE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our style guide recommends not doing nested ternaries. I'd suggest just using if/else in this function and return early if something matches.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in ff861eb

? `${Math.round((deviationBucketRate / baselineBucketRate) * 100) / 100}x higher`
: `${Math.round((baselineBucketRate / deviationBucketRate) * 100) / 100}x lower`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guess we also need to add i18n to those strings.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use https://github.com/elastic/kibana/blob/main/x-pack/plugins/ml/common/util/metric_change_description.ts for these, as used for the anomalies table? That will use 'More than 100x higher' if the factor is > 100, which is probably appropriate to use here too? Or if you can't call that same code, then use the same rules around precision so that e.g. x14.23 higher becomes x14 higher.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to round and to add localization in ff861eb

: analysisType === LOG_RATE_ANALYSIS_TYPE.SPIKE
? i18n.translate(
'xpack.aiops.logRateAnalysis.resultsTableGroups.logRateIncreaseLabelColumnTooltip',
{
defaultMessage: '{deviationBucketRate} docs from 0 in baseline',
values: { deviationBucketRate },
}
)
: i18n.translate(
'xpack.aiops.logRateAnalysis.resultsTableGroups.logRateDecreaseLabelColumnTooltip',
{
defaultMessage: '0 docs from ${baselineBucketRate} in baseline',
peteharverson marked this conversation as resolved.
Show resolved Hide resolved
values: { baselineBucketRate },
}
);

return logRateChange;
}

export function getBaselineAndDeviationRates(
baselineBuckets: number,
deviationBuckets: number,
docCount: number | undefined,
bgCount: number | undefined
) {
let baselineBucketRate;
let deviationBucketRate;

if (bgCount !== undefined) {
baselineBucketRate = Math.round(bgCount / baselineBuckets);
}

if (docCount !== undefined) {
deviationBucketRate = Math.round(docCount / deviationBuckets);
}

return { baselineBucketRate, deviationBucketRate };
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ export const LogRateAnalysisResultsTable: FC<LogRateAnalysisResultsTableProps> =
const selectedSignificantItem = useAppSelector(
(s) => s.logRateAnalysisTableRow.selectedSignificantItem
);
const {
analysisType,
windowParameters,
documentStats: { documentCountStats },
} = useAppSelector((s) => s.logRateAnalysis);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since useColumns is a hook, you could move this inside the hook itself so doesn't need to get passed on as arguments to useColumns.


const dispatch = useAppDispatch();

Expand All @@ -97,6 +102,9 @@ export const LogRateAnalysisResultsTable: FC<LogRateAnalysisResultsTableProps> =

const columns = useColumns(
LOG_RATE_ANALYSIS_RESULTS_TABLE_TYPE.SIGNIFICANT_ITEMS,
analysisType,
windowParameters,
documentCountStats?.interval ?? 0,
skippedColumns,
searchQuery,
barColorOverride,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ export const LogRateAnalysisResultsGroupsTable: FC<LogRateAnalysisResultsTablePr

const pinnedGroup = useAppSelector((s) => s.logRateAnalysisTableRow.pinnedGroup);
const selectedGroup = useAppSelector((s) => s.logRateAnalysisTableRow.selectedGroup);
const {
analysisType,
windowParameters,
documentStats: { documentCountStats },
} = useAppSelector((s) => s.logRateAnalysis);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since useColumns is a hook, you could move this inside the hook itself so doesn't need to get passed on as arguments to useColumns.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch - moved in ff861eb

const dispatch = useAppDispatch();
const isMounted = useMountedState();

Expand Down Expand Up @@ -149,6 +154,7 @@ export const LogRateAnalysisResultsGroupsTable: FC<LogRateAnalysisResultsTablePr
{
'data-test-subj': 'aiopsLogRateAnalysisResultsGroupsTableColumnGroup',
field: 'group',
width: skippedColumns.length < 3 ? '34%' : '50%',
name: (
<>
<FormattedMessage
Expand Down Expand Up @@ -238,6 +244,9 @@ export const LogRateAnalysisResultsGroupsTable: FC<LogRateAnalysisResultsTablePr

const columns = useColumns(
LOG_RATE_ANALYSIS_RESULTS_TABLE_TYPE.GROUPS,
analysisType,
windowParameters,
documentCountStats?.interval ?? 0,
skippedColumns,
searchQuery,
barColorOverride,
Expand Down
Loading