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,16 @@ 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+ private final Counter LOOKUP_GET_APPLICATIONS_SERVICE_URL = SpectatorUtil .counter (PREFIX + "Lookup" , "getApplicationsServiceUrl" , DiscoveryClient .class );
141+
136142 // instance variables
137143 /**
138144 * A scheduler to be used for the following 3 tasks:
@@ -564,6 +570,7 @@ public ApplicationInfoManager getApplicationInfoManager() {
564570 */
565571 @ Override
566572 public Application getApplication (String appName ) {
573+ LOOKUP_GET_APPLICATION .increment ();
567574 return getApplications ().getRegisteredApplications (appName );
568575 }
569576
@@ -574,11 +581,13 @@ public Application getApplication(String appName) {
574581 */
575582 @ Override
576583 public Applications getApplications () {
584+ LOOKUP_GET_APPLICATIONS .increment ();
577585 return localRegionApps .get ();
578586 }
579587
580588 @ Override
581589 public Applications getApplicationsForARegion (@ Nullable String region ) {
590+ LOOKUP_GET_APPLICATIONS_FOR_A_REGION .increment ();
582591 if (instanceRegionChecker .isLocalRegion (region )) {
583592 return localRegionApps .get ();
584593 } else {
@@ -604,6 +613,7 @@ public Set<String> getAllKnownRegions() {
604613 */
605614 @ Override
606615 public List <InstanceInfo > getInstancesById (String id ) {
616+ LOOKUP_GET_INSTANCES_BY_ID .increment ();
607617 List <InstanceInfo > instancesList = new ArrayList <>();
608618 for (Application app : this .getApplications ()
609619 .getRegisteredApplications ()) {
@@ -688,6 +698,7 @@ public List<InstanceInfo> getInstancesByVipAddress(String vipAddress, boolean se
688698 @ Override
689699 public List <InstanceInfo > getInstancesByVipAddress (String vipAddress , boolean secure ,
690700 @ Nullable String region ) {
701+ LOOKUP_GET_INSTANCES_BY_VIP .increment ();
691702 if (vipAddress == null ) {
692703 throw new IllegalArgumentException (
693704 "Supplied VIP Address cannot be null" );
@@ -700,30 +711,17 @@ public List<InstanceInfo> getInstancesByVipAddress(String vipAddress, boolean se
700711 if (null == applications ) {
701712 logger .debug ("No applications are defined for region {}, so returning an empty instance list for vip "
702713 + "address {}." , region , vipAddress );
703- recordVipAddressLookup (vipAddress , secure );
704714 return Collections .emptyList ();
705715 }
706716 }
707717
708- recordVipAddressLookup (vipAddress , secure );
709718 if (!secure ) {
710719 return applications .getInstancesByVirtualHostName (vipAddress );
711720 } else {
712721 return applications .getInstancesBySecureVirtualHostName (vipAddress );
713722 }
714723 }
715724
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-
727725 /**
728726 * Gets the list of instances matching the given VIP Address and the given
729727 * application name if both of them are not null. If one of them is null,
@@ -740,6 +738,7 @@ private void recordVipAddressLookup(String vipAddress, boolean secure) {
740738 @ Override
741739 public List <InstanceInfo > getInstancesByVipAddressAndAppName (
742740 String vipAddress , String appName , boolean secure ) {
741+ LOOKUP_GET_INSTANCES_BY_VIP_AND_APP .increment ();
743742
744743 List <InstanceInfo > result = new ArrayList <>();
745744 if (vipAddress == null && appName == null ) {
@@ -794,6 +793,7 @@ public List<InstanceInfo> getInstancesByVipAddressAndAppName(
794793 */
795794 @ Override
796795 public InstanceInfo getNextServerFromEureka (String virtualHostname , boolean secure ) {
796+ LOOKUP_GET_NEXT_SERVER .increment ();
797797 List <InstanceInfo > instanceInfoList = this .getInstancesByVipAddress (
798798 virtualHostname , secure );
799799 if (instanceInfoList == null || instanceInfoList .isEmpty ()) {
@@ -815,6 +815,7 @@ public InstanceInfo getNextServerFromEureka(String virtualHostname, boolean secu
815815 */
816816 @ Override
817817 public Applications getApplications (String serviceUrl ) {
818+ LOOKUP_GET_APPLICATIONS_SERVICE_URL .increment ();
818819 try {
819820 EurekaHttpResponse <Applications > response = clientConfig .getRegistryRefreshSingleVipAddress () == null
820821 ? eurekaTransport .queryClient .getApplications ()
0 commit comments