Skip to content

Commit 1406e74

Browse files
committed
Account for negative clock skew in flushMetrics
1 parent afbe0da commit 1406e74

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

stats.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ var conf;
7070

7171
// Flush metrics to each backend.
7272
function flushMetrics() {
73-
setTimeout(flushMetrics, getFlushTimeout(flushInterval));
74-
7573
var time_stamp = Math.round(new Date().getTime() / 1000);
7674
if (old_timestamp > 0) {
7775
gauges[timestamp_lag_namespace] = (time_stamp - old_timestamp - (Number(conf.flushInterval)/1000));
@@ -141,7 +139,7 @@ function flushMetrics() {
141139
}
142140
}
143141

144-
// normally gauges are not reset. so if we don't delete them, continue to persist previous value
142+
// Normally gauges are not reset. so if we don't delete them, continue to persist previous value
145143
conf.deleteGauges = conf.deleteGauges || false;
146144
if (conf.deleteGauges) {
147145
for (var gauge_key in metrics.gauges) {
@@ -154,6 +152,10 @@ function flushMetrics() {
154152
backendEvents.emit('flush', time_stamp, metrics);
155153
});
156154

155+
// Performing this setTimeout at the end of this method rather than the beginning
156+
// helps ensure we adapt to negative clock skew by letting the method's latency
157+
// introduce a short delay that should more than compensate.
158+
setTimeout(flushMetrics, getFlushTimeout(flushInterval));
157159
}
158160

159161
var stats = {

0 commit comments

Comments
 (0)