Skip to content

Commit

Permalink
Fix links from waffle map to the logging ui
Browse files Browse the repository at this point in the history
  • Loading branch information
weltenwort committed Sep 18, 2018
1 parent 65c8090 commit 6dfe01f
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { EuiContextMenu, EuiContextMenuPanelDescriptor, EuiPopover } from '@elastic/eui';
import React from 'react';
import { InfraWaffleMapNode, InfraWaffleMapOptions } from '../../lib/lib';
import { getContainerLogsUrl, getHostLogsUrl, getPodLogsUrl } from '../../pages/link_to';

interface Props {
options: InfraWaffleMapOptions;
Expand All @@ -24,15 +25,21 @@ export const NodeContextMenu: React.SFC<Props> = ({
// TODO: This needs to be change to be dynamic based on the options passed in.
const nodeType = 'host';

const nodeLogsUrl = getNodeLogsUrl(nodeType, node);

const panels: EuiContextMenuPanelDescriptor[] = [
{
id: 0,
title: '',
items: [
{
name: `View logs for this ${nodeType}`,
href: `#/logs?filter=${node.name}`,
},
...(nodeLogsUrl
? [
{
name: `View logs for this ${nodeType}`,
href: nodeLogsUrl,
},
]
: []),
{
name: `View APM Traces for this ${nodeType}`,
href: `/app/apm`,
Expand All @@ -52,3 +59,25 @@ export const NodeContextMenu: React.SFC<Props> = ({
</EuiPopover>
);
};

const getNodeLogsUrl = (
nodeType: 'host' | 'container' | 'pod',
{ path }: InfraWaffleMapNode
): string | undefined => {
if (path.length <= 0) {
return undefined;
}

const lastPathSegment = path[path.length - 1];

switch (nodeType) {
case 'host':
return getHostLogsUrl({ hostname: lastPathSegment.value });
case 'container':
return getContainerLogsUrl({ containerId: lastPathSegment.value });
case 'host':
return getPodLogsUrl({ podId: lastPathSegment.value });
default:
return undefined;
}
};
6 changes: 3 additions & 3 deletions x-pack/plugins/infra/public/pages/link_to/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
*/

export { LinkToPage } from './link_to';
export { RedirectToContainerLogs } from './redirect_to_container_logs';
export { RedirectToHostLogs } from './redirect_to_host_logs';
export { RedirectToPodLogs } from './redirect_to_pod_logs';
export { getContainerLogsUrl, RedirectToContainerLogs } from './redirect_to_container_logs';
export { getHostLogsUrl, RedirectToHostLogs } from './redirect_to_host_logs';
export { getPodLogsUrl, RedirectToPodLogs } from './redirect_to_pod_logs';
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,11 @@ export const RedirectToContainerLogs = ({
}}
</WithSource>
);

export const getContainerLogsUrl = ({
containerId,
time,
}: {
containerId: string;
time?: number;
}) => ['#/link-to/container-logs/', containerId, ...(time ? [`?time=${time}`] : [])].join('');
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ export const RedirectToHostLogs = ({
}}
</WithSource>
);

export const getHostLogsUrl = ({ hostname, time }: { hostname: string; time?: number }) =>
['#/link-to/host-logs/', hostname, ...(time ? [`?time=${time}`] : [])].join('');
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ export const RedirectToPodLogs = ({ match, location }: RouteComponentProps<{ pod
}}
</WithSource>
);

export const getPodLogsUrl = ({ podId, time }: { podId: string; time?: number }) =>
['#/link-to/pod-logs/', podId, ...(time ? [`?time=${time}`] : [])].join('');

0 comments on commit 6dfe01f

Please sign in to comment.