SEBSERV-286 fixed wrong indicator PK (connectionId) on some saves

and also mitigated the possibility of getting negative ping times.
This commit is contained in:
anhefti 2022-03-03 15:59:11 +01:00
parent 8632e594bd
commit 95669ec576
4 changed files with 22 additions and 14 deletions

View file

@ -74,8 +74,10 @@ public abstract class AbstractLogLevelCountIndicator extends AbstractLogIndicato
.execute();
// update active indicator value record on persistent when caching is not enabled
if (!this.cachingEnabled && this.active && this.ditributedIndicatorValueRecordId != null) {
this.distributedPingCache.updateIndicatorValue(this.connectionId, numberOfLogs.longValue());
if (this.active && this.ditributedIndicatorValueRecordId != null) {
this.distributedPingCache.updateIndicatorValue(
this.ditributedIndicatorValueRecordId,
numberOfLogs.longValue());
}
return numberOfLogs.doubleValue();

View file

@ -99,8 +99,10 @@ public abstract class AbstractLogNumberIndicator extends AbstractLogIndicator {
if (numericValue != null) {
// update active indicator value record on persistent when caching is not enabled
if (!this.cachingEnabled && this.active && this.ditributedIndicatorValueRecordId != null) {
this.distributedPingCache.updateIndicatorValue(this.connectionId, numericValue.longValue());
if (this.active && this.ditributedIndicatorValueRecordId != null) {
this.distributedPingCache.updateIndicatorValue(
this.ditributedIndicatorValueRecordId,
numericValue.longValue());
}
return numericValue.doubleValue();

View file

@ -361,7 +361,7 @@ public class DistributedIndicatorValueService implements DisposableBean {
pingRecord,
Utils.getMillisecondsNow()));
} catch (final Exception e) {
if (log.isDebugEnabled()) {
if (log.isTraceEnabled()) {
log.warn("Failed to schedule ping task: {}" + e.getMessage());
}
}

View file

@ -81,12 +81,19 @@ public final class PingIntervalClientIndicator extends AbstractPingIndicator {
if (!this.initialized) {
return Double.NaN;
}
final long currentTimeMillis = DateTimeUtils.currentTimeMillis();
if (this.initialized && !this.cachingEnabled && this.active
&& this.lastUpdate != this.distributedPingCache.lastUpdate()) {
final long currentTimeMillis = DateTimeUtils.currentTimeMillis();
this.currentValue = computeValueAt(currentTimeMillis);
return (currentTimeMillis < this.currentValue)
? DateTimeUtils.currentTimeMillis() - this.currentValue
: currentTimeMillis - this.currentValue;
} else {
return DateTimeUtils.currentTimeMillis() - this.currentValue;
}
return currentTimeMillis - this.currentValue;
}
@Override
@ -101,17 +108,14 @@ public final class PingIntervalClientIndicator extends AbstractPingIndicator {
@Override
public final double computeValueAt(final long timestamp) {
if (!this.cachingEnabled && super.ditributedIndicatorValueRecordId != null) {
if (super.ditributedIndicatorValueRecordId != null) {
final Long lastPing = this.distributedPingCache
.getIndicatorValue(super.ditributedIndicatorValueRecordId);
if (lastPing != null) {
final double doubleValue = lastPing.doubleValue();
return Math.max(Double.isNaN(this.currentValue) ? doubleValue : this.currentValue, doubleValue);
}
return this.currentValue;
return (lastPing != null)
? lastPing.doubleValue()
: this.currentValue;
}
return !this.initialized ? timestamp : this.currentValue;