• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2024 The 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 #ifndef GRPC_SUPPORT_METRICS_H
16 #define GRPC_SUPPORT_METRICS_H
17 
18 #include <grpc/event_engine/endpoint_config.h>
19 #include <grpc/support/port_platform.h>
20 
21 #include "absl/strings/string_view.h"
22 
23 namespace grpc_core {
24 namespace experimental {
25 
26 // Configuration (scope) for a specific client channel to be used for stats
27 // plugins. For some components like XdsClient where the same XdsClient instance
28 // can be shared across multiple channels that share the same target name but
29 // have different default authority and channel arguments, the component uses
30 // the configuration from the first channel that uses this XdsClient instance to
31 // determine StatsPluginChannelScope.
32 class StatsPluginChannelScope {
33  public:
StatsPluginChannelScope(absl::string_view target,absl::string_view default_authority,const grpc_event_engine::experimental::EndpointConfig & args)34   StatsPluginChannelScope(
35       absl::string_view target, absl::string_view default_authority,
36       const grpc_event_engine::experimental::EndpointConfig& args)
37       : target_(target), default_authority_(default_authority), args_(args) {}
38 
39   /// Returns the target used for creating the channel in the canonical form.
40   /// (Canonicalized target definition -
41   /// https://github.com/grpc/proposal/blob/master/A66-otel-stats.md)
target()42   absl::string_view target() const { return target_; }
43   /// Returns the default authority for the channel.
default_authority()44   absl::string_view default_authority() const { return default_authority_; }
45   /// Returns channel arguments.  THIS METHOD IS EXPERIMENTAL.
46   // TODO(roth, ctiller, yashkt): Find a better representation for
47   // channel args before de-experimentalizing this API.
experimental_args()48   const grpc_event_engine::experimental::EndpointConfig& experimental_args()
49       const {
50     return args_;
51   }
52 
53  private:
54   // Disable copy constructor and copy-assignment operator.
55   StatsPluginChannelScope(const StatsPluginChannelScope&) = delete;
56   StatsPluginChannelScope& operator=(const StatsPluginChannelScope&) = delete;
57 
58   absl::string_view target_;
59   absl::string_view default_authority_;
60   const grpc_event_engine::experimental::EndpointConfig& args_;
61 };
62 
63 }  // namespace experimental
64 }  // namespace grpc_core
65 
66 #endif /* GRPC_SUPPORT_METRICS_H */
67