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.
[Infra] Add endpoints to manage Custom Dashboards (elastic#176612)
Closes elastic#176069 ## Summary This adds the logic to register a new Saved Object type to store custom dashboards for Asset Details and adds endpoints to fetch and save custom dashboards. Changes highlights: * Renamed the `enableInfrastructureHostsCustomDashboards` to `enableInfrastructureAssetCustomDashboards` to make it more generic and support additional asset types in the future * Added a new Saved Object type * Moved initialization of all Infra endpoints to plugin's `start`. This one one of the points on [the BE tech debt ticket](elastic#175975). Having endpoint initialization in `start` makes it more convenient to access start dependencies which almost all endpoints require. * Added `savedObjectClient` and `uiSettingsClient` to the custom request context (also one of the ideas for endpoints improvement). Right now infra endpoints use custom `libs` object with all dependencies required for routes, the idea is to rely on the request context instead because it automatically available for every route handler and by default includes some useful things like scoped service clients. * Added a wrapper `handleRouteErrors` to avoid error handling duplication which we now have in a few routes. In the future we could do something similar right within `registerRoutes` framework function, but this would require a bit of refactoring. ## Hot to Test 1. Toggle the UI setting off in Advanced Settings ![CleanShot 2024-02-13 at 16 01 36@2x](https://github.com/elastic/kibana/assets/793851/fc3772a1-a075-42bd-bdc3-2c7e83278844) 2. Go to the Dev Tools and try the endpoints, both should respond with 403 ``` GET kbn:api/infra/custom-dashboards/host POST kbn:api/infra/custom-dashboards { "assetType": "host", "dashboardIdList": ["0", "1"] } ``` 3. Toggle the UI setting on 4. Try the endpoints again, now they should work as expected --------- Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
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.