mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
pass bucket size as _interval param to calculation metric script (#14731)
This commit is contained in:
parent
b82f34a992
commit
799c80ef8e
3 changed files with 19 additions and 10 deletions
|
@ -63,7 +63,8 @@ class CalculationAgg extends Component {
|
|||
<div className="vis_editor__row_item">
|
||||
<label className="vis_editor__label" htmlFor={htmlId('painless')}>
|
||||
Painless Script - Variables are keys on the <code>params</code>
|
||||
object, i.e. <code>params.<name></code>
|
||||
object, i.e. <code>params.<name></code>.
|
||||
To access the bucket interval (in milliseconds) use <code>params._interval</code>.
|
||||
</label>
|
||||
<input
|
||||
id={htmlId('painless')}
|
||||
|
|
|
@ -10,7 +10,7 @@ describe('bucketTransform', () => {
|
|||
expect(fn(metric)).to.eql({
|
||||
bucket_script: {
|
||||
buckets_path: { count: '_count' },
|
||||
script: { inline: 'count * 1', lang: 'expression' },
|
||||
script: { source: 'count * 1', lang: 'expression' },
|
||||
gap_policy: 'skip'
|
||||
}
|
||||
});
|
||||
|
@ -340,8 +340,11 @@ describe('bucketTransform', () => {
|
|||
},
|
||||
gap_policy: 'skip',
|
||||
script: {
|
||||
inline: 'params.idle != null ? 1 - params.idle : 0',
|
||||
source: 'params.idle != null ? 1 - params.idle : 0',
|
||||
lang: 'painless'
|
||||
},
|
||||
params: {
|
||||
_interval: 10000
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -382,7 +385,7 @@ describe('bucketTransform', () => {
|
|||
},
|
||||
gap_policy: 'skip',
|
||||
script: {
|
||||
inline: 'params.value > 0 ? params.value : 0',
|
||||
source: 'params.value > 0 ? params.value : 0',
|
||||
lang: 'painless'
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import parseSettings from './parse_settings';
|
||||
import getBucketsPath from './get_buckets_path';
|
||||
import { parseInterval } from '../../../../../../ui/public/utils/parse_interval';
|
||||
|
||||
function checkMetric(metric, fields) {
|
||||
fields.forEach(field => {
|
||||
if (!metric[field]) {
|
||||
|
@ -39,7 +41,7 @@ export default {
|
|||
bucket_script: {
|
||||
buckets_path: { count: '_count' },
|
||||
script: {
|
||||
inline: 'count * 1',
|
||||
source: 'count * 1',
|
||||
lang: 'expression'
|
||||
},
|
||||
gap_policy: 'skip'
|
||||
|
@ -52,7 +54,7 @@ export default {
|
|||
bucket_script: {
|
||||
buckets_path: { count: '_count' },
|
||||
script: {
|
||||
inline: bucket.value,
|
||||
source: bucket.value,
|
||||
lang: 'painless'
|
||||
},
|
||||
gap_policy: 'skip'
|
||||
|
@ -159,7 +161,7 @@ export default {
|
|||
return body;
|
||||
},
|
||||
|
||||
calculation: (bucket, metrics) => {
|
||||
calculation: (bucket, metrics, bucketSize) => {
|
||||
checkMetric(bucket, ['variables', 'script']);
|
||||
const body = {
|
||||
bucket_script: {
|
||||
|
@ -168,8 +170,11 @@ export default {
|
|||
return acc;
|
||||
}, {}),
|
||||
script: {
|
||||
inline: bucket.script,
|
||||
lang: 'painless'
|
||||
source: bucket.script,
|
||||
lang: 'painless',
|
||||
params: {
|
||||
_interval: parseInterval(bucketSize).asMilliseconds()
|
||||
}
|
||||
},
|
||||
gap_policy: 'skip' // seems sane
|
||||
}
|
||||
|
@ -186,7 +191,7 @@ export default {
|
|||
value: getBucketsPath(bucket.field, metrics)
|
||||
},
|
||||
script: {
|
||||
inline: 'params.value > 0 ? params.value : 0',
|
||||
source: 'params.value > 0 ? params.value : 0',
|
||||
lang: 'painless'
|
||||
},
|
||||
gap_policy: 'skip' // seems sane
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue