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

[close #480] add metrics inside grpc and netty (#484) #488

Merged
merged 2 commits into from
Jan 20, 2022
Merged
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
51 changes: 51 additions & 0 deletions src/main/java/io/grpc/internal/ClientCallImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import io.perfmark.Link;
import io.perfmark.PerfMark;
import io.perfmark.Tag;
import io.prometheus.client.Histogram;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.Locale;
Expand All @@ -61,10 +62,18 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nullable;
import org.tikv.common.util.HistogramUtils;

/** Implementation of {@link ClientCall}. */
final class ClientCallImpl<ReqT, RespT> extends ClientCall<ReqT, RespT> {

public static final Histogram perfmarkClientCallImplDuration =
HistogramUtils.buildDuration()
.name("perfmark_client_call_impl_duration_seconds")
.help("Perfmark client call impl duration seconds")
.labelNames("type")
.register();

private static final Logger log = Logger.getLogger(ClientCallImpl.class.getName());
private static final byte[] FULL_STREAM_DECOMPRESSION_ENCODINGS =
"gzip".getBytes(Charset.forName("US-ASCII"));
Expand Down Expand Up @@ -179,10 +188,12 @@ static void prepareHeaders(
@Override
public void start(Listener<RespT> observer, Metadata headers) {
PerfMark.startTask("ClientCall.start", tag);
Histogram.Timer start = perfmarkClientCallImplDuration.labels("ClientCall.start").startTimer();
try {
startInternal(observer, headers);
} finally {
PerfMark.stopTask("ClientCall.start", tag);
start.observeDuration();
}
}

Expand Down Expand Up @@ -428,22 +439,28 @@ private static Deadline min(@Nullable Deadline deadline0, @Nullable Deadline dea
@Override
public void request(int numMessages) {
PerfMark.startTask("ClientCall.request", tag);
Histogram.Timer request =
perfmarkClientCallImplDuration.labels("ClientCall.request").startTimer();
try {
checkState(stream != null, "Not started");
checkArgument(numMessages >= 0, "Number requested must be non-negative");
stream.request(numMessages);
} finally {
PerfMark.stopTask("ClientCall.request", tag);
request.observeDuration();
}
}

@Override
public void cancel(@Nullable String message, @Nullable Throwable cause) {
PerfMark.startTask("ClientCall.cancel", tag);
Histogram.Timer cancel =
perfmarkClientCallImplDuration.labels("ClientCall.cancel").startTimer();
try {
cancelInternal(message, cause);
} finally {
PerfMark.stopTask("ClientCall.cancel", tag);
cancel.observeDuration();
}
}

Expand Down Expand Up @@ -479,10 +496,13 @@ private void cancelInternal(@Nullable String message, @Nullable Throwable cause)
@Override
public void halfClose() {
PerfMark.startTask("ClientCall.halfClose", tag);
Histogram.Timer halfClose =
perfmarkClientCallImplDuration.labels("ClientCall.halfClose").startTimer();
try {
halfCloseInternal();
} finally {
PerfMark.stopTask("ClientCall.halfClose", tag);
halfClose.observeDuration();
}
}

Expand All @@ -497,10 +517,13 @@ private void halfCloseInternal() {
@Override
public void sendMessage(ReqT message) {
PerfMark.startTask("ClientCall.sendMessage", tag);
Histogram.Timer sendMessage =
perfmarkClientCallImplDuration.labels("ClientCall.sendMessage").startTimer();
try {
sendMessageInternal(message);
} finally {
PerfMark.stopTask("ClientCall.sendMessage", tag);
sendMessage.observeDuration();
}
}

Expand Down Expand Up @@ -582,6 +605,8 @@ private void exceptionThrown(Status status) {
@Override
public void headersRead(final Metadata headers) {
PerfMark.startTask("ClientStreamListener.headersRead", tag);
Histogram.Timer headersRead =
perfmarkClientCallImplDuration.labels("ClientStreamListener.headersRead").startTimer();
final Link link = PerfMark.linkOut();

final class HeadersRead extends ContextRunnable {
Expand All @@ -592,11 +617,14 @@ final class HeadersRead extends ContextRunnable {
@Override
public void runInContext() {
PerfMark.startTask("ClientCall$Listener.headersRead", tag);
Histogram.Timer headersRead =
perfmarkClientCallImplDuration.labels("ClientCall$Listener.headersRead").startTimer();
PerfMark.linkIn(link);
try {
runInternal();
} finally {
PerfMark.stopTask("ClientCall$Listener.headersRead", tag);
headersRead.observeDuration();
}
}

Expand All @@ -617,12 +645,17 @@ private void runInternal() {
callExecutor.execute(new HeadersRead());
} finally {
PerfMark.stopTask("ClientStreamListener.headersRead", tag);
headersRead.observeDuration();
}
}

@Override
public void messagesAvailable(final MessageProducer producer) {
PerfMark.startTask("ClientStreamListener.messagesAvailable", tag);
Histogram.Timer messagesAvailable =
perfmarkClientCallImplDuration
.labels("ClientStreamListener.messagesAvailable")
.startTimer();
final Link link = PerfMark.linkOut();

final class MessagesAvailable extends ContextRunnable {
Expand All @@ -633,11 +666,16 @@ final class MessagesAvailable extends ContextRunnable {
@Override
public void runInContext() {
PerfMark.startTask("ClientCall$Listener.messagesAvailable", tag);
Histogram.Timer messagesAvailable =
perfmarkClientCallImplDuration
.labels("ClientCall$Listener.messagesAvailable")
.startTimer();
PerfMark.linkIn(link);
try {
runInternal();
} finally {
PerfMark.stopTask("ClientCall$Listener.messagesAvailable", tag);
messagesAvailable.observeDuration();
}
}

Expand Down Expand Up @@ -669,6 +707,7 @@ private void runInternal() {
callExecutor.execute(new MessagesAvailable());
} finally {
PerfMark.stopTask("ClientStreamListener.messagesAvailable", tag);
messagesAvailable.observeDuration();
}
}

Expand All @@ -680,10 +719,13 @@ public void closed(Status status, Metadata trailers) {
@Override
public void closed(Status status, RpcProgress rpcProgress, Metadata trailers) {
PerfMark.startTask("ClientStreamListener.closed", tag);
Histogram.Timer closed =
perfmarkClientCallImplDuration.labels("ClientStreamListener.closed").startTimer();
try {
closedInternal(status, rpcProgress, trailers);
} finally {
PerfMark.stopTask("ClientStreamListener.closed", tag);
closed.observeDuration();
}
}

Expand Down Expand Up @@ -715,11 +757,14 @@ final class StreamClosed extends ContextRunnable {
@Override
public void runInContext() {
PerfMark.startTask("ClientCall$Listener.onClose", tag);
Histogram.Timer onClose =
perfmarkClientCallImplDuration.labels("ClientCall$Listener.onClose").startTimer();
PerfMark.linkIn(link);
try {
runInternal();
} finally {
PerfMark.stopTask("ClientCall$Listener.onClose", tag);
onClose.observeDuration();
}
}

Expand Down Expand Up @@ -756,6 +801,8 @@ public void onReady() {
}

PerfMark.startTask("ClientStreamListener.onReady", tag);
Histogram.Timer onReady =
perfmarkClientCallImplDuration.labels("ClientStreamListener.onReady").startTimer();
final Link link = PerfMark.linkOut();

final class StreamOnReady extends ContextRunnable {
Expand All @@ -766,11 +813,14 @@ final class StreamOnReady extends ContextRunnable {
@Override
public void runInContext() {
PerfMark.startTask("ClientCall$Listener.onReady", tag);
Histogram.Timer onReady =
perfmarkClientCallImplDuration.labels("ClientCall$Listener.onReady").startTimer();
PerfMark.linkIn(link);
try {
runInternal();
} finally {
PerfMark.stopTask("ClientCall$Listener.onReady", tag);
onReady.observeDuration();
}
}

Expand All @@ -791,6 +841,7 @@ private void runInternal() {
callExecutor.execute(new StreamOnReady());
} finally {
PerfMark.stopTask("ClientStreamListener.onReady", tag);
onReady.observeDuration();
}
}
}
Expand Down
Loading