Skip to content

Commit cf6b82a

Browse files
committed
Added static Events and tests
1 parent 6db2af2 commit cf6b82a

14 files changed

+1228
-47
lines changed

.github/workflows/run-tests.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ jobs:
119119
JACKSON_OSON_PASSWORD=${{ secrets.TEST_JACKSON_OSON_PASSWORD }}\n
120120
" >> ojdbc-provider-jackson-oson/test.properties
121121
122+
# Generate ojdbc-provider-observability/test.properties
123+
echo -e "OBSERVABILITY_URL=${{ secrets.TEST_JACKSON_OSON_URL }}\n
124+
OBSERVABILITY_USERNAME=${{ secrets.TEST_JACKSON_OSON_USERNAME }}\n
125+
OBSERVABILITY_PASSWORD=${{ secrets.TEST_JACKSON_OSON_PASSWORD }}\n
126+
" >> ojdbc-provider-observability/test.properties
127+
122128
- name: Run tests with Maven
123129
run: mvn -B test --file pom.xml
124130

@@ -133,3 +139,4 @@ jobs:
133139
rm ojdbc-provider-azure/test.properties
134140
135141
rm ojdbc-provider-jackson-oson/test.properties
142+
rm ojdbc-provider-observability/test.properties
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
################################################################################
2+
# Copyright (c) 2024 Oracle and/or its affiliates.
3+
#
4+
# The Universal Permissive License (UPL), Version 1.0
5+
#
6+
# Subject to the condition set forth below, permission is hereby granted to any
7+
# person obtaining a copy of this software, associated documentation and/or data
8+
# (collectively the "Software"), free of charge and under any and all copyright
9+
# rights in the Software, and any and all patent rights owned or freely
10+
# licensable by each licensor hereunder covering either (i) the unmodified
11+
# Software as contributed to or provided by such licensor, or (ii) the Larger
12+
# Works (as defined below), to deal in both
13+
#
14+
# (a) the Software, and
15+
# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
16+
# one is included with the Software (each a "Larger Work" to which the Software
17+
# is contributed by such licensors),
18+
#
19+
# without restriction, including without limitation the rights to copy, create
20+
# derivative works of, display, perform, and distribute the Software and make,
21+
# use, sell, offer for sale, import, export, have made, and have sold the
22+
# Software and the Larger Work(s), and to sublicense the foregoing rights on
23+
# either these or other terms.
24+
#
25+
# This license is subject to the following condition:
26+
# The above copyright notice and either this complete permission notice or at
27+
# a minimum a reference to the UPL must be included in all copies or
28+
# substantial portions of the Software.
29+
#
30+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
35+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36+
# SOFTWARE.
37+
################################################################################
38+
39+
# This file provides examples of properties that configure tests in this
40+
# module.
41+
#
42+
# QUICK GUIDE TO RUNNING TESTS:
43+
# 1. Create a copy of this file named "test.properties":
44+
# cp example-test.properties test.properties
45+
# 2. In test.properties, replace example values with real values (the file is
46+
# .gitignore'd, so sensitive info won't be checked in to the repo)
47+
# 3. Comment out any lines for which a value can not be provided (tests are
48+
# skipped if no value is configured).
49+
# 4. mvn clean verify
50+
#
51+
# CONFIGURING TEST PROPERTIES
52+
# Test properties are read from a properties file by the TestProperties class.
53+
# The TestProperties class can be found in:
54+
# ojdbc-provider-common/src/testFixtures/java/oracle/jdbc/provider/TestProperties.java
55+
# The default behavior of TestProperties is to read a file named
56+
# "test.properties" in the current directory. A non-default location may be
57+
# specified as a JVM system property:
58+
# mvn clean verify -Doracle.jdbc.provider.TestProperties=/path/to/my-test.properties
59+
#
60+
# MAINTAINING THIS FILE
61+
# Project maintainers should add an example to this file anytime they write a
62+
# test which requires a new property. Not doing so will inflict pain and
63+
# suffering upon our fellow programmers, and will also lead to increased
64+
# maintenance costs.
65+
#
66+
# IGNORING UNCONFIGURED PROPERTIES
67+
# No test should cause a build failure due to an unconfigured property.
68+
# Using JUnit terminology: A test should "abort" rather than "fail" when a
69+
# property is not configured. This means that the test does not pass, but it
70+
# does not cause the build to fail either.
71+
# Methods of the TestProperties class will automatically abort a test if a
72+
# property is not configured. The org.junit.jupiter.api.Assumptions class may
73+
# also be used directly to abort a test.
74+
# There is NO environment in which ALL tests can be run. Some tests may
75+
# require authentication as a managed identity in an Azure VM, while other
76+
# tests require authentication as an instance principal in an OCI compute
77+
# instance; These environments are mutually exclusive. This is one reason why
78+
# tests can not fail the build if a required property is not set.
79+
# A more practical reason is that developers may not need to run all tests if
80+
# their changes are isolated to single module. For instance, a developer
81+
# working on an OCI provider should not need to set up an Azure tenancy to test
82+
# their changes.
83+
84+
OBSERVABILITY_URL=<url>
85+
OBSERVABILITY_USERNAME=<username>
86+
OBSERVABILITY_PASSWORD=<password>

ojdbc-provider-observability/pom.xml

+12
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@
3939
<artifactId>junit-jupiter-engine</artifactId>
4040
<scope>test</scope>
4141
</dependency>
42+
<dependency>
43+
<groupId>org.junit.jupiter</groupId>
44+
<artifactId>junit-jupiter-params</artifactId>
45+
<scope>test</scope>
46+
</dependency>
47+
<dependency>
48+
<artifactId>ojdbc-provider-common</artifactId>
49+
<groupId>com.oracle.database.jdbc</groupId>
50+
<version>1.0.2</version>
51+
<classifier>tests</classifier>
52+
<type>test-jar</type>
53+
</dependency>
4254
</dependencies>
4355

4456
</project>

ojdbc-provider-observability/src/main/java/oracle/jdbc/provider/observability/ObservabilityTraceEventListener.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public ObservabilityTracer getTracer() {
3030
public Object roundTrip(Sequence sequence, TraceContext traceContext, Object userContext) {
3131
EnumMap<Tracers, Object> currentUserContext = getCurrentUserContext(userContext);
3232
for (Tracers tracer : ObservabilityConfiguration.getInstance().getEnabledTracersSet()) {
33-
Object newUserContext = tracer.getTracer().traceRoudtrip(sequence, traceContext, currentUserContext.get(tracer));
33+
Object newUserContext = tracer.getTracer().traceRoundtrip(sequence, traceContext, currentUserContext.get(tracer));
3434
currentUserContext.put(tracer, newUserContext);
3535
}
3636
return currentUserContext;

ojdbc-provider-observability/src/main/java/oracle/jdbc/provider/observability/ObservabilityTraceEventListenerProvider.java

+5-14
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
import javax.management.ReflectionException;
1818

1919
import oracle.jdbc.TraceEventListener;
20+
import oracle.jdbc.provider.observability.configuration.ObservabilityConfiguration;
2021
import oracle.jdbc.spi.TraceEventListenerProvider;
2122

2223
public class ObservabilityTraceEventListenerProvider implements TraceEventListenerProvider {
2324

2425
private static final String PROVIDER_NAME = "observability-trace-event-listener-provider";
25-
private static final String MBEAN_OBJECT_NAME = "com.oracle.jdbc.extension.opentelemetry:type=ObservabilityTraceEventListener";
26+
private static final String MBEAN_OBJECT_NAME = "com.oracle.jdbc.extension.observability:type=ObservabilityConfiguration";
2627

2728
private static final MBeanServer server = ManagementFactory.getPlatformMBeanServer();;
2829
private static ObjectName objectName;
@@ -39,23 +40,13 @@ public class ObservabilityTraceEventListenerProvider implements TraceEventListen
3940

4041
@Override
4142
public TraceEventListener getTraceEventListener(Map<Parameter, CharSequence> map) {
42-
ObservabilityTraceEventListener observabilityBean;
4343
try {
44-
if (objectName != null && server.isRegistered(objectName)) {
45-
observabilityBean = (ObservabilityTraceEventListener) server
46-
.instantiate(ObservabilityTraceEventListener.class.getName());
47-
return observabilityBean;
48-
}
49-
} catch (ReflectionException | MBeanException e) {
50-
logger.log(Level.WARNING, "Could not retrieve MBean from server", e);
51-
}
52-
observabilityBean = new ObservabilityTraceEventListener();
53-
try {
54-
server.registerMBean(observabilityBean, objectName);
44+
if (!server.isRegistered(objectName))
45+
server.registerMBean(ObservabilityConfiguration.getInstance(), objectName);
5546
} catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e) {
5647
logger.log(Level.WARNING, "Could not register MBean", e);
5748
}
58-
return observabilityBean;
49+
return new ObservabilityTraceEventListener();
5950
}
6051

6152
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package oracle.jdbc.provider.observability;
2+
3+
import java.util.Collection;
4+
import java.util.Collections;
5+
6+
public class OpenTelemetryTraceEventListenerProvider extends ObservabilityTraceEventListenerProvider {
7+
8+
private static final String PROVIDER_NAME = "open-telemetry-trace-event-listener-provider";
9+
10+
@Override
11+
public String getName() {
12+
return PROVIDER_NAME;
13+
}
14+
15+
@Override
16+
public Collection<? extends Parameter> getParameters() {
17+
return Collections.emptyList();
18+
}
19+
20+
}

ojdbc-provider-observability/src/main/java/oracle/jdbc/provider/observability/configuration/ObservabilityConfiguration.java

+15-4
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,22 @@
88

99
public class ObservabilityConfiguration implements ObservabilityConfigurationMBean {
1010

11-
private final ReentrantLock observabilityConfiguraitonLock = new ReentrantLock();
11+
private static final ReentrantLock observabilityConfiguraitonLock = new ReentrantLock();
1212

13-
private static final ObservabilityConfiguration INSTANCE = new ObservabilityConfiguration();
13+
private static final ObservabilityConfiguration INSTANCE;
14+
15+
static {
16+
INSTANCE = new ObservabilityConfiguration();
17+
//INSTANCE.setSensitiveDataEnabled(true);
18+
INSTANCE.setEnabledTracers(System.getProperty("oracle.jdbc.provider.observability.tracer", "OTEL,JFR"));
19+
}
1420

1521
private ObservabilityConfiguration() { }
1622

1723
private boolean sensitiveDataEnabled;
1824
private String tracers;
1925

20-
private EnumSet<ObservabilityTraceEventListener.Tracers> enabledTracers;
26+
private EnumSet<ObservabilityTraceEventListener.Tracers> enabledTracers = EnumSet.noneOf(ObservabilityTraceEventListener.Tracers.class);
2127

2228
@Override
2329
public String getEnabledTracers() {
@@ -32,6 +38,7 @@ public String getEnabledTracers() {
3238
@Override
3339
public void setEnabledTracers(String tracers) {
3440
try {
41+
observabilityConfiguraitonLock.lock();
3542
enabledTracers.clear();
3643
String[] items = tracers.split(",");
3744
for (String item : items) {
@@ -61,7 +68,11 @@ public static ObservabilityConfiguration getInstance() {
6168
}
6269

6370
public EnumSet<ObservabilityTraceEventListener.Tracers> getEnabledTracersSet() {
64-
return enabledTracers.clone();
71+
if (enabledTracers != null) {
72+
return enabledTracers.clone();
73+
} else {
74+
return null;
75+
}
6576
}
6677

6778
}

0 commit comments

Comments
 (0)