Fix flush time calculation
Capture system time in local var. Add blank lines for consistency. Change-Id: I703843c9d45ac9d6be6a9e981eeaf9877b036109
This commit is contained in:
parent
4c4c1d3464
commit
1969fb74be
@ -94,7 +94,7 @@ public abstract class FlushableHandler<T> {
|
||||
|
||||
if (msg == null) {
|
||||
|
||||
if (checkFlushTime()) {
|
||||
if (isFlushTime()) {
|
||||
|
||||
int msgFlushCnt = flush();
|
||||
|
||||
@ -111,7 +111,7 @@ public abstract class FlushableHandler<T> {
|
||||
|
||||
this.processedMeter.mark();
|
||||
|
||||
if (checkBatchSize()) {
|
||||
if (isBatchSize()) {
|
||||
|
||||
int msgFlushCnt = flush();
|
||||
|
||||
@ -124,7 +124,7 @@ public abstract class FlushableHandler<T> {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkBatchSize() throws Exception {
|
||||
private boolean isBatchSize() throws Exception {
|
||||
|
||||
logger.debug("[{}]: checking batch size", this.threadId);
|
||||
|
||||
@ -141,7 +141,7 @@ public abstract class FlushableHandler<T> {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkFlushTime() throws Exception {
|
||||
private boolean isFlushTime() throws Exception {
|
||||
|
||||
logger.debug("[{}}: checking flush time", this.threadId);
|
||||
|
||||
@ -150,12 +150,14 @@ public abstract class FlushableHandler<T> {
|
||||
this.threadId,
|
||||
this.secondsBetweenFlushes);
|
||||
|
||||
if (this.flushTimeMillis < System.currentTimeMillis()) {
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
if (this.flushTimeMillis <= now ) {
|
||||
|
||||
logger.debug(
|
||||
"[{}]: {} millis past flush time. flushing to repository now.",
|
||||
this.threadId,
|
||||
(System.currentTimeMillis() - this.flushTimeMillis));
|
||||
now - this.flushTimeMillis);
|
||||
|
||||
return true;
|
||||
|
||||
@ -164,7 +166,7 @@ public abstract class FlushableHandler<T> {
|
||||
logger.debug(
|
||||
"[{}]: {} millis to next flush time. no need to flush at this time.",
|
||||
this.threadId,
|
||||
this.flushTimeMillis - System.currentTimeMillis());
|
||||
this.flushTimeMillis - now);
|
||||
|
||||
return false;
|
||||
|
||||
@ -188,6 +190,7 @@ public abstract class FlushableHandler<T> {
|
||||
logger.debug("[{}]: flushed {} msg", this.threadId, msgFlushCnt);
|
||||
|
||||
this.msgCount = 0;
|
||||
|
||||
this.batchCount++;
|
||||
|
||||
return msgFlushCnt;
|
||||
|
@ -69,22 +69,33 @@ public class InfluxV9AlarmRepo extends InfluxAlarmRepo {
|
||||
List<InfluxPoint> influxPointList = new LinkedList<>();
|
||||
|
||||
for (AlarmStateTransitionedEvent event : this.alarmStateTransitionedEventList) {
|
||||
|
||||
Map<String, Object> valueMap = new HashMap<>();
|
||||
|
||||
valueMap.put("tenant_id", event.tenantId);
|
||||
|
||||
valueMap.put("alarm_id", event.alarmId);
|
||||
|
||||
valueMap.put("metrics", this.objectMapper.writeValueAsString(event.metrics));
|
||||
|
||||
valueMap.put("old_state", event.oldState);
|
||||
|
||||
valueMap.put("new_state", event.newState);
|
||||
|
||||
valueMap.put("sub_alarms", this.objectMapper.writeValueAsString(event.subAlarms));
|
||||
|
||||
valueMap.put("reason", event.stateChangeReason);
|
||||
|
||||
valueMap.put("reason_data", "{}");
|
||||
|
||||
DateTime dateTime = new DateTime(event.timestamp, DateTimeZone.UTC);
|
||||
|
||||
String dateString = this.dateFormatter.print(dateTime);
|
||||
|
||||
Map<String, String> tags = new HashMap<>();
|
||||
|
||||
tags.put("tenant_id", event.tenantId);
|
||||
|
||||
tags.put("alarm_id", event.alarmId);
|
||||
|
||||
InfluxPoint
|
||||
@ -92,6 +103,7 @@ public class InfluxV9AlarmRepo extends InfluxAlarmRepo {
|
||||
new InfluxPoint(ALARM_STATE_HISTORY_NAME, tags, dateString, valueMap);
|
||||
|
||||
influxPointList.add(influxPoint);
|
||||
|
||||
}
|
||||
|
||||
return influxPointList.toArray(new InfluxPoint[influxPointList.size()]);
|
||||
|
@ -111,7 +111,9 @@ public class InfluxV9MetricRepo extends InfluxMetricRepo {
|
||||
for (Map.Entry<String, String> dimensionsEntry : dimensions.entrySet()) {
|
||||
|
||||
String name = dimensionsEntry.getKey();
|
||||
|
||||
String value = dimensionsEntry.getValue();
|
||||
|
||||
tagMap.put(name, value);
|
||||
|
||||
}
|
||||
|
@ -30,13 +30,17 @@ public class MeasurementBuffer {
|
||||
Map<Dimensions, List<Measurement>> dimensionsMap = this.measurementMap.get(definition);
|
||||
|
||||
if (dimensionsMap == null) {
|
||||
|
||||
dimensionsMap = initDimensionsMap(definition, dimensions);
|
||||
|
||||
}
|
||||
|
||||
List<Measurement> measurementList = dimensionsMap.get(dimensions);
|
||||
|
||||
if (measurementList == null) {
|
||||
|
||||
measurementList = initMeasurementList(dimensionsMap, dimensions);
|
||||
|
||||
}
|
||||
|
||||
measurementList.add(measurement);
|
||||
@ -65,8 +69,11 @@ public class MeasurementBuffer {
|
||||
Dimensions dimensions) {
|
||||
|
||||
Map<Dimensions, List<Measurement>> dimensionsMap = new HashMap<>();
|
||||
|
||||
List<Measurement> measurementList = new LinkedList<>();
|
||||
|
||||
dimensionsMap.put(dimensions, measurementList);
|
||||
|
||||
this.measurementMap.put(definition, dimensionsMap);
|
||||
|
||||
return dimensionsMap;
|
||||
@ -76,6 +83,7 @@ public class MeasurementBuffer {
|
||||
Dimensions dimensions) {
|
||||
|
||||
List<Measurement> measurementList = new LinkedList<>();
|
||||
|
||||
dimensionsMap.put(dimensions, measurementList);
|
||||
|
||||
return measurementList;
|
||||
|
Loading…
x
Reference in New Issue
Block a user