-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…177569) # Backport This will backport the following commits from `main` to `8.13`: - [[Infra] Add endpoints to manage Custom Dashboards (#176612)](#176612) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Mykola Harmash","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-02-22T10:56:33Z","message":"[Infra] Add endpoints to manage Custom Dashboards (#176612)\n\nCloses https://github.com/elastic/kibana/issues/176069\r\n\r\n## Summary\r\n\r\nThis adds the logic to register a new Saved Object type to store custom\r\ndashboards for Asset Details and adds endpoints to fetch and save custom\r\ndashboards.\r\n\r\nChanges highlights:\r\n* Renamed the `enableInfrastructureHostsCustomDashboards` to\r\n`enableInfrastructureAssetCustomDashboards` to make it more generic and\r\nsupport additional asset types in the future\r\n* Added a new Saved Object type\r\n* Moved initialization of all Infra endpoints to plugin's `start`. This\r\none one of the points on [the BE tech debt\r\nticket](#175975). Having\r\nendpoint initialization in `start` makes it more convenient to access\r\nstart dependencies which almost all endpoints require.\r\n* Added `savedObjectClient` and `uiSettingsClient` to the custom request\r\ncontext (also one of the ideas for endpoints improvement). Right now\r\ninfra endpoints use custom `libs` object with all dependencies required\r\nfor routes, the idea is to rely on the request context instead because\r\nit automatically available for every route handler and by default\r\nincludes some useful things like scoped service clients.\r\n* Added a wrapper `handleRouteErrors` to avoid error handling\r\nduplication which we now have in a few routes. In the future we could do\r\nsomething similar right within `registerRoutes` framework function, but\r\nthis would require a bit of refactoring.\r\n\r\n## Hot to Test\r\n\r\n1. Toggle the UI setting off in Advanced Settings\r\n![CleanShot 2024-02-13 at 16 01\r\n36@2x](https://github.com/elastic/kibana/assets/793851/fc3772a1-a075-42bd-bdc3-2c7e83278844)\r\n2. Go to the Dev Tools and try the endpoints, both should respond with\r\n403\r\n```\r\nGET kbn:api/infra/custom-dashboards/host\r\n\r\nPOST kbn:api/infra/custom-dashboards\r\n{\r\n \"assetType\": \"host\",\r\n \"dashboardIdList\": [\"0\", \"1\"]\r\n}\r\n```\r\n3. Toggle the UI setting on\r\n4. Try the endpoints again, now they should work as expected\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <[email protected]>","sha":"b50f5387fcf1e5e5e706a2f566455ee619f4b006","branchLabelMapping":{"^v8.14.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:obs-ux-infra_services","Team:obs-ux-management","v8.13.0","v8.14.0"],"title":"[Infra] Add endpoints to manage Custom Dashboards","number":176612,"url":"https://github.com/elastic/kibana/pull/176612","mergeCommit":{"message":"[Infra] Add endpoints to manage Custom Dashboards (#176612)\n\nCloses https://github.com/elastic/kibana/issues/176069\r\n\r\n## Summary\r\n\r\nThis adds the logic to register a new Saved Object type to store custom\r\ndashboards for Asset Details and adds endpoints to fetch and save custom\r\ndashboards.\r\n\r\nChanges highlights:\r\n* Renamed the `enableInfrastructureHostsCustomDashboards` to\r\n`enableInfrastructureAssetCustomDashboards` to make it more generic and\r\nsupport additional asset types in the future\r\n* Added a new Saved Object type\r\n* Moved initialization of all Infra endpoints to plugin's `start`. This\r\none one of the points on [the BE tech debt\r\nticket](#175975). Having\r\nendpoint initialization in `start` makes it more convenient to access\r\nstart dependencies which almost all endpoints require.\r\n* Added `savedObjectClient` and `uiSettingsClient` to the custom request\r\ncontext (also one of the ideas for endpoints improvement). Right now\r\ninfra endpoints use custom `libs` object with all dependencies required\r\nfor routes, the idea is to rely on the request context instead because\r\nit automatically available for every route handler and by default\r\nincludes some useful things like scoped service clients.\r\n* Added a wrapper `handleRouteErrors` to avoid error handling\r\nduplication which we now have in a few routes. In the future we could do\r\nsomething similar right within `registerRoutes` framework function, but\r\nthis would require a bit of refactoring.\r\n\r\n## Hot to Test\r\n\r\n1. Toggle the UI setting off in Advanced Settings\r\n![CleanShot 2024-02-13 at 16 01\r\n36@2x](https://github.com/elastic/kibana/assets/793851/fc3772a1-a075-42bd-bdc3-2c7e83278844)\r\n2. Go to the Dev Tools and try the endpoints, both should respond with\r\n403\r\n```\r\nGET kbn:api/infra/custom-dashboards/host\r\n\r\nPOST kbn:api/infra/custom-dashboards\r\n{\r\n \"assetType\": \"host\",\r\n \"dashboardIdList\": [\"0\", \"1\"]\r\n}\r\n```\r\n3. Toggle the UI setting on\r\n4. Try the endpoints again, now they should work as expected\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <[email protected]>","sha":"b50f5387fcf1e5e5e706a2f566455ee619f4b006"}},"sourceBranch":"main","suggestedTargetBranches":["8.13"],"targetPullRequestStates":[{"branch":"8.13","label":"v8.13.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.14.0","branchLabelMappingKey":"^v8.14.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/176612","number":176612,"mergeCommit":{"message":"[Infra] Add endpoints to manage Custom Dashboards (#176612)\n\nCloses https://github.com/elastic/kibana/issues/176069\r\n\r\n## Summary\r\n\r\nThis adds the logic to register a new Saved Object type to store custom\r\ndashboards for Asset Details and adds endpoints to fetch and save custom\r\ndashboards.\r\n\r\nChanges highlights:\r\n* Renamed the `enableInfrastructureHostsCustomDashboards` to\r\n`enableInfrastructureAssetCustomDashboards` to make it more generic and\r\nsupport additional asset types in the future\r\n* Added a new Saved Object type\r\n* Moved initialization of all Infra endpoints to plugin's `start`. This\r\none one of the points on [the BE tech debt\r\nticket](#175975). Having\r\nendpoint initialization in `start` makes it more convenient to access\r\nstart dependencies which almost all endpoints require.\r\n* Added `savedObjectClient` and `uiSettingsClient` to the custom request\r\ncontext (also one of the ideas for endpoints improvement). Right now\r\ninfra endpoints use custom `libs` object with all dependencies required\r\nfor routes, the idea is to rely on the request context instead because\r\nit automatically available for every route handler and by default\r\nincludes some useful things like scoped service clients.\r\n* Added a wrapper `handleRouteErrors` to avoid error handling\r\nduplication which we now have in a few routes. In the future we could do\r\nsomething similar right within `registerRoutes` framework function, but\r\nthis would require a bit of refactoring.\r\n\r\n## Hot to Test\r\n\r\n1. Toggle the UI setting off in Advanced Settings\r\n![CleanShot 2024-02-13 at 16 01\r\n36@2x](https://github.com/elastic/kibana/assets/793851/fc3772a1-a075-42bd-bdc3-2c7e83278844)\r\n2. Go to the Dev Tools and try the endpoints, both should respond with\r\n403\r\n```\r\nGET kbn:api/infra/custom-dashboards/host\r\n\r\nPOST kbn:api/infra/custom-dashboards\r\n{\r\n \"assetType\": \"host\",\r\n \"dashboardIdList\": [\"0\", \"1\"]\r\n}\r\n```\r\n3. Toggle the UI setting on\r\n4. Try the endpoints again, now they should work as expected\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <[email protected]>","sha":"b50f5387fcf1e5e5e706a2f566455ee619f4b006"}}]}] BACKPORT--> Co-authored-by: Mykola Harmash <[email protected]>
- Loading branch information
1 parent
86d8801
commit ffe0d21
Showing
31 changed files
with
596 additions
and
41 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { InventoryItemType } from '@kbn/metrics-data-access-plugin/common'; | ||
|
||
export type InfraCustomDashboardAssetType = InventoryItemType; | ||
|
||
export interface InfraCustomDashboard { | ||
dashboardIdList: string[]; | ||
assetType: InfraCustomDashboardAssetType; | ||
kuery?: string; | ||
} |
47 changes: 47 additions & 0 deletions
47
x-pack/plugins/infra/common/http_api/custom_dashboards_api.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,47 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { ItemTypeRT } from '@kbn/metrics-data-access-plugin/common'; | ||
import * as rt from 'io-ts'; | ||
|
||
const AssetTypeRT = rt.type({ | ||
assetType: ItemTypeRT, | ||
}); | ||
|
||
const CustomDashboardRT = rt.intersection([ | ||
AssetTypeRT, | ||
rt.type({ | ||
dashboardIdList: rt.array(rt.string), | ||
}), | ||
rt.partial({ | ||
kuery: rt.string, | ||
}), | ||
]); | ||
|
||
/** | ||
GET endpoint | ||
*/ | ||
export const InfraGetCustomDashboardsRequestParamsRT = AssetTypeRT; | ||
export const InfraGetCustomDashboardsResponseBodyRT = CustomDashboardRT; | ||
export type InfraGetCustomDashboardsRequestParams = rt.TypeOf< | ||
typeof InfraGetCustomDashboardsRequestParamsRT | ||
>; | ||
export type InfraGetCustomDashboardsResponseBody = rt.TypeOf< | ||
typeof InfraGetCustomDashboardsResponseBodyRT | ||
>; | ||
|
||
/** | ||
* POST endpoint | ||
*/ | ||
export const InfraSaveCustomDashboardsRequestPayloadRT = CustomDashboardRT; | ||
export const InfraSaveCustomDashboardsResponseBodyRT = CustomDashboardRT; | ||
export type InfraSaveCustomDashboardsRequestPayload = rt.TypeOf< | ||
typeof InfraSaveCustomDashboardsRequestPayloadRT | ||
>; | ||
export type InfraSaveCustomDashboardsResponseBody = rt.TypeOf< | ||
typeof InfraSaveCustomDashboardsResponseBodyRT | ||
>; |
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
15 changes: 15 additions & 0 deletions
15
x-pack/plugins/infra/server/routes/custom_dashboards/custom_dashboards.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,15 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { KibanaFramework } from '../../lib/adapters/framework/kibana_framework_adapter'; | ||
import { initGetCustomDashboardRoute } from './get_custom_dashboard'; | ||
import { initSaveCustomDashboardRoute } from './save_custom_dashboard'; | ||
|
||
export function initCustomDashboardsRoutes(framework: KibanaFramework) { | ||
initGetCustomDashboardRoute(framework); | ||
initSaveCustomDashboardRoute(framework); | ||
} |
Oops, something went wrong.