Debian Codegraph @

src/core/ext/xds/xds_cluster.h

raw
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_CLUSTER_H
18 #define GRPC_CORE_EXT_XDS_XDS_CLUSTER_H
19
20 #include <grpc/support/port_platform.h>
21
22 #include <stdint.h>
23
24 #include <algorithm>
25 #include <memory>
26 #include <string>
27 #include <vector>
28
29 #include "absl/strings/string_view.h"
30 #include "absl/types/optional.h"
31 #include "envoy/config/cluster/v3/cluster.upbdefs.h"
32 #include "envoy/extensions/clusters/aggregate/v3/cluster.upbdefs.h"
33 #include "envoy/extensions/transport_sockets/tls/v3/tls.upbdefs.h"
34 #include "upb/def.h"
35
36 #include "src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.h"
37 #include "src/core/ext/xds/xds_bootstrap.h"
38 #include "src/core/ext/xds/xds_bootstrap_grpc.h"
39 #include "src/core/ext/xds/xds_client.h"
40 #include "src/core/ext/xds/xds_common_types.h"
41 #include "src/core/ext/xds/xds_resource_type.h"
42 #include "src/core/ext/xds/xds_resource_type_impl.h"
43 #include "src/core/lib/json/json.h"
44
45 namespace grpc_core {
46
47 bool XdsCustomLbPolicyEnabled();
48
49 struct XdsClusterResource : public XdsResourceType::ResourceData {
50 enum ClusterType { EDS, LOGICAL_DNS, AGGREGATE };
51 ClusterType cluster_type;
52 // For cluster type EDS.
53 // The name to use in the EDS request.
54 // If empty, the cluster name will be used.
55 std::string eds_service_name;
56 // For cluster type LOGICAL_DNS.
57 // The hostname to lookup in DNS.
58 std::string dns_hostname;
59 // For cluster type AGGREGATE.
60 // The prioritized list of cluster names.
61 std::vector<std::string> prioritized_cluster_names;
62
63 // Tls Context used by clients
64 CommonTlsContext common_tls_context;
65
66 // The LRS server to use for load reporting.
67 // If not set, load reporting will be disabled.
68 absl::optional<GrpcXdsBootstrap::GrpcXdsServer> lrs_load_reporting_server;
69
70 // The LB policy to use for locality and endpoint picking.
71 Json::Array lb_policy_config;
72
73 // Maximum number of outstanding requests can be made to the upstream
74 // cluster.
75 uint32_t max_concurrent_requests = 1024;
76
77 absl::optional<OutlierDetectionConfig> outlier_detection;
78
79 bool operator==(const XdsClusterResource& other) const {
80 return cluster_type == other.cluster_type &&
81 eds_service_name == other.eds_service_name &&
82 dns_hostname == other.dns_hostname &&
83 prioritized_cluster_names == other.prioritized_cluster_names &&
84 common_tls_context == other.common_tls_context &&
85 lrs_load_reporting_server == other.lrs_load_reporting_server &&
86 lb_policy_config == other.lb_policy_config &&
87 max_concurrent_requests == other.max_concurrent_requests &&
88 outlier_detection == other.outlier_detection;
89 }
90
91 std::string ToString() const;
92 };
93
94 class XdsClusterResourceType
95 : public XdsResourceTypeImpl<XdsClusterResourceType, XdsClusterResource> {
96 public:
97 absl::string_view type_url() const override {
98 return "envoy.config.cluster.v3.Cluster";
99 }
100
101 DecodeResult Decode(const XdsResourceType::DecodeContext& context,
102 absl::string_view serialized_resource) const override;
103
104 bool AllResourcesRequiredInSotW() const override { return true; }
105
106 void InitUpbSymtab(XdsClient*, upb_DefPool* symtab) const override {
107 envoy_config_cluster_v3_Cluster_getmsgdef(symtab);
108 envoy_extensions_clusters_aggregate_v3_ClusterConfig_getmsgdef(symtab);
109 envoy_extensions_transport_sockets_tls_v3_UpstreamTlsContext_getmsgdef(
110 symtab);
111 }
112 };
113
114 } // namespace grpc_core
115
116 #endif // GRPC_CORE_EXT_XDS_XDS_CLUSTER_H