generated from oracle/template-repo
-
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
Open
elaaissaouiabdessamad
wants to merge
3
commits into
observability-provider
Choose a base branch
from
feature/ucp-monitoring-otel-jfr
base: observability-provider
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Global configuration | ||
elaaissaouiabdessamad marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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 | ||
55 changes: 55 additions & 0 deletions
55
...src/main/java/oracle/ucp/provider/observability/jfr/core/JFRUCPEventListenerProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
77 changes: 77 additions & 0 deletions
77
...-observability/src/main/java/oracle/ucp/provider/observability/jfr/core/UCPBaseEvent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
| } | ||
| } |
77 changes: 77 additions & 0 deletions
77
...servability/src/main/java/oracle/ucp/provider/observability/jfr/core/UCPEventFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
| } | ||
| } |
16 changes: 16 additions & 0 deletions
16
...java/oracle/ucp/provider/observability/jfr/events/connection/ConnectionBorrowedEvent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
16 changes: 16 additions & 0 deletions
16
...n/java/oracle/ucp/provider/observability/jfr/events/connection/ConnectionClosedEvent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
16 changes: 16 additions & 0 deletions
16
.../java/oracle/ucp/provider/observability/jfr/events/connection/ConnectionCreatedEvent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
16 changes: 16 additions & 0 deletions
16
...java/oracle/ucp/provider/observability/jfr/events/connection/ConnectionReturnedEvent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
...rc/main/java/oracle/ucp/provider/observability/jfr/events/lifecycle/PoolCreatedEvent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.