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

[8.x] Adding model versions for all remaining so types without model versions (#195500) #196457

Merged
merged 1 commit into from
Oct 16, 2024
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 @@ -60,7 +60,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"action_task_params": "b50cb5c8a493881474918e8d4985e61374ca4c30",
"ad_hoc_run_params": "d4e3c5c794151d0a4f5c71e886b2aa638da73ad2",
"alert": "05b07040b12ff45ab642f47464e8a6c903cf7b86",
"api_key_pending_invalidation": "1399e87ca37b3d3a65d269c924eda70726cfe886",
"api_key_pending_invalidation": "8f5554d1984854011b8392d9a6f7ef985bcac03c",
"apm-custom-dashboards": "b67128f78160c288bd7efe25b2da6e2afd5e82fc",
"apm-indices": "8a2d68d415a4b542b26b0d292034a28ffac6fed4",
"apm-server-schema": "58a8c6468edae3d1dc520f0134f59cf3f4fd7eff",
Expand All @@ -83,7 +83,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"cloud-security-posture-settings": "e0f61c68bbb5e4cfa46ce8994fa001e417df51ca",
"config": "179b3e2bc672626aafce3cf92093a113f456af38",
"config-global": "8e8a134a2952df700d7d4ec51abb794bbd4cf6da",
"connector_token": "5a9ac29fe9c740eb114e9c40517245c71706b005",
"connector_token": "79977ea2cb1530ba7e315b95c1b5a524b622a6b3",
"core-usage-stats": "b3c04da317c957741ebcdedfea4524049fdc79ff",
"csp-rule-template": "c151324d5f85178169395eecb12bac6b96064654",
"dashboard": "211e9ca30f5a95d5f3c27b1bf2b58e6cfa0c9ae9",
Expand Down Expand Up @@ -131,7 +131,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"lens": "5cfa2c52b979b4f8df56dd13c477e152183468b9",
"lens-ui-telemetry": "8c47a9e393861f76e268345ecbadfc8a5fb1e0bd",
"links": "1dd432cc94619a513b75cec43660a50be7aadc90",
"maintenance-window": "d893544460abad56ff7a0e25b78f78776dfe10d1",
"maintenance-window": "bf36863f5577c2d22625258bdad906eeb4cccccc",
"map": "76c71023bd198fb6b1163b31bafd926fe2ceb9da",
"metrics-data-source": "81b69dc9830699d9ead5ac8dcb9264612e2a3c89",
"metrics-explorer-view": "98cf395d0e87b89ab63f173eae16735584a8ff42",
Expand All @@ -147,7 +147,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"policy-settings-protection-updates-note": "33924bb246f9e5bcb876109cc83e3c7a28308352",
"query": "501bece68f26fe561286a488eabb1a8ab12f1137",
"risk-engine-configuration": "aea0c371a462e6d07c3ceb3aff11891b47feb09d",
"rules-settings": "892a2918ebaeba809a612b8d97cec0b07c800b5f",
"rules-settings": "ba57ef1881b3dcbf48fbfb28902d8f74442190b2",
"sample-data-telemetry": "37441b12f5b0159c2d6d5138a494c9f440e950b5",
"search": "0aa6eefb37edd3145be340a8b67779c2ca578b22",
"search-session": "b2fcd840e12a45039ada50b1355faeafa39876d1",
Expand Down
8 changes: 6 additions & 2 deletions x-pack/plugins/actions/server/saved_objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import type {
import { EncryptedSavedObjectsPluginSetup } from '@kbn/encrypted-saved-objects-plugin/server';
import { getOldestIdleActionTask } from '@kbn/task-manager-plugin/server';
import { ALERTING_CASES_SAVED_OBJECT_INDEX } from '@kbn/core-saved-objects-server';
import { actionTaskParamsModelVersions } from './model_versions';
import { actionMappings, actionTaskParamsMappings, connectorTokenMappings } from './mappings';
import { getActionsMigrations } from './actions_migrations';
import { getActionTaskParamsMigrations } from './action_task_params_migrations';
Expand All @@ -26,7 +25,11 @@ import {
ACTION_TASK_PARAMS_SAVED_OBJECT_TYPE,
CONNECTOR_TOKEN_SAVED_OBJECT_TYPE,
} from '../constants/saved_objects';
import { connectorModelVersions } from './model_versions';
import {
actionTaskParamsModelVersions,
connectorModelVersions,
connectorTokenModelVersions,
} from './model_versions';

export function setupSavedObjects(
savedObjects: SavedObjectsServiceSetup,
Expand Down Expand Up @@ -121,6 +124,7 @@ export function setupSavedObjects(
management: {
importableAndExportable: false,
},
modelVersions: connectorTokenModelVersions,
});

encryptedSavedObjects.registerType({
Expand Down
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 { SavedObjectsModelVersionMap } from '@kbn/core-saved-objects-server';
import { rawConnectorTokenSchemaV1 } from '../schemas/raw_connector_token';

export const connectorTokenModelVersions: SavedObjectsModelVersionMap = {
'1': {
changes: [],
schemas: {
forwardCompatibility: rawConnectorTokenSchemaV1.extends({}, { unknowns: 'ignore' }),
create: rawConnectorTokenSchemaV1,
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
*/

export { connectorModelVersions } from './connector_model_versions';
export { connectorTokenModelVersions } from './connector_token_model_versions';
export { actionTaskParamsModelVersions } from './action_task_params_model_versions';
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 { rawConnectorTokenSchema as rawConnectorTokenSchemaV1 } from './v1';
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.
*/

import { schema } from '@kbn/config-schema';

export const rawConnectorTokenSchema = schema.object({
createdAt: schema.string(),
connectorId: schema.string(),
expiresAt: schema.string(),
token: schema.string(),
tokenType: schema.string(),
updatedAt: schema.string(),
});
11 changes: 10 additions & 1 deletion x-pack/plugins/alerting/server/saved_objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ import {
RULES_SETTINGS_SAVED_OBJECT_TYPE,
MAINTENANCE_WINDOW_SAVED_OBJECT_TYPE,
} from '../../common';
import { ruleModelVersions, adHocRunParamsModelVersions } from './model_versions';
import {
adHocRunParamsModelVersions,
apiKeyPendingInvalidationModelVersions,
maintenanceWindowModelVersions,
ruleModelVersions,
rulesSettingsModelVersions,
} from './model_versions';

export const RULE_SAVED_OBJECT_TYPE = 'alert';
export const AD_HOC_RUN_SAVED_OBJECT_TYPE = 'ad_hoc_run_params';
Expand Down Expand Up @@ -145,6 +151,7 @@ export function setupSavedObjects(
},
},
},
modelVersions: apiKeyPendingInvalidationModelVersions,
});

savedObjects.registerType({
Expand All @@ -153,6 +160,7 @@ export function setupSavedObjects(
hidden: true,
namespaceType: 'single',
mappings: rulesSettingsMappings,
modelVersions: rulesSettingsModelVersions,
});

savedObjects.registerType({
Expand All @@ -161,6 +169,7 @@ export function setupSavedObjects(
hidden: true,
namespaceType: 'multiple-isolated',
mappings: maintenanceWindowMappings,
modelVersions: maintenanceWindowModelVersions,
});

savedObjects.registerType({
Expand Down
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 { SavedObjectsModelVersionMap } from '@kbn/core-saved-objects-server';
import { rawApiKeyPendingInvalidationSchemaV1 } from '../schemas/raw_api_key_pending_invalidation';

export const apiKeyPendingInvalidationModelVersions: SavedObjectsModelVersionMap = {
'1': {
changes: [],
schemas: {
forwardCompatibility: rawApiKeyPendingInvalidationSchemaV1.extends(
{},
{ unknowns: 'ignore' }
),
create: rawApiKeyPendingInvalidationSchemaV1,
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
*/

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 { 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 { SavedObjectsModelVersionMap } from '@kbn/core-saved-objects-server';
import { rawMaintenanceWindowSchemaV1 } from '../schemas/raw_maintenance_window';

export const maintenanceWindowModelVersions: SavedObjectsModelVersionMap = {
'1': {
changes: [],
schemas: {
forwardCompatibility: rawMaintenanceWindowSchemaV1.extends({}, { unknowns: 'ignore' }),
create: rawMaintenanceWindowSchemaV1,
},
},
};
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 { SavedObjectsModelVersionMap } from '@kbn/core-saved-objects-server';
import { rawRulesSettingsSchemaV1 } from '../schemas/raw_rules_settings';

export const rulesSettingsModelVersions: SavedObjectsModelVersionMap = {
'1': {
changes: [],
schemas: {
forwardCompatibility: rawRulesSettingsSchemaV1.extends({}, { unknowns: 'ignore' }),
create: rawRulesSettingsSchemaV1,
},
},
};
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 { rawApiKeyPendingInvalidationSchema as rawApiKeyPendingInvalidationSchemaV1 } from './v1';
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 { schema } from '@kbn/config-schema';

export const rawApiKeyPendingInvalidationSchema = schema.object({
apiKeyId: schema.string(),
createdAt: schema.string(),
});
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 { rawMaintenanceWindowSchema as rawMaintenanceWindowSchemaV1 } from './v1';
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* 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 { FilterStateStore } from '@kbn/es-query';

export const alertsFilterQuerySchema = schema.object({
kql: schema.string(),
filters: schema.arrayOf(
schema.object({
query: schema.maybe(schema.recordOf(schema.string(), schema.any())),
meta: schema.recordOf(schema.string(), schema.any()),
$state: schema.maybe(
schema.object({
store: schema.oneOf([
schema.literal(FilterStateStore.APP_STATE),
schema.literal(FilterStateStore.GLOBAL_STATE),
]),
})
),
})
),
dsl: schema.maybe(schema.string()),
});

const rRuleSchema = schema.object({
dtstart: schema.string(),
tzid: schema.string(),
freq: schema.maybe(
schema.oneOf([
schema.literal(0),
schema.literal(1),
schema.literal(2),
schema.literal(3),
schema.literal(4),
schema.literal(5),
schema.literal(6),
])
),
until: schema.maybe(schema.string()),
count: schema.maybe(schema.number()),
interval: schema.maybe(schema.number()),
wkst: schema.maybe(
schema.oneOf([
schema.literal('MO'),
schema.literal('TU'),
schema.literal('WE'),
schema.literal('TH'),
schema.literal('FR'),
schema.literal('SA'),
schema.literal('SU'),
])
),
byweekday: schema.maybe(schema.arrayOf(schema.oneOf([schema.string(), schema.number()]))),
bymonth: schema.maybe(schema.number()),
bysetpos: schema.maybe(schema.number()),
bymonthday: schema.maybe(schema.number()),
byyearday: schema.maybe(schema.number()),
byweekno: schema.maybe(schema.number()),
byhour: schema.maybe(schema.number()),
byminute: schema.maybe(schema.number()),
bysecond: schema.maybe(schema.number()),
});

const rawMaintenanceWindowEventsSchema = schema.object({
gte: schema.string(),
lte: schema.string(),
});

export const rawMaintenanceWindowSchema = schema.object({
categoryIds: schema.maybe(schema.nullable(schema.arrayOf(schema.string()))),
createdAt: schema.string(),
createdBy: schema.nullable(schema.string()),
duration: schema.number(),
enabled: schema.boolean(),
events: schema.arrayOf(rawMaintenanceWindowEventsSchema),
expirationDate: schema.string(),
rRule: rRuleSchema,
scopedQuery: schema.maybe(schema.nullable(alertsFilterQuerySchema)),
title: schema.string(),
updatedAt: schema.string(),
updatedBy: schema.nullable(schema.string()),
});
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 { rawRulesSettingsSchema as rawRulesSettingsSchemaV1 } from './v1';
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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';

export const rawRulesSettingsSchema = schema.object({
flapping: schema.maybe(
schema.object({
createdAt: schema.string(),
createdBy: schema.nullable(schema.string()),
enabled: schema.boolean(),
lookBackWindow: schema.number(),
statusChangeThreshold: schema.number(),
updatedAt: schema.string(),
updatedBy: schema.nullable(schema.string()),
})
),
queryDelay: schema.maybe(
schema.object({
createdAt: schema.string(),
createdBy: schema.nullable(schema.string()),
delay: schema.number(),
updatedAt: schema.string(),
updatedBy: schema.nullable(schema.string()),
})
),
});