[java-opensaml] branch main updated: Add a slot for a counter to increment.
Scott Cantor
cantor.2 at osu.edu
Thu May 25 16:45:11 UTC 2023
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch main
in repository java-opensaml.
View the commit online:
http://git.shibboleth.net/view/?p=java-opensaml.git;a=commit;h=e0087f3749b80c8c96592bbe8a5a2afde4401100
The following commit(s) were added to refs/heads/main by this push:
new e0087f374 Add a slot for a counter to increment.
e0087f374 is described below
commit e0087f3749b80c8c96592bbe8a5a2afde4401100
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Thu May 25 12:45:08 2023 -0400
Add a slot for a counter to increment.
---
opensaml-profile-impl/pom.xml | 5 ++++
.../profile/action/impl/PopulateMetricContext.java | 32 +++++++++++++++++++++-
2 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/opensaml-profile-impl/pom.xml b/opensaml-profile-impl/pom.xml
index 6a0f35678..d7a9e2633 100644
--- a/opensaml-profile-impl/pom.xml
+++ b/opensaml-profile-impl/pom.xml
@@ -63,6 +63,11 @@
<artifactId>shib-security</artifactId>
</dependency>
+ <dependency>
+ <groupId>io.dropwizard.metrics</groupId>
+ <artifactId>metrics-core</artifactId>
+ </dependency>
+
<!-- Provided Dependencies -->
<dependency>
<groupId>jakarta.servlet</groupId>
diff --git a/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/PopulateMetricContext.java b/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/PopulateMetricContext.java
index fa0b525a6..866eb2cb1 100644
--- a/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/PopulateMetricContext.java
+++ b/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/PopulateMetricContext.java
@@ -22,14 +22,18 @@ import java.util.function.Function;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+import org.opensaml.core.metrics.MetricsSupport;
import org.opensaml.profile.action.AbstractProfileAction;
import org.opensaml.profile.context.MetricContext;
import org.opensaml.profile.context.ProfileRequestContext;
import org.slf4j.Logger;
+import com.codahale.metrics.MetricRegistry;
+
import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.primitive.LoggerFactory;
+import net.shibboleth.shared.primitive.StringSupport;
/**
@@ -40,7 +44,9 @@ import net.shibboleth.shared.primitive.LoggerFactory;
* <p>Unlike a more typical "lookup strategy" design used in most other places, the strategy function
* supplied is free, and indeed expected, to directly manipulate the created child context directly
* rather than returning the data to use. The function may return false to indicate a lack of success,
- * but this value is merely logged.</p>
+ * but this is merely logged.</p>
+ *
+ * <p>A side effect of this action is the incrementing of a counter corresponding to the profile running.</p>
*
* @event {@link org.opensaml.profile.action.EventIds#PROCEED_EVENT_ID}
*/
@@ -49,9 +55,25 @@ public class PopulateMetricContext extends AbstractProfileAction {
/** Class logger. */
@Nonnull private final Logger log = LoggerFactory.getLogger(PopulateMetricContext.class);
+ /** Counter to increment on execution. */
+ @Nullable private String counterName;
+
/** Strategy function for establishing metric mappings to apply. */
@NonnullAfterInit private Function<ProfileRequestContext,Boolean> metricStrategy;
+ /**
+ * Set a counter name to increment.
+ *
+ * @param name counter name
+ *
+ * @since 5.0.0
+ */
+ public void setCounterName(@Nullable final String name) {
+ checkSetterPreconditions();
+
+ counterName = StringSupport.trimOrNull(name);
+ }
+
/**
* Set strategy to establish the metric mappings to use.
*
@@ -77,6 +99,14 @@ public class PopulateMetricContext extends AbstractProfileAction {
@Override
protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
+ // Increment a counter if set.
+ if (counterName != null) {
+ final MetricRegistry registry = MetricsSupport.getMetricRegistry();
+ if (registry != null) {
+ registry.counter(counterName).inc();
+ }
+ }
+
final MetricContext metricCtx = new MetricContext();
profileRequestContext.addSubcontext(metricCtx, true);
if (!metricStrategy.apply(profileRequestContext)) {
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list