Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5ecbbf2

Browse files
committed
Return 0 for staleness when the client is shutdown or when refreshes not enabled. Otherwise the metric can be misleading.
1 parent 12712a9 commit 5ecbbf2

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

eureka-client/src/main/java/com/netflix/discovery/DiscoveryClient.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,6 +1677,10 @@ public long getLastSuccessfulRegistryFetchTimePeriod() {
16771677
@com.netflix.servo.annotations.Monitor(name = METRIC_REGISTRATION_PREFIX + "lastSuccessfulHeartbeatTimePeriod",
16781678
description = "How much time has passed from last successful heartbeat", type = DataSourceType.GAUGE)
16791679
private long getLastSuccessfulHeartbeatTimePeriodInternal() {
1680+
if (!clientConfig.shouldRegisterWithEureka() || isShutdown.get()) {
1681+
heartbeatStalenessMonitor.update(0);
1682+
return 0;
1683+
}
16801684
long delay = getLastSuccessfulHeartbeatTimePeriod();
16811685
heartbeatStalenessMonitor.update(computeStalenessMonitorDelay(delay));
16821686
return delay;
@@ -1686,6 +1690,10 @@ private long getLastSuccessfulHeartbeatTimePeriodInternal() {
16861690
@com.netflix.servo.annotations.Monitor(name = METRIC_REGISTRY_PREFIX + "lastSuccessfulRegistryFetchTimePeriod",
16871691
description = "How much time has passed from last successful local registry update", type = DataSourceType.GAUGE)
16881692
private long getLastSuccessfulRegistryFetchTimePeriodInternal() {
1693+
if (!clientConfig.shouldFetchRegistry() || isShutdown.get()) {
1694+
registryStalenessMonitor.update(0);
1695+
return 0;
1696+
}
16891697
long delay = getLastSuccessfulRegistryFetchTimePeriod();
16901698
registryStalenessMonitor.update(computeStalenessMonitorDelay(delay));
16911699
return delay;

0 commit comments

Comments
 (0)