Revert "Revert "Fold opencensus into grpc_impl namespace""

pull/18396/head
Karthik Ravi Shankar 6 years ago committed by GitHub
parent 3b4835d92d
commit f66b654795
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      BUILD
  2. 26
      include/grpcpp/opencensus.h
  3. 51
      include/grpcpp/opencensus_impl.h
  4. 65
      src/cpp/ext/filters/census/grpc_plugin.cc
  5. 6
      src/cpp/ext/filters/census/grpc_plugin.h
  6. 32
      src/cpp/ext/filters/census/views.cc
  7. 2
      test/cpp/ext/filters/census/stats_plugin_end2end_test.cc
  8. 6
      test/cpp/microbenchmarks/bm_opencensus_plugin.cc

@ -2283,6 +2283,7 @@ grpc_cc_library(
],
hdrs = [
"include/grpcpp/opencensus.h",
"include/grpcpp/opencensus_impl.h",
"src/cpp/ext/filters/census/channel_filter.h",
"src/cpp/ext/filters/census/client_filter.h",
"src/cpp/ext/filters/census/context.h",

@ -19,30 +19,6 @@
#ifndef GRPCPP_OPENCENSUS_H
#define GRPCPP_OPENCENSUS_H
#include "opencensus/trace/span.h"
namespace grpc {
// These symbols in this file will not be included in the binary unless
// grpc_opencensus_plugin build target was added as a dependency. At the moment
// it is only setup to be built with Bazel.
// Registers the OpenCensus plugin with gRPC, so that it will be used for future
// RPCs. This must be called before any views are created.
void RegisterOpenCensusPlugin();
// RPC stats definitions, defined by
// https://github.com/census-instrumentation/opencensus-specs/blob/master/stats/gRPC.md
// Registers the cumulative gRPC views so that they will be exported by any
// registered stats exporter. For on-task stats, construct a View using the
// ViewDescriptors below.
void RegisterOpenCensusViewsForExport();
class ServerContext;
// Returns the tracing Span for the current RPC.
::opencensus::trace::Span GetSpanFromServerContext(ServerContext* context);
} // namespace grpc
#include "grpcpp/opencensus_impl.h"
#endif // GRPCPP_OPENCENSUS_H

@ -0,0 +1,51 @@
/*
*
* Copyright 2019 gRPC authors.
*
* 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.
*
*/
#ifndef GRPCPP_OPENCENSUS_IMPL_H
#define GRPCPP_OPENCENSUS_IMPL_H
#include "opencensus/trace/span.h"
namespace grpc {
class ServerContext;
}
namespace grpc_impl {
// These symbols in this file will not be included in the binary unless
// grpc_opencensus_plugin build target was added as a dependency. At the moment
// it is only setup to be built with Bazel.
// Registers the OpenCensus plugin with gRPC, so that it will be used for future
// RPCs. This must be called before any views are created.
void RegisterOpenCensusPlugin();
// RPC stats definitions, defined by
// https://github.com/census-instrumentation/opencensus-specs/blob/master/stats/gRPC.md
// Registers the cumulative gRPC views so that they will be exported by any
// registered stats exporter. For on-task stats, construct a View using the
// ViewDescriptors below.
void RegisterOpenCensusViewsForExport();
// Returns the tracing Span for the current RPC.
::opencensus::trace::Span GetSpanFromServerContext(
grpc::ServerContext* context);
} // namespace grpc_impl
#endif // GRPCPP_OPENCENSUS_IMPL_H

@ -30,35 +30,6 @@
namespace grpc {
void RegisterOpenCensusPlugin() {
RegisterChannelFilter<CensusChannelData, CensusClientCallData>(
"opencensus_client", GRPC_CLIENT_CHANNEL, INT_MAX /* priority */,
nullptr /* condition function */);
RegisterChannelFilter<CensusChannelData, CensusServerCallData>(
"opencensus_server", GRPC_SERVER_CHANNEL, INT_MAX /* priority */,
nullptr /* condition function */);
// Access measures to ensure they are initialized. Otherwise, creating a view
// before the first RPC would cause an error.
RpcClientSentBytesPerRpc();
RpcClientReceivedBytesPerRpc();
RpcClientRoundtripLatency();
RpcClientServerLatency();
RpcClientSentMessagesPerRpc();
RpcClientReceivedMessagesPerRpc();
RpcServerSentBytesPerRpc();
RpcServerReceivedBytesPerRpc();
RpcServerServerLatency();
RpcServerSentMessagesPerRpc();
RpcServerReceivedMessagesPerRpc();
}
::opencensus::trace::Span GetSpanFromServerContext(ServerContext* context) {
return reinterpret_cast<const CensusContext*>(context->census_context())
->Span();
}
// These measure definitions should be kept in sync across opencensus
// implementations--see
// https://github.com/census-instrumentation/opencensus-java/blob/master/contrib/grpc_metrics/src/main/java/io/opencensus/contrib/grpc/metrics/RpcMeasureConstants.java.
@ -126,5 +97,39 @@ ABSL_CONST_INIT const absl::string_view
ABSL_CONST_INIT const absl::string_view kRpcServerServerLatencyMeasureName =
"grpc.io/server/server_latency";
} // namespace grpc
namespace grpc_impl {
void RegisterOpenCensusPlugin() {
grpc::RegisterChannelFilter<grpc::CensusChannelData,
grpc::CensusClientCallData>(
"opencensus_client", GRPC_CLIENT_CHANNEL, INT_MAX /* priority */,
nullptr /* condition function */);
grpc::RegisterChannelFilter<grpc::CensusChannelData,
grpc::CensusServerCallData>(
"opencensus_server", GRPC_SERVER_CHANNEL, INT_MAX /* priority */,
nullptr /* condition function */);
// Access measures to ensure they are initialized. Otherwise, creating a view
// before the first RPC would cause an error.
grpc::RpcClientSentBytesPerRpc();
grpc::RpcClientReceivedBytesPerRpc();
grpc::RpcClientRoundtripLatency();
grpc::RpcClientServerLatency();
grpc::RpcClientSentMessagesPerRpc();
grpc::RpcClientReceivedMessagesPerRpc();
grpc::RpcServerSentBytesPerRpc();
grpc::RpcServerReceivedBytesPerRpc();
grpc::RpcServerServerLatency();
grpc::RpcServerSentMessagesPerRpc();
grpc::RpcServerReceivedMessagesPerRpc();
}
::opencensus::trace::Span GetSpanFromServerContext(
grpc::ServerContext* context) {
return reinterpret_cast<const grpc::CensusContext*>(context->census_context())
->Span();
}
} // namespace grpc_impl

@ -22,12 +22,14 @@
#include <grpc/support/port_platform.h>
#include "absl/strings/string_view.h"
#include "include/grpcpp/opencensus.h"
#include "include/grpcpp/opencensus_impl.h"
#include "opencensus/stats/stats.h"
namespace grpc {
namespace grpc_impl {
class ServerContext;
}
namespace grpc {
// The tag keys set when recording RPC stats.
::opencensus::stats::TagKey ClientMethodTagKey();

@ -25,6 +25,23 @@
#include "opencensus/stats/internal/set_aggregation_window.h"
#include "opencensus/stats/stats.h"
namespace grpc_impl {
void RegisterOpenCensusViewsForExport() {
grpc::ClientSentMessagesPerRpcCumulative().RegisterForExport();
grpc::ClientSentBytesPerRpcCumulative().RegisterForExport();
grpc::ClientReceivedMessagesPerRpcCumulative().RegisterForExport();
grpc::ClientReceivedBytesPerRpcCumulative().RegisterForExport();
grpc::ClientRoundtripLatencyCumulative().RegisterForExport();
grpc::ClientServerLatencyCumulative().RegisterForExport();
grpc::ServerSentMessagesPerRpcCumulative().RegisterForExport();
grpc::ServerSentBytesPerRpcCumulative().RegisterForExport();
grpc::ServerReceivedMessagesPerRpcCumulative().RegisterForExport();
grpc::ServerReceivedBytesPerRpcCumulative().RegisterForExport();
grpc::ServerServerLatencyCumulative().RegisterForExport();
}
} // namespace grpc_impl
namespace grpc {
using ::opencensus::stats::Aggregation;
@ -71,21 +88,6 @@ ViewDescriptor HourDescriptor() {
} // namespace
void RegisterOpenCensusViewsForExport() {
ClientSentMessagesPerRpcCumulative().RegisterForExport();
ClientSentBytesPerRpcCumulative().RegisterForExport();
ClientReceivedMessagesPerRpcCumulative().RegisterForExport();
ClientReceivedBytesPerRpcCumulative().RegisterForExport();
ClientRoundtripLatencyCumulative().RegisterForExport();
ClientServerLatencyCumulative().RegisterForExport();
ServerSentMessagesPerRpcCumulative().RegisterForExport();
ServerSentBytesPerRpcCumulative().RegisterForExport();
ServerReceivedMessagesPerRpcCumulative().RegisterForExport();
ServerReceivedBytesPerRpcCumulative().RegisterForExport();
ServerServerLatencyCumulative().RegisterForExport();
}
// client cumulative
const ViewDescriptor& ClientSentBytesPerRpcCumulative() {
const static ViewDescriptor descriptor =

@ -58,7 +58,7 @@ class EchoServer final : public EchoTestService::Service {
class StatsPluginEnd2EndTest : public ::testing::Test {
protected:
static void SetUpTestCase() { RegisterOpenCensusPlugin(); }
static void SetUpTestCase() { grpc_impl::RegisterOpenCensusPlugin(); }
void SetUp() {
// Set up a synchronous server on a different thread to avoid the asynch

@ -29,7 +29,9 @@
#include "test/cpp/microbenchmarks/helpers.h"
absl::once_flag once;
void RegisterOnce() { absl::call_once(once, grpc::RegisterOpenCensusPlugin); }
void RegisterOnce() {
absl::call_once(once, grpc_impl::RegisterOpenCensusPlugin);
}
class EchoServer final : public grpc::testing::EchoTestService::Service {
grpc::Status Echo(grpc::ServerContext* context,
@ -99,7 +101,7 @@ static void BM_E2eLatencyCensusEnabled(benchmark::State& state) {
RegisterOnce();
// This we can safely repeat, and doing so clears accumulated data to avoid
// initialization costs varying between runs.
grpc::RegisterOpenCensusViewsForExport();
grpc_impl::RegisterOpenCensusViewsForExport();
EchoServerThread server;
std::unique_ptr<grpc::testing::EchoTestService::Stub> stub =

Loading…
Cancel
Save