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

[Infra] Add endpoints to manage Custom Dashboards #176612

Conversation

mykolaharmash
Copy link
Contributor

@mykolaharmash mykolaharmash commented Feb 9, 2024

Closes #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. 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
  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"]
}
  1. Toggle the UI setting on
  2. Try the endpoints again, now they should work as expected

@mykolaharmash
Copy link
Contributor Author

/ci

@apmmachine
Copy link
Contributor

🤖 GitHub comments

Expand to view the GitHub comments

Just comment with:

  • /oblt-deploy : Deploy a Kibana instance using the Observability test environments.
  • /oblt-deploy-serverless : Deploy a serverless Kibana instance using the Observability test environments.
  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@mykolaharmash mykolaharmash force-pushed the 176069-infra-register-dashboard-saved-object-and-create-crud-endpoints-to-manage-it branch from e702cad to 517846a Compare February 13, 2024 14:50
@mykolaharmash
Copy link
Contributor Author

/ci

@mykolaharmash
Copy link
Contributor Author

/ci

@mykolaharmash mykolaharmash marked this pull request as ready for review February 13, 2024 15:12
@mykolaharmash mykolaharmash requested review from a team as code owners February 13, 2024 15:12
@mykolaharmash mykolaharmash added release_note:skip Skip the PR/issue when compiling release notes Team:obs-ux-infra_services Observability Infrastructure & Services User Experience Team v8.13.0 labels Feb 13, 2024
@elasticmachine
Copy link
Contributor

Pinging @elastic/obs-ux-infra_services-team (Team:obs-ux-infra_services)

@botelastic botelastic bot added the Team:obs-ux-management Observability Management User Experience Team label Feb 13, 2024
@elasticmachine
Copy link
Contributor

Pinging @elastic/obs-ux-management-team (Team:obs-ux-management)

x-pack/plugins/infra/server/plugin.ts Outdated Show resolved Hide resolved
params: validateParams,
},
},
handleRouteErrors(async (context, request, response) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the name handleRouteErrors is a bit odd. At first, I thought this would be handled only when errors happened. But that is not the case, right? It wraps up the handle and handles when errors happen.

Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to implement it here instead?

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 think the name handleRouteErrors is a bit odd. At first, I thought this would be handled only when errors happened. But that is not the case, right? It wraps up the handle and handles when errors happen.

Could you explain a bit more? Not sure I get your point.

Does it make sense to implement it here instead?

Yeah, I mentioned this in the PR description. It would definitely make sense but just a bit out of scope for this change I think.

In the future we could do something similar right within registerRoutes framework function, but this would require a bit of refactoring.

Copy link
Contributor

Choose a reason for hiding this comment

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

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.

Can you elaborate on why this would need refactoring?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mainly because some routes already have a bespoke error handling and ideally we'd need to remove those and re-test the routes.

Copy link
Contributor

Choose a reason for hiding this comment

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

If you can create a follow-up issue for this tech debt would be nice, so we don't lose track of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created the issue

@yuliacech yuliacech self-requested a review February 14, 2024 09:56
Copy link
Contributor

@yuliacech yuliacech left a comment

Choose a reason for hiding this comment

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

Advanced settings constant change LGTM 👍

@@ -259,21 +264,26 @@ export class InfraServerPlugin
]);
}

initInfraServer(this.libs);
Copy link
Contributor

Choose a reason for hiding this comment

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

You mentioned

"Having endpoint initialization in start makes it more convenient to access start dependencies which almost all endpoints require."

What kind of start dependencies do most of the endpoints require?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Depends on the endpoint, but there is a getStartServices that we put into libs during start phase and pass down to route initializers. Here are instances of where this method is used. Creating this loophole from the start phase in form of getStartServices() feels a bit weird to me. But I'm happy to discuss, maybe there is a better approach 🙌

Copy link
Contributor Author

@mykolaharmash mykolaharmash Feb 14, 2024

Choose a reason for hiding this comment

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

Mistyped there, libs are formed during the setup phase, not start

Copy link
Contributor

@jloleysens jloleysens left a comment

Choose a reason for hiding this comment

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

Left a question regarding the access level of the new server routes. Otherwise changes LGTM!

packages/kbn-check-mappings-update-cli/current_fields.json Outdated Show resolved Hide resolved

if (customDashboards.total === 0) {
return response.ok({
body: InfraGetCustomDashboardsResponseBodyRT.encode({
Copy link
Contributor

Choose a reason for hiding this comment

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

FMI: will .encode strip unknown fields?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looked at the io-ts code, seems like encode is purely a type guard encode: <A>(a: A): A => a, so it won't let you pass unknown fields.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, in that case I would recommend cherry picking fields in responses like you are doing here, but same for below:

      const attrs = customDashboards.saved_objects[0].attributes;
      return response.ok({
        body: InfraGetCustomDashboardsResponseBodyRT.encode(
          { a: attr.a, b: attr.b }
        ),
      });

This ensures we are only sending known values over the wire.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I added the access: internal to the endpoints and adjusted the response object.

framework.registerRoute(
{
method: 'get',
path: '/api/infra/custom-dashboards/{assetType}',
Copy link
Contributor

@kpatticha kpatticha Feb 14, 2024

Choose a reason for hiding this comment

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

In the end, this might be the feature we'd like to deliver to the users, I just want to highlight that with this approach the custom dashboards are linked tightly with the asset type and it's not abstract enough from the technical point of view.

I think we assume that the user's custom dashboards are built based and focused only on the asset type metrics. What if they want to link a revenue dashboard to all their Kubernetes and hosts?

@roshan-elastic is the above a use case for the custom dashboard in infra or do the users mostly want metrics dashboards we're not prodiving in our created pre-build dashboards??

Copy link
Contributor

@crespocarlos crespocarlos Feb 21, 2024

Choose a reason for hiding this comment

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

I think we assume that the user's custom dashboards are built based and focused only on the asset type metrics. What if they want to link a revenue dashboard to all their Kubernetes and hosts?

I guess for the GET endpoint this is fine, or I'm missing something? This endpoint will retrieve only the dashboards linked to the asset type.

It's an interesting use case, though, but the linking feature would have to support linking a dashboard to multiple asset types, and we'd have to change the assetType to be an array both in the Saved Objects schema and in the POST request payload type. Making assetType an array would indeed make this future-proof (In fact, we'd need to have one saved object per dashboardSavedObjectId and assetType being an array to meet that requirement)

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 @kpatticha @crespocarlos, just had a chat with @roshan-elastic, he confirmed that we want to stick to dashboards linked to asset types, and there is a feature planned to allow users to disable filtering by a specific asset for a dashboard, so this would enable generic dashboards to work even when you look at some asset details view. This would require an additional field on the saved object, but this will be a non-braking change and we can add it with a migration.

It seems that we're good and nothing needs to be changed in this PR, so I'll go ahead and merge it.

'1': {
changes: [],
schemas: {
create: schema.object(createSchema),
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Could be just me but I find it easier to read the code when the schema is defined here
ex

Suggested change
create: schema.object(createSchema),
create: schema.object({
dashboardSavedObjectIdList:
schema.arrayOf(schema.string()),
assetType: schema.string(),
kuery: schema.maybe(schema.string()),
}),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, that would be more readable. The reason I've put it into a separate object is to have an explicit type Record<keyof InfraCustomDashboard, Type<any>> to make sure schema fields stay the same as the corresponding InfraCustomDashboard type. Tbh, I'd trade off some readability for more type-safety, or maybe there is a way to achieve both that I'm missing?

… src/core/server/integration_tests/ci_checks'
Copy link
Member

@bmorelli25 bmorelli25 left a comment

Choose a reason for hiding this comment

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

Docs LGTM

Copy link
Contributor

@jloleysens jloleysens left a comment

Choose a reason for hiding this comment

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

Pending making the route internal and sending only known values over the wire this LGTM! Great work!


if (customDashboards.total === 0) {
return response.ok({
body: InfraGetCustomDashboardsResponseBodyRT.encode({
Copy link
Contributor

Choose a reason for hiding this comment

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

OK, in that case I would recommend cherry picking fields in responses like you are doing here, but same for below:

      const attrs = customDashboards.saved_objects[0].attributes;
      return response.ok({
        body: InfraGetCustomDashboardsResponseBodyRT.encode(
          { a: attr.a, b: attr.b }
        ),
      });

This ensures we are only sending known values over the wire.

…-register-dashboard-saved-object-and-create-crud-endpoints-to-manage-it
…er-dashboard-saved-object-and-create-crud-endpoints-to-manage-it
…saved-object-and-create-crud-endpoints-to-manage-it' into 176069-infra-register-dashboard-saved-object-and-create-crud-endpoints-to-manage-it
…hboard-saved-object-and-create-crud-endpoints-to-manage-it' into 176069-infra-register-dashboard-saved-object-and-create-crud-endpoints-to-manage-it
Copy link
Contributor

@cauemarcondes cauemarcondes left a comment

Choose a reason for hiding this comment

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

LGTM

@mykolaharmash
Copy link
Contributor Author

@elasticmachine merge upstream

@mykolaharmash
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Member

@maryam-saeidi maryam-saeidi left a comment

Choose a reason for hiding this comment

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

I get bad request for the second query, with both enabled and disabled setting:

image

@mykolaharmash
Copy link
Contributor Author

mykolaharmash commented Feb 19, 2024

I get bad request for the second query, with both enabled and disabled setting:

image

Sorry @maryam-saeidi, the field name was updated in the process of code review but I forgot to update the description, the new field name is dashboardIdList instead of dashboardSavedObjectIdList

The description is now up to day.

@mykolaharmash
Copy link
Contributor Author

@elasticmachine merge upstream

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
infra 29 34 +5

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
infra 8 6 -2

Saved Objects .kibana field count

Every field in each saved object type adds overhead to Elasticsearch. Kibana needs to keep the total field count below Elasticsearch's default limit of 1000 fields. Only specify field mappings for the fields you wish to search on or query. See https://www.elastic.co/guide/en/kibana/master/saved-objects-service.html#_mappings

id before after diff
infra-custom-dashboards - 4 +4
Unknown metric groups

API count

id before after diff
infra 32 37 +5

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@mykolaharmash mykolaharmash merged commit b50f538 into elastic:main Feb 22, 2024
18 checks passed
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Feb 22, 2024
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]>
(cherry picked from commit b50f538)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.13

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Feb 22, 2024
…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]>
fkanout pushed a commit to fkanout/kibana that referenced this pull request Mar 4, 2024
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes Team:obs-ux-infra_services Observability Infrastructure & Services User Experience Team Team:obs-ux-management Observability Management User Experience Team v8.13.0 v8.14.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Infra] Register dashboard saved object and create endpoints to manage it