Skip to content
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

Emit command latency events using JFR #1821

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
});
}
}