[rrd4j] Improve timestamp handling (#15107)

* [rrd4j] Improve timestamp handling

Signed-off-by: Jan N. Klug <github@klug.nrw>
This commit is contained in:
J-N-K 2023-06-18 21:14:41 +02:00 committed by GitHub
parent 2603f5f355
commit 07e640387c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -205,6 +205,16 @@ public class RRD4jPersistenceService implements QueryablePersistenceService {
return; return;
} }
try {
if (now < db.getLastUpdateTime()) {
logger.warn("RRD4J does not support adding past value this={}, last update={}. Discarding {} - {}", now,
db.getLastUpdateTime(), name, value);
return;
}
} catch (IOException ignored) {
// we can ignore that here, we'll fail again later.
}
ConsolFun function = getConsolidationFunction(db); ConsolFun function = getConsolidationFunction(db);
if (function != ConsolFun.AVERAGE) { if (function != ConsolFun.AVERAGE) {
try { try {
@ -231,8 +241,8 @@ public class RRD4jPersistenceService implements QueryablePersistenceService {
Sample sample = db.createSample(); Sample sample = db.createSample();
sample.setTime(now); sample.setTime(now);
double storeValue = value; double storeValue = value;
if (db.getDatasource(DATASOURCE_STATE).getType() == DsType.COUNTER) { // counter values must be if (db.getDatasource(DATASOURCE_STATE).getType() == DsType.COUNTER) {
// adjusted by stepsize // counter values must be adjusted by stepsize
storeValue = value * db.getRrdDef().getStep(); storeValue = value * db.getRrdDef().getStep();
} }
sample.setValue(DATASOURCE_STATE, storeValue); sample.setValue(DATASOURCE_STATE, storeValue);
@ -247,8 +257,7 @@ public class RRD4jPersistenceService implements QueryablePersistenceService {
job.cancel(true); job.cancel(true);
scheduledJobs.remove(name); scheduledJobs.remove(name);
} }
job = scheduler.schedule(() -> internalStore(name, value, now + 1, false), 1, TimeUnit.SECONDS); internalStore(name, value, now + 1, false);
scheduledJobs.put(name, job);
} else { } else {
logger.warn("Could not persist '{}' to rrd4j database: {}", name, e.getMessage()); logger.warn("Could not persist '{}' to rrd4j database: {}", name, e.getMessage());
} }