-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Upgrade Assistant] External links with checkpoint time-range applied #111252
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
Changes from 9 commits
061c777
91d95df
f4c14d5
b148eb2
c51fa30
ff6c599
5bbda84
273faa4
e24f9df
18d507c
8ee5104
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| * 2.0. | ||
| */ | ||
|
|
||
| import { encode } from 'rison-node'; | ||
| import React, { FunctionComponent, useState, useEffect } from 'react'; | ||
|
|
||
| import { FormattedMessage } from '@kbn/i18n/react'; | ||
|
|
@@ -17,10 +18,12 @@ import { | |
| DEPRECATION_LOGS_SOURCE_ID, | ||
| } from '../../../../../common/constants'; | ||
|
|
||
| const getDeprecationIndexPatternId = async (dataService: DataPublicPluginStart) => { | ||
| const { indexPatterns: indexPatternService } = dataService; | ||
| interface Props { | ||
| checkpoint: string; | ||
| } | ||
|
|
||
| const results = await indexPatternService.find(DEPRECATION_LOGS_INDEX_PATTERN); | ||
| const getDeprecationIndexPatternId = async (dataService: DataPublicPluginStart) => { | ||
| const results = await dataService.dataViews.find(DEPRECATION_LOGS_INDEX_PATTERN); | ||
sabarasaba marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Since the find might return also results with wildcard matchers we need to find the | ||
| // index pattern that has an exact match with our title. | ||
| const deprecationIndexPattern = results.find( | ||
|
|
@@ -30,15 +33,15 @@ const getDeprecationIndexPatternId = async (dataService: DataPublicPluginStart) | |
| if (deprecationIndexPattern) { | ||
| return deprecationIndexPattern.id; | ||
| } else { | ||
| const newIndexPattern = await indexPatternService.createAndSave({ | ||
| const newIndexPattern = await dataService.dataViews.createAndSave({ | ||
| title: DEPRECATION_LOGS_INDEX_PATTERN, | ||
| allowNoIndex: true, | ||
| }); | ||
| return newIndexPattern.id; | ||
| } | ||
| }; | ||
|
|
||
| const DiscoverAppLink: FunctionComponent = () => { | ||
| const DiscoverAppLink: FunctionComponent<Props> = ({ checkpoint }) => { | ||
| const { | ||
| services: { data: dataService }, | ||
| plugins: { share }, | ||
|
|
@@ -55,12 +58,19 @@ const DiscoverAppLink: FunctionComponent = () => { | |
| return; | ||
| } | ||
|
|
||
| const url = await locator.getUrl({ indexPatternId }); | ||
| const url = await locator.getUrl({ | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dug a bit into
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps in a separate PR we can change https://github.com/elastic/kibana/blob/master/src/plugins/share/common/url_service/locators/use_locator_url.ts#L42 to define the dependencies more comprehensively: // Convert params object to string to be able to compare its value,
// allowing the consumer to freely pass new objects to the hook on each
// render without requiring it to be memoized.
const paramsStringified = params ? JSON.stringify(params) : undefined;
/* eslint-disable react-hooks/exhaustive-deps */
useEffect(() => {
if (!locator) {
setUrl('');
return;
}
locator
.getUrl(params, getUrlParams)
.then((result: string) => {
if (!isMounted()) return;
setUrl(result);
})
.catch((error) => {
if (!isMounted()) return;
// eslint-disable-next-line no-console
console.error('useLocatorUrl', error);
setUrl('');
});
}, [locator, paramsStringified, ...deps]);
/* eslint-enable react-hooks/exhaustive-deps */This would allow us to consume the hook, since it will update once the /*
* All this code replaces the current `useEffect`
*/
const [indexPatternId, setIndexPatternId] = useState<string | undefined>();
useEffect(() => {
async function fetchIndexPatternId() {
setIndexPatternId(await getDeprecationIndexPatternId(dataService));
}
fetchIndexPatternId();
}, []);
const locator = share.url.locators.get('DISCOVER_APP_LOCATOR');
const discoverUrl = locator?.useUrl({
indexPatternId,
query: {
language: 'kuery',
query: `@timestamp > "${lastCheckpoint}"`,
},
});
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍🏼 I've created #111512 to track that |
||
| indexPatternId, | ||
| query: { | ||
| language: 'kuery', | ||
| query: `@timestamp > "${checkpoint}"`, | ||
| }, | ||
| }); | ||
|
|
||
| setDiscoveryUrl(url); | ||
| }; | ||
|
|
||
| getDiscoveryUrl(); | ||
| }, [dataService, share.url.locators]); | ||
| }, [dataService, checkpoint, share.url.locators]); | ||
|
|
||
| return ( | ||
| <EuiLink href={discoveryUrl} data-test-subj="viewDiscoverLogs"> | ||
|
|
@@ -72,14 +82,16 @@ const DiscoverAppLink: FunctionComponent = () => { | |
| ); | ||
| }; | ||
|
|
||
| const ObservabilityAppLink: FunctionComponent = () => { | ||
| const ObservabilityAppLink: FunctionComponent<Props> = ({ checkpoint }) => { | ||
| const { | ||
| services: { | ||
| core: { http }, | ||
| }, | ||
| } = useAppContext(); | ||
| const logStreamUrl = http?.basePath?.prepend( | ||
| `/app/logs/stream?sourceId=${DEPRECATION_LOGS_SOURCE_ID}` | ||
| `/app/logs/stream?sourceId=${DEPRECATION_LOGS_SOURCE_ID}&logPosition=(end:now,start:${encode( | ||
sabarasaba marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| checkpoint | ||
| )})` | ||
| ); | ||
|
|
||
| return ( | ||
|
|
@@ -92,7 +104,7 @@ const ObservabilityAppLink: FunctionComponent = () => { | |
| ); | ||
| }; | ||
|
|
||
| export const ExternalLinks: FunctionComponent = () => { | ||
| export const ExternalLinks: FunctionComponent<Props> = ({ checkpoint }) => { | ||
| return ( | ||
| <EuiFlexGroup> | ||
| <EuiFlexItem> | ||
|
|
@@ -106,7 +118,7 @@ export const ExternalLinks: FunctionComponent = () => { | |
| </p> | ||
| </EuiText> | ||
| <EuiSpacer size="m" /> | ||
| <ObservabilityAppLink /> | ||
| <ObservabilityAppLink checkpoint={checkpoint} /> | ||
| </EuiPanel> | ||
| </EuiFlexItem> | ||
| <EuiFlexItem> | ||
|
|
@@ -120,7 +132,7 @@ export const ExternalLinks: FunctionComponent = () => { | |
| </p> | ||
| </EuiText> | ||
| <EuiSpacer size="m" /> | ||
| <DiscoverAppLink /> | ||
| <DiscoverAppLink checkpoint={checkpoint} /> | ||
| </EuiPanel> | ||
| </EuiFlexItem> | ||
| </EuiFlexGroup> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| * 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 moment from 'moment-timezone'; | ||
|
|
||
| import { Storage } from '../../shared_imports'; | ||
|
|
||
| const SETTING_ID = 'kibana.upgradeAssistant.lastCheckpoint'; | ||
| const localStorage = new Storage(window.localStorage); | ||
|
|
||
| export const loadLogsCheckpoint = () => { | ||
| const storedValue = moment(localStorage.get(SETTING_ID)); | ||
|
|
||
| if (storedValue.isValid()) { | ||
| return storedValue.toISOString(); | ||
| } | ||
|
|
||
| const now = moment().toISOString(); | ||
| localStorage.set(SETTING_ID, now); | ||
|
|
||
| return now; | ||
| }; | ||
|
|
||
| export const saveLogsCheckpoint = (value: string) => { | ||
| localStorage.set(SETTING_ID, value); | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this name makes more sense if the function returns a string. In #111252 (comment) I suggested moving
new URLSearchParams().toString()into the function to accomplish that -- WDYT?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somehow I miss read the previous comment, i patched that up and will merge when ci finishes 🚀