mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Cases] Rounding the file size to avoid decimals (#155542)
This PR fixes a bug in the telemetry code around the average file size. A float can be returned by the average aggregation. To avoid the float we'll round it before saving the value in the document.
This commit is contained in:
parent
792c7868b1
commit
fe75fbd55d
2 changed files with 91 additions and 1 deletions
|
@ -565,6 +565,88 @@ describe('utils', () => {
|
|||
});
|
||||
|
||||
describe('files', () => {
|
||||
it('rounds the average file size when it is a decimal', () => {
|
||||
const attachmentFramework: AttachmentFrameworkAggsResult = {
|
||||
externalReferenceTypes: {
|
||||
buckets: [
|
||||
{
|
||||
doc_count: 5,
|
||||
key: '.files',
|
||||
references: {
|
||||
cases: {
|
||||
max: {
|
||||
value: 10,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
persistableReferenceTypes: {
|
||||
buckets: [],
|
||||
},
|
||||
};
|
||||
|
||||
expect(
|
||||
getAttachmentsFrameworkStats({
|
||||
attachmentAggregations: attachmentFramework,
|
||||
totalCasesForOwner: 5,
|
||||
filesAggregations: {
|
||||
averageSize: { value: 1.1 },
|
||||
topMimeTypes: {
|
||||
buckets: [],
|
||||
},
|
||||
},
|
||||
}).attachmentFramework.files
|
||||
).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"average": 1,
|
||||
"averageSize": 1,
|
||||
"maxOnACase": 10,
|
||||
"topMimeTypes": Array [],
|
||||
"total": 5,
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it('sets the average file size to 0 when the aggregation does not exist', () => {
|
||||
const attachmentFramework: AttachmentFrameworkAggsResult = {
|
||||
externalReferenceTypes: {
|
||||
buckets: [
|
||||
{
|
||||
doc_count: 5,
|
||||
key: '.files',
|
||||
references: {
|
||||
cases: {
|
||||
max: {
|
||||
value: 10,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
persistableReferenceTypes: {
|
||||
buckets: [],
|
||||
},
|
||||
};
|
||||
|
||||
expect(
|
||||
getAttachmentsFrameworkStats({
|
||||
attachmentAggregations: attachmentFramework,
|
||||
totalCasesForOwner: 5,
|
||||
}).attachmentFramework.files
|
||||
).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"average": 1,
|
||||
"averageSize": 0,
|
||||
"maxOnACase": 10,
|
||||
"topMimeTypes": Array [],
|
||||
"total": 5,
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it('sets the files stats to empty when the file aggregation results is the empty version', () => {
|
||||
const attachmentFramework: AttachmentFrameworkAggsResult = {
|
||||
externalReferenceTypes: {
|
||||
|
|
|
@ -230,7 +230,7 @@ export const getAttachmentsFrameworkStats = ({
|
|||
return emptyAttachmentFramework();
|
||||
}
|
||||
|
||||
const averageFileSize = filesAggregations?.averageSize?.value;
|
||||
const averageFileSize = getAverageFileSize(filesAggregations);
|
||||
const topMimeTypes = filesAggregations?.topMimeTypes;
|
||||
|
||||
return {
|
||||
|
@ -253,6 +253,14 @@ export const getAttachmentsFrameworkStats = ({
|
|||
};
|
||||
};
|
||||
|
||||
const getAverageFileSize = (filesAggregations?: FileAttachmentAggsResult) => {
|
||||
if (filesAggregations?.averageSize?.value == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Math.round(filesAggregations.averageSize.value);
|
||||
};
|
||||
|
||||
const getAttachmentRegistryStats = (
|
||||
registryResults: BucketsWithMaxOnCase,
|
||||
totalCasesForOwner: number
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue