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

# Backport

This will backport the following commits from `main` to `8.x`:
- [Adding model versions for all remaining so types without model
versions (#195500)](https://github.com/elastic/kibana/pull/195500)

<!--- Backport version: 8.9.8 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Ying
Mao","email":"ying.mao@elastic.co"},"sourceCommit":{"committedDate":"2024-10-15T22:22:46Z","message":"Adding
model versions for all remaining so types without model versions
(#195500)\n\nResolves
https://github.com/elastic/kibana/issues/184618\r\n\r\n##
Summary\r\n\r\nAdds v1 schemas for all remaining Response Ops owned
saved object types:\r\n* `connector_token`\r\n*
`api_key_pending_invalidation`\r\n* `maintenance-window`\r\n*
`rules-settings`\r\n\r\n## To Verify\r\n\r\n1. Run ES and Kibana on
`main` and create saved objects for each of the\r\nabove types:\r\na.
Create an OAuth ServiceNow ITOM connector to create
a\r\n`connector_token` saved object\r\nb. Create a rule, let it run, and
then delete the rule. This will create\r\nan
`api_key_pending_invalidation` SO and 2 `rules-settings` SOs\r\n c.
Create some maintenance windows, both with and without filters\r\n2.
Keep ES running and switch to this branch and restart Kibana.
Then\r\nverify you can read and modify the existing SOs with no
errors\r\na. Test the ServiceNow ITOM connector, which should read
the\r\n`connector_token` SO\r\nb. Modify the rules settings and then run
a rule to ensure they're\r\nloaded with no errors\r\n c. Load the
maintenance window UI and edit a MW\r\n\r\nCo-authored-by: Elastic
Machine
<elasticmachine@users.noreply.github.com>","sha":"d9cd17bdbd47d66968bd5fda6fb32a08134fbc2d","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Alerting","release_note:skip","Feature:Actions","Team:ResponseOps","v9.0.0","backport:prev-minor","v8.16.0"],"number":195500,"url":"https://github.com/elastic/kibana/pull/195500","mergeCommit":{"message":"Adding
model versions for all remaining so types without model versions
(#195500)\n\nResolves
https://github.com/elastic/kibana/issues/184618\r\n\r\n##
Summary\r\n\r\nAdds v1 schemas for all remaining Response Ops owned
saved object types:\r\n* `connector_token`\r\n*
`api_key_pending_invalidation`\r\n* `maintenance-window`\r\n*
`rules-settings`\r\n\r\n## To Verify\r\n\r\n1. Run ES and Kibana on
`main` and create saved objects for each of the\r\nabove types:\r\na.
Create an OAuth ServiceNow ITOM connector to create
a\r\n`connector_token` saved object\r\nb. Create a rule, let it run, and
then delete the rule. This will create\r\nan
`api_key_pending_invalidation` SO and 2 `rules-settings` SOs\r\n c.
Create some maintenance windows, both with and without filters\r\n2.
Keep ES running and switch to this branch and restart Kibana.
Then\r\nverify you can read and modify the existing SOs with no
errors\r\na. Test the ServiceNow ITOM connector, which should read
the\r\n`connector_token` SO\r\nb. Modify the rules settings and then run
a rule to ensure they're\r\nloaded with no errors\r\n c. Load the
maintenance window UI and edit a MW\r\n\r\nCo-authored-by: Elastic
Machine
<elasticmachine@users.noreply.github.com>","sha":"d9cd17bdbd47d66968bd5fda6fb32a08134fbc2d"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/195500","number":195500,"mergeCommit":{"message":"Adding
model versions for all remaining so types without model versions
(#195500)\n\nResolves
https://github.com/elastic/kibana/issues/184618\r\n\r\n##
Summary\r\n\r\nAdds v1 schemas for all remaining Response Ops owned
saved object types:\r\n* `connector_token`\r\n*
`api_key_pending_invalidation`\r\n* `maintenance-window`\r\n*
`rules-settings`\r\n\r\n## To Verify\r\n\r\n1. Run ES and Kibana on
`main` and create saved objects for each of the\r\nabove types:\r\na.
Create an OAuth ServiceNow ITOM connector to create
a\r\n`connector_token` saved object\r\nb. Create a rule, let it run, and
then delete the rule. This will create\r\nan
`api_key_pending_invalidation` SO and 2 `rules-settings` SOs\r\n c.
Create some maintenance windows, both with and without filters\r\n2.
Keep ES running and switch to this branch and restart Kibana.
Then\r\nverify you can read and modify the existing SOs with no
errors\r\na. Test the ServiceNow ITOM connector, which should read
the\r\n`connector_token` SO\r\nb. Modify the rules settings and then run
a rule to ensure they're\r\nloaded with no errors\r\n c. Load the
maintenance window UI and edit a MW\r\n\r\nCo-authored-by: Elastic
Machine
<elasticmachine@users.noreply.github.com>","sha":"d9cd17bdbd47d66968bd5fda6fb32a08134fbc2d"}},{"branch":"8.x","label":"v8.16.0","labelRegex":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
This commit is contained in:
Ying Mao 2024-10-15 21:15:16 -04:00 committed by GitHub
parent 1549d38d02
commit d5d39e5974
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 283 additions and 7 deletions

View file

@ -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",
@ -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",
@ -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",
@ -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",

View file

@ -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';
@ -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,
@ -121,6 +124,7 @@ export function setupSavedObjects(
management: {
importableAndExportable: false,
},
modelVersions: connectorTokenModelVersions,
});
encryptedSavedObjects.registerType({

View file

@ -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,
},
},
};

View file

@ -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';

View file

@ -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';

View file

@ -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(),
});

View file

@ -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';
@ -145,6 +151,7 @@ export function setupSavedObjects(
},
},
},
modelVersions: apiKeyPendingInvalidationModelVersions,
});
savedObjects.registerType({
@ -153,6 +160,7 @@ export function setupSavedObjects(
hidden: true,
namespaceType: 'single',
mappings: rulesSettingsMappings,
modelVersions: rulesSettingsModelVersions,
});
savedObjects.registerType({
@ -161,6 +169,7 @@ export function setupSavedObjects(
hidden: true,
namespaceType: 'multiple-isolated',
mappings: maintenanceWindowMappings,
modelVersions: maintenanceWindowModelVersions,
});
savedObjects.registerType({

View file

@ -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,
},
},
};

View file

@ -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';

View file

@ -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,
},
},
};

View file

@ -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,
},
},
};

View file

@ -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';

View file

@ -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(),
});

View file

@ -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';

View file

@ -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()),
});

View file

@ -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';

View file

@ -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()),
})
),
});