From f24f4be6452c403c7d4dba69c0eb9a43d67064f2 Mon Sep 17 00:00:00 2001 From: Jonathan Buttner Date: Mon, 3 Apr 2023 13:57:51 -0400 Subject: [PATCH 1/5] Adding mime type telemetry --- .../server/telemetry/queries/cases.test.ts | 4 +-- .../cases/server/telemetry/queries/cases.ts | 18 +++++++--- .../server/telemetry/queries/utils.test.ts | 4 +-- .../cases/server/telemetry/queries/utils.ts | 35 ++++++++++++------- .../plugins/cases/server/telemetry/schema.ts | 7 ++++ .../plugins/cases/server/telemetry/types.ts | 25 ++++++++----- .../schema/xpack_plugins.json | 9 +++++ 7 files changed, 73 insertions(+), 29 deletions(-) diff --git a/x-pack/plugins/cases/server/telemetry/queries/cases.test.ts b/x-pack/plugins/cases/server/telemetry/queries/cases.test.ts index ca6049885b298..ff5bbc5470e91 100644 --- a/x-pack/plugins/cases/server/telemetry/queries/cases.test.ts +++ b/x-pack/plugins/cases/server/telemetry/queries/cases.test.ts @@ -12,7 +12,7 @@ import type { AttachmentAggregationResult, AttachmentFrameworkAggsResult, CaseAggregationResult, - FileAttachmentAggregationResult, + FileAttachmentAggregationResults, } from '../types'; import { getCasesTelemetryData } from './cases'; @@ -187,7 +187,7 @@ describe('getCasesTelemetryData', () => { ...attachmentFramework, }; - const filesRes: FileAttachmentAggregationResult = { + const filesRes: FileAttachmentAggregationResults = { securitySolution: { averageSize: 500, }, diff --git a/x-pack/plugins/cases/server/telemetry/queries/cases.ts b/x-pack/plugins/cases/server/telemetry/queries/cases.ts index 0e999721ae105..9d873a165f49d 100644 --- a/x-pack/plugins/cases/server/telemetry/queries/cases.ts +++ b/x-pack/plugins/cases/server/telemetry/queries/cases.ts @@ -23,7 +23,7 @@ import type { LatestDates, CaseAggregationResult, AttachmentAggregationResult, - FileAttachmentAggregationResult, + FileAttachmentAggregationResults, } from '../types'; import { findValueInBuckets, @@ -284,7 +284,7 @@ const getCommentsSavedObjectTelemetry = async ( const getFilesTelemetry = async ( savedObjectsClient: ISavedObjectsRepository -): Promise> => { +): Promise> => { const averageSize = () => ({ averageSize: { avg: { @@ -293,6 +293,15 @@ const getFilesTelemetry = async ( }, }); + const top20MimeTypes = () => ({ + topMimeTypes: { + terms: { + field: `${FILE_SO_TYPE}.attributes.mime_type`, + size: 20, + }, + }, + }); + const filesByOwnerAggregationQuery = OWNERS.reduce( (aggQuery, owner) => ({ ...aggQuery, @@ -304,6 +313,7 @@ const getFilesTelemetry = async ( }, aggs: { ...averageSize(), + ...top20MimeTypes(), }, }, }), @@ -312,12 +322,12 @@ const getFilesTelemetry = async ( const filterCaseIdExists = fromKueryExpression(`${FILE_SO_TYPE}.attributes.Meta.caseId: *`); - return savedObjectsClient.find({ + return savedObjectsClient.find({ page: 0, perPage: 0, type: FILE_SO_TYPE, filter: filterCaseIdExists, - aggs: { ...filesByOwnerAggregationQuery, ...averageSize() }, + aggs: { ...filesByOwnerAggregationQuery, ...averageSize(), ...top20MimeTypes() }, }); }; diff --git a/x-pack/plugins/cases/server/telemetry/queries/utils.test.ts b/x-pack/plugins/cases/server/telemetry/queries/utils.test.ts index d7c6a0e9bf7b9..4e5a975e2d9d6 100644 --- a/x-pack/plugins/cases/server/telemetry/queries/utils.test.ts +++ b/x-pack/plugins/cases/server/telemetry/queries/utils.test.ts @@ -10,7 +10,7 @@ import type { AttachmentAggregationResult, AttachmentFrameworkAggsResult, CaseAggregationResult, - FileAttachmentAggregationResult, + FileAttachmentAggregationResults, } from '../types'; import { findValueInBuckets, @@ -168,7 +168,7 @@ describe('utils', () => { ...attachmentFramework, }; - const filesRes: FileAttachmentAggregationResult = { + const filesRes: FileAttachmentAggregationResults = { securitySolution: { averageSize: 500, }, diff --git a/x-pack/plugins/cases/server/telemetry/queries/utils.ts b/x-pack/plugins/cases/server/telemetry/queries/utils.ts index 0c0a4f7bbf87d..f9eb531f3a207 100644 --- a/x-pack/plugins/cases/server/telemetry/queries/utils.ts +++ b/x-pack/plugins/cases/server/telemetry/queries/utils.ts @@ -23,8 +23,8 @@ import type { BucketsWithMaxOnCase, AttachmentStats, FileAttachmentStats, - FileAttachmentAggregationResult, - FileAttachmentAverageSize, + FileAttachmentAggregationResults, + FileAttachmentAggsResult, AttachmentFrameworkAggsResult, } from '../types'; import { buildFilter } from '../../client/utils'; @@ -170,7 +170,7 @@ export const getSolutionValues = ({ }: { caseAggregations?: CaseAggregationResult; attachmentAggregations?: AttachmentAggregationResult; - filesAggregations?: FileAttachmentAggregationResult; + filesAggregations?: FileAttachmentAggregationResults; owner: Owner; }): SolutionTelemetry => { const aggregationsBuckets = getAggregationsBuckets({ @@ -223,13 +223,15 @@ export const getAttachmentsFrameworkStats = ({ totalCasesForOwner, }: { attachmentAggregations?: AttachmentFrameworkAggsResult; - filesAggregations?: FileAttachmentAverageSize; + filesAggregations?: FileAttachmentAggsResult; totalCasesForOwner: number; }): AttachmentFramework => { if (!attachmentAggregations) { return emptyAttachmentFramework(); } + const averageFileSize = filesAggregations?.averageSize; + const topMimeTypes = filesAggregations?.topMimeTypes; return { attachmentFramework: { @@ -245,6 +247,7 @@ export const getAttachmentsFrameworkStats = ({ registryResults: attachmentAggregations.externalReferenceTypes, averageFileSize, totalCasesForOwner, + topMimeTypes, }), }, }; @@ -272,8 +275,8 @@ const getAttachmentRegistryStats = ( return stats; }; -const calculateTypePerCaseAverage = (typeDocCount: number, totalCases: number) => { - if (totalCases === 0) { +const calculateTypePerCaseAverage = (typeDocCount: number | undefined, totalCases: number) => { + if (typeDocCount == null || totalCases === 0) { return 0; } @@ -284,22 +287,27 @@ const getFileAttachmentStats = ({ registryResults, averageFileSize, totalCasesForOwner, + topMimeTypes, }: { registryResults: BucketsWithMaxOnCase; averageFileSize?: number; totalCasesForOwner: number; + topMimeTypes?: Buckets; }): FileAttachmentStats => { const fileBucket = registryResults.buckets.find((bucket) => bucket.key === FILE_ATTACHMENT_TYPE); - if (!fileBucket || averageFileSize == null) { - return emptyFileAttachment(); - } + const mimeTypes = + topMimeTypes?.buckets.map((mimeType) => ({ + count: mimeType.doc_count, + name: mimeType.key, + })) ?? []; return { - averageSize: averageFileSize, - average: calculateTypePerCaseAverage(fileBucket.doc_count, totalCasesForOwner), - maxOnACase: fileBucket.references.cases.max.value, - total: fileBucket.doc_count, + averageSize: averageFileSize ?? 0, + average: calculateTypePerCaseAverage(fileBucket?.doc_count, totalCasesForOwner), + maxOnACase: fileBucket?.references.cases.max.value ?? 0, + total: fileBucket?.doc_count ?? 0, + topMimeTypes: mimeTypes, }; }; @@ -332,4 +340,5 @@ const emptyFileAttachment = (): FileAttachmentStats => ({ averageSize: 0, maxOnACase: 0, total: 0, + topMimeTypes: [], }); diff --git a/x-pack/plugins/cases/server/telemetry/schema.ts b/x-pack/plugins/cases/server/telemetry/schema.ts index 59506c932a51f..33d44101c5a6d 100644 --- a/x-pack/plugins/cases/server/telemetry/schema.ts +++ b/x-pack/plugins/cases/server/telemetry/schema.ts @@ -51,6 +51,13 @@ const attachmentFrameworkSchema: AttachmentFrameworkSchema = { averageSize: long, maxOnACase: long, total: long, + topMimeTypes: { + type: 'array', + items: { + count: long, + name: string, + }, + }, }, }; diff --git a/x-pack/plugins/cases/server/telemetry/types.ts b/x-pack/plugins/cases/server/telemetry/types.ts index e28c3abaf4d52..f1cf2e79499ab 100644 --- a/x-pack/plugins/cases/server/telemetry/types.ts +++ b/x-pack/plugins/cases/server/telemetry/types.ts @@ -9,11 +9,15 @@ import type { ISavedObjectsRepository, Logger } from '@kbn/core/server'; import type { MakeSchemaFrom } from '@kbn/usage-collection-plugin/server'; import type { Owner } from '../../common/constants/types'; -export interface Buckets { - buckets: Array<{ - doc_count: number; - key: number | string; - }>; +export type BucketKeyString = Omit & { key: string }; + +interface Bucket { + doc_count: number; + key: T; +} + +export interface Buckets { + buckets: Array>; } export interface Cardinality { @@ -57,12 +61,13 @@ export interface AssigneesFilters { }; } -export interface FileAttachmentAverageSize { +export interface FileAttachmentAggsResult { averageSize: number; + topMimeTypes: Buckets; } -export type FileAttachmentAggregationResult = Record & - FileAttachmentAverageSize; +export type FileAttachmentAggregationResults = Record & + FileAttachmentAggsResult; export interface BucketsWithMaxOnCase { buckets: Array< @@ -118,6 +123,10 @@ export interface AttachmentStats extends CommonAttachmentStats { export interface FileAttachmentStats extends CommonAttachmentStats { averageSize: number; + topMimeTypes: Array<{ + name: string; + count: number; + }>; } export interface AttachmentFramework { diff --git a/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json b/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json index a4c73bac176e8..c5fc6183bed29 100644 --- a/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json +++ b/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json @@ -4836,6 +4836,15 @@ }, "total": { "type": "long" + }, + "topMimeTypes": { + "type": "array", + "items": { + "properties": { + "name": "keyword", + "count": "long" + } + } } } } From 97bed79642dd41f74fd54460eceb44ed49f13017 Mon Sep 17 00:00:00 2001 From: Jonathan Buttner Date: Mon, 10 Apr 2023 17:03:16 -0400 Subject: [PATCH 2/5] Fixing caseIds issue --- .../cases/server/telemetry/queries/cases.ts | 4 ++- .../schema/xpack_plugins.json | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/cases/server/telemetry/queries/cases.ts b/x-pack/plugins/cases/server/telemetry/queries/cases.ts index 9d873a165f49d..59576fa1f45c0 100644 --- a/x-pack/plugins/cases/server/telemetry/queries/cases.ts +++ b/x-pack/plugins/cases/server/telemetry/queries/cases.ts @@ -234,6 +234,7 @@ const getCommentsSavedObjectTelemetry = async ( externalReferenceTypes: { terms: { field: `${CASE_COMMENT_SAVED_OBJECT}.attributes.externalReferenceAttachmentTypeId`, + size: 10, }, aggs: { ...getMaxBucketOnCaseAggregationQuery(CASE_COMMENT_SAVED_OBJECT), @@ -242,6 +243,7 @@ const getCommentsSavedObjectTelemetry = async ( persistableReferenceTypes: { terms: { field: `${CASE_COMMENT_SAVED_OBJECT}.attributes.persistableStateAttachmentTypeId`, + size: 10, }, aggs: { ...getMaxBucketOnCaseAggregationQuery(CASE_COMMENT_SAVED_OBJECT), @@ -320,7 +322,7 @@ const getFilesTelemetry = async ( {} ); - const filterCaseIdExists = fromKueryExpression(`${FILE_SO_TYPE}.attributes.Meta.caseId: *`); + const filterCaseIdExists = fromKueryExpression(`${FILE_SO_TYPE}.attributes.Meta.caseIds: *`); return savedObjectsClient.find({ page: 0, diff --git a/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json b/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json index 2b72d15439070..b33416a9b087f 100644 --- a/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json +++ b/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json @@ -4995,6 +4995,15 @@ }, "total": { "type": "long" + }, + "topMimeTypes": { + "type": "array", + "items": { + "properties": { + "name": "keyword", + "count": "long" + } + } } } } @@ -5082,6 +5091,15 @@ }, "total": { "type": "long" + }, + "topMimeTypes": { + "type": "array", + "items": { + "properties": { + "name": "keyword", + "count": "long" + } + } } } } @@ -5169,6 +5187,15 @@ }, "total": { "type": "long" + }, + "topMimeTypes": { + "type": "array", + "items": { + "properties": { + "name": "keyword", + "count": "long" + } + } } } } From 31801a7b0bff885d78f25745327814cb2597f64d Mon Sep 17 00:00:00 2001 From: Jonathan Buttner Date: Tue, 11 Apr 2023 09:58:11 -0400 Subject: [PATCH 3/5] Fixing tests --- .../server/telemetry/queries/cases.test.ts | 92 +++++++++- .../server/telemetry/queries/utils.test.ts | 167 +++++++++++++++++- 2 files changed, 254 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/cases/server/telemetry/queries/cases.test.ts b/x-pack/plugins/cases/server/telemetry/queries/cases.test.ts index ff5bbc5470e91..d6198e5c37444 100644 --- a/x-pack/plugins/cases/server/telemetry/queries/cases.test.ts +++ b/x-pack/plugins/cases/server/telemetry/queries/cases.test.ts @@ -190,14 +190,62 @@ describe('getCasesTelemetryData', () => { const filesRes: FileAttachmentAggregationResults = { securitySolution: { averageSize: 500, + topMimeTypes: { + buckets: [ + { + doc_count: 5, + key: 'image/png', + }, + { + doc_count: 1, + key: 'application/json', + }, + ], + }, }, observability: { averageSize: 500, + topMimeTypes: { + buckets: [ + { + doc_count: 5, + key: 'image/png', + }, + { + doc_count: 1, + key: 'application/json', + }, + ], + }, }, cases: { averageSize: 500, + topMimeTypes: { + buckets: [ + { + doc_count: 5, + key: 'image/png', + }, + { + doc_count: 1, + key: 'application/json', + }, + ], + }, }, averageSize: 500, + topMimeTypes: { + buckets: [ + { + doc_count: 5, + key: 'image/png', + }, + { + doc_count: 1, + key: 'application/json', + }, + ], + }, }; mockFind(caseAggsResult); @@ -259,6 +307,16 @@ describe('getCasesTelemetryData', () => { average, maxOnACase: 10, total, + topMimeTypes: [ + { + count: 5, + name: 'image/png', + }, + { + count: 1, + name: 'application/json', + }, + ], }, }, }; @@ -644,6 +702,7 @@ describe('getCasesTelemetryData', () => { }, "terms": Object { "field": "cases-comments.attributes.externalReferenceAttachmentTypeId", + "size": 10, }, }, "persistableReferenceTypes": Object { @@ -677,6 +736,7 @@ describe('getCasesTelemetryData', () => { }, "terms": Object { "field": "cases-comments.attributes.persistableStateAttachmentTypeId", + "size": 10, }, }, }, @@ -717,6 +777,7 @@ describe('getCasesTelemetryData', () => { }, "terms": Object { "field": "cases-comments.attributes.externalReferenceAttachmentTypeId", + "size": 10, }, }, "observability": Object { @@ -752,6 +813,7 @@ describe('getCasesTelemetryData', () => { }, "terms": Object { "field": "cases-comments.attributes.externalReferenceAttachmentTypeId", + "size": 10, }, }, "persistableReferenceTypes": Object { @@ -785,6 +847,7 @@ describe('getCasesTelemetryData', () => { }, "terms": Object { "field": "cases-comments.attributes.persistableStateAttachmentTypeId", + "size": 10, }, }, }, @@ -830,6 +893,7 @@ describe('getCasesTelemetryData', () => { }, "terms": Object { "field": "cases-comments.attributes.persistableStateAttachmentTypeId", + "size": 10, }, }, "securitySolution": Object { @@ -865,6 +929,7 @@ describe('getCasesTelemetryData', () => { }, "terms": Object { "field": "cases-comments.attributes.externalReferenceAttachmentTypeId", + "size": 10, }, }, "persistableReferenceTypes": Object { @@ -898,6 +963,7 @@ describe('getCasesTelemetryData', () => { }, "terms": Object { "field": "cases-comments.attributes.persistableStateAttachmentTypeId", + "size": 10, }, }, }, @@ -1031,6 +1097,12 @@ describe('getCasesTelemetryData', () => { "field": "file.attributes.size", }, }, + "topMimeTypes": Object { + "terms": Object { + "field": "file.attributes.mime_type", + "size": 20, + }, + }, }, "filter": Object { "term": Object { @@ -1045,6 +1117,12 @@ describe('getCasesTelemetryData', () => { "field": "file.attributes.size", }, }, + "topMimeTypes": Object { + "terms": Object { + "field": "file.attributes.mime_type", + "size": 20, + }, + }, }, "filter": Object { "term": Object { @@ -1059,6 +1137,12 @@ describe('getCasesTelemetryData', () => { "field": "file.attributes.size", }, }, + "topMimeTypes": Object { + "terms": Object { + "field": "file.attributes.mime_type", + "size": 20, + }, + }, }, "filter": Object { "term": Object { @@ -1066,13 +1150,19 @@ describe('getCasesTelemetryData', () => { }, }, }, + "topMimeTypes": Object { + "terms": Object { + "field": "file.attributes.mime_type", + "size": 20, + }, + }, }, "filter": Object { "arguments": Array [ Object { "isQuoted": false, "type": "literal", - "value": "file.attributes.Meta.caseId", + "value": "file.attributes.Meta.caseIds", }, Object { "type": "wildcard", diff --git a/x-pack/plugins/cases/server/telemetry/queries/utils.test.ts b/x-pack/plugins/cases/server/telemetry/queries/utils.test.ts index 4e5a975e2d9d6..8116af2763e3e 100644 --- a/x-pack/plugins/cases/server/telemetry/queries/utils.test.ts +++ b/x-pack/plugins/cases/server/telemetry/queries/utils.test.ts @@ -171,14 +171,62 @@ describe('utils', () => { const filesRes: FileAttachmentAggregationResults = { securitySolution: { averageSize: 500, + topMimeTypes: { + buckets: [ + { + doc_count: 5, + key: 'image/png', + }, + { + doc_count: 1, + key: 'application/json', + }, + ], + }, }, observability: { averageSize: 500, + topMimeTypes: { + buckets: [ + { + doc_count: 5, + key: 'image/png', + }, + { + doc_count: 1, + key: 'application/json', + }, + ], + }, }, cases: { averageSize: 500, + topMimeTypes: { + buckets: [ + { + doc_count: 5, + key: 'image/png', + }, + { + doc_count: 1, + key: 'application/json', + }, + ], + }, }, averageSize: 500, + topMimeTypes: { + buckets: [ + { + doc_count: 5, + key: 'image/png', + }, + { + doc_count: 1, + key: 'application/json', + }, + ], + }, }; it('constructs the solution values correctly', () => { @@ -215,6 +263,16 @@ describe('utils', () => { "average": 1, "averageSize": 500, "maxOnACase": 10, + "topMimeTypes": Array [ + Object { + "count": 5, + "name": "image/png", + }, + Object { + "count": 1, + "name": "application/json", + }, + ], "total": 5, }, "persistableAttachments": Array [ @@ -271,6 +329,16 @@ describe('utils', () => { "average": 5, "averageSize": 500, "maxOnACase": 10, + "topMimeTypes": Array [ + Object { + "count": 5, + "name": "image/png", + }, + Object { + "count": 1, + "name": "application/json", + }, + ], "total": 5, }, "persistableAttachments": Array [ @@ -327,6 +395,16 @@ describe('utils', () => { "average": 5, "averageSize": 500, "maxOnACase": 10, + "topMimeTypes": Array [ + Object { + "count": 5, + "name": "image/png", + }, + Object { + "count": 1, + "name": "application/json", + }, + ], "total": 5, }, "persistableAttachments": Array [ @@ -363,6 +441,7 @@ describe('utils', () => { "average": 0, "averageSize": 0, "maxOnACase": 0, + "topMimeTypes": Array [], "total": 0, }, "persistableAttachments": Array [], @@ -486,7 +565,7 @@ describe('utils', () => { }); describe('files', () => { - it('sets the files stats to empty when it cannot find a files entry', () => { + it('sets the files stats to empty when the file aggregation results is the empty version', () => { const attachmentFramework: AttachmentFrameworkAggsResult = { externalReferenceTypes: { buckets: [ @@ -512,19 +591,25 @@ describe('utils', () => { getAttachmentsFrameworkStats({ attachmentAggregations: attachmentFramework, totalCasesForOwner: 5, - filesAggregations: { averageSize: 500 }, + filesAggregations: { + averageSize: 0, + topMimeTypes: { + buckets: [], + }, + }, }).attachmentFramework.files ).toMatchInlineSnapshot(` Object { "average": 0, "averageSize": 0, "maxOnACase": 0, + "topMimeTypes": Array [], "total": 0, } `); }); - it('sets the files stats when it finds a files entry', () => { + it('sets the files stats using the file aggregation result', () => { const attachmentFramework: AttachmentFrameworkAggsResult = { externalReferenceTypes: { buckets: [ @@ -549,7 +634,21 @@ describe('utils', () => { expect( getAttachmentsFrameworkStats({ attachmentAggregations: attachmentFramework, - filesAggregations: { averageSize: 500 }, + filesAggregations: { + averageSize: 500, + topMimeTypes: { + buckets: [ + { + doc_count: 5, + key: 'image/png', + }, + { + doc_count: 1, + key: 'application/json', + }, + ], + }, + }, totalCasesForOwner: 5, }).attachmentFramework.files ).toMatchInlineSnapshot(` @@ -557,10 +656,70 @@ describe('utils', () => { "average": 1, "averageSize": 500, "maxOnACase": 10, + "topMimeTypes": Array [ + Object { + "count": 5, + "name": "image/png", + }, + Object { + "count": 1, + "name": "application/json", + }, + ], "total": 5, } `); }); + + it('sets the top mime types when a file entry is not found', () => { + const attachmentFramework: AttachmentFrameworkAggsResult = { + externalReferenceTypes: { + buckets: [], + }, + persistableReferenceTypes: { + buckets: [], + }, + }; + + expect( + getAttachmentsFrameworkStats({ + attachmentAggregations: attachmentFramework, + filesAggregations: { + averageSize: 0, + topMimeTypes: { + buckets: [ + { + doc_count: 5, + key: 'image/png', + }, + { + doc_count: 1, + key: 'application/json', + }, + ], + }, + }, + totalCasesForOwner: 5, + }).attachmentFramework.files + ).toMatchInlineSnapshot(` + Object { + "average": 0, + "averageSize": 0, + "maxOnACase": 0, + "topMimeTypes": Array [ + Object { + "count": 5, + "name": "image/png", + }, + Object { + "count": 1, + "name": "application/json", + }, + ], + "total": 0, + } + `); + }); }); }); From a351747e8f3bec825b4f7659cfa3436623b7466b Mon Sep 17 00:00:00 2001 From: Jonathan Buttner Date: Tue, 11 Apr 2023 10:27:43 -0400 Subject: [PATCH 4/5] Fixing schema --- .../schema/xpack_plugins.json | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json b/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json index b33416a9b087f..594373a71e188 100644 --- a/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json +++ b/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json @@ -4844,8 +4844,12 @@ "type": "array", "items": { "properties": { - "name": "keyword", - "count": "long" + "count": { + "type": "long" + }, + "name": { + "type": "keyword" + } } } } @@ -5000,8 +5004,12 @@ "type": "array", "items": { "properties": { - "name": "keyword", - "count": "long" + "count": { + "type": "long" + }, + "name": { + "type": "keyword" + } } } } @@ -5096,8 +5104,12 @@ "type": "array", "items": { "properties": { - "name": "keyword", - "count": "long" + "count": { + "type": "long" + }, + "name": { + "type": "keyword" + } } } } @@ -5192,8 +5204,12 @@ "type": "array", "items": { "properties": { - "name": "keyword", - "count": "long" + "count": { + "type": "long" + }, + "name": { + "type": "keyword" + } } } } From 1e2a3152d0f688283eda7c9eedc2c50320056273 Mon Sep 17 00:00:00 2001 From: Jonathan Buttner Date: Tue, 11 Apr 2023 12:14:46 -0400 Subject: [PATCH 5/5] Fixing average schema value issue --- .../cases/server/telemetry/queries/cases.test.ts | 8 ++++---- .../cases/server/telemetry/queries/utils.test.ts | 14 +++++++------- .../cases/server/telemetry/queries/utils.ts | 2 +- x-pack/plugins/cases/server/telemetry/types.ts | 4 +++- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/x-pack/plugins/cases/server/telemetry/queries/cases.test.ts b/x-pack/plugins/cases/server/telemetry/queries/cases.test.ts index d6198e5c37444..b97235ff82247 100644 --- a/x-pack/plugins/cases/server/telemetry/queries/cases.test.ts +++ b/x-pack/plugins/cases/server/telemetry/queries/cases.test.ts @@ -189,7 +189,7 @@ describe('getCasesTelemetryData', () => { const filesRes: FileAttachmentAggregationResults = { securitySolution: { - averageSize: 500, + averageSize: { value: 500 }, topMimeTypes: { buckets: [ { @@ -204,7 +204,7 @@ describe('getCasesTelemetryData', () => { }, }, observability: { - averageSize: 500, + averageSize: { value: 500 }, topMimeTypes: { buckets: [ { @@ -219,7 +219,7 @@ describe('getCasesTelemetryData', () => { }, }, cases: { - averageSize: 500, + averageSize: { value: 500 }, topMimeTypes: { buckets: [ { @@ -233,7 +233,7 @@ describe('getCasesTelemetryData', () => { ], }, }, - averageSize: 500, + averageSize: { value: 500 }, topMimeTypes: { buckets: [ { diff --git a/x-pack/plugins/cases/server/telemetry/queries/utils.test.ts b/x-pack/plugins/cases/server/telemetry/queries/utils.test.ts index 8116af2763e3e..359aa621798f0 100644 --- a/x-pack/plugins/cases/server/telemetry/queries/utils.test.ts +++ b/x-pack/plugins/cases/server/telemetry/queries/utils.test.ts @@ -170,7 +170,7 @@ describe('utils', () => { const filesRes: FileAttachmentAggregationResults = { securitySolution: { - averageSize: 500, + averageSize: { value: 500 }, topMimeTypes: { buckets: [ { @@ -185,7 +185,7 @@ describe('utils', () => { }, }, observability: { - averageSize: 500, + averageSize: { value: 500 }, topMimeTypes: { buckets: [ { @@ -200,7 +200,7 @@ describe('utils', () => { }, }, cases: { - averageSize: 500, + averageSize: { value: 500 }, topMimeTypes: { buckets: [ { @@ -214,7 +214,7 @@ describe('utils', () => { ], }, }, - averageSize: 500, + averageSize: { value: 500 }, topMimeTypes: { buckets: [ { @@ -592,7 +592,7 @@ describe('utils', () => { attachmentAggregations: attachmentFramework, totalCasesForOwner: 5, filesAggregations: { - averageSize: 0, + averageSize: { value: 0 }, topMimeTypes: { buckets: [], }, @@ -635,7 +635,7 @@ describe('utils', () => { getAttachmentsFrameworkStats({ attachmentAggregations: attachmentFramework, filesAggregations: { - averageSize: 500, + averageSize: { value: 500 }, topMimeTypes: { buckets: [ { @@ -685,7 +685,7 @@ describe('utils', () => { getAttachmentsFrameworkStats({ attachmentAggregations: attachmentFramework, filesAggregations: { - averageSize: 0, + averageSize: { value: 0 }, topMimeTypes: { buckets: [ { diff --git a/x-pack/plugins/cases/server/telemetry/queries/utils.ts b/x-pack/plugins/cases/server/telemetry/queries/utils.ts index f9eb531f3a207..7896c2bdac760 100644 --- a/x-pack/plugins/cases/server/telemetry/queries/utils.ts +++ b/x-pack/plugins/cases/server/telemetry/queries/utils.ts @@ -230,7 +230,7 @@ export const getAttachmentsFrameworkStats = ({ return emptyAttachmentFramework(); } - const averageFileSize = filesAggregations?.averageSize; + const averageFileSize = filesAggregations?.averageSize?.value; const topMimeTypes = filesAggregations?.topMimeTypes; return { diff --git a/x-pack/plugins/cases/server/telemetry/types.ts b/x-pack/plugins/cases/server/telemetry/types.ts index f1cf2e79499ab..b38d46d04283b 100644 --- a/x-pack/plugins/cases/server/telemetry/types.ts +++ b/x-pack/plugins/cases/server/telemetry/types.ts @@ -62,7 +62,9 @@ export interface AssigneesFilters { } export interface FileAttachmentAggsResult { - averageSize: number; + averageSize: { + value: number; + }; topMimeTypes: Buckets; }