Skip to content

Commit

Permalink
[One Discover] Add app menu actions for Observability projects (elast…
Browse files Browse the repository at this point in the history
…ic#198987)

## 📓 Summary

Closes elastic#182230 

This work introduces a new observability root profile and uses the new
extension point to register custom actions on the app menu.
The registered actions and link will appear only with the new project
navigation enabled on an Observability project:
- A link to the data sets quality page
- On the alerts sub menu...
- replace the default search rule creation with the observability custom
threshold rule
  - add an entry to directly create an SLO for the current search

To access the SLO capabilities without breaking the dependencies
hierarchy of the new sustainable architecture, the feature is registered
by the common plugin `discover-shared` in SLO and consumed then by
Discover using the IoC principle.

## 🖼️ Screenshots

### Observability project solution - show new menu

<img width="3004" alt="Screenshot 2024-11-06 at 12 37 02"
src="https://github.com/user-attachments/assets/d70b532d-1889-4d5b-b2ee-de2f048560f4">

### Search project solution - hide new menu

<img width="3006" alt="Screenshot 2024-11-06 at 12 36 19"
src="https://github.com/user-attachments/assets/660893c3-f6b5-4b06-b8de-50a61a6bdb98">

### Default navigation mode - hide new menu

<img width="3002" alt="Screenshot 2024-11-06 at 12 35 43"
src="https://github.com/user-attachments/assets/674c5a08-0084-40e5-ae34-a56c363cacce">

## 🎥  Demo


https://github.com/user-attachments/assets/104e6074-0401-4fd2-a8e6-8b05f2c070d7

---------

Co-authored-by: Marco Antonio Ghiani <[email protected]>
Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
3 people authored Nov 14, 2024
1 parent 68d95e4 commit 9d38922
Show file tree
Hide file tree
Showing 20 changed files with 424 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/plugins/discover/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"charts",
"data",
"dataViews",
"discoverShared",
"embeddable",
"inspector",
"fieldFormats",
Expand All @@ -30,7 +31,7 @@
"unifiedDocViewer",
"unifiedSearch",
"unifiedHistogram",
"contentManagement"
"contentManagement",
],
"optionalPlugins": [
"dataVisualizer",
Expand All @@ -46,7 +47,7 @@
"observabilityAIAssistant",
"aiops",
"fieldsMetadata",
"logsDataAccess"
"logsDataAccess",
],
"requiredBundles": [
"kibanaUtils",
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/discover/public/build_services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import type { AiopsPluginStart } from '@kbn/aiops-plugin/public';
import type { DataVisualizerPluginStart } from '@kbn/data-visualizer-plugin/public';
import type { FieldsMetadataPublicStart } from '@kbn/fields-metadata-plugin/public';
import { LogsDataAccessPluginStart } from '@kbn/logs-data-access-plugin/public';
import { DiscoverSharedPublicStart } from '@kbn/discover-shared-plugin/public';
import type { DiscoverStartPlugins } from './types';
import type { DiscoverContextAppLocator } from './application/context/services/locator';
import type { DiscoverSingleDocLocator } from './application/doc/locator';
Expand Down Expand Up @@ -89,6 +90,7 @@ export interface DiscoverServices {
chrome: ChromeStart;
core: CoreStart;
data: DataPublicPluginStart;
discoverShared: DiscoverSharedPublicStart;
docLinks: DocLinksStart;
embeddable: EmbeddableStart;
history: History<HistoryLocationState>;
Expand Down Expand Up @@ -178,6 +180,7 @@ export const buildServices = memoize(
core,
data: plugins.data,
dataVisualizer: plugins.dataVisualizer,
discoverShared: plugins.discoverShared,
docLinks: core.docLinks,
embeddable: plugins.embeddable,
i18n: core.i18n,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { AppMenuActionId, AppMenuActionType, AppMenuRegistry } from '@kbn/discover-utils';
import { DATA_QUALITY_LOCATOR_ID, DataQualityLocatorParams } from '@kbn/deeplinks-observability';
import { OBSERVABILITY_THRESHOLD_RULE_TYPE_ID } from '@kbn/rule-data-utils';
import { isOfQueryType } from '@kbn/es-query';
import { i18n } from '@kbn/i18n';
import { AppMenuExtensionParams } from '../../../..';
import type { RootProfileProvider } from '../../../../profiles';
import { ProfileProviderServices } from '../../../profile_provider_services';

export const createGetAppMenu =
(services: ProfileProviderServices): RootProfileProvider['profile']['getAppMenu'] =>
(prev) =>
(params) => {
const prevValue = prev(params);

return {
appMenuRegistry: (registry) => {
// Register custom link actions
registerDatasetQualityLink(registry, services);
// Register alerts sub menu actions
registerCreateSLOAction(registry, services, params);
registerCustomThresholdRuleAction(registry, services, params);

return prevValue.appMenuRegistry(registry);
},
};
};

const registerDatasetQualityLink = (
registry: AppMenuRegistry,
{ share, timefilter }: ProfileProviderServices
) => {
const dataQualityLocator =
share?.url.locators.get<DataQualityLocatorParams>(DATA_QUALITY_LOCATOR_ID);

if (dataQualityLocator) {
registry.registerCustomAction({
id: 'dataset-quality-link',
type: AppMenuActionType.custom,
controlProps: {
label: i18n.translate('discover.observabilitySolution.appMenu.datasets', {
defaultMessage: 'Data sets',
}),
testId: 'discoverAppMenuDatasetQualityLink',
onClick: ({ onFinishAction }) => {
const refresh = timefilter.getRefreshInterval();
const { from, to } = timefilter.getTime();

dataQualityLocator.navigate({
filters: {
timeRange: {
from: from ?? 'now-24h',
to: to ?? 'now',
refresh,
},
},
});

onFinishAction();
},
},
});
}
};

const registerCustomThresholdRuleAction = (
registry: AppMenuRegistry,
{ data, triggersActionsUi }: ProfileProviderServices,
{ dataView }: AppMenuExtensionParams
) => {
registry.registerCustomActionUnderSubmenu(AppMenuActionId.alerts, {
id: AppMenuActionId.createRule,
type: AppMenuActionType.custom,
order: 101,
controlProps: {
label: i18n.translate('discover.observabilitySolution.appMenu.customThresholdRule', {
defaultMessage: 'Create custom threshold rule',
}),
iconType: 'visGauge',
testId: 'discoverAppMenuCustomThresholdRule',
onClick: ({ onFinishAction }) => {
const index = dataView?.toMinimalSpec();
const { filters, query } = data.query.getState();

return triggersActionsUi.getAddRuleFlyout({
consumer: 'logs',
ruleTypeId: OBSERVABILITY_THRESHOLD_RULE_TYPE_ID,
canChangeTrigger: false,
initialValues: {
params: {
searchConfiguration: {
index,
query,
filter: filters,
},
},
},
onClose: onFinishAction,
});
},
},
});
};

const registerCreateSLOAction = (
registry: AppMenuRegistry,
{ data, discoverShared }: ProfileProviderServices,
{ dataView, isEsqlMode }: AppMenuExtensionParams
) => {
const sloFeature = discoverShared.features.registry.getById('observability-create-slo');

if (sloFeature) {
registry.registerCustomActionUnderSubmenu(AppMenuActionId.alerts, {
id: 'create-slo',
type: AppMenuActionType.custom,
order: 102,
controlProps: {
label: i18n.translate('discover.observabilitySolution.appMenu.slo', {
defaultMessage: 'Create SLO',
}),
iconType: 'bell',
testId: 'discoverAppMenuCreateSlo',
onClick: ({ onFinishAction }) => {
const index = dataView?.getIndexPattern();
const timestampField = dataView?.timeFieldName;
const { filters, query: kqlQuery } = data.query.getState();

const filter = isEsqlMode
? {}
: {
kqlQuery: isOfQueryType(kqlQuery) ? kqlQuery.query : '',
filters: filters?.map(({ meta, query }) => ({ meta, query })),
};

return sloFeature.createSLOFlyout({
initialValues: {
indicator: {
type: 'sli.kql.custom',
params: {
index,
timestampField,
filter,
},
},
},
onClose: onFinishAction,
});
},
},
});
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export { createGetAppMenu } from './get_app_menu';
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export { createObservabilityRootProfileProvider } from './profile';
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { SolutionType } from '../../../profiles';
import { createContextAwarenessMocks } from '../../../__mocks__';
import { createObservabilityRootProfileProvider } from './profile';

const mockServices = createContextAwarenessMocks().profileProviderServices;

describe('observabilityRootProfileProvider', () => {
const observabilityRootProfileProvider = createObservabilityRootProfileProvider(mockServices);
const RESOLUTION_MATCH = {
isMatch: true,
context: { solutionType: SolutionType.Observability },
};
const RESOLUTION_MISMATCH = {
isMatch: false,
};

it('should match when the solution project is observability', () => {
expect(
observabilityRootProfileProvider.resolve({
solutionNavId: SolutionType.Observability,
})
).toEqual(RESOLUTION_MATCH);
});

it('should NOT match when the solution project anything but observability', () => {
expect(
observabilityRootProfileProvider.resolve({
solutionNavId: SolutionType.Default,
})
).toEqual(RESOLUTION_MISMATCH);
expect(
observabilityRootProfileProvider.resolve({
solutionNavId: SolutionType.Search,
})
).toEqual(RESOLUTION_MISMATCH);
expect(
observabilityRootProfileProvider.resolve({
solutionNavId: SolutionType.Security,
})
).toEqual(RESOLUTION_MISMATCH);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { RootProfileProvider, SolutionType } from '../../../profiles';
import { ProfileProviderServices } from '../../profile_provider_services';
import { createGetAppMenu } from './accessors';

export const createObservabilityRootProfileProvider = (
services: ProfileProviderServices
): RootProfileProvider => ({
profileId: 'observability-root-profile',
profile: {
getAppMenu: createGetAppMenu(services),
},
resolve: (params) => {
if (params.solutionNavId === SolutionType.Observability) {
return { isMatch: true, context: { solutionType: SolutionType.Observability } };
}

return { isMatch: false };
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
ProfileProviderServices,
} from './profile_provider_services';
import type { DiscoverServices } from '../../build_services';
import { createObservabilityRootProfileProvider } from './observability/observability_root_profile';

/**
* Register profile providers for root, data source, and document contexts to the profile profile services
Expand Down Expand Up @@ -122,6 +123,7 @@ const createRootProfileProviders = (providerServices: ProfileProviderServices) =
createExampleRootProfileProvider(),
createExampleSolutionViewRootProfileProvider(),
createSecurityRootProfileProvider(providerServices),
createObservabilityRootProfileProvider(providerServices),
];

/**
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/discover/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import type { AiopsPluginStart } from '@kbn/aiops-plugin/public';
import type { DataVisualizerPluginStart } from '@kbn/data-visualizer-plugin/public';
import type { FieldsMetadataPublicStart } from '@kbn/fields-metadata-plugin/public';
import type { LogsDataAccessPluginStart } from '@kbn/logs-data-access-plugin/public';
import { DiscoverSharedPublicStart } from '@kbn/discover-shared-plugin/public';
import { DiscoverAppLocator } from '../common';
import { DiscoverCustomizationContext } from './customizations';
import { type DiscoverContainerProps } from './components/discover_container';
Expand Down Expand Up @@ -151,6 +152,7 @@ export interface DiscoverStartPlugins {
dataViewFieldEditor: IndexPatternFieldEditorStart;
dataViews: DataViewsServicePublic;
dataVisualizer?: DataVisualizerPluginStart;
discoverShared: DiscoverSharedPublicStart;
embeddable: EmbeddableStart;
expressions: ExpressionsStart;
fieldFormats: FieldFormatsStart;
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/discover/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@
"@kbn/logs-data-access-plugin",
"@kbn/core-lifecycle-browser",
"@kbn/discover-contextual-components",
"@kbn/esql-ast"
"@kbn/esql-ast",
"@kbn/discover-shared-plugin"
],
"exclude": [
"target/**/*"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,16 @@ export interface ObservabilityLogsAIAssistantFeature {
render: (deps: ObservabilityLogsAIAssistantFeatureRenderDeps) => JSX.Element;
}

export interface ObservabilityCreateSLOFeature {
id: 'observability-create-slo';
createSLOFlyout: (props: {
onClose: () => void;
initialValues: Record<string, unknown>;
}) => React.ReactNode;
}

// This should be a union of all the available client features.
export type DiscoverFeature = ObservabilityLogsAIAssistantFeature;
export type DiscoverFeature = ObservabilityLogsAIAssistantFeature | ObservabilityCreateSLOFeature;

/**
* Service types
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/observability_solution/slo/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"dashboard",
"data",
"dataViews",
"discoverShared",
"lens",
"dataViewEditor",
"dataViewFieldEditor",
Expand Down
Loading

0 comments on commit 9d38922

Please sign in to comment.