-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Logs UI] Redirect Logs UI to Discover when in serverless mode #154145
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
Merged
tonyghiani
merged 36 commits into
elastic:main
from
tonyghiani:153890-redirect-logs-ui-to-discover-serverless
Apr 19, 2023
Merged
Changes from 29 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
39ba6a6
feat(infra): add logs.app_target config
f61e185
refactor(infra): stricter parameter validation
0e19e58
refactor(infra): update tests
1596b6b
refactor(infra): update functional tests
b4b21e3
chore(infra): include discover plugin to access locator
e5e0a70
feat(infra): add logs app service
e7d61b8
feat(infra): consume logs app service
539c7d9
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine e4995f7
Merge branch 'main' into 153890-redirect-logs-ui-to-discover-serverless
tonyghiani b2346f6
feat(infra): minor change
f91d543
refactor(infra): lift navigation higher in the tree
643f798
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine 7dcef58
refactor(infra): create discover app
8a0b2c3
Merge branch '153890-redirect-logs-ui-to-discover-serverless' of gith…
4c08f60
refactor(infra): fix merge conflict
e280f64
Merge branch 'main' into 153890-redirect-logs-ui-to-discover-serverless
tonyghiani 313c330
refactor(infra): stricter app mount
712783a
refactor(infra): stop machine service on unmount
6d4d032
refactor(infra): remove unused type
694b6be
refactor(infra): minor change
0e5b194
Merge branch 'main' into 153890-redirect-logs-ui-to-discover-serverless
tonyghiani 071da03
refactor(infra): remove doc for xpack.infra.logs.app_target config
19ab5a2
Merge branch 'main' into 153890-redirect-logs-ui-to-discover-serverless
tonyghiani 5d41247
Merge branch '153890-redirect-logs-ui-to-discover-serverless' of gith…
5f2d288
refactor(infra): use toSpec method to create locator config
9b363ee
refactor(infra): split logs and discover apps registrations
fef8be3
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine 7748e7e
refactor(infra): change requests
f2c2d84
Merge branch 'main' into 153890-redirect-logs-ui-to-discover-serverless
tonyghiani 9ff6c2d
refactor(infra): replace url on logs redirect
f2db6f2
refactor(infra): apply name to ad-hoc data view
0835ce5
Merge branch 'main' into 153890-redirect-logs-ui-to-discover-serverless
tonyghiani 04e9316
refactor(infra): restore log view from url
8ae8fb5
fix(fleet): mismatching config name
31a3018
Merge branch 'main' into 153890-redirect-logs-ui-to-discover-serverless
tonyghiani 36e7b92
Merge branch 'main' into 153890-redirect-logs-ui-to-discover-serverless
tonyghiani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| xpack.infra.logs.app_target: discover |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
| "charts", | ||
| "data", | ||
| "dataViews", | ||
| "discover", | ||
| "embeddable", | ||
| "features", | ||
| "lens", | ||
|
|
||
This file contains hidden or 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,76 @@ | ||
| /* | ||
| * 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 { interpret } from 'xstate'; | ||
| import type { DiscoverStart } from '@kbn/discover-plugin/public'; | ||
| import type { InfraClientStartDeps, InfraClientStartExports } from '../types'; | ||
| import type { LogViewColumnConfiguration, ResolvedLogView } from '../../common/log_views'; | ||
| import { createLogViewStateMachine, DEFAULT_LOG_VIEW } from '../observability_logs/log_view_state'; | ||
| import { MESSAGE_FIELD, TIMESTAMP_FIELD } from '../../common/constants'; | ||
|
|
||
| export const renderApp = (plugins: InfraClientStartDeps, pluginStart: InfraClientStartExports) => { | ||
| const { discover } = plugins; | ||
| const { logViews } = pluginStart; | ||
|
|
||
| const machine = createLogViewStateMachine({ | ||
| initialContext: { logViewReference: DEFAULT_LOG_VIEW }, | ||
| logViews: logViews.client, | ||
| }); | ||
|
|
||
| const service = interpret(machine) | ||
| .onTransition((state) => { | ||
| if ( | ||
| state.matches('checkingStatus') || | ||
| state.matches('resolvedPersistedLogView') || | ||
| state.matches('resolvedInlineLogView') | ||
| ) { | ||
| return redirectToDiscover(discover, state.context.resolvedLogView); | ||
| } else if ( | ||
| state.matches('loadingFailed') || | ||
| state.matches('resolutionFailed') || | ||
| state.matches('checkingStatusFailed') | ||
| ) { | ||
| return redirectToDiscover(discover); | ||
| } | ||
| }) | ||
| .start(); | ||
|
|
||
| return () => { | ||
| // Stop machine interpreter after navigation | ||
| service.stop(); | ||
| }; | ||
| }; | ||
|
|
||
| const redirectToDiscover = (discover: DiscoverStart, resolvedLogView?: ResolvedLogView) => { | ||
| if (!resolvedLogView) { | ||
| return discover.locator?.navigate({}); | ||
| } | ||
|
|
||
| const columns = parseColumns(resolvedLogView.columns); | ||
| const dataViewSpec = resolvedLogView.dataViewReference.toSpec(); | ||
|
|
||
| return discover.locator?.navigate({ | ||
| columns, | ||
| dataViewId: dataViewSpec.id, | ||
| dataViewSpec, | ||
| }); | ||
| }; | ||
|
|
||
| /** | ||
| * Helpers | ||
| */ | ||
|
|
||
| const parseColumns = (columns: ResolvedLogView['columns']) => { | ||
| return columns.map(getColumnValue).filter(Boolean) as string[]; | ||
| }; | ||
|
|
||
| const getColumnValue = (column: LogViewColumnConfiguration) => { | ||
| if ('messageColumn' in column) return MESSAGE_FIELD; | ||
| if ('timestampColumn' in column) return TIMESTAMP_FIELD; | ||
| if ('fieldColumn' in column) return column.fieldColumn.field; | ||
|
|
||
| return null; | ||
| }; | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do we need to use the log view reference from the url instead of a hard-coded default here? Or am I missing some other mechanism using which it is initialized correctly?
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 didn't think of it and you are right, it was always using the default log view, even with a different one specified in the URL. I created the
initializeFromUrlfunction and passed it to the state machine, now it does correctly recover the URL param if exists.