Skip to content
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

[Discover] Add logs source and document contexts #184601

Merged
merged 67 commits into from
Jun 18, 2024
Merged
Changes from 1 commit
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
9e823b9
Initial pass at context provider services
davismcphee May 13, 2024
12e56b1
Initial context awareness implementation
davismcphee May 14, 2024
83f0696
Add profile service
davismcphee May 15, 2024
0a44de8
Add use_profile_accessor
davismcphee May 15, 2024
226cdd7
Add custom cell renderers and grid flyout
davismcphee May 15, 2024
4ca0e67
Attach document profiles to data table records
davismcphee May 16, 2024
f64aef3
Make root profile service async and add profiles provider
davismcphee May 16, 2024
ae19e34
Make data source profile service async and set it via profiles provider
davismcphee May 16, 2024
cbf6601
Move example profiles to separate file
davismcphee May 16, 2024
926ad4a
Improve example profiles
davismcphee May 17, 2024
d8fbdb7
Add default columns extension
davismcphee May 17, 2024
3afc77e
Don't display message field in cell renderer
davismcphee May 18, 2024
defad74
Add ProfilesManager
davismcphee May 19, 2024
efa94d1
Use ProfilesManager for accessing and setting profiles
davismcphee May 19, 2024
0115332
Change tsx files to ts
davismcphee May 21, 2024
fbf856b
Handle ProfilesManager abort controllers internally
davismcphee May 21, 2024
9c1b031
Rename ProfilesManager methods
davismcphee May 21, 2024
ff8aaeb
Remove static profile services and instead instantiate them in plugin…
davismcphee May 22, 2024
0964db1
Don't export useProfiles
davismcphee May 22, 2024
35f58a1
Retrieve ProfilesManager from services
davismcphee May 22, 2024
6a871aa
Remove show_confirm_panel since it's no longer used
davismcphee May 22, 2024
2e0b76e
Rename contextCollector to proflesCollector
davismcphee May 22, 2024
2db3ecc
Revert discover_data_state_container change
davismcphee May 22, 2024
2ea64d1
Fix broken types, Jest tests, and translations
davismcphee May 22, 2024
7e93b69
Simplify useProfileAccessor
davismcphee May 27, 2024
53ffd34
Attach context with profile ID to data table records
davismcphee May 28, 2024
19eba4c
Don't retrigger useProfiles on init
davismcphee May 28, 2024
4321c75
Move data source resolution before data fetching
davismcphee May 28, 2024
faa68c2
Log and fallback to default on context resolution failure
davismcphee May 30, 2024
e953b41
Remove profile provider ordering
davismcphee May 30, 2024
a5f2de8
Add profiles support to saved search embeddable
davismcphee May 30, 2024
fcc8ebc
Add Jest tests
davismcphee May 31, 2024
3d8ff5a
Clean up ProfilesManager
davismcphee May 31, 2024
15ea447
Add skeleton of logs profile providers
weltenwort May 31, 2024
3ce74dd
Set codeowners for the logs providers
weltenwort May 31, 2024
45b618b
feat(kbn-data-view-utils): add createRegExpPatternFrom util
May 31, 2024
c05c675
feat(kbn-data-view-utils): update createRegExpPatternFrom to support …
Jun 3, 2024
bb7d439
feat(kbn-data-view-utils): add testPatternAgainstAllowedList utils
Jun 3, 2024
314b033
refactor(logs_explorer): replace logs pattern matching utilities
Jun 3, 2024
5ecc0dd
implement actual log document resolution logic
weltenwort Jun 3, 2024
516e996
feat(discover): add initial logs data source resolution
Jun 4, 2024
e443c32
refactor(discover): extract types to resolve cyclic imports
Jun 4, 2024
c2ebbde
refactor(discover): update logs data source provider to factory function
Jun 4, 2024
5905c46
refactor(discover): move logs context utils into kbn-discover-utils
Jun 4, 2024
69d655d
refactor(discover): update logs document profile to use logs context …
Jun 4, 2024
2f68870
refactor(discover): update profiles imports/exports
Jun 5, 2024
28a5d2f
refactor(discover): update type predicates
Jun 6, 2024
08db9ae
Merge branch 'main' into one-discover-logs-contexts
tonyghiani Jun 11, 2024
5a32251
refactor(discover): update duplicate code
Jun 11, 2024
f657706
refactor(discover): revert changes missed in rebase
Jun 11, 2024
8ef60f2
refactor(discover): revert changes missed in rebase
Jun 11, 2024
7283f3c
refactor(discover): revert changes missed in rebase
Jun 11, 2024
9d09a4d
refactor(discover): fix linting issues
Jun 11, 2024
c3c9f61
Merge branch 'main' into one-discover-logs-contexts
tonyghiani Jun 11, 2024
4b925c9
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Jun 11, 2024
326ac11
[CI] Auto-commit changed files from 'node scripts/generate codeowners'
kibanamachine Jun 11, 2024
07a6ecc
Merge branch 'main' into one-discover-logs-contexts
tonyghiani Jun 11, 2024
6957b86
refactor(logs-explorer): fix usage of logs criteria
Jun 11, 2024
23ad7d3
refactor(logs-explorer): update broken imports and tests
Jun 11, 2024
aab6cb6
Merge branch 'main' into one-discover-logs-contexts
tonyghiani Jun 11, 2024
baf9613
refactor(logs-explorer): revert test change
Jun 11, 2024
db98177
refactor(discover): update regexp to match potential _ in word bounda…
Jun 13, 2024
9ecedd5
Merge branch 'main' into one-discover-logs-contexts
tonyghiani Jun 13, 2024
f2f5462
Update packages/kbn-data-view-utils/src/utils/create_regexp_pattern_f…
tonyghiani Jun 13, 2024
f55015f
Merge branch 'main' into one-discover-logs-contexts
tonyghiani Jun 17, 2024
d7c7f55
Merge branch 'main' into one-discover-logs-contexts
tonyghiani Jun 17, 2024
35a32ce
Merge branch 'main' into one-discover-logs-contexts
davismcphee Jun 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Attach context with profile ID to data table records
davismcphee committed May 30, 2024
commit 53ffd34c1cf9c64ea0edbdaea0398f62432505f6
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
* Side Public License, v 1.
*/
import { i18n } from '@kbn/i18n';
import { filter, map, tap } from 'rxjs';
import { filter, map } from 'rxjs';
import { lastValueFrom } from 'rxjs';
import { isRunningResponse, ISearchSource } from '@kbn/data-plugin/public';
import { buildDataTableRecordList } from '@kbn/discover-utils';
@@ -44,8 +44,6 @@ export const fetchDocuments = (
description: isFetchingMore ? 'fetch more documents' : 'fetch documents',
};

const profilesCollector = services.profilesManager.createDocumentProfilesCollector();

const fetch$ = searchSource
.fetch$({
abortSignal: abortController.signal,
@@ -71,13 +69,10 @@ export const fetchDocuments = (
map((res) => {
return buildDataTableRecordList(res.rawResponse.hits.hits as EsHitRecord[], dataView, {
processRecord: (record) => {
profilesCollector.collect({ record });
services.profilesManager.resolveDocumentProfile({ record });
return record;
},
});
}),
tap(() => {
profilesCollector.finalize(!isFetchingMore);
})
);

Original file line number Diff line number Diff line change
@@ -62,7 +62,6 @@ export function fetchEsql(
let esqlQueryColumns: Datatable['columns'] | undefined;
let error: string | undefined;
let esqlHeaderWarning: string | undefined;
const profilesCollector = profilesManager.createDocumentProfilesCollector();
execution.pipe(pluck('result')).subscribe((resp) => {
const response = resp as Datatable | EsqlErrorResponse;
if (response.type === 'error') {
@@ -79,7 +78,7 @@ export function fetchEsql(
flattened: row,
};

profilesCollector.collect({ record });
profilesManager.resolveDocumentProfile({ record });

return record;
});
@@ -89,8 +88,6 @@ export function fetchEsql(
if (error) {
throw new Error(error);
} else {
profilesCollector.finalize(true);

return {
records: finalData || [],
esqlQueryColumns,
4 changes: 2 additions & 2 deletions src/plugins/discover/public/context_awareness/index.ts
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@

export * from './types';
export * from './profiles';
export { type ComposableProfile, getMergedAccessor } from './composable_profile';
export { type GetProfilesOptions, ProfilesManager } from './profiles_manager';
export { getMergedAccessor } from './composable_profile';
export { ProfilesManager } from './profiles_manager';
export { useProfileAccessor } from './hooks/use_profile_accessor';
export { useRootProfile } from './hooks/use_root_profile';
36 changes: 27 additions & 9 deletions src/plugins/discover/public/context_awareness/profile_service.ts
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@ export interface ProfileProvider<
TMode extends ProfileProviderMode
> {
order: number;
profileId: string;
profile: ComposableProfile<TProfile>;
resolve: (
params: TParams
@@ -32,6 +33,10 @@ export interface ProfileProvider<
: ResolveProfileResult<TContext> | Promise<ResolveProfileResult<TContext>>;
}

export type ContextWithProfileId<TContext> = TContext & { profileId: string };

const EMPTY_PROFILE = {};

abstract class BaseProfileService<
TProfile extends PartialProfile,
TParams,
@@ -40,33 +45,43 @@ abstract class BaseProfileService<
> {
protected readonly providers: Array<ProfileProvider<TProfile, TParams, TContext, TMode>> = [];

protected constructor(public readonly defaultContext: ContextWithProfileId<TContext>) {}

public registerProvider(provider: ProfileProvider<TProfile, TParams, TContext, TMode>) {
this.providers.push(provider);
this.providers.sort((a, b) => a.order - b.order);
}

public getProfile(context: ContextWithProfileId<TContext>): ComposableProfile<Profile> {
const provider = this.providers.find((current) => current.profileId === context.profileId);
return provider?.profile ?? EMPTY_PROFILE;
}

public abstract resolve(
params: TParams
): TMode extends 'sync' ? ComposableProfile<Profile> : Promise<ComposableProfile<Profile>>;
): TMode extends 'sync'
? ContextWithProfileId<TContext>
: Promise<ContextWithProfileId<TContext>>;
}

const EMPTY_PROFILE = {};

export class ProfileService<
TProfile extends PartialProfile,
TParams,
TContext
> extends BaseProfileService<TProfile, TParams, TContext, 'sync'> {
public resolve(params: TParams): ComposableProfile<Profile> {
public resolve(params: TParams) {
for (const provider of this.providers) {
const result = provider.resolve(params);

if (result.isMatch) {
return provider.profile as ComposableProfile<Profile>;
return {
...result.context,
profileId: provider.profileId,
};
}
}

return EMPTY_PROFILE;
return this.defaultContext;
}
}

@@ -75,15 +90,18 @@ export class AsyncProfileService<
TParams,
TContext
> extends BaseProfileService<TProfile, TParams, TContext, 'async'> {
public async resolve(params: TParams): Promise<ComposableProfile<Profile>> {
public async resolve(params: TParams) {
for (const provider of this.providers) {
const result = await provider.resolve(params);

if (result.isMatch) {
return provider.profile as ComposableProfile<Profile>;
return {
...result.context,
profileId: provider.profileId,
};
}
}

return EMPTY_PROFILE;
return this.defaultContext;
}
}
Original file line number Diff line number Diff line change
@@ -33,6 +33,13 @@ export class DataSourceProfileService extends AsyncProfileService<
DataSourceProfile,
DataSourceProfileProviderParams,
DataSourceContext
> {}
> {
constructor() {
super({
profileId: 'default-data-source-profile',
category: DataSourceCategory.Default,
});
}
}

export type DataSourceProfileProvider = Parameters<DataSourceProfileService['registerProvider']>[0];
Original file line number Diff line number Diff line change
@@ -29,6 +29,13 @@ export class DocumentProfileService extends ProfileService<
DocumentProfile,
DocumentProfileProviderParams,
DocumentContext
> {}
> {
constructor() {
super({
profileId: 'default-document-profile',
type: DocumentType.Default,
});
}
}

export type DocumentProfileProvider = Parameters<DocumentProfileService['registerProvider']>[0];
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@ import { RootProfileProvider, SolutionType } from './root_profile';

export const o11yRootProfileProvider: RootProfileProvider = {
order: 0,
profileId: 'o11y-root-profile',
profile: {
getTopNavItems: (prev) => () =>
[
@@ -53,6 +54,7 @@ export const o11yRootProfileProvider: RootProfileProvider = {

export const logsDataSourceProfileProvider: DataSourceProfileProvider = {
order: 0,
profileId: 'logs-data-source-profile',
profile: {
getTopNavItems: (prev) => () =>
[
@@ -138,6 +140,7 @@ export const logsDataSourceProfileProvider: DataSourceProfileProvider = {

export const logDocumentProfileProvider: DocumentProfileProvider = {
order: 0,
profileId: 'log-document-profile',
profile: {
getDocViewsRegistry: (prev) => (registry) => {
registry.enableById('doc_view_logs_overview');
Original file line number Diff line number Diff line change
@@ -30,6 +30,13 @@ export class RootProfileService extends AsyncProfileService<
RootProfile,
RootProfileProviderParams,
RootContext
> {}
> {
constructor() {
super({
profileId: 'default-root-profile',
solutionType: SolutionType.Default,
});
}
}

export type RootProfileProvider = Parameters<RootProfileService['registerProvider']>[0];
Loading