Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
*/

export { type RelevantPanel, relevantPanelSchema } from './schema/relevant_panel/v1';
export { type RelatedDashboard, relatedDashboardSchema } from './schema/related_dashboard/v1';
export {
type RelatedDashboard,
type SuggestedDashboard,
relatedDashboardSchema,
suggestedDashboardSchema,
} from './schema/related_dashboard/v1';
export {
type GetRelatedDashboardsResponse,
getRelatedDashboardsResponseSchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ import { z } from '@kbn/zod';
import { relevantPanelSchema } from '../relevant_panel/latest';

export const relatedDashboardSchema = z.object({
id: z.string(),
title: z.string(),
matchedBy: z.object({
fields: z.array(z.string()).optional(),
index: z.array(z.string()).optional(),
linked: z.boolean().optional(),
}),
relevantPanelCount: z.number().optional(),
relevantPanels: z.array(relevantPanelSchema).optional(),
});

export const suggestedDashboardSchema = z.object({
id: z.string(),
title: z.string(),
matchedBy: z.object({
Expand All @@ -21,3 +33,4 @@ export const relatedDashboardSchema = z.object({
});

export type RelatedDashboard = z.output<typeof relatedDashboardSchema>;
export type SuggestedDashboard = z.output<typeof suggestedDashboardSchema>;
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ const alertsDynamicDashboardSuggestions = createObservabilityServerRoute({
});

const alertsClient = await ruleRegistry.getRacClientWithRequest(request);
const investigateAlertsClient = new InvestigateAlertsClient(alertsClient);
const rulesClient = await ruleRegistry.alerting.getRulesClientWithRequest(request);
const investigateAlertsClient = new InvestigateAlertsClient(alertsClient, rulesClient);

const dashboardParser = new RelatedDashboardsClient(
logger,
Expand All @@ -51,10 +52,11 @@ const alertsDynamicDashboardSuggestions = createObservabilityServerRoute({
alertId
);
try {
const { suggestedDashboards } = await dashboardParser.fetchSuggestedDashboards();
const { suggestedDashboards, linkedDashboards } =
await dashboardParser.fetchRelatedDashboards();
return {
suggestedDashboards,
linkedDashboards: [],
linkedDashboards,
};
} catch (e) {
if (e instanceof AlertNotFoundError) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,27 @@

import { omit } from 'lodash';
import { CustomThresholdParams } from '@kbn/response-ops-rule-params/custom_threshold';
import type { AlertsClient } from '@kbn/rule-registry-plugin/server';
import { DataViewSpec } from '@kbn/response-ops-rule-params/common';
import {
ALERT_RULE_PARAMETERS,
ALERT_RULE_TYPE_ID,
ALERT_RULE_UUID,
OBSERVABILITY_THRESHOLD_RULE_TYPE_ID,
fields as TECHNICAL_ALERT_FIELDS,
} from '@kbn/rule-data-utils';

export class AlertData {
constructor(private alert: any) {}
constructor(private alert: Awaited<ReturnType<AlertsClient['get']>>) {}

getRuleParameters() {
return this.alert[ALERT_RULE_PARAMETERS];
}

getRuleId() {
return this.alert[ALERT_RULE_UUID];
}

getRelevantRuleFields(): Set<string> {
const ruleParameters = this.getRuleParameters();
const relevantFields = new Set<string>();
Expand Down Expand Up @@ -81,7 +87,7 @@ export class AlertData {
}
}

getRuleTypeId() {
getRuleTypeId(): string | undefined {
return this.alert[ALERT_RULE_TYPE_ID];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
* 2.0.
*/
import { OBSERVABILITY_RULE_TYPE_IDS } from '@kbn/rule-data-utils';
import { AlertsClient } from '@kbn/rule-registry-plugin/server';
import type { RulesClientApi } from '@kbn/alerting-plugin/server/types';
import type { AlertsClient } from '@kbn/rule-registry-plugin/server';
import { AlertNotFoundError } from '../common/errors/alert_not_found_error';
import { AlertData } from './alert_data';

export class InvestigateAlertsClient {
constructor(private alertsClient: AlertsClient) {}
constructor(private alertsClient: AlertsClient, private rulesClient: RulesClientApi) {}

async getAlertById(alertId: string): Promise<AlertData> {
const indices = (await this.getAlertsIndices()) || [];
Expand All @@ -31,6 +32,10 @@ export class InvestigateAlertsClient {
}
}

async getRuleById(ruleId: string) {
return await this.rulesClient.get({ id: ruleId });
}

async getAlertsIndices() {
return await this.alertsClient.getAuthorizedAlertsIndices(OBSERVABILITY_RULE_TYPE_IDS);
}
Expand Down
Loading