Skip to content

Commit

Permalink
Fix issue with long values in TSVB static metric (#40256)
Browse files Browse the repository at this point in the history
* Fix issue with long values in TSVB static metric

* Handle numeric values with decimal zeros

* Work properly with exponential values

* Wrap into boolean
  • Loading branch information
Tim Roes authored Jul 5, 2019
1 parent 01f6efa commit b7de2ac
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,13 @@ export const bucketTransform = {
},
static: bucket => {
checkMetric(bucket, ['value']);
// Anything containing a decimal point or an exponent is considered decimal value
const isDecimalValue = Boolean(bucket.value.match(/[.e]/i));
return {
bucket_script: {
buckets_path: { count: '_count' },
script: {
source: bucket.value,
source: isDecimalValue ? bucket.value : `${bucket.value}L`,
lang: 'painless',
},
gap_policy: 'skip',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,35 @@ describe('src/legacy/core_plugins/metrics/server/lib/vis_data/helpers/bucket_tra
expect(bucketTransform.moving_average(bucket, metrics)).toMatchSnapshot();
});
});

describe('static', () => {
test('should return a script with a double value when using decimals', () => {
expect(bucketTransform.static({ value: '421.12' })).toHaveProperty(
'bucket_script.script.source',
'421.12'
);
});

test('should return a long script for integer values', () => {
expect(bucketTransform.static({ value: '1234567890123' })).toHaveProperty(
'bucket_script.script.source',
'1234567890123L'
);
});

test('should not return a long script for exponential values', () => {
expect(bucketTransform.static({ value: '123123123e12' })).toHaveProperty(
'bucket_script.script.source',
'123123123e12'
);
});

test('should return decimal scripts for very large decimals', () => {
expect(bucketTransform.static({ value: '1234178312312381273123123.11123' })).toHaveProperty(
'bucket_script.script.source',
'1234178312312381273123123.11123'
);
});
});
});
});

0 comments on commit b7de2ac

Please sign in to comment.