-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Infra UI] Provide routes for accessing pre-filtered log views (#23246)
This PR introduces a set of routes that can be used as stable entry points into the infra ui with partly pre-populated stated (e.g. filters and time): * `app/infra/#/link-to/container-logs/:containerId[?time=${TIMESTAMP}]` * `app/infra/#/link-to/host-logs/:hostname[?time=${TIMESTAMP}]` * `app/infra/#/link-to/pod-logs/:podId[?time=${TIMESTAMP}]` It also fixes the links from the waffle map to the logging ui to result in an appropriately filtered view.
- Loading branch information
1 parent
1608d19
commit cc9c30b
Showing
17 changed files
with
333 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* 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 { | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiLoadingSpinner, | ||
EuiPageBody, | ||
EuiPageContent, | ||
} from '@elastic/eui'; | ||
import React from 'react'; | ||
|
||
import { FlexPage } from './page'; | ||
|
||
interface LoadingPageProps { | ||
message?: string; | ||
} | ||
|
||
export const LoadingPage = ({ message }: LoadingPageProps) => ( | ||
<FlexPage> | ||
<EuiPageBody> | ||
<EuiPageContent verticalPosition="center" horizontalPosition="center"> | ||
<EuiFlexGroup alignItems="center"> | ||
<EuiFlexItem grow={false}> | ||
<EuiLoadingSpinner size="xl" /> | ||
</EuiFlexItem> | ||
<EuiFlexItem>{message}</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiPageContent> | ||
</EuiPageBody> | ||
</FlexPage> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* 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 { connect } from 'react-redux'; | ||
|
||
import { sourceSelectors, State } from '../store'; | ||
import { asChildFunctionRenderer } from '../utils/typed_react'; | ||
|
||
export const withSource = connect((state: State) => ({ | ||
configuredFields: sourceSelectors.selectSourceFields(state), | ||
})); | ||
|
||
export const WithSource = asChildFunctionRenderer(withSource); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export { LinkToPage } from './link_to'; | ||
export { getContainerLogsUrl, RedirectToContainerLogs } from './redirect_to_container_logs'; | ||
export { getHostLogsUrl, RedirectToHostLogs } from './redirect_to_host_logs'; | ||
export { getPodLogsUrl, RedirectToPodLogs } from './redirect_to_pod_logs'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { RedirectToContainerLogs } from './redirect_to_container_logs'; | ||
import { RedirectToHostLogs } from './redirect_to_host_logs'; | ||
import { RedirectToPodLogs } from './redirect_to_pod_logs'; | ||
|
||
interface LinkToPageProps { | ||
match: RouteMatch<{}>; | ||
} | ||
|
||
export class LinkToPage extends React.Component<LinkToPageProps> { | ||
public render() { | ||
const { match } = this.props; | ||
|
||
return ( | ||
<Switch> | ||
<Route | ||
path={`${match.url}/container-logs/:containerId`} | ||
component={RedirectToContainerLogs} | ||
/> | ||
<Route path={`${match.url}/host-logs/:hostname`} component={RedirectToHostLogs} /> | ||
<Route path={`${match.url}/pod-logs/:podId`} component={RedirectToPodLogs} /> | ||
<Redirect to="/home" /> | ||
</Switch> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* 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 { Location } from 'history'; | ||
|
||
import { getParamFromQueryString, getQueryStringFromLocation } from '../../utils/url_state'; | ||
|
||
export const getTimeFromLocation = (location: Location) => { | ||
const timeParam = getParamFromQueryString(getQueryStringFromLocation(location), 'time'); | ||
return timeParam ? parseFloat(timeParam) : NaN; | ||
}; |
43 changes: 43 additions & 0 deletions
43
x-pack/plugins/infra/public/pages/link_to/redirect_to_container_logs.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* 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 compose from 'lodash/fp/compose'; | ||
import React from 'react'; | ||
import { Redirect, RouteComponentProps } from 'react-router-dom'; | ||
|
||
import { LoadingPage } from '../../components/loading_page'; | ||
import { replaceLogFilterInQueryString } from '../../containers/logs/with_log_filter'; | ||
import { replaceLogPositionInQueryString } from '../../containers/logs/with_log_position'; | ||
import { WithSource } from '../../containers/with_source'; | ||
import { getTimeFromLocation } from './query_params'; | ||
|
||
export const RedirectToContainerLogs = ({ | ||
match, | ||
location, | ||
}: RouteComponentProps<{ containerId: string }>) => ( | ||
<WithSource> | ||
{({ configuredFields }) => { | ||
if (!configuredFields) { | ||
return <LoadingPage message="Loading container logs" />; | ||
} | ||
|
||
const searchString = compose( | ||
replaceLogFilterInQueryString(`${configuredFields.container}: ${match.params.containerId}`), | ||
replaceLogPositionInQueryString(getTimeFromLocation(location)) | ||
)(''); | ||
|
||
return <Redirect to={`/logs?${searchString}`} />; | ||
}} | ||
</WithSource> | ||
); | ||
|
||
export const getContainerLogsUrl = ({ | ||
containerId, | ||
time, | ||
}: { | ||
containerId: string; | ||
time?: number; | ||
}) => ['#/link-to/container-logs/', containerId, ...(time ? [`?time=${time}`] : [])].join(''); |
38 changes: 38 additions & 0 deletions
38
x-pack/plugins/infra/public/pages/link_to/redirect_to_host_logs.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* 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 compose from 'lodash/fp/compose'; | ||
import React from 'react'; | ||
import { Redirect, RouteComponentProps } from 'react-router-dom'; | ||
|
||
import { LoadingPage } from '../../components/loading_page'; | ||
import { replaceLogFilterInQueryString } from '../../containers/logs/with_log_filter'; | ||
import { replaceLogPositionInQueryString } from '../../containers/logs/with_log_position'; | ||
import { WithSource } from '../../containers/with_source'; | ||
import { getTimeFromLocation } from './query_params'; | ||
|
||
export const RedirectToHostLogs = ({ | ||
match, | ||
location, | ||
}: RouteComponentProps<{ hostname: string }>) => ( | ||
<WithSource> | ||
{({ configuredFields }) => { | ||
if (!configuredFields) { | ||
return <LoadingPage message="Loading host logs" />; | ||
} | ||
|
||
const searchString = compose( | ||
replaceLogFilterInQueryString(`${configuredFields.hostname}: ${match.params.hostname}`), | ||
replaceLogPositionInQueryString(getTimeFromLocation(location)) | ||
)(''); | ||
|
||
return <Redirect to={`/logs?${searchString}`} />; | ||
}} | ||
</WithSource> | ||
); | ||
|
||
export const getHostLogsUrl = ({ hostname, time }: { hostname: string; time?: number }) => | ||
['#/link-to/host-logs/', hostname, ...(time ? [`?time=${time}`] : [])].join(''); |
35 changes: 35 additions & 0 deletions
35
x-pack/plugins/infra/public/pages/link_to/redirect_to_pod_logs.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* 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 compose from 'lodash/fp/compose'; | ||
import React from 'react'; | ||
import { Redirect, RouteComponentProps } from 'react-router-dom'; | ||
|
||
import { LoadingPage } from '../../components/loading_page'; | ||
import { replaceLogFilterInQueryString } from '../../containers/logs/with_log_filter'; | ||
import { replaceLogPositionInQueryString } from '../../containers/logs/with_log_position'; | ||
import { WithSource } from '../../containers/with_source'; | ||
import { getTimeFromLocation } from './query_params'; | ||
|
||
export const RedirectToPodLogs = ({ match, location }: RouteComponentProps<{ podId: string }>) => ( | ||
<WithSource> | ||
{({ configuredFields }) => { | ||
if (!configuredFields) { | ||
return <LoadingPage message="Loading pod logs" />; | ||
} | ||
|
||
const searchString = compose( | ||
replaceLogFilterInQueryString(`${configuredFields.pod}: ${match.params.podId}`), | ||
replaceLogPositionInQueryString(getTimeFromLocation(location)) | ||
)(''); | ||
|
||
return <Redirect to={`/logs?${searchString}`} />; | ||
}} | ||
</WithSource> | ||
); | ||
|
||
export const getPodLogsUrl = ({ podId, time }: { podId: string; time?: number }) => | ||
['#/link-to/pod-logs/', podId, ...(time ? [`?time=${time}`] : [])].join(''); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.