Skip to content

Commit

Permalink
Use check response status. (envoyproxy#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
qiwzhang authored Jun 1, 2017
1 parent 5ed8205 commit a1882dc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
14 changes: 5 additions & 9 deletions mixerclient/src/client_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ using ::google::protobuf::util::error::Code;

namespace istio {
namespace mixer_client {
namespace {
bool IsNetworkError(Status status) {
return status.error_code() == Code::UNAVAILABLE;
}
} // namespace

MixerClientImpl::MixerClientImpl(const MixerClientOptions &options)
: options_(options), converter_({}) {
Expand All @@ -55,17 +50,18 @@ void MixerClientImpl::Check(const Attributes &attributes, DoneFunc on_done) {
auto response = new CheckResponse;
options_.check_transport(request, response, [this, signature, response,
on_done](const Status &status) {
delete response;
if (IsNetworkError(status)) {
if (!status.ok()) {
if (options_.check_options.network_fail_open) {
on_done(Status::OK);
} else {
on_done(status);
}
} else {
check_cache_->CacheResponse(signature, status);
on_done(status);
Status resp_status = ConvertRpcStatus(response->status());
check_cache_->CacheResponse(signature, resp_status);
on_done(resp_status);
}
delete response;
});
}

Expand Down
4 changes: 4 additions & 0 deletions mixerclient/utils/protobuf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,9 @@ milliseconds ToMilliseonds(const Duration& duration) {
duration_cast<milliseconds>(nanoseconds(duration.nanos()));
}

Status ConvertRpcStatus(const ::google::rpc::Status& status) {
return Status(static_cast<Code>(status.code()), status.message());
}

} // namespace mixer_client
} // namespace istio
5 changes: 5 additions & 0 deletions mixerclient/utils/protobuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "google/protobuf/duration.pb.h"
#include "google/protobuf/stubs/status.h"
#include "google/protobuf/timestamp.pb.h"
#include "mixer/v1/service.pb.h"

#include <chrono>

Expand All @@ -36,6 +37,10 @@ ::google::protobuf::Duration CreateDuration(std::chrono::nanoseconds value);
std::chrono::milliseconds ToMilliseonds(
const ::google::protobuf::Duration& duration);

// Convert from grpc status to protobuf status.
::google::protobuf::util::Status ConvertRpcStatus(
const ::google::rpc::Status& status);

} // namespace mixer_client
} // namespace istio

Expand Down

0 comments on commit a1882dc

Please sign in to comment.