Skip to content

Commit 960012d

Browse files
committedMay 24, 2024·
api: Add ClientStreamTracer.inboundHeaders(Metadata)
This will be used by the metadata exchange of CSM. When recording per-attempt metrics, we really need per-attempt data and can't leverage ClientInterceptors.
1 parent fea577c commit 960012d

File tree

7 files changed

+31
-8
lines changed

7 files changed

+31
-8
lines changed
 

‎api/src/main/java/io/grpc/ClientStreamTracer.java

+16-3
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,23 @@ public void inboundHeaders() {
7070
}
7171

7272
/**
73-
* Trailing metadata has been received from the server.
73+
* Headers has been received from the server. This method does not pass ownership to {@code
74+
* headers}, so implementations must not access the metadata after returning. Modifications to the
75+
* metadata within this method will be seen by interceptors and the application.
7476
*
75-
* @param trailers the mutable trailing metadata. Modifications to it will be seen by
76-
* interceptors and the application.
77+
* @param headers the received header metadata
78+
*/
79+
public void inboundHeaders(Metadata headers) {
80+
inboundHeaders();
81+
}
82+
83+
/**
84+
* Trailing metadata has been received from the server. This method does not pass ownership to
85+
* {@code trailers}, so implementations must not access the metadata after returning.
86+
* Modifications to the metadata within this method will be seen by interceptors and the
87+
* application.
88+
*
89+
* @param trailers the received trailing metadata
7790
* @since 1.17.0
7891
*/
7992
public void inboundTrailers(Metadata trailers) {

‎binder/src/main/java/io/grpc/binder/internal/Inbound.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ boolean countsForInUse() {
579579
@GuardedBy("this")
580580
protected void handlePrefix(int flags, Parcel parcel) throws StatusException {
581581
Metadata headers = MetadataHelper.readMetadata(parcel, attributes);
582-
statsTraceContext.clientInboundHeaders();
582+
statsTraceContext.clientInboundHeaders(headers);
583583
listener.headersRead(headers);
584584
}
585585

‎core/src/main/java/io/grpc/internal/AbstractClientStream.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ protected final boolean isOutboundClosed() {
304304
*/
305305
protected void inboundHeadersReceived(Metadata headers) {
306306
checkState(!statusReported, "Received headers on closed stream");
307-
statsTraceCtx.clientInboundHeaders();
307+
statsTraceCtx.clientInboundHeaders(headers);
308308

309309
boolean compressedStream = false;
310310
String streamEncoding = headers.get(CONTENT_ENCODING_KEY);

‎core/src/main/java/io/grpc/internal/ForwardingClientStreamTracer.java

+5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ public void inboundHeaders() {
4949
delegate().inboundHeaders();
5050
}
5151

52+
@Override
53+
public void inboundHeaders(Metadata headers) {
54+
delegate().inboundHeaders(headers);
55+
}
56+
5257
@Override
5358
public void inboundTrailers(Metadata trailers) {
5459
delegate().inboundTrailers(trailers);

‎core/src/main/java/io/grpc/internal/StatsTraceContext.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ public void clientOutboundHeaders() {
101101
*
102102
* <p>Called from abstract stream implementations.
103103
*/
104-
public void clientInboundHeaders() {
104+
public void clientInboundHeaders(Metadata headers) {
105105
for (StreamTracer tracer : tracers) {
106-
((ClientStreamTracer) tracer).inboundHeaders();
106+
((ClientStreamTracer) tracer).inboundHeaders(headers);
107107
}
108108
}
109109

‎inprocess/src/main/java/io/grpc/inprocess/InProcessTransport.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ public void writeHeaders(Metadata headers, boolean flush) {
571571
return;
572572
}
573573

574-
clientStream.statsTraceCtx.clientInboundHeaders();
574+
clientStream.statsTraceCtx.clientInboundHeaders(headers);
575575
syncContext.executeLater(() -> clientStreamListener.headersRead(headers));
576576
}
577577
syncContext.drain();

‎util/src/main/java/io/grpc/util/ForwardingClientStreamTracer.java

+5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ public void inboundHeaders() {
4848
delegate().inboundHeaders();
4949
}
5050

51+
@Override
52+
public void inboundHeaders(Metadata headers) {
53+
delegate().inboundHeaders(headers);
54+
}
55+
5156
@Override
5257
public void inboundTrailers(Metadata trailers) {
5358
delegate().inboundTrailers(trailers);

0 commit comments

Comments
 (0)
Please sign in to comment.