Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not associate vendor connection pool metrics with an application for mpMetrics-5.x #30398

Open
wants to merge 2 commits into
base: integration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down Expand Up @@ -539,7 +548,15 @@ <T> FunctionCounterAdapter<T> internalCounter(MpMetadata metadata, T obj, ToDoub

FunctionCounterAdapter<T> 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());
}

Expand Down Expand Up @@ -599,16 +616,61 @@ <T> GaugeAdapter<Double> internalGauge(MpMetadata metadata, MetricDescriptor id,
validateTagNamesMatch(id);
GaugeAdapter.DoubleFunctionGauge<T> 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")
<T, R extends Number> GaugeAdapter<R> internalGauge(MpMetadata metadata, MetricDescriptor id, T obj, Function<T, R> f) {
validateTagNamesMatch(id);
GaugeAdapter.FunctionGauge<T, R> 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());
}

Expand Down Expand Up @@ -656,7 +718,15 @@ <T extends Number> GaugeAdapter<T> internalGauge(MpMetadata metadata, MetricDesc
validateTagNamesMatch(id);
GaugeAdapter<T> result = checkCast(GaugeAdapter.NumberSupplierGauge.class, metadata,
constructedMeters.computeIfAbsent(id, k -> new GaugeAdapter.NumberSupplierGauge<T>(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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down