Skip to content

Commit aa05cad

Browse files
committed
fix grpc: write call statistics after run middlewares
commit_hash:024b0b11851daf92ff459d22c21331dd9e0e27f1
1 parent 1bb1787 commit aa05cad

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

grpc/include/userver/ugrpc/client/impl/async_stream_methods.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ void CheckOk(
2929

3030
void CheckFinishStatus(CallState& state);
3131

32-
void ProcessFinish(CallState& state, const google::protobuf::Message* final_response);
32+
void ProcessFinish(CallState& state, const grpc::Status& status, const google::protobuf::Message* final_response);
3333

34-
void ProcessFinishAbandoned(CallState& state) noexcept;
34+
void ProcessFinishAbandoned(CallState& state, const grpc::Status& status) noexcept;
3535

3636
void ProcessCancelled(CallState& state, std::string_view stage) noexcept;
3737

@@ -65,7 +65,7 @@ void Finish(
6565
case ugrpc::impl::AsyncMethodInvocation::WaitStatus::kOk:
6666
state.GetStatsScope().SetFinishTime(invocation.GetFinishTime());
6767
try {
68-
ProcessFinish(state, final_response);
68+
ProcessFinish(state, state.GetStatus(), final_response);
6969
} catch (const std::exception& ex) {
7070
if (throw_on_error) {
7171
throw;
@@ -117,7 +117,7 @@ void FinishAbandoned(GrpcStream& stream, StreamingCallState& state) noexcept try
117117
state.GetStatsScope().SetFinishTime(invocation.GetFinishTime());
118118

119119
if (ok) {
120-
ProcessFinishAbandoned(state);
120+
ProcessFinishAbandoned(state, state.GetStatus());
121121
} else {
122122
ProcessNetworkError(state, "Finish");
123123
}

grpc/src/ugrpc/client/impl/async_stream_methods.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,18 @@ void CheckFinishStatus(CallState& state) {
7070
}
7171
}
7272

73-
void ProcessFinish(CallState& state, const google::protobuf::Message* final_response) {
74-
const auto& status = state.GetStatus();
73+
void ProcessFinish(CallState& state, const grpc::Status& status, const google::protobuf::Message* response) {
74+
RunMiddlewarePipeline(state, MiddlewareHooks::FinishHooks(status, status.ok() ? response : nullptr));
7575

7676
HandleCallStatistics(state, status);
7777

78-
RunMiddlewarePipeline(state, MiddlewareHooks::FinishHooks(status, status.ok() ? final_response : nullptr));
79-
8078
SetStatusAndResetSpan(state, status);
8179
}
8280

83-
void ProcessFinishAbandoned(CallState& state) noexcept { SetStatusAndResetSpan(state, state.GetStatus()); }
81+
void ProcessFinishAbandoned(CallState& state, const grpc::Status& status) noexcept {
82+
// Nothing to do with statistics, `RpcStatisticsScope` automatically accounts "abandoned-error"
83+
SetStatusAndResetSpan(state, status);
84+
}
8485

8586
void ProcessCancelled(CallState& state, std::string_view stage) noexcept {
8687
state.GetStatsScope().OnCancelled();

0 commit comments

Comments
 (0)