Skip to content

Commit

Permalink
base StatsMonitor expiration on writes (#450)
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
brharrington committed Jun 27, 2018
1 parent 356a025 commit 2d27fda
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Expand Up @@ -435,21 +435,21 @@ private void updateGauges() {
*/
@Override
public List<Monitor<?>> getMonitors() {
return monitors;
}

/**
* Record the measurement we want to perform statistics on.
*/
public void record(long measurement) {
lastUsed = clock.now();
if (isExpired()) {
LOGGER.info("Attempting to get the value for an expired monitor: {}."
+ "Will start computing stats again.",
getConfig().getName());
startComputingStats(executor, statsConfig.getFrequencyMillis());
return Collections.emptyList();
}
return monitors;
}

/**
* Record the measurement we want to perform statistics on.
*/
public void record(long measurement) {
synchronized (updateLock) {
cur.record(measurement);
}
Expand Down
@@ -1,5 +1,5 @@
/**
* Copyright 2015 Netflix, Inc.
/*
* Copyright 2011-2018 Netflix, Inc.
* <p/>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -38,7 +38,7 @@ public void testExpiration() throws Exception {
clock.set(TimeUnit.MINUTES.toMillis(20));
monitor.computeStats();
assertTrue(monitor.isExpired());
monitor.getMonitors();
monitor.record(42);
monitor.computeStats();
assertFalse(monitor.isExpired());
}
Expand Down

0 comments on commit 2d27fda

Please sign in to comment.