-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add stats for DiscoveryClient (#1282)
Introduce a nested class for `DiscoveryClient` to make it easier for users to read helpful attributes that can assist in log analysis and debugging. Most of these attributes are captured by existing metrics: - `initTimestampMs`: timestamp when the client was initialized - `localRegistrySize`: number of instances for all applications - `lastSuccessfulRegistryFetchTimestampMs`: timestamp for last successful fetch - `lastSuccessfulHeartbeatTimestampMs`: timestamp for last successful heartbeat Add a new attribute called `initLocalRegistrySize`, which is the number of instances for all applications read when the client was initialized. Include a helper method that uses this attribute so that users can determine whether the client's initial fetch of registry information succeeded or failed. Note that other accessors are suffixed with `Ms` (for milliseconds) to denote the time unit. Additionally, update the existing `registrySize` with the value from `initLocalRegistrySize` during initialization instead of waiting until the first local registry refresh. Co-authored-by: John Bennett <bennett@netflix.com>
- Loading branch information
Showing
3 changed files
with
124 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
eureka-client/src/test/java/com/netflix/discovery/DiscoveryClientStatsInitFailedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.netflix.discovery; | ||
|
||
import com.netflix.discovery.junit.resource.DiscoveryClientResource; | ||
import org.junit.After; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Tests for DiscoveryClient stats reported when initial registry fetch fails. | ||
*/ | ||
public class DiscoveryClientStatsInitFailedTest extends BaseDiscoveryClientTester { | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
setupProperties(); | ||
populateRemoteRegistryAtStartup(); | ||
setupDiscoveryClient(); | ||
} | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
shutdownDiscoveryClient(); | ||
DiscoveryClientResource.clearDiscoveryClientConfig(); | ||
} | ||
|
||
@Test | ||
public void testEmptyInitLocalRegistrySize() throws Exception { | ||
Assert.assertTrue(client instanceof DiscoveryClient); | ||
DiscoveryClient clientImpl = (DiscoveryClient) client; | ||
Assert.assertEquals(0, clientImpl.getStats().initLocalRegistrySize()); | ||
} | ||
|
||
@Test | ||
public void testInitFailed() throws Exception { | ||
Assert.assertTrue(client instanceof DiscoveryClient); | ||
DiscoveryClient clientImpl = (DiscoveryClient) client; | ||
Assert.assertFalse(clientImpl.getStats().initSucceeded()); | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
eureka-client/src/test/java/com/netflix/discovery/DiscoveryClientStatsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.netflix.discovery; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Tests for DiscoveryClient stats reported when initial registry fetch succeeds. | ||
*/ | ||
public class DiscoveryClientStatsTest extends AbstractDiscoveryClientTester { | ||
|
||
@Test | ||
public void testNonEmptyInitLocalRegistrySize() throws Exception { | ||
Assert.assertTrue(client instanceof DiscoveryClient); | ||
DiscoveryClient clientImpl = (DiscoveryClient) client; | ||
Assert.assertEquals(createLocalApps().size(), clientImpl.getStats().initLocalRegistrySize()); | ||
} | ||
|
||
@Test | ||
public void testInitSucceeded() throws Exception { | ||
Assert.assertTrue(client instanceof DiscoveryClient); | ||
DiscoveryClient clientImpl = (DiscoveryClient) client; | ||
Assert.assertTrue(clientImpl.getStats().initSucceeded()); | ||
} | ||
|
||
} |