|
| 1 | +Service Config via DNS |
| 2 | +---------------------- |
| 3 | +* Author(s): Mark D. Roth (roth@google.com) |
| 4 | +* Approver: a11r |
| 5 | +* Status: Draft |
| 6 | +* Implemented in: N/A |
| 7 | +* Last updated: 2017-01-19 |
| 8 | +* Discussion at: https://groups.google.com/d/topic/grpc-io/DkweyrWEXxU/discussion |
| 9 | + |
| 10 | +## Abstract |
| 11 | + |
| 12 | +This document proposes a mechanism for encoding gRPC service config data |
| 13 | +in DNS for use in the open-source world. |
| 14 | + |
| 15 | +## Background |
| 16 | + |
| 17 | +The [service |
| 18 | +config](https://github.com/grpc/grpc/blob/master/doc/service_config.md) |
| 19 | +mechanism was originally designed for use inside of Google. However, all |
| 20 | +but one part of the original design works fine in the open-source world. |
| 21 | +That one part is the specification of how the service config data will |
| 22 | +be encoded in DNS. This proposal fills in this missing piece. |
| 23 | + |
| 24 | +### Related Proposals: |
| 25 | + |
| 26 | +N/A |
| 27 | + |
| 28 | +## Proposal |
| 29 | + |
| 30 | +There are two parts to this proposal. The first part is to add some |
| 31 | +JSON wrapping for controlling how service config changes are canary |
| 32 | +tested. The second part describes how the service config is encoded in |
| 33 | +DNS. |
| 34 | + |
| 35 | +### Canarying Changes |
| 36 | + |
| 37 | +When deploying a change to a service config, it is useful to be able to |
| 38 | +canary test changes to avoid wide-spread breakage by slowly increasing the |
| 39 | +number of clients that see the new version. To that end, multiple |
| 40 | +service configs choices can be listed, in order, along with criteria that |
| 41 | +determine which choice will be selected by a given client: |
| 42 | + |
| 43 | +``` |
| 44 | +// A list of one or more service config choices. |
| 45 | +// The first matching entry wins. |
| 46 | +[ |
| 47 | + { |
| 48 | + // Criteria used to select this choice. |
| 49 | + // If a field is absent or empty, it matches all clients. |
| 50 | + // All fields must match a client for this choice to be selected. |
| 51 | + // |
| 52 | + // Client language(s): a list of strings (e.g., 'c++', 'java', 'go', |
| 53 | + // 'python', etc). |
| 54 | + 'clientLanguage': [string], |
| 55 | + // Percentage: integer from 0 to 100 indicating the percentage of |
| 56 | + // clients that should use this choice. |
| 57 | + 'percentage': number, |
| 58 | + // Client hostname(s): a list of strings. |
| 59 | + 'clientHostname': [string], |
| 60 | +
|
| 61 | + // The service config data object for clients that match the above |
| 62 | + // criteria. (The format for this object is defined in |
| 63 | + // https://github.com/grpc/grpc/blob/master/doc/service_config.md.) |
| 64 | + 'serviceConfig': object |
| 65 | + } |
| 66 | +] |
| 67 | +``` |
| 68 | + |
| 69 | +### Encoding in DNS TXT Records |
| 70 | + |
| 71 | +In DNS, the service config data (in the form documented in the previous |
| 72 | +section) will be encoded in a TXT record via the mechanism described in |
| 73 | +[RFC-1464](https://tools.ietf.org/html/rfc1464) using the attribute name |
| 74 | +`grpc_config`. The attribute value will be a JSON list containing service |
| 75 | +config choices. For example, here is an example TXT record: |
| 76 | + |
| 77 | +``` |
| 78 | +myserver 3600 TXT "grpc_config=[{'serviceConfig':{'loadBalancingPolicy':'round_robin','methodConfig':[{'name':[{'service':'MyService','method':'Foo'}],'waitForReady':true}]}}]" |
| 79 | +``` |
| 80 | + |
| 81 | +Note that TXT records are limited to 255 bytes per string, as per |
| 82 | +[RFC-1035 section 3.3](https://tools.ietf.org/html/rfc1035#section-3.3). |
| 83 | +However, there can be multiple strings, which will be |
| 84 | +concatenated together, as described in [RFC-4408 section |
| 85 | +3.1.3](https://tools.ietf.org/html/rfc4408#section-3.1.3). The total |
| 86 | +DNS response cannot exceed 65535 bytes. (See the "Open Issues" |
| 87 | +section below for more discussion.) |
| 88 | + |
| 89 | +Note that because TXT records must be ASCII, this also imposes the |
| 90 | +restruction that the contents of the service config are also ASCII |
| 91 | +(e.g., service and method names, load balancing policy names, etc). |
| 92 | + |
| 93 | +## Rationale |
| 94 | + |
| 95 | +The service config is designed to be returned as part of name |
| 96 | +resolution, so encoding it in DNS makes the most sense. Sites that use |
| 97 | +a naming system other than DNS can, of course, implement their own |
| 98 | +resolvers with their own mechanism for encoding service config data. |
| 99 | + |
| 100 | +When encoding the service config in DNS, TXT records are the "obvious" |
| 101 | +choice, since the service config is effectively additional metadata |
| 102 | +associated with the DNS name. |
| 103 | + |
| 104 | +## Implementation |
| 105 | + |
| 106 | +The implementation will be done in C-core first. Once the new c-ares |
| 107 | +DNS resolver code (https://github.com/grpc/grpc/pull/7771) has been |
| 108 | +merged, we will extend it to query for the TXT records and return the |
| 109 | +resulting service config JSON data. |
| 110 | + |
| 111 | +Note that, due to platform support issues, we will initially *not* |
| 112 | +support the c-ares resolver under Windows or for Node. Alternatives |
| 113 | +will need to be found for these environments. |
| 114 | + |
| 115 | +## Open issues (if applicable) |
| 116 | + |
| 117 | +DNS TXT records do have some limitations that need to be taken into |
| 118 | +account here. In particular: |
| 119 | + |
| 120 | +- If a DNS response exceeds 512 bytes, it will fall back from UDP to |
| 121 | + TCP, which adds overhead. |
| 122 | +- The total DNS response cannot exceed 65535 bytes. |
| 123 | +- It is not clear whether individual DNS implementations will allow |
| 124 | + anywhere close to 65535 bytes, even though the spec says that they |
| 125 | + should. |
| 126 | + |
| 127 | +Feedback is requested on whether these considerations will be a |
| 128 | +significant drawback for this design (in which case the design will |
| 129 | +probably have to be changed). |
0 commit comments