1Service Config in gRPC 2====================== 3 4# Objective 5 6The service config is a mechanism that allows service owners to publish 7parameters to be automatically used by all clients of their service. 8 9# Format 10 11The service config is a JSON string of the following form: 12 13``` 14{ 15 // Load balancing policy name (case insensitive). 16 // Currently, the only selectable client-side policy provided with gRPC 17 // is 'round_robin', but third parties may add their own policies. 18 // This field is optional; if unset, the default behavior is to pick 19 // the first available backend. 20 // If the policy name is set via the client API, that value overrides 21 // the value specified here. 22 // 23 // Note that if the resolver returns at least one balancer address (as 24 // opposed to backend addresses), gRPC will use grpclb (see 25 // https://github.com/grpc/grpc/blob/master/doc/load-balancing.md), 26 // regardless of what LB policy is requested either here or via the 27 // client API. 28 'loadBalancingPolicy': string, 29 30 // Per-method configuration. Optional. 31 'methodConfig': [ 32 { 33 // The names of the methods to which this method config applies. There 34 // must be at least one name. Each name entry must be unique across the 35 // entire service config. If the 'method' field is empty, then this 36 // method config specifies the defaults for all methods for the specified 37 // service. 38 // 39 // For example, let's say that the service config contains the following 40 // method config entries: 41 // 42 // 'methodConfig': [ 43 // { 'name': [ { 'service': 'MyService' } ] ... }, 44 // { 'name': [ { 'service': 'MyService', 'method': 'Foo' } ] ... } 45 // ] 46 // 47 // For a request for MyService/Foo, we will use the second entry, because 48 // it exactly matches the service and method name. 49 // For a request for MyService/Bar, we will use the first entry, because 50 // it provides the default for all methods of MyService. 51 'name': [ 52 { 53 // RPC service name. Required. 54 // If using gRPC with protobuf as the IDL, then this will be of 55 // the form "pkg.service_name", where "pkg" is the package name 56 // defined in the proto file. 57 'service': string, 58 59 // RPC method name. Optional (see above). 60 'method': string, 61 } 62 ], 63 64 // Whether RPCs sent to this method should wait until the connection is 65 // ready by default. If false, the RPC will abort immediately if there 66 // is a transient failure connecting to the server. Otherwise, gRPC will 67 // attempt to connect until the deadline is exceeded. 68 // 69 // The value specified via the gRPC client API will override the value 70 // set here. However, note that setting the value in the client API will 71 // also affect transient errors encountered during name resolution, 72 // which cannot be caught by the value here, since the service config 73 // is obtained by the gRPC client via name resolution. 74 'waitForReady': bool, 75 76 // The default timeout in seconds for RPCs sent to this method. This can 77 // be overridden in code. If no reply is received in the specified amount 78 // of time, the request is aborted and a deadline-exceeded error status 79 // is returned to the caller. 80 // 81 // The actual deadline used will be the minimum of the value specified 82 // here and the value set by the application via the gRPC client API. 83 // If either one is not set, then the other will be used. 84 // If neither is set, then the request has no deadline. 85 // 86 // The format of the value is that of the 'Duration' type defined here: 87 // https://developers.google.com/protocol-buffers/docs/proto3#json 88 'timeout': string, 89 90 // The maximum allowed payload size for an individual request or object 91 // in a stream (client->server) in bytes. The size which is measured is 92 // the serialized, uncompressed payload in bytes. This applies both 93 // to streaming and non-streaming requests. 94 // 95 // The actual value used is the minimum of the value specified here and 96 // the value set by the application via the gRPC client API. 97 // If either one is not set, then the other will be used. 98 // If neither is set, then the built-in default is used. 99 // 100 // If a client attempts to send an object larger than this value, it 101 // will not be sent and the client will see an error. 102 // Note that 0 is a valid value, meaning that the request message must 103 // be empty. 104 'maxRequestMessageBytes': number, 105 106 // The maximum allowed payload size for an individual response or object 107 // in a stream (server->client) in bytes. The size which is measured is 108 // the serialized, uncompressed payload in bytes. This applies both 109 // to streaming and non-streaming requests. 110 // 111 // The actual value used is the minimum of the value specified here and 112 // the value set by the application via the gRPC client API. 113 // If either one is not set, then the other will be used. 114 // If neither is set, then the built-in default is used. 115 // 116 // If a server attempts to send an object larger than this value, it 117 // will not be sent, and the client will see an error. 118 // Note that 0 is a valid value, meaning that the response message must 119 // be empty. 120 'maxResponseMessageBytes': number 121 } 122 ] 123} 124``` 125 126Note that new per-method parameters may be added in the future as new 127functionality is introduced. 128 129# Architecture 130 131A service config is associated with a server name. The [name resolver](naming.md) 132plugin, when asked to resolve a particular server 133name, will return both the resolved addresses and the service config. 134 135TODO(roth): Design how the service config will be encoded in DNS. 136 137# APIs 138 139The service config is used in the following APIs: 140 141- In the resolver API, used by resolver plugins to return the service 142 config to the gRPC client. 143- In the gRPC client API, where users can query the channel to obtain 144 the service config associated with the channel (for debugging 145 purposes). 146- In the gRPC client API, where users can set the service config 147 explicitly. This is intended for use in unit tests. 148