Skip to content

Commit 23794bc

Browse files
authored
Merge pull request #29159 from Channyboy/23337-LibertyMetricsToMpTel-connPool2
Bridge sessions, threadpool, request timing and connection pool metrics to MP Telemetry + minimum FATS
2 parents 494ec70 + 16a779a commit 23794bc

File tree

54 files changed

+2567
-35
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2567
-35
lines changed

dev/com.ibm.websphere.appserver.features/visibility/public/mpTelemetry-2.0/io.openliberty.mpTelemetry-2.0.feature

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@ IBM-API-Package: \
3838
io.opentelemetry.exporter.otlp.logs;type="third-party",\
3939
io.opentelemetry.exporter.otlp;type="third-party"
4040
-features=\
41-
io.openliberty.mpTelemetry2.0.ee-10.0; ibm.tolerates:= "11.0, 9.0, 8.0, 7.0"
41+
io.openliberty.mpTelemetry2.0.ee-10.0; ibm.tolerates:= "11.0, 9.0, 8.0, 7.0",\
42+
com.ibm.websphere.appserver.monitor-1.0
4243
-bundles=\
4344
io.openliberty.com.squareup.okhttp,\
4445
io.openliberty.com.squareup.okio-jvm,\
4546
io.openliberty.org.jetbrains.kotlin,\
4647
io.openliberty.org.jetbrains.annotation,\
47-
io.openliberty.io.zipkin.zipkin2.2.0
48+
io.openliberty.io.zipkin.zipkin2.2.0,\
49+
io.openliberty.microprofile.telemetry.monitor.internal
4850
-jars=io.openliberty.mpTelemetry.2.0.thirdparty; location:="dev/api/third-party/,lib/"
4951
kind=beta
5052
edition=core

dev/com.ibm.ws.connectionpool.monitor/bnd.bnd

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#*******************************************************************************
2-
# Copyright (c) 2017, 2023 IBM Corporation and others.
2+
# Copyright (c) 2017, 2024 IBM Corporation and others.
33
# All rights reserved. This program and the accompanying materials
44
# are made available under the terms of the Eclipse Public License 2.0
55
# which accompanies this distribution, and is available at
@@ -20,9 +20,11 @@ Bundle-Description: ConnectionPool Management; version=${bVersion}
2020

2121

2222
Export-Package: \
23-
com.ibm.websphere.connectionpool.monitor
23+
com.ibm.websphere.connectionpool.monitor,\
24+
com.ibm.ws.connectionpool.monitor.metrics
2425

2526
Import-Package: \
27+
com.ibm.ws.connectionpool.monitor.metrics,\
2628
!*.internal.*,*
2729

2830
Private-Package: \
@@ -31,6 +33,8 @@ Private-Package: \
3133
Include-Resource: \
3234
com/ibm/ws/connectionpool/monitor/xml/j2cModule.xml=resources/com/ibm/ws/connectionpool/monitor/xml/j2cModule.xml
3335

36+
-dsannotations: \
37+
com.ibm.ws.connectionpool.monitor.metrics.MetricsManager
3438

3539
DynamicImport-Package: com.ibm.websphere.monitor.meters;version="1.0.0", \
3640
com.ibm.websphere.monitor.annotation;version="1.0.0", \
@@ -49,4 +53,8 @@ instrument.disabled: true
4953
com.ibm.ws.monitor;version=latest,\
5054
com.ibm.ws.logging.core;version=latest,\
5155
com.ibm.ws.jca.cm;version=latest,\
52-
com.ibm.ws.org.osgi.annotation.versioning;version=latest
56+
com.ibm.ws.org.osgi.annotation.versioning;version=latest,\
57+
com.ibm.wsspi.org.osgi.service.component.annotations;version=latest,\
58+
com.ibm.wsspi.org.osgi.service.event;version=latest,\
59+
com.ibm.ws.container.service.compat;version=latest,\
60+
com.ibm.ws.kernel.boot.core;version=latest

dev/com.ibm.ws.connectionpool.monitor/src/com/ibm/ws/connectionpool/monitor/ConnectionPoolMonitor.java

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
* are made available under the terms of the Eclipse Public License 2.0
55
* which accompanies this distribution, and is available at
66
* http://www.eclipse.org/legal/epl-2.0/
7-
*
7+
*
88
* SPDX-License-Identifier: EPL-2.0
99
*
1010
* Contributors:
1111
* IBM Corporation - initial API and implementation
1212
*******************************************************************************/
1313
package com.ibm.ws.connectionpool.monitor;
1414

15+
import java.time.Duration;
1516
import java.util.HashMap;
1617

1718
import com.ibm.websphere.jca.pmi.JCAPMIHelper;
@@ -25,6 +26,7 @@
2526
import com.ibm.websphere.monitor.meters.MeterCollection;
2627
import com.ibm.websphere.ras.Tr;
2728
import com.ibm.websphere.ras.TraceComponent;
29+
import com.ibm.ws.connectionpool.monitor.metrics.MetricsManager;
2830
import com.ibm.ws.ffdc.FFDCFilter;
2931
import com.ibm.wsspi.pmi.factory.StatisticActions;
3032
import com.ibm.wsspi.pmi.factory.StatsFactory;
@@ -98,11 +100,11 @@ public synchronized ConnectionPoolStats initializeConnectionPoolStats(String dsN
98100

99101
/**
100102
* @param FreePool Object
101-
* This method is responsible for calculating createCount(incremented) = number of connections created and ManagedConnectionCount(incremented) = number of
102-
* connections in use
103-
* This is called when control successfully returns from FreePool createManagedConnectionWithMCWrapper which is an indication that connection is
104-
* successfully created or is being used.
105-
* HookPoints=FreePool.createManagedConnectionWithMCWrapper
103+
* This method is responsible for calculating createCount(incremented) = number of connections created and ManagedConnectionCount(incremented) = number of
104+
* connections in use
105+
* This is called when control successfully returns from FreePool createManagedConnectionWithMCWrapper which is an indication that connection is
106+
* successfully created or is being used.
107+
* HookPoints=FreePool.createManagedConnectionWithMCWrapper
106108
*/
107109
@ProbeAtReturn
108110
@ProbeSite(clazz = "com.ibm.ejs.j2c.FreePool", method = "createManagedConnectionWithMCWrapper")
@@ -146,8 +148,8 @@ public void incCreateCount(@This Object fpObject) {
146148

147149
/**
148150
* @param MCWrapper Object
149-
* This code is responsible for calculating Destroy Count(incremented)=Number of connections destroyed or released and ManagedConnections(Decremented).
150-
* HookPoints=MCWrapper.destroy.
151+
* This code is responsible for calculating Destroy Count(incremented)=Number of connections destroyed or released and ManagedConnections(Decremented).
152+
* HookPoints=MCWrapper.destroy.
151153
*/
152154
@ProbeAtReturn
153155
@ProbeAtExceptionExit
@@ -197,8 +199,8 @@ public void incDestroyCount(@This Object ob) {
197199

198200
/**
199201
* @param MCWrapper Object
200-
* This method is responsible for calculating connectionHandleCount(increment)
201-
* HookPoints=MCWrapper.incrementHandleCount
202+
* This method is responsible for calculating connectionHandleCount(increment)
203+
* HookPoints=MCWrapper.incrementHandleCount
202204
*/
203205
@ProbeAtReturn
204206
@ProbeSite(clazz = "com.ibm.ejs.j2c.MCWrapper", method = "incrementHandleCount")
@@ -242,8 +244,8 @@ public void incConnectionHandleCount(@This Object ob) {
242244

243245
/**
244246
* @param MCWrapper Object
245-
* This method is responsible for calculating connectionHandleCount(decrement)
246-
* HookPoints:MCWrapper.decrementHandleCount
247+
* This method is responsible for calculating connectionHandleCount(decrement)
248+
* HookPoints:MCWrapper.decrementHandleCount
247249
*/
248250
@ProbeAtReturn
249251
@ProbeSite(clazz = "com.ibm.ejs.j2c.MCWrapper", method = "decrementHandleCount")
@@ -304,7 +306,7 @@ public void waitTimeEntry() {
304306

305307
/**
306308
* @param wtobj
307-
* Code which gets value from ThreadLocal and calculates the time spent in queueRequest which will give the wait time.
309+
* Code which gets value from ThreadLocal and calculates the time spent in queueRequest which will give the wait time.
308310
*/
309311
@ProbeAtReturn
310312
@ProbeAtExceptionExit
@@ -337,6 +339,10 @@ public void waitTimeExit(@This Object wtobj) {
337339
}
338340
//cStats = connectionPoolCountByName.get(JNDIName);
339341
cStats.updateWaitTime(elapsed);
342+
MetricsManager metricsManager = MetricsManager.getInstance();
343+
if (metricsManager != null) {
344+
metricsManager.updateWaitTimeMetrics(JNDIName, Duration.ofMillis(elapsed));
345+
}
340346

341347
if (tc.isEntryEnabled()) {
342348
Tr.exit(tc, "waitTimeExit");
@@ -345,9 +351,9 @@ public void waitTimeExit(@This Object wtobj) {
345351

346352
/**
347353
* @param MCWrapper Object
348-
* This particular Method is called when when a connection going through cleanup was not already in the Free Active
349-
* state. This means the free pool connection count should be incremented. The connection is either going to be
350-
* added to the free pool, or will be destroyed (and the free pool count will be decremented in destroy).
354+
* This particular Method is called when when a connection going through cleanup was not already in the Free Active
355+
* state. This means the free pool connection count should be incremented. The connection is either going to be
356+
* added to the free pool, or will be destroyed (and the free pool count will be decremented in destroy).
351357
*/
352358
@ProbeAtEntry
353359
@ProbeSite(clazz = "com.ibm.ejs.j2c.MCWrapper", method = "isNotAlreadyFreeActive")
@@ -388,6 +394,10 @@ public void incFreePoolSize(@This Object ob) {
388394
if (iuTime != null) {
389395
long elapsed = (System.currentTimeMillis() - tlocalforiuTime.get());
390396
cStats.updateInUseTime(elapsed);
397+
MetricsManager metricsManager = MetricsManager.getInstance();
398+
if (metricsManager != null) {
399+
metricsManager.updateInUseTimeMetrics(JNDIName, Duration.ofMillis(elapsed));
400+
}
391401
if (tlocalforiumconThread.get() < 2) {
392402
tlocalforiuTime.set(null);
393403
} else {
@@ -408,7 +418,7 @@ public void incFreePoolSize(@This Object ob) {
408418

409419
/**
410420
* @param MCWrapper
411-
* This method is called when Connection is being marked "as in use" which means that thread is being pulled from
421+
* This method is called when Connection is being marked "as in use" which means that thread is being pulled from
412422
*/
413423
@ProbeAtReturn
414424
@ProbeSite(clazz = "com.ibm.ejs.j2c.MCWrapper", method = "markInUse")
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 IBM Corporation and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License 2.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*******************************************************************************/
10+
package com.ibm.ws.connectionpool.monitor.metrics;
11+
12+
import java.time.Duration;
13+
14+
/**
15+
* Intended to be a service-component.
16+
* Implemented by subsequent Metric run-times in their respective bundles.
17+
*/
18+
public interface ConnectionPoolMetricAdapter {
19+
20+
/**
21+
* Given the Connection pool's (JNDI) name , update the Connection pool wait time metric of the respective Metrics runtime
22+
*
23+
* @param poolName
24+
* @param duration
25+
* @param appName This value can be `null` to indicate that we're updating metrics relating to the server. Not all Implementations may need the appname value.
26+
*/
27+
public void updateWaitTimeMetrics(String poolName, Duration duration);
28+
29+
/**
30+
* Given the Connection pool's (JNDI) name , update the Connection pool in use time metric of the respective Metrics runtime
31+
*
32+
* @param poolName
33+
* @param duration
34+
* @param appName This value can be `null` to indicate that we're updating metrics relating to the server. Not all Implementations may need the appname value.
35+
*/
36+
public void updateInUseTimeMetrics(String poolName, Duration duration);
37+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 IBM Corporation and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License 2.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*******************************************************************************/
10+
package com.ibm.ws.connectionpool.monitor.metrics;
11+
12+
import static org.osgi.service.component.annotations.ConfigurationPolicy.IGNORE;
13+
14+
import java.time.Duration;
15+
import java.util.List;
16+
17+
import org.osgi.service.component.annotations.Activate;
18+
import org.osgi.service.component.annotations.Component;
19+
import org.osgi.service.component.annotations.Deactivate;
20+
import org.osgi.service.component.annotations.Reference;
21+
import org.osgi.service.component.annotations.ReferenceCardinality;
22+
import org.osgi.service.component.annotations.ReferencePolicy;
23+
import org.osgi.service.component.annotations.ReferencePolicyOption;
24+
25+
import com.ibm.websphere.ras.Tr;
26+
import com.ibm.websphere.ras.TraceComponent;
27+
import com.ibm.ws.kernel.productinfo.ProductInfo;
28+
29+
@Component(configurationPolicy = IGNORE, immediate = true)
30+
public class MetricsManager {
31+
32+
private static MetricsManager instance;
33+
34+
private static final TraceComponent tc = Tr.register(MetricsManager.class);
35+
36+
@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC, policyOption = ReferencePolicyOption.GREEDY)
37+
private volatile List<ConnectionPoolMetricAdapter> metricRuntimes;
38+
39+
@Activate
40+
public void activate() {
41+
instance = this;
42+
}
43+
44+
@Deactivate
45+
public void deactivate() {
46+
47+
instance = null;
48+
}
49+
50+
public static MetricsManager getInstance() {
51+
52+
//beta - return no instance
53+
if (!ProductInfo.getBetaEdition()) {
54+
return null;
55+
}
56+
57+
if (instance != null) {
58+
return instance;
59+
}
60+
61+
if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
62+
Tr.debug(tc, "No MetricsManager Instance available ");
63+
}
64+
return null;
65+
}
66+
67+
/**
68+
*
69+
* @param poolName JNDI name of the pool (i.e., data source)
70+
* @param duration recorded Duration of the wait time
71+
*/
72+
public void updateWaitTimeMetrics(String poolName, Duration duration) {
73+
//just in case
74+
if (!ProductInfo.getBetaEdition()) {
75+
return;
76+
}
77+
metricRuntimes.stream().forEach(adapters -> adapters.updateWaitTimeMetrics(poolName, duration));
78+
79+
}
80+
81+
/**
82+
*
83+
* @param poolName JNDI name of the pool (i.e., data source)
84+
* @param Duration recorded Duration of the (in) use time.
85+
*/
86+
public void updateInUseTimeMetrics(String poolName, Duration duration) {
87+
//just in case
88+
if (!ProductInfo.getBetaEdition()) {
89+
return;
90+
}
91+
metricRuntimes.stream().forEach(adapters -> adapters.updateInUseTimeMetrics(poolName, duration));
92+
}
93+
94+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 IBM Corporation and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License 2.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*******************************************************************************/
10+
@org.osgi.annotation.versioning.Version("1.0")
11+
package com.ibm.ws.connectionpool.monitor.metrics;

dev/com.ibm.ws.kernel.feature.resolver_fat/publish/verify/singleton_expected.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13865,6 +13865,12 @@
1386513865
<resolved>io.openliberty.mpJwtPropagation-2.1</resolved>
1386613866
<resolved>io.openliberty.cdi3.0-transaction2.0</resolved>
1386713867
<resolved>io.openliberty.cdi3.0-appSecurity</resolved>
13868+
<resolved-feature>io.openliberty.servlet5.0-monitor1.0</resolved-feature>
13869+
<resolved-feature>com.ibm.websphere.appserver.distributedMapPMI-1.0</resolved-feature>
13870+
<resolved-feature>io.openliberty.restfulWS3.0-monitor1.0</resolved-feature>
13871+
<resolved-feature>io.openliberty.httpStat-monitor1.0.jakarta</resolved-feature>
13872+
<resolved-feature>monitor-1.0</resolved-feature>
13873+
<resolved-feature>com.ibm.websphere.appserver.sessionMonitor-1.0</resolved-feature>
1386813874
</output>
1386913875
</case>
1387013876
<case>
@@ -15587,6 +15593,11 @@
1558715593
<resolved>io.openliberty.cdi3.0-jndi1.0</resolved>
1558815594
<resolved>io.openliberty.cdi4.0-servlet6.0</resolved>
1558915595
<resolved>io.openliberty.cdi3.0-transaction2.0</resolved>
15596+
<resolved-feature>io.openliberty.servlet5.0-monitor1.0</resolved-feature>
15597+
<resolved-feature>io.openliberty.restfulWS3.0-monitor1.0</resolved-feature>
15598+
<resolved-feature>io.openliberty.httpStat-monitor1.0.jakarta</resolved-feature>
15599+
<resolved-feature>monitor-1.0</resolved-feature>
15600+
<resolved-feature>com.ibm.websphere.appserver.sessionMonitor-1.0</resolved-feature>
1559015601
</output>
1559115602
</case>
1559215603
<case>

dev/com.ibm.ws.kernel.feature.resolver_fat/publish/verify/singleton_expected_WL.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,11 @@
215215
<resolved-feature>io.openliberty.cdi3.0-jndi1.0</resolved-feature>
216216
<resolved-feature>io.openliberty.cdi4.0-servlet6.0</resolved-feature>
217217
<resolved-feature>io.openliberty.cdi3.0-transaction2.0</resolved-feature>
218+
<resolved-feature>io.openliberty.servlet5.0-monitor1.0</resolved-feature>
219+
<resolved-feature>io.openliberty.restfulWS3.0-monitor1.0</resolved-feature>
220+
<resolved-feature>io.openliberty.httpStat-monitor1.0.jakarta</resolved-feature>
221+
<resolved-feature>monitor-1.0</resolved-feature>
222+
<resolved-feature>com.ibm.websphere.appserver.sessionMonitor-1.0</resolved-feature>
218223
</output>
219224
</case>
220225
<case>
@@ -7292,6 +7297,12 @@
72927297
<resolved-feature>io.openliberty.mpJwtPropagation-2.1</resolved-feature>
72937298
<resolved-feature>io.openliberty.cdi3.0-transaction2.0</resolved-feature>
72947299
<resolved-feature>io.openliberty.cdi3.0-appSecurity</resolved-feature>
7300+
<resolved-feature>io.openliberty.servlet5.0-monitor1.0</resolved-feature>
7301+
<resolved-feature>com.ibm.websphere.appserver.distributedMapPMI-1.0</resolved-feature>
7302+
<resolved-feature>io.openliberty.restfulWS3.0-monitor1.0</resolved-feature>
7303+
<resolved-feature>io.openliberty.httpStat-monitor1.0.jakarta</resolved-feature>
7304+
<resolved-feature>monitor-1.0</resolved-feature>
7305+
<resolved-feature>com.ibm.websphere.appserver.sessionMonitor-1.0</resolved-feature>
72957306
</output>
72967307
</case>
72977308
<case>

0 commit comments

Comments
 (0)