xds_endpoint.h
Go to the documentation of this file.
1 //
2 // Copyright 2018 gRPC authors.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #ifndef GRPC_CORE_EXT_XDS_XDS_ENDPOINT_H
18 #define GRPC_CORE_EXT_XDS_XDS_ENDPOINT_H
19 
21 
22 #include <stdint.h>
23 
24 #include <algorithm>
25 #include <map>
26 #include <memory>
27 #include <string>
28 #include <utility>
29 #include <vector>
30 
31 #include "absl/status/statusor.h"
32 #include "absl/strings/string_view.h"
34 #include "upb/def.h"
35 
42 
43 namespace grpc_core {
44 
46  struct Priority {
47  struct Locality {
51 
52  bool operator==(const Locality& other) const {
53  return *name == *other.name && lb_weight == other.lb_weight &&
54  endpoints == other.endpoints;
55  }
56  bool operator!=(const Locality& other) const { return !(*this == other); }
57  std::string ToString() const;
58  };
59 
60  std::map<XdsLocalityName*, Locality, XdsLocalityName::Less> localities;
61 
62  bool operator==(const Priority& other) const;
63  std::string ToString() const;
64  };
65  using PriorityList = std::vector<Priority>;
66 
67  // There are two phases of accessing this class's content:
68  // 1. to initialize in the control plane combiner;
69  // 2. to use in the data plane combiner.
70  // So no additional synchronization is needed.
71  class DropConfig : public RefCounted<DropConfig> {
72  public:
73  struct DropCategory {
74  bool operator==(const DropCategory& other) const {
75  return name == other.name &&
77  }
78 
81  };
82 
83  using DropCategoryList = std::vector<DropCategory>;
84 
85  void AddCategory(std::string name, uint32_t parts_per_million) {
86  drop_category_list_.emplace_back(
87  DropCategory{std::move(name), parts_per_million});
88  if (parts_per_million == 1000000) drop_all_ = true;
89  }
90 
91  // The only method invoked from outside the WorkSerializer (used in
92  // the data plane).
93  bool ShouldDrop(const std::string** category_name) const;
94 
96  return drop_category_list_;
97  }
98 
99  bool drop_all() const { return drop_all_; }
100 
101  bool operator==(const DropConfig& other) const {
103  }
104  bool operator!=(const DropConfig& other) const { return !(*this == other); }
105 
106  std::string ToString() const;
107 
108  private:
110  bool drop_all_ = false;
111  };
112 
115 
116  bool operator==(const XdsEndpointResource& other) const {
117  return priorities == other.priorities && *drop_config == *other.drop_config;
118  }
119  std::string ToString() const;
120 };
121 
123  : public XdsResourceTypeImpl<XdsEndpointResourceType, XdsEndpointResource> {
124  public:
125  absl::string_view type_url() const override {
126  return "envoy.config.endpoint.v3.ClusterLoadAssignment";
127  }
128  absl::string_view v2_type_url() const override {
129  return "envoy.api.v2.ClusterLoadAssignment";
130  }
131 
133  absl::string_view serialized_resource,
134  bool is_v2) const override;
135 
136  void InitUpbSymtab(upb_DefPool* symtab) const override {
138  }
139 };
140 
141 } // namespace grpc_core
142 
143 #endif // GRPC_CORE_EXT_XDS_XDS_ENDPOINT_H
grpc_core::XdsEndpointResource::Priority::Locality::operator==
bool operator==(const Locality &other) const
Definition: xds_endpoint.h:52
xds_client_stats.h
endpoint.upbdefs.h
grpc_core::XdsEndpointResource::DropConfig::DropCategoryList
std::vector< DropCategory > DropCategoryList
Definition: xds_endpoint.h:83
grpc_core::XdsEncodingContext
Definition: upb_utils.h:39
grpc_core
Definition: call_metric_recorder.h:31
grpc_core::XdsEndpointResource::Priority::localities
std::map< XdsLocalityName *, Locality, XdsLocalityName::Less > localities
Definition: xds_endpoint.h:60
grpc_core::XdsEndpointResourceType
Definition: xds_endpoint.h:122
grpc_core::XdsEndpointResource::ToString
std::string ToString() const
Definition: xds_endpoint.cc:111
absl::string_view
Definition: abseil-cpp/absl/strings/string_view.h:167
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
grpc_core::XdsEndpointResource::DropConfig::DropCategory::parts_per_million
const uint32_t parts_per_million
Definition: xds_endpoint.h:80
grpc_core::XdsEndpointResource::DropConfig::DropCategory::name
std::string name
Definition: xds_endpoint.h:79
xds_resource_type_impl.h
setup.name
name
Definition: setup.py:542
grpc_core::XdsEndpointResource::DropConfig::DropCategory
Definition: xds_endpoint.h:73
grpc_core::XdsEndpointResource::Priority::ToString
std::string ToString() const
Definition: xds_endpoint.cc:79
grpc_core::XdsEndpointResource::priorities
PriorityList priorities
Definition: xds_endpoint.h:113
uint32_t
unsigned int uint32_t
Definition: stdint-msvc2008.h:80
grpc_core::XdsEndpointResourceType::InitUpbSymtab
void InitUpbSymtab(upb_DefPool *symtab) const override
Definition: xds_endpoint.h:136
grpc_core::XdsEndpointResource::DropConfig::ShouldDrop
bool ShouldDrop(const std::string **category_name) const
Definition: xds_endpoint.cc:87
grpc_core::XdsEndpointResource::Priority
Definition: xds_endpoint.h:46
grpc_core::XdsEndpointResource::operator==
bool operator==(const XdsEndpointResource &other) const
Definition: xds_endpoint.h:116
grpc_core::XdsResourceTypeImpl
Definition: xds_resource_type_impl.h:34
grpc_core::XdsEndpointResource::drop_config
RefCountedPtr< DropConfig > drop_config
Definition: xds_endpoint.h:114
grpc_core::XdsEndpointResource::DropConfig::drop_all
bool drop_all() const
Definition: xds_endpoint.h:99
grpc_core::RefCountedPtr
Definition: ref_counted_ptr.h:35
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
grpc_core::XdsEndpointResource::Priority::Locality
Definition: xds_endpoint.h:47
grpc_core::XdsEndpointResource::Priority::Locality::name
RefCountedPtr< XdsLocalityName > name
Definition: xds_endpoint.h:48
grpc_core::XdsEndpointResource::DropConfig::AddCategory
void AddCategory(std::string name, uint32_t parts_per_million)
Definition: xds_endpoint.h:85
grpc_core::XdsEndpointResource::Priority::Locality::operator!=
bool operator!=(const Locality &other) const
Definition: xds_endpoint.h:56
server_address.h
grpc_core::XdsEndpointResource::Priority::Locality::ToString
std::string ToString() const
Definition: xds_endpoint.cc:56
grpc_core::XdsEndpointResourceType::v2_type_url
absl::string_view v2_type_url() const override
Definition: xds_endpoint.h:128
grpc_core::XdsEndpointResourceType::Decode
absl::StatusOr< DecodeResult > Decode(const XdsEncodingContext &context, absl::string_view serialized_resource, bool is_v2) const override
Definition: xds_endpoint.cc:344
grpc_core::RefCounted
Definition: ref_counted.h:280
grpc_core::XdsEndpointResource::PriorityList
std::vector< Priority > PriorityList
Definition: xds_endpoint.h:65
grpc_core::ServerAddressList
std::vector< ServerAddress > ServerAddressList
Definition: server_address.h:120
stdint.h
grpc_core::XdsEndpointResource::DropConfig::ToString
std::string ToString() const
Definition: xds_endpoint.cc:101
grpc_core::XdsEndpointResource::DropConfig::drop_category_list
const DropCategoryList & drop_category_list() const
Definition: xds_endpoint.h:95
symtab
upb_symtab * symtab
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:774
grpc_core::XdsEndpointResource::DropConfig
Definition: xds_endpoint.h:71
grpc_core::XdsEndpointResource::DropConfig::DropCategory::operator==
bool operator==(const DropCategory &other) const
Definition: xds_endpoint.h:74
grpc_core::XdsEndpointResource::DropConfig::drop_category_list_
DropCategoryList drop_category_list_
Definition: xds_endpoint.h:109
envoy_config_endpoint_v3_ClusterLoadAssignment_getmsgdef
const UPB_INLINE upb_MessageDef * envoy_config_endpoint_v3_ClusterLoadAssignment_getmsgdef(upb_DefPool *s)
Definition: endpoint.upbdefs.h:24
grpc_core::XdsEndpointResource
Definition: xds_endpoint.h:45
ref_counted.h
def.h
grpc_core::XdsEndpointResource::Priority::Locality::lb_weight
uint32_t lb_weight
Definition: xds_endpoint.h:49
grpc_core::XdsEndpointResourceType::type_url
absl::string_view type_url() const override
Definition: xds_endpoint.h:125
grpc_core::XdsEndpointResource::DropConfig::drop_all_
bool drop_all_
Definition: xds_endpoint.h:110
grpc_core::XdsEndpointResource::DropConfig::operator!=
bool operator!=(const DropConfig &other) const
Definition: xds_endpoint.h:104
ref_counted_ptr.h
grpc_core::XdsEndpointResource::Priority::operator==
bool operator==(const Priority &other) const
Definition: xds_endpoint.cc:66
context
grpc::ClientContext context
Definition: istio_echo_server_lib.cc:61
absl::StatusOr
Definition: abseil-cpp/absl/status/statusor.h:187
upb_utils.h
upb_DefPool
Definition: upb/upb/def.c:217
grpc_core::XdsEndpointResource::DropConfig::operator==
bool operator==(const DropConfig &other) const
Definition: xds_endpoint.h:101
port_platform.h
grpc_core::XdsEndpointResource::Priority::Locality::endpoints
ServerAddressList endpoints
Definition: xds_endpoint.h:50


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:56