From 2d27fdafe2b03a6ca45982261395b19e4e3436ab Mon Sep 17 00:00:00 2001 From: brharrington Date: Wed, 27 Jun 2018 09:17:56 -0700 Subject: [PATCH] base StatsMonitor expiration on writes (#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`. --- .../com/netflix/servo/monitor/StatsMonitor.java | 14 +++++++------- .../netflix/servo/monitor/StatsMonitorTest.java | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/servo-core/src/main/java/com/netflix/servo/monitor/StatsMonitor.java b/servo-core/src/main/java/com/netflix/servo/monitor/StatsMonitor.java index 836cf1b0..63cfb7af 100644 --- a/servo-core/src/main/java/com/netflix/servo/monitor/StatsMonitor.java +++ b/servo-core/src/main/java/com/netflix/servo/monitor/StatsMonitor.java @@ -435,21 +435,21 @@ private void updateGauges() { */ @Override public List> 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); } diff --git a/servo-core/src/test/java/com/netflix/servo/monitor/StatsMonitorTest.java b/servo-core/src/test/java/com/netflix/servo/monitor/StatsMonitorTest.java index 580f8d83..2767af3d 100644 --- a/servo-core/src/test/java/com/netflix/servo/monitor/StatsMonitorTest.java +++ b/servo-core/src/test/java/com/netflix/servo/monitor/StatsMonitorTest.java @@ -1,5 +1,5 @@ -/** - * Copyright 2015 Netflix, Inc. +/* + * Copyright 2011-2018 Netflix, Inc. *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -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()); }