Skip to content

Commit ffc034b

Browse files
committed
refactor grpc: using RpcType extensively
commit_hash:9844be32b717029db220cbf0f8afe4c7f5d37c66
1 parent aa6372e commit ffc034b

30 files changed

+126
-177
lines changed

.mapping.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,7 +2332,6 @@
23322332
"grpc/include/userver/ugrpc/client/impl/async_methods.hpp":"taxi/uservices/userver/grpc/include/userver/ugrpc/client/impl/async_methods.hpp",
23332333
"grpc/include/userver/ugrpc/client/impl/async_stream_methods.hpp":"taxi/uservices/userver/grpc/include/userver/ugrpc/client/impl/async_stream_methods.hpp",
23342334
"grpc/include/userver/ugrpc/client/impl/async_unary_call_adapter.hpp":"taxi/uservices/userver/grpc/include/userver/ugrpc/client/impl/async_unary_call_adapter.hpp",
2335-
"grpc/include/userver/ugrpc/client/impl/call_kind.hpp":"taxi/uservices/userver/grpc/include/userver/ugrpc/client/impl/call_kind.hpp",
23362335
"grpc/include/userver/ugrpc/client/impl/call_params.hpp":"taxi/uservices/userver/grpc/include/userver/ugrpc/client/impl/call_params.hpp",
23372336
"grpc/include/userver/ugrpc/client/impl/call_state.hpp":"taxi/uservices/userver/grpc/include/userver/ugrpc/client/impl/call_state.hpp",
23382337
"grpc/include/userver/ugrpc/client/impl/channel_argument_utils.hpp":"taxi/uservices/userver/grpc/include/userver/ugrpc/client/impl/channel_argument_utils.hpp",
@@ -2388,7 +2387,6 @@
23882387
"grpc/include/userver/ugrpc/impl/maybe_owned_string.hpp":"taxi/uservices/userver/grpc/include/userver/ugrpc/impl/maybe_owned_string.hpp",
23892388
"grpc/include/userver/ugrpc/impl/protobuf_collector.hpp":"taxi/uservices/userver/grpc/include/userver/ugrpc/impl/protobuf_collector.hpp",
23902389
"grpc/include/userver/ugrpc/impl/queue_runner.hpp":"taxi/uservices/userver/grpc/include/userver/ugrpc/impl/queue_runner.hpp",
2391-
"grpc/include/userver/ugrpc/impl/rpc_type.hpp":"taxi/uservices/userver/grpc/include/userver/ugrpc/impl/rpc_type.hpp",
23922390
"grpc/include/userver/ugrpc/impl/static_service_metadata.hpp":"taxi/uservices/userver/grpc/include/userver/ugrpc/impl/static_service_metadata.hpp",
23932391
"grpc/include/userver/ugrpc/impl/statistics.hpp":"taxi/uservices/userver/grpc/include/userver/ugrpc/impl/statistics.hpp",
23942392
"grpc/include/userver/ugrpc/impl/statistics_scope.hpp":"taxi/uservices/userver/grpc/include/userver/ugrpc/impl/statistics_scope.hpp",
@@ -2398,14 +2396,14 @@
23982396
"grpc/include/userver/ugrpc/protobuf_logging.hpp":"taxi/uservices/userver/grpc/include/userver/ugrpc/protobuf_logging.hpp",
23992397
"grpc/include/userver/ugrpc/protobuf_visit.hpp":"taxi/uservices/userver/grpc/include/userver/ugrpc/protobuf_visit.hpp",
24002398
"grpc/include/userver/ugrpc/rich_status.hpp":"taxi/uservices/userver/grpc/include/userver/ugrpc/rich_status.hpp",
2399+
"grpc/include/userver/ugrpc/rpc_type.hpp":"taxi/uservices/userver/grpc/include/userver/ugrpc/rpc_type.hpp",
24012400
"grpc/include/userver/ugrpc/server/call_context.hpp":"taxi/uservices/userver/grpc/include/userver/ugrpc/server/call_context.hpp",
24022401
"grpc/include/userver/ugrpc/server/component_list.hpp":"taxi/uservices/userver/grpc/include/userver/ugrpc/server/component_list.hpp",
24032402
"grpc/include/userver/ugrpc/server/exceptions.hpp":"taxi/uservices/userver/grpc/include/userver/ugrpc/server/exceptions.hpp",
24042403
"grpc/include/userver/ugrpc/server/generic_service_base.hpp":"taxi/uservices/userver/grpc/include/userver/ugrpc/server/generic_service_base.hpp",
24052404
"grpc/include/userver/ugrpc/server/impl/async_method_invocation.hpp":"taxi/uservices/userver/grpc/include/userver/ugrpc/server/impl/async_method_invocation.hpp",
24062405
"grpc/include/userver/ugrpc/server/impl/async_methods.hpp":"taxi/uservices/userver/grpc/include/userver/ugrpc/server/impl/async_methods.hpp",
24072406
"grpc/include/userver/ugrpc/server/impl/async_service.hpp":"taxi/uservices/userver/grpc/include/userver/ugrpc/server/impl/async_service.hpp",
2408-
"grpc/include/userver/ugrpc/server/impl/call_kind.hpp":"taxi/uservices/userver/grpc/include/userver/ugrpc/server/impl/call_kind.hpp",
24092407
"grpc/include/userver/ugrpc/server/impl/call_processor.hpp":"taxi/uservices/userver/grpc/include/userver/ugrpc/server/impl/call_processor.hpp",
24102408
"grpc/include/userver/ugrpc/server/impl/call_state.hpp":"taxi/uservices/userver/grpc/include/userver/ugrpc/server/impl/call_state.hpp",
24112409
"grpc/include/userver/ugrpc/server/impl/call_traits.hpp":"taxi/uservices/userver/grpc/include/userver/ugrpc/server/impl/call_traits.hpp",

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

Lines changed: 0 additions & 25 deletions
This file was deleted.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <userver/ugrpc/client/middlewares/fwd.hpp>
1515
#include <userver/ugrpc/impl/maybe_owned_string.hpp>
1616
#include <userver/ugrpc/impl/statistics.hpp>
17+
#include <userver/ugrpc/rpc_type.hpp>
1718

1819
USERVER_NAMESPACE_BEGIN
1920

@@ -26,6 +27,7 @@ struct CallParams {
2627
grpc::CompletionQueue& queue;
2728
dynamic_config::Snapshot config;
2829
std::string_view endpoint;
30+
RpcType rpc_type{};
2931
ugrpc::impl::MaybeOwnedString call_name;
3032
std::string_view service_name;
3133
std::string_view method_name;

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
#include <userver/tracing/in_place_span.hpp>
1313

1414
#include <userver/ugrpc/client/fwd.hpp>
15-
#include <userver/ugrpc/client/impl/call_kind.hpp>
1615
#include <userver/ugrpc/client/impl/middleware_pipeline.hpp>
1716
#include <userver/ugrpc/client/impl/stub_handle.hpp>
1817
#include <userver/ugrpc/impl/async_method_invocation.hpp>
1918
#include <userver/ugrpc/impl/maybe_owned_string.hpp>
2019
#include <userver/ugrpc/impl/statistics_scope.hpp>
20+
#include <userver/ugrpc/rpc_type.hpp>
2121

2222
USERVER_NAMESPACE_BEGIN
2323

@@ -37,7 +37,7 @@ struct RpcConfigValues final {
3737

3838
class CallState {
3939
public:
40-
CallState(CallParams&&, CallKind);
40+
explicit CallState(CallParams&& params);
4141

4242
~CallState() noexcept = default;
4343

@@ -52,9 +52,11 @@ class CallState {
5252

5353
grpc::ClientContext& GetClientContext() noexcept;
5454

55+
std::string_view GetClientName() const noexcept;
56+
5557
std::string_view GetCallName() const noexcept;
5658

57-
std::string_view GetClientName() const noexcept;
59+
RpcType GetRpcType() const noexcept;
5860

5961
tracing::Span& GetSpan() noexcept;
6062

@@ -66,8 +68,6 @@ class CallState {
6668

6769
const testsuite::GrpcControl& GetTestsuiteControl() const noexcept;
6870

69-
CallKind GetCallKind() const noexcept;
70-
7171
void ResetSpan() noexcept;
7272

7373
ugrpc::impl::RpcStatisticsScope& GetStatsScope() noexcept;
@@ -88,8 +88,11 @@ class CallState {
8888
std::unique_ptr<grpc::ClientContext> client_context_;
8989

9090
std::string client_name_;
91+
9192
ugrpc::impl::MaybeOwnedString call_name_;
9293

94+
RpcType rpc_type_{};
95+
9396
bool is_deadline_propagated_{false};
9497

9598
std::optional<tracing::InPlaceSpan> span_;
@@ -104,16 +107,14 @@ class CallState {
104107

105108
const testsuite::GrpcControl& testsuite_grpc_;
106109

107-
CallKind call_kind_{};
108-
109110
grpc::Status status_;
110111

111112
std::atomic<bool> committed_{false};
112113
};
113114

114115
class StreamingCallState final : public CallState {
115116
public:
116-
StreamingCallState(CallParams&& params, CallKind call_kind);
117+
explicit StreamingCallState(CallParams&& params);
117118

118119
~StreamingCallState() noexcept;
119120

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ InputStream<Response>::InputStream(
254254
PrepareServerStreamingCall<Stub, Request, Response> prepare_async_method,
255255
const Request& request
256256
)
257-
: state_{std::move(params), CallKind::kInputStream},
257+
: state_{std::move(params)},
258258
context_{utils::impl::InternalTag{}, state_}
259259
{
260260
RunMiddlewarePipeline(state_, MiddlewareHooks::StartCallHooks(ToBaseMessage(&request)));
@@ -302,7 +302,7 @@ OutputStream<Request, Response>::OutputStream(
302302
CallParams&& params,
303303
PrepareClientStreamingCall<Stub, Request, Response> prepare_async_method
304304
)
305-
: state_{std::move(params), CallKind::kOutputStream},
305+
: state_{std::move(params)},
306306
context_{utils::impl::InternalTag{}, state_}
307307
{
308308
RunMiddlewarePipeline(state_, MiddlewareHooks::StartCallHooks());
@@ -378,7 +378,7 @@ BidirectionalStream<Request, Response>::BidirectionalStream(
378378
CallParams&& params,
379379
PrepareBidiStreamingCall<Stub, Request, Response> prepare_async_method
380380
)
381-
: state_{std::move(params), CallKind::kBidirectionalStream},
381+
: state_{std::move(params)},
382382
context_{utils::impl::InternalTag{}, state_}
383383
{
384384
RunMiddlewarePipeline(state_, MiddlewareHooks::StartCallHooks());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class UnaryCall final {
3636

3737
UnaryCall(CallParams&& params, PrepareUnaryCall&& prepare_unary_call, const Request& request)
3838
: call_options_{std::move(params.call_options)},
39-
state_{std::move(params), CallKind::kUnaryCall},
39+
state_{std::move(params)},
4040
context_{utils::impl::InternalTag{}, state_},
4141
prepare_unary_call_{std::move(prepare_unary_call)},
4242
request_{request}

grpc/include/userver/ugrpc/client/middlewares/base.hpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <userver/tracing/span.hpp>
1717
#include <userver/utils/impl/internal_tag_fwd.hpp>
1818

19+
#include <userver/ugrpc/rpc_type.hpp>
1920
#include <userver/ugrpc/time_utils.hpp>
2021

2122
USERVER_NAMESPACE_BEGIN
@@ -62,15 +63,12 @@ class MiddlewareCallContext final {
6263
/// @returns RPC name
6364
std::string_view GetCallName() const noexcept;
6465

66+
/// @returns RPC type
67+
RpcType GetRpcType() const noexcept;
68+
6569
/// @returns RPC span
6670
tracing::Span& GetSpan() noexcept;
6771

68-
/// @returns Is a client-side streaming call
69-
bool IsClientStreaming() const noexcept;
70-
71-
/// @returns Is a server-side streaming call
72-
bool IsServerStreaming() const noexcept;
73-
7472
/// @cond
7573
// For internal use only
7674
impl::CallState& GetState(utils::impl::InternalTag);

grpc/include/userver/ugrpc/impl/rpc_type.hpp

Lines changed: 0 additions & 17 deletions
This file was deleted.

grpc/include/userver/ugrpc/impl/static_service_metadata.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <userver/utils/span.hpp>
77
#include <userver/utils/string_literal.hpp>
88

9-
#include <userver/ugrpc/impl/rpc_type.hpp>
9+
#include <userver/ugrpc/rpc_type.hpp>
1010

1111
USERVER_NAMESPACE_BEGIN
1212

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#pragma once
2+
3+
/// @file userver/ugrpc/rpc_type.hpp
4+
/// @brief @copybrief ugrpc::RpcType
5+
6+
USERVER_NAMESPACE_BEGIN
7+
8+
namespace ugrpc {
9+
10+
/// Type categorizes RPCs by unary or streaming type
11+
enum class RpcType {
12+
kUnary,
13+
kClientStreaming,
14+
kServerStreaming,
15+
kBidiStreaming,
16+
};
17+
18+
/// Returns `true` for `RpcType::kUnary` and `RpcType::kServerStreaming`, where the client sends a single request
19+
constexpr bool IsSingleRequestMethod(RpcType rpc_type) noexcept {
20+
return RpcType::kUnary == rpc_type || RpcType::kServerStreaming == rpc_type;
21+
}
22+
23+
/// Returns `true` for `RpcType::kUnary` and `RpcType::kClientStreaming`, where the server sends back a single response
24+
constexpr bool IsSingleResponseMethod(RpcType rpc_type) noexcept {
25+
return RpcType::kUnary == rpc_type || RpcType::kClientStreaming == rpc_type;
26+
}
27+
28+
} // namespace ugrpc
29+
30+
USERVER_NAMESPACE_END

0 commit comments

Comments
 (0)