Skip to content

Commit

Permalink
Add JFR Event for Command Latency #1820
Browse files Browse the repository at this point in the history
Original pull request: #1821.
  • Loading branch information
HashJang authored and mp911de committed Sep 3, 2021
1 parent 0a1aae7 commit 553d969
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/main/java/io/lettuce/core/event/metrics/JfrCommandLatency.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package io.lettuce.core.event.metrics;

import io.lettuce.core.metrics.CommandLatencyId;
import io.lettuce.core.metrics.CommandMetrics;
import jdk.jfr.Category;
import jdk.jfr.Event;
import jdk.jfr.Label;
import jdk.jfr.StackTrace;

import java.util.concurrent.TimeUnit;

/**
* A JFR event for Each Command Latency
* triggered by JfrCommandLatencyEvent
*
* @see JfrCommandLatency
* @author Hash.Jang
*/
@Category({ "Lettuce", "Command Events" })
@Label("Command Latency")
@StackTrace(false)
public class JfrCommandLatency extends Event {
private final String remoteAddress;
private final String commandType;
private final long count;
private final TimeUnit timeUnit;
private final long firstResponseMin;
private final long firstResponseMax;
private final String firstResponsePercentiles;
private final long completionResponseMin;
private final long completionResponseMax;
private final String completionResponsePercentiles;

public JfrCommandLatency(CommandLatencyId commandLatencyId, CommandMetrics commandMetrics) {
this.remoteAddress = commandLatencyId.remoteAddress().toString();
this.commandType = commandLatencyId.commandType().toString();
this.count = commandMetrics.getCount();
this.timeUnit = commandMetrics.getTimeUnit();
this.firstResponseMin = commandMetrics.getFirstResponse().getMin();
this.firstResponseMax = commandMetrics.getFirstResponse().getMax();
this.firstResponsePercentiles = commandMetrics.getFirstResponse().getPercentiles().toString();
this.completionResponseMin = commandMetrics.getCompletion().getMin();
this.completionResponseMax = commandMetrics.getCompletion().getMax();
this.completionResponsePercentiles = commandMetrics.getCompletion().getPercentiles().toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.lettuce.core.event.metrics;

import jdk.jfr.Category;
import jdk.jfr.Event;
import jdk.jfr.Label;
import jdk.jfr.StackTrace;

/**
* JFR Event for CommandLatencyEvent
* A JfrCommandLatencyEvent is only a trigger of multiple JfrCommandLatency
*
* @see JfrCommandLatency
* @author Hash.Jang
*/
@Category({ "Lettuce", "Command Events" })
@Label("Command Latency Trigger")
@StackTrace(false)
public class JfrCommandLatencyEvent extends Event {
private final int size;

public JfrCommandLatencyEvent(CommandLatencyEvent commandLatencyEvent) {
this.size = commandLatencyEvent.getLatencies().size();
commandLatencyEvent.getLatencies().forEach((commandLatencyId, commandMetrics) -> {
JfrCommandLatency jfrCommandLatency = new JfrCommandLatency(commandLatencyId, commandMetrics);
jfrCommandLatency.commit();
});
}
}

0 comments on commit 553d969

Please sign in to comment.