xref: /aosp_15_r20/external/grpc-grpc/src/proto/grpc/lookup/v1/rls_config.proto (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
1// Copyright 2020 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
15syntax = "proto3";
16
17package grpc.lookup.v1;
18
19import "google/protobuf/duration.proto";
20
21option go_package = "google.golang.org/grpc/lookup/grpc_lookup_v1";
22option java_multiple_files = true;
23option java_package = "io.grpc.lookup.v1";
24option java_outer_classname = "RlsConfigProto";
25
26// Extract a key based on a given name (e.g. header name or query parameter
27// name).  The name must match one of the names listed in the "name" field.  If
28// the "required_match" field is true, one of the specified names must be
29// present for the keybuilder to match.
30message NameMatcher {
31  // The name that will be used in the RLS key_map to refer to this value.
32  // If required_match is true, you may omit this field or set it to an empty
33  // string, in which case the matcher will require a match, but won't update
34  // the key_map.
35  string key = 1;
36
37  // Ordered list of names (headers or query parameter names) that can supply
38  // this value; the first one with a non-empty value is used.
39  repeated string names = 2;
40
41  // If true, make this extraction required; the key builder will not match
42  // if no value is found.
43  bool required_match = 3;
44}
45
46// A GrpcKeyBuilder applies to a given gRPC service, name, and headers.
47message GrpcKeyBuilder {
48  // To match, one of the given Name fields must match; the service and method
49  // fields are specified as fixed strings.  The service name is required and
50  // includes the proto package name.  The method name may be omitted, in
51  // which case any method on the given service is matched.
52  message Name {
53    string service = 1;
54    string method = 2;
55  }
56  repeated Name names = 1;
57
58  // If you wish to include the host, service, or method names as keys in the
59  // generated RouteLookupRequest, specify key names to use in the extra_keys
60  // submessage. If a key name is empty, no key will be set for that value.
61  // If this submessage is specified, the normal host/path fields will be left
62  // unset in the RouteLookupRequest. We are deprecating host/path in the
63  // RouteLookupRequest, so services should migrate to the ExtraKeys approach.
64  message ExtraKeys {
65    string host = 1;
66    string service = 2;
67    string method = 3;
68  }
69  ExtraKeys extra_keys = 3;
70
71  // Extract keys from all listed headers.
72  // For gRPC, it is an error to specify "required_match" on the NameMatcher
73  // protos.
74  repeated NameMatcher headers = 2;
75
76  // You can optionally set one or more specific key/value pairs to be added to
77  // the key_map.  This can be useful to identify which builder built the key,
78  // for example if you are suppressing the actual method, but need to
79  // separately cache and request all the matched methods.
80  map<string, string> constant_keys = 4;
81}
82
83// An HttpKeyBuilder applies to a given HTTP URL and headers.
84//
85// Path and host patterns use the matching syntax from gRPC transcoding to
86// extract named key/value pairs from the path and host components of the URL:
87// https://github.com/googleapis/googleapis/blob/master/google/api/http.proto
88//
89// It is invalid to specify the same key name in multiple places in a pattern.
90//
91// For a service where the project id can be expressed either as a subdomain or
92// in the path, separate HttpKeyBuilders must be used:
93//     host_pattern: 'example.com' path_pattern: '/{id}/{object}/**'
94//     host_pattern: '{id}.example.com' path_pattern: '/{object}/**'
95// If the host is exactly 'example.com', the first path segment will be used as
96// the id and the second segment as the object. If the host has a subdomain, the
97// subdomain will be used as the id and the first segment as the object. If
98// neither pattern matches, no keys will be extracted.
99message HttpKeyBuilder {
100  // host_pattern is an ordered list of host template patterns for the desired
101  // value.  If any host_pattern values are specified, then at least one must
102  // match, and the last one wins and sets any specified variables.  A host
103  // consists of labels separated by dots. Each label is matched against the
104  // label in the pattern as follows:
105  //   - "*": Matches any single label.
106  //   - "**": Matches zero or more labels (first or last part of host only).
107  //   - "{<name>=...}": One or more label capture, where "..." can be any
108  //      template that does not include a capture.
109  //   - "{<name>}": A single label capture. Identical to {<name>=*}.
110  //
111  // Examples:
112  //   - "example.com": Only applies to the exact host example.com.
113  //   - "*.example.com": Matches subdomains of example.com.
114  //   - "**.example.com": matches example.com, and all levels of subdomains.
115  //   - "{project}.example.com": Extracts the third level subdomain.
116  //   - "{project=**}.example.com": Extracts the third level+ subdomains.
117  //   - "{project=**}": Extracts the entire host.
118  repeated string host_patterns = 1;
119
120  // path_pattern is an ordered list of path template patterns for the desired
121  // value.  If any path_pattern values are specified, then at least one must
122  // match, and the last one wins and sets any specified variables.  A path
123  // consists of segments separated by slashes. Each segment is matched against
124  // the segment in the pattern as follows:
125  //   - "*": Matches any single segment.
126  //   - "**": Matches zero or more segments (first or last part of path only).
127  //   - "{<name>=...}": One or more segment capture, where "..." can be any
128  //      template that does not include a capture.
129  //   - "{<name>}": A single segment capture. Identical to {<name>=*}.
130  // A custom method may also be specified by appending ":" and the custom
131  // method name or "*" to indicate any custom method (including no custom
132  // method).  For example, "/*/projects/{project_id}/**:*" extracts
133  // `{project_id}` for any version, resource and custom method that includes
134  // it.  By default, any custom method will be matched.
135  //
136  // Examples:
137  //   - "/v1/{name=messages/*}": extracts a name like "messages/12345".
138  //   - "/v1/messages/{message_id}": extracts a message_id like "12345".
139  //   - "/v1/users/{user_id}/messages/{message_id}": extracts two key values.
140  repeated string path_patterns = 2;
141
142  // List of query parameter names to try to match.
143  // For example: ["parent", "name", "resource.name"]
144  // We extract all the specified query_parameters (case-sensitively).  If any
145  // are marked as "required_match" and are not present, this keybuilder fails
146  // to match.  If a given parameter appears multiple times (?foo=a&foo=b) we
147  // will report it as a comma-separated string (foo=a,b).
148  repeated NameMatcher query_parameters = 3;
149
150  // List of headers to try to match.
151  // We extract all the specified header values (case-insensitively).  If any
152  // are marked as "required_match" and are not present, this keybuilder fails
153  // to match.  If a given header appears multiple times in the request we will
154  // report it as a comma-separated string, in standard HTTP fashion.
155  repeated NameMatcher headers = 4;
156
157  // You can optionally set one or more specific key/value pairs to be added to
158  // the key_map.  This can be useful to identify which builder built the key,
159  // for example if you are suppressing a lot of information from the URL, but
160  // need to separately cache and request URLs with that content.
161  map<string, string> constant_keys = 5;
162}
163
164message RouteLookupConfig {
165  // Ordered specifications for constructing keys for HTTP requests.  Last
166  // match wins.  If no HttpKeyBuilder matches, an empty key_map will be sent to
167  // the lookup service; it should likely reply with a global default route
168  // and raise an alert.
169  repeated HttpKeyBuilder http_keybuilders = 1;
170
171  // Unordered specifications for constructing keys for gRPC requests.  All
172  // GrpcKeyBuilders on this list must have unique "name" fields so that the
173  // client is free to prebuild a hash map keyed by name.  If no GrpcKeyBuilder
174  // matches, an empty key_map will be sent to the lookup service; it should
175  // likely reply with a global default route and raise an alert.
176  repeated GrpcKeyBuilder grpc_keybuilders = 2;
177
178  // The name of the lookup service as a gRPC URI.  Typically, this will be
179  // a subdomain of the target, such as "lookup.datastore.googleapis.com".
180  string lookup_service = 3;
181
182  // Configure a timeout value for lookup service requests.
183  // Defaults to 10 seconds if not specified.
184  google.protobuf.Duration lookup_service_timeout = 4;
185
186  // How long are responses valid for (like HTTP Cache-Control).
187  // If omitted or zero, the longest valid cache time is used.
188  // This value is clamped to 5 minutes to avoid unflushable bad responses.
189  google.protobuf.Duration max_age = 5;
190
191  // After a response has been in the client cache for this amount of time
192  // and is re-requested, start an asynchronous RPC to re-validate it.
193  // This value should be less than max_age by at least the length of a
194  // typical RTT to the Route Lookup Service to fully mask the RTT latency.
195  // If omitted, keys are only re-requested after they have expired.
196  google.protobuf.Duration stale_age = 6;
197
198  // Rough indicator of amount of memory to use for the client cache.  Some of
199  // the data structure overhead is not accounted for, so actual memory consumed
200  // will be somewhat greater than this value.  If this field is omitted or set
201  // to zero, a client default will be used.  The value may be capped to a lower
202  // amount based on client configuration.
203  int64 cache_size_bytes = 7;
204
205  // This is a list of all the possible targets that can be returned by the
206  // lookup service.  If a target not on this list is returned, it will be
207  // treated the same as an unhealthy target.
208  repeated string valid_targets = 8;
209
210  // This value provides a default target to use if needed.  If set, it will be
211  // used if RLS returns an error, times out, or returns an invalid response.
212  // Note that requests can be routed only to a subdomain of the original
213  // target, e.g. "us_east_1.cloudbigtable.googleapis.com".
214  string default_target = 9;
215
216  reserved 10;
217  reserved "request_processing_strategy";
218}
219
220// RouteLookupClusterSpecifier is used in xDS to represent a cluster specifier
221// plugin for RLS.
222message RouteLookupClusterSpecifier {
223  // The RLS config for this cluster specifier plugin instance.
224  RouteLookupConfig route_lookup_config = 1;
225}
226