mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Uptime] Uptime to Logging integration (#36741)
Add links to logs UI from Uptime
This commit is contained in:
parent
09102cd17e
commit
a8f75c1588
9 changed files with 236 additions and 23 deletions
|
@ -15,6 +15,8 @@ import {
|
|||
getInfraContainerHref,
|
||||
getInfraIpHref,
|
||||
getInfraKubernetesHref,
|
||||
getLoggingContainerHref,
|
||||
getLoggingKubernetesHref,
|
||||
} from '../../lib/helper';
|
||||
|
||||
interface MonitorListActionsPopoverProps {
|
||||
|
@ -170,6 +172,60 @@ export const MonitorListActionsPopover = ({
|
|||
)}
|
||||
/>
|
||||
</EuiFlexItem>
|
||||
<EuiFlexItem>
|
||||
<IntegrationLink
|
||||
ariaLabel={i18n.translate(
|
||||
'xpack.uptime.monitorList.loggingIntegrationAction.kubernetes.ariaLabel',
|
||||
{
|
||||
defaultMessage: 'Show pod logs',
|
||||
}
|
||||
)}
|
||||
href={getLoggingKubernetesHref(monitor, basePath)}
|
||||
iconType="loggingApp"
|
||||
message={i18n.translate(
|
||||
'xpack.uptime.monitorList.loggingIntegrationAction.kubernetes.message',
|
||||
{
|
||||
defaultMessage: 'Show pod logs',
|
||||
}
|
||||
)}
|
||||
tooltipContent={i18n.translate(
|
||||
'xpack.uptime.monitorList.loggingIntegrationAction.kubernetes.tooltip',
|
||||
{
|
||||
defaultMessage: 'Check for logs for pod UID "{podUid}"',
|
||||
values: {
|
||||
podUid,
|
||||
},
|
||||
}
|
||||
)}
|
||||
/>
|
||||
</EuiFlexItem>
|
||||
<EuiFlexItem>
|
||||
<IntegrationLink
|
||||
ariaLabel={i18n.translate(
|
||||
'xpack.uptime.monitorList.loggingIntegrationAction.container.id',
|
||||
{
|
||||
defaultMessage: 'Show container logs',
|
||||
}
|
||||
)}
|
||||
href={getLoggingContainerHref(monitor, basePath)}
|
||||
iconType="loggingApp"
|
||||
message={i18n.translate(
|
||||
'xpack.uptime.monitorList.loggingIntegrationAction.container.message',
|
||||
{
|
||||
defaultMessage: 'Show container logs',
|
||||
}
|
||||
)}
|
||||
tooltipContent={i18n.translate(
|
||||
'xpack.uptime.monitorList.loggingIntegrationAction.container.tooltip',
|
||||
{
|
||||
defaultMessage: 'Check Logging UI for container ID "{containerId}"',
|
||||
values: {
|
||||
containerId,
|
||||
},
|
||||
}
|
||||
)}
|
||||
/>
|
||||
</EuiFlexItem>
|
||||
</EuiFlexGroup>
|
||||
</EuiPopover>
|
||||
);
|
||||
|
|
|
@ -2,4 +2,4 @@
|
|||
|
||||
exports[`getApmHref creates href with base path when present 1`] = `"/foo/app/apm#/services?kuery=url.domain:%20%22www.elastic.co%22&rangeFrom=now-15m&rangeTo=now"`;
|
||||
|
||||
exports[`getApmHref does not add a base path or extra slash when base path is undefined 1`] = `"/app/apm#/services?kuery=url.domain:%20%22www.elastic.co%22&rangeFrom=now-15m&rangeTo=now"`;
|
||||
exports[`getApmHref does not add a base path or extra slash when base path is empty string 1`] = `"/app/apm#/services?kuery=url.domain:%20%22www.elastic.co%22&rangeFrom=now-15m&rangeTo=now"`;
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`getLoggingHref creates a container href with base path when present 1`] = `"/bar/app/infra#/logs?logFilter=(expression:'container.id%20:%20test-container-id',kind:kuery)"`;
|
||||
|
||||
exports[`getLoggingHref creates a container href without a base path if it's an empty string 1`] = `"/app/infra#/logs?logFilter=(expression:'container.id%20:%20test-container-id',kind:kuery)"`;
|
||||
|
||||
exports[`getLoggingHref creates a pod href with base path when present 1`] = `"/bar/app/infra#/logs?logFilter=(expression:'pod.uid%20:%20test-pod-id',kind:kuery)"`;
|
||||
|
||||
exports[`getLoggingHref creates a pod href without a base path when it's an empty string 1`] = `"/app/infra#/logs?logFilter=(expression:'pod.uid%20:%20test-pod-id',kind:kuery)"`;
|
||||
|
||||
exports[`getLoggingHref creates an ip href with base path when present 1`] = `"/bar/app/infra#/logs?logFilter=(expression:'pod.uid%20:%20test-pod-id',kind:kuery)"`;
|
||||
|
||||
exports[`getLoggingHref creates an ip href without a base path when it's an empty string 1`] = `"/app/infra#/logs?logFilter=(expression:'host.ip%20%3A%20151.101.202.217',kind:kuery)"`;
|
|
@ -29,7 +29,7 @@ describe('getApmHref', () => {
|
|||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('does not add a base path or extra slash when base path is undefined', () => {
|
||||
it('does not add a base path or extra slash when base path is empty string', () => {
|
||||
const result = getApmHref(monitor, '', 'now-15m', 'now');
|
||||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
|
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* 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 {
|
||||
getLoggingContainerHref,
|
||||
getLoggingKubernetesHref,
|
||||
getLoggingIpHref,
|
||||
} from '../get_logging_href';
|
||||
import { LatestMonitor } from '../../../../../common/graphql/types';
|
||||
|
||||
describe('getLoggingHref', () => {
|
||||
let monitor: LatestMonitor;
|
||||
|
||||
beforeEach(() => {
|
||||
monitor = {
|
||||
id: {
|
||||
key: 'monitorId',
|
||||
},
|
||||
ping: {
|
||||
container: {
|
||||
id: 'test-container-id',
|
||||
},
|
||||
kubernetes: {
|
||||
pod: {
|
||||
uid: 'test-pod-id',
|
||||
},
|
||||
},
|
||||
monitor: {
|
||||
ip: '151.101.202.217',
|
||||
},
|
||||
timestamp: 'foo',
|
||||
url: {
|
||||
domain: 'www.elastic.co',
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
it('creates a container href with base path when present', () => {
|
||||
const result = getLoggingContainerHref(monitor, 'bar');
|
||||
expect(result).not.toBeUndefined();
|
||||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it(`creates a container href without a base path if it's an empty string`, () => {
|
||||
const result = getLoggingContainerHref(monitor, '');
|
||||
expect(result).not.toBeUndefined();
|
||||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it(`creates an ip href with base path when present`, () => {
|
||||
const result = getLoggingKubernetesHref(monitor, 'bar');
|
||||
expect(result).not.toBeUndefined();
|
||||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('creates a pod href with base path when present', () => {
|
||||
const result = getLoggingKubernetesHref(monitor, 'bar');
|
||||
expect(result).not.toBeUndefined();
|
||||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it(`creates a pod href without a base path when it's an empty string`, () => {
|
||||
const result = getLoggingKubernetesHref(monitor, '');
|
||||
expect(result).not.toBeUndefined();
|
||||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it(`creates an ip href without a base path when it's an empty string`, () => {
|
||||
const result = getLoggingIpHref(monitor, '');
|
||||
expect(result).not.toBeUndefined();
|
||||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('returns undefined if necessary container is not present', () => {
|
||||
expect.assertions(1);
|
||||
delete monitor.ping;
|
||||
expect(getLoggingContainerHref(monitor, '')).toBeUndefined();
|
||||
});
|
||||
|
||||
it('returns undefined if necessary pod is not present', () => {
|
||||
expect.assertions(1);
|
||||
delete monitor.ping;
|
||||
expect(getLoggingKubernetesHref(monitor, '')).toBeUndefined();
|
||||
});
|
||||
|
||||
it('returns undefined ip href if ip is not present', () => {
|
||||
expect.assertions(1);
|
||||
delete monitor.ping;
|
||||
expect(getLoggingIpHref(monitor, '')).toBeUndefined();
|
||||
});
|
||||
});
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* 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 { get } from 'lodash';
|
||||
import { LatestMonitor } from '../../../../common/graphql/types';
|
||||
|
||||
/**
|
||||
* Builds URLs to the designated features by extracting values from the provided
|
||||
* monitor object on a given path. Then returns the result of a provided function
|
||||
* to place the value in its rightful place on the URI string.
|
||||
* @param monitor the data object
|
||||
* @param path the location on the object of the desired data
|
||||
* @param getHref a function that returns the full URL
|
||||
*/
|
||||
export const buildHref = (
|
||||
monitor: LatestMonitor,
|
||||
path: string,
|
||||
getHref: (value: string) => string
|
||||
): string | undefined => {
|
||||
const queryValue = get<string | undefined>(monitor, path);
|
||||
if (queryValue === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
return getHref(queryValue);
|
||||
};
|
|
@ -4,29 +4,9 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { get } from 'lodash';
|
||||
import { LatestMonitor } from '../../../../common/graphql/types';
|
||||
import { addBasePath } from './add_base_path';
|
||||
|
||||
/**
|
||||
* Builds URLs to the designated features by extracting values from the provided
|
||||
* monitor object on a given path. Then returns the result of a provided function
|
||||
* to place the value in its rightful place on the URI string.
|
||||
* @param monitor the data object
|
||||
* @param path the location on the object of the desired data
|
||||
* @param getHref a function that returns the full URL
|
||||
*/
|
||||
const buildHref = (
|
||||
monitor: LatestMonitor,
|
||||
path: string,
|
||||
getHref: (value: string) => string
|
||||
): string | undefined => {
|
||||
const queryValue = get<string | undefined>(monitor, path);
|
||||
if (queryValue === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
return getHref(queryValue);
|
||||
};
|
||||
import { buildHref } from './build_href';
|
||||
|
||||
export const getInfraContainerHref = (
|
||||
monitor: LatestMonitor,
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* 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 { LatestMonitor } from '../../../../common/graphql/types';
|
||||
import { addBasePath } from './add_base_path';
|
||||
import { buildHref } from './build_href';
|
||||
|
||||
export const getLoggingContainerHref = (
|
||||
monitor: LatestMonitor,
|
||||
basePath: string
|
||||
): string | undefined =>
|
||||
buildHref(monitor, 'ping.container.id', containerId =>
|
||||
addBasePath(
|
||||
basePath,
|
||||
`/app/infra#/logs?logFilter=${encodeURI(
|
||||
`(expression:'container.id : ${containerId}',kind:kuery)`
|
||||
)}`
|
||||
)
|
||||
);
|
||||
|
||||
export const getLoggingKubernetesHref = (monitor: LatestMonitor, basePath: string) =>
|
||||
buildHref(monitor, 'ping.kubernetes.pod.uid', podUID =>
|
||||
addBasePath(
|
||||
basePath,
|
||||
`/app/infra#/logs?logFilter=${encodeURI(`(expression:'pod.uid : ${podUID}',kind:kuery)`)}`
|
||||
)
|
||||
);
|
||||
|
||||
export const getLoggingIpHref = (monitor: LatestMonitor, basePath: string) =>
|
||||
buildHref(monitor, 'ping.monitor.ip', ip =>
|
||||
addBasePath(
|
||||
basePath,
|
||||
`/app/infra#/logs?logFilter=(expression:'${encodeURIComponent(
|
||||
`host.ip : ${ip}`
|
||||
)}',kind:kuery)`
|
||||
)
|
||||
);
|
|
@ -6,3 +6,4 @@
|
|||
|
||||
export { getApmHref } from './get_apm_href';
|
||||
export { getInfraContainerHref, getInfraIpHref, getInfraKubernetesHref } from './get_infra_href';
|
||||
export { getLoggingKubernetesHref, getLoggingContainerHref } from './get_logging_href';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue