diff options
author | Costa Tsaousis <costa@netdata.cloud> | 2023-10-04 20:54:16 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-04 20:54:16 +0300 |
commit | 9fd9823e077869987e7d2b665fd46ac3e5a015ec (patch) | |
tree | 476937a7dd0a734e9f04678e6fd5cc69e88ba7c7 /libnetdata | |
parent | 0904758540fe93fd92829960497e66d4a0a82a4d (diff) |
journal: fix the 1 second latency in play mode (#16123)
provide a relative_to_absolute function that does not touch the current realtime time
Diffstat (limited to 'libnetdata')
-rw-r--r-- | libnetdata/libnetdata.c | 33 | ||||
-rw-r--r-- | libnetdata/libnetdata.h | 3 |
2 files changed, 25 insertions, 11 deletions
diff --git a/libnetdata/libnetdata.c b/libnetdata/libnetdata.c index 0fbf7e211d..159e89950f 100644 --- a/libnetdata/libnetdata.c +++ b/libnetdata/libnetdata.c @@ -1969,18 +1969,13 @@ int hash256_string(const unsigned char *string, size_t size, char *hash) { } #endif -// Returns 1 if an absolute period was requested or 0 if it was a relative period -bool rrdr_relative_window_to_absolute(time_t *after, time_t *before, time_t *now_ptr, bool unittest_running) { - time_t now = now_realtime_sec() - 1; - if(now_ptr) - *now_ptr = now; +bool rrdr_relative_window_to_absolute(time_t *after, time_t *before, time_t now) { + if(!now) now = now_realtime_sec(); int absolute_period_requested = -1; - long long after_requested, before_requested; - - before_requested = *before; - after_requested = *after; + time_t before_requested = *before; + time_t after_requested = *after; // allow relative for before (smaller than API_RELATIVE_TIME_MAX) if(ABS(before_requested) <= API_RELATIVE_TIME_MAX) { @@ -2025,11 +2020,29 @@ bool rrdr_relative_window_to_absolute(time_t *after, time_t *before, time_t *now // shift the query back to be in the present time // (this may also happen because of the rules above) if(before_requested > now) { - long long delta = before_requested - now; + time_t delta = before_requested - now; before_requested -= delta; after_requested -= delta; } + *before = before_requested; + *after = after_requested; + + return (absolute_period_requested != 1); +} + +// Returns 1 if an absolute period was requested or 0 if it was a relative period +bool rrdr_relative_window_to_absolute_query(time_t *after, time_t *before, time_t *now_ptr, bool unittest_running) { + time_t now = now_realtime_sec() - 1; + + if(now_ptr) + *now_ptr = now; + + time_t before_requested = *before; + time_t after_requested = *after; + + int absolute_period_requested = rrdr_relative_window_to_absolute(&after_requested, &before_requested, now); + time_t absolute_minimum_time = now - (10 * 365 * 86400); time_t absolute_maximum_time = now + (1 * 365 * 86400); diff --git a/libnetdata/libnetdata.h b/libnetdata/libnetdata.h index 164817044e..c337b3b5d4 100644 --- a/libnetdata/libnetdata.h +++ b/libnetdata/libnetdata.h @@ -989,7 +989,8 @@ int hash256_string(const unsigned char *string, size_t size, char *hash); extern bool unittest_running; #define API_RELATIVE_TIME_MAX (3 * 365 * 86400) -bool rrdr_relative_window_to_absolute(time_t *after, time_t *before, time_t *now_ptr, bool unittest_running); +bool rrdr_relative_window_to_absolute(time_t *after, time_t *before, time_t now); +bool rrdr_relative_window_to_absolute_query(time_t *after, time_t *before, time_t *now_ptr, bool unittest_running); int netdata_base64_decode(const char *encoded, char *decoded, size_t decoded_size); |