Skip to content

Commit c382c66

Browse files
polyfractaljimczi
authored andcommitted
[Rollup] Log deprecation if config and request intervals are mixed (#33284)
Backport of #32052, with some changes. In 6.5, we forbid mixed intervals (one fixed, one calendar). But for a 6.4.x bugfix release this would be a pretty extreme break. So we continue to allow mixed intervals in 6.4, but log a deprecation warning. 6.4 also doesn't enforce that the request is a multiple of the config. We also log a deprecation if that is not the case, but don't prevent the query. Finally, mixed intervals are only used if a better job cap can't be found. To support the case where we have to compare fixed and calendar, there is a table of rough conversions (e.g. 1 day == 86400000ms). This lets us crudely ensure the user doesn't try to query `2d` on an index that is set for `1w`.
1 parent 7c7c6e2 commit c382c66

File tree

8 files changed

+442
-93
lines changed

8 files changed

+442
-93
lines changed

docs/reference/rollup/apis/put-job.asciidoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ started with the <<rollup-start-job,Start Job API>>.
4444
`metrics`::
4545
(object) Defines the metrics that should be collected for each grouping tuple. See <<rollup-job-config,rollup job config>>.
4646

47+
For more details about the job configuration, see <<rollup-job-config>>.
48+
4749
==== Authorization
4850

4951
You must have `manage` or `manage_rollup` cluster privileges to use this API.

docs/reference/rollup/apis/rollup-job-config.asciidoc

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ PUT _xpack/rollup/job/sensor
2424
"groups" : {
2525
"date_histogram": {
2626
"field": "timestamp",
27-
"interval": "1h",
27+
"interval": "60m",
2828
"delay": "7d"
2929
},
3030
"terms": {
@@ -94,7 +94,7 @@ fields will then be available later for aggregating into buckets. For example,
9494
"groups" : {
9595
"date_histogram": {
9696
"field": "timestamp",
97-
"interval": "1h",
97+
"interval": "60m",
9898
"delay": "7d"
9999
},
100100
"terms": {
@@ -128,9 +128,9 @@ The `date_histogram` group has several parameters:
128128
The date field that is to be rolled up.
129129

130130
`interval` (required)::
131-
The interval of time buckets to be generated when rolling up. E.g. `"1h"` will produce hourly rollups. This follows standard time formatting
132-
syntax as used elsewhere in Elasticsearch. The `interval` defines the _minimum_ interval that can be aggregated only. If hourly (`"1h"`)
133-
intervals are configured, <<rollup-search,Rollup Search>> can execute aggregations with 1hr or greater (weekly, monthly, etc) intervals.
131+
The interval of time buckets to be generated when rolling up. E.g. `"60m"` will produce 60 minute (hourly) rollups. This follows standard time formatting
132+
syntax as used elsewhere in Elasticsearch. The `interval` defines the _minimum_ interval that can be aggregated only. If hourly (`"60m"`)
133+
intervals are configured, <<rollup-search,Rollup Search>> can execute aggregations with 60m or greater (weekly, monthly, etc) intervals.
134134
So define the interval as the smallest unit that you wish to later query.
135135

136136
Note: smaller, more granular intervals take up proportionally more space.
@@ -149,6 +149,46 @@ The `date_histogram` group has several parameters:
149149
to be stored with a specific timezone. By default, rollup documents are stored in `UTC`, but this can be changed with the `time_zone`
150150
parameter.
151151

152+
.Calendar vs Fixed time intervals
153+
**********************************
154+
Elasticsearch understands both "calendar" and "fixed" time intervals. Fixed time intervals are fairly easy to understand;
155+
`"60s"` means sixty seconds. But what does `"1M` mean? One month of time depends on which month we are talking about,
156+
some months are longer or shorter than others. This is an example of "calendar" time, and the duration of that unit
157+
depends on context. Calendar units are also affected by leap-seconds, leap-years, etc.
158+
159+
This is important because the buckets generated by Rollup will be in either calendar or fixed intervals, and will limit
160+
how you can query them later (see <<rollup-search-limitations-intervals, Requests must be multiples of the config>>.
161+
162+
We recommend sticking with "fixed" time intervals, since they are easier to understand and are more flexible at query
163+
time. It will introduce some drift in your data during leap-events, and you will have to think about months in a fixed
164+
quantity (30 days) instead of the actual calendar length... but it is often easier than dealing with calendar units
165+
at query time.
166+
167+
Multiples of units are always "fixed" (e.g. `"2h"` is always the fixed quantity `7200` seconds. Single units can be
168+
fixed or calendar depending on the unit:
169+
170+
[options="header"]
171+
|=======
172+
|Unit |Calendar |Fixed
173+
|millisecond |NA |`1ms`, `10ms`, etc
174+
|second |NA |`1s`, `10s`, etc
175+
|minute |`1m` |`2m`, `10m`, etc
176+
|hour |`1h` |`2h`, `10h`, etc
177+
|day |`1d` |`2d`, `10d`, etc
178+
|week |`1w` |NA
179+
|month |`1M` |NA
180+
|quarter |`1q` |NA
181+
|year |`1y` |NA
182+
|=======
183+
184+
For some units where there are both fixed and calendar, you may need to express the quantity in terms of the next
185+
smaller unit. For example, if you want a fixed day (not a calendar day), you should specify `24h` instead of `1d`.
186+
Similarly, if you want fixed hours, specify `60m` instead of `1h`. This is because the single quantity entails
187+
calendar time, and limits you to querying by calendar time in the future.
188+
189+
190+
**********************************
191+
152192
===== Terms
153193

154194
The `terms` group can be used on `keyword` or numeric fields, to allow bucketing via the `terms` aggregation at a later point. The `terms`

docs/reference/rollup/rollup-getting-started.asciidoc

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ PUT _xpack/rollup/job/sensor
3939
"groups" : {
4040
"date_histogram": {
4141
"field": "timestamp",
42-
"interval": "1h",
43-
"delay": "7d"
42+
"interval": "60m"
4443
},
4544
"terms": {
4645
"fields": ["node"]
@@ -68,7 +67,7 @@ The `cron` parameter controls when and how often the job activates. When a roll
6867
from where it left off after the last activation. So if you configure the cron to run every 30 seconds, the job will process the last 30
6968
seconds worth of data that was indexed into the `sensor-*` indices.
7069

71-
If instead the cron was configured to run once a day at midnight, the job would process the last 24hours worth of data. The choice is largely
70+
If instead the cron was configured to run once a day at midnight, the job would process the last 24 hours worth of data. The choice is largely
7271
preference, based on how "realtime" you want the rollups, and if you wish to process continuously or move it to off-peak hours.
7372

7473
Next, we define a set of `groups` and `metrics`. The metrics are fairly straightforward: we want to save the min/max/sum of the `temperature`
@@ -81,7 +80,7 @@ It also allows us to run terms aggregations on the `node` field.
8180
.Date histogram interval vs cron schedule
8281
**********************************
8382
You'll note that the job's cron is configured to run every 30 seconds, but the date_histogram is configured to
84-
rollup at hourly intervals. How do these relate?
83+
rollup at 60 minute intervals. How do these relate?
8584
8685
The date_histogram controls the granularity of the saved data. Data will be rolled up into hourly intervals, and you will be unable
8786
to query with finer granularity. The cron simply controls when the process looks for new data to rollup. Every 30 seconds it will see
@@ -225,70 +224,71 @@ Which returns a corresponding response:
225224
[source,js]
226225
----
227226
{
228-
"took" : 93,
229-
"timed_out" : false,
230-
"terminated_early" : false,
231-
"_shards" : ... ,
232-
"hits" : {
233-
"total" : 0,
234-
"max_score" : 0.0,
235-
"hits" : [ ]
236-
},
237-
"aggregations" : {
238-
"timeline" : {
239-
"meta" : { },
240-
"buckets" : [
241-
{
242-
"key_as_string" : "2018-01-18T00:00:00.000Z",
243-
"key" : 1516233600000,
244-
"doc_count" : 6,
245-
"nodes" : {
246-
"doc_count_error_upper_bound" : 0,
247-
"sum_other_doc_count" : 0,
248-
"buckets" : [
249-
{
250-
"key" : "a",
251-
"doc_count" : 2,
252-
"max_temperature" : {
253-
"value" : 202.0
254-
},
255-
"avg_voltage" : {
256-
"value" : 5.1499998569488525
257-
}
258-
},
259-
{
260-
"key" : "b",
261-
"doc_count" : 2,
262-
"max_temperature" : {
263-
"value" : 201.0
264-
},
265-
"avg_voltage" : {
266-
"value" : 5.700000047683716
267-
}
268-
},
269-
{
270-
"key" : "c",
271-
"doc_count" : 2,
272-
"max_temperature" : {
273-
"value" : 202.0
274-
},
275-
"avg_voltage" : {
276-
"value" : 4.099999904632568
277-
}
278-
}
279-
]
280-
}
281-
}
282-
]
283-
}
284-
}
227+
"took" : 93,
228+
"timed_out" : false,
229+
"terminated_early" : false,
230+
"_shards" : ... ,
231+
"hits" : {
232+
"total" : 0,
233+
"max_score" : 0.0,
234+
"hits" : [ ]
235+
},
236+
"aggregations" : {
237+
"timeline" : {
238+
"meta" : { },
239+
"buckets" : [
240+
{
241+
"key_as_string" : "2018-01-18T00:00:00.000Z",
242+
"key" : 1516233600000,
243+
"doc_count" : 6,
244+
"nodes" : {
245+
"doc_count_error_upper_bound" : 0,
246+
"sum_other_doc_count" : 0,
247+
"buckets" : [
248+
{
249+
"key" : "a",
250+
"doc_count" : 2,
251+
"max_temperature" : {
252+
"value" : 202.0
253+
},
254+
"avg_voltage" : {
255+
"value" : 5.1499998569488525
256+
}
257+
},
258+
{
259+
"key" : "b",
260+
"doc_count" : 2,
261+
"max_temperature" : {
262+
"value" : 201.0
263+
},
264+
"avg_voltage" : {
265+
"value" : 5.700000047683716
266+
}
267+
},
268+
{
269+
"key" : "c",
270+
"doc_count" : 2,
271+
"max_temperature" : {
272+
"value" : 202.0
273+
},
274+
"avg_voltage" : {
275+
"value" : 4.099999904632568
276+
}
277+
}
278+
]
279+
}
280+
}
281+
]
282+
}
283+
}
285284
}
285+
286286
----
287287
// TESTRESPONSE[s/"took" : 93/"took" : $body.$_path/]
288288
// TESTRESPONSE[s/"_shards" : \.\.\. /"_shards" : $body.$_path/]
289289

290290
In addition to being more complicated (date histogram and a terms aggregation, plus an additional average metric), you'll notice
291-
the date_histogram uses a `7d` interval instead of `1h`.
291+
the date_histogram uses a `7d` interval instead of `60m`.
292292

293293
[float]
294294
=== Conclusion

docs/reference/rollup/rollup-search-limitations.asciidoc

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,25 @@ The response will tell you that the field and aggregation were not possible, bec
8282
[float]
8383
=== Interval Granularity
8484

85-
Rollups are stored at a certain granularity, as defined by the `date_histogram` group in the configuration. If data is rolled up at hourly
86-
intervals, the <<rollup-search>> API can aggregate on any time interval hourly or greater. Intervals that are less than an hour will throw
87-
an exception, since the data simply doesn't exist for finer granularities.
85+
Rollups are stored at a certain granularity, as defined by the `date_histogram` group in the configuration. This means you
86+
can only search/aggregate the rollup data with an interval that is greater-than or equal to the configured rollup interval.
87+
88+
For example, if data is rolled up at hourly intervals, the <<rollup-search>> API can aggregate on any time interval
89+
hourly or greater. Intervals that are less than an hour will throw an exception, since the data simply doesn't
90+
exist for finer granularities.
91+
92+
[[rollup-search-limitations-intervals]]
93+
.Requests must be multiples of the config
94+
**********************************
95+
Perhaps not immediately apparent, but the interval specified in an aggregation request must be a whole
96+
multiple of the configured interval. If the job was configured to rollup on `3d` intervals, you can only
97+
query and aggregate on multiples of three (`3d`, `6d`, `9d`, etc).
98+
99+
A non-multiple wouldn't work, since the rolled up data wouldn't cleanly "overlap" with the buckets generated
100+
by the aggregation, leading to incorrect results.
101+
102+
For that reason, an error is thrown if a whole multiple of the configured interval isn't found.
103+
**********************************
88104

89105
Because the RollupSearch endpoint can "upsample" intervals, there is no need to configure jobs with multiple intervals (hourly, daily, etc).
90106
It's recommended to just configure a single job with the smallest granularity that is needed, and allow the search endpoint to upsample

x-pack/docs/build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -674,9 +674,8 @@ setups['sensor_prefab_data'] = '''
674674
page_size: 1000
675675
groups:
676676
date_histogram:
677-
delay: "7d"
678677
field: "timestamp"
679-
interval: "1h"
678+
interval: "7d"
680679
time_zone: "UTC"
681680
terms:
682681
fields:

0 commit comments

Comments
 (0)