Skip to content

Commit

Permalink
[Uptime] Improve query performance with Heartbeat 7.6+ data. (#52433) (
Browse files Browse the repository at this point in the history
…#54352)

This PR optimizes both the snapshot component and the monitor list on the overview page by using the new monitor.timespan field from elastic/beats#14778. Note that the functionality here will work with heartbeats lacking that patch, but the performance improvements will be absent.

This PR adapts the snapshot tests to use synthetically generated data which should be easier to maintain. As a result some of that code is refactored as well.

See #52433 parent issue as well.
  • Loading branch information
andrewvc authored Jan 9, 2020
1 parent ace1893 commit 40346ca
Show file tree
Hide file tree
Showing 47 changed files with 493 additions and 343 deletions.
12 changes: 0 additions & 12 deletions x-pack/legacy/plugins/uptime/common/graphql/introspection.json
Original file line number Diff line number Diff line change
Expand Up @@ -2173,18 +2173,6 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "mixed",
"description": "",
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": { "kind": "SCALAR", "name": "Int", "ofType": null }
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "total",
"description": "",
Expand Down
2 changes: 0 additions & 2 deletions x-pack/legacy/plugins/uptime/common/graphql/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,6 @@ export interface SnapshotCount {

down: number;

mixed: number;

total: number;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import * as t from 'io-ts';

export const SnapshotType = t.type({
down: t.number,
mixed: t.number,
total: t.number,
up: t.number,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ describe('Snapshot component', () => {
const snapshot: Snapshot = {
up: 8,
down: 2,
mixed: 0,
total: 10,
};

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import React from 'react';
describe('DonutChartLegendRow', () => {
it('passes appropriate props', () => {
const wrapper = shallowWithIntl(
<DonutChartLegendRow color="green" message="Foo" content={23} />
<DonutChartLegendRow color="green" message="Foo" content={23} data-test-subj="foo" />
);
expect(wrapper).toMatchSnapshot();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const DonutChart = ({ height, down, up, width }: DonutChartProps) => {
<EuiFlexGroup alignItems="center" responsive={false}>
<EuiFlexItem grow={false}>
<svg
aria-label={i18n.translate('xpack.uptime.donutChart.ariaLabel', {
aria-label={i18n.translate('xpack.uptime.snapshot.donutChart.ariaLabel', {
defaultMessage:
'Pie chart showing the current status. {down} of {total} monitors are down.',
values: { down, total: up + down },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,19 @@ export const DonutChartLegend = ({ down, up }: Props) => {
<DonutChartLegendRow
color={danger}
content={down}
message={i18n.translate('xpack.uptime.donutChart.legend.downRowLabel', {
message={i18n.translate('xpack.uptime.snapshot.donutChart.legend.downRowLabel', {
defaultMessage: 'Down',
})}
data-test-subj={'xpack.uptime.snapshot.donutChart.down'}
/>
<EuiSpacer size="m" />
<DonutChartLegendRow
color={gray}
content={up}
message={i18n.translate('xpack.uptime.donutChart.legend.upRowLabel', {
message={i18n.translate('xpack.uptime.snapshot.donutChart.legend.upRowLabel', {
defaultMessage: 'Up',
})}
data-test-subj={'xpack.uptime.snapshot.donutChart.up'}
/>
</LegendContainer>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,19 @@ interface Props {
color: string;
message: string;
content: string | number;
'data-test-subj': string;
}

export const DonutChartLegendRow = ({ color, content, message }: Props) => (
export const DonutChartLegendRow = ({ color, content, message, 'data-test-subj': dts }: Props) => (
<EuiFlexGroup gutterSize="l" responsive={false}>
<EuiFlexItemReducedMargin component="span" grow={false}>
<EuiHealth color={color} />
</EuiFlexItemReducedMargin>
<EuiFlexItemReducedMargin component="span" grow={false}>
{message}
</EuiFlexItemReducedMargin>
<EuiFlexItemAlignRight component="span">{content}</EuiFlexItemAlignRight>
<EuiFlexItemAlignRight component="span" data-test-subj={dts}>
{content}
</EuiFlexItemAlignRight>
</EuiFlexGroup>
);
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@
"monitor": {
"id": null,
"name": "elastic",
"status": "mixed",
"type": null,
"__typename": "MonitorState"
},
Expand Down Expand Up @@ -377,7 +376,6 @@
"monitor": {
"id": null,
"name": null,
"status": "mixed",
"type": null,
"__typename": "MonitorState"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ const getHealthColor = (status: string): string => {
return 'success';
case 'down':
return 'danger';
case 'mixed':
return 'warning';
default:
return '';
}
Expand All @@ -37,10 +35,6 @@ const getHealthMessage = (status: string): string | null => {
return i18n.translate('xpack.uptime.monitorList.statusColumn.downLabel', {
defaultMessage: 'Down',
});
case 'mixed':
return i18n.translate('xpack.uptime.monitorList.statusColumn.mixedLabel', {
defaultMessage: 'Mixed',
});
default:
return null;
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('snapshot API', () => {
fetchMock = jest.spyOn(window, 'fetch');
mockResponse = {
ok: true,
json: () => new Promise(r => r({ up: 3, down: 12, mixed: 0, total: 15 })),
json: () => new Promise(r => r({ up: 3, down: 12, total: 15 })),
};
});

Expand All @@ -34,7 +34,7 @@ describe('snapshot API', () => {
expect(fetchMock).toHaveBeenCalledWith(
'/api/uptime/snapshot/count?dateRangeStart=now-15m&dateRangeEnd=now&filters=monitor.id%3A%22auto-http-0X21EE76EAC459873F%22&statusFilter=up'
);
expect(resp).toEqual({ up: 3, down: 12, mixed: 0, total: 15 });
expect(resp).toEqual({ up: 3, down: 12, total: 15 });
});

it(`throws when server response doesn't correspond to expected type`, async () => {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('snapshot reducer', () => {
expect(
snapshotReducer(
{
count: { down: 1, mixed: 0, total: 4, up: 3 },
count: { down: 1, total: 4, up: 3 },
errors: [],
loading: false,
},
Expand All @@ -47,7 +47,6 @@ describe('snapshot reducer', () => {
payload: {
up: 10,
down: 15,
mixed: 0,
total: 25,
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export interface SnapshotState {
const initialState: SnapshotState = {
count: {
down: 0,
mixed: 0,
total: 0,
up: 0,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ describe('state selectors', () => {
count: {
up: 2,
down: 0,
mixed: 0,
total: 2,
},
errors: [],
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 40346ca

Please sign in to comment.