[java-identity-provider] 01/03: IDP-2114 Add metrics for installed plugins and modules

Rod Widdowson rdw at steadingsoftware.com
Tue Jun 20 14:51:27 UTC 2023


This is an automated email from the git hooks/post-receive script.

rdw pushed a commit to branch main
in repository java-identity-provider.

View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=cb1343702a56905f183525c40fa812926e2c83a7

commit cb1343702a56905f183525c40fa812926e2c83a7
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Sat Jun 17 16:56:17 2023 +0100

    IDP-2114 Add metrics for installed plugins and modules
    
    https://shibboleth.atlassian.net/browse/IDP-2114
    
    Guage to report all avalable modules whether they are enabled.
---
 .../shibboleth/idp/module/impl/ModuleGuageSet.java | 99 ++++++++++++++++++++++
 .../net/shibboleth/idp/conf/admin-system.xml       |  2 +
 .../shibboleth/idp/module/conf/admin/metrics.xml   |  1 +
 3 files changed, 102 insertions(+)

diff --git a/idp-admin-impl/src/main/java/net/shibboleth/idp/module/impl/ModuleGuageSet.java b/idp-admin-impl/src/main/java/net/shibboleth/idp/module/impl/ModuleGuageSet.java
new file mode 100644
index 000000000..71a9c2cbc
--- /dev/null
+++ b/idp-admin-impl/src/main/java/net/shibboleth/idp/module/impl/ModuleGuageSet.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.idp.module.impl;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.ServiceLoader;
+
+import javax.annotation.Nonnull;
+
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ApplicationObjectSupport;
+
+import com.codahale.metrics.Gauge;
+import com.codahale.metrics.Metric;
+import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.MetricSet;
+
+import net.shibboleth.idp.module.IdPModule;
+import net.shibboleth.profile.module.ModuleContext;
+import net.shibboleth.shared.annotation.constraint.NonnullElements;
+import net.shibboleth.shared.annotation.constraint.NotEmpty;
+import net.shibboleth.shared.annotation.constraint.NotLive;
+import net.shibboleth.shared.collection.CollectionSupport;
+import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.primitive.StringSupport;
+
+/**
+ * Guage set to report the Modules' statuses.
+ */
+public class ModuleGuageSet extends ApplicationObjectSupport implements MetricSet {
+    
+    /** Default prefix for metrics. */
+    @Nonnull @NotEmpty private static final String DEFAULT_METRIC_NAME = "net.shibboleth.idp.modules";
+
+    /** The map of gauges. */
+    @Nonnull @NonnullElements private final Map<String,Metric> gauges = new HashMap<>();
+    
+    public ModuleGuageSet() {
+        gauges.put(MetricRegistry.name(DEFAULT_METRIC_NAME, "list"),
+                new Gauge<Map<String, Boolean>>() {
+                    public Map<String, Boolean> getValue() {
+                        return getModules();
+                    }
+                });
+    }
+
+    /** Return the module Ids and whether rhey are enabled or not.
+     * @return the modules.
+     */
+    @NotLive @Nonnull private Map<String, Boolean> getModules() {
+        final Map<String, Boolean> result = new HashMap<>();
+        final Iterator<IdPModule> modules = ServiceLoader.load(IdPModule.class).iterator();
+        final ModuleContext mc = new ModuleContext(getIdpHome());
+        while (modules.hasNext()) {
+            final IdPModule module = modules.next();
+            result.put(module.getId(), module.isEnabled(mc));
+        }
+        return CollectionSupport.copyToMap(result);
+    }
+
+    /** Get the idp home location (from the properties in the context)
+     * @return idpHome
+     */
+    @Nonnull private String getIdpHome() {
+        final ApplicationContext context = getApplicationContext();
+        assert context != null;
+        return Constraint.isNotNull(StringSupport.trimOrNull(context.getEnvironment().getProperty("idp.home")), "idp.home is not available");
+    }
+
+    @Override
+    public Map<String, Metric> getMetrics() {
+        return gauges;
+    }
+    
+    /** {@inheritDoc} */
+    @Override
+    protected boolean isContextRequired() {
+        return true;
+    }
+
+
+}
diff --git a/idp-conf-impl/src/main/resources/net/shibboleth/idp/conf/admin-system.xml b/idp-conf-impl/src/main/resources/net/shibboleth/idp/conf/admin-system.xml
index 9144a917a..17d349ac9 100644
--- a/idp-conf-impl/src/main/resources/net/shibboleth/idp/conf/admin-system.xml
+++ b/idp-conf-impl/src/main/resources/net/shibboleth/idp/conf/admin-system.xml
@@ -285,6 +285,8 @@
     
     <bean id="shibboleth.metrics.CoreGaugeSet" class="org.opensaml.core.metrics.impl.CoreGaugeSet" lazy-init="true" />
     
+    <bean id="shibboleth.metrics.ModuleGaugeSet" class="net.shibboleth.idp.module.impl.ModuleGuageSet" lazy-init="true" />
+
     <bean id="shibboleth.metrics.IdPGaugeSet" class="net.shibboleth.idp.metrics.impl.IdPGaugeSet" lazy-init="true"
         p:exposedProperties="#{getObject('shibboleth.metrics.ExposedProperties')}" />
     
diff --git a/idp-conf-impl/src/main/resources/net/shibboleth/idp/module/conf/admin/metrics.xml b/idp-conf-impl/src/main/resources/net/shibboleth/idp/module/conf/admin/metrics.xml
index 208ab6b2e..782d707a3 100644
--- a/idp-conf-impl/src/main/resources/net/shibboleth/idp/module/conf/admin/metrics.xml
+++ b/idp-conf-impl/src/main/resources/net/shibboleth/idp/module/conf/admin/metrics.xml
@@ -31,6 +31,7 @@
                 <ref bean="shibboleth.metrics.AttributeFilterGaugeSet" />
                 <ref bean="shibboleth.metrics.CASServiceRegistryGaugeSet" />
                 <ref bean="shibboleth.metrics.ManagedBeanGaugeSet" />
+                <ref bean="shibboleth.metrics.ModuleGaugeSet" />
 
                 <!--
                 <bean class="com.codahale.metrics.jvm.CachedThreadStatesGaugeSet"

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list