Skip to content

Commit b6be914

Browse files
committed
Fix big spikes in usage_time metric
The StartupTime of an app can be 0 when the app was (automatically) stopped before the app has started up. This resulted in the UsageTime becoming the current time in milliseconds.
1 parent 9ed84b8 commit b6be914

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

src/main/java/eu/openanalytics/containerproxy/service/ProxyService.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,12 @@ public void stopProxy(Proxy proxy, boolean async, boolean ignoreAccessControl) {
298298
backend.stopProxy(proxy);
299299
logService.detach(proxy);
300300
log.info(String.format("Proxy released [user: %s] [spec: %s] [id: %s]", proxy.getUserId(), proxy.getSpec().getId(), proxy.getId()));
301-
applicationEventPublisher.publishEvent(new ProxyStopEvent(this, proxy.getUserId(),
302-
proxy.getSpec().getId(),
303-
Duration.ofMillis(System.currentTimeMillis() - proxy.getStartupTimestamp())));
304-
301+
if (proxy.getStartupTimestamp() == 0) {
302+
applicationEventPublisher.publishEvent(new ProxyStopEvent(this, proxy.getUserId(), proxy.getSpec().getId(), null));
303+
} else {
304+
applicationEventPublisher.publishEvent(new ProxyStopEvent(this, proxy.getUserId(), proxy.getSpec().getId(),
305+
Duration.ofMillis(System.currentTimeMillis() - proxy.getStartupTimestamp())));
306+
}
305307
} catch (Exception e){
306308
log.error("Failed to release proxy " + proxy.getId(), e);
307309
}

src/main/java/eu/openanalytics/containerproxy/stat/impl/Micrometer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ public void onProxyStartEvent(ProxyStartEvent event) {
126126
public void onProxyStopEvent(ProxyStopEvent event) {
127127
logger.debug("ProxyStopEvent [user: {}, usageTime: {}]", event.getUserId(), event.getUsageTime());
128128
registry.counter("appStops", "spec.id", event.getSpecId()).increment();
129-
registry.timer("usageTime", "spec.id", event.getSpecId()).record(event.getUsageTime());
129+
if (event.getUsageTime() != null) {
130+
registry.timer("usageTime", "spec.id", event.getSpecId()).record(event.getUsageTime());
131+
}
130132
}
131133

132134
@EventListener

0 commit comments

Comments
 (0)