Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into xds_logging
Browse files Browse the repository at this point in the history
  • Loading branch information
markdroth committed Oct 16, 2020
2 parents 6c982e6 + 09ace01 commit 27795e7
Show file tree
Hide file tree
Showing 26 changed files with 249 additions and 85 deletions.
21 changes: 0 additions & 21 deletions .clang_complete

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -151,3 +151,6 @@ BenchmarkDotNet.Artifacts/

# pyenv config
.python-version

# clang JSON compilation database file
compile_commands.json
11 changes: 11 additions & 0 deletions bazel/grpc_deps.bzl
Expand Up @@ -279,6 +279,17 @@ def grpc_deps():
sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44",
)

if "bazel_compdb" not in native.existing_rules():
http_archive(
name = "bazel_compdb",
sha256 = "bcecfd622c4ef272fd4ba42726a52e140b961c4eac23025f18b346c968a8cfb4",
strip_prefix = "bazel-compilation-database-0.4.5",
urls = [
"https://storage.googleapis.com/grpc-bazel-mirror/github.com/grailbio/bazel-compilation-database/archive/0.4.5.tar.gz",
"https://github.com/grailbio/bazel-compilation-database/archive/0.4.5.tar.gz",
],
)

if "io_opencensus_cpp" not in native.existing_rules():
http_archive(
name = "io_opencensus_cpp",
Expand Down
2 changes: 1 addition & 1 deletion src/python/grpcio/grpc/__init__.py
Expand Up @@ -2125,6 +2125,6 @@ class Compression(enum.IntEnum):
pass

# Prevents import order issue in the case of renamed path.
if sys.version_info >= (3, 6) and __name__ == "grpc.__init__":
if sys.version_info >= (3, 6) and __name__ == "grpc":
from grpc import aio # pylint: disable=ungrouped-imports
sys.modules.update({'grpc.aio': aio})
8 changes: 3 additions & 5 deletions src/python/grpcio_tests/tests_aio/unit/init_test.py
Expand Up @@ -14,17 +14,15 @@
import logging
import unittest

from tests_aio.unit._test_base import AioTestBase

class TestInit(unittest.TestCase):

class TestInit(AioTestBase):

async def test_grpc(self):
def test_grpc(self):
import grpc # pylint: disable=wrong-import-position
channel = grpc.aio.insecure_channel('dummy')
self.assertIsInstance(channel, grpc.aio.Channel)

async def test_grpc_dot_aio(self):
def test_grpc_dot_aio(self):
import grpc.aio # pylint: disable=wrong-import-position
channel = grpc.aio.insecure_channel('dummy')
self.assertIsInstance(channel, grpc.aio.Channel)
Expand Down
Expand Up @@ -20,7 +20,7 @@
# This is because clang-tidy 7.0 started treating compiler errors as tidy errors
# and there are a couple of files which are not properly compiled via tidy so it
# should be using 6.0 version until all compilation errors are addressed.
RUN apt-get update && apt-get install -y clang-tidy-6.0
RUN apt-get update && apt-get install -y clang-tidy-6.0 jq
ENV CLANG_TIDY=clang-tidy-6.0

ADD clang_tidy_all_the_things.sh /
Expand Down
2 changes: 1 addition & 1 deletion templates/tools/dockerfile/test/sanity/Dockerfile.template
Expand Up @@ -40,7 +40,7 @@
# This is because clang-tidy 7.0 started treating compiler errors as tidy errors
# and there are a couple of files which are not properly compiled via tidy so it
# should be using 6.0 version until all compilation errors are addressed.
RUN apt-get install -y clang-tidy-6.0
RUN apt-get install -y clang-tidy-6.0 jq
ENV CLANG_TIDY=clang-tidy-6.0


Expand Down
9 changes: 4 additions & 5 deletions test/cpp/end2end/client_lb_end2end_test.cc
Expand Up @@ -412,7 +412,8 @@ class ClientLbEnd2endTest : public ::testing::Test {
}

bool WaitForChannelState(
Channel* channel, std::function<bool(grpc_connectivity_state)> predicate,
Channel* channel,
const std::function<bool(grpc_connectivity_state)>& predicate,
bool try_to_connect = false, int timeout_seconds = 5) {
const gpr_timespec deadline =
grpc_timeout_seconds_to_deadline(timeout_seconds);
Expand Down Expand Up @@ -1759,13 +1760,11 @@ class ClientLbInterceptTrailingMetadataTest : public ClientLbEnd2endTest {
self->load_report_->set_rps(backend_metric_data->requests_per_second);
for (const auto& p : backend_metric_data->request_cost) {
std::string name = std::string(p.first);
(*self->load_report_->mutable_request_cost())[std::move(name)] =
p.second;
(*self->load_report_->mutable_request_cost())[name] = p.second;
}
for (const auto& p : backend_metric_data->utilization) {
std::string name = std::string(p.first);
(*self->load_report_->mutable_utilization())[std::move(name)] =
p.second;
(*self->load_report_->mutable_utilization())[name] = p.second;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/cpp/end2end/message_allocator_end2end_test.cc
Expand Up @@ -69,7 +69,7 @@ class CallbackTestServiceImpl
std::function<void(experimental::RpcAllocatorState* allocator_state,
const EchoRequest* req, EchoResponse* resp)>
mutator) {
allocator_mutator_ = mutator;
allocator_mutator_ = std::move(mutator);
}

experimental::ServerUnaryReactor* Echo(
Expand Down
5 changes: 3 additions & 2 deletions test/cpp/end2end/xds_end2end_test.cc
Expand Up @@ -440,7 +440,7 @@ class AdsServiceImpl : public std::enable_shared_from_this<AdsServiceImpl> {

struct EdsResourceArgs {
struct Locality {
Locality(const std::string& sub_zone, std::vector<int> ports,
Locality(std::string sub_zone, std::vector<int> ports,
int lb_weight = kDefaultLocalityWeight,
int priority = kDefaultLocalityPriority,
std::vector<HealthStatus> health_statuses = {})
Expand Down Expand Up @@ -1508,7 +1508,7 @@ class XdsEnd2endTest : public ::testing::TestWithParam<TestType> {

RpcOptions& set_metadata(
std::vector<std::pair<std::string, std::string>> rpc_metadata) {
metadata = rpc_metadata;
metadata = std::move(rpc_metadata);
return *this;
}
};
Expand Down Expand Up @@ -4811,6 +4811,7 @@ TEST_P(LocalityMapTest, UpdateMap) {
const double kTotalLocalityWeight0 =
std::accumulate(kLocalityWeights0.begin(), kLocalityWeights0.end(), 0);
std::vector<double> locality_weight_rate_0;
locality_weight_rate_0.reserve(kLocalityWeights0.size());
for (int weight : kLocalityWeights0) {
locality_weight_rate_0.push_back(weight / kTotalLocalityWeight0);
}
Expand Down
6 changes: 3 additions & 3 deletions test/cpp/interop/http2_client.cc
Expand Up @@ -43,15 +43,15 @@ const int kLargeResponseSize = 314159;
} // namespace

Http2Client::ServiceStub::ServiceStub(const std::shared_ptr<Channel>& channel)
: channel_(std::move(channel)) {
: channel_(channel) {
stub_ = TestService::NewStub(channel);
}

TestService::Stub* Http2Client::ServiceStub::Get() { return stub_.get(); }

Http2Client::Http2Client(const std::shared_ptr<Channel>& channel)
: serviceStub_(channel),
channel_(std::move(channel)),
channel_(channel),
defaultRequest_(BuildDefaultRequest()) {}

bool Http2Client::AssertStatusCode(const Status& s, StatusCode expected_code) {
Expand Down Expand Up @@ -159,7 +159,7 @@ bool Http2Client::DoMaxStreams() {
std::string(kLargeResponseSize, '\0'));

std::vector<std::thread> test_threads;

test_threads.reserve(10);
for (int i = 0; i < 10; i++) {
test_threads.emplace_back(
std::thread(&Http2Client::MaxStreamsWorker, this, channel_));
Expand Down
5 changes: 4 additions & 1 deletion test/cpp/qps/BUILD
Expand Up @@ -116,7 +116,10 @@ grpc_cc_library(
"histogram.h",
"stats.h",
],
deps = ["//test/core/util:grpc_test_util"],
deps = [
"//src/proto/grpc/testing:stats_proto",
"//test/core/util:grpc_test_util",
],
)

grpc_cc_binary(
Expand Down
4 changes: 3 additions & 1 deletion test/cpp/qps/histogram.h
Expand Up @@ -39,7 +39,9 @@ class Histogram {
impl_ = grpc_histogram_create(default_resolution(), default_max_possible());
}

Histogram(Histogram&& other) : impl_(other.impl_) { other.impl_ = nullptr; }
Histogram(Histogram&& other) noexcept : impl_(other.impl_) {
other.impl_ = nullptr;
}

void Merge(const Histogram& h) { grpc_histogram_merge(impl_, h.impl_); }
void Add(double value) { grpc_histogram_add(impl_, value); }
Expand Down
38 changes: 19 additions & 19 deletions test/cpp/util/grpc_tool.cc
Expand Up @@ -86,26 +86,26 @@ class GrpcTool {
virtual ~GrpcTool() {}

bool Help(int argc, const char** argv, const CliCredentials& cred,
GrpcToolOutputCallback callback);
const GrpcToolOutputCallback& callback);
bool CallMethod(int argc, const char** argv, const CliCredentials& cred,
GrpcToolOutputCallback callback);
const GrpcToolOutputCallback& callback);
bool ListServices(int argc, const char** argv, const CliCredentials& cred,
GrpcToolOutputCallback callback);
const GrpcToolOutputCallback& callback);
bool PrintType(int argc, const char** argv, const CliCredentials& cred,
GrpcToolOutputCallback callback);
const GrpcToolOutputCallback& callback);
// TODO(zyc): implement the following methods
// bool ListServices(int argc, const char** argv, GrpcToolOutputCallback
// callback);
// bool PrintTypeId(int argc, const char** argv, GrpcToolOutputCallback
// callback);
bool ParseMessage(int argc, const char** argv, const CliCredentials& cred,
GrpcToolOutputCallback callback);
const GrpcToolOutputCallback& callback);
bool ToText(int argc, const char** argv, const CliCredentials& cred,
GrpcToolOutputCallback callback);
const GrpcToolOutputCallback& callback);
bool ToJson(int argc, const char** argv, const CliCredentials& cred,
GrpcToolOutputCallback callback);
const GrpcToolOutputCallback& callback);
bool ToBinary(int argc, const char** argv, const CliCredentials& cred,
GrpcToolOutputCallback callback);
const GrpcToolOutputCallback& callback);

void SetPrintCommandMode(int exit_status) {
print_command_usage_ = true;
Expand Down Expand Up @@ -193,8 +193,8 @@ void PrintMetadata(const T& m, const std::string& message) {
}

void ReadResponse(CliCall* call, const std::string& method_name,
GrpcToolOutputCallback callback, ProtoFileParser* parser,
gpr_mu* parser_mu, bool print_mode) {
const GrpcToolOutputCallback& callback,
ProtoFileParser* parser, gpr_mu* parser_mu, bool print_mode) {
std::string serialized_response_proto;
std::multimap<grpc::string_ref, grpc::string_ref> server_initial_metadata;

Expand Down Expand Up @@ -287,7 +287,7 @@ const Command* FindCommand(const std::string& name) {
} // namespace

int GrpcToolMainLib(int argc, const char** argv, const CliCredentials& cred,
GrpcToolOutputCallback callback) {
const GrpcToolOutputCallback& callback) {
if (argc < 2) {
Usage("No command specified");
}
Expand Down Expand Up @@ -324,7 +324,7 @@ void GrpcTool::CommandUsage(const std::string& usage) const {
}

bool GrpcTool::Help(int argc, const char** argv, const CliCredentials& cred,
GrpcToolOutputCallback callback) {
const GrpcToolOutputCallback& callback) {
CommandUsage(
"Print help\n"
" grpc_cli help [subcommand]\n");
Expand All @@ -344,7 +344,7 @@ bool GrpcTool::Help(int argc, const char** argv, const CliCredentials& cred,

bool GrpcTool::ListServices(int argc, const char** argv,
const CliCredentials& cred,
GrpcToolOutputCallback callback) {
const GrpcToolOutputCallback& callback) {
CommandUsage(
"List services\n"
" grpc_cli ls <address> [<service>[/<method>]]\n"
Expand Down Expand Up @@ -445,7 +445,7 @@ bool GrpcTool::ListServices(int argc, const char** argv,

bool GrpcTool::PrintType(int /*argc*/, const char** argv,
const CliCredentials& cred,
GrpcToolOutputCallback callback) {
const GrpcToolOutputCallback& callback) {
CommandUsage(
"Print type\n"
" grpc_cli type <address> <type>\n"
Expand Down Expand Up @@ -473,7 +473,7 @@ bool GrpcTool::PrintType(int /*argc*/, const char** argv,

bool GrpcTool::CallMethod(int argc, const char** argv,
const CliCredentials& cred,
GrpcToolOutputCallback callback) {
const GrpcToolOutputCallback& callback) {
CommandUsage(
"Call method\n"
" grpc_cli call <address> <service>[.<method>] <request>\n"
Expand Down Expand Up @@ -836,7 +836,7 @@ bool GrpcTool::CallMethod(int argc, const char** argv,

bool GrpcTool::ParseMessage(int argc, const char** argv,
const CliCredentials& cred,
GrpcToolOutputCallback callback) {
const GrpcToolOutputCallback& callback) {
CommandUsage(
"Parse message\n"
" grpc_cli parse <address> <type> [<message>]\n"
Expand Down Expand Up @@ -927,7 +927,7 @@ bool GrpcTool::ParseMessage(int argc, const char** argv,
}

bool GrpcTool::ToText(int argc, const char** argv, const CliCredentials& cred,
GrpcToolOutputCallback callback) {
const GrpcToolOutputCallback& callback) {
CommandUsage(
"Convert binary message to text\n"
" grpc_cli totext <protofiles> <type>\n"
Expand All @@ -945,7 +945,7 @@ bool GrpcTool::ToText(int argc, const char** argv, const CliCredentials& cred,
}

bool GrpcTool::ToJson(int argc, const char** argv, const CliCredentials& cred,
GrpcToolOutputCallback callback) {
const GrpcToolOutputCallback& callback) {
CommandUsage(
"Convert binary message to json\n"
" grpc_cli tojson <protofiles> <type>\n"
Expand All @@ -964,7 +964,7 @@ bool GrpcTool::ToJson(int argc, const char** argv, const CliCredentials& cred,
}

bool GrpcTool::ToBinary(int argc, const char** argv, const CliCredentials& cred,
GrpcToolOutputCallback callback) {
const GrpcToolOutputCallback& callback) {
CommandUsage(
"Convert text message to binary\n"
" grpc_cli tobinary <protofiles> <type> [<message>]\n"
Expand Down
2 changes: 1 addition & 1 deletion test/cpp/util/grpc_tool.h
Expand Up @@ -31,7 +31,7 @@ namespace testing {
typedef std::function<bool(const std::string&)> GrpcToolOutputCallback;

int GrpcToolMainLib(int argc, const char** argv, const CliCredentials& cred,
GrpcToolOutputCallback callback);
const GrpcToolOutputCallback& callback);

} // namespace testing
} // namespace grpc
Expand Down
3 changes: 3 additions & 0 deletions tools/bazel.rc
Expand Up @@ -103,3 +103,6 @@ build:mutrace --copt=-O3
build:mutrace --copt=-fno-omit-frame-pointer
build:mutrace --copt=-DNDEBUG
build:mutrace --linkopt=-rdynamic

# Compile database generation config
build:compdb --build_tag_filters=-nocompdb
26 changes: 25 additions & 1 deletion tools/distrib/clang_tidy_code.sh
Expand Up @@ -21,6 +21,22 @@ set -ex
cd $(dirname $0)/../..
REPO_ROOT=$(pwd)

# grep targets with manual tag, which is not included in a result of bazel build using ...
# let's get a list of them using query command and pass it to gen_compilation_database.py
export MANUAL_TARGETS=$(bazel query 'attr("tags", "manual", tests(//test/cpp/...))' | grep -v _on_ios)

# generate a clang compilation database for all C/C++ sources in the repo.
tools/distrib/gen_compilation_database.py \
--include_headers \
--ignore_system_headers \
--dedup_targets \
"//:*" \
"//src/core/..." \
"//src/compiler/..." \
"//test/core/..." \
"//test/cpp/..." \
$MANUAL_TARGETS

if [ "$CLANG_TIDY_SKIP_DOCKER" == "" ]
then
# build clang-tidy docker image
Expand All @@ -29,7 +45,15 @@ then
# run clang-tidy against the checked out codebase
# when modifying the checked-out files, the current user will be impersonated
# so that the updated files don't end up being owned by "root".
docker run -e TEST="$TEST" -e CHANGED_FILES="$CHANGED_FILES" -e CLANG_TIDY_ROOT="/local-code" --rm=true -v "${REPO_ROOT}":/local-code --user "$(id -u):$(id -g)" -t grpc_clang_tidy /clang_tidy_all_the_things.sh "$@"
docker run \
-e TEST="$TEST" \
-e CHANGED_FILES="$CHANGED_FILES" \
-e CLANG_TIDY_ROOT="/local-code" \
--rm=true \
-v "${REPO_ROOT}":/local-code \
-v "${HOME/.cache/bazel}":"${HOME/.cache/bazel}" \
--user "$(id -u):$(id -g)" \
-t grpc_clang_tidy /clang_tidy_all_the_things.sh "$@"
else
CLANG_TIDY_ROOT="${REPO_ROOT}" tools/dockerfile/grpc_clang_tidy/clang_tidy_all_the_things.sh "$@"
fi

0 comments on commit 27795e7

Please sign in to comment.