[java-opensaml COMMIT] /trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/AbstractDynam...

noreply at shibboleth.net noreply at shibboleth.net
Sun Nov 6 19:54:44 EST 2016


Author: putmanb
Date: Sun Nov  6 19:54:44 2016
New Revision: 4567

URL: http://svn.shibboleth.net/view/java-opensaml?rev=4567&view=rev
Log:
OSJ-182: Add Metrics instrumentation to dynamic metadata resolvers

Add a gauge and internal supporting code for metrics on the persistent cache init.
Also log the persistent cache init metrics data on debug, since we have it handy.

Modified:
    trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/AbstractDynamicMetadataResolver.java

Modified: trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/AbstractDynamicMetadataResolver.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/AbstractDynamicMetadataResolver.java?rev=4567&r1=4566&r2=4567&view=diff
==============================================================================
--- trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/AbstractDynamicMetadataResolver.java	(original)
+++ trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/AbstractDynamicMetadataResolver.java	Sun Nov  6 19:54:44 2016
@@ -56,6 +56,7 @@
 import com.codahale.metrics.RatioGauge;
 import com.codahale.metrics.Timer.Context;
 import com.google.common.base.Function;
+import com.google.common.base.MoreObjects;
 import com.google.common.base.Predicate;
 import com.google.common.base.Predicates;
 import com.google.common.base.Strings;
@@ -92,6 +93,9 @@
     /** Metric name for the gauge of the number of live entityIDs. */
     public static final String METRIC_GAUGE_NUM_LIVE_ENTITYIDS = "gauge.numLiveEntityIDs";
     
+    /** Metric name for the gauge of the persistent cache initialization metrics. */
+    public static final String METRIC_GAUGE_PERSISTENT_CACHE_INIT = "gauge.persistentCacheInitialization";
+    
     /** Class logger. */
     private final Logger log = LoggerFactory.getLogger(AbstractDynamicMetadataResolver.class);
     
@@ -109,6 +113,9 @@
     
     /** Metrics Gauge for the number of live entityIDs.*/
     @Nullable private Gauge<Integer> gaugeNumLiveEntityIDs;
+    
+    /** Metrics Gauge for the persistent cache initialization.*/
+    @Nullable private Gauge<PersistentCacheInitializationMetrics> gaugePersistentCacheInit;
     
     /** Timer used to schedule background metadata update tasks. */
     private Timer taskTimer;
@@ -153,6 +160,9 @@
     /** Predicate which determines whether a given entity should be loaded from the persistent cache
      * at resolver initialization time. */
     private Predicate<EntityDescriptor> initializationFromCachePredicate;
+    
+    /** Object tracking metrics related to the persistent cache initialization. */
+    @NonnullAfterInit private PersistentCacheInitializationMetrics persistentCacheInitMetrics;
     
     /** Flag used to track state of whether currently initializing or not. */
     private boolean initializing;
@@ -836,7 +846,9 @@
                 setInitializationFromCachePredicate(Predicates.<EntityDescriptor>alwaysTrue());
             }
             
+            persistentCacheInitMetrics = new PersistentCacheInitializationMetrics();
             if (isPersistentCachingEnabled()) {
+                persistentCacheInitMetrics.enabled = true;
                 if (isInitializeFromPersistentCacheInBackground()) {
                     log.debug("Initializing from the persistent cache in the background in {} ms", 
                             getBackgroundInitializatonFromCacheDelay());
@@ -894,6 +906,14 @@
                             return getBackingStore().getIndexedDescriptors().keySet().size();
                         }},
                     true);
+            
+            gaugePersistentCacheInit = MetricsSupport.register(
+                    MetricRegistry.name(getMetricsBaseName(), METRIC_GAUGE_PERSISTENT_CACHE_INIT),
+                    new Gauge<PersistentCacheInitializationMetrics>() {
+                        public PersistentCacheInitializationMetrics getValue() {
+                            return persistentCacheInitMetrics;
+                        }},
+                    true);
         }
     }
     
@@ -908,8 +928,10 @@
             log.trace("Attempting to load and process entities from the persistent cache");
         }
         
+        long start = System.nanoTime();
         try {
             for (final Pair<String, EntityDescriptor> cacheEntry: getPersistentCacheManager().listAll()) {
+                persistentCacheInitMetrics.entriesTotal++;
                 final EntityDescriptor descriptor = cacheEntry.getSecond();
                 final String currentKey = cacheEntry.getFirst();
                 log.trace("Loaded EntityDescriptor from cache store with entityID '{}' and storage key '{}'", 
@@ -927,6 +949,7 @@
                     if (!lookupIndexedEntityID(entityID).isEmpty()) {
                         log.trace("Metadata for entityID '{}' found in persistent cache was already live, " 
                                 + "ignoring cached entry", entityID);

[... 175 lines stripped ...]


More information about the commits mailing list