From 4628ed96fde16f78a7b2a6330b4960e1d99ca7e7 Mon Sep 17 00:00:00 2001 From: David Chan Date: Wed, 11 Dec 2024 14:25:33 -0500 Subject: [PATCH 1/2] Do not asssociate vendor connection pool metrics with an application --- .../LegacyMetricRegistryAdapter.java | 80 +++++++++++++++++-- 1 file changed, 75 insertions(+), 5 deletions(-) diff --git a/dev/io.openliberty.io.smallrye.metrics/src/io/smallrye/metrics/legacyapi/LegacyMetricRegistryAdapter.java b/dev/io.openliberty.io.smallrye.metrics/src/io/smallrye/metrics/legacyapi/LegacyMetricRegistryAdapter.java index bee41a2a17e..fcbf70009c1 100644 --- a/dev/io.openliberty.io.smallrye.metrics/src/io/smallrye/metrics/legacyapi/LegacyMetricRegistryAdapter.java +++ b/dev/io.openliberty.io.smallrye.metrics/src/io/smallrye/metrics/legacyapi/LegacyMetricRegistryAdapter.java @@ -504,7 +504,16 @@ CounterAdapter internalCounter(MpMetadata metadata, MetricDescriptor id) { CounterAdapter result = checkCast(CounterAdapter.class, metadata, constructedMeters.computeIfAbsent(id, k -> new CounterAdapter())); - addNameToApplicationMap(id); + + //LIBERTY CHANGE START + /* + * Check if metric is an Openliberty connection pool metric. + * Do not associate with application if true. + */ + if (!isLibertyVendorConnectionPoolMetricCounter(id.name())) { + addNameToApplicationMap(id); + } + //LIBERTY CHANGE END return result.register(metadata, id, registry, scope, resolveMPConfigGlobalTagsByServer()); } @@ -539,7 +548,15 @@ FunctionCounterAdapter internalCounter(MpMetadata metadata, T obj, ToDoub FunctionCounterAdapter result = checkCast(FunctionCounterAdapter.class, metadata, constructedMeters.computeIfAbsent(id, k -> new FunctionCounterAdapter(obj, func))); - addNameToApplicationMap(id); + //LIBERTY CHANGE START + /* + * Check if metric is an Openliberty connection pool metric. + * Do not associate with application if true. + */ + if (!isLibertyVendorConnectionPoolMetricCounter(id.name())) { + addNameToApplicationMap(id); + } + //LIBERTY CHANGE END return result.register(metadata, id, registry, scope, resolveMPConfigGlobalTagsByServer()); } @@ -599,16 +616,61 @@ GaugeAdapter internalGauge(MpMetadata metadata, MetricDescriptor id, validateTagNamesMatch(id); GaugeAdapter.DoubleFunctionGauge result = checkCast(GaugeAdapter.DoubleFunctionGauge.class, metadata, constructedMeters.computeIfAbsent(id, k -> new GaugeAdapter.DoubleFunctionGauge<>(obj, f))); - addNameToApplicationMap(id); + //LIBERTY CHANGE START + /* + * Check if metric is an Openliberty connection pool metric. + * Do not associate with application if true. + */ + if (!isLibertyVendorConnectionPoolMetricGauge(id.name())) { + addNameToApplicationMap(id); + } + //LIBERTY CHANGE END return result.register(metadata, id, registry, scope, resolveMPConfigGlobalTagsByServer()); } + //LIBERTY CHANGE START + /* + * Checks if the metric being registered matches one of the connection pool vendor metrics provided by Liberty. + */ + private boolean isLibertyVendorConnectionPoolMetricCounter(String metricName) { + if (metricName.equalsIgnoreCase("connectionpool.create.total") || + metricName.equalsIgnoreCase("connectionpool.destroy.total") || + metricName.equalsIgnoreCase("connectionpool.queuedRequests.total") || + metricName.equalsIgnoreCase("connectionpool.usedConnections.total")) { + return true; + } + return false; + } + + /* + * Checks if the metric being registered matches one of the connection pool vendor metrics provided by Liberty. + */ + private boolean isLibertyVendorConnectionPoolMetricGauge(String metricName) { + if (metricName.equalsIgnoreCase("connectionpool.managedConnections") || + metricName.equalsIgnoreCase("connectionpool.connectionHandles") || + metricName.equalsIgnoreCase("connectionpool.freeConnections") || + metricName.equalsIgnoreCase("connectionpool.waitTime.total") || + metricName.equalsIgnoreCase("connectionpool.inUseTime.total")) { + return true; + } + return false; + } + //LIBERTY CHANGE END + @SuppressWarnings("unchecked") GaugeAdapter internalGauge(MpMetadata metadata, MetricDescriptor id, T obj, Function f) { validateTagNamesMatch(id); GaugeAdapter.FunctionGauge result = checkCast(GaugeAdapter.FunctionGauge.class, metadata, constructedMeters.computeIfAbsent(id, k -> new GaugeAdapter.FunctionGauge<>(obj, f))); - addNameToApplicationMap(id); + //LIBERTY CHANGE START + /* + * Check if metric is an Openliberty connection pool metric. + * Do not associate with application if true. + */ + if (!isLibertyVendorConnectionPoolMetricGauge(id.name())) { + addNameToApplicationMap(id); + } + //LIBERTY CHANGE END return result.register(metadata, id, registry, scope, resolveMPConfigGlobalTagsByServer()); } @@ -656,7 +718,15 @@ GaugeAdapter internalGauge(MpMetadata metadata, MetricDesc validateTagNamesMatch(id); GaugeAdapter result = checkCast(GaugeAdapter.NumberSupplierGauge.class, metadata, constructedMeters.computeIfAbsent(id, k -> new GaugeAdapter.NumberSupplierGauge(f))); - addNameToApplicationMap(id); + //LIBERTY CHANGE START + /* + * Check if metric is an Openliberty connection pool metric. + * Do not associate with application if true. + */ + if (!isLibertyVendorConnectionPoolMetricGauge(id.name())) { + addNameToApplicationMap(id); + } + //LIBERTY CHANGE END return result.register(metadata, id, registry, scope, resolveMPConfigGlobalTagsByServer()); } From 580cff401fe9845e5a5ec6a2b52b8ad4237c4ec8 Mon Sep 17 00:00:00 2001 From: David Chan Date: Wed, 11 Dec 2024 14:25:49 -0500 Subject: [PATCH 2/2] Update FATS --- .../TestEnableDisableFeaturesTest.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/dev/io.openliberty.microprofile.metrics.internal.5.x.monitor_fat/fat/src/io/openliberty/microprofile/metrics/internal/monitor_fat/TestEnableDisableFeaturesTest.java b/dev/io.openliberty.microprofile.metrics.internal.5.x.monitor_fat/fat/src/io/openliberty/microprofile/metrics/internal/monitor_fat/TestEnableDisableFeaturesTest.java index 86c9ebd0e9b..5193753c8fb 100644 --- a/dev/io.openliberty.microprofile.metrics.internal.5.x.monitor_fat/fat/src/io/openliberty/microprofile/metrics/internal/monitor_fat/TestEnableDisableFeaturesTest.java +++ b/dev/io.openliberty.microprofile.metrics.internal.5.x.monitor_fat/fat/src/io/openliberty/microprofile/metrics/internal/monitor_fat/TestEnableDisableFeaturesTest.java @@ -253,6 +253,35 @@ public void testEDF4() throws Exception { "connectionpool_queuedRequests_total{datasource=\"jdbc_exampleDS2\",mp_scope=\"vendor\",}", "connectionpool_usedConnections_total{datasource=\"jdbc_exampleDS2\",mp_scope=\"vendor\",}" }, new String[] {}); + + currentServ.setMarkToEndOfLog(); + // FAT updated to check that connectionpool metric remains after unloading + // application. + boolean res = currentServ.removeDropinsApplications("testJDBCApp.war"); + Assert.assertTrue("TestJDBCApp.war was not removed", res); + + currentServ.waitForStringInLog(".*CWWKZ0009I: The application testJDBCApp has stopped successfully.*"); + Log.info(c, testName, "------- Removed JDBC application ------"); + checkStrings(getHttpsServlet("/metrics?scope=vendor", serverEDF4), + new String[] { "connectionpool_connectionHandles{datasource=\"jdbc_exampleDS1\",mp_scope=\"vendor\",}", + "connectionpool_freeConnections{datasource=\"jdbc_exampleDS1\",mp_scope=\"vendor\",}", + "connectionpool_destroy_total{datasource=\"jdbc_exampleDS1\",mp_scope=\"vendor\",}", + "connectionpool_create_total{datasource=\"jdbc_exampleDS1\",mp_scope=\"vendor\",}", + "connectionpool_managedConnections{datasource=\"jdbc_exampleDS1\",mp_scope=\"vendor\",}", + "connectionpool_waitTime_total_seconds{datasource=\"jdbc_exampleDS1\",mp_scope=\"vendor\",}", + "connectionpool_inUseTime_total_seconds{datasource=\"jdbc_exampleDS1\",mp_scope=\"vendor\",}", + "connectionpool_queuedRequests_total{datasource=\"jdbc_exampleDS1\",mp_scope=\"vendor\",}", + "connectionpool_usedConnections_total{datasource=\"jdbc_exampleDS1\",mp_scope=\"vendor\",}", + "connectionpool_connectionHandles{datasource=\"jdbc_exampleDS2\",mp_scope=\"vendor\",}", + "connectionpool_freeConnections{datasource=\"jdbc_exampleDS2\",mp_scope=\"vendor\",}", + "connectionpool_destroy_total{datasource=\"jdbc_exampleDS2\",mp_scope=\"vendor\",}", + "connectionpool_create_total{datasource=\"jdbc_exampleDS2\",mp_scope=\"vendor\",}", + "connectionpool_managedConnections{datasource=\"jdbc_exampleDS2\",mp_scope=\"vendor\",}", + "connectionpool_waitTime_total_seconds{datasource=\"jdbc_exampleDS2\",mp_scope=\"vendor\",}", + "connectionpool_inUseTime_total_seconds{datasource=\"jdbc_exampleDS2\",mp_scope=\"vendor\",}", + "connectionpool_queuedRequests_total{datasource=\"jdbc_exampleDS2\",mp_scope=\"vendor\",}", + "connectionpool_usedConnections_total{datasource=\"jdbc_exampleDS2\",mp_scope=\"vendor\",}" }, + new String[] {}); } @Test