Skip to content

Commit

Permalink
[GSM] Some initial structure (grpc#33952)
Browse files Browse the repository at this point in the history
<!--

If you know who should review your pull request, please assign it to
that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the
appropriate
lang label.

-->
  • Loading branch information
yashykt authored Aug 2, 2023
1 parent e0b5188 commit 7e63a2f
Show file tree
Hide file tree
Showing 8 changed files with 266 additions and 2 deletions.
52 changes: 52 additions & 0 deletions src/cpp/ext/gsm/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# gRPC Bazel BUILD file.
#
# Copyright 2023 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:public"],
features = [
"layering_check",
],
)

grpc_cc_library(
name = "gsm_observability",
srcs = [
"gsm_observability.cc",
],
hdrs = [
"gsm_observability.h",
],
external_deps = [
"absl/container:flat_hash_set",
"absl/status",
"absl/status:statusor",
"absl/strings",
"otel/sdk/src/metrics",
],
language = "c++",
visibility = ["//:__subpackages__"],
deps = [
"//:gpr_platform",
"//src/cpp/ext/otel:otel_plugin",
],
)
59 changes: 59 additions & 0 deletions src/cpp/ext/gsm/gsm_observability.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
//
// Copyright 2023 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/gsm/gsm_observability.h"

#include "absl/status/status.h"

#include "src/cpp/ext/otel/otel_plugin.h"

namespace grpc {
namespace internal {

//
// GsmCustomObservabilityBuilder
//

GsmCustomObservabilityBuilder& GsmCustomObservabilityBuilder::SetMeterProvider(
std::shared_ptr<opentelemetry::sdk::metrics::MeterProvider>
meter_provider) {
builder_.SetMeterProvider(meter_provider);
return *this;
}

GsmCustomObservabilityBuilder& GsmCustomObservabilityBuilder::EnableMetrics(
const absl::flat_hash_set<absl::string_view>& metric_names) {
builder_.EnableMetrics(metric_names);
return *this;
}

GsmCustomObservabilityBuilder& GsmCustomObservabilityBuilder::DisableMetrics(
const absl::flat_hash_set<absl::string_view>& metric_names) {
builder_.DisableMetrics(metric_names);
return *this;
}

absl::StatusOr<GsmObservability>
GsmCustomObservabilityBuilder::BuildAndRegister() {
return absl::UnimplementedError("Not Implemented");
}

} // namespace internal
} // namespace grpc
64 changes: 64 additions & 0 deletions src/cpp/ext/gsm/gsm_observability.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
//
// Copyright 2023 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_SRC_CPP_EXT_GSM_GSM_OBSERVABILITY_H
#define GRPC_SRC_CPP_EXT_GSM_GSM_OBSERVABILITY_H

#include <grpc/support/port_platform.h>

#include <memory>

#include "absl/container/flat_hash_set.h"
#include "absl/status/statusor.h"
#include "absl/strings/string_view.h"
#include "opentelemetry/sdk/metrics/meter_provider.h"

#include "src/cpp/ext/otel/otel_plugin.h"

namespace grpc {
namespace internal {

class GsmObservability {};

class GsmCustomObservabilityBuilder {
public:
// TODO(yashykt): Should this take the SDK or the API MeterProvider? Benefit
// of SDK MeterProvider - Can explicitly set histogram bucket boundaries, but
// in the next iteration of the API, we would have it there as well.
GsmCustomObservabilityBuilder& SetMeterProvider(
std::shared_ptr<opentelemetry::sdk::metrics::MeterProvider>
meter_provider);
// Enable metrics in \a metric_names
GsmCustomObservabilityBuilder& EnableMetrics(
const absl::flat_hash_set<absl::string_view>& metric_names);
// Disable metrics in \a metric_names
GsmCustomObservabilityBuilder& DisableMetrics(
const absl::flat_hash_set<absl::string_view>& metric_names);
// Builds the GsmObservability plugin. The return status shows whether
// GsmObservability was successfully enabled or not. TODO(): Is the
// GsmObservability object useful?
absl::StatusOr<GsmObservability> BuildAndRegister();

private:
OpenTelemetryPluginBuilder builder_;
};

} // namespace internal
} // namespace grpc

#endif // GRPC_SRC_CPP_EXT_GSM_GSM_OBSERVABILITY_H
41 changes: 41 additions & 0 deletions test/cpp/ext/gsm/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2023 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/gsm",
visibility = "tests",
)

grpc_cc_test(
name = "gsm_observability_test",
srcs = [
"gsm_observability_test.cc",
],
external_deps = [
"gtest",
"otel/sdk/src/metrics",
],
language = "C++",
tags = [
],
deps = [
"//:grpc++",
"//src/cpp/ext/gsm:gsm_observability",
"//test/core/util:grpc_test_util",
],
)
43 changes: 43 additions & 0 deletions test/cpp/ext/gsm/gsm_observability_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
//
// Copyright 2023 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/gsm/gsm_observability.h"

#include "gtest/gtest.h"

#include "test/core/util/test_config.h"

namespace grpc {
namespace testing {
namespace {

TEST(GsmCustomObservabilityBuilderTest, Basic) {
EXPECT_EQ(
internal::GsmCustomObservabilityBuilder().BuildAndRegister().status(),
absl::UnimplementedError("Not Implemented"));
}

} // namespace
} // namespace testing
} // namespace grpc

int main(int argc, char** argv) {
grpc::testing::TestEnvironment env(&argc, argv);
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
5 changes: 4 additions & 1 deletion tools/buildgen/extract_metadata_from_bazel_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,10 @@ def _exclude_unwanted_cc_tests(tests: List[str]) -> List[str]:

# we have not added otel dependency outside of bazel
tests = [
test for test in tests if not test.startswith("test/cpp/ext/otel:")
test
for test in tests
if not test.startswith("test/cpp/ext/otel:")
and not test.startswith("test/cpp/ext/gsm:")
]

# missing opencensus/stats/stats.h
Expand Down
3 changes: 2 additions & 1 deletion tools/distrib/fix_build_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
"opentelemetry/metrics/sync_instruments.h": "otel/api",
"opentelemetry/nostd/shared_ptr.h": "otel/api",
"opentelemetry/nostd/unique_ptr.h": "otel/api",
"sdk/include/opentelemetry/sdk/metrics/meter_provider.h": "otel/sdk/src/metrics",
"opentelemetry/sdk/metrics/meter_provider.h": "otel/sdk/src/metrics",
"ares.h": "cares",
"fuzztest/fuzztest.h": ["fuzztest", "fuzztest_main"],
"google/api/monitored_resource.pb.h": (
Expand Down Expand Up @@ -379,6 +379,7 @@ def score_best(proposed, existing):
"",
"src/core",
"src/cpp/ext/gcp",
"src/cpp/ext/gsm",
"src/cpp/ext/otel",
"test/core/backoff",
"test/core/experiments",
Expand Down
1 change: 1 addition & 0 deletions tools/distrib/iwyu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ tools/distrib/gen_compilation_database.py \
--dedup_targets \
"//:*" \
"//src/core/..." \
"//src/cpp/ext/gsm/..." \
"//src/cpp/ext/otel/..." \
"//src/compiler/..." \
"//test/core/..." \
Expand Down

0 comments on commit 7e63a2f

Please sign in to comment.