Skip to content

Commit 2d27fda

Browse files
authored
base StatsMonitor expiration on writes (Netflix#450)
Before it was using calls to `getMonitors` to update the last used time. That method will not get called when delegating to Spectator and thus it will always expire 15 minutes after registration and never come back. This changes the last used time to get updated when values are recorded rather than when they are read using `getMonitors`.
1 parent 356a025 commit 2d27fda

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

servo-core/src/main/java/com/netflix/servo/monitor/StatsMonitor.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -435,21 +435,21 @@ private void updateGauges() {
435435
*/
436436
@Override
437437
public List<Monitor<?>> getMonitors() {
438+
return monitors;
439+
}
440+
441+
/**
442+
* Record the measurement we want to perform statistics on.
443+
*/
444+
public void record(long measurement) {
438445
lastUsed = clock.now();
439446
if (isExpired()) {
440447
LOGGER.info("Attempting to get the value for an expired monitor: {}."
441448
+ "Will start computing stats again.",
442449
getConfig().getName());
443450
startComputingStats(executor, statsConfig.getFrequencyMillis());
444-
return Collections.emptyList();
445451
}
446-
return monitors;
447-
}
448452

449-
/**
450-
* Record the measurement we want to perform statistics on.
451-
*/
452-
public void record(long measurement) {
453453
synchronized (updateLock) {
454454
cur.record(measurement);
455455
}

servo-core/src/test/java/com/netflix/servo/monitor/StatsMonitorTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/**
2-
* Copyright 2015 Netflix, Inc.
1+
/*
2+
* Copyright 2011-2018 Netflix, Inc.
33
* <p/>
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,7 +38,7 @@ public void testExpiration() throws Exception {
3838
clock.set(TimeUnit.MINUTES.toMillis(20));
3939
monitor.computeStats();
4040
assertTrue(monitor.isExpired());
41-
monitor.getMonitors();
41+
monitor.record(42);
4242
monitor.computeStats();
4343
assertFalse(monitor.isExpired());
4444
}

0 commit comments

Comments
 (0)