diff --git a/include/envoy/grpc/status.h b/include/envoy/grpc/status.h index dbc7c0a016f1c..027ecd19f5dbf 100644 --- a/include/envoy/grpc/status.h +++ b/include/envoy/grpc/status.h @@ -5,9 +5,11 @@ namespace Grpc { class Status { public: + using GrpcStatus = int64_t; + // If this enum is changed, then the std::unordered_map in Envoy::Grpc::Utility::nameToGrpcStatus // located at: //source/common/access_log/grpc/status.cc must also be changed. - enum GrpcStatus { + enum WellKnownGrpcStatus { // The RPC completed successfully. Ok = 0, // The RPC was canceled. @@ -44,7 +46,7 @@ class Status { Unauthenticated = 16, // Maximum value of valid status codes. - MaximumValid = Unauthenticated, + MaximumKnown = Unauthenticated, // This is a non-GRPC error code, indicating the status code in gRPC headers // was invalid. diff --git a/source/common/access_log/access_log_impl.cc b/source/common/access_log/access_log_impl.cc index 837842f621aeb..7613e3ba9ae07 100644 --- a/source/common/access_log/access_log_impl.cc +++ b/source/common/access_log/access_log_impl.cc @@ -240,7 +240,7 @@ bool GrpcStatusFilter::evaluate(const StreamInfo::StreamInfo& info, const Http:: // 2. response_headers gRPC status, if it exists. // 3. Inferred from info HTTP status, if it exists. // - // If none of those options exist, it will default to Grpc::Status::GrpcStatus::Unknown. + // If none of those options exist, it will default to Grpc::Status::WellKnownGrpcStatus::Unknown. const std::array, 3> optional_statuses = {{ {Grpc::Common::getGrpcStatus(response_trailers)}, {Grpc::Common::getGrpcStatus(response_headers)}, @@ -249,7 +249,7 @@ bool GrpcStatusFilter::evaluate(const StreamInfo::StreamInfo& info, const Http:: : absl::nullopt}, }}; - Grpc::Status::GrpcStatus status = Grpc::Status::GrpcStatus::Unknown; + Grpc::Status::GrpcStatus status = Grpc::Status::WellKnownGrpcStatus::Unknown; for (const auto& optional_status : optional_statuses) { if (optional_status.has_value()) { status = optional_status.value(); diff --git a/source/common/config/delta_subscription_state.cc b/source/common/config/delta_subscription_state.cc index 93ddc18164dae..8fdfdca0ffca6 100644 --- a/source/common/config/delta_subscription_state.cc +++ b/source/common/config/delta_subscription_state.cc @@ -110,7 +110,7 @@ void DeltaSubscriptionState::handleGoodResponse( void DeltaSubscriptionState::handleBadResponse(const EnvoyException& e, UpdateAck& ack) { // Note that error_detail being set is what indicates that a DeltaDiscoveryRequest is a NACK. - ack.error_detail_.set_code(Grpc::Status::GrpcStatus::Internal); + ack.error_detail_.set_code(Grpc::Status::WellKnownGrpcStatus::Internal); ack.error_detail_.set_message(e.what()); disableInitFetchTimeoutTimer(); ENVOY_LOG(warn, "delta config for {} rejected: {}", type_url_, e.what()); @@ -158,7 +158,7 @@ envoy::api::v2::DeltaDiscoveryRequest DeltaSubscriptionState::getNextRequestWithAck(const UpdateAck& ack) { envoy::api::v2::DeltaDiscoveryRequest request = getNextRequestAckless(); request.set_response_nonce(ack.nonce_); - if (ack.error_detail_.code() != Grpc::Status::GrpcStatus::Ok) { + if (ack.error_detail_.code() != Grpc::Status::WellKnownGrpcStatus::Ok) { // Don't needlessly make the field present-but-empty if status is ok. request.mutable_error_detail()->CopyFrom(ack.error_detail_); } diff --git a/source/common/config/grpc_mux_impl.cc b/source/common/config/grpc_mux_impl.cc index fdb3fa603758a..3246dfbbd189d 100644 --- a/source/common/config/grpc_mux_impl.cc +++ b/source/common/config/grpc_mux_impl.cc @@ -201,7 +201,7 @@ void GrpcMuxImpl::onDiscoveryResponse( Envoy::Config::ConfigUpdateFailureReason::UpdateRejected, &e); } ::google::rpc::Status* error_detail = api_state_[type_url].request_.mutable_error_detail(); - error_detail->set_code(Grpc::Status::GrpcStatus::Internal); + error_detail->set_code(Grpc::Status::WellKnownGrpcStatus::Internal); error_detail->set_message(e.what()); } api_state_[type_url].request_.set_response_nonce(message->nonce()); diff --git a/source/common/grpc/async_client_impl.cc b/source/common/grpc/async_client_impl.cc index 5c42c0e91d343..c4f99bc988521 100644 --- a/source/common/grpc/async_client_impl.cc +++ b/source/common/grpc/async_client_impl.cc @@ -64,7 +64,7 @@ AsyncStreamImpl::AsyncStreamImpl(AsyncClientImpl& parent, absl::string_view serv void AsyncStreamImpl::initialize(bool buffer_body_for_retry) { if (parent_.cm_.get(parent_.remote_cluster_name_) == nullptr) { - callbacks_.onRemoteClose(Status::GrpcStatus::Unavailable, "Cluster not available"); + callbacks_.onRemoteClose(Status::WellKnownGrpcStatus::Unavailable, "Cluster not available"); http_reset_ = true; return; } @@ -74,7 +74,7 @@ void AsyncStreamImpl::initialize(bool buffer_body_for_retry) { stream_ = http_async_client.start(*this, options_.setBufferBodyForRetry(buffer_body_for_retry)); if (stream_ == nullptr) { - callbacks_.onRemoteClose(Status::GrpcStatus::Unavailable, EMPTY_STRING); + callbacks_.onRemoteClose(Status::WellKnownGrpcStatus::Unavailable, EMPTY_STRING); http_reset_ = true; return; } @@ -112,8 +112,8 @@ void AsyncStreamImpl::onHeaders(Http::HeaderMapPtr&& headers, bool end_stream) { // Technically this should be // https://github.com/grpc/grpc/blob/master/doc/http-grpc-status-mapping.md // as given by Grpc::Utility::httpToGrpcStatus(), but the Google gRPC client treats - // this as GrpcStatus::Canceled. - streamError(Status::GrpcStatus::Canceled); + // this as WellKnownGrpcStatus::Canceled. + streamError(Status::WellKnownGrpcStatus::Canceled); return; } if (end_stream) { @@ -124,24 +124,24 @@ void AsyncStreamImpl::onHeaders(Http::HeaderMapPtr&& headers, bool end_stream) { void AsyncStreamImpl::onData(Buffer::Instance& data, bool end_stream) { decoded_frames_.clear(); if (!decoder_.decode(data, decoded_frames_)) { - streamError(Status::GrpcStatus::Internal); + streamError(Status::WellKnownGrpcStatus::Internal); return; } for (auto& frame : decoded_frames_) { if (frame.length_ > 0 && frame.flags_ != GRPC_FH_DEFAULT) { - streamError(Status::GrpcStatus::Internal); + streamError(Status::WellKnownGrpcStatus::Internal); return; } if (!callbacks_.onReceiveMessageRaw(frame.data_ ? std::move(frame.data_) : std::make_unique())) { - streamError(Status::GrpcStatus::Internal); + streamError(Status::WellKnownGrpcStatus::Internal); return; } } if (end_stream) { - streamError(Status::GrpcStatus::Unknown); + streamError(Status::WellKnownGrpcStatus::Unknown); } } @@ -152,7 +152,7 @@ void AsyncStreamImpl::onTrailers(Http::HeaderMapPtr&& trailers) { const std::string grpc_message = Common::getGrpcMessage(*trailers); callbacks_.onReceiveTrailingMetadata(std::move(trailers)); if (!grpc_status) { - grpc_status = Status::GrpcStatus::Unknown; + grpc_status = Status::WellKnownGrpcStatus::Unknown; } callbacks_.onRemoteClose(grpc_status.value(), grpc_message); cleanup(); @@ -174,7 +174,7 @@ void AsyncStreamImpl::onReset() { } http_reset_ = true; - streamError(Status::GrpcStatus::Internal); + streamError(Status::WellKnownGrpcStatus::Internal); } void AsyncStreamImpl::sendMessage(const Protobuf::Message& request, bool end_stream) { @@ -252,7 +252,7 @@ void AsyncRequestImpl::onReceiveTrailingMetadata(Http::HeaderMapPtr&&) {} void AsyncRequestImpl::onRemoteClose(Grpc::Status::GrpcStatus status, const std::string& message) { current_span_->setTag(Tracing::Tags::get().GrpcStatusCode, std::to_string(status)); - if (status != Grpc::Status::GrpcStatus::Ok) { + if (status != Grpc::Status::WellKnownGrpcStatus::Ok) { current_span_->setTag(Tracing::Tags::get().Error, Tracing::Tags::get().True); callbacks_.onFailure(status, message, *current_span_); } else if (response_ == nullptr) { diff --git a/source/common/grpc/common.cc b/source/common/grpc/common.cc index 54c4b3b9639ce..72a3894e7700f 100644 --- a/source/common/grpc/common.cc +++ b/source/common/grpc/common.cc @@ -48,16 +48,17 @@ bool Common::isGrpcResponseHeader(const Http::HeaderMap& headers, bool end_strea return hasGrpcContentType(headers); } -absl::optional Common::getGrpcStatus(const Http::HeaderMap& trailers) { +absl::optional Common::getGrpcStatus(const Http::HeaderMap& trailers, + bool allow_user_defined) { const Http::HeaderEntry* grpc_status_header = trailers.GrpcStatus(); - uint64_t grpc_status_code; + if (!grpc_status_header || grpc_status_header->value().empty()) { return absl::nullopt; } if (!absl::SimpleAtoi(grpc_status_header->value().getStringView(), &grpc_status_code) || - grpc_status_code > Status::GrpcStatus::MaximumValid) { - return {Status::GrpcStatus::InvalidCode}; + (grpc_status_code > Status::WellKnownGrpcStatus::MaximumKnown && !allow_user_defined)) { + return {Status::WellKnownGrpcStatus::InvalidCode}; } return {static_cast(grpc_status_code)}; } @@ -222,7 +223,7 @@ void Common::checkForHeaderOnlyError(Http::Message& http_response) { return; } - if (grpc_status_code.value() == Status::GrpcStatus::InvalidCode) { + if (grpc_status_code.value() == Status::WellKnownGrpcStatus::InvalidCode) { throw Exception(absl::optional(), "bad grpc-status header"); } diff --git a/source/common/grpc/common.h b/source/common/grpc/common.h index e5939eaee45ff..21bffc5c74ffe 100644 --- a/source/common/grpc/common.h +++ b/source/common/grpc/common.h @@ -45,10 +45,13 @@ class Common { /** * Returns the GrpcStatus code from a given set of trailers, if present. * @param trailers the trailers to parse. + * @param allow_user_status whether allow user defined grpc status. + * if this value is false, custom grpc status is regarded as invalid status * @return absl::optional the parsed status code or InvalidCode if no valid * status is found. */ - static absl::optional getGrpcStatus(const Http::HeaderMap& trailers); + static absl::optional getGrpcStatus(const Http::HeaderMap& trailers, + bool allow_user_defined = false); /** * Returns the grpc-message from a given set of trailers, if present. diff --git a/source/common/grpc/google_async_client_impl.cc b/source/common/grpc/google_async_client_impl.cc index abc17b32f44ca..17007ba260c24 100644 --- a/source/common/grpc/google_async_client_impl.cc +++ b/source/common/grpc/google_async_client_impl.cc @@ -84,7 +84,7 @@ GoogleAsyncClientImpl::GoogleAsyncClientImpl(Event::Dispatcher& dispatcher, stub_ = stub_factory.createStub(channel); // Initialize client stats. stats_.streams_total_ = &scope_->counter("streams_total"); - for (uint32_t i = 0; i <= Status::GrpcStatus::MaximumValid; ++i) { + for (uint32_t i = 0; i <= Status::WellKnownGrpcStatus::MaximumKnown; ++i) { stats_.streams_closed_[i] = &scope_->counter(fmt::format("streams_closed_{}", i)); } } @@ -177,7 +177,7 @@ void GoogleAsyncStreamImpl::initialize(bool /*buffer_body_for_retry*/) { rw_ = parent_.stub_->PrepareCall(&ctxt_, "/" + service_full_name_ + "/" + method_name_, &parent_.tls_.completionQueue()); if (rw_ == nullptr) { - notifyRemoteClose(Status::GrpcStatus::Unavailable, nullptr, EMPTY_STRING); + notifyRemoteClose(Status::WellKnownGrpcStatus::Unavailable, nullptr, EMPTY_STRING); call_failed_ = true; return; } @@ -189,12 +189,12 @@ void GoogleAsyncStreamImpl::initialize(bool /*buffer_body_for_retry*/) { void GoogleAsyncStreamImpl::notifyRemoteClose(Status::GrpcStatus grpc_status, Http::HeaderMapPtr trailing_metadata, const std::string& message) { - if (grpc_status > Status::GrpcStatus::MaximumValid || grpc_status < 0) { + if (grpc_status > Status::WellKnownGrpcStatus::MaximumKnown || grpc_status < 0) { ENVOY_LOG(error, "notifyRemoteClose invalid gRPC status code {}", grpc_status); // Set the grpc_status as InvalidCode but increment the Unknown stream to avoid out-of-range // crash.. - grpc_status = Status::GrpcStatus::InvalidCode; - parent_.stats_.streams_closed_[Status::GrpcStatus::Unknown]->inc(); + grpc_status = Status::WellKnownGrpcStatus::InvalidCode; + parent_.stats_.streams_closed_[Status::WellKnownGrpcStatus::Unknown]->inc(); } else { parent_.stats_.streams_closed_[grpc_status]->inc(); } @@ -272,7 +272,7 @@ void GoogleAsyncStreamImpl::handleOpCompletion(GoogleAsyncTag::Operation op, boo // Early fails can be just treated as Internal. if (op == GoogleAsyncTag::Operation::Init || op == GoogleAsyncTag::Operation::ReadInitialMetadata) { - notifyRemoteClose(Status::GrpcStatus::Internal, nullptr, EMPTY_STRING); + notifyRemoteClose(Status::WellKnownGrpcStatus::Internal, nullptr, EMPTY_STRING); resetStream(); return; } @@ -324,7 +324,7 @@ void GoogleAsyncStreamImpl::handleOpCompletion(GoogleAsyncTag::Operation op, boo auto buffer = GoogleGrpcUtils::makeBufferInstance(read_buf_); if (!buffer || !callbacks_.onReceiveMessageRaw(std::move(buffer))) { // This is basically streamError in Grpc::AsyncClientImpl. - notifyRemoteClose(Status::GrpcStatus::Internal, nullptr, EMPTY_STRING); + notifyRemoteClose(Status::WellKnownGrpcStatus::Internal, nullptr, EMPTY_STRING); resetStream(); break; } @@ -438,7 +438,7 @@ void GoogleAsyncRequestImpl::onRemoteClose(Grpc::Status::GrpcStatus status, const std::string& message) { current_span_->setTag(Tracing::Tags::get().GrpcStatusCode, std::to_string(status)); - if (status != Grpc::Status::GrpcStatus::Ok) { + if (status != Grpc::Status::WellKnownGrpcStatus::Ok) { current_span_->setTag(Tracing::Tags::get().Error, Tracing::Tags::get().True); callbacks_.onFailure(status, message, *current_span_); } else if (response_ == nullptr) { diff --git a/source/common/grpc/google_async_client_impl.h b/source/common/grpc/google_async_client_impl.h index edc633a08d4d8..1026780cdba6d 100644 --- a/source/common/grpc/google_async_client_impl.h +++ b/source/common/grpc/google_async_client_impl.h @@ -118,7 +118,7 @@ struct GoogleAsyncClientStats { // .streams_total Stats::Counter* streams_total_; // .streams_closed_ - std::array streams_closed_; + std::array streams_closed_; }; // Interface to allow the gRPC stub to be mocked out by tests. diff --git a/source/common/grpc/status.cc b/source/common/grpc/status.cc index 70fdcce027113..be44ee8b9f8f9 100644 --- a/source/common/grpc/status.cc +++ b/source/common/grpc/status.cc @@ -8,77 +8,77 @@ Status::GrpcStatus Utility::httpToGrpcStatus(uint64_t http_response_status) { // https://github.com/grpc/grpc/blob/master/doc/http-grpc-status-mapping.md. switch (http_response_status) { case 400: - return Status::GrpcStatus::Internal; + return Status::WellKnownGrpcStatus::Internal; case 401: - return Status::GrpcStatus::Unauthenticated; + return Status::WellKnownGrpcStatus::Unauthenticated; case 403: - return Status::GrpcStatus::PermissionDenied; + return Status::WellKnownGrpcStatus::PermissionDenied; case 404: - return Status::GrpcStatus::Unimplemented; + return Status::WellKnownGrpcStatus::Unimplemented; case 429: case 502: case 503: case 504: - return Status::GrpcStatus::Unavailable; + return Status::WellKnownGrpcStatus::Unavailable; default: - return Status::GrpcStatus::Unknown; + return Status::WellKnownGrpcStatus::Unknown; } } uint64_t Utility::grpcToHttpStatus(Status::GrpcStatus grpc_status) { // From https://cloud.google.com/apis/design/errors#handling_errors. switch (grpc_status) { - case Status::GrpcStatus::Ok: + case Status::WellKnownGrpcStatus::Ok: return 200; - case Status::GrpcStatus::Canceled: + case Status::WellKnownGrpcStatus::Canceled: // Client closed request. return 499; - case Status::GrpcStatus::Unknown: + case Status::WellKnownGrpcStatus::Unknown: // Internal server error. return 500; - case Status::GrpcStatus::InvalidArgument: + case Status::WellKnownGrpcStatus::InvalidArgument: // Bad request. return 400; - case Status::GrpcStatus::DeadlineExceeded: + case Status::WellKnownGrpcStatus::DeadlineExceeded: // Gateway Time-out. return 504; - case Status::GrpcStatus::NotFound: + case Status::WellKnownGrpcStatus::NotFound: // Not found. return 404; - case Status::GrpcStatus::AlreadyExists: + case Status::WellKnownGrpcStatus::AlreadyExists: // Conflict. return 409; - case Status::GrpcStatus::PermissionDenied: + case Status::WellKnownGrpcStatus::PermissionDenied: // Forbidden. return 403; - case Status::GrpcStatus::ResourceExhausted: + case Status::WellKnownGrpcStatus::ResourceExhausted: // Too many requests. return 429; - case Status::GrpcStatus::FailedPrecondition: + case Status::WellKnownGrpcStatus::FailedPrecondition: // Bad request. return 400; - case Status::GrpcStatus::Aborted: + case Status::WellKnownGrpcStatus::Aborted: // Conflict. return 409; - case Status::GrpcStatus::OutOfRange: + case Status::WellKnownGrpcStatus::OutOfRange: // Bad request. return 400; - case Status::GrpcStatus::Unimplemented: + case Status::WellKnownGrpcStatus::Unimplemented: // Not implemented. return 501; - case Status::GrpcStatus::Internal: + case Status::WellKnownGrpcStatus::Internal: // Internal server error. return 500; - case Status::GrpcStatus::Unavailable: + case Status::WellKnownGrpcStatus::Unavailable: // Service unavailable. return 503; - case Status::GrpcStatus::DataLoss: + case Status::WellKnownGrpcStatus::DataLoss: // Internal server error. return 500; - case Status::GrpcStatus::Unauthenticated: + case Status::WellKnownGrpcStatus::Unauthenticated: // Unauthorized. return 401; - case Status::GrpcStatus::InvalidCode: + case Status::WellKnownGrpcStatus::InvalidCode: default: // Internal server error. return 500; diff --git a/source/common/grpc/typed_async_client.h b/source/common/grpc/typed_async_client.h index d1a95d41960ee..72907e42e6117 100644 --- a/source/common/grpc/typed_async_client.h +++ b/source/common/grpc/typed_async_client.h @@ -64,7 +64,7 @@ template class AsyncRequestCallbacks : public RawAsyncReques Internal::parseMessageUntyped(std::make_unique(), std::move(response)) .release())); if (!message) { - onFailure(Status::GrpcStatus::Internal, "", span); + onFailure(Status::WellKnownGrpcStatus::Internal, "", span); return; } onSuccess(std::move(message), span); diff --git a/source/common/router/router.cc b/source/common/router/router.cc index 63f36fc0bbcfb..87c1b686987e4 100644 --- a/source/common/router/router.cc +++ b/source/common/router/router.cc @@ -565,7 +565,6 @@ Http::ConnectionPool::Instance* Filter::getConnPool() { // Choose protocol based on cluster configuration and downstream connection // Note: Cluster may downgrade HTTP2 to HTTP1 based on runtime configuration. Http::Protocol protocol = cluster_->upstreamHttpProtocol(callbacks_->streamInfo().protocol()); - transport_socket_options_ = Network::TransportSocketOptionsUtility::fromFilterState( callbacks_->streamInfo().filterState()); diff --git a/source/common/tracing/http_tracer_impl.cc b/source/common/tracing/http_tracer_impl.cc index a1e3ea860e747..8d23ecf6459e2 100644 --- a/source/common/tracing/http_tracer_impl.cc +++ b/source/common/tracing/http_tracer_impl.cc @@ -94,7 +94,7 @@ static void addGrpcTags(Span& span, const Http::HeaderMap& headers) { } absl::optional grpc_status_code = Grpc::Common::getGrpcStatus(headers); // Set error tag when status is not OK. - if (grpc_status_code && grpc_status_code.value() != Grpc::Status::GrpcStatus::Ok) { + if (grpc_status_code && grpc_status_code.value() != Grpc::Status::WellKnownGrpcStatus::Ok) { span.setTag(Tracing::Tags::get().Error, Tracing::Tags::get().True); } } diff --git a/source/common/upstream/health_checker_impl.cc b/source/common/upstream/health_checker_impl.cc index 4b64c362b5a67..05179cfeed79c 100644 --- a/source/common/upstream/health_checker_impl.cc +++ b/source/common/upstream/health_checker_impl.cc @@ -545,7 +545,7 @@ void GrpcHealthCheckerImpl::GrpcActiveHealthCheckSession::decodeHeaders( return; } if (!Grpc::Common::hasGrpcContentType(*headers)) { - onRpcComplete(Grpc::Status::GrpcStatus::Internal, "invalid gRPC content-type", false); + onRpcComplete(Grpc::Status::WellKnownGrpcStatus::Internal, "invalid gRPC content-type", false); return; } if (end_stream) { @@ -556,7 +556,7 @@ void GrpcHealthCheckerImpl::GrpcActiveHealthCheckSession::decodeHeaders( onRpcComplete(grpc_status.value(), Grpc::Common::getGrpcMessage(*headers), true); return; } - onRpcComplete(Grpc::Status::GrpcStatus::Internal, + onRpcComplete(Grpc::Status::WellKnownGrpcStatus::Internal, "gRPC protocol violation: unexpected stream end", true); } } @@ -564,7 +564,7 @@ void GrpcHealthCheckerImpl::GrpcActiveHealthCheckSession::decodeHeaders( void GrpcHealthCheckerImpl::GrpcActiveHealthCheckSession::decodeData(Buffer::Instance& data, bool end_stream) { if (end_stream) { - onRpcComplete(Grpc::Status::GrpcStatus::Internal, + onRpcComplete(Grpc::Status::WellKnownGrpcStatus::Internal, "gRPC protocol violation: unexpected stream end", true); return; } @@ -572,13 +572,14 @@ void GrpcHealthCheckerImpl::GrpcActiveHealthCheckSession::decodeData(Buffer::Ins // We should end up with only one frame here. std::vector decoded_frames; if (!decoder_.decode(data, decoded_frames)) { - onRpcComplete(Grpc::Status::GrpcStatus::Internal, "gRPC wire protocol decode error", false); + onRpcComplete(Grpc::Status::WellKnownGrpcStatus::Internal, "gRPC wire protocol decode error", + false); } for (auto& frame : decoded_frames) { if (frame.length_ > 0) { if (health_check_response_) { // grpc.health.v1.Health.Check is unary RPC, so only one message is allowed. - onRpcComplete(Grpc::Status::GrpcStatus::Internal, "unexpected streaming", false); + onRpcComplete(Grpc::Status::WellKnownGrpcStatus::Internal, "unexpected streaming", false); return; } health_check_response_ = std::make_unique(); @@ -586,8 +587,8 @@ void GrpcHealthCheckerImpl::GrpcActiveHealthCheckSession::decodeData(Buffer::Ins if (frame.flags_ != Grpc::GRPC_FH_DEFAULT || !health_check_response_->ParseFromZeroCopyStream(&stream)) { - onRpcComplete(Grpc::Status::GrpcStatus::Internal, "invalid grpc.health.v1 RPC payload", - false); + onRpcComplete(Grpc::Status::WellKnownGrpcStatus::Internal, + "invalid grpc.health.v1 RPC payload", false); return; } } @@ -598,7 +599,9 @@ void GrpcHealthCheckerImpl::GrpcActiveHealthCheckSession::decodeTrailers( Http::HeaderMapPtr&& trailers) { auto maybe_grpc_status = Grpc::Common::getGrpcStatus(*trailers); auto grpc_status = - maybe_grpc_status ? maybe_grpc_status.value() : Grpc::Status::GrpcStatus::Internal; + maybe_grpc_status + ? maybe_grpc_status.value() + : static_cast(Grpc::Status::WellKnownGrpcStatus::Internal); const std::string grpc_message = maybe_grpc_status ? Grpc::Common::getGrpcMessage(*trailers) : "invalid gRPC status"; onRpcComplete(grpc_status, grpc_message, true); @@ -684,7 +687,7 @@ void GrpcHealthCheckerImpl::GrpcActiveHealthCheckSession::onGoAway() { bool GrpcHealthCheckerImpl::GrpcActiveHealthCheckSession::isHealthCheckSucceeded( Grpc::Status::GrpcStatus grpc_status) const { - if (grpc_status != Grpc::Status::GrpcStatus::Ok) { + if (grpc_status != Grpc::Status::WellKnownGrpcStatus::Ok) { return false; } @@ -757,7 +760,7 @@ void GrpcHealthCheckerImpl::GrpcActiveHealthCheckSession::logHealthCheckStatus( } } std::string grpc_status_message; - if (grpc_status != Grpc::Status::GrpcStatus::Ok && !grpc_message.empty()) { + if (grpc_status != Grpc::Status::WellKnownGrpcStatus::Ok && !grpc_message.empty()) { grpc_status_message = fmt::format("{} ({})", grpc_status, grpc_message); } else { grpc_status_message = fmt::format("{}", grpc_status); diff --git a/source/extensions/filters/common/ext_authz/ext_authz_grpc_impl.cc b/source/extensions/filters/common/ext_authz/ext_authz_grpc_impl.cc index fb09b6d08c4a4..749d75313c436 100644 --- a/source/extensions/filters/common/ext_authz/ext_authz_grpc_impl.cc +++ b/source/extensions/filters/common/ext_authz/ext_authz_grpc_impl.cc @@ -45,7 +45,7 @@ void GrpcClientImpl::check(RequestCallbacks& callbacks, void GrpcClientImpl::onSuccess(std::unique_ptr&& response, Tracing::Span& span) { ResponsePtr authz_response = std::make_unique(Response{}); - if (response->status().code() == Grpc::Status::GrpcStatus::Ok) { + if (response->status().code() == Grpc::Status::WellKnownGrpcStatus::Ok) { span.setTag(TracingConstants::get().TraceStatus, TracingConstants::get().TraceOk); authz_response->status = CheckStatus::OK; if (response->has_ok_response()) { @@ -70,7 +70,7 @@ void GrpcClientImpl::onSuccess(std::unique_ptrcomplete(LimitStatus::Error, nullptr, nullptr); callbacks_ = nullptr; } diff --git a/source/extensions/filters/http/grpc_http1_reverse_bridge/filter.cc b/source/extensions/filters/http/grpc_http1_reverse_bridge/filter.cc index 4c5e9182cbd4c..318b7331c2ac8 100644 --- a/source/extensions/filters/http/grpc_http1_reverse_bridge/filter.cc +++ b/source/extensions/filters/http/grpc_http1_reverse_bridge/filter.cc @@ -33,7 +33,7 @@ Grpc::Status::GrpcStatus grpcStatusFromHeaders(Http::HeaderMap& headers) { // from the standard but is key in being able to transform a successful // upstream HTTP response into a gRPC response. if (http_response_status == 200) { - return Grpc::Status::GrpcStatus::Ok; + return Grpc::Status::WellKnownGrpcStatus::Ok; } else { return Grpc::Utility::httpToGrpcStatus(http_response_status); } @@ -111,7 +111,7 @@ Http::FilterDataStatus Filter::decodeData(Buffer::Instance& buffer, bool) { // Fail the request if the body is too small to possibly contain a gRPC frame. if (buffer.length() < Grpc::GRPC_FRAME_HEADER_SIZE) { decoder_callbacks_->sendLocalReply(Http::Code::OK, "invalid request body", nullptr, - Grpc::Status::GrpcStatus::Unknown, + Grpc::Status::WellKnownGrpcStatus::Unknown, RcDetails::get().GrpcBridgeFailedTooSmall); return Http::FilterDataStatus::StopIterationNoBuffer; } @@ -133,7 +133,7 @@ Http::FilterHeadersStatus Filter::encodeHeaders(Http::HeaderMap& headers, bool) if (content_type == nullptr || content_type->value().getStringView() != upstream_content_type_) { headers.insertGrpcMessage().value(badContentTypeMessage(headers)); - headers.insertGrpcStatus().value(Envoy::Grpc::Status::GrpcStatus::Unknown); + headers.insertGrpcStatus().value(Envoy::Grpc::Status::WellKnownGrpcStatus::Unknown); headers.insertStatus().value(enumToInt(Http::Code::OK)); if (content_type != nullptr) { diff --git a/source/extensions/filters/http/grpc_json_transcoder/json_transcoder_filter.cc b/source/extensions/filters/http/grpc_json_transcoder/json_transcoder_filter.cc index 00476e1b6b6b1..6b52e7701802f 100644 --- a/source/extensions/filters/http/grpc_json_transcoder/json_transcoder_filter.cc +++ b/source/extensions/filters/http/grpc_json_transcoder/json_transcoder_filter.cc @@ -465,7 +465,7 @@ Http::FilterTrailersStatus JsonTranscoderFilter::encodeTrailers(Http::HeaderMap& response_in_.finish(); const absl::optional grpc_status = - Grpc::Common::getGrpcStatus(trailers); + Grpc::Common::getGrpcStatus(trailers, true); if (grpc_status && maybeConvertGrpcStatus(*grpc_status, trailers)) { return Http::FilterTrailersStatus::Continue; } @@ -486,7 +486,7 @@ Http::FilterTrailersStatus JsonTranscoderFilter::encodeTrailers(Http::HeaderMap& // so there is no need to copy headers from one to the other. bool is_trailers_only_response = response_headers_ == &trailers; - if (!grpc_status || grpc_status.value() == Grpc::Status::GrpcStatus::InvalidCode) { + if (!grpc_status || grpc_status.value() == Grpc::Status::WellKnownGrpcStatus::InvalidCode) { response_headers_->Status()->value(enumToInt(Http::Code::ServiceUnavailable)); } else { response_headers_->Status()->value(Grpc::Utility::grpcToHttpStatus(grpc_status.value())); @@ -568,8 +568,8 @@ bool JsonTranscoderFilter::maybeConvertGrpcStatus(Grpc::Status::GrpcStatus grpc_ return false; } - if (grpc_status == Grpc::Status::GrpcStatus::Ok || - grpc_status == Grpc::Status::GrpcStatus::InvalidCode) { + if (grpc_status == Grpc::Status::WellKnownGrpcStatus::Ok || + grpc_status == Grpc::Status::WellKnownGrpcStatus::InvalidCode) { return false; } diff --git a/source/extensions/filters/http/ratelimit/ratelimit.h b/source/extensions/filters/http/ratelimit/ratelimit.h index 19afcd2e46946..cc5e05e606123 100644 --- a/source/extensions/filters/http/ratelimit/ratelimit.h +++ b/source/extensions/filters/http/ratelimit/ratelimit.h @@ -45,7 +45,7 @@ class FilterConfig { failure_mode_deny_(config.failure_mode_deny()), rate_limited_grpc_status_( config.rate_limited_as_resource_exhausted() - ? absl::make_optional(Grpc::Status::GrpcStatus::ResourceExhausted) + ? absl::make_optional(Grpc::Status::WellKnownGrpcStatus::ResourceExhausted) : absl::nullopt), http_context_(http_context), stat_names_(scope.symbolTable()) {} const std::string& domain() const { return domain_; } diff --git a/test/common/access_log/access_log_impl_test.cc b/test/common/access_log/access_log_impl_test.cc index 7ebc5caf14165..14fd8129b83cb 100644 --- a/test/common/access_log/access_log_impl_test.cc +++ b/test/common/access_log/access_log_impl_test.cc @@ -1050,7 +1050,7 @@ name: envoy.file_access_log )EOF"; const auto desc = envoy::config::filter::accesslog::v2::GrpcStatusFilter_Status_descriptor(); - const int grpcStatuses = static_cast(Grpc::Status::GrpcStatus::MaximumValid) + 1; + const int grpcStatuses = static_cast(Grpc::Status::WellKnownGrpcStatus::MaximumKnown) + 1; if (desc->value_count() != grpcStatuses) { FAIL() << "Mismatch in number of gRPC statuses, GrpcStatus has " << grpcStatuses << ", GrpcStatusFilter_Status has " << desc->value_count() << "."; @@ -1172,7 +1172,7 @@ name: envoy.file_access_log const InstanceSharedPtr log = AccessLogFactory::fromProto(parseAccessLogFromV2Yaml(yaml), context_); - for (int i = 0; i <= static_cast(Grpc::Status::GrpcStatus::MaximumValid); i++) { + for (int i = 0; i <= static_cast(Grpc::Status::WellKnownGrpcStatus::MaximumKnown); i++) { EXPECT_CALL(*file_, write(_)).Times(i == 0 ? 0 : 1); response_trailers_.addCopy(Http::Headers::get().GrpcStatus, std::to_string(i)); diff --git a/test/common/config/delta_subscription_impl_test.cc b/test/common/config/delta_subscription_impl_test.cc index 366d2eec6f585..e6b783b6583fa 100644 --- a/test/common/config/delta_subscription_impl_test.cc +++ b/test/common/config/delta_subscription_impl_test.cc @@ -18,15 +18,15 @@ class DeltaSubscriptionImplTest : public DeltaSubscriptionTestHarness, public te TEST_F(DeltaSubscriptionImplTest, UpdateResourcesCausesRequest) { startSubscription({"name1", "name2", "name3"}); - expectSendMessage({"name4"}, {"name1", "name2"}, Grpc::Status::GrpcStatus::Ok, "", {}); + expectSendMessage({"name4"}, {"name1", "name2"}, Grpc::Status::WellKnownGrpcStatus::Ok, "", {}); subscription_->updateResourceInterest({"name3", "name4"}); - expectSendMessage({"name1", "name2"}, {}, Grpc::Status::GrpcStatus::Ok, "", {}); + expectSendMessage({"name1", "name2"}, {}, Grpc::Status::WellKnownGrpcStatus::Ok, "", {}); subscription_->updateResourceInterest({"name1", "name2", "name3", "name4"}); - expectSendMessage({}, {"name1", "name2"}, Grpc::Status::GrpcStatus::Ok, "", {}); + expectSendMessage({}, {"name1", "name2"}, Grpc::Status::WellKnownGrpcStatus::Ok, "", {}); subscription_->updateResourceInterest({"name3", "name4"}); - expectSendMessage({"name1", "name2"}, {}, Grpc::Status::GrpcStatus::Ok, "", {}); + expectSendMessage({"name1", "name2"}, {}, Grpc::Status::WellKnownGrpcStatus::Ok, "", {}); subscription_->updateResourceInterest({"name1", "name2", "name3", "name4"}); - expectSendMessage({}, {"name1", "name2", "name3"}, Grpc::Status::GrpcStatus::Ok, "", {}); + expectSendMessage({}, {"name1", "name2", "name3"}, Grpc::Status::WellKnownGrpcStatus::Ok, "", {}); subscription_->updateResourceInterest({"name4"}); } @@ -38,7 +38,7 @@ TEST_F(DeltaSubscriptionImplTest, PauseHoldsRequest) { startSubscription({"name1", "name2", "name3"}); subscription_->pause(); - expectSendMessage({"name4"}, {"name1", "name2"}, Grpc::Status::GrpcStatus::Ok, "", {}); + expectSendMessage({"name4"}, {"name1", "name2"}, Grpc::Status::WellKnownGrpcStatus::Ok, "", {}); // If not for the pause, these updates would make the expectSendMessage fail due to too many // messages being sent. subscription_->updateResourceInterest({"name3", "name4"}); diff --git a/test/common/config/delta_subscription_state_test.cc b/test/common/config/delta_subscription_state_test.cc index 2a96f2b0953f2..f98dfe5aa05ef 100644 --- a/test/common/config/delta_subscription_state_test.cc +++ b/test/common/config/delta_subscription_state_test.cc @@ -174,7 +174,7 @@ TEST_F(DeltaSubscriptionStateTest, AckGenerated) { populateRepeatedResource({{"name1", "version1A"}, {"name2", "version2A"}}); UpdateAck ack = deliverDiscoveryResponse(added_resources, {}, "debug1", "nonce1"); EXPECT_EQ("nonce1", ack.nonce_); - EXPECT_EQ(Grpc::Status::GrpcStatus::Ok, ack.error_detail_.code()); + EXPECT_EQ(Grpc::Status::WellKnownGrpcStatus::Ok, ack.error_detail_.code()); } // The next response updates 1 and 2, and adds 3. { @@ -182,7 +182,7 @@ TEST_F(DeltaSubscriptionStateTest, AckGenerated) { {{"name1", "version1B"}, {"name2", "version2B"}, {"name3", "version3A"}}); UpdateAck ack = deliverDiscoveryResponse(added_resources, {}, "debug2", "nonce2"); EXPECT_EQ("nonce2", ack.nonce_); - EXPECT_EQ(Grpc::Status::GrpcStatus::Ok, ack.error_detail_.code()); + EXPECT_EQ(Grpc::Status::WellKnownGrpcStatus::Ok, ack.error_detail_.code()); } // The next response tries but fails to update all 3, and so should produce a NACK. { @@ -190,7 +190,7 @@ TEST_F(DeltaSubscriptionStateTest, AckGenerated) { {{"name1", "version1C"}, {"name2", "version2C"}, {"name3", "version3B"}}); UpdateAck ack = deliverBadDiscoveryResponse(added_resources, {}, "debug3", "nonce3"); EXPECT_EQ("nonce3", ack.nonce_); - EXPECT_NE(Grpc::Status::GrpcStatus::Ok, ack.error_detail_.code()); + EXPECT_NE(Grpc::Status::WellKnownGrpcStatus::Ok, ack.error_detail_.code()); } // The last response successfully updates all 3. { @@ -198,7 +198,7 @@ TEST_F(DeltaSubscriptionStateTest, AckGenerated) { {{"name1", "version1D"}, {"name2", "version2D"}, {"name3", "version3C"}}); UpdateAck ack = deliverDiscoveryResponse(added_resources, {}, "debug4", "nonce4"); EXPECT_EQ("nonce4", ack.nonce_); - EXPECT_EQ(Grpc::Status::GrpcStatus::Ok, ack.error_detail_.code()); + EXPECT_EQ(Grpc::Status::WellKnownGrpcStatus::Ok, ack.error_detail_.code()); } } diff --git a/test/common/config/delta_subscription_test_harness.h b/test/common/config/delta_subscription_test_harness.h index 720b771e65dda..bf35490d4b901 100644 --- a/test/common/config/delta_subscription_test_harness.h +++ b/test/common/config/delta_subscription_test_harness.h @@ -76,7 +76,7 @@ class DeltaSubscriptionTestHarness : public SubscriptionTestHarness { bool expect_node = false) override { UNREFERENCED_PARAMETER(version); UNREFERENCED_PARAMETER(expect_node); - expectSendMessage(cluster_names, {}, Grpc::Status::GrpcStatus::Ok, "", {}); + expectSendMessage(cluster_names, {}, Grpc::Status::WellKnownGrpcStatus::Ok, "", {}); } void expectSendMessage(const std::set& subscribe, @@ -101,7 +101,7 @@ class DeltaSubscriptionTestHarness : public SubscriptionTestHarness { (*expected_request.mutable_initial_resource_versions())[resource.first] = resource.second; } - if (error_code != Grpc::Status::GrpcStatus::Ok) { + if (error_code != Grpc::Status::WellKnownGrpcStatus::Ok) { ::google::rpc::Status* error_detail = expected_request.mutable_error_detail(); error_detail->set_code(error_code); error_detail->set_message(error_message); @@ -146,7 +146,7 @@ class DeltaSubscriptionTestHarness : public SubscriptionTestHarness { } else { EXPECT_CALL(callbacks_, onConfigUpdateFailed( Envoy::Config::ConfigUpdateFailureReason::UpdateRejected, _)); - expectSendMessage({}, {}, Grpc::Status::GrpcStatus::Internal, "bad config", {}); + expectSendMessage({}, {}, Grpc::Status::WellKnownGrpcStatus::Internal, "bad config", {}); } static_cast(subscription_->getContextForTest().get()) ->onDiscoveryResponse(std::move(response)); @@ -163,7 +163,7 @@ class DeltaSubscriptionTestHarness : public SubscriptionTestHarness { cluster_names.begin(), cluster_names.end(), std::inserter(unsub, unsub.begin())); - expectSendMessage(sub, unsub, Grpc::Status::GrpcStatus::Ok, "", {}); + expectSendMessage(sub, unsub, Grpc::Status::WellKnownGrpcStatus::Ok, "", {}); subscription_->updateResourceInterest(cluster_names); last_cluster_names_ = cluster_names; } diff --git a/test/common/config/grpc_mux_impl_test.cc b/test/common/config/grpc_mux_impl_test.cc index 7ef57acb1a8cf..c9fb873d61581 100644 --- a/test/common/config/grpc_mux_impl_test.cc +++ b/test/common/config/grpc_mux_impl_test.cc @@ -66,7 +66,7 @@ class GrpcMuxImplTestBase : public testing::Test { void expectSendMessage(const std::string& type_url, const std::vector& resource_names, const std::string& version, bool first = false, const std::string& nonce = "", - const Protobuf::int32 error_code = Grpc::Status::GrpcStatus::Ok, + const Protobuf::int32 error_code = Grpc::Status::WellKnownGrpcStatus::Ok, const std::string& error_message = "") { envoy::api::v2::DiscoveryRequest expected_request; if (first) { @@ -80,7 +80,7 @@ class GrpcMuxImplTestBase : public testing::Test { } expected_request.set_response_nonce(nonce); expected_request.set_type_url(type_url); - if (error_code != Grpc::Status::GrpcStatus::Ok) { + if (error_code != Grpc::Status::WellKnownGrpcStatus::Ok) { ::google::rpc::Status* error_detail = expected_request.mutable_error_detail(); error_detail->set_code(error_code); error_detail->set_message(error_message); @@ -163,7 +163,7 @@ TEST_F(GrpcMuxImplTest, ResetStream) { EXPECT_CALL(random_, random()); ASSERT_TRUE(timer != nullptr); // initialized from dispatcher mock. EXPECT_CALL(*timer, enableTimer(_, _)); - grpc_mux_->grpcStreamForTest().onRemoteClose(Grpc::Status::GrpcStatus::Canceled, ""); + grpc_mux_->grpcStreamForTest().onRemoteClose(Grpc::Status::WellKnownGrpcStatus::Canceled, ""); EXPECT_EQ(0, control_plane_connected_state_.value()); EXPECT_CALL(*async_client_, startRaw(_, _, _, _)).WillOnce(Return(&async_stream_)); expectSendMessage("foo", {"x", "y"}, "", true); @@ -227,7 +227,7 @@ TEST_F(GrpcMuxImplTest, TypeUrlMismatch) { })); expectSendMessage( - "foo", {"x", "y"}, "", false, "", Grpc::Status::GrpcStatus::Internal, + "foo", {"x", "y"}, "", false, "", Grpc::Status::WellKnownGrpcStatus::Internal, fmt::format("bar does not match the message-wide type URL foo in DiscoveryResponse {}", invalid_response->DebugString())); grpc_mux_->grpcStreamForTest().onReceiveMessage(std::move(invalid_response)); diff --git a/test/common/config/grpc_stream_test.cc b/test/common/config/grpc_stream_test.cc index 0c37a22642594..bb575711ea20c 100644 --- a/test/common/config/grpc_stream_test.cc +++ b/test/common/config/grpc_stream_test.cc @@ -59,7 +59,7 @@ TEST_F(GrpcStreamTest, EstablishStream) { grpc_stream_.establishNewStream(); EXPECT_TRUE(grpc_stream_.grpcStreamAvailable()); } - grpc_stream_.onRemoteClose(Grpc::Status::GrpcStatus::Ok, ""); + grpc_stream_.onRemoteClose(Grpc::Status::WellKnownGrpcStatus::Ok, ""); EXPECT_FALSE(grpc_stream_.grpcStreamAvailable()); // Successful re-establishment { diff --git a/test/common/config/grpc_subscription_impl_test.cc b/test/common/config/grpc_subscription_impl_test.cc index 9664aed24e9ef..f7bed58385554 100644 --- a/test/common/config/grpc_subscription_impl_test.cc +++ b/test/common/config/grpc_subscription_impl_test.cc @@ -46,8 +46,8 @@ TEST_F(GrpcSubscriptionImplTest, RemoteStreamClose) { .Times(0); EXPECT_CALL(*timer_, enableTimer(_, _)); EXPECT_CALL(random_, random()); - subscription_->grpcMux()->grpcStreamForTest().onRemoteClose(Grpc::Status::GrpcStatus::Canceled, - ""); + subscription_->grpcMux()->grpcStreamForTest().onRemoteClose( + Grpc::Status::WellKnownGrpcStatus::Canceled, ""); EXPECT_TRUE(statsAre(2, 0, 0, 1, 0, 0)); verifyControlPlaneStats(0); diff --git a/test/common/config/grpc_subscription_test_harness.h b/test/common/config/grpc_subscription_test_harness.h index b5cb517c4b838..476230d68cb58 100644 --- a/test/common/config/grpc_subscription_test_harness.h +++ b/test/common/config/grpc_subscription_test_harness.h @@ -52,7 +52,8 @@ class GrpcSubscriptionTestHarness : public SubscriptionTestHarness { void expectSendMessage(const std::set& cluster_names, const std::string& version, bool expect_node = false) override { - expectSendMessage(cluster_names, version, expect_node, Grpc::Status::GrpcStatus::Ok, ""); + expectSendMessage(cluster_names, version, expect_node, Grpc::Status::WellKnownGrpcStatus::Ok, + ""); } void expectSendMessage(const std::set& cluster_names, const std::string& version, @@ -71,7 +72,7 @@ class GrpcSubscriptionTestHarness : public SubscriptionTestHarness { } expected_request.set_response_nonce(last_response_nonce_); expected_request.set_type_url(Config::TypeUrl::get().ClusterLoadAssignment); - if (error_code != Grpc::Status::GrpcStatus::Ok) { + if (error_code != Grpc::Status::WellKnownGrpcStatus::Ok) { ::google::rpc::Status* error_detail = expected_request.mutable_error_detail(); error_detail->set_code(error_code); error_detail->set_message(error_message); @@ -111,8 +112,8 @@ class GrpcSubscriptionTestHarness : public SubscriptionTestHarness { } else { EXPECT_CALL(callbacks_, onConfigUpdateFailed( Envoy::Config::ConfigUpdateFailureReason::UpdateRejected, _)); - expectSendMessage(last_cluster_names_, version_, false, Grpc::Status::GrpcStatus::Internal, - "bad config"); + expectSendMessage(last_cluster_names_, version_, false, + Grpc::Status::WellKnownGrpcStatus::Internal, "bad config"); } subscription_->grpcMux()->onDiscoveryResponse(std::move(response)); Mock::VerifyAndClearExpectations(&async_stream_); diff --git a/test/common/grpc/async_client_impl_test.cc b/test/common/grpc/async_client_impl_test.cc index 15d65f60ffbad..72e5d6411584f 100644 --- a/test/common/grpc/async_client_impl_test.cc +++ b/test/common/grpc/async_client_impl_test.cc @@ -41,7 +41,7 @@ class EnvoyAsyncClientImplTest : public testing::Test { TEST_F(EnvoyAsyncClientImplTest, StreamHttpStartFail) { MockAsyncStreamCallbacks grpc_callbacks; ON_CALL(http_client_, start(_, _)).WillByDefault(Return(nullptr)); - EXPECT_CALL(grpc_callbacks, onRemoteClose(Status::GrpcStatus::Unavailable, "")); + EXPECT_CALL(grpc_callbacks, onRemoteClose(Status::WellKnownGrpcStatus::Unavailable, "")); auto grpc_stream = grpc_client_->start(*method_descriptor_, grpc_callbacks, Http::AsyncClient::StreamOptions()); EXPECT_TRUE(grpc_stream == nullptr); @@ -52,7 +52,7 @@ TEST_F(EnvoyAsyncClientImplTest, StreamHttpStartFail) { TEST_F(EnvoyAsyncClientImplTest, RequestHttpStartFail) { MockAsyncRequestCallbacks grpc_callbacks; ON_CALL(http_client_, start(_, _)).WillByDefault(Return(nullptr)); - EXPECT_CALL(grpc_callbacks, onFailure(Status::GrpcStatus::Unavailable, "", _)); + EXPECT_CALL(grpc_callbacks, onFailure(Status::WellKnownGrpcStatus::Unavailable, "", _)); helloworld::HelloRequest request_msg; Tracing::MockSpan active_span; @@ -93,7 +93,7 @@ TEST_F(EnvoyAsyncClientImplTest, StreamHttpSendHeadersFail) { http_callbacks->onReset(); })); EXPECT_CALL(grpc_callbacks, onReceiveTrailingMetadata_(_)); - EXPECT_CALL(grpc_callbacks, onRemoteClose(Status::GrpcStatus::Internal, "")); + EXPECT_CALL(grpc_callbacks, onRemoteClose(Status::WellKnownGrpcStatus::Internal, "")); auto grpc_stream = grpc_client_->start(*method_descriptor_, grpc_callbacks, Http::AsyncClient::StreamOptions()); EXPECT_TRUE(grpc_stream == nullptr); @@ -119,7 +119,7 @@ TEST_F(EnvoyAsyncClientImplTest, RequestHttpSendHeadersFail) { UNREFERENCED_PARAMETER(end_stream); http_callbacks->onReset(); })); - EXPECT_CALL(grpc_callbacks, onFailure(Status::GrpcStatus::Internal, "", _)); + EXPECT_CALL(grpc_callbacks, onFailure(Status::WellKnownGrpcStatus::Internal, "", _)); helloworld::HelloRequest request_msg; Tracing::MockSpan active_span; @@ -145,7 +145,7 @@ TEST_F(EnvoyAsyncClientImplTest, StreamHttpClientException) { MockAsyncStreamCallbacks grpc_callbacks; ON_CALL(cm_, get(_)).WillByDefault(Return(nullptr)); EXPECT_CALL(grpc_callbacks, - onRemoteClose(Status::GrpcStatus::Unavailable, "Cluster not available")); + onRemoteClose(Status::WellKnownGrpcStatus::Unavailable, "Cluster not available")); auto grpc_stream = grpc_client_->start(*method_descriptor_, grpc_callbacks, Http::AsyncClient::StreamOptions()); EXPECT_TRUE(grpc_stream == nullptr); diff --git a/test/common/grpc/common_test.cc b/test/common/grpc/common_test.cc index ec3f6d7cff91a..88761b4026766 100644 --- a/test/common/grpc/common_test.cc +++ b/test/common/grpc/common_test.cc @@ -30,6 +30,12 @@ TEST(GrpcContextTest, GetGrpcStatus) { Http::TestHeaderMapImpl invalid_trailers{{"grpc-status", "-1"}}; EXPECT_EQ(Status::InvalidCode, Common::getGrpcStatus(invalid_trailers).value()); + + Http::TestHeaderMapImpl user_defined_invalid_trailers{{"grpc-status", "1024"}}; + EXPECT_EQ(Status::InvalidCode, Common::getGrpcStatus(invalid_trailers).value()); + + Http::TestHeaderMapImpl user_defined_trailers{{"grpc-status", "1024"}}; + EXPECT_EQ(1024, Common::getGrpcStatus(user_defined_trailers, true).value()); } TEST(GrpcContextTest, GetGrpcMessage) { @@ -89,14 +95,14 @@ TEST(GrpcCommonTest, GrpcStatusDetailsBin) { {"grpc-status-details-bin", "CAUSElJlc291cmNlIG5vdCBmb3VuZA"}}; auto status = Common::getGrpcStatusDetailsBin(unpadded_value); ASSERT_TRUE(status); - EXPECT_EQ(Status::GrpcStatus::NotFound, status->code()); + EXPECT_EQ(Status::WellKnownGrpcStatus::NotFound, status->code()); EXPECT_EQ("Resource not found", status->message()); Http::TestHeaderMapImpl padded_value{ {"grpc-status-details-bin", "CAUSElJlc291cmNlIG5vdCBmb3VuZA=="}}; status = Common::getGrpcStatusDetailsBin(padded_value); ASSERT_TRUE(status); - EXPECT_EQ(Status::GrpcStatus::NotFound, status->code()); + EXPECT_EQ(Status::WellKnownGrpcStatus::NotFound, status->code()); EXPECT_EQ("Resource not found", status->message()); } @@ -200,24 +206,24 @@ TEST(GrpcContextTest, PrepareHeaders) { TEST(GrpcContextTest, GrpcToHttpStatus) { const std::vector> test_set = { - {Status::GrpcStatus::Ok, 200}, - {Status::GrpcStatus::Canceled, 499}, - {Status::GrpcStatus::Unknown, 500}, - {Status::GrpcStatus::InvalidArgument, 400}, - {Status::GrpcStatus::DeadlineExceeded, 504}, - {Status::GrpcStatus::NotFound, 404}, - {Status::GrpcStatus::AlreadyExists, 409}, - {Status::GrpcStatus::PermissionDenied, 403}, - {Status::GrpcStatus::ResourceExhausted, 429}, - {Status::GrpcStatus::FailedPrecondition, 400}, - {Status::GrpcStatus::Aborted, 409}, - {Status::GrpcStatus::OutOfRange, 400}, - {Status::GrpcStatus::Unimplemented, 501}, - {Status::GrpcStatus::Internal, 500}, - {Status::GrpcStatus::Unavailable, 503}, - {Status::GrpcStatus::DataLoss, 500}, - {Status::GrpcStatus::Unauthenticated, 401}, - {Status::GrpcStatus::InvalidCode, 500}, + {Status::WellKnownGrpcStatus::Ok, 200}, + {Status::WellKnownGrpcStatus::Canceled, 499}, + {Status::WellKnownGrpcStatus::Unknown, 500}, + {Status::WellKnownGrpcStatus::InvalidArgument, 400}, + {Status::WellKnownGrpcStatus::DeadlineExceeded, 504}, + {Status::WellKnownGrpcStatus::NotFound, 404}, + {Status::WellKnownGrpcStatus::AlreadyExists, 409}, + {Status::WellKnownGrpcStatus::PermissionDenied, 403}, + {Status::WellKnownGrpcStatus::ResourceExhausted, 429}, + {Status::WellKnownGrpcStatus::FailedPrecondition, 400}, + {Status::WellKnownGrpcStatus::Aborted, 409}, + {Status::WellKnownGrpcStatus::OutOfRange, 400}, + {Status::WellKnownGrpcStatus::Unimplemented, 501}, + {Status::WellKnownGrpcStatus::Internal, 500}, + {Status::WellKnownGrpcStatus::Unavailable, 503}, + {Status::WellKnownGrpcStatus::DataLoss, 500}, + {Status::WellKnownGrpcStatus::Unauthenticated, 401}, + {Status::WellKnownGrpcStatus::InvalidCode, 500}, }; for (const auto& test_case : test_set) { EXPECT_EQ(test_case.second, Grpc::Utility::grpcToHttpStatus(test_case.first)); @@ -226,11 +232,15 @@ TEST(GrpcContextTest, GrpcToHttpStatus) { TEST(GrpcContextTest, HttpToGrpcStatus) { const std::vector> test_set = { - {400, Status::GrpcStatus::Internal}, {401, Status::GrpcStatus::Unauthenticated}, - {403, Status::GrpcStatus::PermissionDenied}, {404, Status::GrpcStatus::Unimplemented}, - {429, Status::GrpcStatus::Unavailable}, {502, Status::GrpcStatus::Unavailable}, - {503, Status::GrpcStatus::Unavailable}, {504, Status::GrpcStatus::Unavailable}, - {500, Status::GrpcStatus::Unknown}, + {400, Status::WellKnownGrpcStatus::Internal}, + {401, Status::WellKnownGrpcStatus::Unauthenticated}, + {403, Status::WellKnownGrpcStatus::PermissionDenied}, + {404, Status::WellKnownGrpcStatus::Unimplemented}, + {429, Status::WellKnownGrpcStatus::Unavailable}, + {502, Status::WellKnownGrpcStatus::Unavailable}, + {503, Status::WellKnownGrpcStatus::Unavailable}, + {504, Status::WellKnownGrpcStatus::Unavailable}, + {500, Status::WellKnownGrpcStatus::Unknown}, }; for (const auto& test_case : test_set) { EXPECT_EQ(test_case.second, Grpc::Utility::httpToGrpcStatus(test_case.first)); diff --git a/test/common/grpc/google_async_client_impl_test.cc b/test/common/grpc/google_async_client_impl_test.cc index ffc9c395fc843..40a7d02da2dab 100644 --- a/test/common/grpc/google_async_client_impl_test.cc +++ b/test/common/grpc/google_async_client_impl_test.cc @@ -78,7 +78,7 @@ TEST_F(EnvoyGoogleAsyncClientImplTest, StreamHttpStartFail) { MockAsyncStreamCallbacks grpc_callbacks; EXPECT_CALL(grpc_callbacks, onCreateInitialMetadata(_)); EXPECT_CALL(grpc_callbacks, onReceiveTrailingMetadata_(_)); - EXPECT_CALL(grpc_callbacks, onRemoteClose(Status::GrpcStatus::Unavailable, "")); + EXPECT_CALL(grpc_callbacks, onRemoteClose(Status::WellKnownGrpcStatus::Unavailable, "")); auto grpc_stream = grpc_client_->start(*method_descriptor_, grpc_callbacks, Http::AsyncClient::StreamOptions()); EXPECT_TRUE(grpc_stream == nullptr); @@ -90,7 +90,7 @@ TEST_F(EnvoyGoogleAsyncClientImplTest, RequestHttpStartFail) { EXPECT_CALL(*stub_factory_.stub_, PrepareCall_(_, _, _)).WillOnce(Return(nullptr)); MockAsyncRequestCallbacks grpc_callbacks; EXPECT_CALL(grpc_callbacks, onCreateInitialMetadata(_)); - EXPECT_CALL(grpc_callbacks, onFailure(Status::GrpcStatus::Unavailable, "", _)); + EXPECT_CALL(grpc_callbacks, onFailure(Status::WellKnownGrpcStatus::Unavailable, "", _)); helloworld::HelloRequest request_msg; Tracing::MockSpan active_span; diff --git a/test/common/grpc/grpc_client_integration_test.cc b/test/common/grpc/grpc_client_integration_test.cc index f0dbc9690f176..d2c93021882f0 100644 --- a/test/common/grpc/grpc_client_integration_test.cc +++ b/test/common/grpc/grpc_client_integration_test.cc @@ -25,7 +25,7 @@ TEST_P(GrpcClientIntegrationTest, BasicStream) { stream->sendRequest(); stream->sendServerInitialMetadata(empty_metadata_); stream->sendReply(); - stream->sendServerTrailers(Status::GrpcStatus::Ok, "", empty_metadata_); + stream->sendServerTrailers(Status::WellKnownGrpcStatus::Ok, "", empty_metadata_); dispatcher_helper_.runDispatcher(); } @@ -54,8 +54,8 @@ TEST_P(GrpcClientIntegrationTest, MultiStream) { stream_1->sendRequest(); stream_0->sendServerInitialMetadata(empty_metadata_); stream_0->sendReply(); - stream_1->sendServerTrailers(Status::GrpcStatus::Unavailable, "", empty_metadata_, true); - stream_0->sendServerTrailers(Status::GrpcStatus::Ok, "", empty_metadata_); + stream_1->sendServerTrailers(Status::WellKnownGrpcStatus::Unavailable, "", empty_metadata_, true); + stream_0->sendServerTrailers(Status::WellKnownGrpcStatus::Ok, "", empty_metadata_); dispatcher_helper_.runDispatcher(); } @@ -80,8 +80,8 @@ TEST_P(GrpcClientIntegrationTest, HttpNon200Status) { // Technically this should be // https://github.com/grpc/grpc/blob/master/doc/http-grpc-status-mapping.md // as given by Grpc::Utility::httpToGrpcStatus(), but the Google gRPC client treats - // this as GrpcStatus::Canceled. - stream->expectGrpcStatus(Status::GrpcStatus::Canceled); + // this as WellKnownGrpcStatus::Canceled. + stream->expectGrpcStatus(Status::WellKnownGrpcStatus::Canceled); stream->fake_stream_->encodeHeaders(reply_headers, true); dispatcher_helper_.runDispatcher(); } @@ -93,11 +93,11 @@ TEST_P(GrpcClientIntegrationTest, GrpcStatusFallback) { auto stream = createStream(empty_metadata_); const Http::TestHeaderMapImpl reply_headers{ {":status", "404"}, - {"grpc-status", std::to_string(enumToInt(Status::GrpcStatus::PermissionDenied))}, + {"grpc-status", std::to_string(enumToInt(Status::WellKnownGrpcStatus::PermissionDenied))}, {"grpc-message", "error message"}}; stream->expectInitialMetadata(empty_metadata_); stream->expectTrailingMetadata(empty_metadata_); - stream->expectGrpcStatus(Status::GrpcStatus::PermissionDenied); + stream->expectGrpcStatus(Status::WellKnownGrpcStatus::PermissionDenied); stream->fake_stream_->encodeHeaders(reply_headers, true); dispatcher_helper_.runDispatcher(); } @@ -109,7 +109,7 @@ TEST_P(GrpcClientIntegrationTest, HttpReset) { stream->sendServerInitialMetadata(empty_metadata_); dispatcher_helper_.runDispatcher(); stream->expectTrailingMetadata(empty_metadata_); - stream->expectGrpcStatus(Status::GrpcStatus::Internal); + stream->expectGrpcStatus(Status::WellKnownGrpcStatus::Internal); stream->fake_stream_->encodeResetStream(); dispatcher_helper_.runDispatcher(); } @@ -125,7 +125,7 @@ TEST_P(GrpcClientIntegrationTest, BadReplyGrpcFraming) { stream->sendRequest(); stream->sendServerInitialMetadata(empty_metadata_); stream->expectTrailingMetadata(empty_metadata_); - stream->expectGrpcStatus(Status::GrpcStatus::Internal); + stream->expectGrpcStatus(Status::WellKnownGrpcStatus::Internal); Buffer::OwnedImpl reply_buffer("\xde\xad\xbe\xef\x00", 5); stream->fake_stream_->encodeData(reply_buffer, true); dispatcher_helper_.runDispatcher(); @@ -138,7 +138,7 @@ TEST_P(GrpcClientIntegrationTest, BadReplyProtobuf) { stream->sendRequest(); stream->sendServerInitialMetadata(empty_metadata_); stream->expectTrailingMetadata(empty_metadata_); - stream->expectGrpcStatus(Status::GrpcStatus::Internal); + stream->expectGrpcStatus(Status::WellKnownGrpcStatus::Internal); Buffer::OwnedImpl reply_buffer("\x00\x00\x00\x00\x02\xff\xff", 7); stream->fake_stream_->encodeData(reply_buffer, true); dispatcher_helper_.runDispatcher(); @@ -174,7 +174,7 @@ TEST_P(GrpcClientIntegrationTest, OutOfRangeGrpcStatus) { stream->sendReply(); EXPECT_CALL(*stream, onReceiveTrailingMetadata_(_)).WillExitIfNeeded(); dispatcher_helper_.setStreamEventPending(); - stream->expectGrpcStatus(Status::GrpcStatus::InvalidCode); + stream->expectGrpcStatus(Status::WellKnownGrpcStatus::InvalidCode); const Http::TestHeaderMapImpl reply_trailers{{"grpc-status", std::to_string(0x1337)}}; stream->fake_stream_->encodeTrailers(reply_trailers); dispatcher_helper_.runDispatcher(); @@ -188,7 +188,7 @@ TEST_P(GrpcClientIntegrationTest, MissingGrpcStatus) { stream->sendReply(); EXPECT_CALL(*stream, onReceiveTrailingMetadata_(_)).WillExitIfNeeded(); dispatcher_helper_.setStreamEventPending(); - stream->expectGrpcStatus(Status::GrpcStatus::Unknown); + stream->expectGrpcStatus(Status::WellKnownGrpcStatus::Unknown); const Http::TestHeaderMapImpl reply_trailers{{"some", "other header"}}; stream->fake_stream_->encodeTrailers(reply_trailers); dispatcher_helper_.runDispatcher(); @@ -205,7 +205,7 @@ TEST_P(GrpcClientIntegrationTest, ReplyNoTrailers) { EXPECT_CALL(*stream, onReceiveMessage_(HelloworldReplyEq(HELLO_REPLY))).WillExitIfNeeded(); dispatcher_helper_.setStreamEventPending(); stream->expectTrailingMetadata(empty_metadata_); - stream->expectGrpcStatus(Status::GrpcStatus::InvalidCode); + stream->expectGrpcStatus(Status::WellKnownGrpcStatus::InvalidCode); auto serialized_response = Grpc::Common::serializeToGrpcFrame(reply); stream->fake_stream_->encodeData(*serialized_response, true); stream->fake_stream_->encodeResetStream(); @@ -220,7 +220,7 @@ TEST_P(GrpcClientIntegrationTest, StreamClientInitialMetadata) { {Http::LowerCaseString("baz"), "blah"}, }; auto stream = createStream(initial_metadata); - stream->sendServerTrailers(Status::GrpcStatus::Ok, "", empty_metadata_, true); + stream->sendServerTrailers(Status::WellKnownGrpcStatus::Ok, "", empty_metadata_, true); dispatcher_helper_.runDispatcher(); } @@ -258,7 +258,7 @@ TEST_P(GrpcClientIntegrationTest, ServerInitialMetadata) { }; stream->sendServerInitialMetadata(initial_metadata); stream->sendReply(); - stream->sendServerTrailers(Status::GrpcStatus::Ok, "", empty_metadata_); + stream->sendServerTrailers(Status::WellKnownGrpcStatus::Ok, "", empty_metadata_); dispatcher_helper_.runDispatcher(); } @@ -273,7 +273,7 @@ TEST_P(GrpcClientIntegrationTest, ServerTrailingMetadata) { {Http::LowerCaseString("foo"), "bar"}, {Http::LowerCaseString("baz"), "blah"}, }; - stream->sendServerTrailers(Status::GrpcStatus::Ok, "", trailing_metadata); + stream->sendServerTrailers(Status::WellKnownGrpcStatus::Ok, "", trailing_metadata); dispatcher_helper_.runDispatcher(); } @@ -281,7 +281,7 @@ TEST_P(GrpcClientIntegrationTest, ServerTrailingMetadata) { TEST_P(GrpcClientIntegrationTest, StreamTrailersOnly) { initialize(); auto stream = createStream(empty_metadata_); - stream->sendServerTrailers(Status::GrpcStatus::Ok, "", empty_metadata_, true); + stream->sendServerTrailers(Status::WellKnownGrpcStatus::Ok, "", empty_metadata_, true); dispatcher_helper_.runDispatcher(); } @@ -308,7 +308,7 @@ TEST_P(GrpcClientIntegrationTest, ResourceExhaustedError) { stream->sendServerInitialMetadata(empty_metadata_); stream->sendReply(); dispatcher_helper_.runDispatcher(); - stream->sendServerTrailers(Status::GrpcStatus::ResourceExhausted, "error message", + stream->sendServerTrailers(Status::WellKnownGrpcStatus::ResourceExhausted, "error message", empty_metadata_); dispatcher_helper_.runDispatcher(); } @@ -318,18 +318,20 @@ TEST_P(GrpcClientIntegrationTest, UnauthenticatedError) { initialize(); auto stream = createStream(empty_metadata_); stream->sendServerInitialMetadata(empty_metadata_); - stream->sendServerTrailers(Status::GrpcStatus::Unauthenticated, "error message", empty_metadata_); + stream->sendServerTrailers(Status::WellKnownGrpcStatus::Unauthenticated, "error message", + empty_metadata_); dispatcher_helper_.runDispatcher(); } // Validate that a trailers reply is still handled even if a grpc status code larger than -// MaximumValid, is handled. -TEST_P(GrpcClientIntegrationTest, MaximumValidPlusOne) { +// MaximumKnown, is handled. +TEST_P(GrpcClientIntegrationTest, MaximumKnownPlusOne) { initialize(); auto stream = createStream(empty_metadata_); stream->sendServerInitialMetadata(empty_metadata_); - stream->sendServerTrailers(static_cast(Status::GrpcStatus::MaximumValid + 1), - "error message", empty_metadata_); + stream->sendServerTrailers( + static_cast(Status::WellKnownGrpcStatus::MaximumKnown + 1), + "error message", empty_metadata_); dispatcher_helper_.runDispatcher(); } @@ -340,7 +342,7 @@ TEST_P(GrpcClientIntegrationTest, ReceiveAfterLocalClose) { stream->sendRequest(true); stream->sendServerInitialMetadata(empty_metadata_); stream->sendReply(); - stream->sendServerTrailers(Status::GrpcStatus::Ok, "", empty_metadata_); + stream->sendServerTrailers(Status::WellKnownGrpcStatus::Ok, "", empty_metadata_); dispatcher_helper_.runDispatcher(); } @@ -458,7 +460,7 @@ TEST_P(GrpcAccessTokenClientIntegrationTest, AccessTokenAuthStream) { stream->sendServerInitialMetadata(empty_metadata_); stream->sendRequest(); stream->sendReply(); - stream->sendServerTrailers(Status::GrpcStatus::Ok, "", empty_metadata_); + stream->sendServerTrailers(Status::WellKnownGrpcStatus::Ok, "", empty_metadata_); dispatcher_helper_.runDispatcher(); } diff --git a/test/common/grpc/grpc_client_integration_test_harness.h b/test/common/grpc/grpc_client_integration_test_harness.h index cb9dc9fa3ceec..8b37766adb6d8 100644 --- a/test/common/grpc/grpc_client_integration_test_harness.h +++ b/test/common/grpc/grpc_client_integration_test_harness.h @@ -148,10 +148,11 @@ class HelloworldStream : public MockAsyncStreamCallbacks } void expectGrpcStatus(Status::GrpcStatus grpc_status) { - if (grpc_status == Status::GrpcStatus::InvalidCode) { + if (grpc_status == Status::WellKnownGrpcStatus::InvalidCode) { EXPECT_CALL(*this, onRemoteClose(_, _)).WillExitIfNeeded(); - } else if (grpc_status > Status::GrpcStatus::MaximumValid) { - EXPECT_CALL(*this, onRemoteClose(Status::GrpcStatus::InvalidCode, _)).WillExitIfNeeded(); + } else if (grpc_status > Status::WellKnownGrpcStatus::MaximumKnown) { + EXPECT_CALL(*this, onRemoteClose(Status::WellKnownGrpcStatus::InvalidCode, _)) + .WillExitIfNeeded(); } else { EXPECT_CALL(*this, onRemoteClose(grpc_status, _)).WillExitIfNeeded(); } diff --git a/test/common/http/utility_test.cc b/test/common/http/utility_test.cc index a9f96f315aebd..67585504416ee 100644 --- a/test/common/http/utility_test.cc +++ b/test/common/http/utility_test.cc @@ -457,7 +457,7 @@ TEST(HttpUtility, SendLocalGrpcReply) { EXPECT_EQ(headers.Status()->value().getStringView(), "200"); EXPECT_NE(headers.GrpcStatus(), nullptr); EXPECT_EQ(headers.GrpcStatus()->value().getStringView(), - std::to_string(enumToInt(Grpc::Status::GrpcStatus::Unknown))); + std::to_string(enumToInt(Grpc::Status::WellKnownGrpcStatus::Unknown))); EXPECT_NE(headers.GrpcMessage(), nullptr); EXPECT_EQ(headers.GrpcMessage()->value().getStringView(), "large"); })); @@ -483,7 +483,7 @@ TEST(HttpUtility, SendLocalGrpcReplyWithUpstreamJsonPayload) { EXPECT_EQ(headers.Status()->value().getStringView(), "200"); EXPECT_NE(headers.GrpcStatus(), nullptr); EXPECT_EQ(headers.GrpcStatus()->value().getStringView(), - std::to_string(enumToInt(Grpc::Status::GrpcStatus::Unauthenticated))); + std::to_string(enumToInt(Grpc::Status::WellKnownGrpcStatus::Unauthenticated))); EXPECT_NE(headers.GrpcMessage(), nullptr); const auto& encoded = Utility::PercentEncoding::encode(json); EXPECT_EQ(headers.GrpcMessage()->value().getStringView(), encoded); @@ -499,7 +499,7 @@ TEST(HttpUtility, RateLimitedGrpcStatus) { .WillOnce(Invoke([&](const HeaderMap& headers, bool) -> void { EXPECT_NE(headers.GrpcStatus(), nullptr); EXPECT_EQ(headers.GrpcStatus()->value().getStringView(), - std::to_string(enumToInt(Grpc::Status::GrpcStatus::Unavailable))); + std::to_string(enumToInt(Grpc::Status::WellKnownGrpcStatus::Unavailable))); })); Utility::sendLocalReply(true, callbacks, false, Http::Code::TooManyRequests, "", absl::nullopt, false); @@ -508,12 +508,12 @@ TEST(HttpUtility, RateLimitedGrpcStatus) { .WillOnce(Invoke([&](const HeaderMap& headers, bool) -> void { EXPECT_NE(headers.GrpcStatus(), nullptr); EXPECT_EQ(headers.GrpcStatus()->value().getStringView(), - std::to_string(enumToInt(Grpc::Status::GrpcStatus::ResourceExhausted))); + std::to_string(enumToInt(Grpc::Status::WellKnownGrpcStatus::ResourceExhausted))); })); - Utility::sendLocalReply( - true, callbacks, false, Http::Code::TooManyRequests, "", - absl::make_optional(Grpc::Status::GrpcStatus::ResourceExhausted), - false); + Utility::sendLocalReply(true, callbacks, false, Http::Code::TooManyRequests, "", + absl::make_optional( + Grpc::Status::WellKnownGrpcStatus::ResourceExhausted), + false); } TEST(HttpUtility, SendLocalReplyDestroyedEarly) { diff --git a/test/common/upstream/load_stats_reporter_test.cc b/test/common/upstream/load_stats_reporter_test.cc index 519c4fafc50a3..fe22e4a4c3567 100644 --- a/test/common/upstream/load_stats_reporter_test.cc +++ b/test/common/upstream/load_stats_reporter_test.cc @@ -223,7 +223,7 @@ TEST_F(LoadStatsReporterTest, RemoteStreamClose) { createLoadStatsReporter(); EXPECT_CALL(*response_timer_, disableTimer()); EXPECT_CALL(*retry_timer_, enableTimer(_, _)); - load_stats_reporter_->onRemoteClose(Grpc::Status::GrpcStatus::Canceled, ""); + load_stats_reporter_->onRemoteClose(Grpc::Status::WellKnownGrpcStatus::Canceled, ""); EXPECT_CALL(*async_client_, startRaw(_, _, _, _)).WillOnce(Return(&async_stream_)); expectSendMessage({}); retry_timer_cb_(); diff --git a/test/extensions/filters/common/ext_authz/ext_authz_grpc_impl_test.cc b/test/extensions/filters/common/ext_authz/ext_authz_grpc_impl_test.cc index 89fe617e87a44..832467749e3c7 100644 --- a/test/extensions/filters/common/ext_authz/ext_authz_grpc_impl_test.cc +++ b/test/extensions/filters/common/ext_authz/ext_authz_grpc_impl_test.cc @@ -74,7 +74,7 @@ TEST_P(ExtAuthzGrpcClientTest, AuthorizationOk) { auto check_response = std::make_unique(); auto status = check_response->mutable_status(); - status->set_code(Grpc::Status::GrpcStatus::Ok); + status->set_code(Grpc::Status::WellKnownGrpcStatus::Ok); auto authz_response = Response{}; authz_response.status = CheckStatus::OK; @@ -97,8 +97,9 @@ TEST_P(ExtAuthzGrpcClientTest, AuthorizationOkWithAllAtributes) { const std::string empty_body{}; const auto expected_headers = TestCommon::makeHeaderValueOption({{"foo", "bar", false}}); - auto check_response = TestCommon::makeCheckResponse( - Grpc::Status::GrpcStatus::Ok, envoy::type::StatusCode::OK, empty_body, expected_headers); + auto check_response = + TestCommon::makeCheckResponse(Grpc::Status::WellKnownGrpcStatus::Ok, + envoy::type::StatusCode::OK, empty_body, expected_headers); auto authz_response = TestCommon::makeAuthzResponse(CheckStatus::OK, Http::Code::OK, empty_body, expected_headers); @@ -121,7 +122,7 @@ TEST_P(ExtAuthzGrpcClientTest, AuthorizationDenied) { auto check_response = std::make_unique(); auto status = check_response->mutable_status(); - status->set_code(Grpc::Status::GrpcStatus::PermissionDenied); + status->set_code(Grpc::Status::WellKnownGrpcStatus::PermissionDenied); auto authz_response = Response{}; authz_response.status = CheckStatus::Denied; @@ -145,7 +146,7 @@ TEST_P(ExtAuthzGrpcClientTest, AuthorizationDeniedGrpcUnknownStatus) { auto check_response = std::make_unique(); auto status = check_response->mutable_status(); - status->set_code(Grpc::Status::GrpcStatus::Unknown); + status->set_code(Grpc::Status::WellKnownGrpcStatus::Unknown); auto authz_response = Response{}; authz_response.status = CheckStatus::Denied; @@ -170,9 +171,9 @@ TEST_P(ExtAuthzGrpcClientTest, AuthorizationDeniedWithAllAttributes) { const std::string expected_body{"test"}; const auto expected_headers = TestCommon::makeHeaderValueOption({{"foo", "bar", false}, {"foobar", "bar", true}}); - auto check_response = TestCommon::makeCheckResponse(Grpc::Status::GrpcStatus::PermissionDenied, - envoy::type::StatusCode::Unauthorized, - expected_body, expected_headers); + auto check_response = TestCommon::makeCheckResponse( + Grpc::Status::WellKnownGrpcStatus::PermissionDenied, envoy::type::StatusCode::Unauthorized, + expected_body, expected_headers); auto authz_response = TestCommon::makeAuthzResponse(CheckStatus::Denied, Http::Code::Unauthorized, expected_body, expected_headers); diff --git a/test/extensions/filters/common/ext_authz/test_common.cc b/test/extensions/filters/common/ext_authz/test_common.cc index a4b1dfe1ea330..50eaf9434ec46 100644 --- a/test/extensions/filters/common/ext_authz/test_common.cc +++ b/test/extensions/filters/common/ext_authz/test_common.cc @@ -18,7 +18,7 @@ CheckResponsePtr TestCommon::makeCheckResponse(Grpc::Status::GrpcStatus response auto status = response->mutable_status(); status->set_code(response_status); - if (response_status != Grpc::Status::GrpcStatus::Ok) { + if (response_status != Grpc::Status::WellKnownGrpcStatus::Ok) { const auto denied_response = response->mutable_denied_response(); if (!body.empty()) { denied_response->set_body(body); diff --git a/test/extensions/filters/common/ext_authz/test_common.h b/test/extensions/filters/common/ext_authz/test_common.h index 17d75d7e89f35..2ac2d0e7331d1 100644 --- a/test/extensions/filters/common/ext_authz/test_common.h +++ b/test/extensions/filters/common/ext_authz/test_common.h @@ -29,11 +29,11 @@ class TestCommon { static Http::MessagePtr makeMessageResponse(const HeaderValueOptionVector& headers, const std::string& body = std::string{}); - static CheckResponsePtr - makeCheckResponse(Grpc::Status::GrpcStatus response_status = Grpc::Status::GrpcStatus::Ok, - envoy::type::StatusCode http_status_code = envoy::type::StatusCode::OK, - const std::string& body = std::string{}, - const HeaderValueOptionVector& headers = HeaderValueOptionVector{}); + static CheckResponsePtr makeCheckResponse( + Grpc::Status::GrpcStatus response_status = Grpc::Status::WellKnownGrpcStatus::Ok, + envoy::type::StatusCode http_status_code = envoy::type::StatusCode::OK, + const std::string& body = std::string{}, + const HeaderValueOptionVector& headers = HeaderValueOptionVector{}); static Response makeAuthzResponse(CheckStatus status, Http::Code status_code = Http::Code::OK, diff --git a/test/integration/ads_integration_test.cc b/test/integration/ads_integration_test.cc index 548ee0f33fbd9..56e7b33be962b 100644 --- a/test/integration/ads_integration_test.cc +++ b/test/integration/ads_integration_test.cc @@ -55,7 +55,8 @@ TEST_P(AdsIntegrationTest, Failure) { EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Listener, "", {}, {}, {})); EXPECT_TRUE(compareDiscoveryRequest( - Config::TypeUrl::get().Cluster, "", {}, {}, {}, true, Grpc::Status::GrpcStatus::Internal, + Config::TypeUrl::get().Cluster, "", {}, {}, {}, true, + Grpc::Status::WellKnownGrpcStatus::Internal, fmt::format("does not match the message-wide type URL {}", Config::TypeUrl::get().Cluster))); sendDiscoveryResponse(Config::TypeUrl::get().Cluster, {buildCluster("cluster_0")}, @@ -70,7 +71,7 @@ TEST_P(AdsIntegrationTest, Failure) { EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "1", {}, {}, {})); EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "", {"cluster_0"}, {}, {}, true, - Grpc::Status::GrpcStatus::Internal, + Grpc::Status::WellKnownGrpcStatus::Internal, fmt::format("does not match the message-wide type URL {}", Config::TypeUrl::get().ClusterLoadAssignment))); sendDiscoveryResponse( @@ -84,7 +85,8 @@ TEST_P(AdsIntegrationTest, Failure) { {buildRouteConfig("listener_0", "route_config_0")}, {}, "1"); EXPECT_TRUE(compareDiscoveryRequest( - Config::TypeUrl::get().Listener, "", {}, {}, {}, true, Grpc::Status::GrpcStatus::Internal, + Config::TypeUrl::get().Listener, "", {}, {}, {}, true, + Grpc::Status::WellKnownGrpcStatus::Internal, fmt::format("does not match the message-wide type URL {}", Config::TypeUrl::get().Listener))); sendDiscoveryResponse( Config::TypeUrl::get().Listener, {buildListener("listener_0", "route_config_0")}, @@ -99,7 +101,7 @@ TEST_P(AdsIntegrationTest, Failure) { EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Listener, "1", {}, {}, {})); EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().RouteConfiguration, "", {"route_config_0"}, {}, {}, true, - Grpc::Status::GrpcStatus::Internal, + Grpc::Status::WellKnownGrpcStatus::Internal, fmt::format("does not match the message-wide type URL {}", Config::TypeUrl::get().RouteConfiguration))); sendDiscoveryResponse( diff --git a/test/integration/integration.cc b/test/integration/integration.cc index 6d02fe346c221..2d6f441d3ff3d 100644 --- a/test/integration/integration.cc +++ b/test/integration/integration.cc @@ -672,7 +672,7 @@ AssertionResult BaseIntegrationTest::compareDeltaDiscoveryRequest( request.error_detail().code(), expected_error_code, request.error_detail().message()); } - if (expected_error_code != Grpc::Status::GrpcStatus::Ok && + if (expected_error_code != Grpc::Status::WellKnownGrpcStatus::Ok && request.error_detail().message().find(expected_error_substring) == std::string::npos) { return AssertionFailure() << "\"" << expected_error_substring << "\" is not a substring of actual error message \"" diff --git a/test/integration/integration.h b/test/integration/integration.h index 3cdabb86abfbe..5b4d476ba182a 100644 --- a/test/integration/integration.h +++ b/test/integration/integration.h @@ -222,14 +222,13 @@ class BaseIntegrationTest : Logger::Loggable { // available if you're writing a SotW/delta-specific test. // TODO(fredlas) expect_node was defaulting false here; the delta+SotW unification work restores // it. - AssertionResult - compareDiscoveryRequest(const std::string& expected_type_url, const std::string& expected_version, - const std::vector& expected_resource_names, - const std::vector& expected_resource_names_added, - const std::vector& expected_resource_names_removed, - bool expect_node = true, - const Protobuf::int32 expected_error_code = Grpc::Status::GrpcStatus::Ok, - const std::string& expected_error_message = ""); + AssertionResult compareDiscoveryRequest( + const std::string& expected_type_url, const std::string& expected_version, + const std::vector& expected_resource_names, + const std::vector& expected_resource_names_added, + const std::vector& expected_resource_names_removed, bool expect_node = true, + const Protobuf::int32 expected_error_code = Grpc::Status::WellKnownGrpcStatus::Ok, + const std::string& expected_error_message = ""); template void sendDiscoveryResponse(const std::string& type_url, const std::vector& state_of_the_world, const std::vector& added_or_updated, @@ -245,7 +244,7 @@ class BaseIntegrationTest : Logger::Loggable { const std::string& expected_type_url, const std::vector& expected_resource_subscriptions, const std::vector& expected_resource_unsubscriptions, - const Protobuf::int32 expected_error_code = Grpc::Status::GrpcStatus::Ok, + const Protobuf::int32 expected_error_code = Grpc::Status::WellKnownGrpcStatus::Ok, const std::string& expected_error_message = "") { return compareDeltaDiscoveryRequest(expected_type_url, expected_resource_subscriptions, expected_resource_unsubscriptions, xds_stream_, @@ -256,7 +255,7 @@ class BaseIntegrationTest : Logger::Loggable { const std::string& expected_type_url, const std::vector& expected_resource_subscriptions, const std::vector& expected_resource_unsubscriptions, FakeStreamPtr& stream, - const Protobuf::int32 expected_error_code = Grpc::Status::GrpcStatus::Ok, + const Protobuf::int32 expected_error_code = Grpc::Status::WellKnownGrpcStatus::Ok, const std::string& expected_error_message = ""); // TODO(fredlas) expect_node was defaulting false here; the delta+SotW unification work restores @@ -264,7 +263,7 @@ class BaseIntegrationTest : Logger::Loggable { AssertionResult compareSotwDiscoveryRequest( const std::string& expected_type_url, const std::string& expected_version, const std::vector& expected_resource_names, bool expect_node = true, - const Protobuf::int32 expected_error_code = Grpc::Status::GrpcStatus::Ok, + const Protobuf::int32 expected_error_code = Grpc::Status::WellKnownGrpcStatus::Ok, const std::string& expected_error_message = ""); template