-
Notifications
You must be signed in to change notification settings - Fork 8
implementing JFR and Open telemetry providers to monitor UCP #217
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
base: observability-provider
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,8 +22,11 @@ | |
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.oracle.database.jdbc</groupId> | ||
<artifactId>ojdbc11</artifactId> | ||
<groupId>com.oracle</groupId> | ||
<artifactId>ojdbc</artifactId> | ||
<version>11.2.0.4</version> <!-- Change to your version --> | ||
<scope>system</scope> | ||
<systemPath>/Users/abdessamadelaaissaoui/Desktop/ojdbc11.jar</systemPath> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.opentelemetry</groupId> | ||
|
@@ -51,16 +54,53 @@ | |
<classifier>tests</classifier> | ||
<type>test-jar</type> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.oracle</groupId> | ||
<artifactId>ucp</artifactId> | ||
<version>11.2.0.4</version> | ||
<scope>system</scope> | ||
<systemPath>/Users/abdessamadelaaissaoui/Desktop/ucp11.jar</systemPath> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
</dependency> | ||
<dependency> | ||
<groupId>com.oracle.database.security</groupId> | ||
<artifactId>oraclepki</artifactId> | ||
<version>23.3.0.23.09</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.oracle.database.ha</groupId> | ||
<artifactId>ons</artifactId> | ||
<version>23.9.0.25.07</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.opentelemetry</groupId> | ||
<artifactId>opentelemetry-api</artifactId> | ||
<version>1.32.0</version> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we using a different version here? |
||
</dependency> | ||
<dependency> | ||
<groupId>io.opentelemetry</groupId> | ||
<artifactId>opentelemetry-sdk</artifactId> | ||
<version>1.32.0</version> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this dependency needed? |
||
</dependency> | ||
<dependency> | ||
<groupId>io.opentelemetry</groupId> | ||
<artifactId>opentelemetry-exporter-prometheus</artifactId> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we have a dependency to a specific exporter? Shouldn't the library work with all exporters? |
||
<version>1.32.0-alpha</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.opentelemetry</groupId> | ||
<artifactId>opentelemetry-sdk-extension-autoconfigure</artifactId> | ||
<version>1.32.0</version> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<configuration> | ||
<!-- | ||
<!-- | ||
ObservabilityConfigurationTest must run first and alone since it depends on | ||
ObservabilityConfiguration being started with system properties set on the | ||
ObservabilityConfiguration being started with system properties set on the | ||
test. | ||
Running tests alphabetical and single threaded ensures that. | ||
--> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Global configuration | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this configuration necessary? |
||
global: | ||
scrape_interval: 15s # Scrape targets every 15 seconds | ||
evaluation_interval: 15s # Evaluate rules every 15 seconds | ||
|
||
# Scrape configuration | ||
scrape_configs: | ||
# Job to scrape your UCP application | ||
- job_name: 'ucp-application' | ||
static_configs: | ||
- targets: ['localhost:8080'] # Your app's metrics endpoint | ||
scrape_interval: 5s # Scrape every 5 seconds for testing | ||
metrics_path: '/metrics' # Path to metrics endpoint | ||
|
||
# Job to scrape Prometheus itself (optional) | ||
- job_name: 'prometheus' | ||
static_configs: | ||
- targets: ['localhost:9091'] # ✅ Changed from 9090 to 9091 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package oracle.ucp.provider.observability.jfr.core; | ||
|
||
import oracle.ucp.events.core.UCPEventContext; | ||
import oracle.ucp.events.core.UCPEventListener; | ||
import oracle.ucp.events.core.UCPEventListenerProvider; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Provider that supplies a UCP event listener for recording JFR events. | ||
* Integrates UCP events with Java Flight Recorder for low-overhead monitoring. | ||
*/ | ||
public final class JFRUCPEventListenerProvider implements UCPEventListenerProvider { | ||
|
||
private final UCPEventListener listener; | ||
|
||
/** | ||
* Singleton listener that records UCP events as JFR events. | ||
* Thread-safe and optimized for minimal overhead. | ||
*/ | ||
public static final UCPEventListener TRACE_EVENT_LISTENER = new UCPEventListener() { | ||
@Override | ||
public void onUCPEvent(EventType eventType, UCPEventContext context) { | ||
UCPEventFactory.recordEvent(eventType, context); | ||
} | ||
}; | ||
|
||
/** | ||
* Creates a new provider instance. | ||
*/ | ||
public JFRUCPEventListenerProvider() { | ||
this.listener = TRACE_EVENT_LISTENER; | ||
} | ||
|
||
/** | ||
* Returns the provider's unique identifier. | ||
* | ||
* @return "jfr-ucp-listener" | ||
*/ | ||
@Override | ||
public String getName() { | ||
return "jfr-ucp-listener"; | ||
} | ||
|
||
/** | ||
* Returns the JFR recording listener instance. | ||
* | ||
* @param config configuration map (ignored) | ||
* @return the JFR event listener | ||
*/ | ||
@Override | ||
public UCPEventListener getListener(Map<String, String> config) { | ||
return listener; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package oracle.ucp.provider.observability.jfr.core; | ||
|
||
import jdk.jfr.*; | ||
import oracle.ucp.events.core.UCPEventContext; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* Abstract base class for UCP JFR events providing common fields and initialization. | ||
* All UCP events extend this class to inherit standard pool metrics and metadata. | ||
*/ | ||
@Category("UCP Events") | ||
@Description("Base UCP Event") | ||
public abstract class UCPBaseEvent extends Event { | ||
|
||
/** Name of the connection pool */ | ||
@Label("Pool Name") | ||
protected String poolName; | ||
|
||
/** Event timestamp in milliseconds since epoch */ | ||
@Label("Timestamp") | ||
protected long timestamp; | ||
|
||
/** Maximum configured pool size */ | ||
@Label("Max Pool Size") | ||
protected int maxPoolSize; | ||
|
||
/** Minimum configured pool size */ | ||
@Label("Min Pool Size") | ||
protected int minPoolSize; | ||
|
||
/** Current count of borrowed connections */ | ||
@Label("Borrowed Connections") | ||
protected int borrowedConnections; | ||
|
||
/** Current count of available connections */ | ||
@Label("Available Connections") | ||
protected int availableConnections; | ||
|
||
/** Total active connections (borrowed + available) */ | ||
@Label("Total Connections") | ||
protected int totalConnections; | ||
|
||
/** Lifetime count of closed connections */ | ||
@Label("Closed Connections") | ||
protected int closedConnections; | ||
|
||
/** Lifetime count of created connections */ | ||
@Label("Created Connections") | ||
protected int createdConnections; | ||
|
||
/** Average connection wait time in milliseconds */ | ||
@Label("Average Wait Time (ms)") | ||
@Timespan(Timespan.MILLISECONDS) | ||
protected long avgWaitTime; | ||
|
||
/** | ||
* Initializes common fields from UCP event context. | ||
* | ||
* @param ctx event context containing pool metrics | ||
* @throws NullPointerException if ctx is null | ||
*/ | ||
protected void initCommonFields(UCPEventContext ctx) { | ||
Objects.requireNonNull(ctx, "UCPEventContext cannot be null"); | ||
|
||
this.poolName = ctx.poolName(); | ||
this.timestamp = ctx.timestamp(); | ||
this.maxPoolSize = ctx.maxPoolSize(); | ||
this.minPoolSize = ctx.minPoolSize(); | ||
this.borrowedConnections = ctx.borrowedConnectionsCount(); | ||
this.availableConnections = ctx.availableConnectionsCount(); | ||
this.totalConnections = ctx.totalConnections(); | ||
this.closedConnections = ctx.closedConnections(); | ||
this.createdConnections = ctx.createdConnections(); | ||
this.avgWaitTime = ctx.getAverageConnectionWaitTime(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package oracle.ucp.provider.observability.jfr.core; | ||
|
||
import jdk.jfr.Event; | ||
import oracle.ucp.events.core.UCPEventContext; | ||
import oracle.ucp.events.core.UCPEventListener; | ||
import oracle.ucp.provider.observability.jfr.events.connection.*; | ||
import oracle.ucp.provider.observability.jfr.events.lifecycle.*; | ||
import oracle.ucp.provider.observability.jfr.events.maintenance.*; | ||
|
||
/** | ||
* Factory for creating and recording JFR events from UCP operations. | ||
* Maps UCP event types to specific JFR event classes and handles recording. | ||
*/ | ||
public class UCPEventFactory { | ||
|
||
/** | ||
* Creates a JFR event instance for the specified UCP event type. | ||
* | ||
* @param type UCP event type | ||
* @param ctx event context with pool metrics | ||
* @return configured JFR event ready for recording | ||
* @throws IllegalStateException if event type is unrecognized | ||
* @throws NullPointerException if parameters are null | ||
*/ | ||
public static Event createEvent(UCPEventListener.EventType type, UCPEventContext ctx) { | ||
switch (type) { | ||
// Pool Lifecycle Events | ||
case POOL_CREATED: | ||
return new PoolCreatedEvent(ctx); | ||
case POOL_STARTING: | ||
return new PoolStartingEvent(ctx); | ||
case POOL_STARTED: | ||
return new PoolStartedEvent(ctx); | ||
case POOL_STOPPED: | ||
return new PoolStoppedEvent(ctx); | ||
case POOL_RESTARTING: | ||
return new PoolRestartingEvent(ctx); | ||
case POOL_RESTARTED: | ||
return new PoolRestartedEvent(ctx); | ||
case POOL_DESTROYED: | ||
return new PoolDestroyedEvent(ctx); | ||
|
||
// Connection Lifecycle Events | ||
case CONNECTION_CREATED: | ||
return new ConnectionCreatedEvent(ctx); | ||
case CONNECTION_BORROWED: | ||
return new ConnectionBorrowedEvent(ctx); | ||
case CONNECTION_RETURNED: | ||
return new ConnectionReturnedEvent(ctx); | ||
case CONNECTION_CLOSED: | ||
return new ConnectionClosedEvent(ctx); | ||
|
||
// Maintenance Operations | ||
case POOL_REFRESHED: | ||
return new PoolRefreshedEvent(ctx); | ||
case POOL_RECYCLED: | ||
return new PoolRecycledEvent(ctx); | ||
case POOL_PURGED: | ||
return new PoolPurgedEvent(ctx); | ||
|
||
default: | ||
throw new IllegalStateException("Unexpected event type: " + type); | ||
} | ||
} | ||
|
||
/** | ||
* Creates and immediately records a JFR event for the UCP operation. | ||
* | ||
* @param type UCP event type to record | ||
* @param ctx event context with pool metrics | ||
* @throws NullPointerException if parameters are null | ||
*/ | ||
public static void recordEvent(UCPEventListener.EventType type, UCPEventContext ctx) { | ||
Event event = createEvent(type, ctx); | ||
event.commit(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package oracle.ucp.provider.observability.jfr.events.connection; | ||
|
||
import oracle.ucp.provider.observability.jfr.core.UCPBaseEvent; | ||
import jdk.jfr.Category; | ||
import jdk.jfr.Label; | ||
import jdk.jfr.Name; | ||
import oracle.ucp.events.core.UCPEventContext; | ||
|
||
@Name("ucp.ConnectionBorrowed") | ||
@Label("Connection Borrowed") | ||
@Category({"UCP Events","Connection Lifecycle Events"}) | ||
public class ConnectionBorrowedEvent extends UCPBaseEvent { | ||
public ConnectionBorrowedEvent(UCPEventContext ctx) { | ||
initCommonFields(ctx); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package oracle.ucp.provider.observability.jfr.events.connection; | ||
|
||
import jdk.jfr.Category; | ||
import jdk.jfr.Label; | ||
import jdk.jfr.Name; | ||
import oracle.ucp.provider.observability.jfr.core.UCPBaseEvent; | ||
import oracle.ucp.events.core.UCPEventContext; | ||
|
||
@Name("ucp.ConnectionClosed") | ||
@Label("Connection Closed") | ||
@Category({"UCP Events","Connection Lifecycle Events"}) | ||
public class ConnectionClosedEvent extends UCPBaseEvent { | ||
public ConnectionClosedEvent(UCPEventContext ctx) { | ||
initCommonFields(ctx); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package oracle.ucp.provider.observability.jfr.events.connection; | ||
|
||
import oracle.ucp.provider.observability.jfr.core.UCPBaseEvent; | ||
import jdk.jfr.Category; | ||
import jdk.jfr.Label; | ||
import jdk.jfr.Name; | ||
import oracle.ucp.events.core.UCPEventContext; | ||
|
||
@Name("ucp.ConnectionCreated") | ||
@Label("Connection Created") | ||
@Category({"UCP Events","Connection Lifecycle Events"}) | ||
public class ConnectionCreatedEvent extends UCPBaseEvent { | ||
public ConnectionCreatedEvent(UCPEventContext ctx) { | ||
initCommonFields(ctx); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package oracle.ucp.provider.observability.jfr.events.connection; | ||
|
||
import oracle.ucp.provider.observability.jfr.core.UCPBaseEvent; | ||
import jdk.jfr.Category; | ||
import jdk.jfr.Label; | ||
import jdk.jfr.Name; | ||
import oracle.ucp.events.core.UCPEventContext; | ||
|
||
@Name("ucp.ConnectionReturned") | ||
@Label("Connection Returned") | ||
@Category({"UCP Events","Connection Lifecycle Events"}) | ||
public class ConnectionReturnedEvent extends UCPBaseEvent { | ||
public ConnectionReturnedEvent(UCPEventContext ctx) { | ||
initCommonFields(ctx); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package oracle.ucp.provider.observability.jfr.events.lifecycle; | ||
|
||
import oracle.ucp.provider.observability.jfr.core.UCPBaseEvent; | ||
import jdk.jfr.Category; | ||
import jdk.jfr.Description; | ||
import jdk.jfr.Label; | ||
import jdk.jfr.Name; | ||
import oracle.ucp.events.core.UCPEventContext; | ||
|
||
@Name("ucp.PoolCreated") | ||
@Label("Pool Created") | ||
@Category({"UCP Events","Pool Lifecycle Events"}) | ||
public class PoolCreatedEvent extends UCPBaseEvent { | ||
public PoolCreatedEvent(UCPEventContext ctx) { | ||
initCommonFields(ctx); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should avoid adding paths to your own environment.