[CSM] Plumbing fixes (#34440)

Changes -
* CsmObservability doesn't need `SetTargetSelector`. Removed it.
* Added missing plumbing of `ServiceMeshLabelsInjector` in
`CsmObservability` to actually do the metadata exchange.

<!--

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.

-->
create-pull-request/patch-5c8858f
Yash Tibrewal 1 year ago committed by GitHub
parent d491fc5993
commit ddc682c6c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      include/grpcpp/ext/csm_observability.h
  2. 8
      src/cpp/ext/csm/BUILD
  3. 16
      src/cpp/ext/csm/csm_observability.cc
  4. 2
      tools/distrib/fix_build_deps.py

@ -55,11 +55,6 @@ class CsmObservabilityBuilder {
CsmObservabilityBuilder& EnableMetric(absl::string_view metric_name); CsmObservabilityBuilder& EnableMetric(absl::string_view metric_name);
CsmObservabilityBuilder& DisableMetric(absl::string_view metric_name); CsmObservabilityBuilder& DisableMetric(absl::string_view metric_name);
CsmObservabilityBuilder& DisableAllMetrics(); CsmObservabilityBuilder& DisableAllMetrics();
// If set, \a target_selector is called per channel to decide whether to
// collect metrics on that target or not.
CsmObservabilityBuilder& SetTargetSelector(
absl::AnyInvocable<bool(absl::string_view /*target*/) const>
target_selector);
// If set, \a target_attribute_filter is called per channel to decide whether // If set, \a target_attribute_filter is called per channel to decide whether
// to record the target attribute on client or to replace it with "other". // to record the target attribute on client or to replace it with "other".
// This helps reduce the cardinality on metrics in cases where many channels // This helps reduce the cardinality on metrics in cases where many channels

@ -23,9 +23,10 @@ licenses(["reciprocal"])
package( package(
default_visibility = ["//visibility:public"], default_visibility = ["//visibility:public"],
features = [ # TODO(yashykt): Google Cloud C++ does not explicitly export the headers. Remove this once that is fixed.
"layering_check", #features = [
], # "layering_check",
#],
) )
grpc_cc_library( grpc_cc_library(
@ -46,6 +47,7 @@ grpc_cc_library(
"absl/strings", "absl/strings",
"absl/types:optional", "absl/types:optional",
"absl/types:variant", "absl/types:variant",
"google_cloud_cpp:experimental-opentelemetry",
"otel/sdk/src/metrics", "otel/sdk/src/metrics",
"otel/sdk:headers", "otel/sdk:headers",
"upb_lib", "upb_lib",

@ -27,7 +27,10 @@
#include "absl/functional/any_invocable.h" #include "absl/functional/any_invocable.h"
#include "absl/status/statusor.h" #include "absl/status/statusor.h"
#include "absl/types/optional.h" #include "absl/types/optional.h"
#include "google/cloud/opentelemetry/resource_detector.h"
#include "opentelemetry/sdk/metrics/meter_provider.h" #include "opentelemetry/sdk/metrics/meter_provider.h"
#include "opentelemetry/sdk/resource/resource.h"
#include "opentelemetry/sdk/resource/resource_detector.h"
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include <grpcpp/ext/csm_observability.h> #include <grpcpp/ext/csm_observability.h>
@ -35,6 +38,7 @@
#include "src/core/ext/xds/xds_enabled_server.h" #include "src/core/ext/xds/xds_enabled_server.h"
#include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/uri/uri_parser.h" #include "src/core/lib/uri/uri_parser.h"
#include "src/cpp/ext/csm/metadata_exchange.h"
#include "src/cpp/ext/otel/otel_plugin.h" #include "src/cpp/ext/otel/otel_plugin.h"
namespace grpc { namespace grpc {
@ -68,13 +72,6 @@ CsmObservabilityBuilder& CsmObservabilityBuilder::DisableAllMetrics() {
return *this; return *this;
} }
CsmObservabilityBuilder& CsmObservabilityBuilder::SetTargetSelector(
absl::AnyInvocable<bool(absl::string_view /*target*/) const>
target_selector) {
builder_.SetTargetSelector(std::move(target_selector));
return *this;
}
CsmObservabilityBuilder& CsmObservabilityBuilder::SetTargetAttributeFilter( CsmObservabilityBuilder& CsmObservabilityBuilder::SetTargetAttributeFilter(
absl::AnyInvocable<bool(absl::string_view /*target*/) const> absl::AnyInvocable<bool(absl::string_view /*target*/) const>
target_attribute_filter) { target_attribute_filter) {
@ -87,6 +84,11 @@ absl::StatusOr<CsmObservability> CsmObservabilityBuilder::BuildAndRegister() {
return args.GetBool(GRPC_ARG_XDS_ENABLED_SERVER).value_or(false); return args.GetBool(GRPC_ARG_XDS_ENABLED_SERVER).value_or(false);
}); });
builder_.SetTargetSelector(internal::CsmChannelTargetSelector); builder_.SetTargetSelector(internal::CsmChannelTargetSelector);
builder_.SetLabelsInjector(
std::make_unique<internal::ServiceMeshLabelsInjector>(
google::cloud::otel::MakeResourceDetector()
->Detect()
.GetAttributes()));
builder_.BuildAndRegisterGlobal(); builder_.BuildAndRegisterGlobal();
return CsmObservability(); return CsmObservability();
} }

@ -107,6 +107,8 @@ EXTERNAL_DEPS = {
"opentelemetry/nostd/unique_ptr.h": "otel/api", "opentelemetry/nostd/unique_ptr.h": "otel/api",
"opentelemetry/sdk/metrics/meter_provider.h": "otel/sdk/src/metrics", "opentelemetry/sdk/metrics/meter_provider.h": "otel/sdk/src/metrics",
"opentelemetry/sdk/common/attribute_utils.h": "otel/sdk:headers", "opentelemetry/sdk/common/attribute_utils.h": "otel/sdk:headers",
"opentelemetry/sdk/resource/resource.h": "otel/sdk:headers",
"opentelemetry/sdk/resource/resource_detector.h": "otel/sdk:headers",
"opentelemetry/sdk/resource/semantic_conventions.h": "otel/sdk:headers", "opentelemetry/sdk/resource/semantic_conventions.h": "otel/sdk:headers",
"ares.h": "cares", "ares.h": "cares",
"fuzztest/fuzztest.h": ["fuzztest", "fuzztest_main"], "fuzztest/fuzztest.h": ["fuzztest", "fuzztest_main"],

Loading…
Cancel
Save