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 support for log overview tab to Discover log profile #186680

Merged
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,15 @@ export const exampleDataSourceProfileProvider: DataSourceProfileProvider = {
return {
title: `Record #${recordId}`,
docViewsRegistry: (registry) => {
registry.enableById('doc_view_logs_overview');
registry.add({
id: 'doc_view_example',
title: 'Example',
order: 0,
component: () => (
<div data-test-subj="exampleDataSourceProfileDocView">Example Doc View</div>
),
});

return prevValue.docViewsRegistry(registry);
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ export const exampleDocumentProfileProvider: DocumentProfileProvider = {
profileId: 'example-document-profile',
profile: {},
resolve: (params) => {
if (getFieldValue(params.record, 'data_stream.type') !== 'logs') {
if (getFieldValue(params.record, 'data_stream.type') !== 'example') {
return { isMatch: false };
}

return {
isMatch: true,
context: {
type: DocumentType.Log,
type: DocumentType.Default,
},
};
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { i18n } from '@kbn/i18n';
import { UnifiedDocViewerLogsOverview } from '@kbn/unified-doc-viewer-plugin/public';
import React from 'react';
import type { DocumentProfileProvider } from '../../../profiles';

export const getDocViewer: DocumentProfileProvider['profile']['getDocViewer'] =
(prev) => (params) => {
const prevDocViewer = prev(params);

return {
...prevDocViewer,
docViewsRegistry: (registry) => {
registry.add({
id: 'doc_view_logs_overview',
title: i18n.translate('discover.docViews.logsOverview.title', {
defaultMessage: 'Log overview',
}),
order: 0,
component: (props) => <UnifiedDocViewerLogsOverview {...props} />,
});

return prevDocViewer.docViewsRegistry(registry);
},
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export { getDocViewer } from './get_doc_viewer';
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import { buildDataTableRecord } from '@kbn/discover-utils';
import { DocViewsRegistry } from '@kbn/unified-doc-viewer';
import { DocumentType } from '../../profiles';
import { createContextAwarenessMocks } from '../../__mocks__';
import { createLogDocumentProfileProvider } from './profile';
Expand Down Expand Up @@ -65,6 +66,32 @@ describe('logDocumentProfileProvider', () => {
})
).toEqual(RESOLUTION_MISMATCH);
});

describe('getDocViewer', () => {
it('adds a log overview doc view to the registry', () => {
const getDocViewer = logDocumentProfileProvider.profile.getDocViewer!(() => ({
title: 'test title',
docViewsRegistry: (registry) => registry,
}));
const docViewer = getDocViewer({
record: buildDataTableRecord({}),
});
const registry = new DocViewsRegistry();

expect(docViewer.title).toBe('test title');
expect(registry.getAll()).toHaveLength(0);
docViewer.docViewsRegistry(registry);
expect(registry.getAll()).toHaveLength(1);
expect(registry.getAll()[0]).toEqual(
expect.objectContaining({
id: 'doc_view_logs_overview',
title: 'Log overview',
order: 0,
component: expect.any(Function),
})
);
});
});
});

const buildMockRecord = (index: string, fields: Record<string, unknown[]> = {}) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
import { DataTableRecord } from '@kbn/discover-utils';
import { DocumentProfileProvider, DocumentType } from '../../profiles';
import { ProfileProviderServices } from '../profile_provider_services';
import { getDocViewer } from './accessors';

export const createLogDocumentProfileProvider = (
services: ProfileProviderServices
): DocumentProfileProvider => ({
profileId: 'log-document-profile',
profile: {},
profile: {
getDocViewer,
},
resolve: ({ record }) => {
const isLogRecord = getIsLogRecord(record, services.logsContextService.isLogsIndexPattern);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('registerProfileProviders', () => {
const documentContext = documentProfileServiceMock.resolve({
record: {
id: 'test',
flattened: { 'data_stream.type': 'logs' },
flattened: { 'data_stream.type': 'example' },
raw: {},
},
});
Expand Down Expand Up @@ -100,7 +100,7 @@ describe('registerProfileProviders', () => {
const documentContext = documentProfileServiceMock.resolve({
record: {
id: 'test',
flattened: { 'data_stream.type': 'logs' },
flattened: { 'data_stream.type': 'example' },
raw: {},
},
});
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/unified_doc_viewer/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"server": false,
"browser": true,
"requiredBundles": ["kibanaUtils"],
"requiredPlugins": ["data", "discoverShared", "fieldFormats", "share"],
"requiredPlugins": ["data", "fieldFormats", "share"],
"optionalPlugins": ["fieldsMetadata"]
}
}
2 changes: 0 additions & 2 deletions src/plugins/unified_doc_viewer/public/__mocks__/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import { analyticsServiceMock } from '@kbn/core-analytics-browser-mocks';
import { dataPluginMock } from '@kbn/data-plugin/public/mocks';
import { discoverSharedPluginMock } from '@kbn/discover-shared-plugin/public/mocks';
import { fieldFormatsMock } from '@kbn/field-formats-plugin/common/mocks';
import { fieldsMetadataPluginPublicMock } from '@kbn/fields-metadata-plugin/public/mocks';
import { uiSettingsServiceMock } from '@kbn/core-ui-settings-browser-mocks';
Expand All @@ -24,7 +23,6 @@ export const mockUnifiedDocViewer: jest.Mocked<UnifiedDocViewerStart> = {
export const mockUnifiedDocViewerServices: jest.Mocked<UnifiedDocViewerServices> = {
analytics: analyticsServiceMock.createAnalyticsServiceStart(),
data: dataPluginMock.createStartContract(),
discoverShared: discoverSharedPluginMock.createStartContract(),
fieldFormats: fieldFormatsMock,
fieldsMetadata: fieldsMetadataPluginPublicMock.createStartContract(),
storage: new Storage(localStorage),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { LogsOverview } from './logs_overview';

// Required for usage in React.lazy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,29 @@ import React from 'react';
import { DocViewRenderProps } from '@kbn/unified-doc-viewer/types';
import { getLogDocumentOverview } from '@kbn/discover-utils';
import { EuiHorizontalRule, EuiSpacer } from '@elastic/eui';
import { ObservabilityLogsAIAssistantFeatureRenderDeps } from '@kbn/discover-shared-plugin/public';
import { LogsOverviewHeader } from './logs_overview_header';
import { LogsOverviewHighlights } from './logs_overview_highlights';
import { FieldActionsProvider } from '../../hooks/use_field_actions';
import { getUnifiedDocViewerServices } from '../../plugin';
import { LogsOverviewAIAssistant } from './logs_overview_ai_assistant';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

This file could be removed right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it can, removed here: 97ba3c1.

import { LogsOverviewDegradedFields } from './logs_overview_degraded_fields';

export type LogsOverviewProps = DocViewRenderProps & {
renderAIAssistant?: (deps: ObservabilityLogsAIAssistantFeatureRenderDeps) => JSX.Element;
};

export function LogsOverview({
columns,
dataView,
hit,
filter,
onAddColumn,
onRemoveColumn,
}: DocViewRenderProps) {
renderAIAssistant,
}: LogsOverviewProps) {
const { fieldFormats } = getUnifiedDocViewerServices();
const parsedDoc = getLogDocumentOverview(hit, { dataView, fieldFormats });
const LogsOverviewAIAssistant = renderAIAssistant;

return (
<FieldActionsProvider
Expand All @@ -40,7 +46,7 @@ export function LogsOverview({
<EuiHorizontalRule margin="xs" />
<LogsOverviewHighlights formattedDoc={parsedDoc} flattenedDoc={hit.flattened} />
<LogsOverviewDegradedFields rawDoc={hit.raw} />
<LogsOverviewAIAssistant doc={hit} />
{LogsOverviewAIAssistant && <LogsOverviewAIAssistant doc={hit} />}
</FieldActionsProvider>
);
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import React from 'react';
import { EuiDelayRender, EuiSkeletonText } from '@elastic/eui';
import { dynamic } from '@kbn/shared-ux-utility';

export const UnifiedDocViewerLogsOverview = dynamic(() => import('./doc_viewer_logs_overview'), {
fallback: (
<EuiDelayRender delay={300}>
<EuiSkeletonText />
</EuiDelayRender>
),
});
3 changes: 3 additions & 0 deletions src/plugins/unified_doc_viewer/public/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ export { useEsDocSearch } from './hooks';
export { UnifiedDocViewer } from './components/lazy_doc_viewer';
export { UnifiedDocViewerFlyout } from './components/lazy_doc_viewer_flyout';

export type { LogsOverviewProps as UnifiedDocViewerLogsOverviewProps } from './components/doc_viewer_logs_overview/logs_overview';
export { UnifiedDocViewerLogsOverview } from './components/lazy_doc_viewer_logs_overview';

export const plugin = () => new UnifiedDocViewerPublicPlugin();
20 changes: 1 addition & 19 deletions src/plugins/unified_doc_viewer/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { DataPublicPluginStart } from '@kbn/data-plugin/public';
import { FieldFormatsStart } from '@kbn/field-formats-plugin/public';
import { CoreStart } from '@kbn/core/public';
import { dynamic } from '@kbn/shared-ux-utility';
import { DiscoverSharedPublicStart } from '@kbn/discover-shared-plugin/public';
import { FieldsMetadataPublicStart } from '@kbn/fields-metadata-plugin/public';
import { SharePluginStart } from '@kbn/share-plugin/public';
import type { UnifiedDocViewerServices } from './types';
Expand All @@ -31,9 +30,6 @@ const fallback = (
</EuiDelayRender>
);

const LazyDocViewerLogsOverview = dynamic(() => import('./components/doc_viewer_logs_overview'), {
fallback,
});
const LazyDocViewerLegacyTable = dynamic(() => import('./components/doc_viewer_table/legacy'), {
fallback,
});
Expand All @@ -50,7 +46,6 @@ export interface UnifiedDocViewerStart {

export interface UnifiedDocViewerStartDeps {
data: DataPublicPluginStart;
discoverShared: DiscoverSharedPublicStart;
fieldFormats: FieldFormatsStart;
fieldsMetadata: FieldsMetadataPublicStart;
share: SharePluginStart;
Expand All @@ -62,18 +57,6 @@ export class UnifiedDocViewerPublicPlugin
private docViewsRegistry = new DocViewsRegistry();

public setup(core: CoreSetup<UnifiedDocViewerStartDeps, UnifiedDocViewerStart>) {
this.docViewsRegistry.add({
id: 'doc_view_logs_overview',
title: i18n.translate('unifiedDocViewer.docViews.logsOverview.title', {
defaultMessage: 'Overview',
}),
order: 0,
enabled: false, // Disabled doc view by default, can be programmatically enabled using the DocViewsRegistry.prototype.enableById method.
component: (props) => {
return <LazyDocViewerLogsOverview {...props} />;
},
});

this.docViewsRegistry.add({
id: 'doc_view_table',
title: i18n.translate('unifiedDocViewer.docViews.table.tableTitle', {
Expand Down Expand Up @@ -123,15 +106,14 @@ export class UnifiedDocViewerPublicPlugin

public start(core: CoreStart, deps: UnifiedDocViewerStartDeps) {
const { analytics, uiSettings } = core;
const { data, discoverShared, fieldFormats, fieldsMetadata, share } = deps;
const { data, fieldFormats, fieldsMetadata, share } = deps;
const storage = new Storage(localStorage);
const unifiedDocViewer = {
registry: this.docViewsRegistry,
};
const services = {
analytics,
data,
discoverShared,
fieldFormats,
fieldsMetadata,
storage,
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/unified_doc_viewer/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export type { UnifiedDocViewerSetup, UnifiedDocViewerStart } from './plugin';

import type { AnalyticsServiceStart } from '@kbn/core-analytics-browser';
import type { DataPublicPluginStart } from '@kbn/data-plugin/public';
import type { DiscoverSharedPublicStart } from '@kbn/discover-shared-plugin/public';
import type { FieldFormatsStart } from '@kbn/field-formats-plugin/public';
import type { FieldsMetadataPublicStart } from '@kbn/fields-metadata-plugin/public';
import type { Storage } from '@kbn/kibana-utils-plugin/public';
Expand All @@ -22,7 +21,6 @@ import type { UnifiedDocViewerStart } from './plugin';
export interface UnifiedDocViewerServices {
analytics: AnalyticsServiceStart;
data: DataPublicPluginStart;
discoverShared: DiscoverSharedPublicStart;
fieldFormats: FieldFormatsStart;
fieldsMetadata: FieldsMetadataPublicStart;
storage: Storage;
Expand Down
3 changes: 1 addition & 2 deletions test/accessibility/apps/discover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

// adding a11y tests for the new data grid
it('a11y test on single document view', async () => {
await testSubjects.click('docTableExpandToggleColumn');
await PageObjects.discover.clickDocViewerTab('doc_view_table');
await dataGrid.clickRowToggle();
await a11y.testAppSnapshot();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const deployment = getService('deployment');
const retry = getService('retry');
const security = getService('security');
const dataGrid = getService('dataGrid');

const checkUrl = async (fieldValue: string) => {
const windowHandlers = await browser.getAllWindowHandles();
Expand Down Expand Up @@ -79,16 +80,16 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await common.setTime({ from, to });
await common.navigateToApp('discover');
await discover.selectIndexPattern('logstash-*');
await testSubjects.click('docTableExpandToggleColumn');
await dataGrid.clickRowToggle();
await retry.waitForWithTimeout(`${fieldName} is visible`, 30000, async () => {
return await testSubjects.isDisplayed(`tableDocViewRow-${fieldName}-value`);
});
const fieldLink = await find.byCssSelector(
`[data-test-subj="tableDocViewRow-${fieldName}-value"] a`
);
const fieldValue = await fieldLink.getVisibleText();
await fieldLink.click();
await retry.try(async () => {
await fieldLink.click();
await checkUrl(fieldValue);
});
});
Expand Down
Loading