Skip to content
Closed
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
5 changes: 5 additions & 0 deletions src/platform/packages/shared/kbn-utility-types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,8 @@ export type RecursivePartial<T> = {
: RecursivePartial<T[P]>;
};
type NonAny = number | boolean | string | symbol | null;

/**
* Utility type for making all properties of an object nullable.
*/
export type Nullable<T extends object> = { [K in keyof T]: T[K] | null };
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
export const SIEM_MIGRATIONS_ASSISTANT_USER = 'assistant';

export const SIEM_MIGRATIONS_PATH = '/internal/siem_migrations' as const;

// TODO: Move `SIEM_RULE_MIGRATIONS_PATH` and composed paths to rules/constants.ts
export const SIEM_RULE_MIGRATIONS_PATH = `${SIEM_MIGRATIONS_PATH}/rules` as const;

export const SIEM_RULE_MIGRATIONS_ALL_STATS_PATH = `${SIEM_RULE_MIGRATIONS_PATH}/stats` as const;
Expand Down Expand Up @@ -61,11 +63,17 @@ export enum SiemMigrationRetryFilter {
NOT_FULLY_TRANSLATED = 'not_fully_translated',
}

// TODO: Refactor all uses of `RuleTranslationResult` -> `MigrationTranslationResult`
export enum RuleTranslationResult {
FULL = 'full',
PARTIAL = 'partial',
UNTRANSLATABLE = 'untranslatable',
}
export enum MigrationTranslationResult {
FULL = 'full',
PARTIAL = 'partial',
UNTRANSLATABLE = 'untranslatable',
}

export const DEFAULT_TRANSLATION_FIELDS = {
from: 'now-360s',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,23 @@ import { SIEM_MIGRATIONS_PATH } from '../constants';

export const SIEM_DASHBOARD_MIGRATIONS_PATH = `${SIEM_MIGRATIONS_PATH}/dashboards` as const;

export const SIEM_DASHBOARD_MIGRATION_EVALUATE_PATH =
`${SIEM_DASHBOARD_MIGRATIONS_PATH}/evaluate` as const;

// Migration ID specific routes

export const SIEM_DASHBOARD_MIGRATION_PATH =
`${SIEM_DASHBOARD_MIGRATIONS_PATH}/{migration_id}` as const;

export const SIEM_DASHBOARD_MIGRATION_DASHBOARDS_PATH =
`${SIEM_DASHBOARD_MIGRATION_PATH}/dashboards` as const;

export const SIEM_DASHBOARD_MIGRATION_START_PATH =
`${SIEM_DASHBOARD_MIGRATION_PATH}/start` as const;
export const SIEM_DASHBOARD_MIGRATION_STOP_PATH = `${SIEM_DASHBOARD_MIGRATION_PATH}/stop` as const;

export const SIEM_DASHBOARD_MIGRATION_STATS_PATH =
`${SIEM_DASHBOARD_MIGRATION_PATH}/stats` as const;

export const SIEM_DASHBOARD_MIGRATION_DASHBOARDS_PATH =
`${SIEM_DASHBOARD_MIGRATION_PATH}/dashboards` as const;
export const SIEM_DASHBOARD_MIGRATION_TRANSLATION_STATS_PATH =
`${SIEM_DASHBOARD_MIGRATION_PATH}/translation_stats` as const;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* 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 './resource_identifier';
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.
*/
// TODO: move resource related types to migration.gen.ts
import type { RuleMigrationResourceBase } from '../../model/rule_migration.gen';
import type { DashboardMigrationDashboard } from '../../model/dashboard_migration.gen';
import { ResourceIdentifier } from '../../resources/resource_identifier';
import type { SiemMigrationVendor } from '../../types';

export class DashboardResourceIdentifier extends ResourceIdentifier<DashboardMigrationDashboard> {
protected getVendor(): SiemMigrationVendor {
return this.item.original_dashboard.vendor;
}

public fromOriginal(rule?: DashboardMigrationDashboard): RuleMigrationResourceBase[] {
const originalDashboard = rule?.original_dashboard ?? this.item.original_dashboard;
const queries: string[] = []; // TODO: Parse the originalDashboard to extract the queries
return queries.flatMap((query) => this.identifier(query));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* 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 type { SiemMigrationFilters } from '../types';

export interface DashboardMigrationFilters extends SiemMigrationFilters {
searchTerm?: string;
installed?: boolean;
installable?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@
import { z } from '@kbn/zod';

import { NonEmptyString } from '../../../../api/model/primitives.gen';
import { DashboardMigration, DashboardMigrationTaskStats } from '../../dashboard_migration.gen';
import {
DashboardMigration,
DashboardMigrationTaskExecutionSettings,
DashboardMigrationRetryFilter,
DashboardMigrationTaskStats,
} from '../../dashboard_migration.gen';
import { SplunkOriginalDashboardExport } from '../../vendor/dashboards/splunk.gen';
import { LangSmithOptions } from '../../common.gen';

export type CreateDashboardMigrationRequestBody = z.infer<
typeof CreateDashboardMigrationRequestBody
Expand Down Expand Up @@ -82,3 +88,57 @@ export type GetDashboardMigrationStatsRequestParamsInput = z.input<

export type GetDashboardMigrationStatsResponse = z.infer<typeof GetDashboardMigrationStatsResponse>;
export const GetDashboardMigrationStatsResponse = DashboardMigrationTaskStats;

export type StartDashboardsMigrationRequestParams = z.infer<
typeof StartDashboardsMigrationRequestParams
>;
export const StartDashboardsMigrationRequestParams = z.object({
migration_id: NonEmptyString,
});
export type StartDashboardsMigrationRequestParamsInput = z.input<
typeof StartDashboardsMigrationRequestParams
>;

export type StartDashboardsMigrationRequestBody = z.infer<
typeof StartDashboardsMigrationRequestBody
>;
export const StartDashboardsMigrationRequestBody = z.object({
/**
* Settings applicable to current dashboard migration task execution.
*/
settings: DashboardMigrationTaskExecutionSettings,
langsmith_options: LangSmithOptions.optional(),
/**
* The optional indicator to retry the dashboard translation based on this filter criteria.
*/
retry: DashboardMigrationRetryFilter.optional(),
});
export type StartDashboardsMigrationRequestBodyInput = z.input<
typeof StartDashboardsMigrationRequestBody
>;

export type StartDashboardsMigrationResponse = z.infer<typeof StartDashboardsMigrationResponse>;
export const StartDashboardsMigrationResponse = z.object({
/**
* Indicates the migration has been started. `false` means the migration does not need to be started.
*/
started: z.boolean(),
});

export type StopDashboardsMigrationRequestParams = z.infer<
typeof StopDashboardsMigrationRequestParams
>;
export const StopDashboardsMigrationRequestParams = z.object({
migration_id: NonEmptyString,
});
export type StopDashboardsMigrationRequestParamsInput = z.input<
typeof StopDashboardsMigrationRequestParams
>;

export type StopDashboardsMigrationResponse = z.infer<typeof StopDashboardsMigrationResponse>;
export const StopDashboardsMigrationResponse = z.object({
/**
* Indicates the migration has been stopped.
*/
stopped: z.boolean(),
});
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,86 @@ paths:
200:
description: Indicates dashboards have been added to the migration successfully.

/internal/siem_migrations/dashboards/{migration_id}/start:
post:
summary: Starts a dashboard migration
operationId: StartDashboardsMigration
x-codegen-enabled: true
x-internal: true
description: Starts a SIEM dashboards migration using the migration id provided
tags:
- SIEM Dashboard Migrations
parameters:
- name: migration_id
in: path
required: true
schema:
description: The migration id to start
$ref: '../../../../../common/api/model/primitives.schema.yaml#/components/schemas/NonEmptyString'
requestBody:
required: true
content:
application/json:
schema:
type: object
required:
- settings
properties:
settings:
$ref: '../../dashboard_migration.schema.yaml#/components/schemas/DashboardMigrationTaskExecutionSettings'
description: Settings applicable to current dashboard migration task execution.
langsmith_options:
$ref: '../../common.schema.yaml#/components/schemas/LangSmithOptions'
retry:
$ref: '../../dashboard_migration.schema.yaml#/components/schemas/DashboardMigrationRetryFilter'
description: The optional indicator to retry the dashboard translation based on this filter criteria.
responses:
200:
description: Indicates the migration start request has been processed successfully.
content:
application/json:
schema:
type: object
required:
- started
properties:
started:
type: boolean
description: Indicates the migration has been started. `false` means the migration does not need to be started.
204:
description: Indicates the migration id was not found.

/internal/siem_migrations/dashboards/{migration_id}/stop:
post:
summary: Stops an existing dashboard migration
operationId: StopDashboardsMigration
x-codegen-enabled: true
x-internal: true
description: Stops a running SIEM dashboards migration using the migration id provided
tags:
- SIEM Dashboard Migrations
parameters:
- name: migration_id
in: path
required: true
schema:
description: The migration id to stop
$ref: '../../../../../common/api/model/primitives.schema.yaml#/components/schemas/NonEmptyString'
responses:
200:
description: Indicates migration task stop has been processed successfully.
content:
application/json:
schema:
type: object
required:
- stopped
properties:
stopped:
type: boolean
description: Indicates the migration has been stopped.
204:
description: Indicates the migration id was not found running.

/internal/siem_migrations/dashboards/{migration_id}/stats:
get:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,52 +49,3 @@ export const LangSmithEvaluationOptions = LangSmithOptions.merge(
dataset: z.string(),
})
);

/**
* The status of migration.
*/
export type MigrationStatus = z.infer<typeof MigrationStatus>;
export const MigrationStatus = z.enum(['pending', 'processing', 'completed', 'failed']);
export type MigrationStatusEnum = typeof MigrationStatus.enum;
export const MigrationStatusEnum = MigrationStatus.enum;

/**
* The status of the migration task.
*/
export type MigrationTaskStatus = z.infer<typeof MigrationTaskStatus>;
export const MigrationTaskStatus = z.enum([
'ready',
'running',
'stopped',
'finished',
'interrupted',
]);
export type MigrationTaskStatusEnum = typeof MigrationTaskStatus.enum;
export const MigrationTaskStatusEnum = MigrationTaskStatus.enum;

/**
* The last execution of a migration task.
*/
export type MigrationLastExecution = z.infer<typeof MigrationLastExecution>;
export const MigrationLastExecution = z.object({
/**
* The moment the last execution started.
*/
started_at: z.string().optional(),
/**
* The moment the last execution finished.
*/
finished_at: z.string().nullable().optional(),
/**
* The connector ID used for the last execution.
*/
connector_id: z.string().optional(),
/**
* The error message if the last execution failed.
*/
error: z.string().nullable().optional(),
/**
* Indicates if the last execution was stopped by the user.
*/
is_stopped: z.boolean().optional(),
});
Original file line number Diff line number Diff line change
Expand Up @@ -35,45 +35,3 @@ components:
dataset:
type: string
description: The dataset name to use for evaluations.

MigrationStatus:
type: string
description: The status of migration.
enum: # should match SiemMigrationsStatus enum at ../constants.ts
- pending
- processing
- completed
- failed

MigrationTaskStatus:
type: string
description: The status of the migration task.
enum: # should match SiemMigrationTaskStatus enum at ../constants.ts
- ready
- running
- stopped
- finished
- interrupted

MigrationLastExecution:
type: object
description: The last execution of a migration task.
properties:
started_at:
type: string
description: The moment the last execution started.
finished_at:
type: string
nullable: true
description: The moment the last execution finished.
connector_id:
type: string
description: The connector ID used for the last execution.
error:
type: string
nullable: true
description: The error message if the last execution failed.
is_stopped:
type: boolean
description: Indicates if the last execution was stopped by the user.

Loading