forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[One Discover] Add app menu actions for Observability projects (elast…
…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
1 parent
68d95e4
commit 9d38922
Showing
20 changed files
with
424 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
161 changes: 161 additions & 0 deletions
161
...ness/profile_providers/observability/observability_root_profile/accessors/get_app_menu.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
}, | ||
}, | ||
}); | ||
} | ||
}; |
10 changes: 10 additions & 0 deletions
10
...t_awareness/profile_providers/observability/observability_root_profile/accessors/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
10 changes: 10 additions & 0 deletions
10
...lic/context_awareness/profile_providers/observability/observability_root_profile/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
51 changes: 51 additions & 0 deletions
51
...text_awareness/profile_providers/observability/observability_root_profile/profile.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
.../context_awareness/profile_providers/observability/observability_root_profile/profile.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.