Skip to content

Commit

Permalink
[uptime] Ping Redirects (#65292)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 authored Aug 6, 2020
1 parent 810ff87 commit ccf8e2b
Show file tree
Hide file tree
Showing 18 changed files with 332 additions and 26 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/uptime/common/runtime_types/ping/ping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export const PingType = t.intersection([
response: t.partial({
body: HttpResponseBodyType,
bytes: t.number,
redirects: t.string,
redirects: t.array(t.string),
status_code: t.number,
}),
version: t.string,
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 @@ -18,6 +18,7 @@ import React from 'react';
import { i18n } from '@kbn/i18n';
import { Ping, HttpResponseBody } from '../../../../common/runtime_types';
import { DocLinkForBody } from './doc_link_body';
import { PingRedirects } from './ping_redirects';

interface Props {
ping: Ping;
Expand Down Expand Up @@ -78,7 +79,12 @@ export const PingListExpandedRowComponent = ({ ping }: Props) => {
});
}
return (
<EuiFlexGroup>
<EuiFlexGroup direction="column">
{ping?.http?.response?.redirects && (
<EuiFlexItem>
<PingRedirects monitorStatus={ping} showTitle={true} />
</EuiFlexItem>
)}
<EuiFlexItem>
<EuiCallOut color={ping?.error ? 'danger' : 'primary'}>
<EuiDescriptionList listItems={listItems} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ export const PingListComponent = (props: Props) => {
render: (item: Ping) => {
return (
<EuiButtonIcon
data-test-subj="uptimePingListExpandBtn"
onClick={() => toggleDetails(item, expandedRows, setExpandedRows)}
disabled={!item.error && !(item.http?.response?.body?.bytes ?? 0 > 0)}
aria-label={
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;
* you may not use this file except in compliance with the Elastic License.
*/

import React from 'react';
import { i18n } from '@kbn/i18n';
import styled from 'styled-components';
import { EuiListGroup, EuiListGroupItemProps, EuiPanel, EuiSpacer, EuiText } from '@elastic/eui';
import { Ping } from '../../../../common/runtime_types/ping';

const ListGroup = styled(EuiListGroup)`
&&& {
a {
padding-left: 0;
}
}
`;

interface Props {
monitorStatus: Ping | null;
showTitle?: boolean;
}

export const PingRedirects: React.FC<Props> = ({ monitorStatus, showTitle }) => {
const monitorUrl = monitorStatus?.url?.full;

const list = monitorStatus?.http?.response?.redirects;

const listOfRedirects: EuiListGroupItemProps[] = [
{
label: monitorUrl,
href: monitorUrl,
iconType: 'globe',
size: 's',
target: '_blank',
extraAction: {
color: 'subdued',
iconType: 'popout',
iconSize: 's',
alwaysShow: true,
'aria-label': i18n.translate('xpack.uptime.monitorList.redirects.openWindow', {
defaultMessage: 'Link will open in new window.',
}),
},
},
];

(list ?? []).forEach((url: string) => {
listOfRedirects.push({
label: url,
href: url,
iconType: 'sortDown',
size: 's',
target: '_blank',
extraAction: {
color: 'subdued',
iconType: 'popout',
iconSize: 's',
'aria-label': i18n.translate('xpack.uptime.monitorList.redirects.openWindow', {
defaultMessage: 'Link will open in new window.',
}),
alwaysShow: true,
},
});
});

const Panel = showTitle ? EuiPanel : 'div';

return list ? (
<Panel data-test-subj="uptimeMonitorPingListRedirectInfo">
{showTitle && (
<EuiText size="xs">
<h3>
{i18n.translate('xpack.uptime.monitorList.redirects.title', {
defaultMessage: 'Redirects',
})}
</h3>
</EuiText>
)}
<EuiSpacer size="xs" />
{
<EuiText>
{i18n.translate('xpack.uptime.monitorList.redirects.description', {
defaultMessage: 'Heartbeat followed {number} redirects while executing ping.',
values: {
number: list?.length ?? 0,
},
})}
</EuiText>
}
<EuiSpacer size="s" />
<ListGroup gutterSize={'none'} listItems={listOfRedirects} />
</Panel>
) : null;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React, { useState } from 'react';
import { i18n } from '@kbn/i18n';
import { EuiPopover } from '@elastic/eui';
import styled from 'styled-components';
import { Ping } from '../../../../../common/runtime_types';
import { PingRedirects } from '../../ping_list/ping_redirects';
import { MonListDescription, MonListTitle } from './status_bar';

interface Props {
monitorStatus: Ping | null;
}

const RedirectBtn = styled.span`
cursor: pointer;
`;

export const MonitorRedirects: React.FC<Props> = ({ monitorStatus }) => {
const list = monitorStatus?.http?.response?.redirects;

const [isPopoverOpen, setIsPopoverOpen] = useState(false);

const button = (
<MonListDescription>
<RedirectBtn
className="euiLink euiLink--primary"
onClick={() => setIsPopoverOpen(!isPopoverOpen)}
data-test-subj="uptimeMonitorRedirectInfo"
>
{i18n.translate('xpack.uptime.monitorList.redirects.title.number', {
defaultMessage: '{number}',
values: {
number: list?.length ?? 0,
},
})}
</RedirectBtn>
</MonListDescription>
);

return list ? (
<>
<MonListTitle>Redirects</MonListTitle>
<EuiPopover
button={button}
isOpen={isPopoverOpen}
anchorPosition="downLeft"
closePopover={() => setIsPopoverOpen(false)}
>
<PingRedirects monitorStatus={monitorStatus} />
</EuiPopover>
</>
) : null;
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { MonitorIDLabel, OverallAvailability } from '../translations';
import { URL_LABEL } from '../../../common/translations';
import { MonitorLocations } from '../../../../../common/runtime_types/monitor';
import { formatAvailabilityValue } from '../availability_reporting/availability_reporting';
import { MonitorRedirects } from './monitor_redirects';

export const MonListTitle = styled(EuiDescriptionListTitle)`
&&& {
Expand Down Expand Up @@ -76,6 +77,7 @@ export const MonitorStatusBar: React.FC = () => {
<MonListTitle>{MonitorIDLabel}</MonListTitle>
<MonListDescription data-test-subj="monitor-page-title">{monitorId}</MonListDescription>
<MonitorSSLCertificate tls={monitorStatus?.tls} />
<MonitorRedirects monitorStatus={monitorStatus} />
</EuiDescriptionList>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('getLatestMonitor', () => {
},
},
size: 1,
_source: ['url', 'monitor', 'observer', '@timestamp', 'tls.*'],
_source: ['url', 'monitor', 'observer', '@timestamp', 'tls.*', 'http'],
sort: {
'@timestamp': { order: 'desc' },
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const getLatestMonitor: UMElasticsearchQueryFn<GetLatestMonitorParams, Pi
},
},
size: 1,
_source: ['url', 'monitor', 'observer', '@timestamp', 'tls.*'],
_source: ['url', 'monitor', 'observer', '@timestamp', 'tls.*', 'http'],
sort: {
'@timestamp': { order: 'desc' },
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,32 @@
"hostname": "avc-x1x"
},
"@timestamp": "2019-09-11T03:40:34.371Z",
"http": {
"rtt": {
"response_header": {
"us": 262
},
"total": {
"us": 20331
},
"write_request": {
"us": 82
},
"content": {
"us": 57
},
"validate": {
"us": 319
}
},
"response": {
"status_code": 200,
"body": {
"bytes": 3,
"hash": "27badc983df1780b60c2b3fa9d3a19a00e46aac798451f0febdca52920faaddf"
}
}
},
"monitor": {
"duration": {
"us": 24627
Expand All @@ -28,4 +54,4 @@
},
"docId": "h5toHm0B0I9WX_CznN_V",
"timestamp": "2019-09-11T03:40:34.371Z"
}
}
2 changes: 1 addition & 1 deletion x-pack/test/functional/apps/uptime/certificates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
});

it('can navigate to cert page', async () => {
await uptimeService.cert.isUptimeDataMissing();
await uptimeService.common.waitUntilDataIsLoaded();
await uptimeService.cert.hasViewCertButton();
await uptimeService.navigation.goToCertificates();
});
Expand Down
4 changes: 4 additions & 0 deletions x-pack/test/functional/apps/uptime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ export default ({ loadTestFile, getService }: FtrProviderContext) => {
loadTestFile(require.resolve('./certificates'));
});

describe('with generated data but no data reset', () => {
loadTestFile(require.resolve('./ping_redirects'));
});

describe('with real-world data', () => {
before(async () => {
await esArchiver.unload(ARCHIVE);
Expand Down
5 changes: 2 additions & 3 deletions x-pack/test/functional/apps/uptime/locations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/

import moment from 'moment';
import { makeChecksWithStatus } from '../../../api_integration/apis/uptime/rest/helper/make_checks';
import { FtrProviderContext } from '../../ftr_provider_context';

Expand Down Expand Up @@ -40,8 +39,8 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
};

describe('Observer location', () => {
const start = moment().subtract('15', 'm').toISOString();
const end = moment().toISOString();
const start = '~ 15 minutes ago';
const end = 'now';

before(async () => {
await addMonitorWithNoLocation();
Expand Down
Loading

0 comments on commit ccf8e2b

Please sign in to comment.