-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Infra] Add endpoints to manage Custom Dashboards #176612
Conversation
/ci |
🤖 GitHub commentsExpand to view the GitHub comments
Just comment with:
|
e702cad
to
517846a
Compare
/ci |
/ci |
Pinging @elastic/obs-ux-infra_services-team (Team:obs-ux-infra_services) |
Pinging @elastic/obs-ux-management-team (Team:obs-ux-management) |
params: validateParams, | ||
}, | ||
}, | ||
handleRouteErrors(async (context, request, response) => { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created the issue
x-pack/plugins/infra/server/routes/custom_dashboards/lib/check_custom_dashboards_enabled.ts
Outdated
Show resolved
Hide resolved
x-pack/plugins/infra/server/routes/custom_dashboards/lib/find_custom_dashboard.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 🙌
There was a problem hiding this comment.
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
There was a problem hiding this 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!
x-pack/plugins/infra/server/routes/custom_dashboards/get_custom_dashboard.ts
Outdated
Show resolved
Hide resolved
|
||
if (customDashboards.total === 0) { | ||
return response.ok({ | ||
body: InfraGetCustomDashboardsResponseBodyRT.encode({ |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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}', |
There was a problem hiding this comment.
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??
There was a problem hiding this comment.
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 (In fact, we'd need to have one saved object per 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-proofdashboardSavedObjectId
and assetType
being an array to meet that requirement)
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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
create: schema.object(createSchema), | |
create: schema.object({ | |
dashboardSavedObjectIdList: | |
schema.arrayOf(schema.string()), | |
assetType: schema.string(), | |
kuery: schema.maybe(schema.string()), | |
}), |
There was a problem hiding this comment.
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'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs LGTM
There was a problem hiding this 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({ |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@elasticmachine merge upstream |
…-and-create-crud-endpoints-to-manage-it
@elasticmachine merge upstream |
…-and-create-crud-endpoints-to-manage-it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 The description is now up to day. |
@elasticmachine merge upstream |
…-and-create-crud-endpoints-to-manage-it
💚 Build Succeeded
Metrics [docs]Public APIs missing comments
Public APIs missing exports
Saved Objects .kibana field count
History
To update your PR or re-run it, just comment with: |
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)
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
…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]>
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]>
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:
enableInfrastructureHostsCustomDashboards
toenableInfrastructureAssetCustomDashboards
to make it more generic and support additional asset types in the futurestart
. This one one of the points on the BE tech debt ticket. Having endpoint initialization instart
makes it more convenient to access start dependencies which almost all endpoints require.savedObjectClient
anduiSettingsClient
to the custom request context (also one of the ideas for endpoints improvement). Right now infra endpoints use customlibs
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.handleRouteErrors
to avoid error handling duplication which we now have in a few routes. In the future we could do something similar right withinregisterRoutes
framework function, but this would require a bit of refactoring.Hot to Test