Skip to content

Commit

Permalink
[8.x] [Synthetics] Fix issue where heatmap UI crashes on undefined hi…
Browse files Browse the repository at this point in the history
…stogram data (#192508) (#193154)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Synthetics] Fix issue where heatmap UI crashes on undefined
histogram data (#192508)](#192508)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Justin
Kambic","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-09-17T12:08:51Z","message":"[Synthetics]
Fix issue where heatmap UI crashes on undefined histogram data
(#192508)\n\n## Summary\r\n\r\nRecently, [we
fixed](#184177)
an\r\n[issue](#180076) where
the\r\nheatmap data on the detail and monitor history pages would not
fill up.\r\n\r\nA side effect of this fix was a new regression that
caused certain rarer\r\ncases to see the page crash because of an
unhandled case of calling a\r\nfunction on a potentially-null object;
our histogram data used to\r\npopulate this heatmap can be `undefined`
in certain cases.\r\n\r\nThis patch introduces a change that will handle
this case, and adds unit\r\ntests for the module in
question.\r\n\r\n\r\n### Checklist\r\n\r\nDelete any items that are not
applicable to this PR.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] Any UI touched in this PR is
usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [ ] Any UI
touched in this PR does not create any new axe failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[ ] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n\r\n###
Risk Matrix\r\n\r\nDelete this section if it is not applicable to this
PR.\r\n\r\nBefore closing this PR, invite QA, stakeholders, and other
developers to\r\nidentify risks that should be tested prior to the
change/feature\r\nrelease.\r\n\r\nWhen forming the risk matrix, consider
some of the following examples\r\nand how they may potentially impact
the change:\r\n\r\n| Risk | Probability | Severity | Mitigation/Notes
|\r\n\r\n|---------------------------|-------------|----------|-------------------------|\r\n|
Multiple Spaces&mdash;unexpected behavior in non-default Kibana
Space.\r\n| Low | High | Integration tests will verify that all features
are still\r\nsupported in non-default Kibana Space and when user
switches between\r\nspaces. |\r\n| Multiple nodes&mdash;Elasticsearch
polling might have race conditions\r\nwhen multiple Kibana nodes are
polling for the same tasks. | High | Low\r\n| Tasks are idempotent, so
executing them multiple times will not result\r\nin logical error, but
will degrade performance. To test for this case we\r\nadd plenty of unit
tests around this logic and document manual testing\r\nprocedure. |\r\n|
Code should gracefully handle cases when feature X or plugin Y
are\r\ndisabled. | Medium | High | Unit tests will verify that any
feature flag\r\nor plugin combination still results in our service
operational. |\r\n| [See more potential
risk\r\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)
|\r\n\r\n\r\n### For maintainers\r\n\r\n- [ ] This was checked for
breaking API changes and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by:
Shahzad
<[email protected]>","sha":"da2f7f6dae265e29713e5c6586c542499b03bcd6","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:fix","v9.0.0","ci:project-deploy-observability","Team:obs-ux-management","v8.16.0"],"title":"[Synthetics]
Fix issue where heatmap UI crashes on undefined histogram
data","number":192508,"url":"https://github.com/elastic/kibana/pull/192508","mergeCommit":{"message":"[Synthetics]
Fix issue where heatmap UI crashes on undefined histogram data
(#192508)\n\n## Summary\r\n\r\nRecently, [we
fixed](#184177)
an\r\n[issue](#180076) where
the\r\nheatmap data on the detail and monitor history pages would not
fill up.\r\n\r\nA side effect of this fix was a new regression that
caused certain rarer\r\ncases to see the page crash because of an
unhandled case of calling a\r\nfunction on a potentially-null object;
our histogram data used to\r\npopulate this heatmap can be `undefined`
in certain cases.\r\n\r\nThis patch introduces a change that will handle
this case, and adds unit\r\ntests for the module in
question.\r\n\r\n\r\n### Checklist\r\n\r\nDelete any items that are not
applicable to this PR.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] Any UI touched in this PR is
usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [ ] Any UI
touched in this PR does not create any new axe failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[ ] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n\r\n###
Risk Matrix\r\n\r\nDelete this section if it is not applicable to this
PR.\r\n\r\nBefore closing this PR, invite QA, stakeholders, and other
developers to\r\nidentify risks that should be tested prior to the
change/feature\r\nrelease.\r\n\r\nWhen forming the risk matrix, consider
some of the following examples\r\nand how they may potentially impact
the change:\r\n\r\n| Risk | Probability | Severity | Mitigation/Notes
|\r\n\r\n|---------------------------|-------------|----------|-------------------------|\r\n|
Multiple Spaces&mdash;unexpected behavior in non-default Kibana
Space.\r\n| Low | High | Integration tests will verify that all features
are still\r\nsupported in non-default Kibana Space and when user
switches between\r\nspaces. |\r\n| Multiple nodes&mdash;Elasticsearch
polling might have race conditions\r\nwhen multiple Kibana nodes are
polling for the same tasks. | High | Low\r\n| Tasks are idempotent, so
executing them multiple times will not result\r\nin logical error, but
will degrade performance. To test for this case we\r\nadd plenty of unit
tests around this logic and document manual testing\r\nprocedure. |\r\n|
Code should gracefully handle cases when feature X or plugin Y
are\r\ndisabled. | Medium | High | Unit tests will verify that any
feature flag\r\nor plugin combination still results in our service
operational. |\r\n| [See more potential
risk\r\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)
|\r\n\r\n\r\n### For maintainers\r\n\r\n- [ ] This was checked for
breaking API changes and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by:
Shahzad
<[email protected]>","sha":"da2f7f6dae265e29713e5c6586c542499b03bcd6"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/192508","number":192508,"mergeCommit":{"message":"[Synthetics]
Fix issue where heatmap UI crashes on undefined histogram data
(#192508)\n\n## Summary\r\n\r\nRecently, [we
fixed](#184177)
an\r\n[issue](#180076) where
the\r\nheatmap data on the detail and monitor history pages would not
fill up.\r\n\r\nA side effect of this fix was a new regression that
caused certain rarer\r\ncases to see the page crash because of an
unhandled case of calling a\r\nfunction on a potentially-null object;
our histogram data used to\r\npopulate this heatmap can be `undefined`
in certain cases.\r\n\r\nThis patch introduces a change that will handle
this case, and adds unit\r\ntests for the module in
question.\r\n\r\n\r\n### Checklist\r\n\r\nDelete any items that are not
applicable to this PR.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] Any UI touched in this PR is
usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [ ] Any UI
touched in this PR does not create any new axe failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[ ] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n\r\n###
Risk Matrix\r\n\r\nDelete this section if it is not applicable to this
PR.\r\n\r\nBefore closing this PR, invite QA, stakeholders, and other
developers to\r\nidentify risks that should be tested prior to the
change/feature\r\nrelease.\r\n\r\nWhen forming the risk matrix, consider
some of the following examples\r\nand how they may potentially impact
the change:\r\n\r\n| Risk | Probability | Severity | Mitigation/Notes
|\r\n\r\n|---------------------------|-------------|----------|-------------------------|\r\n|
Multiple Spaces&mdash;unexpected behavior in non-default Kibana
Space.\r\n| Low | High | Integration tests will verify that all features
are still\r\nsupported in non-default Kibana Space and when user
switches between\r\nspaces. |\r\n| Multiple nodes&mdash;Elasticsearch
polling might have race conditions\r\nwhen multiple Kibana nodes are
polling for the same tasks. | High | Low\r\n| Tasks are idempotent, so
executing them multiple times will not result\r\nin logical error, but
will degrade performance. To test for this case we\r\nadd plenty of unit
tests around this logic and document manual testing\r\nprocedure. |\r\n|
Code should gracefully handle cases when feature X or plugin Y
are\r\ndisabled. | Medium | High | Unit tests will verify that any
feature flag\r\nor plugin combination still results in our service
operational. |\r\n| [See more potential
risk\r\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)
|\r\n\r\n\r\n### For maintainers\r\n\r\n- [ ] This was checked for
breaking API changes and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by:
Shahzad
<[email protected]>","sha":"da2f7f6dae265e29713e5c6586c542499b03bcd6"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Justin Kambic <[email protected]>
  • Loading branch information
kibanamachine and justinkambic authored Sep 17, 2024
1 parent 146ae69 commit c9c3e89
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* 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 { createStatusTimeBins, getStatusEffectiveValue } from './monitor_status_data';

describe('createStatusTimeBins', () => {
beforeEach(() => {
jest.clearAllMocks();
});

it('should return default values when `heatmapData` is `undefined`', () => {
const timeBuckets = [
{ start: 1000, end: 2000 },
{ start: 2000, end: 3000 },
];

const result = createStatusTimeBins(timeBuckets, undefined);

expect(result).toEqual([
{ start: 1000, end: 2000, ups: 0, downs: 0, value: 0 },
{ start: 2000, end: 3000, ups: 0, downs: 0, value: 0 },
]);
});

it('should calculate `ups` and `downs` correctly from `heatmapData`', () => {
const timeBuckets = [
{ start: 1000, end: 2000 },
{ start: 2000, end: 3000 },
];

const heatmapData = [
{ key: 1500, key_as_string: '1500', up: { value: 1 }, down: { value: 2 }, doc_count: 3 },
{ key: 2500, key_as_string: '2500', up: { value: 3 }, down: { value: 1 }, doc_count: 4 },
];

const result = createStatusTimeBins(timeBuckets, heatmapData);

expect(result).toEqual([
{ start: 1000, end: 2000, ups: 1, downs: 2, value: getStatusEffectiveValue(1, 2) },
{ start: 2000, end: 3000, ups: 3, downs: 1, value: getStatusEffectiveValue(3, 1) },
]);
});

it('should return value 0 when ups + downs is 0', () => {
const timeBuckets = [
{ start: 1000, end: 2000 },
{ start: 2000, end: 3000 },
];

const heatmapData = [
{ key: 1500, key_as_string: '1500', up: { value: 0 }, down: { value: 0 }, doc_count: 0 },
{ key: 2500, key_as_string: '2500', up: { value: 0 }, down: { value: 0 }, doc_count: 0 },
];

const result = createStatusTimeBins(timeBuckets, heatmapData);

expect(result).toEqual([
{ start: 1000, end: 2000, ups: 0, downs: 0, value: 0 },
{ start: 2000, end: 3000, ups: 0, downs: 0, value: 0 },
]);
});

it('should filter heatmapData correctly based on start and end values', () => {
const timeBuckets = [
{ start: 1000, end: 2000 },
{ start: 2000, end: 3000 },
];

const heatmapData = [
{ key: 500, key_as_string: '500', doc_count: 2, up: { value: 1 }, down: { value: 1 } },
{ key: 1500, key_as_string: '1500', doc_count: 5, up: { value: 2 }, down: { value: 3 } },
{ key: 2500, key_as_string: '2500', doc_count: 9, up: { value: 4 }, down: { value: 5 } },
{ key: 3500, key_as_string: '3500', doc_count: 1, up: { value: 6 }, down: { value: 7 } },
];

const result = createStatusTimeBins(timeBuckets, heatmapData);

expect(result).toEqual([
{ start: 1000, end: 2000, ups: 2, downs: 3, value: getStatusEffectiveValue(2, 3) },
{ start: 2000, end: 3000, ups: 4, downs: 5, value: getStatusEffectiveValue(4, 5) },
]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,18 @@ export function createTimeBuckets(intervalMinutes: number, from: number, to: num

export function createStatusTimeBins(
timeBuckets: MonitorStatusTimeBucket[],
heatmapData: MonitorStatusHeatmapBucket[]
heatmapData?: MonitorStatusHeatmapBucket[]
): MonitorStatusTimeBin[] {
return timeBuckets.map(({ start, end }) => {
if (!Array.isArray(heatmapData)) {
return {
start,
end,
ups: 0,
downs: 0,
value: 0,
};
}
const { ups, downs } = heatmapData
.filter(({ key }) => key >= start && key <= end)
.reduce(
Expand Down Expand Up @@ -163,7 +172,7 @@ export function getBrushData(e: BrushEvent) {
return { from, to, fromUtc, toUtc };
}

function getStatusEffectiveValue(ups: number, downs: number): number {
export function getStatusEffectiveValue(ups: number, downs: number): number {
if (ups === downs) {
return -0.1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const useMonitorStatusData = ({ from, to, initialSizeRef }: Props) => {
}, [binsAvailableByWidth, initialSizeRef]);

useEffect(() => {
if (monitor?.id && location?.label && debouncedBinsCount !== null && minsPerBin !== null) {
if (monitor?.id && location?.label && debouncedBinsCount !== null && !!minsPerBin) {
dispatch(
quietGetMonitorStatusHeatmapAction.get({
monitorId: monitor.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from './actions';

export interface MonitorStatusHeatmap {
heatmap: MonitorStatusHeatmapBucket[];
heatmap?: MonitorStatusHeatmapBucket[];
loading: boolean;
error: IHttpSerializedFetchError | null;
}
Expand Down

0 comments on commit c9c3e89

Please sign in to comment.