Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 }) => {
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