[java-identity-provider] 02/02: IDP-2114 - Add metrics for installed plugins and modules
Scott Cantor
cantor.2 at osu.edu
Tue Jun 20 15:58:43 UTC 2023
This is an automated email from the git hooks/post-receive script.
scantor 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=17f63f644d21efd6e17992458f5fe2c27a2aca6d
commit 17f63f644d21efd6e17992458f5fe2c27a2aca6d
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Jun 20 11:58:38 2023 -0400
IDP-2114 - Add metrics for installed plugins and modules
https://shibboleth.atlassian.net/browse/IDP-2114
Add MetricFilter interface and wire in new gauges as a group.
Rename metrics path to "installation"
Tweak logging levels, verbiage.
---
.../admin/impl/InstallableComponentGuageSet.java | 45 +++++++++++++---------
.../idp/admin/impl/ReportUpdateStatus.java | 16 ++++----
.../net/shibboleth/idp/conf/admin-system.xml | 1 +
.../shibboleth/idp/module/conf/admin/metrics.xml | 3 ++
4 files changed, 37 insertions(+), 28 deletions(-)
diff --git a/idp-admin-impl/src/main/java/net/shibboleth/idp/admin/impl/InstallableComponentGuageSet.java b/idp-admin-impl/src/main/java/net/shibboleth/idp/admin/impl/InstallableComponentGuageSet.java
index baeed636b..bc1138235 100644
--- a/idp-admin-impl/src/main/java/net/shibboleth/idp/admin/impl/InstallableComponentGuageSet.java
+++ b/idp-admin-impl/src/main/java/net/shibboleth/idp/admin/impl/InstallableComponentGuageSet.java
@@ -36,6 +36,7 @@ import org.slf4j.Logger;
import com.codahale.metrics.Gauge;
import com.codahale.metrics.Metric;
+import com.codahale.metrics.MetricFilter;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.MetricSet;
@@ -48,10 +49,10 @@ import net.shibboleth.profile.installablecomponent.InstallableComponentSupport;
import net.shibboleth.profile.installablecomponent.InstallableComponentSupport.SupportLevel;
import net.shibboleth.profile.installablecomponent.InstallableComponentVersion;
import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
-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.annotation.constraint.NullableElements;
+import net.shibboleth.shared.annotation.constraint.Unmodifiable;
import net.shibboleth.shared.collection.CollectionSupport;
import net.shibboleth.shared.component.AbstractIdentifiableInitializableComponent;
import net.shibboleth.shared.component.ComponentInitializationException;
@@ -61,16 +62,17 @@ import net.shibboleth.shared.primitive.LoggerFactory;
/**
* Guage set to report the Plugins' & IdP's installation and update statuses.
*/
-public class InstallableComponentGuageSet extends AbstractIdentifiableInitializableComponent implements MetricSet {
+public class InstallableComponentGuageSet extends AbstractIdentifiableInitializableComponent
+ implements MetricSet, MetricFilter {
/** Default prefix for metrics. */
- @Nonnull @NotEmpty private static final String DEFAULT_METRIC_NAME = "net.shibboleth.idp.installedcomponent";
+ @Nonnull @NotEmpty private static final String DEFAULT_METRIC_NAME = "net.shibboleth.idp.installation";
/** Logger. */
@Nonnull private final Logger log = LoggerFactory.getLogger(InstallableComponentGuageSet.class);
/** The map of gauges. */
- @Nonnull @NonnullElements private final Map<String,Metric> gauges = new HashMap<>();
+ @Nonnull private final Map<String,Metric> gauges = new HashMap<>();
/** Where to look for update information. */
@Nonnull private List<URL> idpUpdateUrls = CollectionSupport.emptyList();
@@ -144,7 +146,7 @@ public class InstallableComponentGuageSet extends AbstractIdentifiableInitializa
*
* @return map where the key is the PluginId and the value is the version
*/
- @Nonnull @NotLive private Map<String, InstallableComponentVersion> getPluginList() {
+ @Nonnull @NotLive @Unmodifiable private Map<String, InstallableComponentVersion> getPluginList() {
final Map<String, InstallableComponentVersion> result = new HashMap<>();
final Iterator<IdPPlugin> plugins = ServiceLoader.load(IdPPlugin.class).iterator();
while (plugins.hasNext()) {
@@ -154,7 +156,7 @@ public class InstallableComponentGuageSet extends AbstractIdentifiableInitializa
return CollectionSupport.copyToMap(result);
}
- private Map<String, InstallableComponentDetails> getPluginDetails() {
+ @Nonnull @NotLive @Unmodifiable private Map<String, InstallableComponentDetails> getPluginDetails() {
@NullableElements final Map<URL, Properties> pluginInfoCache = new HashMap<>();
final Map<String, InstallableComponentDetails> result = new HashMap<>();
final Iterator<IdPPlugin> plugins = ServiceLoader.load(IdPPlugin.class).iterator();
@@ -163,14 +165,14 @@ public class InstallableComponentGuageSet extends AbstractIdentifiableInitializa
assert plugin!=null;
final Properties properties = lookupIdPProperties(plugin, pluginInfoCache);
if (properties==null) {
- log.error("Could not located Plugin version information");
+ log.warn("Could not locate plugin version information");
continue;
}
final InstallableComponentInfo info = new PluginInfo(plugin.getPluginId(), properties);
final InstallableComponentVersion pluginVersion = new InstallableComponentVersion(plugin);
final VersionInfo verInfo = info.getAvailableVersions().get(pluginVersion);
if (verInfo == null) {
- log.error("Could not located Plugin version information");
+ log.warn("Could not locate plugin version information");
continue;
}
final InstallableComponentVersion newPluginVersion =
@@ -182,11 +184,11 @@ public class InstallableComponentGuageSet extends AbstractIdentifiableInitializa
}
/**
- * Look in the cache for the URL and return the properties if its there,
+ * Look in the cache for the URL and return the properties if it's there,
* otherwise reach out to the URL and load the properties.
*
* @param plugin the {@link IdPPlugin} to consider
- * @param pluginInfoCache the cache of already looked up info. Also serves as a negative cache
+ * @param pluginInfoCache the cache of already looked up info, also serves as a negative cache
*
* @return IdP update properties
*/
@@ -196,10 +198,10 @@ public class InstallableComponentGuageSet extends AbstractIdentifiableInitializa
try {
urls = plugin.getUpdateURLs();
} catch (final IOException e) {
- log.error("Could not locate plugin {} update urls", plugin.getPluginId(), e);
+ log.error("Could not locate plugin {} update URLs", plugin.getPluginId(), e);
return null;
}
- for (final URL url:urls) {
+ for (final URL url : urls) {
if (pluginInfoCache.containsKey(url)) {
return pluginInfoCache.get(url);
}
@@ -224,13 +226,13 @@ public class InstallableComponentGuageSet extends AbstractIdentifiableInitializa
final Properties properties =
InstallableComponentSupport.loadInfo(idpUpdateUrls, httpClient, securityParams);
if (properties == null) {
- log.error("Could not locate IdP update information");
+ log.warn("Could not locate IdP update information");
return null;
}
final InstallableComponentInfo info = new IdPInfo(properties);
final VersionInfo verInfo = info.getAvailableVersions().get(getIdPVersion());
if (verInfo == null) {
- log.error("Could not located IdP version information");
+ log.warn("Could not locate IdP version information");
return null;
}
final InstallableComponentVersion newIdPVersion =
@@ -247,12 +249,12 @@ public class InstallableComponentGuageSet extends AbstractIdentifiableInitializa
protected void doInitialize() throws ComponentInitializationException {
super.doInitialize();
if (httpClient == null) {
- throw new ComponentInitializationException("Http Client was null");
+ throw new ComponentInitializationException("HttpClient was null");
}
final String idpVersionStr = Version.getVersion();
if (idpVersionStr == null) {
- // So things work inside eclipse.
- log.error("Could not find Current IdP Version, assuming V5.0.0");
+ // So things work inside Eclipse.
+ log.warn("Could not find current IdP Version (likely operating inside IDE), assuming V5.0.0");
idpVersion = new InstallableComponentVersion(5,0,0);
} else {
idpVersion = new InstallableComponentVersion(idpVersionStr);
@@ -265,7 +267,12 @@ public class InstallableComponentGuageSet extends AbstractIdentifiableInitializa
return gauges;
}
- record InstallableComponentDetails(@Nonnull @NotEmpty SupportLevel supportedState,
- @Nullable InstallableComponentVersion updateVersion) { };
+ /** {@inheritDoc} */
+ public boolean matches(final String name, final Metric metric) {
+ return gauges.containsKey(name);
+ }
+ record InstallableComponentDetails(@Nonnull @NotEmpty SupportLevel supportedState,
+ @Nullable InstallableComponentVersion updateVersion) { }
+
}
\ No newline at end of file
diff --git a/idp-admin-impl/src/main/java/net/shibboleth/idp/admin/impl/ReportUpdateStatus.java b/idp-admin-impl/src/main/java/net/shibboleth/idp/admin/impl/ReportUpdateStatus.java
index 0ae8704eb..1c9474f0e 100644
--- a/idp-admin-impl/src/main/java/net/shibboleth/idp/admin/impl/ReportUpdateStatus.java
+++ b/idp-admin-impl/src/main/java/net/shibboleth/idp/admin/impl/ReportUpdateStatus.java
@@ -102,12 +102,10 @@ public class ReportUpdateStatus extends AbstractIdentifiableInitializableCompone
return;
}
if (httpClient == null) {
- log.error("Http Client was not set");
- throw new ComponentInitializationException("Http Client was not set");
+ throw new ComponentInitializationException("HttpClient was not set");
}
if (updateUrls.isEmpty()) {
- log.error("No Update Urls set");
- throw new ComponentInitializationException("No Update Urls set");
+ throw new ComponentInitializationException("No update URLs set");
}
final ExecutorService svc = Executors.newSingleThreadExecutor();
@@ -123,14 +121,14 @@ public class ReportUpdateStatus extends AbstractIdentifiableInitializableCompone
try {
final String versionStr = Version.getVersion();
if (versionStr == null) {
- log.error("Could not find Current IdP Version");
+ log.warn("Could not find current IdP Version (likely operating inside IDE)");
return;
}
@Nonnull final InstallableComponentVersion version = new InstallableComponentVersion(versionStr);
assert httpClient!=null;
final Properties properties = InstallableComponentSupport.loadInfo(updateUrls, httpClient, securityParams);
if (properties == null) {
- log.error("Could not locate IdP update information");
+ log.warn("Could not locate IdP update information");
return;
}
final InstallableComponentInfo info = new IdPInfo(properties);
@@ -138,7 +136,7 @@ public class ReportUpdateStatus extends AbstractIdentifiableInitializableCompone
final InstallableComponentVersion newIdPVersion =
InstallableComponentSupport.getBestVersion(version, version, info);
if (newIdPVersion == null) {
- log.info("No Upgrade available from {}", version);
+ log.info("No upgrade available from {}", version);
} else {
log.warn("Version {} can be upgraded to {}", version, newIdPVersion);
}
@@ -152,7 +150,7 @@ public class ReportUpdateStatus extends AbstractIdentifiableInitializableCompone
log.debug("Version {} is current");
break;
case Secadv:
- log.error("Version {} has secuorty alerts again it.", version);
+ log.error("Version {} has known security vulnerabilities", version);
break;
default:
log.warn("Support level for {} is {}", version, sl);
@@ -164,4 +162,4 @@ public class ReportUpdateStatus extends AbstractIdentifiableInitializableCompone
}
}
-}
+}
\ No newline at end of file
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 95f271e45..92238f547 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
@@ -351,6 +351,7 @@
<value>http://plugins.shibboleth.net/idp-versions.properties</value>
</util:list>
+ <!-- Used to log state of updateability in IdP log, no role after startup. -->
<bean id="shibboleth.UpdateStatus"
class="net.shibboleth.idp.admin.impl.ReportUpdateStatus"
lazy-init="false"
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 ea6bb25f4..0bdbe39b6 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
@@ -32,6 +32,8 @@
<ref bean="shibboleth.metrics.CASServiceRegistryGaugeSet" />
<ref bean="shibboleth.metrics.ManagedBeanGaugeSet" />
<ref bean="shibboleth.metrics.ModuleGaugeSet" />
+
+ <!-- Note that this accesses remote "state" regarding IdP and plugin updates. -->
<ref bean="shibboleth.metrics.InstallableComponents" />
<!--
@@ -67,6 +69,7 @@
<entry key="filter" value-ref="shibboleth.metrics.AttributeFilterGaugeSet" />
<entry key="cas" value-ref="shibboleth.metrics.CASServiceRegistryGaugeSet" />
<entry key="bean" value-ref="shibboleth.metrics.ManagedBeanGaugeSet" />
+ <entry key="updates" value-ref="shibboleth.metrics.InstallableComponents" />
</util:map>
<!-- Add any desired properties into set to expose them as IdP metrics. -->
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list