Skip to content

Commit 8d5ee26

Browse files
authored
[Uptime] Display response headers for a ping (#82332)
1 parent d831676 commit 8d5ee26

5 files changed

Lines changed: 180 additions & 0 deletions

File tree

x-pack/plugins/uptime/common/runtime_types/ping/ping.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export const PingType = t.intersection([
145145
bytes: t.number,
146146
redirects: t.array(t.string),
147147
status_code: t.number,
148+
headers: t.record(t.string, t.string),
148149
}),
149150
version: t.string,
150151
}),

x-pack/plugins/uptime/public/components/monitor/ping_list/__tests__/__snapshots__/ping_headers.test.tsx.snap

Lines changed: 94 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { shallowWithIntl } from 'test_utils/enzyme_helpers';
8+
import React from 'react';
9+
import { PingHeaders } from '../headers';
10+
11+
describe('Ping Headers', () => {
12+
const headers = {
13+
'Content-Type': 'text/html',
14+
'Content-Length': '174781',
15+
Expires: 'Mon, 02 Nov 2020 17:22:03 GMT',
16+
'X-Xss-Protection': '0',
17+
'Accept-Ranges': 'bytes',
18+
Date: 'Mon, 02 Nov 2020 17:22:03 GMT',
19+
'Cache-Control': 'private, max-age=0',
20+
'Alt-Svc':
21+
'h3-Q050=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-T051=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"',
22+
Server: 'sffe',
23+
'Last-Modified': 'Wed, 28 Oct 2020 18:45:00 GMT',
24+
Vary: 'Accept-Encoding',
25+
'X-Content-Type-Options': 'nosniff',
26+
};
27+
28+
it('shallow renders expected elements for valid props', () => {
29+
expect(shallowWithIntl(<PingHeaders headers={headers} />)).toMatchSnapshot();
30+
});
31+
});

x-pack/plugins/uptime/public/components/monitor/ping_list/expanded_row.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { Ping, HttpResponseBody } from '../../../../common/runtime_types';
2121
import { DocLinkForBody } from './doc_link_body';
2222
import { PingRedirects } from './ping_redirects';
2323
import { BrowserExpandedRow } from '../synthetics/browser_expanded_row';
24+
import { PingHeaders } from './headers';
2425

2526
interface Props {
2627
ping: Ping;
@@ -105,6 +106,11 @@ export const PingListExpandedRowComponent = ({ ping }: Props) => {
105106
<PingRedirects monitorStatus={ping} showTitle={true} />
106107
</EuiFlexItem>
107108
)}
109+
{ping?.http?.response?.headers && (
110+
<EuiFlexItem>
111+
<PingHeaders headers={ping?.http?.response?.headers} />
112+
</EuiFlexItem>
113+
)}
108114
<EuiFlexItem>
109115
<EuiCallOut color={ping?.error ? 'danger' : 'primary'}>
110116
<EuiDescriptionList listItems={listItems} />
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import React from 'react';
8+
import { EuiAccordion, EuiDescriptionList, EuiSpacer, EuiText } from '@elastic/eui';
9+
import { i18n } from '@kbn/i18n';
10+
11+
interface Props {
12+
headers: Record<string, string>;
13+
}
14+
15+
export const PingHeaders = ({ headers }: Props) => {
16+
const headersList = Object.keys(headers)
17+
.sort()
18+
.map((header) => ({
19+
title: header,
20+
description: headers[header],
21+
}));
22+
23+
return (
24+
<>
25+
<EuiSpacer size="s" />
26+
<EuiAccordion
27+
id="responseHeaderAccord"
28+
buttonContent={
29+
<EuiText size="s">
30+
<h3>
31+
{i18n.translate('xpack.uptime.pingList.headers.title', {
32+
defaultMessage: 'Response headers',
33+
})}
34+
</h3>
35+
</EuiText>
36+
}
37+
>
38+
<EuiSpacer size="s" />
39+
<EuiDescriptionList
40+
titleProps={{ style: { width: '30%', paddingLeft: 30 } }}
41+
compressed={true}
42+
type="responsiveColumn"
43+
listItems={headersList}
44+
/>
45+
</EuiAccordion>
46+
</>
47+
);
48+
};

0 commit comments

Comments
 (0)