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
5 changes: 5 additions & 0 deletions packages/kbn-check-saved-objects-cli/current_fields.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@
"updatedAt",
"updatedBy"
],
"alerting_rule_template": [
"name",
"ruleTypeId",
"tags"
],
"api_key_pending_invalidation": [
"apiKeyId",
"createdAt"
Expand Down
20 changes: 20 additions & 0 deletions packages/kbn-check-saved-objects-cli/current_mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,26 @@
}
}
},
"alerting_rule_template": {
"dynamic": false,
"properties": {
"name": {
"fields": {
"keyword": {
"normalizer": "lowercase",
"type": "keyword"
}
},
"type": "text"
},
"ruleTypeId": {
"type": "keyword"
},
"tags": {
"type": "keyword"
}
}
},
"api_key_pending_invalidation": {
"properties": {
"apiKeyId": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ export { registerCoreObjectTypes } from './registration';

// set minimum number of registered saved objects to ensure no object types are removed after 8.8
// declared in internal implementation explicitly to prevent unintended changes.
export const SAVED_OBJECT_TYPES_COUNT = 135 as const;
export const SAVED_OBJECT_TYPES_COUNT = 136 as const;
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"action_task_params": "cd91a48515202852ebf1fed0d999cd96f6b2823e",
"ad_hoc_run_params": "690b8991f48c73a04e6a8cf41fd4967a42f8e552",
"alert": "581f322afd6784aebdb80f872b825a928533d364",
"alerting_rule_template": "409b303ab6441623caabedd9118922670e431dd9",
"api_key_pending_invalidation": "cef0693ec88475a0e1f43614cfa6ca43c24d0338",
"apm-custom-dashboards": "9b08d5d5222131c6981a70144b1d61648757a613",
"apm-indices": "b844821e9675768b1cb78f6d91ff336ed09d4739",
Expand Down Expand Up @@ -284,6 +285,11 @@ describe('checking migration metadata changes on all registered SO types', () =>
"alert|warning: This type uses 'migrations:' WRAPPER functions that prevent detecting changes in the implementation.",
"alert|warning: The SO type owner should ensure these transform functions DO NOT mutate after they are defined.",
"==============================================================================================================",
"alerting_rule_template|global: a8ee387a4bc794ff6450017a92742b39b79e0446",
"alerting_rule_template|mappings: 6556e5b0800a79f7a18c17736ac3e795f262c23b",
"alerting_rule_template|schemas: da39a3ee5e6b4b0d3255bfef95601890afd80709",
"alerting_rule_template|10.1.0: f68ee2bf06bce643c5d9ff273d105cee963d5d8c",
"=======================================================================",
"api_key_pending_invalidation|global: 95b04002ba51622fd4512312dc80f09c2176999c",
"api_key_pending_invalidation|mappings: 6690f4f2a071feda5eec8353cdb23c0f1624910a",
"api_key_pending_invalidation|schemas: da39a3ee5e6b4b0d3255bfef95601890afd80709",
Expand Down Expand Up @@ -1222,6 +1228,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"action_task_params": "10.2.0",
"ad_hoc_run_params": "10.2.0",
"alert": "10.6.0",
"alerting_rule_template": "10.1.0",
"api_key_pending_invalidation": "10.1.0",
"apm-custom-dashboards": "10.1.0",
"apm-indices": "10.1.0",
Expand Down Expand Up @@ -1367,6 +1374,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"action_task_params": "10.2.0",
"ad_hoc_run_params": "10.2.0",
"alert": "10.6.0",
"alerting_rule_template": "10.1.0",
"api_key_pending_invalidation": "10.1.0",
"apm-custom-dashboards": "10.1.0",
"apm-indices": "10.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const previouslyRegisteredTypes = [
'action_task_params',
'ad_hoc_run_params',
'alert',
'alerting_rule_template',
'api_key_pending_invalidation',
'apm-custom-dashboards',
'apm-indices',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ import type { MigrateFunctionsObject } from '@kbn/kibana-utils-plugin/common';
import { ALERTING_CASES_SAVED_OBJECT_INDEX } from '@kbn/core-saved-objects-server';
import { alertMappings } from '../../common/saved_objects/rules/mappings';
import { rulesSettingsMappings } from './rules_settings_mappings';
import { ruleTemplateMappings } from './rule_template_mappings';
import { maintenanceWindowMappings } from './maintenance_window_mapping';
import { getMigrations } from './migrations';
import { transformRulesForExport } from './transform_rule_for_export';
import type { RawRule } from '../types';
import type { RawRule, RawRuleTemplate } from '../types';
import { getImportWarnings } from './get_import_warnings';
import { isRuleExportable } from './is_rule_exportable';
import type { RuleTypeRegistry } from '../rule_type_registry';
Expand All @@ -33,10 +34,12 @@ import {
apiKeyPendingInvalidationModelVersions,
maintenanceWindowModelVersions,
ruleModelVersions,
ruleTemplateModelVersions,
rulesSettingsModelVersions,
} from './model_versions';

export const RULE_SAVED_OBJECT_TYPE = 'alert';
export const RULE_TEMPLATE_SAVED_OBJECT_TYPE = 'alerting_rule_template';
export const AD_HOC_RUN_SAVED_OBJECT_TYPE = 'ad_hoc_run_params';
export const API_KEY_PENDING_INVALIDATION_TYPE = 'api_key_pending_invalidation';

Expand Down Expand Up @@ -211,6 +214,21 @@ export function setupSavedObjects(
modelVersions: adHocRunParamsModelVersions,
});

savedObjects.registerType({
name: RULE_TEMPLATE_SAVED_OBJECT_TYPE,
indexPattern: ALERTING_CASES_SAVED_OBJECT_INDEX,
hidden: true,
namespaceType: 'multiple-isolated',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A note that this will make the templates available only in the space where the user installed the templates. I think this is the intended behavior, but I wanted to call out just in case.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes Fleet install kibana assets in a specific space, so with that type they should be able to install the assets in the different space they are needed.

management: {
importableAndExportable: true,
getTitle(ruleTemplateSavedObject: SavedObject<RawRuleTemplate>) {
return `${ruleTemplateSavedObject.attributes.name}`;
},
},
mappings: ruleTemplateMappings,
modelVersions: ruleTemplateModelVersions,
});

// Encrypted attributes
encryptedSavedObjects.registerType({
type: RULE_SAVED_OBJECT_TYPE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export { adHocRunParamsModelVersions } from './ad_hoc_run_params_model_versions'
export { apiKeyPendingInvalidationModelVersions } from './api_key_pending_invalidation_model_versions';
export { maintenanceWindowModelVersions } from './maintenance_window_model_versions';
export { ruleModelVersions } from './rule_model_versions';
export { ruleTemplateModelVersions } from './rule_template_model_versions';
export { rulesSettingsModelVersions } from './rules_settings_model_versions';
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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 { SavedObjectsModelVersionMap } from '@kbn/core-saved-objects-server';
import { rawRuleTemplateSchemaV1 } from '../schemas/raw_rule_template';

export const ruleTemplateModelVersions: SavedObjectsModelVersionMap = {
'1': {
changes: [],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question to the @elastic/kibana-core team. When we register a new SO, should we also add all fields here?

schemas: {
forwardCompatibility: rawRuleTemplateSchemaV1.extends({}, { unknowns: 'ignore' }),
create: rawRuleTemplateSchemaV1,
},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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 { SavedObjectsTypeMappingDefinition } from '@kbn/core/server';

export const ruleTemplateMappings: SavedObjectsTypeMappingDefinition = {
dynamic: false,
properties: {
name: {
type: 'text',
fields: {
keyword: {
type: 'keyword',
normalizer: 'lowercase',
},
},
},
ruleTypeId: {
type: 'keyword',
},
tags: {
type: 'keyword',
},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* 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 { TypeOf } from '@kbn/config-schema';

import { rawRuleTemplateSchema } from './v1';

export { rawRuleTemplateSchema as rawRuleTemplateSchemaV1 };
export type RawRuleTemplate = TypeOf<typeof rawRuleTemplateSchema>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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 { schema } from '@kbn/config-schema';

import { rawRuleSchema } from '../raw_rule/v6';

export const rawRuleTemplateSchema = schema.object({
name: rawRuleSchema.getPropSchemas().name,
tags: rawRuleSchema.getPropSchemas().tags,
ruleTypeId: rawRuleSchema.getPropSchemas().alertTypeId,
schedule: rawRuleSchema.getPropSchemas().schedule,
flapping: rawRuleSchema.getPropSchemas().flapping,
alertDelay: rawRuleSchema.getPropSchemas().alertDelay,
params: rawRuleSchema.getPropSchemas().params,
});
2 changes: 2 additions & 0 deletions x-pack/platform/plugins/shared/alerting/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,4 +460,6 @@ export type {
RawRuleMonitoring,
} from './saved_objects/schemas/raw_rule';

export type { RawRuleTemplate } from './saved_objects/schemas/raw_rule_template';

export type { DataStreamAdapter } from './alerts_service/lib/data_stream_adapter';