[RAM] ResponseOps saved object updates (#152857)

## Summary

This PR is just the first phase for response ops to go through their
saved object attributes. The idea is to comment out all the attributes
that we all agree that we do not need to filter/search/sort/aggregate
on.

After, in a second phase/PR, we will create a new file who will
represent all of attributes in our saved object as a source of truth.
Then, we will generate our SO mappings from this source of truth to
register our saved object.

Phase 3, we will try to generate also our type from our source of truth.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Xavier Mouligneau 2023-04-18 11:02:25 -04:00 committed by GitHub
parent 9ab0c45454
commit ad2d5adf43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 271 additions and 236 deletions

View file

@ -55,9 +55,9 @@ describe('checking migration metadata changes on all registered SO types', () =>
expect(hashMap).toMatchInlineSnapshot(`
Object {
"action": "6cfc277ed3211639e37546ac625f4a68f2494215",
"action_task_params": "5f419caba96dd8c77d0f94013e71d43890e3d5d6",
"alert": "7bec97d7775a025ecf36a33baf17386b9e7b4c3c",
"action": "12c6b25ef1fffb36d8de893318f8a2bc5d6a46a6",
"action_task_params": "c725c37de66135934150465f9b1e76fe349e8a23",
"alert": "0cd1f1921014004a9ff5c0a9333ca9bde14bf748",
"api_key_pending_invalidation": "16e7bcf8e78764102d7f525542d5b616809a21ee",
"apm-indices": "d19dd7fb51f2d2cbc1f8769481721e0953f9a6d2",
"apm-server-schema": "1d42f17eff9ec6c16d3a9324d9539e2d123d0a9a",
@ -77,7 +77,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"cases-user-actions": "8ad74294b71edffa58fad7a40eea2388209477c9",
"config": "97e16b8f5dc10c404fd3b201ef36bc6c3c63dc80",
"config-global": "d9791e8f73edee884630e1cb6e4954ae513ce75e",
"connector_token": "fb05ff5afdcb6e2f20c9c6513ff7a1ab12b66f36",
"connector_token": "aff1aa0ebc0a6b44b570057972af25178b0bca42",
"core-usage-stats": "b3c04da317c957741ebcdedfea4524049fdc79ff",
"csp-rule-template": "099c229bf97578d9ca72b3a672d397559b84ee0b",
"dashboard": "71e3f8dfcffeb5fbd410dec81ce46f5691763c43",
@ -124,7 +124,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"osquery-pack-asset": "18e08979d46ee7e5538f54c080aec4d8c58516ca",
"osquery-saved-query": "f5e4e303f65c7607248ea8b2672f1ee30e4fb15e",
"query": "cfc049e1f0574fb4fdb2d653d7c10bdc970a2610",
"rules-settings": "9854495c3b54b16a6625fb250c35e5504da72266",
"rules-settings": "eb8d40b7d60aeffe66831f7d5d83de28d85776d8",
"sample-data-telemetry": "c38daf1a49ed24f2a4fb091e6e1e833fccf19935",
"search": "ed3a9b1681b57d69560909d51933fdf17576ea68",
"search-session": "fae0dfc63274d6a3b90ca583802c48cab8760637",
@ -142,7 +142,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"synthetics-param": "9776c9b571d35f0d0397e8915e035ea1dc026db7",
"synthetics-privates-locations": "7d032fc788905e32152029ae7ab3d6038c48ae44",
"tag": "87f21f07df9cc37001b15a26e413c18f50d1fbfe",
"task": "ff760534a44c4cfabcf4baf8cfe8283f717cab02",
"task": "533ee80c50c47f0505846bfac73fc10962c5bc45",
"telemetry": "561b329aaed3c15b91aaf2075645be3097247612",
"ui-metric": "410a8ad28e0f44b161c960ff0ce950c712b17c52",
"upgrade-assistant-ml-upgrade-operation": "d8816e5ce32649e7a3a43e2c406c632319ff84bb",

View file

@ -9,11 +9,10 @@ import type {
SavedObject,
SavedObjectsExportTransformContext,
SavedObjectsServiceSetup,
SavedObjectsTypeMappingDefinition,
} from '@kbn/core/server';
import { EncryptedSavedObjectsPluginSetup } from '@kbn/encrypted-saved-objects-plugin/server';
import { getOldestIdleActionTask } from '@kbn/task-manager-plugin/server';
import mappings from './mappings.json';
import { actionMappings, actionTaskParamsMappings, connectorTokenMappings } from './mappings';
import { getActionsMigrations } from './actions_migrations';
import { getActionTaskParamsMigrations } from './action_task_params_migrations';
import { PreConfiguredAction, RawAction } from '../types';
@ -38,7 +37,7 @@ export function setupSavedObjects(
hidden: true,
namespaceType: 'multiple-isolated',
convertToMultiNamespaceTypeVersion: '8.0.0',
mappings: mappings.action as SavedObjectsTypeMappingDefinition,
mappings: actionMappings,
migrations: getActionsMigrations(encryptedSavedObjects),
management: {
displayName: 'connector',
@ -76,7 +75,7 @@ export function setupSavedObjects(
hidden: true,
namespaceType: 'multiple-isolated',
convertToMultiNamespaceTypeVersion: '8.0.0',
mappings: mappings.action_task_params as SavedObjectsTypeMappingDefinition,
mappings: actionTaskParamsMappings,
migrations: getActionTaskParamsMigrations(encryptedSavedObjects, preconfiguredActions),
excludeOnUpgrade: async ({ readonlyEsClient }) => {
const oldestIdleActionTask = await getOldestIdleActionTask(
@ -102,7 +101,7 @@ export function setupSavedObjects(
name: CONNECTOR_TOKEN_SAVED_OBJECT_TYPE,
hidden: true,
namespaceType: 'agnostic',
mappings: mappings.connector_token as SavedObjectsTypeMappingDefinition,
mappings: connectorTokenMappings,
management: {
importableAndExportable: false,
},

View file

@ -1,74 +0,0 @@
{
"action": {
"properties": {
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"actionTypeId": {
"type": "keyword"
},
"isMissingSecrets": {
"type": "boolean"
},
"config": {
"enabled": false,
"type": "object"
},
"secrets": {
"type": "binary"
}
}
},
"action_task_params": {
"dynamic": false,
"properties": {
"actionId": {
"type": "keyword"
},
"consumer": {
"type": "keyword"
},
"params": {
"enabled": false,
"type": "object"
},
"apiKey": {
"type": "binary"
},
"executionId": {
"type": "keyword"
},
"relatedSavedObjects": {
"enabled": false,
"type": "object"
}
}
},
"connector_token": {
"properties": {
"connectorId": {
"type": "keyword"
},
"tokenType": {
"type": "keyword"
},
"token": {
"type": "binary"
},
"expiresAt": {
"type": "date"
},
"createdAt": {
"type": "date"
},
"updatedAt": {
"type": "date"
}
}
}
}

View file

@ -0,0 +1,93 @@
/*
* 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 { SavedObjectsTypeMappingDefinition } from '@kbn/core/server';
export const actionMappings: SavedObjectsTypeMappingDefinition = {
dynamic: false,
properties: {
name: {
type: 'text',
fields: {
keyword: {
type: 'keyword',
},
},
},
actionTypeId: {
type: 'keyword',
},
// NO NEED TO BE INDEXED
// isMissingSecrets: {
// type: 'boolean',
// },
// NO NEED TO BE INDEXED
// config: {
// enabled: false,
// type: 'object',
// },
// NEED TO CHECK WITH KIBANA SECURITY
// secrets: {
// type: 'binary',
// },
},
};
export const actionTaskParamsMappings: SavedObjectsTypeMappingDefinition = {
dynamic: false,
properties: {
// NO NEED TO BE INDEXED
// actionId: {
// type: 'keyword',
// },
// consumer: {
// type: 'keyword',
// },
// params: {
// enabled: false,
// type: 'object',
// },
// apiKey: {
// type: 'binary',
// },
// executionId: {
// type: 'keyword',
// },
// relatedSavedObjects: {
// enabled: false,
// type: 'object',
// },
// source: {
// type: 'keyword'
// }
},
};
export const connectorTokenMappings: SavedObjectsTypeMappingDefinition = {
dynamic: false,
properties: {
connectorId: {
type: 'keyword',
},
tokenType: {
type: 'keyword',
},
// NO NEED TO BE INDEXED
// token: {
// type: 'binary',
// },
// expiresAt: {
// type: 'date',
// },
// createdAt: {
// type: 'date',
// },
// updatedAt: {
// type: 'date',
// },
},
};

View file

@ -6,7 +6,6 @@
*/
import { SavedObjectsTypeMappingDefinition } from '@kbn/core/server';
import { rRuleMappingsField } from './rrule_mappings_field';
export const alertMappings: SavedObjectsTypeMappingDefinition = {
dynamic: false,
@ -55,26 +54,27 @@ export const alertMappings: SavedObjectsTypeMappingDefinition = {
actionTypeId: {
type: 'keyword',
},
params: {
dynamic: false,
properties: {},
},
frequency: {
properties: {
summary: {
index: false,
type: 'boolean',
},
notifyWhen: {
index: false,
type: 'keyword',
},
throttle: {
index: false,
type: 'keyword',
},
},
},
// NO NEED TO BE INDEXED
// params: {
// dynamic: false,
// properties: {},
// },
// frequency: {
// properties: {
// summary: {
// index: false,
// type: 'boolean',
// },
// notifyWhen: {
// index: false,
// type: 'keyword',
// },
// throttle: {
// index: false,
// type: 'keyword',
// },
// },
// },
},
},
params: {
@ -106,12 +106,14 @@ export const alertMappings: SavedObjectsTypeMappingDefinition = {
updatedAt: {
type: 'date',
},
apiKey: {
type: 'binary',
},
apiKeyOwner: {
type: 'keyword',
},
// NEED TO CHECK WITH KIBANA SECURITY
// apiKey: {
// type: 'binary',
// },
// NO NEED TO BE INDEXED
// apiKeyOwner: {
// type: 'keyword',
// },
throttle: {
type: 'keyword',
},
@ -124,33 +126,34 @@ export const alertMappings: SavedObjectsTypeMappingDefinition = {
mutedInstanceIds: {
type: 'keyword',
},
meta: {
properties: {
versionApiKeyLastmodified: {
type: 'keyword',
},
},
},
// NO NEED TO BE INDEXED
// meta: {
// properties: {
// versionApiKeyLastmodified: {
// type: 'keyword',
// },
// },
// },
monitoring: {
properties: {
run: {
properties: {
history: {
properties: {
duration: {
type: 'long',
},
success: {
type: 'boolean',
},
timestamp: {
type: 'date',
},
outcome: {
type: 'keyword',
},
},
},
// history: {
// properties: {
// duration: {
// type: 'long',
// },
// success: {
// type: 'boolean',
// },
// timestamp: {
// type: 'date',
// },
// outcome: {
// type: 'keyword',
// },
// },
// },
calculated_metrics: {
properties: {
p50: {
@ -200,8 +203,8 @@ export const alertMappings: SavedObjectsTypeMappingDefinition = {
},
},
},
// There is need to query for a rule by a specific revision
revision: {
index: true, // Explicitly setting to `true` as there is need to query for a rule by a specific revision
type: 'long',
},
snoozeSchedule: {
@ -217,12 +220,14 @@ export const alertMappings: SavedObjectsTypeMappingDefinition = {
type: 'date',
format: 'strict_date_time',
},
rRule: rRuleMappingsField,
// NO NEED TO BE INDEXED
// rRule: rRuleMappingsField,
},
},
nextRun: {
type: 'date',
},
// NO NEED TO BE INDEXED
// nextRun: {
// type: 'date',
// },
// Deprecated, if you need to add new property please do it in `last_run`
executionStatus: {
properties: {
@ -268,12 +273,13 @@ export const alertMappings: SavedObjectsTypeMappingDefinition = {
outcomeOrder: {
type: 'float',
},
warning: {
type: 'text',
},
outcomeMsg: {
type: 'text',
},
// NO NEED TO BE INDEXED
// warning: {
// type: 'text',
// },
// outcomeMsg: {
// type: 'text',
// },
alertsCount: {
properties: {
active: {

View file

@ -8,37 +8,39 @@
import { SavedObjectsTypeMappingDefinition } from '@kbn/core/server';
export const rulesSettingsMappings: SavedObjectsTypeMappingDefinition = {
dynamic: false,
properties: {
flapping: {
properties: {
enabled: {
type: 'boolean',
index: false,
},
lookBackWindow: {
type: 'long',
index: false,
},
statusChangeThreshold: {
type: 'long',
index: false,
},
createdBy: {
type: 'keyword',
index: false,
},
updatedBy: {
type: 'keyword',
index: false,
},
createdAt: {
type: 'date',
index: false,
},
updatedAt: {
type: 'date',
index: false,
},
// NO NEED TO BE INDEXED
// enabled: {
// type: 'boolean',
// index: false,
// },
// lookBackWindow: {
// type: 'long',
// index: false,
// },
// statusChangeThreshold: {
// type: 'long',
// index: false,
// },
// createdBy: {
// type: 'keyword',
// index: false,
// },
// updatedBy: {
// type: 'keyword',
// index: false,
// },
// createdAt: {
// type: 'date',
// index: false,
// },
// updatedAt: {
// type: 'date',
// index: false,
// },
},
},
},

View file

@ -5,9 +5,9 @@
* 2.0.
*/
import type { SavedObjectsServiceSetup, SavedObjectsTypeMappingDefinition } from '@kbn/core/server';
import type { SavedObjectsServiceSetup } from '@kbn/core/server';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import mappings from './mappings.json';
import { taskMappings } from './mappings';
import { getMigrations } from './migrations';
import { TaskManagerConfig } from '../config';
import { getOldestIdleActionTask } from '../queries/oldest_idle_action_task';
@ -22,7 +22,7 @@ export function setupSavedObjects(
namespaceType: 'agnostic',
hidden: true,
convertToAliasScript: `ctx._id = ctx._source.type + ':' + ctx._id; ctx._source.remove("kibana")`,
mappings: mappings.task as SavedObjectsTypeMappingDefinition,
mappings: taskMappings,
migrations: getMigrations(),
indexPattern: TASK_MANAGER_INDEX,
excludeOnUpgrade: async ({ readonlyEsClient }) => {

View file

@ -1,55 +0,0 @@
{
"task": {
"properties": {
"taskType": {
"type": "keyword"
},
"scheduledAt": {
"type": "date"
},
"runAt": {
"type": "date"
},
"startedAt": {
"type": "date"
},
"retryAt": {
"type": "date"
},
"enabled": {
"type": "boolean"
},
"schedule": {
"properties": {
"interval": {
"type": "keyword"
}
}
},
"attempts": {
"type": "integer"
},
"status": {
"type": "keyword"
},
"traceparent": {
"type": "text"
},
"params": {
"type": "text"
},
"state": {
"type": "text"
},
"user": {
"type": "keyword"
},
"scope": {
"type": "keyword"
},
"ownerId": {
"type": "keyword"
}
}
}
}

View file

@ -0,0 +1,66 @@
/*
* 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 { SavedObjectsTypeMappingDefinition } from '@kbn/core/server';
export const taskMappings: SavedObjectsTypeMappingDefinition = {
dynamic: false,
properties: {
taskType: {
type: 'keyword',
},
scheduledAt: {
type: 'date',
},
runAt: {
type: 'date',
},
// NO NEED TO BE INDEXED
// startedAt: {
// type: 'date',
// },
retryAt: {
type: 'date',
},
enabled: {
type: 'boolean',
},
schedule: {
properties: {
interval: {
type: 'keyword',
},
},
},
attempts: {
type: 'integer',
},
status: {
type: 'keyword',
},
// NO NEED TO BE INDEXED
// traceparent: {
// type: 'text',
// },
// params: {
// type: 'text',
// },
// state: {
// type: 'text',
// },
// NO NEED TO BE INDEXED
// user: {
// type: 'keyword',
// },
scope: {
type: 'keyword',
},
ownerId: {
type: 'keyword',
},
},
};

View file

@ -9,13 +9,11 @@ import moment from 'moment';
import { random } from 'lodash';
import expect from '@kbn/expect';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import TaskManagerMapping from '@kbn/task-manager-plugin/server/saved_objects/mappings.json';
import { taskMappings as TaskManagerMapping } from '@kbn/task-manager-plugin/server/saved_objects/mappings';
import { ConcreteTaskInstance, BulkUpdateTaskResult } from '@kbn/task-manager-plugin/server';
import { FtrProviderContext } from '../../ftr_provider_context';
const {
task: { properties: taskManagerIndexMapping },
} = TaskManagerMapping;
const { properties: taskManagerIndexMapping } = TaskManagerMapping;
export interface RawDoc {
_id: string;