[ML] AIOPs: Fixing log pattern analysis sparklines and chart (#168337)

Fixing two issues with the log pattern analysis charts:

Occasionally the count of docs in a category can be slightly greater
than the doc count which causes the chart to render negative values when
hovering over a category in the table.

Broken:

![image](0559c060-4bf3-406a-a9be-88eef8942585)

Fixed:

![image](52b3a0ed-66a6-45f9-ae79-e75afa2728c1)


---

The sparkles were incorrectly not subtracting the difference from the
doc count. So they always rendered the pattern count on top of the doc
count.

Broken:

![image](81dc7d83-5cbe-4576-b087-7fff078dfee7)

Fixed:

![image](0f00609f-932c-4fab-b946-58aa5ea34bd8)
This commit is contained in:
James Gowdy 2023-10-09 15:28:28 +01:00 committed by GitHub
parent c2e5ea5502
commit b5bf4a186c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 9 deletions

View file

@ -135,12 +135,18 @@ export const CategoryTable: FC<Props> = ({
if (sparkLine === undefined) {
return null;
}
const histogram = eventRate.map((e) => ({
doc_count_overall: e.docCount,
doc_count_significant_term: sparkLine[e.key],
key: e.key,
key_as_string: `${e.key}`,
}));
const histogram = eventRate.map(({ key: catKey, docCount }) => {
const term = sparkLine[catKey] ?? 0;
const newTerm = term > docCount ? docCount : term;
const adjustedDocCount = docCount - newTerm;
return {
doc_count_overall: adjustedDocCount,
doc_count_significant_term: newTerm,
key: catKey,
key_as_string: `${catKey}`,
};
});
return (
<MiniHistogram

View file

@ -49,8 +49,10 @@ export const DocumentCountChart: FC<Props> = ({
return eventRate.map(({ key, docCount }) => {
let value = docCount;
if (category && sparkLines[category.key] && sparkLines[category.key][key]) {
value -= sparkLines[category.key][key];
const val = sparkLines[category.key][key];
value = val > docCount ? 0 : docCount - val;
}
return { time: key, value };
});
}, [eventRate, pinnedCategory, selectedCategory, sparkLines]);
@ -58,11 +60,13 @@ export const DocumentCountChart: FC<Props> = ({
const chartPointsSplit = useMemo(() => {
const category = selectedCategory ?? pinnedCategory ?? null;
return category !== null
? eventRate.map(({ key }) => {
const value =
? eventRate.map(({ key, docCount }) => {
const val =
sparkLines && sparkLines[category.key] && sparkLines[category.key][key]
? sparkLines[category.key][key]
: 0;
const value = val > docCount ? docCount : val;
return { time: key, value };
})
: undefined;