bugfix: query engine resampling duration (#4759)
Costa Tsaousis committed
Nov 27, 2018 at 15:14 UTC
ba75ffc056be3ed999561545cb6c23e7ef35437f
1 file changed
+33
-18
web/api/queries/query.c
+33
-18
@@ -492,7 +492,7 @@ static inline void do_dimension(
492
r->min = min;
493
r->max = max;
494
r->before = max_date;
495
- r->after = min_date;
495
+ r->after = min_date - (r->group - 1) * r->st->update_every;
496
rrdr_done(r, rrdr_line);
497
498
#ifdef NETDATA_INTERNAL_CHECKS
@@ -539,7 +539,7 @@ static void rrd2rrdr_log_request_response_metdata(RRDR *r
539
, resampling_group
540
541
// after
542
- , (size_t)r->after - (group - 1) * r->st->update_every
542
+ , (size_t)r->after
543
, (size_t)after_wanted
544
, (size_t)after_requested
545
, (size_t)rrdset_first_entry_t(r->st)
@@ -666,26 +666,41 @@ RRDR *rrd2rrdr(
666
info("INTERNAL CHECK: %s: requested gtime %ld secs, is greater than the desired duration %ld secs", st->id, resampling_time_requested, duration);
667
#endif
668
669
- group = available_points; // use all the points
669
+ after_requested = before_requested - resampling_time_requested;
670
+ duration = before_requested - after_requested;
671
+ available_points = duration / st->update_every;
672
+ group = available_points / points_requested;
673
}
671
- else {
672
- // the points we should group to satisfy gtime
673
- resampling_group = resampling_time_requested / st->update_every;
674
- if(unlikely(resampling_time_requested % st->update_every)) {
675
- #ifdef NETDATA_INTERNAL_CHECKS
676
- info("INTERNAL CHECK: %s: requested gtime %ld secs, is not a multiple of the chart's data collection frequency %d secs", st->id, resampling_time_requested, st->update_every);
677
- #endif
674
679
- resampling_group++;
675
+ // if the duration is not aligned to resampling time
676
+ // extend the duration to the past, to avoid a gap at the chart
677
+ // only when the missing duration is above 1/10th of a point
678
+ if(duration % resampling_time_requested) {
679
+ time_t delta = duration % resampling_time_requested;
680
+ if(delta > resampling_time_requested / 10) {
681
+ after_requested -= resampling_time_requested - delta;
682
+ duration = before_requested - after_requested;
683
+ available_points = duration / st->update_every;
684
+ group = available_points / points_requested;
685
}
686
+ }
687
682
- // adapt group according to resampling_group
683
- if(unlikely(group < resampling_group)) group = resampling_group; // do not allow grouping below the desired one
684
- if(unlikely(group % resampling_group)) group += resampling_group - (group % resampling_group); // make sure group is multiple of resampling_group
688
+ // the points we should group to satisfy gtime
689
+ resampling_group = resampling_time_requested / st->update_every;
690
+ if(unlikely(resampling_time_requested % st->update_every)) {
691
+ #ifdef NETDATA_INTERNAL_CHECKS
692
+ info("INTERNAL CHECK: %s: requested gtime %ld secs, is not a multiple of the chart's data collection frequency %d secs", st->id, resampling_time_requested, st->update_every);
693
+ #endif
694
686
- //resampling_divisor = group / resampling_group;
687
- resampling_divisor = (calculated_number)(group * st->update_every) / (calculated_number)resampling_time_requested;
695
+ resampling_group++;
696
}
697
+
698
+ // adapt group according to resampling_group
699
+ if(unlikely(group < resampling_group)) group = resampling_group; // do not allow grouping below the desired one
700
+ if(unlikely(group % resampling_group)) group += resampling_group - (group % resampling_group); // make sure group is multiple of resampling_group
701
+
702
+ //resampling_divisor = group / resampling_group;
703
+ resampling_divisor = (calculated_number)(group * st->update_every) / (calculated_number)resampling_time_requested;
704
}
705
706
// now that we have group,
@@ -710,7 +725,7 @@ RRDR *rrd2rrdr(
725
726
// we need to estimate the number of points, for having
727
// an integer number of values per point
713
- long points_wanted = (before_wanted - after_requested) / st->update_every / group;
728
+ long points_wanted = (before_wanted - after_requested) / (st->update_every * group);
729
730
time_t after_wanted = before_wanted - (points_wanted * group * st->update_every) + st->update_every;
731
if(unlikely(after_wanted < first_entry_t)) {
@@ -951,7 +966,7 @@ RRDR *rrd2rrdr(
966
rrd2rrdr_log_request_response_metdata(r, group_method, aligned, group, resampling_time_requested, resampling_group, after_wanted, after_requested, before_wanted, before_requested, points_requested, points_wanted, after_slot, before_slot, "got 'before' is not wanted 'before'");
967
968
// reported 'after' varies, depending on group
954
- if((r->after - (group - 1) * r->st->update_every) != after_wanted)
969
+ if(r->after != after_wanted)
970
rrd2rrdr_log_request_response_metdata(r, group_method, aligned, group, resampling_time_requested, resampling_group, after_wanted, after_requested, before_wanted, before_requested, points_requested, points_wanted, after_slot, before_slot, "got 'after' is not wanted 'after'");
971
972
#endif