Skip to content

Commit

Permalink
[ML] AIOps Log Rate Analysis: improve explanation of log rate spike/d…
Browse files Browse the repository at this point in the history
…ip (#186342)

## Summary

Related issue: #182714

This PR adds a `Log rate change` column to Log rate analysis results
table.

The log rate change is calculated by getting the number of buckets for
baseline/deviation using the timerange and interval and then comparing
the average rates per bucket for baseline vs deviation.

<img width="1466" alt="image"
src="https://github.com/elastic/kibana/assets/6446462/9b2f1b80-d1d5-407e-908c-f611e54be4f3">

<img width="1471" alt="image"
src="https://github.com/elastic/kibana/assets/6446462/56cb2c35-3758-4b24-9f50-2f99242af1b3">



### Checklist

Delete any items that are not applicable to this PR.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [ ] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [ ] Any UI touched in this PR does not create any new axe failures
(run axe in browser:
[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),
[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))
- [ ] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
alvarezmelissa87 and kibanamachine committed Jun 24, 2024
1 parent 1cbe34b commit 702442d
Show file tree
Hide file tree
Showing 8 changed files with 353 additions and 13 deletions.
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[]>([
'p-value',
'Baseline rate',
'Deviation rate',
]);

const onGroupResultsToggle = (optionId: string) => {
setToggleIdSelected(optionId);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* 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
) {
let message;
let factor;

if (analysisType === LOG_RATE_ANALYSIS_TYPE.SPIKE) {
if (baselineBucketRate > 0) {
factor = Math.round(((deviationBucketRate / baselineBucketRate) * 100) / 100);
message = i18n.translate(
'xpack.aiops.logRateAnalysis.resultsTableGroups.logRateFactorIncreaseLabel',
{
defaultMessage: '{factor}x higher',
values: {
factor,
},
}
);
} else {
message = i18n.translate(
'xpack.aiops.logRateAnalysis.resultsTableGroups.logRateDocIncreaseLabel',
{
defaultMessage:
'{deviationBucketRate} {deviationBucketRate, plural, one {doc} other {docs}} rate up from 0 in baseline',
values: { deviationBucketRate },
}
);
}
} else {
if (deviationBucketRate > 0) {
// For dip, "doc count" refers to the amount of documents in the baseline time range so we use baselineBucketRate
factor = Math.round(((baselineBucketRate / deviationBucketRate) * 100) / 100);
message = i18n.translate(
'xpack.aiops.logRateAnalysis.resultsTableGroups.logRateFactorDecreaseLabel',
{
defaultMessage: '{factor}x lower',
values: {
factor,
},
}
);
} else {
message = i18n.translate(
'xpack.aiops.logRateAnalysis.resultsTableGroups.logRateDocDecreaseLabel',
{
defaultMessage: 'docs rate down to 0 from {baselineBucketRate} in baseline',
values: { baselineBucketRate },
}
);
}
}

return { message, factor };
}

export function getBaselineAndDeviationRates(
analysisType: typeof LOG_RATE_ANALYSIS_TYPE[keyof typeof LOG_RATE_ANALYSIS_TYPE],
baselineBuckets: number,
deviationBuckets: number,
docCount: number | undefined,
bgCount: number | undefined
) {
let baselineBucketRate;
let deviationBucketRate;
if (analysisType === LOG_RATE_ANALYSIS_TYPE.SPIKE) {
if (bgCount !== undefined) {
baselineBucketRate = Math.round(bgCount / baselineBuckets);
}

if (docCount !== undefined) {
deviationBucketRate = Math.round(docCount / deviationBuckets);
}
} else {
// For dip, the "doc count" refers to the amount of documents in the baseline time range so we set baselineBucketRate
if (docCount !== undefined) {
baselineBucketRate = Math.round(docCount / baselineBuckets);
}

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

return { baselineBucketRate, deviationBucketRate };
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export const LogRateAnalysisResultsGroupsTable: FC<LogRateAnalysisResultsTablePr
{
'data-test-subj': 'aiopsLogRateAnalysisResultsGroupsTableColumnGroup',
field: 'group',
width: skippedColumns.length < 3 ? '34%' : '50%',
name: (
<>
<FormattedMessage
Expand Down
Loading

0 comments on commit 702442d

Please sign in to comment.