• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_SRC_CORE_EXT_XDS_XDS_CLUSTER_H
18 #define GRPC_SRC_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 <set>
27 #include <string>
28 #include <vector>
29 
30 #include "absl/strings/string_view.h"
31 #include "absl/types/optional.h"
32 #include "absl/types/variant.h"
33 #include "envoy/config/cluster/v3/cluster.upbdefs.h"
34 #include "envoy/extensions/clusters/aggregate/v3/cluster.upbdefs.h"
35 #include "envoy/extensions/transport_sockets/tls/v3/tls.upbdefs.h"
36 #include "upb/reflection/def.h"
37 
38 #include "src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.h"
39 #include "src/core/ext/xds/xds_bootstrap.h"
40 #include "src/core/ext/xds/xds_bootstrap_grpc.h"
41 #include "src/core/ext/xds/xds_client.h"
42 #include "src/core/ext/xds/xds_common_types.h"
43 #include "src/core/ext/xds/xds_health_status.h"
44 #include "src/core/ext/xds/xds_resource_type.h"
45 #include "src/core/ext/xds/xds_resource_type_impl.h"
46 #include "src/core/lib/json/json.h"
47 
48 namespace grpc_core {
49 
50 bool XdsOverrideHostEnabled();
51 
52 struct XdsClusterResource : public XdsResourceType::ResourceData {
53   struct Eds {
54     // If empty, defaults to the cluster name.
55     std::string eds_service_name;
56 
57     bool operator==(const Eds& other) const {
58       return eds_service_name == other.eds_service_name;
59     }
60   };
61 
62   struct LogicalDns {
63     // The hostname to lookup in DNS.
64     std::string hostname;
65 
66     bool operator==(const LogicalDns& other) const {
67       return hostname == other.hostname;
68     }
69   };
70 
71   struct Aggregate {
72     // Prioritized list of cluster names.
73     std::vector<std::string> prioritized_cluster_names;
74 
75     bool operator==(const Aggregate& other) const {
76       return prioritized_cluster_names == other.prioritized_cluster_names;
77     }
78   };
79 
80   absl::variant<Eds, LogicalDns, Aggregate> type;
81 
82   // The LB policy to use for locality and endpoint picking.
83   Json::Array lb_policy_config;
84 
85   // Note: Remaining fields are not used for aggregate clusters.
86 
87   // The LRS server to use for load reporting.
88   // If not set, load reporting will be disabled.
89   absl::optional<GrpcXdsBootstrap::GrpcXdsServer> lrs_load_reporting_server;
90 
91   // Tls Context used by clients
92   CommonTlsContext common_tls_context;
93 
94   // Maximum number of outstanding requests can be made to the upstream
95   // cluster.
96   uint32_t max_concurrent_requests = 1024;
97 
98   absl::optional<OutlierDetectionConfig> outlier_detection;
99 
100   std::set<XdsHealthStatus> override_host_statuses;
101 
102   bool operator==(const XdsClusterResource& other) const {
103     return type == other.type && lb_policy_config == other.lb_policy_config &&
104            lrs_load_reporting_server == other.lrs_load_reporting_server &&
105            common_tls_context == other.common_tls_context &&
106            max_concurrent_requests == other.max_concurrent_requests &&
107            outlier_detection == other.outlier_detection &&
108            override_host_statuses == other.override_host_statuses;
109   }
110 
111   std::string ToString() const;
112 };
113 
114 class XdsClusterResourceType
115     : public XdsResourceTypeImpl<XdsClusterResourceType, XdsClusterResource> {
116  public:
type_url()117   absl::string_view type_url() const override {
118     return "envoy.config.cluster.v3.Cluster";
119   }
120 
121   DecodeResult Decode(const XdsResourceType::DecodeContext& context,
122                       absl::string_view serialized_resource) const override;
123 
AllResourcesRequiredInSotW()124   bool AllResourcesRequiredInSotW() const override { return true; }
125 
InitUpbSymtab(XdsClient *,upb_DefPool * symtab)126   void InitUpbSymtab(XdsClient*, upb_DefPool* symtab) const override {
127     envoy_config_cluster_v3_Cluster_getmsgdef(symtab);
128     envoy_extensions_clusters_aggregate_v3_ClusterConfig_getmsgdef(symtab);
129     envoy_extensions_transport_sockets_tls_v3_UpstreamTlsContext_getmsgdef(
130         symtab);
131   }
132 };
133 
134 }  // namespace grpc_core
135 
136 #endif  // GRPC_SRC_CORE_EXT_XDS_XDS_CLUSTER_H
137