Skip to content

Commit b8be40c

Browse files
committed
Added grpc calls latency metric
1 parent 1e38902 commit b8be40c

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

jdbc/ydb-token-app/pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@
7272
<artifactId>spring-boot-maven-plugin</artifactId>
7373
<version>${spring.boot.version}</version>
7474
</plugin>
75+
<plugin>
76+
<groupId>org.apache.maven.plugins</groupId>
77+
<artifactId>maven-compiler-plugin</artifactId>
78+
<version>3.12.1</version>
79+
<configuration>
80+
<release>17</release>
81+
<compilerArgs>
82+
<arg>-Xlint</arg>
83+
</compilerArgs>
84+
</configuration>
85+
</plugin>
7586
</plugins>
7687
</build>
7788

jdbc/ydb-token-app/src/main/java/tech/ydb/apps/Application.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public Application(Config config, SchemeService scheme, WorkloadService worload,
6767
this.workloadService = worload;
6868
this.ticker = new AppMetrics(logger, registry);
6969

70+
logger.info("Create fixed thread pool with size {}", config.getThreadCount());
7071
this.executor = Executors.newFixedThreadPool(config.getThreadCount(), this::threadFactory);
7172
}
7273

jdbc/ydb-token-app/src/main/java/tech/ydb/apps/GrpcMetrics.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package tech.ydb.apps;
22

3+
import java.util.concurrent.TimeUnit;
34
import java.util.function.Consumer;
45

56
import javax.annotation.Nullable;
@@ -15,6 +16,7 @@
1516
import io.grpc.Status;
1617
import io.micrometer.core.instrument.Counter;
1718
import io.micrometer.core.instrument.MeterRegistry;
19+
import io.micrometer.core.instrument.Timer;
1820

1921
/**
2022
*
@@ -23,6 +25,8 @@
2325
public class GrpcMetrics implements Consumer<ManagedChannelBuilder<?>>, ClientInterceptor {
2426
private static final Counter.Builder REQUEST = Counter.builder("grpc.request");
2527
private static final Counter.Builder RESPONSE = Counter.builder("grpc.response");
28+
private static final Timer.Builder LATENCY = Timer.builder("grpc.latency")
29+
.publishPercentiles(0.5, 0.9, 0.95, 0.99);
2630

2731
private static MeterRegistry REGISTRY = null;
2832

@@ -101,9 +105,11 @@ public void sendMessage(ReqT message) {
101105

102106
private class ProxyListener extends Listener<RespT> {
103107
private final Listener<RespT> delegate;
108+
private final long startedAt;
104109

105110
public ProxyListener(Listener<RespT> delegate) {
106111
this.delegate = delegate;
112+
this.startedAt = System.currentTimeMillis();
107113
}
108114

109115

@@ -119,8 +125,11 @@ public void onMessage(RespT message) {
119125

120126
@Override
121127
public void onClose(Status status, Metadata trailers) {
128+
long ms = System.currentTimeMillis() - startedAt;
122129
RESPONSE.tag("method", method).tag("authority", authority).tag("status", status.getCode().toString())
123130
.register(registry).increment();
131+
LATENCY.tag("method", method).tag("authority", authority)
132+
.register(registry).record(ms, TimeUnit.MILLISECONDS);
124133
delegate.onClose(status, trailers);
125134
}
126135

0 commit comments

Comments
 (0)