-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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 UI] Register Logs UI Locators #155156
Merged
mohamedhamed-ahmed
merged 40 commits into
elastic:main
from
mohamedhamed-ahmed:104855-register-logs-ui-kibana-locators
May 17, 2023
Merged
Changes from 33 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
dcafc0a
[Logs UI] Register Logs UI Locators
mohamedhamed-ahmed 96beae3
Added Tests and some code refactoring
mohamedhamed-ahmed 491ae2b
Resolve Conflicts
mohamedhamed-ahmed be89547
Allow defining time range in locators
mohamedhamed-ahmed 47ec73a
Code Refactoring
mohamedhamed-ahmed 37044d0
Code Refactoring
mohamedhamed-ahmed f33bd7c
Merge branch 'main' of https://github.com/elastic/kibana into 104855-…
mohamedhamed-ahmed 1a8c68a
Merge branch 'main' of https://github.com/elastic/kibana into 104855-…
mohamedhamed-ahmed f600d36
Merge branch 'main' of https://github.com/elastic/kibana into 104855-…
mohamedhamed-ahmed 0887034
Merge branch 'main' of https://github.com/elastic/kibana into 104855-…
mohamedhamed-ahmed d93c5c9
Code Refactoring
mohamedhamed-ahmed 10eeddd
Remove unused references
mohamedhamed-ahmed 470c441
Awaited on import to lower bundle size
mohamedhamed-ahmed 8fae828
Code Refactoring
mohamedhamed-ahmed 5a16193
Added redirection to discover in serverless
mohamedhamed-ahmed 69d0f6a
Fix Tests
mohamedhamed-ahmed 2e88f65
change from and to to be timeRange
mohamedhamed-ahmed 1bee11b
Update discover redirection to support query params
mohamedhamed-ahmed b038085
bug fix
mohamedhamed-ahmed a546606
Merge Main
mohamedhamed-ahmed 2647b58
Code Refactoring
mohamedhamed-ahmed 877a9ee
Code Refactoring
mohamedhamed-ahmed ec50509
Fix bundle size
mohamedhamed-ahmed be33b45
Added support to redirection in serverless
mohamedhamed-ahmed c3cf1dc
Merge branch 'main' of https://github.com/elastic/kibana into 104855-…
mohamedhamed-ahmed d5e3554
reverted missed code
mohamedhamed-ahmed 120b8f8
Merge branch 'main' of https://github.com/elastic/kibana into 104855-…
mohamedhamed-ahmed e382fc8
Fix Review Comments
mohamedhamed-ahmed 8351cf8
Bug Fix
mohamedhamed-ahmed 455abc4
Use dynamic import
mohamedhamed-ahmed 9904a03
Merge branch 'main' of https://github.com/elastic/kibana into 104855-…
mohamedhamed-ahmed 55f2d5e
Code Refactoring and fixing comments
mohamedhamed-ahmed b6374fc
Merge branch 'main' of https://github.com/elastic/kibana into 104855-…
mohamedhamed-ahmed 6cde016
Merge branch 'main' of https://github.com/elastic/kibana into 104855-…
mohamedhamed-ahmed 5d99d46
Code Refactoring and fixing comments
mohamedhamed-ahmed 311517d
Remove unused translations
mohamedhamed-ahmed 09ed682
Code Refactoring
mohamedhamed-ahmed 6bcbfa4
Code Refactoring
mohamedhamed-ahmed 485f00d
Remove unused reference
mohamedhamed-ahmed ebeabc3
Merge Main
mohamedhamed-ahmed 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 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,137 @@ | ||
/* | ||
* 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 { waitFor } from 'xstate/lib/waitFor'; | ||
import { flowRight } from 'lodash'; | ||
import type { DiscoverAppLocatorParams } from '@kbn/discover-plugin/common'; | ||
import type { DiscoverStart } from '@kbn/discover-plugin/public'; | ||
import { MESSAGE_FIELD, TIMESTAMP_FIELD } from '../../common/constants'; | ||
import { | ||
createLogViewStateMachine, | ||
DEFAULT_LOG_VIEW, | ||
replaceLogViewInQueryString, | ||
} from '../observability_logs/log_view_state'; | ||
import { replaceLogFilterInQueryString } from '../observability_logs/log_stream_query_state'; | ||
import { replaceLogPositionInQueryString } from '../observability_logs/log_stream_position_state/src/url_state_storage_service'; | ||
import type { TimeRange } from '../../common/time'; | ||
import type { LogsLocatorParams } from './logs_locator'; | ||
import type { InfraClientCoreSetup } from '../types'; | ||
import type { | ||
LogViewColumnConfiguration, | ||
LogViewReference, | ||
ResolvedLogView, | ||
} from '../../common/log_views'; | ||
|
||
interface LocationToDiscoverParams { | ||
core: InfraClientCoreSetup; | ||
timeRange?: TimeRange; | ||
filter?: string; | ||
logView?: LogViewReference; | ||
} | ||
|
||
export const parseSearchString = ({ | ||
mohamedhamed-ahmed marked this conversation as resolved.
Show resolved
Hide resolved
|
||
time, | ||
timeRange, | ||
filter = '', | ||
logView = DEFAULT_LOG_VIEW, | ||
}: LogsLocatorParams) => { | ||
return flowRight( | ||
replaceLogFilterInQueryString({ language: 'kuery', query: filter }, time, timeRange), | ||
replaceLogPositionInQueryString(time), | ||
replaceLogViewInQueryString(logView) | ||
)(''); | ||
}; | ||
|
||
export const getLocationToDiscover = async ({ | ||
core, | ||
timeRange, | ||
filter, | ||
logView, | ||
}: LocationToDiscoverParams) => { | ||
const [, plugins, pluginStart] = await core.getStartServices(); | ||
const { discover } = plugins; | ||
const { logViews } = pluginStart; | ||
|
||
const machine = createLogViewStateMachine({ | ||
initialContext: { logViewReference: logView || DEFAULT_LOG_VIEW }, | ||
logViews: logViews.client, | ||
}); | ||
|
||
const discoverParams: DiscoverAppLocatorParams = { | ||
...(timeRange ? { from: timeRange.startTime, to: timeRange.endTime } : {}), | ||
...(filter | ||
? { | ||
query: { | ||
language: 'kuery', | ||
query: filter, | ||
}, | ||
} | ||
: {}), | ||
}; | ||
|
||
let discoverLocation; | ||
|
||
const service = interpret(machine).start(); | ||
const doneState = await waitFor( | ||
service, | ||
(state) => | ||
state.matches('checkingStatus') || | ||
state.matches('resolvedPersistedLogView') || | ||
state.matches('resolvedInlineLogView') || | ||
state.matches('loadingFailed') || | ||
state.matches('resolutionFailed') || | ||
state.matches('checkingStatusFailed') | ||
); | ||
|
||
if ('resolvedLogView' in doneState.context) { | ||
discoverLocation = await constructDiscoverLocation( | ||
discover, | ||
discoverParams, | ||
doneState.context.resolvedLogView | ||
); | ||
} else { | ||
discoverLocation = await constructDiscoverLocation(discover, discoverParams); | ||
} | ||
|
||
service.stop(); | ||
mohamedhamed-ahmed marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (!discoverLocation) { | ||
throw new Error('Discover location not found'); | ||
} | ||
|
||
return discoverLocation; | ||
}; | ||
|
||
const constructDiscoverLocation = async ( | ||
discover: DiscoverStart, | ||
discoverParams: DiscoverAppLocatorParams, | ||
resolvedLogView?: ResolvedLogView | ||
) => { | ||
const locationParams = !resolvedLogView | ||
? discoverParams | ||
: { | ||
...discoverParams, | ||
columns: parseColumns(resolvedLogView.columns), | ||
dataViewId: resolvedLogView.dataViewReference.toSpec().id, | ||
mohamedhamed-ahmed marked this conversation as resolved.
Show resolved
Hide resolved
|
||
dataViewSpec: resolvedLogView.dataViewReference.toSpec(), | ||
}; | ||
|
||
return await discover.locator?.getLocation(locationParams); | ||
}; | ||
|
||
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 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,17 @@ | ||
/* | ||
* 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 type { LogsLocator } from './logs_locator'; | ||
import type { NodeLogsLocator } from './node_logs_locator'; | ||
|
||
export * from './logs_locator'; | ||
export * from './node_logs_locator'; | ||
|
||
export interface InfraLocators { | ||
logsLocator: LogsLocator; | ||
nodeLogsLocator: NodeLogsLocator; | ||
} |
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 | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { sharePluginMock } from '@kbn/share-plugin/public/mocks'; | ||
import type { InfraLocators } from '.'; | ||
|
||
export const createLocatorMock = (): jest.Mocked<InfraLocators> => ({ | ||
logsLocator: sharePluginMock.createLocator(), | ||
nodeLogsLocator: sharePluginMock.createLocator(), | ||
}); |
Oops, something went wrong.
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.
Added the logic to the locator