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

[7.x] [Uptime] Synthetics UI (#77960) #79482

Merged
merged 1 commit into from
Oct 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions x-pack/plugins/uptime/common/runtime_types/ping/ping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,48 @@ export const PingType = t.intersection([
down: t.number,
up: t.number,
}),
synthetics: t.partial({
index: t.number,
journey: t.type({
id: t.string,
name: t.string,
}),
error: t.partial({
message: t.string,
name: t.string,
stack: t.string,
}),
package_version: t.string,
step: t.type({
index: t.number,
name: t.string,
}),
type: t.string,
// ui-related field
screenshotLoading: t.boolean,
// ui-related field
screenshotExists: t.boolean,
blob: t.string,
blob_mime: t.string,
payload: t.partial({
duration: t.number,
index: t.number,
is_navigation_request: t.boolean,
message: t.string,
method: t.string,
name: t.string,
params: t.partial({
homepage: t.string,
}),
source: t.string,
start: t.number,
status: t.string,
ts: t.number,
type: t.string,
url: t.string,
end: t.number,
}),
}),
tags: t.array(t.string),
tcp: t.partial({
rtt: t.partial({
Expand All @@ -202,6 +244,13 @@ export const PingType = t.intersection([
}),
]);

export const SyntheticsJourneyApiResponseType = t.type({
checkGroup: t.string,
steps: t.array(PingType),
});

export type SyntheticsJourneyApiResponse = t.TypeOf<typeof SyntheticsJourneyApiResponseType>;

export type Ping = t.TypeOf<typeof PingType>;

// Convenience function for tests etc that makes an empty ping
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/uptime/public/apps/uptime_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface UptimeAppColors {
range: string;
mean: string;
warning: string;
lightestShade: string;
}

export interface UptimeAppProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('PingListExpandedRow', () => {
docId: 'fdeio12',
timestamp: '19290310',
monitor: {
check_group: 'check_group_id',
duration: {
us: 12345,
},
Expand Down Expand Up @@ -87,4 +88,25 @@ describe('PingListExpandedRow', () => {

expect(docLinkComponent).toHaveLength(1);
});

it('renders a synthetics expanded row for synth monitor', () => {
ping.monitor.type = 'browser';
expect(shallowWithIntl(<PingListExpandedRowComponent ping={ping} />)).toMatchInlineSnapshot(`
<EuiFlexGroup
direction="column"
>
<EuiFlexItem>
<EuiCallOut
iconType="beaker"
title="Experimental feature"
/>
</EuiFlexItem>
<EuiFlexItem>
<BrowserExpandedRow
checkGroup="check_group_id"
/>
</EuiFlexItem>
</EuiFlexGroup>
`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import React from 'react';
import { shallowWithIntl } from 'test_utils/enzyme_helpers';
import { PingListComponent, toggleDetails } from '../ping_list';
import { PingListComponent, rowShouldExpand, toggleDetails } from '../ping_list';
import { Ping, PingsResponse } from '../../../../../common/runtime_types';
import { ExpandedRowMap } from '../../../overview/monitor_list/types';

Expand Down Expand Up @@ -182,6 +182,7 @@ describe('PingList component', () => {
to: 'now',
}}
getPings={jest.fn()}
pruneJourneysCallback={jest.fn()}
lastRefresh={123}
loading={false}
locations={[]}
Expand Down Expand Up @@ -273,5 +274,14 @@ describe('PingList component', () => {
/>
`);
});

describe('rowShouldExpand', () => {
// TODO: expand for all cases
it('returns true for browser monitors', () => {
const ping = pings[0];
ping.monitor.type = 'browser';
expect(rowShouldExpand(ping)).toBe(true);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

// @ts-ignore formatNumber
import { formatNumber } from '@elastic/eui/lib/services/format';
import {
Expand All @@ -19,6 +20,7 @@ import { i18n } from '@kbn/i18n';
import { Ping, HttpResponseBody } from '../../../../common/runtime_types';
import { DocLinkForBody } from './doc_link_body';
import { PingRedirects } from './ping_redirects';
import { BrowserExpandedRow } from '../synthetics/browser_expanded_row';

interface Props {
ping: Ping;
Expand Down Expand Up @@ -53,6 +55,24 @@ const BodyExcerpt = ({ content }: { content: string }) =>
export const PingListExpandedRowComponent = ({ ping }: Props) => {
const listItems = [];

if (ping.monitor.type === 'browser') {
return (
<EuiFlexGroup direction="column">
<EuiFlexItem>
<EuiCallOut
iconType="beaker"
title={i18n.translate('xpack.uptime.synthetics.experimentalCallout.title', {
defaultMessage: 'Experimental feature',
})}
/>
</EuiFlexItem>
<EuiFlexItem>
<BrowserExpandedRow checkGroup={ping.monitor.check_group} />
</EuiFlexItem>
</EuiFlexGroup>
);
}

// Show the error block
if (ping.error) {
listItems.push({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
*/

export { PingListComponent } from './ping_list';
export { PingList } from './ping_list_container';
export { PingList } from './ping_list';
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,63 @@ import {
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import moment from 'moment';
import React, { useState, useEffect } from 'react';
import React, { useCallback, useContext, useState, useEffect } from 'react';
import styled from 'styled-components';
import { useDispatch, useSelector } from 'react-redux';
import { Ping, GetPingsParams, DateRange } from '../../../../common/runtime_types';
import { convertMicrosecondsToMilliseconds as microsToMillis } from '../../../lib/helper';
import { LocationName } from './location_name';
import { Pagination } from '../../overview/monitor_list';
import { PingListExpandedRowComponent } from './expanded_row';
import { PingListProps } from './ping_list_container';
// import { PingListProps } from './ping_list_container';
import { pruneJourneyState } from '../../../state/actions/journey';
import { selectPingList } from '../../../state/selectors';
import { UptimeRefreshContext, UptimeSettingsContext } from '../../../contexts';
import { getPings as getPingsAction } from '../../../state/actions';

export interface PingListProps {
monitorId: string;
}

export const PingList = (props: PingListProps) => {
const {
error,
loading,
pingList: { locations, pings, total },
} = useSelector(selectPingList);

const { lastRefresh } = useContext(UptimeRefreshContext);

const { dateRangeStart: drs, dateRangeEnd: dre } = useContext(UptimeSettingsContext);

const dispatch = useDispatch();
const getPingsCallback = useCallback(
(params: GetPingsParams) => dispatch(getPingsAction(params)),
[dispatch]
);
const pruneJourneysCallback = useCallback(
(checkGroups: string[]) => dispatch(pruneJourneyState(checkGroups)),
[dispatch]
);

return (
<PingListComponent
dateRange={{
from: drs,
to: dre,
}}
error={error}
getPings={getPingsCallback}
pruneJourneysCallback={pruneJourneysCallback}
lastRefresh={lastRefresh}
loading={loading}
locations={locations}
pings={pings}
total={total}
{...props}
/>
);
};

export const AllLocationOption = {
'data-test-subj': 'xpack.uptime.pingList.locationOptions.all',
Expand Down Expand Up @@ -63,6 +112,7 @@ interface Props extends PingListProps {
dateRange: DateRange;
error?: Error;
getPings: (props: GetPingsParams) => void;
pruneJourneysCallback: (checkGroups: string[]) => void;
lastRefresh: number;
loading: boolean;
locations: string[];
Expand Down Expand Up @@ -96,6 +146,13 @@ const statusOptions = [
},
];

export function rowShouldExpand(item: Ping) {
const errorPresent = !!item.error;
const httpBodyPresent = item.http?.response?.body?.bytes ?? 0 > 0;
const isBrowserMonitor = item.monitor.type === 'browser';
return errorPresent || httpBodyPresent || isBrowserMonitor;
}

export const PingListComponent = (props: Props) => {
const [selectedLocation, setSelectedLocation] = useState<string>('');
const [status, setStatus] = useState<string>('');
Expand All @@ -105,6 +162,7 @@ export const PingListComponent = (props: Props) => {
dateRange: { from, to },
error,
getPings,
pruneJourneysCallback,
lastRefresh,
loading,
locations,
Expand All @@ -129,6 +187,27 @@ export const PingListComponent = (props: Props) => {

const [expandedRows, setExpandedRows] = useState<Record<string, JSX.Element>>({});

const expandedIdsToRemove = JSON.stringify(
Object.keys(expandedRows).filter((e) => !pings.some(({ docId }) => docId === e))
);
useEffect(() => {
const parsed = JSON.parse(expandedIdsToRemove);
if (parsed.length) {
parsed.forEach((docId: string) => {
delete expandedRows[docId];
});
setExpandedRows(expandedRows);
}
}, [expandedIdsToRemove, expandedRows]);

const expandedCheckGroups = pings
.filter((p: Ping) => Object.keys(expandedRows).some((f) => p.docId === f))
.map(({ monitor: { check_group: cg } }) => cg);
const expandedCheckGroupsStr = JSON.stringify(expandedCheckGroups);
useEffect(() => {
pruneJourneysCallback(JSON.parse(expandedCheckGroupsStr));
}, [pruneJourneysCallback, expandedCheckGroupsStr]);

const locationOptions = !locations
? [AllLocationOption]
: [AllLocationOption].concat(
Expand Down Expand Up @@ -239,7 +318,7 @@ export const PingListComponent = (props: Props) => {
<EuiButtonIcon
data-test-subj="uptimePingListExpandBtn"
onClick={() => toggleDetails(item, expandedRows, setExpandedRows)}
disabled={!item.error && !(item.http?.response?.body?.bytes ?? 0 > 0)}
disabled={!rowShouldExpand(item)}
aria-label={
expandedRows[item.docId]
? i18n.translate('xpack.uptime.pingList.collapseRow', {
Expand Down

This file was deleted.

Loading