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

[Logs / Metrics UI] [NP followup] Cleanup link-to routes #61162

Merged
merged 5 commits into from
Mar 25, 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
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,7 @@ export const replaceLogPositionInQueryString = (time: number) =>
time,
tiebreaker: 0,
},
end: new Date(time + ONE_HOUR).toISOString(),
start: new Date(time - ONE_HOUR).toISOString(),
streamLive: false,
});
3 changes: 2 additions & 1 deletion x-pack/plugins/infra/public/pages/link_to/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

export { LinkToPage } from './link_to';
export { LinkToLogsPage } from './link_to_logs';
export { LinkToMetricsPage } from './link_to_metrics';
export { getNodeLogsUrl, RedirectToNodeLogs } from './redirect_to_node_logs';
export { getNodeDetailUrl, RedirectToNodeDetail } from './redirect_to_node_detail';
34 changes: 34 additions & 0 deletions x-pack/plugins/infra/public/pages/link_to/link_to_logs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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 { match as RouteMatch, Redirect, Route, Switch } from 'react-router-dom';

import { RedirectToLogs } from './redirect_to_logs';
import { RedirectToNodeLogs } from './redirect_to_node_logs';
import { inventoryModels } from '../../../common/inventory_models';

interface LinkToPageProps {
match: RouteMatch<{}>;
location: {
search: string;
};
}

const ITEM_TYPES = inventoryModels.map(m => m.id).join('|');

export const LinkToLogsPage: React.FC<LinkToPageProps> = props => {
return (
<Switch>
<Route
path={`${props.match.url}/:sourceId?/:nodeType(${ITEM_TYPES})-logs/:nodeId`}
component={RedirectToNodeLogs}
/>
<Route path={`${props.match.url}/:sourceId?`} component={RedirectToLogs} />
<Redirect to="/" />
</Switch>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
import React from 'react';
import { match as RouteMatch, Redirect, Route, Switch } from 'react-router-dom';

import { RedirectToLogs } from './redirect_to_logs';
import { RedirectToNodeDetail } from './redirect_to_node_detail';
import { RedirectToNodeLogs } from './redirect_to_node_logs';
import { RedirectToHostDetailViaIP } from './redirect_to_host_detail_via_ip';
import { inventoryModels } from '../../../common/inventory_models';

Expand All @@ -19,13 +17,9 @@ interface LinkToPageProps {

const ITEM_TYPES = inventoryModels.map(m => m.id).join('|');

export const LinkToPage: React.FC<LinkToPageProps> = props => {
export const LinkToMetricsPage: React.FC<LinkToPageProps> = props => {
return (
<Switch>
<Route
path={`${props.match.url}/:sourceId?/:nodeType(${ITEM_TYPES})-logs/:nodeId`}
component={RedirectToNodeLogs}
/>
<Route
path={`${props.match.url}/:nodeType(${ITEM_TYPES})-detail/:nodeId`}
component={RedirectToNodeDetail}
Expand All @@ -34,8 +28,7 @@ export const LinkToPage: React.FC<LinkToPageProps> = props => {
path={`${props.match.url}/host-detail-via-ip/:hostIp`}
component={RedirectToHostDetailViaIP}
/>
<Route path={`${props.match.url}/:sourceId?/logs`} component={RedirectToLogs} />
<Redirect to="/infrastructure" />
<Redirect to="/" />
</Switch>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('RedirectToLogs component', () => {

expect(component).toMatchInlineSnapshot(`
<Redirect
to="/stream?logPosition=(position:(tiebreaker:0,time:1550671089404),streamLive:!f)&sourceId=default&logFilter=(expression:'',kind:kuery)"
to="/stream?logPosition=(end:'2019-02-20T14:58:09.404Z',position:(tiebreaker:0,time:1550671089404),start:'2019-02-20T12:58:09.404Z',streamLive:!f)&sourceId=default&logFilter=(expression:'',kind:kuery)"
/>
`);
});
Expand All @@ -33,7 +33,7 @@ describe('RedirectToLogs component', () => {

expect(component).toMatchInlineSnapshot(`
<Redirect
to="/stream?logPosition=(position:(tiebreaker:0,time:1550671089404),streamLive:!f)&sourceId=default&logFilter=(expression:'FILTER_FIELD:FILTER_VALUE',kind:kuery)"
to="/stream?logPosition=(end:'2019-02-20T14:58:09.404Z',position:(tiebreaker:0,time:1550671089404),start:'2019-02-20T12:58:09.404Z',streamLive:!f)&sourceId=default&logFilter=(expression:'FILTER_FIELD:FILTER_VALUE',kind:kuery)"
/>
`);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('RedirectToNodeLogs component', () => {

expect(component).toMatchInlineSnapshot(`
<Redirect
to="/?logPosition=(position:(tiebreaker:0,time:1550671089404),streamLive:!f)&sourceId=default&logFilter=(expression:'HOST_FIELD:%20HOST_NAME',kind:kuery)"
to="/?logPosition=(end:'2019-02-20T14:58:09.404Z',position:(tiebreaker:0,time:1550671089404),start:'2019-02-20T12:58:09.404Z',streamLive:!f)&sourceId=default&logFilter=(expression:'HOST_FIELD:%20HOST_NAME',kind:kuery)"
/>
`);
});
Expand All @@ -89,7 +89,7 @@ describe('RedirectToNodeLogs component', () => {

expect(component).toMatchInlineSnapshot(`
<Redirect
to="/?logPosition=(position:(tiebreaker:0,time:1550671089404),streamLive:!f)&sourceId=default&logFilter=(expression:'(HOST_FIELD:%20HOST_NAME)%20and%20(FILTER_FIELD:FILTER_VALUE)',kind:kuery)"
to="/?logPosition=(end:'2019-02-20T14:58:09.404Z',position:(tiebreaker:0,time:1550671089404),start:'2019-02-20T12:58:09.404Z',streamLive:!f)&sourceId=default&logFilter=(expression:'(HOST_FIELD:%20HOST_NAME)%20and%20(FILTER_FIELD:FILTER_VALUE)',kind:kuery)"
/>
`);
});
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/infra/public/routers/logs_router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React from 'react';
import { Route, Router, Switch } from 'react-router-dom';

import { NotFoundPage } from '../pages/404';
import { LinkToPage } from '../pages/link_to';
import { LinkToLogsPage } from '../pages/link_to';
import { LogsPage } from '../pages/logs';
import { RedirectWithQueryParams } from '../utils/redirect_with_query_params';
import { useKibana } from '../../../../../src/plugins/kibana_react/public';
Expand All @@ -19,7 +19,7 @@ export const LogsRouter: AppRouter = ({ history }) => {
return (
<Router history={history}>
<Switch>
<Route path="/link-to" component={LinkToPage} />
<Route path="/link-to" component={LinkToLogsPage} />
{uiCapabilities?.logs?.show && (
<RedirectWithQueryParams from="/" exact={true} to="/stream" />
)}
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/infra/public/routers/metrics_router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Route, Router, Switch } from 'react-router-dom';

import { NotFoundPage } from '../pages/404';
import { InfrastructurePage } from '../pages/infrastructure';
import { LinkToPage } from '../pages/link_to';
import { LinkToMetricsPage } from '../pages/link_to';
import { MetricDetail } from '../pages/metrics';
import { RedirectWithQueryParams } from '../utils/redirect_with_query_params';
import { useKibana } from '../../../../../src/plugins/kibana_react/public';
Expand All @@ -20,7 +20,7 @@ export const MetricsRouter: AppRouter = ({ history }) => {
return (
<Router history={history}>
<Switch>
<Route path="/link-to" component={LinkToPage} />
<Route path="/link-to" component={LinkToMetricsPage} />
{uiCapabilities?.infrastructure?.show && (
<RedirectWithQueryParams from="/" exact={true} to="/inventory" />
)}
Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/functional/apps/infra/link_to.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
it('redirects to the logs app and parses URL search params correctly', async () => {
const location = {
hash: '',
pathname: '/link-to/logs',
pathname: '/link-to',
search: `time=${timestamp}&filter=trace.id:${traceId}`,
state: undefined,
};
Expand Down