[SLO] Add dashboard references to SLO saved object#232583
[SLO] Add dashboard references to SLO saved object#232583cesco-f merged 15 commits intoelastic:mainfrom
Conversation
d8681c2 to
c83a8e7
Compare
|
Pinging @elastic/obs-ux-management-team (Team:obs-ux-management) |
340e840 to
9842d78
Compare
… src/core/server/integration_tests/ci_checks'
kdelemme
left a comment
There was a problem hiding this comment.
Good job, overall this looks good to me.
I have some basic questions for my own understanding of the need for refId (cf comments)
Another question I have is about the usage: Are we going to display the dashboard name when linking to the dashboard, and if so, are we planning to fetch the name ad-hoc or fetch it when we read the references? Or is there a dashboard "locator" that takes care of rendering the name based on the provided id?
Right now we are storing the dashboard id as part of the SLO Definition, do we think it can be useful to store it as part of the SLO Summary as well? I don't know yet, and this would require a bit of changes so let's maybe delay this decision to later. Just wanted to write my thought down.
One thing I would like to test is the upgrade path (should be fine since everything is optional): creating an SLO on main, and then running this branch and trying to read/edit this SLO. Could you confirm everything is fine on this side? Thanks!
| const references: SavedObjectReference[] = []; | ||
| if (slo.artifacts?.dashboards?.length) { | ||
| slo.artifacts.dashboards.forEach(({ id }, index) => { | ||
| const refId = `dashboard-${index}`; |
There was a problem hiding this comment.
Are we using index because we want to allow the same dashboard (id) to be referenced multiple time?
There was a problem hiding this comment.
I think it doesn't really matter what we store in the refId as long as it's unique and it's the same as the name property we store in the reference.
There was a problem hiding this comment.
Exactly point is that refId should be unique and same as the name property in the reference.
| return { | ||
| storedSLO: storedSloDefinitionSchema.encode({ | ||
| ...slo, | ||
| artifacts: { dashboards: dashboardsRef }, |
There was a problem hiding this comment.
Have we considered storing the dashboard id directly instead of the refId? I understand we introduce this refId to handle the case where the same dashboard is added many times but should it be a valid use case? Is there other reason for this custom refId?
Also, how will we search across all SLOs for a given dashboard id (use case: find all SLO related to this dashboard)? Is there an API on the saved object service that we can leverage to search all references of a given type (slo) at once? Or do we need to iterate over each SLO? If we store the dashboard id directly, we should be able to search them directly.
There was a problem hiding this comment.
I tried to replicate the approach we’re using to store references for rules, as described in the Kibana developer documentation.
According to the documentation:
Note how dashboard.panels[0].visualization stores the name property of the reference (not the id directly) to be able to uniquely identify this reference. This guarantees that the id the reference points to always remains up to date. If a visualization id was directly stored in dashboard.panels[0].visualization there is a risk that this id gets updated without updating the reference in the references array.
To find SLOs related to a given dashboard, I think we can leverage this property of the find method in the saved objects client:

| await transformHelper.assertExist(getSLOSummaryTransformId(sloId, 2)); | ||
| }); | ||
|
|
||
| it('updates dashboard artifacts and returns them', async () => { |
There was a problem hiding this comment.
🍰 nit: can you create two sub describe (one for with revision bump and one without). This test belongs in the without revision bump. I want to make sure we document (by test) the behaviour of updating a dashboard artifacts:
- only save the definition with the dashboard
- no revision bump (maybe assert for this)?
| return response.saved_objects | ||
| .map((slo) => this.toSLO(slo)) | ||
| .filter((slo) => slo !== undefined) as SLODefinition[]; | ||
| return response.saved_objects.map((so) => this.toSLO(so)).filter(this.isSLO); |
There was a problem hiding this comment.
👍🏻 thanks for the type guard filter
| properties: { | ||
| dashboards: { | ||
| properties: { | ||
| refId: { type: 'keyword' }, |
There was a problem hiding this comment.
If we were using the dashboard id, we could find every SLO with a specific dashboard id. I guess that's possible with the references also, can you confirm?
There was a problem hiding this comment.
We can leverage the hasReference property of the find method in the saved objects client.
We can discuss this further in the PR for the frontend part, but my idea was to reuse the component we already use to link dashboards to rules. Then, we could create a custom hook that leverages the content management client to fetch the dashboard name based on its ID. I’m not completely sure whether this logic should live in the backend, but I’d suggest handling it in the next PR, when we’ll need to display the dashboard name in the SLO details view.
I’m not sure what the SLO Summary is or how we’re using it in Kibana. Is there any documentation I can read to learn more about it?
I tested this path and I didn't find any issues, all good 👍 |
x-pack/solutions/observability/plugins/slo/server/saved_objects/slo.ts
Outdated
Show resolved
Hide resolved
afharo
left a comment
There was a problem hiding this comment.
LGTM. To give us more freedom, I'd remove the mappings addition for now.
x-pack/solutions/observability/plugins/slo/server/saved_objects/slo.ts
Outdated
Show resolved
Hide resolved
⏳ Build in-progress, with failures
Failed CI StepsTest Failures
History
|
mgiota
left a comment
There was a problem hiding this comment.
Excellent job! Great implementation replicating the approach we’re using to store references for rules!
This PR is a follow-up of #232583 and it closes #228509. Dashboards can be linked to SLOs. https://github.com/user-attachments/assets/a9593926-ad01-4c40-be1b-27b44eef81ae --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This PR is a follow-up of elastic#232583 and it closes elastic#228509. Dashboards can be linked to SLOs. https://github.com/user-attachments/assets/a9593926-ad01-4c40-be1b-27b44eef81ae --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This PR is a follow-up of elastic#232583 and it closes elastic#228509. Dashboards can be linked to SLOs. https://github.com/user-attachments/assets/a9593926-ad01-4c40-be1b-27b44eef81ae --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
First part for closing issue elastic#228509. This update handles only the server-side implementation. The solution follows a similar approach to the one used for attaching dashboards to rules. https://github.com/user-attachments/assets/329af612-f84b-426e-99e0-11f82d565079 --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This PR is a follow-up of elastic#232583 and it closes elastic#228509. Dashboards can be linked to SLOs. https://github.com/user-attachments/assets/a9593926-ad01-4c40-be1b-27b44eef81ae --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
First part for closing issue #228509.
This update handles only the server-side implementation. The solution follows a similar approach to the one used for attaching dashboards to rules.
Screen.Recording.2025-08-22.at.10.13.50.mov