mirror of https://github.com/grpc/grpc.git
Revert "Revert "GCP Observability: Add plugin registry API"" (#30766)
* Revert "Revert "GCP Observability: Add plugin registry API (#30571)" (#30765)"
This reverts commit b8fde2ab47
.
* Remove gcp observability target from header
pull/30790/head
parent
602c5e8e97
commit
60a1b4ad6f
7 changed files with 233 additions and 1 deletions
@ -0,0 +1,53 @@ |
||||
# gRPC Bazel BUILD file. |
||||
# |
||||
# Copyright 2022 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. |
||||
|
||||
load( |
||||
"//bazel:grpc_build_system.bzl", |
||||
"grpc_cc_library", |
||||
) |
||||
|
||||
licenses(["reciprocal"]) |
||||
|
||||
package( |
||||
default_visibility = ["//visibility:private"], |
||||
features = [ |
||||
"layering_check", |
||||
"-parse_headers", |
||||
], |
||||
) |
||||
|
||||
# This is an EXPERIMENTAL target subject to change. |
||||
grpc_cc_library( |
||||
name = "observability", |
||||
srcs = [ |
||||
"observability.cc", |
||||
], |
||||
hdrs = [ |
||||
"observability.h", |
||||
], |
||||
external_deps = [ |
||||
"opencensus-trace", |
||||
"opencensus-trace-stackdriver_exporter", |
||||
"opencensus-stats-stackdriver_exporter", |
||||
], |
||||
language = "c++", |
||||
tags = ["nofixdeps"], |
||||
visibility = ["//test:__subpackages__"], |
||||
deps = [ |
||||
"//:gpr", |
||||
"//:grpc_opencensus_plugin", |
||||
], |
||||
) |
@ -0,0 +1,65 @@ |
||||
//
|
||||
// Copyright 2022 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.
|
||||
//
|
||||
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#include "src/cpp/ext/gcp/observability.h" |
||||
|
||||
#include <stdint.h> |
||||
|
||||
#include <utility> |
||||
|
||||
#include "opencensus/exporters/stats/stackdriver/stackdriver_exporter.h" |
||||
#include "opencensus/exporters/trace/stackdriver/stackdriver_exporter.h" |
||||
#include "opencensus/trace/sampler.h" |
||||
#include "opencensus/trace/trace_config.h" |
||||
|
||||
#include <grpcpp/opencensus.h> |
||||
|
||||
namespace grpc { |
||||
namespace experimental { |
||||
|
||||
namespace { |
||||
// TODO(yashykt): These constants are currently derived from the example at
|
||||
// https://cloud.google.com/traffic-director/docs/observability-proxyless#c++.
|
||||
// We might want these to be configurable.
|
||||
constexpr uint32_t kMaxAttributes = 128; |
||||
constexpr uint32_t kMaxAnnotations = 128; |
||||
constexpr uint32_t kMaxMessageEvents = 128; |
||||
constexpr uint32_t kMaxLinks = 128; |
||||
} // namespace
|
||||
|
||||
void GcpObservabilityInit() { |
||||
// TODO(yashykt): Add code for gRPC config parsing
|
||||
grpc::RegisterOpenCensusPlugin(); |
||||
grpc::RegisterOpenCensusViewsForExport(); |
||||
// TODO(yashykt): Setup tracing and stats exporting only if enabled in config.
|
||||
// TODO(yashykt): Get probability from config
|
||||
opencensus::trace::TraceConfig::SetCurrentTraceParams( |
||||
{kMaxAttributes, kMaxAnnotations, kMaxMessageEvents, kMaxLinks, |
||||
opencensus::trace::ProbabilitySampler(1.0)}); |
||||
opencensus::exporters::trace::StackdriverOptions trace_opts; |
||||
// TODO(yashykt): Set up project ID based on config
|
||||
opencensus::exporters::trace::StackdriverExporter::Register( |
||||
std::move(trace_opts)); |
||||
opencensus::exporters::stats::StackdriverOptions stats_opts; |
||||
// TODO(yashykt): Set up project ID based on config
|
||||
opencensus::exporters::stats::StackdriverExporter::Register( |
||||
std::move(stats_opts)); |
||||
} |
||||
|
||||
} // namespace experimental
|
||||
} // namespace grpc
|
@ -0,0 +1,33 @@ |
||||
//
|
||||
// Copyright 2022 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 GRPC_INTERNAL_CPP_EXT_GCP_OBSERVABILITY_GCP_OBSERVABILITY_H |
||||
#define GRPC_INTERNAL_CPP_EXT_GCP_OBSERVABILITY_GCP_OBSERVABILITY_H |
||||
|
||||
// TODO(yashykt): This file would have been in the top include/grpcpp directory
|
||||
// instead of in src/, but I'm not yet sure about the naming, so keeping it here
|
||||
// till we decide.
|
||||
|
||||
namespace grpc { |
||||
namespace experimental { |
||||
|
||||
// Initialize GCP Observability for gRPC.
|
||||
void GcpObservabilityInit(); |
||||
|
||||
} // namespace experimental
|
||||
} // namespace grpc
|
||||
|
||||
#endif // GRPC_INTERNAL_CPP_EXT_GCP_OBSERVABILITY_GCP_OBSERVABILITY_H
|
@ -0,0 +1,34 @@ |
||||
# Copyright 2022 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. |
||||
|
||||
load("//bazel:grpc_build_system.bzl", "grpc_cc_test", "grpc_package") |
||||
|
||||
licenses(["notice"]) |
||||
|
||||
grpc_package(name = "test/cpp/ext/gcp") |
||||
|
||||
grpc_cc_test( |
||||
name = "observability_test", |
||||
srcs = [ |
||||
"observability_test.cc", |
||||
], |
||||
external_deps = [ |
||||
"gtest", |
||||
], |
||||
language = "C++", |
||||
deps = [ |
||||
"//src/cpp/ext/gcp:observability", |
||||
"//test/cpp/util:test_util", |
||||
], |
||||
) |
@ -0,0 +1,36 @@ |
||||
//
|
||||
// Copyright 2022 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.
|
||||
//
|
||||
|
||||
#include "src/cpp/ext/gcp/observability.h" |
||||
|
||||
#include "gmock/gmock.h" |
||||
#include "gtest/gtest.h" |
||||
|
||||
#include "test/core/util/test_config.h" |
||||
|
||||
namespace { |
||||
|
||||
TEST(GcpObservabilityTest, RegistrationTest) { |
||||
grpc::experimental::GcpObservabilityInit(); |
||||
} |
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char** argv) { |
||||
grpc::testing::TestEnvironment env(&argc, argv); |
||||
::testing::InitGoogleTest(&argc, argv); |
||||
return RUN_ALL_TESTS(); |
||||
} |
Loading…
Reference in new issue