1616
1717package com .netflix .discovery ;
1818
19- import static com .netflix .discovery .EurekaClientNames .METRIC_LOOKUP_PREFIX ;
2019import static com .netflix .discovery .EurekaClientNames .METRIC_REGISTRATION_PREFIX ;
2120import static com .netflix .discovery .EurekaClientNames .METRIC_REGISTRY_PREFIX ;
2221import static com .netflix .discovery .util .SpectatorUtil .monitoredNumber ;
2322import static com .netflix .discovery .util .SpectatorUtil .monitoredValue ;
2423
2524import com .netflix .discovery .util .SpectatorUtil ;
26- import com .netflix .spectator .api .BasicTag ;
2725import com .netflix .spectator .api .Counter ;
28- import com .netflix .spectator .api .Spectator ;
29- import com .netflix .spectator .api .Tag ;
3026import com .netflix .spectator .api .Timer ;
3127import java .util .ArrayList ;
3228import java .util .Collection ;
@@ -133,6 +129,15 @@ public class DiscoveryClient implements EurekaClient {
133129 private final Timer FETCH_REGISTRY_TIMER = SpectatorUtil .timer (PREFIX + "FetchRegistry" , DiscoveryClient .class );
134130 private final Counter REREGISTER_COUNTER = SpectatorUtil .counter (PREFIX + "Reregister" , DiscoveryClient .class );
135131
132+ // Lookup counters
133+ private final Counter LOOKUP_GET_APPLICATION = SpectatorUtil .counter (PREFIX + "Lookup" , "getApplication" , DiscoveryClient .class );
134+ private final Counter LOOKUP_GET_APPLICATIONS = SpectatorUtil .counter (PREFIX + "Lookup" , "getApplications" , DiscoveryClient .class );
135+ private final Counter LOOKUP_GET_APPLICATIONS_FOR_A_REGION = SpectatorUtil .counter (PREFIX + "Lookup" , "getApplicationsForARegion" , DiscoveryClient .class );
136+ private final Counter LOOKUP_GET_INSTANCES_BY_ID = SpectatorUtil .counter (PREFIX + "Lookup" , "getInstancesById" , DiscoveryClient .class );
137+ private final Counter LOOKUP_GET_INSTANCES_BY_VIP = SpectatorUtil .counter (PREFIX + "Lookup" , "getInstancesByVipAddress" , DiscoveryClient .class );
138+ private final Counter LOOKUP_GET_INSTANCES_BY_VIP_AND_APP = SpectatorUtil .counter (PREFIX + "Lookup" , "getInstancesByVipAddressAndAppName" , DiscoveryClient .class );
139+ private final Counter LOOKUP_GET_NEXT_SERVER = SpectatorUtil .counter (PREFIX + "Lookup" , "getNextServerFromEureka" , DiscoveryClient .class );
140+
136141 // instance variables
137142 /**
138143 * A scheduler to be used for the following 3 tasks:
@@ -564,6 +569,7 @@ public ApplicationInfoManager getApplicationInfoManager() {
564569 */
565570 @ Override
566571 public Application getApplication (String appName ) {
572+ LOOKUP_GET_APPLICATION .increment ();
567573 return getApplications ().getRegisteredApplications (appName );
568574 }
569575
@@ -574,11 +580,13 @@ public Application getApplication(String appName) {
574580 */
575581 @ Override
576582 public Applications getApplications () {
583+ LOOKUP_GET_APPLICATIONS .increment ();
577584 return localRegionApps .get ();
578585 }
579586
580587 @ Override
581588 public Applications getApplicationsForARegion (@ Nullable String region ) {
589+ LOOKUP_GET_APPLICATIONS_FOR_A_REGION .increment ();
582590 if (instanceRegionChecker .isLocalRegion (region )) {
583591 return localRegionApps .get ();
584592 } else {
@@ -604,6 +612,7 @@ public Set<String> getAllKnownRegions() {
604612 */
605613 @ Override
606614 public List <InstanceInfo > getInstancesById (String id ) {
615+ LOOKUP_GET_INSTANCES_BY_ID .increment ();
607616 List <InstanceInfo > instancesList = new ArrayList <>();
608617 for (Application app : this .getApplications ()
609618 .getRegisteredApplications ()) {
@@ -688,6 +697,7 @@ public List<InstanceInfo> getInstancesByVipAddress(String vipAddress, boolean se
688697 @ Override
689698 public List <InstanceInfo > getInstancesByVipAddress (String vipAddress , boolean secure ,
690699 @ Nullable String region ) {
700+ LOOKUP_GET_INSTANCES_BY_VIP .increment ();
691701 if (vipAddress == null ) {
692702 throw new IllegalArgumentException (
693703 "Supplied VIP Address cannot be null" );
@@ -700,30 +710,17 @@ public List<InstanceInfo> getInstancesByVipAddress(String vipAddress, boolean se
700710 if (null == applications ) {
701711 logger .debug ("No applications are defined for region {}, so returning an empty instance list for vip "
702712 + "address {}." , region , vipAddress );
703- recordVipAddressLookup (vipAddress , secure );
704713 return Collections .emptyList ();
705714 }
706715 }
707716
708- recordVipAddressLookup (vipAddress , secure );
709717 if (!secure ) {
710718 return applications .getInstancesByVirtualHostName (vipAddress );
711719 } else {
712720 return applications .getInstancesBySecureVirtualHostName (vipAddress );
713721 }
714722 }
715723
716- private void recordVipAddressLookup (String vipAddress , boolean secure ) {
717- if (clientConfig .shouldEnableVipAddressLookupMetrics ()) {
718- SpectatorUtil .counter (
719- METRIC_LOOKUP_PREFIX + "vipAddress" ,
720- "vip" , vipAddress ,
721- "secure" , String .valueOf (secure ),
722- "class" , "DiscoveryClient"
723- ).increment ();
724- }
725- }
726-
727724 /**
728725 * Gets the list of instances matching the given VIP Address and the given
729726 * application name if both of them are not null. If one of them is null,
@@ -740,6 +737,7 @@ private void recordVipAddressLookup(String vipAddress, boolean secure) {
740737 @ Override
741738 public List <InstanceInfo > getInstancesByVipAddressAndAppName (
742739 String vipAddress , String appName , boolean secure ) {
740+ LOOKUP_GET_INSTANCES_BY_VIP_AND_APP .increment ();
743741
744742 List <InstanceInfo > result = new ArrayList <>();
745743 if (vipAddress == null && appName == null ) {
@@ -794,6 +792,7 @@ public List<InstanceInfo> getInstancesByVipAddressAndAppName(
794792 */
795793 @ Override
796794 public InstanceInfo getNextServerFromEureka (String virtualHostname , boolean secure ) {
795+ LOOKUP_GET_NEXT_SERVER .increment ();
797796 List <InstanceInfo > instanceInfoList = this .getInstancesByVipAddress (
798797 virtualHostname , secure );
799798 if (instanceInfoList == null || instanceInfoList .isEmpty ()) {
0 commit comments