Skip to content

Commit

Permalink
Add gRPC authority info to the observation context (#3510)
Browse files Browse the repository at this point in the history
Add and populate the gRPC authority information in both
server and client.
  • Loading branch information
ttddyy committed Nov 3, 2022
1 parent bfab8fb commit d2cd322
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
Expand Up @@ -43,6 +43,8 @@ public class GrpcClientObservationContext extends RequestReplySenderContext<Meta
@Nullable
private Code statusCode;

private String authority;

public GrpcClientObservationContext(Setter<Metadata> setter) {
super(setter);
}
Expand Down Expand Up @@ -88,4 +90,12 @@ public void setStatusCode(Code statusCode) {
this.statusCode = statusCode;
}

public String getAuthority() {
return this.authority;
}

public void setAuthority(String authority) {
this.authority = authority;
}

}
Expand Up @@ -43,6 +43,9 @@ public class GrpcServerObservationContext extends RequestReplyReceiverContext<Me
@Nullable
private Code statusCode;

@Nullable
private String authority;

public GrpcServerObservationContext(Getter<Metadata> getter) {
super(getter);
}
Expand Down Expand Up @@ -88,4 +91,13 @@ public void setStatusCode(Code statusCode) {
this.statusCode = statusCode;
}

@Nullable
public String getAuthority() {
return this.authority;
}

public void setAuthority(@Nullable String authority) {
this.authority = authority;
}

}
Expand Up @@ -80,7 +80,7 @@ public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT
}
context.setFullMethodName(fullMethodName);
context.setMethodType(methodType);

context.setAuthority(next.authority());
return context;
};

Expand Down
Expand Up @@ -83,6 +83,7 @@ public <ReqT, RespT> Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call,
}
context.setFullMethodName(fullMethodName);
context.setMethodType(methodType);
context.setAuthority(call.getAuthority());

return context;
};
Expand Down
Expand Up @@ -400,6 +400,7 @@ void verifyServerContext(String serviceName, String methodName, String contextua
assertThat(serverContext.getMethodName()).isEqualTo(methodName);
assertThat(serverContext.getFullMethodName()).isEqualTo(contextualName);
assertThat(serverContext.getMethodType()).isEqualTo(methodType);
assertThat(serverContext.getAuthority()).isEqualTo("localhost");
});
}

Expand All @@ -411,6 +412,7 @@ void verifyClientContext(String serviceName, String methodName, String contextua
assertThat(clientContext.getMethodName()).isEqualTo(methodName);
assertThat(clientContext.getFullMethodName()).isEqualTo(contextualName);
assertThat(clientContext.getMethodType()).isEqualTo(methodType);
assertThat(clientContext.getAuthority()).isEqualTo("localhost");
});
}

Expand Down

0 comments on commit d2cd322

Please sign in to comment.