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

[One Discover] Add app menu actions for Observability projects #198987

Merged
merged 24 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d619e41
wip(discover): implement app menu actions
Nov 4, 2024
c02bf21
feat(discover): implement app menu actions mvp
Nov 5, 2024
d5e2705
feat(discover): implement app menu for obs root profile
Nov 5, 2024
8c28477
refactor(discover): remove add data from app menu
Nov 5, 2024
e9a679a
refactor(discover): update types
Nov 5, 2024
6cde32f
refactor(discover): remove mock change
Nov 5, 2024
b32046d
refactor(discover): minor type update
Nov 5, 2024
1f0e308
Merge branch 'main' into 182230-app-menu-logs-experience
tonyghiani Nov 5, 2024
6b2480d
refactor(discover): update tsconfig
Nov 5, 2024
250638f
tests(discover): skip search alert test for oblt projects
Nov 6, 2024
9e271f7
Merge branch 'main' into 182230-app-menu-logs-experience
tonyghiani Nov 6, 2024
9f5252f
Merge branch 'main' into 182230-app-menu-logs-experience
tonyghiani Nov 6, 2024
0553ddc
refactor(discover): remove unused file
Nov 6, 2024
8c073e2
refactor(discover): use i18n
Nov 7, 2024
cb44a07
test(discover): add o11y profile FT for app menu
Nov 7, 2024
e9f6c40
Merge branch 'main' into 182230-app-menu-logs-experience
tonyghiani Nov 7, 2024
58eba92
fix(discover): use data view specs for alert rule
Nov 7, 2024
73bd8ba
Merge branch 'main' into 182230-app-menu-logs-experience
tonyghiani Nov 11, 2024
13646a8
Merge branch 'main' into 182230-app-menu-logs-experience
tonyghiani Nov 13, 2024
b7a61fb
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Nov 13, 2024
c22e5b3
fix(slo): conflicts and improve typing
Nov 13, 2024
b08d118
Merge branch '182230-app-menu-logs-experience' of github.com:tonyghia…
Nov 13, 2024
e333f5b
fix(discover): broken slo creation due to filters
Nov 13, 2024
65d854d
Merge branch 'main' into 182230-app-menu-logs-experience
tonyghiani Nov 14, 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
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 }) => {
tonyghiani marked this conversation as resolved.
Show resolved Hide resolved
const refresh = timefilter.getRefreshInterval();
const { from, to } = timefilter.getTime();

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

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

const registerCustomThresholdRuleAction = (
tonyghiani marked this conversation as resolved.
Show resolved Hide resolved
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',
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @tonyghiani,

The PR changes are looking great and the code is very clean.

I have some questions about "Create custom threshold rule" action.

  • Can this rule be applied to other than logs data sets?
  • Can it work with ad-hoc data views?

For some reason I am see an error message when trying to create one (I am using a space with Observability set as the current Solution view).

Screenshot 2024-11-07 at 13 20 07

Copy link
Contributor Author

@tonyghiani tonyghiani Nov 7, 2024

Choose a reason for hiding this comment

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

Hey @jughosta 👋

Can this rule be applied to other than logs data sets?

Yes, the custom threshold rule is an observability alert that can be applied to any data stream where the user wants to control a value.

Can it work with ad-hoc data views?
For some reason I am see an error message when trying to create one (I am using a space with Observability set as the current Solution view).

It does work with ad-hoc views, the failure you are facing is due to the fact I was not passing the data view specs, but only the (erroneously) data view pattern, which I fixed in fix(discover): use data view specs for alert rule

Screenshot 2024-11-07 at 14 47 06

}),
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 = (
Copy link
Contributor

Choose a reason for hiding this comment

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

I ran into an issue where the request failed when I tried to create an SLO, seemingly because of the filter I was using in Discover:
CleanShot 2024-11-07 at 23 58 17@2x

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I reproduced it but it looks like a bug on the SLOs end, we are just embedding the creation flyout.
Could you open an issue for the SLOs team please?

Copy link
Contributor

Choose a reason for hiding this comment

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

I was unable to reproduce this outside of Discover directly in the SLOs app. It seems they might be stripping the $state property from filters or something similar before saving:
CleanShot 2024-11-12 at 22 09 27@2x

Do you know of another area in Kibana where I can create SLOs to try to reproduce it? Mainly I'm unsure if this is a bug that affects other usages too, or if the expectation is that consumers somehow modify the filters as they do before saving.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey Davis, I tried this on Logs Explorer too and it is affected in the same way.
As you thought, the expectation is that the filters don't have the $state property, which is reason why it fails validating the payload sent to the server and fails the SLO creation.

I stripped the property client side and it works fine now

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, I confirmed it works now!

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

if (sloFeature) {
registry.registerCustomActionUnderSubmenu(AppMenuActionId.alerts, {
tonyghiani marked this conversation as resolved.
Show resolved Hide resolved
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();
tonyghiani marked this conversation as resolved.
Show resolved Hide resolved
const timestampField = dataView?.timeFieldName;
const { filters, query } = data.query.getState();

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

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>;
}) => JSX.Element;
}

// 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