Skip to content

Commit 89eb430

Browse files
[Cases] Add total observables to cases SO mapping (#241388)
## Summary This PR adds `total_observables` to SO mapping so that we can do aggregation on how many cases have reached maximum number of observables allowed. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) - [x] Review the [backport guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing) and apply applicable `backport:*` labels. --------- Co-authored-by: kibanamachine <[email protected]>
1 parent afbe65e commit 89eb430

File tree

33 files changed

+189
-11
lines changed

33 files changed

+189
-11
lines changed

packages/kbn-check-saved-objects-cli/current_fields.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@
197197
"total_alerts",
198198
"total_comments",
199199
"total_events",
200+
"total_observables",
200201
"updated_at",
201202
"updated_by",
202203
"updated_by.email",

packages/kbn-check-saved-objects-cli/current_mappings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,9 @@
651651
},
652652
"type": "nested"
653653
},
654+
"total_observables": {
655+
"type": "integer"
656+
},
654657
"owner": {
655658
"type": "keyword"
656659
},

src/core/server/integration_tests/ci_checks/saved_objects/check_registered_types.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
7979
"canvas-element": "288fd8d216eb49cbeb5e8f7491f207ef074b80dd",
8080
"canvas-workpad": "5cd605383a100a27941cca6cbf2d954aa96a16e2",
8181
"canvas-workpad-template": "f9a6ffab76ddfcd8fa3823002aa576c8f1d0e686",
82-
"cases": "1a836084eecbf7dfd56bc2ae79073727866bffb1",
82+
"cases": "d5ffb902405102c6f18b33ee6d96a2ad82358e59",
8383
"cases-comments": "235311d14fbba84faf8ce1f32c31ddb3a435bacb",
8484
"cases-configure": "66d4c64d83b464f5166005b8ffa03b721fcaaf8b",
8585
"cases-connector-mappings": "877bb4d52e9821e330622bd75fba799490ec6952",
@@ -407,8 +407,9 @@ describe('checking migration metadata changes on all registered SO types', () =>
407407
"canvas-workpad-template|warning: The SO type owner should ensure these transform functions DO NOT mutate after they are defined.",
408408
"================================================================================================================================",
409409
"cases|global: 58923536ede82aed6c22799b52c4f51f4bf66aba",
410-
"cases|mappings: 2db3f94cac5a7513ad58ec625e9994dba507b39d",
410+
"cases|mappings: 8b47dda512f5549f92ca1c6b75f0d8ce5b92a008",
411411
"cases|schemas: da39a3ee5e6b4b0d3255bfef95601890afd80709",
412+
"cases|10.8.0: 11a4a6080410fed228ddc0cf518b1b72377d9bef",
412413
"cases|10.7.0: aa0926b29680b10628ef05c77cf67564b7bff573",
413414
"cases|10.6.0: 5837259ab25e4059141fce980a861f0ba977d8a2",
414415
"cases|10.5.0: 3c7812d675d4223c11969bb1b49a4cc626c1bd1f",
@@ -1266,7 +1267,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
12661267
"canvas-element": "10.0.0",
12671268
"canvas-workpad": "10.0.0",
12681269
"canvas-workpad-template": "10.0.0",
1269-
"cases": "10.7.0",
1270+
"cases": "10.8.0",
12701271
"cases-comments": "10.1.0",
12711272
"cases-configure": "10.0.0",
12721273
"cases-connector-mappings": "10.0.0",
@@ -1413,7 +1414,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
14131414
"canvas-element": "8.9.0",
14141415
"canvas-workpad": "8.9.0",
14151416
"canvas-workpad-template": "8.9.0",
1416-
"cases": "10.7.0",
1417+
"cases": "10.8.0",
14171418
"cases-comments": "10.1.0",
14181419
"cases-configure": "7.15.0",
14191420
"cases-connector-mappings": "7.14.0",

x-pack/platform/plugins/shared/cases/common/types/api/case/v1.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ const basicCase: Case = {
136136
description: null,
137137
},
138138
],
139+
total_observables: 1,
139140
incremental_id: 123,
140141
};
141142

x-pack/platform/plugins/shared/cases/common/types/domain/case/v1.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ const basicCase = {
9494
},
9595
],
9696
observables: [],
97+
total_observables: 0,
9798
incremental_id: undefined,
9899
in_progress_at: undefined,
99100
time_to_acknowledge: undefined,
@@ -219,6 +220,7 @@ describe('CaseAttributesRt', () => {
219220
},
220221
],
221222
observables: [],
223+
total_observables: 0,
222224
in_progress_at: undefined,
223225
time_to_acknowledge: undefined,
224226
time_to_investigate: undefined,

x-pack/platform/plugins/shared/cases/common/types/domain/case/v1.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ export const CaseAttributesRt = rt.intersection([
133133
external_service: rt.union([ExternalServiceRt, rt.null]),
134134
updated_at: rt.union([rt.string, rt.null]),
135135
updated_by: rt.union([UserRt, rt.null]),
136+
total_observables: rt.union([rt.number, rt.null]),
136137
}),
137138
rt.exact(
138139
rt.partial({

x-pack/platform/plugins/shared/cases/public/containers/mock.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ export const basicCase: CaseUI = {
274274
category: null,
275275
customFields: [],
276276
observables: [],
277+
totalObservables: 0,
277278
incrementalId: undefined,
278279
};
279280

@@ -402,6 +403,7 @@ export const mockCase: CaseUI = {
402403
category: null,
403404
customFields: [],
404405
observables: [],
406+
totalObservables: 0,
405407
incrementalId: undefined,
406408
};
407409

@@ -596,6 +598,7 @@ export const basicCaseSnake: Case = {
596598
owner: SECURITY_SOLUTION_OWNER,
597599
customFields: [],
598600
incremental_id: undefined,
601+
total_observables: 0,
599602
} as Case;
600603

601604
export const caseWithAlertsSnake = {

x-pack/platform/plugins/shared/cases/server/client/cases/bulk_create.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ describe('bulkCreate', () => {
137137
"totalAlerts": 0,
138138
"totalComment": 0,
139139
"totalEvents": 0,
140+
"total_observables": 0,
140141
"updated_at": "2019-11-25T21:54:48.952Z",
141142
"updated_by": Object {
142143
"email": "[email protected]",
@@ -184,6 +185,7 @@ describe('bulkCreate', () => {
184185
"totalAlerts": 0,
185186
"totalComment": 0,
186187
"totalEvents": 0,
188+
"total_observables": 0,
187189
"updated_at": "2019-11-25T21:54:48.952Z",
188190
"updated_by": Object {
189191
"email": "[email protected]",
@@ -262,6 +264,7 @@ describe('bulkCreate', () => {
262264
"status": "open",
263265
"tags": Array [],
264266
"title": "My Case",
267+
"total_observables": 0,
265268
"updated_at": null,
266269
"updated_by": null,
267270
},
@@ -303,6 +306,7 @@ describe('bulkCreate', () => {
303306
"status": "open",
304307
"tags": Array [],
305308
"title": "My Case",
309+
"total_observables": 0,
306310
"updated_at": null,
307311
"updated_by": null,
308312
},

x-pack/platform/plugins/shared/cases/server/client/cases/bulk_update.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,7 @@ describe('update', () => {
926926
"totalAlerts": 2,
927927
"totalComment": 1,
928928
"totalEvents": 0,
929+
"total_observables": 0,
929930
"updated_at": "2019-11-25T21:54:48.952Z",
930931
"updated_by": Object {
931932
"email": "[email protected]",
@@ -973,6 +974,7 @@ describe('update', () => {
973974
"totalAlerts": 4,
974975
"totalComment": 3,
975976
"totalEvents": 0,
977+
"total_observables": 0,
976978
"updated_at": "2019-11-25T22:32:00.900Z",
977979
"updated_by": Object {
978980
"email": "[email protected]",

x-pack/platform/plugins/shared/cases/server/client/cases/observables.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export const addObservable = async (
110110
originalCase: retrievedCase,
111111
updatedAttributes: {
112112
observables: updatedObservables,
113+
total_observables: updatedObservables.length,
113114
},
114115
});
115116

@@ -199,6 +200,7 @@ export const updateObservable = async (
199200
originalCase: retrievedCase,
200201
updatedAttributes: {
201202
observables: updatedObservables,
203+
total_observables: updatedObservables.length,
202204
},
203205
});
204206

@@ -267,7 +269,10 @@ export const deleteObservable = async (
267269
await caseService.patchCase({
268270
caseId: retrievedCase.id,
269271
originalCase: retrievedCase,
270-
updatedAttributes: { observables: updatedObservables },
272+
updatedAttributes: {
273+
observables: updatedObservables,
274+
total_observables: updatedObservables.length,
275+
},
271276
});
272277
await userActionService.creator.createUserAction({
273278
userAction: {
@@ -340,6 +345,7 @@ export const bulkAddObservables = async (
340345
originalCase: retrievedCase,
341346
updatedAttributes: {
342347
observables: finalObservables,
348+
total_observables: finalObservables.length,
343349
},
344350
});
345351

0 commit comments

Comments
 (0)