Skip to content

Commit 7e63a2f

Browse files
authored
[GSM] Some initial structure (grpc#33952)
<!-- 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. -->
1 parent e0b5188 commit 7e63a2f

File tree

8 files changed

+266
-2
lines changed

8 files changed

+266
-2
lines changed

src/cpp/ext/gsm/BUILD

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# gRPC Bazel BUILD file.
2+
#
3+
# Copyright 2023 gRPC authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
load(
18+
"//bazel:grpc_build_system.bzl",
19+
"grpc_cc_library",
20+
)
21+
22+
licenses(["reciprocal"])
23+
24+
package(
25+
default_visibility = ["//visibility:public"],
26+
features = [
27+
"layering_check",
28+
],
29+
)
30+
31+
grpc_cc_library(
32+
name = "gsm_observability",
33+
srcs = [
34+
"gsm_observability.cc",
35+
],
36+
hdrs = [
37+
"gsm_observability.h",
38+
],
39+
external_deps = [
40+
"absl/container:flat_hash_set",
41+
"absl/status",
42+
"absl/status:statusor",
43+
"absl/strings",
44+
"otel/sdk/src/metrics",
45+
],
46+
language = "c++",
47+
visibility = ["//:__subpackages__"],
48+
deps = [
49+
"//:gpr_platform",
50+
"//src/cpp/ext/otel:otel_plugin",
51+
],
52+
)

src/cpp/ext/gsm/gsm_observability.cc

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//
2+
//
3+
// Copyright 2023 gRPC authors.
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
//
17+
//
18+
19+
#include <grpc/support/port_platform.h>
20+
21+
#include "src/cpp/ext/gsm/gsm_observability.h"
22+
23+
#include "absl/status/status.h"
24+
25+
#include "src/cpp/ext/otel/otel_plugin.h"
26+
27+
namespace grpc {
28+
namespace internal {
29+
30+
//
31+
// GsmCustomObservabilityBuilder
32+
//
33+
34+
GsmCustomObservabilityBuilder& GsmCustomObservabilityBuilder::SetMeterProvider(
35+
std::shared_ptr<opentelemetry::sdk::metrics::MeterProvider>
36+
meter_provider) {
37+
builder_.SetMeterProvider(meter_provider);
38+
return *this;
39+
}
40+
41+
GsmCustomObservabilityBuilder& GsmCustomObservabilityBuilder::EnableMetrics(
42+
const absl::flat_hash_set<absl::string_view>& metric_names) {
43+
builder_.EnableMetrics(metric_names);
44+
return *this;
45+
}
46+
47+
GsmCustomObservabilityBuilder& GsmCustomObservabilityBuilder::DisableMetrics(
48+
const absl::flat_hash_set<absl::string_view>& metric_names) {
49+
builder_.DisableMetrics(metric_names);
50+
return *this;
51+
}
52+
53+
absl::StatusOr<GsmObservability>
54+
GsmCustomObservabilityBuilder::BuildAndRegister() {
55+
return absl::UnimplementedError("Not Implemented");
56+
}
57+
58+
} // namespace internal
59+
} // namespace grpc

src/cpp/ext/gsm/gsm_observability.h

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
//
2+
//
3+
// Copyright 2023 gRPC authors.
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
//
17+
//
18+
19+
#ifndef GRPC_SRC_CPP_EXT_GSM_GSM_OBSERVABILITY_H
20+
#define GRPC_SRC_CPP_EXT_GSM_GSM_OBSERVABILITY_H
21+
22+
#include <grpc/support/port_platform.h>
23+
24+
#include <memory>
25+
26+
#include "absl/container/flat_hash_set.h"
27+
#include "absl/status/statusor.h"
28+
#include "absl/strings/string_view.h"
29+
#include "opentelemetry/sdk/metrics/meter_provider.h"
30+
31+
#include "src/cpp/ext/otel/otel_plugin.h"
32+
33+
namespace grpc {
34+
namespace internal {
35+
36+
class GsmObservability {};
37+
38+
class GsmCustomObservabilityBuilder {
39+
public:
40+
// TODO(yashykt): Should this take the SDK or the API MeterProvider? Benefit
41+
// of SDK MeterProvider - Can explicitly set histogram bucket boundaries, but
42+
// in the next iteration of the API, we would have it there as well.
43+
GsmCustomObservabilityBuilder& SetMeterProvider(
44+
std::shared_ptr<opentelemetry::sdk::metrics::MeterProvider>
45+
meter_provider);
46+
// Enable metrics in \a metric_names
47+
GsmCustomObservabilityBuilder& EnableMetrics(
48+
const absl::flat_hash_set<absl::string_view>& metric_names);
49+
// Disable metrics in \a metric_names
50+
GsmCustomObservabilityBuilder& DisableMetrics(
51+
const absl::flat_hash_set<absl::string_view>& metric_names);
52+
// Builds the GsmObservability plugin. The return status shows whether
53+
// GsmObservability was successfully enabled or not. TODO(): Is the
54+
// GsmObservability object useful?
55+
absl::StatusOr<GsmObservability> BuildAndRegister();
56+
57+
private:
58+
OpenTelemetryPluginBuilder builder_;
59+
};
60+
61+
} // namespace internal
62+
} // namespace grpc
63+
64+
#endif // GRPC_SRC_CPP_EXT_GSM_GSM_OBSERVABILITY_H

test/cpp/ext/gsm/BUILD

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright 2023 gRPC authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
load("//bazel:grpc_build_system.bzl", "grpc_cc_test", "grpc_package")
16+
17+
licenses(["notice"])
18+
19+
grpc_package(
20+
name = "test/cpp/ext/gsm",
21+
visibility = "tests",
22+
)
23+
24+
grpc_cc_test(
25+
name = "gsm_observability_test",
26+
srcs = [
27+
"gsm_observability_test.cc",
28+
],
29+
external_deps = [
30+
"gtest",
31+
"otel/sdk/src/metrics",
32+
],
33+
language = "C++",
34+
tags = [
35+
],
36+
deps = [
37+
"//:grpc++",
38+
"//src/cpp/ext/gsm:gsm_observability",
39+
"//test/core/util:grpc_test_util",
40+
],
41+
)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//
2+
//
3+
// Copyright 2023 gRPC authors.
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
//
17+
//
18+
19+
#include "src/cpp/ext/gsm/gsm_observability.h"
20+
21+
#include "gtest/gtest.h"
22+
23+
#include "test/core/util/test_config.h"
24+
25+
namespace grpc {
26+
namespace testing {
27+
namespace {
28+
29+
TEST(GsmCustomObservabilityBuilderTest, Basic) {
30+
EXPECT_EQ(
31+
internal::GsmCustomObservabilityBuilder().BuildAndRegister().status(),
32+
absl::UnimplementedError("Not Implemented"));
33+
}
34+
35+
} // namespace
36+
} // namespace testing
37+
} // namespace grpc
38+
39+
int main(int argc, char** argv) {
40+
grpc::testing::TestEnvironment env(&argc, argv);
41+
::testing::InitGoogleTest(&argc, argv);
42+
return RUN_ALL_TESTS();
43+
}

tools/buildgen/extract_metadata_from_bazel_xml.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,10 @@ def _exclude_unwanted_cc_tests(tests: List[str]) -> List[str]:
738738

739739
# we have not added otel dependency outside of bazel
740740
tests = [
741-
test for test in tests if not test.startswith("test/cpp/ext/otel:")
741+
test
742+
for test in tests
743+
if not test.startswith("test/cpp/ext/otel:")
744+
and not test.startswith("test/cpp/ext/gsm:")
742745
]
743746

744747
# missing opencensus/stats/stats.h

tools/distrib/fix_build_deps.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
"opentelemetry/metrics/sync_instruments.h": "otel/api",
101101
"opentelemetry/nostd/shared_ptr.h": "otel/api",
102102
"opentelemetry/nostd/unique_ptr.h": "otel/api",
103-
"sdk/include/opentelemetry/sdk/metrics/meter_provider.h": "otel/sdk/src/metrics",
103+
"opentelemetry/sdk/metrics/meter_provider.h": "otel/sdk/src/metrics",
104104
"ares.h": "cares",
105105
"fuzztest/fuzztest.h": ["fuzztest", "fuzztest_main"],
106106
"google/api/monitored_resource.pb.h": (
@@ -379,6 +379,7 @@ def score_best(proposed, existing):
379379
"",
380380
"src/core",
381381
"src/cpp/ext/gcp",
382+
"src/cpp/ext/gsm",
382383
"src/cpp/ext/otel",
383384
"test/core/backoff",
384385
"test/core/experiments",

tools/distrib/iwyu.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ tools/distrib/gen_compilation_database.py \
3232
--dedup_targets \
3333
"//:*" \
3434
"//src/core/..." \
35+
"//src/cpp/ext/gsm/..." \
3536
"//src/cpp/ext/otel/..." \
3637
"//src/compiler/..." \
3738
"//test/core/..." \

0 commit comments

Comments
 (0)