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

[Cases] Adding mime type telemetry #154679

Merged
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
104 changes: 97 additions & 7 deletions x-pack/plugins/cases/server/telemetry/queries/cases.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {
AttachmentAggregationResult,
AttachmentFrameworkAggsResult,
CaseAggregationResult,
FileAttachmentAggregationResult,
FileAttachmentAggregationResults,
} from '../types';
import { getCasesTelemetryData } from './cases';

Expand Down Expand Up @@ -187,17 +187,65 @@ describe('getCasesTelemetryData', () => {
...attachmentFramework,
};

const filesRes: FileAttachmentAggregationResult = {
const filesRes: FileAttachmentAggregationResults = {
securitySolution: {
averageSize: 500,
averageSize: { value: 500 },
topMimeTypes: {
buckets: [
{
doc_count: 5,
key: 'image/png',
},
{
doc_count: 1,
key: 'application/json',
},
],
},
},
observability: {
averageSize: 500,
averageSize: { value: 500 },
topMimeTypes: {
buckets: [
{
doc_count: 5,
key: 'image/png',
},
{
doc_count: 1,
key: 'application/json',
},
],
},
},
cases: {
averageSize: 500,
averageSize: { value: 500 },
topMimeTypes: {
buckets: [
{
doc_count: 5,
key: 'image/png',
},
{
doc_count: 1,
key: 'application/json',
},
],
},
},
averageSize: { value: 500 },
topMimeTypes: {
buckets: [
{
doc_count: 5,
key: 'image/png',
},
{
doc_count: 1,
key: 'application/json',
},
],
},
averageSize: 500,
};

mockFind(caseAggsResult);
Expand Down Expand Up @@ -259,6 +307,16 @@ describe('getCasesTelemetryData', () => {
average,
maxOnACase: 10,
total,
topMimeTypes: [
{
count: 5,
name: 'image/png',
},
{
count: 1,
name: 'application/json',
},
],
},
},
};
Expand Down Expand Up @@ -644,6 +702,7 @@ describe('getCasesTelemetryData', () => {
},
"terms": Object {
"field": "cases-comments.attributes.externalReferenceAttachmentTypeId",
"size": 10,
},
},
"persistableReferenceTypes": Object {
Expand Down Expand Up @@ -677,6 +736,7 @@ describe('getCasesTelemetryData', () => {
},
"terms": Object {
"field": "cases-comments.attributes.persistableStateAttachmentTypeId",
"size": 10,
},
},
},
Expand Down Expand Up @@ -717,6 +777,7 @@ describe('getCasesTelemetryData', () => {
},
"terms": Object {
"field": "cases-comments.attributes.externalReferenceAttachmentTypeId",
"size": 10,
},
},
"observability": Object {
Expand Down Expand Up @@ -752,6 +813,7 @@ describe('getCasesTelemetryData', () => {
},
"terms": Object {
"field": "cases-comments.attributes.externalReferenceAttachmentTypeId",
"size": 10,
},
},
"persistableReferenceTypes": Object {
Expand Down Expand Up @@ -785,6 +847,7 @@ describe('getCasesTelemetryData', () => {
},
"terms": Object {
"field": "cases-comments.attributes.persistableStateAttachmentTypeId",
"size": 10,
},
},
},
Expand Down Expand Up @@ -830,6 +893,7 @@ describe('getCasesTelemetryData', () => {
},
"terms": Object {
"field": "cases-comments.attributes.persistableStateAttachmentTypeId",
"size": 10,
},
},
"securitySolution": Object {
Expand Down Expand Up @@ -865,6 +929,7 @@ describe('getCasesTelemetryData', () => {
},
"terms": Object {
"field": "cases-comments.attributes.externalReferenceAttachmentTypeId",
"size": 10,
},
},
"persistableReferenceTypes": Object {
Expand Down Expand Up @@ -898,6 +963,7 @@ describe('getCasesTelemetryData', () => {
},
"terms": Object {
"field": "cases-comments.attributes.persistableStateAttachmentTypeId",
"size": 10,
},
},
},
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -1059,20 +1137,32 @@ describe('getCasesTelemetryData', () => {
"field": "file.attributes.size",
},
},
"topMimeTypes": Object {
"terms": Object {
"field": "file.attributes.mime_type",
"size": 20,
},
},
},
"filter": Object {
"term": Object {
"file.attributes.Meta.owner": "securitySolution",
},
},
},
"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",
Expand Down
22 changes: 17 additions & 5 deletions x-pack/plugins/cases/server/telemetry/queries/cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import type {
LatestDates,
CaseAggregationResult,
AttachmentAggregationResult,
FileAttachmentAggregationResult,
FileAttachmentAggregationResults,
} from '../types';
import {
findValueInBuckets,
Expand Down Expand Up @@ -234,6 +234,7 @@ const getCommentsSavedObjectTelemetry = async (
externalReferenceTypes: {
terms: {
field: `${CASE_COMMENT_SAVED_OBJECT}.attributes.externalReferenceAttachmentTypeId`,
size: 10,
},
aggs: {
...getMaxBucketOnCaseAggregationQuery(CASE_COMMENT_SAVED_OBJECT),
Expand All @@ -242,6 +243,7 @@ const getCommentsSavedObjectTelemetry = async (
persistableReferenceTypes: {
terms: {
field: `${CASE_COMMENT_SAVED_OBJECT}.attributes.persistableStateAttachmentTypeId`,
size: 10,
},
aggs: {
...getMaxBucketOnCaseAggregationQuery(CASE_COMMENT_SAVED_OBJECT),
Expand Down Expand Up @@ -284,7 +286,7 @@ const getCommentsSavedObjectTelemetry = async (

const getFilesTelemetry = async (
savedObjectsClient: ISavedObjectsRepository
): Promise<SavedObjectsFindResponse<unknown, FileAttachmentAggregationResult>> => {
): Promise<SavedObjectsFindResponse<unknown, FileAttachmentAggregationResults>> => {
const averageSize = () => ({
averageSize: {
avg: {
Expand All @@ -293,6 +295,15 @@ const getFilesTelemetry = async (
},
});

const top20MimeTypes = () => ({
topMimeTypes: {
terms: {
field: `${FILE_SO_TYPE}.attributes.mime_type`,
size: 20,
},
},
});

const filesByOwnerAggregationQuery = OWNERS.reduce(
(aggQuery, owner) => ({
...aggQuery,
Expand All @@ -304,20 +315,21 @@ const getFilesTelemetry = async (
},
aggs: {
...averageSize(),
...top20MimeTypes(),
},
},
}),
{}
);

const filterCaseIdExists = fromKueryExpression(`${FILE_SO_TYPE}.attributes.Meta.caseId: *`);
const filterCaseIdExists = fromKueryExpression(`${FILE_SO_TYPE}.attributes.Meta.caseIds: *`);

return savedObjectsClient.find<unknown, FileAttachmentAggregationResult>({
return savedObjectsClient.find<unknown, FileAttachmentAggregationResults>({
page: 0,
perPage: 0,
type: FILE_SO_TYPE,
filter: filterCaseIdExists,
aggs: { ...filesByOwnerAggregationQuery, ...averageSize() },
aggs: { ...filesByOwnerAggregationQuery, ...averageSize(), ...top20MimeTypes() },
});
};

Expand Down
Loading