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

add recommended dashboards api #213287

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@
"@kbn/observability-logs-explorer-plugin": "link:x-pack/solutions/observability/plugins/observability_logs_explorer",
"@kbn/observability-onboarding-plugin": "link:x-pack/solutions/observability/plugins/observability_onboarding",
"@kbn/observability-plugin": "link:x-pack/solutions/observability/plugins/observability",
"@kbn/observability-schema": "link:x-pack/solutions/observability/packages/kbn-observability-schema",
"@kbn/observability-shared-plugin": "link:x-pack/solutions/observability/plugins/observability_shared",
"@kbn/observability-utils-browser": "link:x-pack/solutions/observability/packages/utils-browser",
"@kbn/observability-utils-common": "link:x-pack/solutions/observability/packages/utils-common",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const namespaces = {
ALERT_RULE_NAMESPACE,
};

const fields = {
export const fields = {
ALERT_ACTION_GROUP,
ALERT_CASE_IDS,
ALERT_DURATION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export { customThresholdParamsSchema } from './latest';
export { customThresholdParamsSchema, type CustomThresholdParams } from './latest';
export { customThresholdParamsSchema as customThresholdParamsSchemaV1 } from './v1';
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { schema } from '@kbn/config-schema';
import { TypeOf, schema } from '@kbn/config-schema';
import { COMPARATORS } from '@kbn/alerting-comparators';
import { dataViewSpecSchema } from '../common';
import { oneOfLiterals, validateKQLStringFilter, LEGACY_COMPARATORS } from '../common/utils';
Expand Down Expand Up @@ -85,3 +84,5 @@ export const customThresholdParamsSchema = schema.object(
},
{ unknowns: 'allow' }
);

export type CustomThresholdParams = TypeOf<typeof customThresholdParamsSchema>;
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ import {
optionsSchema,
} from './cm_services';
import { CONTENT_ID } from '../../../common/content_management';
import { DashboardSavedObjectAttributes } from '../../dashboard_saved_object';
import { type DashboardSavedObjectAttributes } from '../../dashboard_saved_object';

export { type DashboardSavedObjectAttributes } from '../../dashboard_saved_object';

export type DashboardOptions = TypeOf<typeof optionsSchema>;

Expand Down
4 changes: 2 additions & 2 deletions src/platform/plugins/shared/dashboard/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function plugin(initializerContext: PluginInitializerContext) {
}

export type { DashboardPluginSetup, DashboardPluginStart } from './types';
export type { DashboardAttributes } from './content_management';
export type { DashboardSavedObjectAttributes } from './dashboard_saved_object';
export type { DashboardAttributes, DashboardPanel } from './content_management';
export type { DashboardSavedObjectAttributes, SavedDashboardPanel } from './dashboard_saved_object';

export { PUBLIC_API_PATH } from './api/constants';
2 changes: 2 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -1356,6 +1356,8 @@
"@kbn/observability-onboarding-plugin/*": ["x-pack/solutions/observability/plugins/observability_onboarding/*"],
"@kbn/observability-plugin": ["x-pack/solutions/observability/plugins/observability"],
"@kbn/observability-plugin/*": ["x-pack/solutions/observability/plugins/observability/*"],
"@kbn/observability-schema": ["x-pack/solutions/observability/packages/kbn-observability-schema"],
"@kbn/observability-schema/*": ["x-pack/solutions/observability/packages/kbn-observability-schema/*"],
"@kbn/observability-shared-plugin": ["x-pack/solutions/observability/plugins/observability_shared"],
"@kbn/observability-shared-plugin/*": ["x-pack/solutions/observability/plugins/observability_shared/*"],
"@kbn/observability-synthetics-test-data": ["x-pack/solutions/observability/packages/synthetics-test-data"],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @kbn/observability-schema

Provides schema for generic Observability apis
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export * from './related_dashboards/latest';
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

module.exports = {
preset: '@kbn/test',
rootDir: '../../../../..',
roots: ['<rootDir>/x-pack/solutions/observability/packages/kbn-observability-schema'],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "shared-common",
"id": "@kbn/observability-schema",
"owner": "@elastic/obs-ux-management-team",
"group": "observability",
"visibility": "private",
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@kbn/observability-schema",
"descriptio": "Utils to generate observability synthetics test data",
"author": "UX Management",
"private": true,
"version": "1.0.0",
"license": "Elastic License 2.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export { type RelevantPanel, relevantPanelSchema } from './schema/relevant_panel/v1';
export {
type RecommendedDashboard,
recommendedDashboardSchema,
} from './schema/recommended_dashboard/v1';
export {
type GetRelatedDashboardsResponse,
getRelatedDashboardsResponseSchema,
getRelatedDashboardsParamsSchema,
} from './rest_specs/get_related_dashboards/v1';
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export {
type GetRelatedDashboardsResponse,
getRelatedDashboardsResponseSchema,
getRelatedDashboardsParamsSchema,
} from './v1';
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { z } from '@kbn/zod';
import { recommendedDashboardSchema } from '../../schema/recommended_dashboard/v1';

export const getRelatedDashboardsParamsSchema = z.object({
query: z.object({
alertId: z.string(),
}),
});

export const getRelatedDashboardsResponseSchema = z.object({
dashboards: z.array(recommendedDashboardSchema),
});

export type GetRelatedDashboardsResponse = z.output<typeof getRelatedDashboardsResponseSchema>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export { type RecommendedDashboard, recommendedDashboardSchema } from './v1';
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { z } from '@kbn/zod';
import { relevantPanelSchema } from '../relevant_panel/latest';

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

export type RecommendedDashboard = z.output<typeof recommendedDashboardSchema>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export { type RelevantPanel, relevantPanelSchema } from './v1';
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { z } from '@kbn/zod';

export const relevantPanelSchema = z.object({
panel: z.object({
panelIndex: z.string(),
type: z.string(),
embeddableConfig: z.record(z.string(), z.any()),
title: z.string().optional(),
}),
matchedBy: z.object({
fields: z.array(z.string()).optional(),
index: z.array(z.string()).optional(),
}),
});

export type RelevantPanel = z.output<typeof relevantPanelSchema>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "../../../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": [
"jest",
"node"
]
},
"include": [
"**/*.ts",
],
"exclude": [
"target/**/*"
],
"kbn_references": [
"@kbn/zod"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ import { DISCOVER_APP_LOCATOR, type DiscoverAppLocatorParams } from '@kbn/discov
import { FeaturesPluginSetup } from '@kbn/features-plugin/server';
import type { GuidedOnboardingPluginSetup } from '@kbn/guided-onboarding-plugin/server';
import { i18n } from '@kbn/i18n';
import { RuleRegistryPluginSetupContract } from '@kbn/rule-registry-plugin/server';
import {
RuleRegistryPluginSetupContract,
RuleRegistryPluginStartContract,
} from '@kbn/rule-registry-plugin/server';
import { SharePluginSetup } from '@kbn/share-plugin/server';
import { SpacesPluginSetup, SpacesPluginStart } from '@kbn/spaces-plugin/server';
import { UsageCollectionSetup } from '@kbn/usage-collection-plugin/server';
Expand Down Expand Up @@ -70,6 +73,7 @@ interface PluginStart {
alerting: AlertingServerStart;
spaces?: SpacesPluginStart;
dataViews: DataViewsServerPluginStart;
ruleRegistry: RuleRegistryPluginStartContract;
}

const alertingFeatures = OBSERVABILITY_RULE_TYPE_IDS_WITH_SUPPORTED_STACK_RULE_TYPES.map(
Expand Down Expand Up @@ -192,6 +196,7 @@ export class ObservabilityPlugin
...plugins,
core,
},
ruleRegistry: pluginStart.ruleRegistry,
dataViews: pluginStart.dataViews,
spaces: pluginStart.spaces,
ruleDataService,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import {
getRelatedDashboardsParamsSchema,
GetRelatedDashboardsResponse,
} from '@kbn/observability-schema';
import { createObservabilityServerRoute } from '../create_observability_server_route';
import { createDashboardsClient } from '../../services/create_dashboards_client';
import { SuggestedDashboardsClient } from '../../services/suggested_dashboards_client';
import { InvestigateAlertsClient } from '../../services/investigate_alerts_client';

const alertsDynamicDashboardSuggestions = createObservabilityServerRoute({
endpoint: 'GET /api/observability/alerts/related_dashboards 2023-10-31',
security: {
authz: {
enabled: false,
reason: 'TODO: This endpoint returns related dashboards requires no specific authorization',
},
},
options: { access: 'public' },
params: getRelatedDashboardsParamsSchema,
handler: async (services): Promise<GetRelatedDashboardsResponse> => {
const { dependencies, params, request, context, logger } = services;
const { alertId } = params.query;
const { ruleRegistry } = dependencies;

const alertsClient = await ruleRegistry.getRacClientWithRequest(request);
const investigateAlertsClient = new InvestigateAlertsClient(alertsClient);

const dashboardClient = await createDashboardsClient({ request, context });
const dashboardParser = new SuggestedDashboardsClient({
logger,
dashboardClient,
alertId,
alertsClient: investigateAlertsClient,
});
const { dashboards } = await dashboardParser.fetchSuggestedDashboards();
return {
dashboards,
};
},
});

export const alertsRouteRepository = alertsDynamicDashboardSuggestions;
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import { EndpointOf } from '@kbn/server-route-repository';
import { ObservabilityConfig } from '..';
import { aiAssistantRouteRepository } from './assistant/route';
import { rulesRouteRepository } from './rules/route';
import { alertsRouteRepository } from './alerts/route';

export function getObservabilityServerRouteRepository(config: ObservabilityConfig) {
const repository = {
...aiAssistantRouteRepository,
...rulesRouteRepository,
...alertsRouteRepository,
};
return repository;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
import { RulesClientApi } from '@kbn/alerting-plugin/server/types';
import { CoreSetup, KibanaRequest, Logger } from '@kbn/core/server';
import { DataViewsServerPluginStart } from '@kbn/data-views-plugin/server';
import { RuleDataPluginService } from '@kbn/rule-registry-plugin/server';
import {
RuleDataPluginService,
RuleRegistryPluginStartContract,
} from '@kbn/rule-registry-plugin/server';
import { registerRoutes as registerServerRoutes } from '@kbn/server-route-repository';
import { SpacesPluginStart } from '@kbn/spaces-plugin/server';
import { AlertDetailsContextualInsightsService } from '../services';
Expand All @@ -28,6 +31,7 @@ export interface RegisterRoutesDependencies {
dataViews: DataViewsServerPluginStart;
spaces?: SpacesPluginStart;
ruleDataService: RuleDataPluginService;
ruleRegistry: RuleRegistryPluginStartContract;
assistant: {
alertDetailsContextualInsightsService: AlertDetailsContextualInsightsService;
};
Expand Down
Loading