xds_api.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_API_H
18 #define GRPC_CORE_EXT_XDS_XDS_API_H
19 
21 
22 #include <stddef.h>
23 
24 #include <map>
25 #include <set>
26 #include <string>
27 #include <utility>
28 #include <vector>
29 
30 #include "absl/status/status.h"
31 #include "absl/strings/string_view.h"
33 #include "upb/def.hpp"
34 
35 #include <grpc/slice.h>
36 
45 
46 namespace grpc_core {
47 
48 class XdsClient;
49 
50 // TODO(roth): When we have time, split this into multiple pieces:
51 // - a common upb-based parsing framework (combine with XdsEncodingContext)
52 // - ADS request/response handling
53 // - LRS request/response handling
54 // - CSDS response generation
55 class XdsApi {
56  public:
57  // Interface defined by caller and passed to ParseAdsResponse().
59  public:
64  size_t num_resources;
65  };
66 
67  virtual ~AdsResponseParserInterface() = default;
68 
69  // Called when the top-level ADS fields are parsed.
70  // If this returns non-OK, parsing will stop, and the individual
71  // resources will not be processed.
73 
74  // Called to parse each individual resource in the ADS response.
75  virtual void ParseResource(const XdsEncodingContext& context, size_t idx,
77  absl::string_view serialized_resource) = 0;
78  };
79 
82  std::map<RefCountedPtr<XdsLocalityName>, XdsClusterLocalityStats::Snapshot,
86  };
88  std::pair<std::string /*cluster_name*/, std::string /*eds_service_name*/>,
90 
91  // The metadata of the xDS resource; used by the xDS config dump.
93  // Resource status from the view of a xDS client, which tells the
94  // synchronization status between the xDS client and the xDS server.
96  // Client requested this resource but hasn't received any update from
97  // management server. The client will not fail requests, but will queue
98  // them
99  // until update arrives or the client times out waiting for the resource.
101  // This resource has been requested by the client but has either not been
102  // delivered by the server or was previously delivered by the server and
103  // then subsequently removed from resources provided by the server.
105  // Client received this resource and replied with ACK.
107  // Client received this resource and replied with NACK.
109  };
110 
111  // The client status of this resource.
113  // The serialized bytes of the last successfully updated raw xDS resource.
115  // The timestamp when the resource was last successfully updated.
117  // The last successfully updated version of the resource.
119  // The rejected version string of the last failed update attempt.
121  // Details about the last failed update attempt.
123  // Timestamp of the last failed update attempt.
125  };
126  using ResourceMetadataMap =
127  std::map<std::string /*resource_name*/, const ResourceMetadata*>;
130  static_assert(static_cast<ResourceMetadata::ClientResourceStatus>(
132  ResourceMetadata::ClientResourceStatus::REQUESTED,
133  "");
134  static_assert(static_cast<ResourceMetadata::ClientResourceStatus>(
136  ResourceMetadata::ClientResourceStatus::DOES_NOT_EXIST,
137  "");
138  static_assert(static_cast<ResourceMetadata::ClientResourceStatus>(
140  ResourceMetadata::ClientResourceStatus::ACKED,
141  "");
142  static_assert(static_cast<ResourceMetadata::ClientResourceStatus>(
144  ResourceMetadata::ClientResourceStatus::NACKED,
145  "");
146 
147  XdsApi(XdsClient* client, TraceFlag* tracer, const XdsBootstrap::Node* node,
150 
151  // Creates an ADS request.
152  // Takes ownership of \a error.
156  absl::string_view nonce,
157  const std::vector<std::string>& resource_names,
158  grpc_error_handle error, bool populate_node);
159 
160  // Returns non-OK when failing to deserialize response message.
161  // Otherwise, all events are reported to the parser.
163  const grpc_slice& encoded_response,
165 
166  // Creates an initial LRS request.
168 
169  // Creates an LRS request sending a client-side load report.
170  grpc_slice CreateLrsRequest(ClusterLoadReportMap cluster_load_report_map);
171 
172  // Parses the LRS response and returns \a
173  // load_reporting_interval for client-side load reporting. If there is any
174  // error, the output config is invalid.
175  grpc_error_handle ParseLrsResponse(const grpc_slice& encoded_response,
176  bool* send_all_clusters,
177  std::set<std::string>* cluster_names,
178  Duration* load_reporting_interval);
179 
180  // Assemble the client config proto message and return the serialized result.
182  const ResourceTypeMetadataMap& resource_type_metadata_map);
183 
184  private:
187  const XdsBootstrap::Node* node_; // Do not own.
190  upb::SymbolTable* symtab_; // Do not own.
194 };
195 
196 } // namespace grpc_core
197 
198 #endif // GRPC_CORE_EXT_XDS_XDS_API_H
trace.h
grpc_core::XdsApi::client_
XdsClient * client_
Definition: xds_api.h:185
grpc_core::XdsApi::ResourceMetadata::version
std::string version
Definition: xds_api.h:118
grpc_core::XdsApi::ClusterLoadReport::dropped_requests
XdsClusterDropStats::Snapshot dropped_requests
Definition: xds_api.h:81
grpc_core::XdsApi::ResourceMetadata::failed_update_time
Timestamp failed_update_time
Definition: xds_api.h:124
upb::SymbolTable
Definition: def.hpp:377
xds_client_stats.h
certificate_provider_store.h
slice.h
grpc_core::XdsApi::CreateLrsRequest
grpc_slice CreateLrsRequest(ClusterLoadReportMap cluster_load_report_map)
Definition: xds_api.cc:529
grpc_core::XdsEncodingContext
Definition: upb_utils.h:39
grpc_core
Definition: call_metric_recorder.h:31
client
Definition: examples/python/async_streaming/client.py:1
grpc_core::XdsApi::AdsResponseParserInterface::ParseResource
virtual void ParseResource(const XdsEncodingContext &context, size_t idx, absl::string_view type_url, absl::string_view serialized_resource)=0
grpc_core::XdsApi::ResourceMetadata::update_time
Timestamp update_time
Definition: xds_api.h:116
grpc_core::XdsClient
Definition: xds_client.h:60
envoy_admin_v3_NACKED
@ envoy_admin_v3_NACKED
Definition: config_dump.upb.h:101
absl::string_view
Definition: abseil-cpp/absl/strings/string_view.h:167
grpc_core::Timestamp
Definition: src/core/lib/gprpp/time.h:62
grpc_core::XdsApi::user_agent_name_
const std::string user_agent_name_
Definition: xds_api.h:192
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
error
grpc_error_handle error
Definition: retry_filter.cc:499
grpc_core::XdsApi::ResourceMetadata::DOES_NOT_EXIST
@ DOES_NOT_EXIST
Definition: xds_api.h:104
envoy_admin_v3_DOES_NOT_EXIST
@ envoy_admin_v3_DOES_NOT_EXIST
Definition: config_dump.upb.h:99
grpc_core::XdsApi::ResourceMetadata::failed_details
std::string failed_details
Definition: xds_api.h:122
grpc_core::XdsApi::ResourceMetadata::failed_version
std::string failed_version
Definition: xds_api.h:120
version
Definition: version.py:1
def.hpp
grpc_core::XdsBootstrap::Node
Definition: xds_bootstrap.h:43
map
zval * map
Definition: php/ext/google/protobuf/encode_decode.c:480
envoy_admin_v3_REQUESTED
@ envoy_admin_v3_REQUESTED
Definition: config_dump.upb.h:98
grpc_core::CertificateProviderStore::PluginDefinitionMap
std::map< std::string, PluginDefinition > PluginDefinitionMap
Definition: certificate_provider_store.h:55
grpc_core::XdsApi::ResourceMetadata::client_status
ClientResourceStatus client_status
Definition: xds_api.h:112
grpc_core::XdsApi::XdsApi
XdsApi(XdsClient *client, TraceFlag *tracer, const XdsBootstrap::Node *node, const CertificateProviderStore::PluginDefinitionMap *map, upb::SymbolTable *symtab)
Definition: xds_api.cc:81
grpc_core::XdsApi::ResourceTypeMetadataMap
std::map< absl::string_view, ResourceMetadataMap > ResourceTypeMetadataMap
Definition: xds_api.h:129
grpc_core::XdsApi::AdsResponseParserInterface::ProcessAdsResponseFields
virtual absl::Status ProcessAdsResponseFields(AdsResponseFields fields)=0
grpc_core::XdsApi::AssembleClientConfig
std::string AssembleClientConfig(const ResourceTypeMetadataMap &resource_type_metadata_map)
Definition: xds_api.cc:652
asyncio_get_stats.parser
parser
Definition: asyncio_get_stats.py:34
grpc_core::XdsApi::ResourceMetadata
Definition: xds_api.h:92
grpc_core::XdsApi::AdsResponseParserInterface
Definition: xds_api.h:58
grpc_core::XdsApi::ResourceMetadata::NACKED
@ NACKED
Definition: xds_api.h:108
grpc_core::XdsClusterLocalityStats::Snapshot
Definition: xds_client_stats.h:176
grpc_core::XdsApi::CreateAdsRequest
grpc_slice CreateAdsRequest(const XdsBootstrap::XdsServer &server, absl::string_view type_url, absl::string_view version, absl::string_view nonce, const std::vector< std::string > &resource_names, grpc_error_handle error, bool populate_node)
Definition: xds_api.cc:272
grpc_core::XdsApi::AdsResponseParserInterface::AdsResponseFields::num_resources
size_t num_resources
Definition: xds_api.h:64
grpc_core::XdsClusterDropStats::Snapshot
Definition: xds_client_stats.h:109
grpc_core::XdsApi::CreateLrsInitialRequest
grpc_slice CreateLrsInitialRequest(const XdsBootstrap::XdsServer &server)
Definition: xds_api.cc:452
xds_bootstrap.h
grpc_core::XdsApi::AdsResponseParserInterface::AdsResponseFields::version
std::string version
Definition: xds_api.h:62
grpc_core::XdsApi::symtab_
upb::SymbolTable * symtab_
Definition: xds_api.h:190
grpc_core::XdsApi::AdsResponseParserInterface::AdsResponseFields::type_url
std::string type_url
Definition: xds_api.h:61
grpc_core::XdsApi::ResourceMetadata::ClientResourceStatus
ClientResourceStatus
Definition: xds_api.h:95
time.h
grpc_slice
Definition: include/grpc/impl/codegen/slice.h:65
error.h
grpc_core::XdsApi::AdsResponseParserInterface::AdsResponseFields::nonce
std::string nonce
Definition: xds_api.h:63
setup.idx
idx
Definition: third_party/bloaty/third_party/capstone/bindings/python/setup.py:197
envoy_admin_v3_ACKED
@ envoy_admin_v3_ACKED
Definition: config_dump.upb.h:100
grpc_core::TraceFlag
Definition: debug/trace.h:63
symtab
upb_symtab * symtab
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:774
grpc_core::XdsApi::ClusterLoadReport
Definition: xds_api.h:80
grpc_core::XdsApi::build_version_
const std::string build_version_
Definition: xds_api.h:191
grpc_core::XdsBootstrap::XdsServer
Definition: xds_bootstrap.h:52
server
Definition: examples/python/async_streaming/server.py:1
grpc_core::XdsApi::certificate_provider_definition_map_
const CertificateProviderStore::PluginDefinitionMap * certificate_provider_definition_map_
Definition: xds_api.h:189
grpc_core::XdsApi::ResourceMetadata::ACKED
@ ACKED
Definition: xds_api.h:106
grpc_core::XdsApi::ParseLrsResponse
grpc_error_handle ParseLrsResponse(const grpc_slice &encoded_response, bool *send_all_clusters, std::set< std::string > *cluster_names, Duration *load_reporting_interval)
Definition: xds_api.cc:600
grpc_core::XdsApi::ResourceMetadataMap
std::map< std::string, const ResourceMetadata * > ResourceMetadataMap
Definition: xds_api.h:127
absl::Status
Definition: third_party/abseil-cpp/absl/status/status.h:424
profile_analyzer.fields
list fields
Definition: profile_analyzer.py:266
grpc_core::XdsApi::AdsResponseParserInterface::AdsResponseFields
Definition: xds_api.h:60
grpc_core::XdsApi::tracer_
TraceFlag * tracer_
Definition: xds_api.h:186
grpc_core::XdsApi::ClusterLoadReport::load_report_interval
Duration load_report_interval
Definition: xds_api.h:85
type_url
string * type_url
Definition: bloaty/third_party/protobuf/conformance/conformance_cpp.cc:72
ref_counted_ptr.h
grpc_core::XdsApi::AdsResponseParserInterface::~AdsResponseParserInterface
virtual ~AdsResponseParserInterface()=default
grpc_core::XdsLocalityName::Less
Definition: xds_client_stats.h:48
grpc_core::XdsApi::ParseAdsResponse
absl::Status ParseAdsResponse(const XdsBootstrap::XdsServer &server, const grpc_slice &encoded_response, AdsResponseParserInterface *parser)
Definition: xds_api.cc:358
context
grpc::ClientContext context
Definition: istio_echo_server_lib.cc:61
grpc_core::XdsApi
Definition: xds_api.h:55
grpc_error
Definition: error_internal.h:42
grpc_core::XdsApi::user_agent_version_
const std::string user_agent_version_
Definition: xds_api.h:193
upb_utils.h
grpc_core::Duration
Definition: src/core/lib/gprpp/time.h:122
pair
std::pair< std::string, std::string > pair
Definition: abseil-cpp/absl/container/internal/raw_hash_set_benchmark.cc:78
grpc_core::XdsApi::node_
const XdsBootstrap::Node * node_
Definition: xds_api.h:187
grpc_core::XdsApi::ClusterLoadReport::locality_stats
std::map< RefCountedPtr< XdsLocalityName >, XdsClusterLocalityStats::Snapshot, XdsLocalityName::Less > locality_stats
Definition: xds_api.h:84
grpc_core::XdsApi::ClusterLoadReportMap
std::map< std::pair< std::string, std::string >, ClusterLoadReport > ClusterLoadReportMap
Definition: xds_api.h:89
config_dump.upb.h
grpc_core::XdsApi::ResourceMetadata::REQUESTED
@ REQUESTED
Definition: xds_api.h:100
grpc_core::XdsApi::ResourceMetadata::serialized_proto
std::string serialized_proto
Definition: xds_api.h:114
port_platform.h


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