Skip to content

Commit

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

# Backport

This will backport the following commits from `main` to `8.x`:
- [[One Discover] Add app menu actions for Observability projects
(#198987)](#198987)

<!--- Backport version: 8.9.8 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Marco Antonio
Ghiani","email":"marcoantonio.ghiani01@gmail.com"},"sourceCommit":{"committedDate":"2024-11-14T10:00:38Z","message":"[One
Discover] Add app menu actions for Observability projects
(#198987)\n\n## 📓 Summary\r\n\r\nCloses #182230 \r\n\r\nThis work
introduces a new observability root profile and uses the
new\r\nextension point to register custom actions on the app
menu.\r\nThe registered actions and link will appear only with the new
project\r\nnavigation enabled on an Observability project:\r\n- A link
to the data sets quality page\r\n- On the alerts sub menu...\r\n-
replace the default search rule creation with the observability
custom\r\nthreshold rule\r\n - add an entry to directly create an SLO
for the current search\r\n\r\nTo access the SLO capabilities without
breaking the dependencies\r\nhierarchy of the new sustainable
architecture, the feature is registered\r\nby the common plugin
`discover-shared` in SLO and consumed then by\r\nDiscover using the IoC
principle.\r\n\r\n## 🖼️ Screenshots\r\n\r\n### Observability project
solution - show new menu\r\n\r\n<img width=\"3004\" alt=\"Screenshot
2024-11-06 at 12 37
02\"\r\nsrc=\"https://github.com/user-attachments/assets/d70b532d-1889-4d5b-b2ee-de2f048560f4\">\r\n\r\n###
Search project solution - hide new menu\r\n\r\n<img width=\"3006\"
alt=\"Screenshot 2024-11-06 at 12 36
19\"\r\nsrc=\"https://github.com/user-attachments/assets/660893c3-f6b5-4b06-b8de-50a61a6bdb98\">\r\n\r\n###
Default navigation mode - hide new menu\r\n\r\n<img width=\"3002\"
alt=\"Screenshot 2024-11-06 at 12 35
43\"\r\nsrc=\"https://github.com/user-attachments/assets/674c5a08-0084-40e5-ae34-a56c363cacce\">\r\n\r\n##
🎥
Demo\r\n\r\n\r\nhttps://github.com/user-attachments/assets/104e6074-0401-4fd2-a8e6-8b05f2c070d7\r\n\r\n---------\r\n\r\nCo-authored-by:
Marco Antonio Ghiani <marcoantonio.ghiani@elastic.co>\r\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"9d38922401d0bbd0d95d750f68fec77ca22758fb","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","backport:prev-minor","ci:project-deploy-observability","Team:obs-ux-logs","Team:obs-ux-management","Project:OneDiscover"],"number":198987,"url":"https://github.com/elastic/kibana/pull/198987","mergeCommit":{"message":"[One
Discover] Add app menu actions for Observability projects
(#198987)\n\n## 📓 Summary\r\n\r\nCloses #182230 \r\n\r\nThis work
introduces a new observability root profile and uses the
new\r\nextension point to register custom actions on the app
menu.\r\nThe registered actions and link will appear only with the new
project\r\nnavigation enabled on an Observability project:\r\n- A link
to the data sets quality page\r\n- On the alerts sub menu...\r\n-
replace the default search rule creation with the observability
custom\r\nthreshold rule\r\n - add an entry to directly create an SLO
for the current search\r\n\r\nTo access the SLO capabilities without
breaking the dependencies\r\nhierarchy of the new sustainable
architecture, the feature is registered\r\nby the common plugin
`discover-shared` in SLO and consumed then by\r\nDiscover using the IoC
principle.\r\n\r\n## 🖼️ Screenshots\r\n\r\n### Observability project
solution - show new menu\r\n\r\n<img width=\"3004\" alt=\"Screenshot
2024-11-06 at 12 37
02\"\r\nsrc=\"https://github.com/user-attachments/assets/d70b532d-1889-4d5b-b2ee-de2f048560f4\">\r\n\r\n###
Search project solution - hide new menu\r\n\r\n<img width=\"3006\"
alt=\"Screenshot 2024-11-06 at 12 36
19\"\r\nsrc=\"https://github.com/user-attachments/assets/660893c3-f6b5-4b06-b8de-50a61a6bdb98\">\r\n\r\n###
Default navigation mode - hide new menu\r\n\r\n<img width=\"3002\"
alt=\"Screenshot 2024-11-06 at 12 35
43\"\r\nsrc=\"https://github.com/user-attachments/assets/674c5a08-0084-40e5-ae34-a56c363cacce\">\r\n\r\n##
🎥
Demo\r\n\r\n\r\nhttps://github.com/user-attachments/assets/104e6074-0401-4fd2-a8e6-8b05f2c070d7\r\n\r\n---------\r\n\r\nCo-authored-by:
Marco Antonio Ghiani <marcoantonio.ghiani@elastic.co>\r\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"9d38922401d0bbd0d95d750f68fec77ca22758fb"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/198987","number":198987,"mergeCommit":{"message":"[One
Discover] Add app menu actions for Observability projects
(#198987)\n\n## 📓 Summary\r\n\r\nCloses #182230 \r\n\r\nThis work
introduces a new observability root profile and uses the
new\r\nextension point to register custom actions on the app
menu.\r\nThe registered actions and link will appear only with the new
project\r\nnavigation enabled on an Observability project:\r\n- A link
to the data sets quality page\r\n- On the alerts sub menu...\r\n-
replace the default search rule creation with the observability
custom\r\nthreshold rule\r\n - add an entry to directly create an SLO
for the current search\r\n\r\nTo access the SLO capabilities without
breaking the dependencies\r\nhierarchy of the new sustainable
architecture, the feature is registered\r\nby the common plugin
`discover-shared` in SLO and consumed then by\r\nDiscover using the IoC
principle.\r\n\r\n## 🖼️ Screenshots\r\n\r\n### Observability project
solution - show new menu\r\n\r\n<img width=\"3004\" alt=\"Screenshot
2024-11-06 at 12 37
02\"\r\nsrc=\"https://github.com/user-attachments/assets/d70b532d-1889-4d5b-b2ee-de2f048560f4\">\r\n\r\n###
Search project solution - hide new menu\r\n\r\n<img width=\"3006\"
alt=\"Screenshot 2024-11-06 at 12 36
19\"\r\nsrc=\"https://github.com/user-attachments/assets/660893c3-f6b5-4b06-b8de-50a61a6bdb98\">\r\n\r\n###
Default navigation mode - hide new menu\r\n\r\n<img width=\"3002\"
alt=\"Screenshot 2024-11-06 at 12 35
43\"\r\nsrc=\"https://github.com/user-attachments/assets/674c5a08-0084-40e5-ae34-a56c363cacce\">\r\n\r\n##
🎥
Demo\r\n\r\n\r\nhttps://github.com/user-attachments/assets/104e6074-0401-4fd2-a8e6-8b05f2c070d7\r\n\r\n---------\r\n\r\nCo-authored-by:
Marco Antonio Ghiani <marcoantonio.ghiani@elastic.co>\r\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"9d38922401d0bbd0d95d750f68fec77ca22758fb"}}]}]
BACKPORT-->

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
tonyghiani and kibanamachine authored Nov 14, 2024
1 parent 9047ddb commit da7fdf3
Show file tree
Hide file tree
Showing 19 changed files with 429 additions and 16 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 da7fdf3

Please sign in to comment.