From 591e0dc2da7c4f91b6bd65f9558ea0d1064af07b Mon Sep 17 00:00:00 2001 From: Rei Shimizu Date: Tue, 26 Jan 2021 17:32:37 +0900 Subject: [PATCH] disentangle grpc deps from skywalking data definition (#54) * disentangle grpc deps from skywalking data definition * fix * fix --- .bazelversion | 1 + cpp2sky/BUILD | 16 ------- cpp2sky/internal/BUILD | 24 ++++++++++ source/BUILD | 2 +- source/grpc_async_client_impl.cc | 1 - source/utils/BUILD | 3 +- source/utils/grpc_status.h | 82 -------------------------------- test/BUILD | 3 +- 8 files changed, 29 insertions(+), 103 deletions(-) create mode 100644 .bazelversion create mode 100644 cpp2sky/internal/BUILD delete mode 100644 source/utils/grpc_status.h diff --git a/.bazelversion b/.bazelversion new file mode 100644 index 0000000..0b2eb36 --- /dev/null +++ b/.bazelversion @@ -0,0 +1 @@ +3.7.2 diff --git a/cpp2sky/BUILD b/cpp2sky/BUILD index 575a6fd..76c47e8 100644 --- a/cpp2sky/BUILD +++ b/cpp2sky/BUILD @@ -25,22 +25,6 @@ cc_library( "time.h", ], deps = [ - "@com_github_grpc_grpc//:grpc++", - "@skywalking_data_collect_protocol//language-agent:tracing_protocol_cc_grpc", - ":config_cc_proto", - ], - visibility = ["//visibility:public"], -) - -cc_library( - name = "cpp2sky_internal_interface", - hdrs = [ - "internal/async_client.h", - "internal/random_generator.h", - ], - deps = [ - "@com_github_grpc_grpc//:grpc++", - "@skywalking_data_collect_protocol//language-agent:tracing_protocol_cc_grpc", ":config_cc_proto", ], visibility = ["//visibility:public"], diff --git a/cpp2sky/internal/BUILD b/cpp2sky/internal/BUILD new file mode 100644 index 0000000..8e119a4 --- /dev/null +++ b/cpp2sky/internal/BUILD @@ -0,0 +1,24 @@ +load("@rules_cc//cc:defs.bzl", "cc_library", "cc_proto_library") +load("@rules_proto//proto:defs.bzl", "proto_library") + +licenses(["notice"]) # Apache 2 + +cc_library( + name = "async_client_interface", + hdrs = [ + "async_client.h", + ], + deps = [ + "@com_github_grpc_grpc//:grpc++", + "@skywalking_data_collect_protocol//language-agent:tracing_protocol_cc_grpc", + ], + visibility = ["//visibility:public"], +) + +cc_library( + name = "random_generator_interface", + hdrs = [ + "random_generator.h", + ], + visibility = ["//visibility:public"], +) diff --git a/source/BUILD b/source/BUILD index 263c1c6..b62e037 100644 --- a/source/BUILD +++ b/source/BUILD @@ -18,8 +18,8 @@ cc_library( "@skywalking_data_collect_protocol//language-agent:tracing_protocol_cc_proto", "@skywalking_data_collect_protocol//language-agent:tracing_protocol_cc_grpc", "@com_github_grpc_grpc//:grpc++", + "//cpp2sky/internal:async_client_interface", "//cpp2sky:cpp2sky_interface", - "//cpp2sky:cpp2sky_internal_interface", "//source/utils:util_lib", ], visibility = ["//visibility:public"], diff --git a/source/grpc_async_client_impl.cc b/source/grpc_async_client_impl.cc index bcfc1b3..f50fcd0 100644 --- a/source/grpc_async_client_impl.cc +++ b/source/grpc_async_client_impl.cc @@ -19,7 +19,6 @@ #include #include "cpp2sky/exception.h" -#include "utils/grpc_status.h" namespace cpp2sky { diff --git a/source/utils/BUILD b/source/utils/BUILD index 5663673..4b5528f 100644 --- a/source/utils/BUILD +++ b/source/utils/BUILD @@ -5,11 +5,10 @@ cc_library( hdrs = [ "base64.h", "random_generator.h", - "grpc_status.h", "circular_buffer.h", ], deps = [ - "//cpp2sky:cpp2sky_internal_interface", + "//cpp2sky/internal:random_generator_interface", ], visibility = ["//visibility:public"], ) diff --git a/source/utils/grpc_status.h b/source/utils/grpc_status.h deleted file mode 100644 index a97f2b2..0000000 --- a/source/utils/grpc_status.h +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2020 SkyAPM - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 - -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -#pragma once - -#include - -namespace cpp2sky { - -// Based on: -// https://github.com/envoyproxy/envoy/blob/master/source/common/grpc/status.cc -uint16_t grpcStatusToGenericHttpStatus(grpc::StatusCode status) { - switch (status) { - case grpc::StatusCode::OK: - return 200; - case grpc::StatusCode::CANCELLED: - // Client closed request. - return 499; - case grpc::StatusCode::UNKNOWN: - // Internal server error. - return 500; - case grpc::StatusCode::INVALID_ARGUMENT: - // Bad request. - return 400; - case grpc::StatusCode::DEADLINE_EXCEEDED: - // Gateway Time-out. - return 504; - case grpc::StatusCode::NOT_FOUND: - // Not found. - return 404; - case grpc::StatusCode::ALREADY_EXISTS: - // Conflict. - return 409; - case grpc::StatusCode::PERMISSION_DENIED: - // Forbidden. - return 403; - case grpc::StatusCode::RESOURCE_EXHAUSTED: - // Too many requests. - return 429; - case grpc::StatusCode::FAILED_PRECONDITION: - // Bad request. - return 400; - case grpc::StatusCode::ABORTED: - // Conflict. - return 409; - case grpc::StatusCode::OUT_OF_RANGE: - // Bad request. - return 400; - case grpc::StatusCode::UNIMPLEMENTED: - // Not implemented. - return 501; - case grpc::StatusCode::INTERNAL: - // Internal server error. - return 500; - case grpc::StatusCode::UNAVAILABLE: - // Service unavailable. - return 503; - case grpc::StatusCode::DATA_LOSS: - // Internal server error. - return 500; - case grpc::StatusCode::UNAUTHENTICATED: - // Unauthorized. - return 401; - default: - // Internal server error. - return 500; - } -} - -} // namespace cpp2sky diff --git a/test/BUILD b/test/BUILD index 88a000b..23fc11d 100644 --- a/test/BUILD +++ b/test/BUILD @@ -8,7 +8,8 @@ cc_library( deps = [ "@skywalking_data_collect_protocol//language-agent:tracing_protocol_cc_proto", "@com_google_googletest//:gtest_main", - "//cpp2sky:cpp2sky_internal_interface", + "//cpp2sky/internal:async_client_interface", + "//cpp2sky/internal:random_generator_interface", ] )