1// Copyright 2016 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// A ServiceConfig is supplied when a service is deployed. It mostly contains 16// parameters for how clients that connect to the service should behave (for 17// example, the load balancing policy to use to pick between service replicas). 18// 19// The configuration options provided here act as overrides to automatically 20// chosen option values. Service owners should be conservative in specifying 21// options as the system is likely to choose better values for these options in 22// the vast majority of cases. In other words, please specify a configuration 23// option only if you really have to, and avoid copy-paste inclusion of configs. 24// 25// Note that gRPC uses the service config in JSON form, not in protobuf 26// form. This proto definition is intended to help document the schema but 27// will not actually be used directly by gRPC. 28 29syntax = "proto3"; 30 31package grpc.service_config; 32 33import "google/protobuf/duration.proto"; 34import "google/protobuf/struct.proto"; 35import "google/protobuf/wrappers.proto"; 36import "google/rpc/code.proto"; 37 38option java_package = "io.grpc.serviceconfig"; 39option java_multiple_files = true; 40option java_outer_classname = "ServiceConfigProto"; 41 42// Configuration for a method. 43message MethodConfig { 44 // The names of the methods to which this configuration applies. 45 // - MethodConfig without names (empty list) will be skipped. 46 // - Each name entry must be unique across the entire ServiceConfig. 47 // - If the 'method' field is empty, this MethodConfig specifies the defaults 48 // for all methods for the specified service. 49 // - If the 'service' field is empty, the 'method' field must be empty, and 50 // this MethodConfig specifies the default for all methods (it's the default 51 // config). 52 // 53 // When determining which MethodConfig to use for a given RPC, the most 54 // specific match wins. For example, let's say that the service config 55 // contains the following MethodConfig entries: 56 // 57 // method_config { name { } ... } 58 // method_config { name { service: "MyService" } ... } 59 // method_config { name { service: "MyService" method: "Foo" } ... } 60 // 61 // MyService/Foo will use the third entry, because it exactly matches the 62 // service and method name. MyService/Bar will use the second entry, because 63 // it provides the default for all methods of MyService. AnotherService/Baz 64 // will use the first entry, because it doesn't match the other two. 65 // 66 // In JSON representation, value "", value `null`, and not present are the 67 // same. The following are the same Name: 68 // - { "service": "s" } 69 // - { "service": "s", "method": null } 70 // - { "service": "s", "method": "" } 71 message Name { 72 string service = 1; // Required. Includes proto package name. 73 string method = 2; 74 } 75 repeated Name name = 1; 76 77 // Whether RPCs sent to this method should wait until the connection is 78 // ready by default. If false, the RPC will abort immediately if there is 79 // a transient failure connecting to the server. Otherwise, gRPC will 80 // attempt to connect until the deadline is exceeded. 81 // 82 // The value specified via the gRPC client API will override the value 83 // set here. However, note that setting the value in the client API will 84 // also affect transient errors encountered during name resolution, which 85 // cannot be caught by the value here, since the service config is 86 // obtained by the gRPC client via name resolution. 87 google.protobuf.BoolValue wait_for_ready = 2; 88 89 // The default timeout in seconds for RPCs sent to this method. This can be 90 // overridden in code. If no reply is received in the specified amount of 91 // time, the request is aborted and a DEADLINE_EXCEEDED error status 92 // is returned to the caller. 93 // 94 // The actual deadline used will be the minimum of the value specified here 95 // and the value set by the application via the gRPC client API. If either 96 // one is not set, then the other will be used. If neither is set, then the 97 // request has no deadline. 98 google.protobuf.Duration timeout = 3; 99 100 // The maximum allowed payload size for an individual request or object in a 101 // stream (client->server) in bytes. The size which is measured is the 102 // serialized payload after per-message compression (but before stream 103 // compression) in bytes. This applies both to streaming and non-streaming 104 // requests. 105 // 106 // The actual value used is the minimum of the value specified here and the 107 // value set by the application via the gRPC client API. If either one is 108 // not set, then the other will be used. If neither is set, then the 109 // built-in default is used. 110 // 111 // If a client attempts to send an object larger than this value, it will not 112 // be sent and the client will see a ClientError. 113 // Note that 0 is a valid value, meaning that the request message 114 // must be empty. 115 google.protobuf.UInt32Value max_request_message_bytes = 4; 116 117 // The maximum allowed payload size for an individual response or object in a 118 // stream (server->client) in bytes. The size which is measured is the 119 // serialized payload after per-message compression (but before stream 120 // compression) in bytes. This applies both to streaming and non-streaming 121 // requests. 122 // 123 // The actual value used is the minimum of the value specified here and the 124 // value set by the application via the gRPC client API. If either one is 125 // not set, then the other will be used. If neither is set, then the 126 // built-in default is used. 127 // 128 // If a server attempts to send an object larger than this value, it will not 129 // be sent, and a ServerError will be sent to the client instead. 130 // Note that 0 is a valid value, meaning that the response message 131 // must be empty. 132 google.protobuf.UInt32Value max_response_message_bytes = 5; 133 134 // The retry policy for outgoing RPCs. 135 message RetryPolicy { 136 // The maximum number of RPC attempts, including the original attempt. 137 // 138 // This field is required and must be greater than 1. 139 // Any value greater than 5 will be treated as if it were 5. 140 uint32 max_attempts = 1; 141 142 // Exponential backoff parameters. The initial retry attempt will occur at 143 // random(0, initial_backoff). In general, the nth attempt will occur at 144 // random(0, 145 // min(initial_backoff*backoff_multiplier**(n-1), max_backoff)). 146 // Required. Must be greater than zero. 147 google.protobuf.Duration initial_backoff = 2; 148 // Required. Must be greater than zero. 149 google.protobuf.Duration max_backoff = 3; 150 float backoff_multiplier = 4; // Required. Must be greater than zero. 151 152 // The set of status codes which may be retried. 153 // 154 // This field is required and must be non-empty. 155 repeated google.rpc.Code retryable_status_codes = 5; 156 } 157 158 // The hedging policy for outgoing RPCs. Hedged RPCs may execute more than 159 // once on the server, so only idempotent methods should specify a hedging 160 // policy. 161 message HedgingPolicy { 162 // The hedging policy will send up to max_requests RPCs. 163 // This number represents the total number of all attempts, including 164 // the original attempt. 165 // 166 // This field is required and must be greater than 1. 167 // Any value greater than 5 will be treated as if it were 5. 168 uint32 max_attempts = 1; 169 170 // The first RPC will be sent immediately, but the max_requests-1 subsequent 171 // hedged RPCs will be sent at intervals of every hedging_delay. Set this 172 // to 0 to immediately send all max_requests RPCs. 173 google.protobuf.Duration hedging_delay = 2; 174 175 // The set of status codes which indicate other hedged RPCs may still 176 // succeed. If a non-fatal status code is returned by the server, hedged 177 // RPCs will continue. Otherwise, outstanding requests will be canceled and 178 // the error returned to the client application layer. 179 // 180 // This field is optional. 181 repeated google.rpc.Code non_fatal_status_codes = 3; 182 } 183 184 // Only one of retry_policy or hedging_policy may be set. If neither is set, 185 // RPCs will not be retried or hedged. 186 oneof retry_or_hedging_policy { 187 RetryPolicy retry_policy = 6; 188 HedgingPolicy hedging_policy = 7; 189 } 190} 191 192// Configuration for pick_first LB policy. 193message PickFirstConfig {} 194 195// Configuration for round_robin LB policy. 196message RoundRobinConfig {} 197 198// Configuration for grpclb LB policy. 199message GrpcLbConfig { 200 // Optional. What LB policy to use for routing between the backend 201 // addresses. If unset, defaults to round_robin. 202 // Currently, the only supported values are round_robin and pick_first. 203 // Note that this will be used both in balancer mode and in fallback mode. 204 // Multiple LB policies can be specified; clients will iterate through 205 // the list in order and stop at the first policy that they support. 206 repeated LoadBalancingConfig child_policy = 1; 207 // Optional. If specified, overrides the name of the service to be sent to 208 // the balancer. 209 string service_name = 2; 210} 211 212// Configuration for priority LB policy. 213message PriorityLoadBalancingPolicyConfig { 214 // A map of name to child policy configuration. 215 // The names are used to allow the priority policy to update 216 // existing child policies instead of creating new ones every 217 // time it receives a config update. 218 message Child { 219 repeated LoadBalancingConfig config = 1; 220 221 // If true, will ignore reresolution requests from this child. 222 bool ignore_reresolution_requests = 2; 223 } 224 map<string, Child> children = 1; 225 226 // A list of child names in decreasing priority order 227 // (i.e., first element is the highest priority). 228 repeated string priorities = 2; 229} 230 231// Configuration for weighted_target LB policy. 232message WeightedTargetLoadBalancingPolicyConfig { 233 message Target { 234 uint32 weight = 1; 235 repeated LoadBalancingConfig child_policy = 2; 236 } 237 map<string, Target> targets = 1; 238} 239 240// Configuration for xds_cluster_manager_experimental LB policy. 241message XdsClusterManagerLoadBalancingPolicyConfig { 242 message Child { 243 repeated LoadBalancingConfig child_policy = 1; 244 } 245 map<string, Child> children = 1; 246} 247 248// Configuration for the cds LB policy. 249message CdsConfig { 250 string cluster = 1; // Required. 251} 252 253// Represents an xDS server. 254message XdsServer { 255 string server_uri = 1 [json_name = "server_uri"]; // Required. 256 257 message ChannelCredentials { 258 string type = 1; // Required. 259 google.protobuf.Struct config = 2; // Optional JSON config. 260 } 261 // A list of channel creds to use. The first supported type will be used. 262 repeated ChannelCredentials channel_creds = 2 [json_name = "channel_creds"]; 263 264 // A repeated list of server features. 265 repeated google.protobuf.Value server_features = 3 266 [json_name = "server_features"]; 267} 268 269// Configuration for xds_cluster_resolver LB policy. 270message XdsClusterResolverLoadBalancingPolicyConfig { 271 // Describes a discovery mechanism instance. 272 // For EDS or LOGICAL_DNS clusters, there will be exactly one 273 // DiscoveryMechanism, which will describe the cluster of the parent 274 // CDS policy. 275 // For aggregate clusters, there will be one DiscoveryMechanism for each 276 // underlying cluster. 277 message DiscoveryMechanism { 278 // Cluster name. 279 string cluster = 1; 280 281 // LRS server to send load reports to. 282 // If not present, load reporting will be disabled. 283 // If set to the empty string, load reporting will be sent to the same 284 // server that we obtained CDS data from. 285 // DEPRECATED: Use new lrs_load_reporting_server field instead. 286 google.protobuf.StringValue lrs_load_reporting_server_name = 2 287 [deprecated=true]; 288 289 // LRS server to send load reports to. 290 // If not present, load reporting will be disabled. 291 // Supercedes lrs_load_reporting_server_name field. 292 XdsServer lrs_load_reporting_server = 7; 293 294 // Maximum number of outstanding requests can be made to the upstream 295 // cluster. Default is 1024. 296 google.protobuf.UInt32Value max_concurrent_requests = 3; 297 298 enum Type { 299 UNKNOWN = 0; 300 EDS = 1; 301 LOGICAL_DNS = 2; 302 }; 303 Type type = 4; 304 305 // For type EDS only. 306 // EDS service name, as returned in CDS. 307 // May be unset if not specified in CDS. 308 string eds_service_name = 5; 309 310 // For type LOGICAL_DNS only. 311 // DNS name to resolve in "host:port" form. 312 string dns_hostname = 6; 313 } 314 315 // Ordered list of discovery mechanisms. 316 // Must have at least one element. 317 // Results from each discovery mechanism are concatenated together in 318 // successive priorities. 319 repeated DiscoveryMechanism discovery_mechanisms = 1; 320 321 // xDS LB policy. 322 // This represents the xDS LB policy, which does not necessarily map 323 // one-to-one to a gRPC LB policy. Currently, the following policies 324 // are supported: 325 // - "ROUND_ROBIN" (config is empty) 326 // - "RING_HASH" (config is a RingHashLoadBalancingConfig) 327 repeated LoadBalancingConfig xds_lb_policy = 2; 328} 329 330// Configuration for xds_cluster_impl LB policy. 331message XdsClusterImplLoadBalancingPolicyConfig { 332 // Cluster name. Required. 333 string cluster = 1; 334 335 // EDS service name. 336 // Not set if cluster is not an EDS cluster or if it does not 337 // specify an EDS service name. 338 string eds_service_name = 2; 339 340 // Server to send load reports to. 341 // If unset, no load reporting is done. 342 // If set to empty string, load reporting will be sent to the same 343 // server as we are getting xds data from. 344 // DEPRECATED: Use new lrs_load_reporting_server field instead. 345 google.protobuf.StringValue lrs_load_reporting_server_name = 3 346 [deprecated=true]; 347 348 // LRS server to send load reports to. 349 // If not present, load reporting will be disabled. 350 // Supercedes lrs_load_reporting_server_name field. 351 XdsServer lrs_load_reporting_server = 7; 352 353 // Maximum number of outstanding requests can be made to the upstream cluster. 354 // Default is 1024. 355 google.protobuf.UInt32Value max_concurrent_requests = 4; 356 357 // Drop configuration. 358 message DropCategory { 359 string category = 1; 360 uint32 requests_per_million = 2; 361 } 362 repeated DropCategory drop_categories = 5; 363 364 // Child policy. 365 repeated LoadBalancingConfig child_policy = 6; 366} 367 368// Configuration for eds LB policy. 369message EdsLoadBalancingPolicyConfig { 370 // Cluster name. Required. 371 string cluster = 1; 372 373 // EDS service name, as returned in CDS. 374 // May be unset if not specified in CDS. 375 string eds_service_name = 2; 376 377 // Server to send load reports to. 378 // If unset, no load reporting is done. 379 // If set to empty string, load reporting will be sent to the same 380 // server as we are getting xds data from. 381 google.protobuf.StringValue lrs_load_reporting_server_name = 3; 382 383 // Locality-picking policy. 384 // This policy's config is expected to be in the format used 385 // by the weighted_target policy. Note that the config should include 386 // an empty value for the "targets" field; that empty value will be 387 // replaced by one that is dynamically generated based on the EDS data. 388 // Optional; defaults to "weighted_target". 389 repeated LoadBalancingConfig locality_picking_policy = 4; 390 391 // Endpoint-picking policy. 392 // This will be configured as the policy for each child in the 393 // locality-policy's config. 394 // Optional; defaults to "round_robin". 395 repeated LoadBalancingConfig endpoint_picking_policy = 5; 396} 397 398// Configuration for ring_hash LB policy. 399message RingHashLoadBalancingConfig { 400 uint64 min_ring_size = 1; 401 uint64 max_ring_size = 2; 402} 403 404// Configuration for lrs LB policy. 405message LrsLoadBalancingPolicyConfig { 406 // Cluster name. Required. 407 string cluster_name = 1; 408 409 // EDS service name, as returned in CDS. 410 // May be unset if not specified in CDS. 411 string eds_service_name = 2; 412 413 // Server to send load reports to. Required. 414 // If set to empty string, load reporting will be sent to the same 415 // server as we are getting xds data from. 416 string lrs_load_reporting_server_name = 3; 417 418 // The locality for which this policy will report load. Required. 419 message Locality { 420 string region = 1; 421 string zone = 2; 422 string subzone = 3; 423 } 424 Locality locality = 4; 425 426 // Endpoint-picking policy. 427 repeated LoadBalancingConfig child_policy = 5; 428} 429 430// Configuration for xds LB policy. 431message XdsConfig { 432 // Name of balancer to connect to. 433 string balancer_name = 1 [deprecated = true]; 434 // Optional. What LB policy to use for intra-locality routing. 435 // If unset, will use whatever algorithm is specified by the balancer. 436 // Multiple LB policies can be specified; clients will iterate through 437 // the list in order and stop at the first policy that they support. 438 repeated LoadBalancingConfig child_policy = 2; 439 // Optional. What LB policy to use in fallback mode. If not 440 // specified, defaults to round_robin. 441 // Multiple LB policies can be specified; clients will iterate through 442 // the list in order and stop at the first policy that they support. 443 repeated LoadBalancingConfig fallback_policy = 3; 444 // Optional. Name to use in EDS query. If not present, defaults to 445 // the server name from the target URI. 446 string eds_service_name = 4; 447 // LRS server to send load reports to. 448 // If not present, load reporting will be disabled. 449 // If set to the empty string, load reporting will be sent to the same 450 // server that we obtained CDS data from. 451 google.protobuf.StringValue lrs_load_reporting_server_name = 5; 452} 453 454// Selects LB policy and provides corresponding configuration. 455// 456// In general, all instances of this field should be repeated. Clients will 457// iterate through the list in order and stop at the first policy that they 458// support. This allows the service config to specify custom policies that may 459// not be known to all clients. 460// 461// - If the config for the first supported policy is invalid, the whole service 462// config is invalid. 463// - If the list doesn't contain any supported policy, the whole service config 464// is invalid. 465message LoadBalancingConfig { 466 // Exactly one LB policy may be configured. 467 oneof policy { 468 // For each new LB policy supported by gRPC, a new field must be added 469 // here. The field's name must be the LB policy name and its type is a 470 // message that provides whatever configuration parameters are needed 471 // by the LB policy. The configuration message will be passed to the 472 // LB policy when it is instantiated on the client. 473 // 474 // If the LB policy does not require any configuration parameters, the 475 // message for that LB policy may be empty. 476 // 477 // Note that if an LB policy contains another nested LB policy 478 // (e.g., a gslb policy picks the cluster and then delegates to 479 // a round_robin policy to pick the backend within that cluster), its 480 // configuration message may include a nested instance of the 481 // LoadBalancingConfig message to configure the nested LB policy. 482 483 PickFirstConfig pick_first = 4 [json_name = "pick_first"]; 484 485 RoundRobinConfig round_robin = 1 [json_name = "round_robin"]; 486 487 // gRPC lookaside load balancing. 488 // This will eventually be deprecated by the new xDS-based local 489 // balancing policy. 490 GrpcLbConfig grpclb = 3; 491 492 // REMAINING POLICIES ARE EXPERIMENTAL -- DO NOT USE 493 494 PriorityLoadBalancingPolicyConfig priority_experimental = 9 495 [json_name = "priority_experimental"]; 496 WeightedTargetLoadBalancingPolicyConfig weighted_target_experimental = 10 497 [json_name = "weighted_target_experimental"]; 498 499 // xDS-based load balancing. 500 XdsClusterManagerLoadBalancingPolicyConfig xds_cluster_manager_experimental 501 = 14 [json_name = "xds_cluster_manager_experimental"]; 502 CdsConfig cds_experimental = 6 [json_name = "cds_experimental"]; 503 XdsClusterResolverLoadBalancingPolicyConfig 504 xds_cluster_resolver_experimental = 11 505 [json_name = "xds_cluster_resolver_experimental"]; 506 XdsClusterImplLoadBalancingPolicyConfig xds_cluster_impl_experimental = 12 507 [json_name = "xds_cluster_impl_experimental"]; 508 RingHashLoadBalancingConfig ring_hash_experimental = 13 509 [json_name = "ring_hash_experimental"]; 510 511 // Deprecated xDS-related policies. 512 LrsLoadBalancingPolicyConfig lrs_experimental = 8 513 [json_name = "lrs_experimental", deprecated = true]; 514 EdsLoadBalancingPolicyConfig eds_experimental = 7 515 [json_name = "eds_experimental", deprecated = true]; 516 XdsConfig xds = 2 [deprecated = true]; 517 XdsConfig xds_experimental = 5 [json_name = "xds_experimental", 518 deprecated = true]; 519 520 // Next available ID: 14 521 } 522} 523 524// A ServiceConfig represents information about a service but is not specific to 525// any name resolver. 526message ServiceConfig { 527 // Load balancing policy. 528 // 529 // Note that load_balancing_policy is deprecated in favor of 530 // load_balancing_config; the former will be used only if the latter 531 // is unset. 532 // 533 // If no LB policy is configured here, then the default is pick_first. 534 // If the policy name is set via the client API, that value overrides 535 // the value specified here. 536 // 537 // If the deprecated load_balancing_policy field is used, note that if the 538 // resolver returns at least one balancer address (as opposed to backend 539 // addresses), gRPC will use grpclb (see 540 // https://github.com/grpc/grpc/blob/master/doc/load-balancing.md), 541 // regardless of what policy is configured here. However, if the resolver 542 // returns at least one backend address in addition to the balancer 543 // address(es), the client may fall back to the requested policy if it 544 // is unable to reach any of the grpclb load balancers. 545 enum LoadBalancingPolicy { 546 UNSPECIFIED = 0; 547 ROUND_ROBIN = 1; 548 } 549 LoadBalancingPolicy load_balancing_policy = 1 [deprecated = true]; 550 // Multiple LB policies can be specified; clients will iterate through 551 // the list in order and stop at the first policy that they support. If none 552 // are supported, the service config is considered invalid. 553 repeated LoadBalancingConfig load_balancing_config = 4; 554 555 // Per-method configuration. 556 repeated MethodConfig method_config = 2; 557 558 // If a RetryThrottlingPolicy is provided, gRPC will automatically throttle 559 // retry attempts and hedged RPCs when the client's ratio of failures to 560 // successes exceeds a threshold. 561 // 562 // For each server name, the gRPC client will maintain a token_count which is 563 // initially set to max_tokens. Every outgoing RPC (regardless of service or 564 // method invoked) will change token_count as follows: 565 // 566 // - Every failed RPC will decrement the token_count by 1. 567 // - Every successful RPC will increment the token_count by token_ratio. 568 // 569 // If token_count is less than or equal to max_tokens / 2, then RPCs will not 570 // be retried and hedged RPCs will not be sent. 571 message RetryThrottlingPolicy { 572 // The number of tokens starts at max_tokens. The token_count will always be 573 // between 0 and max_tokens. 574 // 575 // This field is required and must be greater than zero. 576 uint32 max_tokens = 1; 577 578 // The amount of tokens to add on each successful RPC. Typically this will 579 // be some number between 0 and 1, e.g., 0.1. 580 // 581 // This field is required and must be greater than zero. Up to 3 decimal 582 // places are supported. 583 float token_ratio = 2; 584 } 585 RetryThrottlingPolicy retry_throttling = 3; 586 587 message HealthCheckConfig { 588 // Service name to use in the health-checking request. 589 google.protobuf.StringValue service_name = 1; 590 } 591 HealthCheckConfig health_check_config = 5; 592 593 // next available tag: 6 594} 595