Skip to content

Commit 2c902aa

Browse files
committed
[Uptime] Use manual intervals for ping histogram (#72928)
* [Uptime] Use manual intervals for ping histogram Fixes elastic/uptime#215 Prior to this we'd get too few buckets in some ranges. * Update test fixtures, remove overly-specific checks * Remove unused import
1 parent 4ff42a3 commit 2c902aa

File tree

5 files changed

+175
-88
lines changed

5 files changed

+175
-88
lines changed

x-pack/plugins/uptime/server/lib/requests/get_ping_histogram.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { UMElasticsearchQueryFn } from '../adapters';
88
import { getFilterClause } from '../helper';
99
import { HistogramResult, HistogramQueryResult } from '../../../common/runtime_types';
1010
import { QUERY } from '../../../common/constants';
11+
import { getHistogramInterval } from '../helper/get_histogram_interval';
1112

1213
export interface GetPingHistogramParams {
1314
/** @member dateRangeStart timestamp bounds */
@@ -36,22 +37,6 @@ export const getPingHistogram: UMElasticsearchQueryFn<
3637
}
3738
const filter = getFilterClause(from, to, additionalFilters);
3839

39-
const seriesHistogram: any = {};
40-
41-
if (bucketSize) {
42-
seriesHistogram.date_histogram = {
43-
field: '@timestamp',
44-
fixed_interval: bucketSize,
45-
missing: 0,
46-
};
47-
} else {
48-
seriesHistogram.auto_date_histogram = {
49-
field: '@timestamp',
50-
buckets: QUERY.DEFAULT_BUCKET_COUNT,
51-
missing: 0,
52-
};
53-
}
54-
5540
const params = {
5641
index: dynamicSettings.heartbeatIndices,
5742
body: {
@@ -63,7 +48,12 @@ export const getPingHistogram: UMElasticsearchQueryFn<
6348
size: 0,
6449
aggs: {
6550
timeseries: {
66-
...seriesHistogram,
51+
date_histogram: {
52+
field: '@timestamp',
53+
fixed_interval:
54+
bucketSize || getHistogramInterval(from, to, QUERY.DEFAULT_BUCKET_COUNT) + 'ms',
55+
missing: 0,
56+
},
6757
aggs: {
6858
down: {
6959
filter: {

x-pack/test/api_integration/apis/uptime/rest/fixtures/ping_histogram.json

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,157 @@
11
{
22
"histogram": [
33
{
4-
"x": 1568172664000,
4+
"x": 1568172657286,
55
"downCount": 7,
66
"upCount": 93,
77
"y": 1
88
},
99
{
10-
"x": 1568172694000,
10+
"x": 1568172680087,
1111
"downCount": 7,
1212
"upCount": 93,
1313
"y": 1
1414
},
1515
{
16-
"x": 1568172724000,
16+
"x": 1568172702888,
1717
"downCount": 7,
1818
"upCount": 93,
1919
"y": 1
2020
},
2121
{
22-
"x": 1568172754000,
22+
"x": 1568172725689,
23+
"downCount": 0,
24+
"upCount": 0,
25+
"y": 1
26+
},
27+
{
28+
"x": 1568172748490,
2329
"downCount": 7,
2430
"upCount": 93,
2531
"y": 1
2632
},
2733
{
28-
"x": 1568172784000,
34+
"x": 1568172771291,
2935
"downCount": 7,
3036
"upCount": 93,
3137
"y": 1
3238
},
3339
{
34-
"x": 1568172814000,
40+
"x": 1568172794092,
3541
"downCount": 8,
3642
"upCount": 92,
3743
"y": 1
3844
},
3945
{
40-
"x": 1568172844000,
46+
"x": 1568172816893,
47+
"downCount": 0,
48+
"upCount": 0,
49+
"y": 1
50+
},
51+
{
52+
"x": 1568172839694,
4153
"downCount": 7,
4254
"upCount": 93,
4355
"y": 1
4456
},
4557
{
46-
"x": 1568172874000,
58+
"x": 1568172862495,
4759
"downCount": 7,
4860
"upCount": 93,
4961
"y": 1
5062
},
5163
{
52-
"x": 1568172904000,
64+
"x": 1568172885296,
5365
"downCount": 7,
5466
"upCount": 93,
5567
"y": 1
5668
},
5769
{
58-
"x": 1568172934000,
70+
"x": 1568172908097,
71+
"downCount": 0,
72+
"upCount": 0,
73+
"y": 1
74+
},
75+
{
76+
"x": 1568172930898,
5977
"downCount": 7,
6078
"upCount": 93,
6179
"y": 1
6280
},
6381
{
64-
"x": 1568172964000,
82+
"x": 1568172953699,
6583
"downCount": 7,
6684
"upCount": 93,
6785
"y": 1
6886
},
6987
{
70-
"x": 1568172994000,
88+
"x": 1568172976500,
7189
"downCount": 8,
7290
"upCount": 92,
7391
"y": 1
7492
},
7593
{
76-
"x": 1568173024000,
94+
"x": 1568172999301,
95+
"downCount": 0,
96+
"upCount": 0,
97+
"y": 1
98+
},
99+
{
100+
"x": 1568173022102,
77101
"downCount": 7,
78102
"upCount": 93,
79103
"y": 1
80104
},
81105
{
82-
"x": 1568173054000,
106+
"x": 1568173044903,
83107
"downCount": 7,
84108
"upCount": 93,
85109
"y": 1
86110
},
87111
{
88-
"x": 1568173084000,
112+
"x": 1568173067704,
89113
"downCount": 7,
90114
"upCount": 93,
91115
"y": 1
92116
},
93117
{
94-
"x": 1568173114000,
118+
"x": 1568173090505,
119+
"downCount": 0,
120+
"upCount": 0,
121+
"y": 1
122+
},
123+
{
124+
"x": 1568173113306,
95125
"downCount": 7,
96126
"upCount": 93,
97127
"y": 1
98128
},
99129
{
100-
"x": 1568173144000,
130+
"x": 1568173136107,
101131
"downCount": 7,
102132
"upCount": 93,
103133
"y": 1
104134
},
105135
{
106-
"x": 1568173174000,
136+
"x": 1568173158908,
107137
"downCount": 8,
108138
"upCount": 92,
109139
"y": 1
110140
},
111141
{
112-
"x": 1568173204000,
142+
"x": 1568173181709,
113143
"downCount": 7,
114144
"upCount": 93,
115145
"y": 1
116146
},
117147
{
118-
"x": 1568173234000,
148+
"x": 1568173204510,
149+
"downCount": 0,
150+
"upCount": 0,
151+
"y": 1
152+
},
153+
{
154+
"x": 1568173227311,
119155
"downCount": 7,
120156
"upCount": 93,
121157
"y": 1

0 commit comments

Comments
 (0)