[Incident Management] [Suggested dashboards] Deduplicated linked dashboards from list of linked dashboards#221972
Conversation
|
/ci |
|
/ci |
|
Pinging @elastic/obs-ux-management-team (Team:obs-ux-management) |
justinkambic
left a comment
There was a problem hiding this comment.
A few comments regarding ways we could possibly improve error handling/logging.
Code looks good, I tested this locally with a few dashboards I made to ensure they're deduped.
...k/solutions/observability/plugins/observability/server/services/investigate_alerts_client.ts
Show resolved
Hide resolved
| const relevantDashboardsById = new Map<string, SuggestedDashboard>(); | ||
| const index = await this.getRuleQueryIndex(); | ||
| if (!this.alert) { | ||
| throw new Error('Alert not found. Could not fetch suggested dashboards.'); |
There was a problem hiding this comment.
I'm noticing repetition of this throw pattern a few times throughout this class, and an inconsistent error message where sometimes the alert ID is included and other times it's not. Since alertId is a required var for this class, perhaps we can extract this throw procedure into the private function and avoid ad-hoc throw Error calls for the same purpose repeated throughout the class. It will make the error messages more standardized when researching issues if they come up as well.
Something like:
private checkAlert(): AlertData {
if (!this.alert) throw new Error(`Alert with id ${this.alertId} not found. Could not fetch related dashboards.`);
return this.alert;
}| const allSuggestedDashboards = new Set<SuggestedDashboard>(); | ||
| const relevantDashboardsById = new Map<string, SuggestedDashboard>(); | ||
| const index = await this.getRuleQueryIndex(); | ||
| if (!this.alert) { |
There was a problem hiding this comment.
Put this condition at the top of the function since it's a no-op? Also, kind of related to my comment below but also different, this exact check happens within getRuleQueryIndex, so the error thrown inside this block will never execute. This is probably fine, because the implementation of getRuleQueryIndex could change in the future. In any case, doing the throw here at the top instead of in the nested function call will make reading the stack trace easier, too.
| if (allRelevantFields.length > 0) { | ||
| const { dashboards } = this.getDashboardsByField(allRelevantFields); | ||
| dashboards.forEach((dashboard) => allRelatedDashboards.add(dashboard)); | ||
| const { dashboards } = this.getDashboardsByField(Array.from(allRelevantFields)); |
There was a problem hiding this comment.
| const { dashboards } = this.getDashboardsByField(Array.from(allRelevantFields)); | |
| const { dashboards } = this.getDashboardsByField(allRelevantFields); |
I think we can cut this as allRelevantFields is already typed as string[].
There was a problem hiding this comment.
Interesting. Wondering if you're looking at an old commit. I don't have this on my branch.
There was a problem hiding this comment.
JK I was on my backport repo looking at this.
| this.getLinkedDashboards(), | ||
| ]); | ||
| const filteredSuggestedDashboards = suggestedDashboards.filter( | ||
| (suggested) => !linkedDashboards.some((linked) => linked.id === suggested.id) |
There was a problem hiding this comment.
My initial impression was "why not use the set method we have below to get O(1) lookup" but I am thinking we are only going to have a handful of linked dashboards in most cases, where N=10 or less, so probably not needed. Agree? Just a thought.
| }; | ||
| } | ||
|
|
||
| async fetchSuggestedDashboards(): Promise<SuggestedDashboard[]> { |
There was a problem hiding this comment.
| async fetchSuggestedDashboards(): Promise<SuggestedDashboard[]> { | |
| private async fetchSuggestedDashboards(): Promise<SuggestedDashboard[]> { |
We could optionally encapsulate this function as we only call it internally in RelatedDashboardsClient. I do see it's referenced in the test file so if you'd rather keep it public for that purpose to avoid complicating testing I'm ok with that.
| getRuleQueryIndex(): string | null { | ||
| if (!this.alert) { | ||
| throw new Error('Alert not found. Could not get the rule query index.'); | ||
| throw new Error('Alert not found. Could not get rule query index.'); |
There was a problem hiding this comment.
Similar to above comment about standardizing some/all of the alert-related throws. It looks like in this case there might be some difference in the information the error needs to convey, but the condition is the same.
| if (!this.alert) { | ||
| throw new Error('Alert not found. Could not get linked dashboards.'); | ||
| } | ||
| const ruleId = this.alert.getRuleId(); | ||
| if (!ruleId) { | ||
| this.logger.warn(`Rule id not found. No linked dashboards available.`); | ||
| return []; | ||
| } |
There was a problem hiding this comment.
I've been wondering about this; is there a reason we can simply log a warning and return an empty set here while we need to throw if the alert is null?
There was a problem hiding this comment.
The rule is only necessary for linked dashboards, but technically we could still return suggested dashboards if linked dashboards fail. I don't know if that's the right UX though. We can keep it consistent by throwing the error here as well.
…rvices/investigate_alerts_client.ts Co-authored-by: Justin Kambic <jk@elastic.co>
justinkambic
left a comment
There was a problem hiding this comment.
LGTM, can implement any other suggestions if you think they're worthwhile but the error throwing aspect was the only part I was truly concerned with.
…erts-related-dashboards-deduplicate-suggested
💚 Build Succeeded
Metrics [docs]Public APIs missing comments
History
|
|
Starting backport for target branches: 8.19 https://github.com/elastic/kibana/actions/runs/15599303794 |
…boards from list of linked dashboards (elastic#221972) ## Summary Resolves elastic#212801 Removes already linked dashboards from the list of suggested dashboards Also has the side effect of returning the linked dashboards from the related dashboards api, which can be used to render the linked dashboards list along with the suggested dashboards, rather than calling a separate API from the client. --------- Co-authored-by: Justin Kambic <jk@elastic.co> (cherry picked from commit 3382566)
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
|
Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync. |
…boards from list of linked dashboards (elastic#221972) ## Summary Resolves elastic#212801 Removes already linked dashboards from the list of suggested dashboards Also has the side effect of returning the linked dashboards from the related dashboards api, which can be used to render the linked dashboards list along with the suggested dashboards, rather than calling a separate API from the client. --------- Co-authored-by: Justin Kambic <jk@elastic.co>
|
Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync. |
…ed dashboards from list of linked dashboards (#221972) (#223488) # Backport This will backport the following commits from `main` to `8.19`: - [[Incident Management] [Suggested dashboards] Deduplicated linked dashboards from list of linked dashboards (#221972)](#221972) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Dominique Clarke","email":"dominique.clarke@elastic.co"},"sourceCommit":{"committedDate":"2025-06-12T01:18:22Z","message":"[Incident Management] [Suggested dashboards] Deduplicated linked dashboards from list of linked dashboards (#221972)\n\n## Summary\n\nResolves https://github.com/elastic/kibana/issues/212801\n\nRemoves already linked dashboards from the list of suggested dashboards\n\nAlso has the side effect of returning the linked dashboards from the\nrelated dashboards api, which can be used to render the linked\ndashboards list along with the suggested dashboards, rather than calling\na separate API from the client.\n\n---------\n\nCo-authored-by: Justin Kambic <jk@elastic.co>","sha":"33825663e9118940eebc9fb6a16ec40cb9342cc7","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:obs-ux-management","backport:version","v9.1.0","v8.19.0","author:obs-ux-management"],"title":"[Incident Management] [Suggested dashboards] Deduplicated linked dashboards from list of linked dashboards","number":221972,"url":"https://github.com/elastic/kibana/pull/221972","mergeCommit":{"message":"[Incident Management] [Suggested dashboards] Deduplicated linked dashboards from list of linked dashboards (#221972)\n\n## Summary\n\nResolves https://github.com/elastic/kibana/issues/212801\n\nRemoves already linked dashboards from the list of suggested dashboards\n\nAlso has the side effect of returning the linked dashboards from the\nrelated dashboards api, which can be used to render the linked\ndashboards list along with the suggested dashboards, rather than calling\na separate API from the client.\n\n---------\n\nCo-authored-by: Justin Kambic <jk@elastic.co>","sha":"33825663e9118940eebc9fb6a16ec40cb9342cc7"}},"sourceBranch":"main","suggestedTargetBranches":["8.19"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/221972","number":221972,"mergeCommit":{"message":"[Incident Management] [Suggested dashboards] Deduplicated linked dashboards from list of linked dashboards (#221972)\n\n## Summary\n\nResolves https://github.com/elastic/kibana/issues/212801\n\nRemoves already linked dashboards from the list of suggested dashboards\n\nAlso has the side effect of returning the linked dashboards from the\nrelated dashboards api, which can be used to render the linked\ndashboards list along with the suggested dashboards, rather than calling\na separate API from the client.\n\n---------\n\nCo-authored-by: Justin Kambic <jk@elastic.co>","sha":"33825663e9118940eebc9fb6a16ec40cb9342cc7"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> --------- Co-authored-by: Dominique Clarke <dominique.clarke@elastic.co> Co-authored-by: Justin Kambic <jk@elastic.co>
Summary
Resolves #212801
Removes already linked dashboards from the list of suggested dashboards
Also has the side effect of returning the linked dashboards from the related dashboards api, which can be used to render the linked dashboards list along with the suggested dashboards, rather than calling a separate API from the client.