Skip to content

Commit

Permalink
[rrd4j] Reliably get the latest value, if the filter end date is set …
Browse files Browse the repository at this point in the history
…to "now" (#16059)

Signed-off-by: Kai Kreuzer <[email protected]>
  • Loading branch information
kaikreuzer authored Dec 14, 2023
1 parent 969518a commit ea3e608
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
Expand Down Expand Up @@ -444,15 +445,13 @@ public Iterable<HistoricItem> query(FilterCriteria filter) {

try {
if (filterBeginDate == null) {
// as rrd goes back for years and gets more and more
// inaccurate, we only support descending order
// and a single return value
// if there is no begin date is given - this case is
// required specifically for the historicState()
// query, which we want to support
// as rrd goes back for years and gets more and more inaccurate, we only support descending order
// and a single return value if no begin date is given - this case is required specifically for the
// historicState() query, which we want to support
if (filter.getOrdering() == Ordering.DESCENDING && filter.getPageSize() == 1
&& filter.getPageNumber() == 0) {
if (filterEndDate == null) {
if (filterEndDate == null || Duration.between(filterEndDate, ZonedDateTime.now()).getSeconds() < db
.getRrdDef().getStep()) {
// we are asked only for the most recent value!
double lastValue = db.getLastDatasourceValue(DATASOURCE_STATE);
if (!Double.isNaN(lastValue)) {
Expand Down

0 comments on commit ea3e608

Please sign in to comment.