forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fleet] Fix links to Logs view to point to Discover in Serverless (el…
…astic#171525) Fixes elastic#168349 ## Summary Fix links to Logs view to point to Discover in Serverless. As the Logs view UI is not available in serverless, the "Open in logs" buttons should point to Discover instead. Rather than hardcode the url in each of the places where is needed, I extracted a small component that builds the two urls and allows switching in an easier way. If in the future on of the two links will go away, it will be easier to find those occurrences. ### Testing Test for serverless following [these instructions](elastic#167976) **Error logs in agent activity flyout** - Enroll an agent and try to cause some error - for instance upgrading an agent that is not upgradeable - Click on "Agent Activity" and find the error and a button besides it - On stateful the button says "Open in Logs" ![Screenshot 2023-11-20 at 13 07 08](https://github.com/elastic/kibana/assets/16084106/704cf0e2-c7ee-4751-9e7f-7dcd263a5aa4) - On serverless is "Open in discover" ![Screenshot 2023-11-20 at 13 08 02](https://github.com/elastic/kibana/assets/16084106/3902f09e-93dc-48d3-867e-1f80d977f437) - Check that both show the same logs: ![Screenshot 2023-11-16 at 11 49 24](https://github.com/elastic/kibana/assets/16084106/d863d99f-0c70-45e5-9316-a37645464c34) ![Screenshot 2023-11-16 at 11 48 54](https://github.com/elastic/kibana/assets/16084106/7cbd0a5f-3b31-4c4d-a4b7-4eb7390983c8) **Agent logs** (Same test as above) - Enroll an agent - Click on the agent and go to the "Logs" tab - On stateful the button says "Open in Logs" ![Screenshot 2023-11-20 at 13 04 41](https://github.com/elastic/kibana/assets/16084106/6a43a062-37db-47ea-819f-acd170439395) - On serverless is "Open in discover" ![Screenshot 2023-11-20 at 13 04 11](https://github.com/elastic/kibana/assets/16084106/e15fdc8b-8780-4ac6-afc6-bff3d3a96be5) - Check that both show the same logs **Custom Logs UI** There is also a link to logs on custom logs UI but I just linked to discover for that one: https://github.com/elastic/kibana/pull/171525/files#diff-e337aa916d60d0d1033e3298c8c9c33c6a6fcd87a8ded971a4a87f5ccfc0981fR20-R22 --------- Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
3bb16c7
commit 10ec713
Showing
9 changed files
with
185 additions
and
112 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
85 changes: 85 additions & 0 deletions
85
...tions/fleet/sections/agents/agent_details_page/components/agent_logs/view_logs_button.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,85 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import url from 'url'; | ||
import { stringify } from 'querystring'; | ||
|
||
import React, { useMemo } from 'react'; | ||
import { encode } from '@kbn/rison'; | ||
import { EuiButton } from '@elastic/eui'; | ||
import { FormattedMessage } from '@kbn/i18n-react'; | ||
|
||
import { useStartServices } from '../../../../../hooks'; | ||
|
||
interface ViewLogsProps { | ||
viewInLogs: boolean; | ||
logStreamQuery: string; | ||
startTime: string; | ||
endTime: string; | ||
} | ||
|
||
/* | ||
Button that takes to the Logs view Ui when that is available, otherwise fallback to the Discover UI | ||
The urls are built using same logStreamQuery (provided by a prop), startTime and endTime, ensuring that they'll both will target same log lines | ||
*/ | ||
export const ViewLogsButton: React.FunctionComponent<ViewLogsProps> = ({ | ||
viewInLogs, | ||
logStreamQuery, | ||
startTime, | ||
endTime, | ||
}) => { | ||
const { http } = useStartServices(); | ||
|
||
// Generate URL to pass page state to Logs UI | ||
const viewInLogsUrl = useMemo( | ||
() => | ||
http.basePath.prepend( | ||
url.format({ | ||
pathname: '/app/logs/stream', | ||
search: stringify({ | ||
logPosition: encode({ | ||
start: startTime, | ||
end: endTime, | ||
streamLive: false, | ||
}), | ||
logFilter: encode({ | ||
expression: logStreamQuery, | ||
kind: 'kuery', | ||
}), | ||
}), | ||
}) | ||
), | ||
[http.basePath, startTime, endTime, logStreamQuery] | ||
); | ||
|
||
const viewInDiscoverUrl = useMemo(() => { | ||
const index = 'logs-*'; | ||
const query = encode({ | ||
query: logStreamQuery, | ||
language: 'kuery', | ||
}); | ||
return http.basePath.prepend( | ||
`/app/discover#/?_g=(filters:!(),refreshInterval:(pause:!t,value:60000),time:(from:'${startTime}',to:'${endTime}'))&_a=(columns:!(event.dataset,message),index:'${index}',query:${query})` | ||
); | ||
}, [logStreamQuery, http.basePath, startTime, endTime]); | ||
|
||
return viewInLogs ? ( | ||
<EuiButton href={viewInLogsUrl} iconType="popout" data-test-subj="viewInLogsBtn"> | ||
<FormattedMessage | ||
id="xpack.fleet.agentLogs.openInLogsUiLinkText" | ||
defaultMessage="Open in Logs" | ||
/> | ||
</EuiButton> | ||
) : ( | ||
<EuiButton href={viewInDiscoverUrl} iconType="popout" data-test-subj="viewInDiscoverBtn"> | ||
<FormattedMessage | ||
id="xpack.fleet.agentLogs.openInDiscoverUiLinkText" | ||
defaultMessage="Open in Discover" | ||
/> | ||
</EuiButton> | ||
); | ||
}; |
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.