[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
Tue Oct 25 21:52:37 EDT 2016
Author: putmanb
Date: Tue Oct 25 21:52:37 2016
New Revision: 4558
URL: http://svn.shibboleth.net/view/java-opensaml?rev=4558&view=rev
Log:
OSJ-182: Add Metrics instrumentation to dynamic metadata resolvers
Initial draft of a couple of counters and a timer.
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=4558&r1=4557&r2=4558&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 Tue Oct 25 21:52:37 2016
@@ -36,6 +36,7 @@
import org.joda.time.DateTime;
import org.joda.time.chrono.ISOChronology;
import org.opensaml.core.criterion.EntityIdCriterion;
+import org.opensaml.core.metrics.MetricsSupport;
import org.opensaml.core.xml.XMLObject;
import org.opensaml.core.xml.io.MarshallingException;
import org.opensaml.core.xml.io.UnmarshallingException;
@@ -50,6 +51,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.codahale.metrics.MetricRegistry;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
@@ -75,8 +77,20 @@
public abstract class AbstractDynamicMetadataResolver extends AbstractMetadataResolver
implements DynamicMetadataResolver {
+ /** Metric name for timer on fetch from origin source. */
+ public static final String METRIC_TIMER_FETCH_FROM_ORIGIN_SOURCE = "fetchFromOriginSourceTimer";
+
+ /** Metric name for counter on number of fetches from origin source. */
+ public static final String METRIC_COUNTER_FETCHES_FROM_ORIGIN_SOURCE = "fetchesFromOriginSource";
+
+ /** Metric name for counter on number of fetches from origin source. */
+ public static final String METRIC_COUNTER_RESOLVE_REQUESTS = "resolveRequests";
+
/** Class logger. */
private final Logger log = LoggerFactory.getLogger(AbstractDynamicMetadataResolver.class);
+
+ /** Base name for Metrics instrumentation names. */
+ @NonnullAfterInit private String metricsBaseName;
/** Timer used to schedule background metadata update tasks. */
private Timer taskTimer;
@@ -430,7 +444,25 @@
cleanupTaskInterval = Constraint.isNotNull(interval, "Cleanup task interval may not be null");
}
-
+ /**
+ * Get the base name for Metrics instrumentation.
+ *
+ * @return the Metrics base name
+ */
+ @NonnullAfterInit public String getMetricsBaseName() {
+ return metricsBaseName;
+ }
+
+ /**
+ * Set the base name for Metrics instrumentation.
+ *
+ * @param baseName the Metrics base name
+ */
+ public void setMetricsBaseName(@Nullable final String baseName) {
+ ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+ ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);
+ metricsBaseName = StringSupport.trimOrNull(baseName);
+ }
/** {@inheritDoc} */
@Override
@@ -446,6 +478,9 @@
final String entityID = StringSupport.trimOrNull(criteria.get(EntityIdCriterion.class).getEntityId());
log.debug("Attempting to resolve metadata for entityID: {}", entityID);
+
+ MetricsSupport.getMetricRegistry().counter(MetricRegistry.name(getMetricsBaseName(),
+ METRIC_COUNTER_RESOLVE_REQUESTS)).inc();
final EntityManagementData mgmtData = getBackingStore().getManagementData(entityID);
final Lock readLock = mgmtData.getReadWriteLock().readLock();
@@ -505,7 +540,19 @@
log.debug("Resolving metadata dynamically for entity ID: {}", entityID);
}
- final XMLObject root = fetchFromOriginSource(criteria);
+ final MetricRegistry metricRegistry = MetricsSupport.getMetricRegistry();
+ metricRegistry.counter(MetricRegistry.name(getMetricsBaseName(),
+ METRIC_COUNTER_FETCHES_FROM_ORIGIN_SOURCE)).inc();
+ final com.codahale.metrics.Timer fetchTimer = metricRegistry.timer(
+ MetricRegistry.name(getMetricsBaseName(), METRIC_TIMER_FETCH_FROM_ORIGIN_SOURCE));
+ final com.codahale.metrics.Timer.Context fetchContext = fetchTimer.time();
+ XMLObject root = null;
+ try {
+ root = fetchFromOriginSource(criteria);
+ } finally {
+ fetchContext.stop();
+ }
+
if (root == null) {
[... 14 lines stripped ...]
More information about the commits
mailing list