Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
routing.proto466 linesDownload Raw Back to api
1// Copyright 2026 Google LLC2//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 at6//7//     http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// 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 and13// limitations under the License.14 15syntax = "proto3";16 17package google.api;18 19import "google/protobuf/descriptor.proto";20 21option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations";22option java_multiple_files = true;23option java_outer_classname = "RoutingProto";24option java_package = "com.google.api";25option objc_class_prefix = "GAPI";26 27extend google.protobuf.MethodOptions {28  // See RoutingRule.29  google.api.RoutingRule routing = 72295729;30}31 32// Specifies the routing information that should be sent along with the request33// in the form of routing header.34// **NOTE:** All service configuration rules follow the "last one wins" order.35//36// The examples below will apply to an RPC which has the following request type:37//38// Message Definition:39//40//     message Request {41//       // The name of the Table42//       // Values can be of the following formats:43//       // - `projects/<project>/tables/<table>`44//       // - `projects/<project>/instances/<instance>/tables/<table>`45//       // - `region/<region>/zones/<zone>/tables/<table>`46//       string table_name = 1;47//48//       // This value specifies routing for replication.49//       // It can be in the following formats:50//       // - `profiles/<profile_id>`51//       // - a legacy `profile_id` that can be any string52//       string app_profile_id = 2;53//     }54//55// Example message:56//57//     {58//       table_name: projects/proj_foo/instances/instance_bar/table/table_baz,59//       app_profile_id: profiles/prof_qux60//     }61//62// The routing header consists of one or multiple key-value pairs. The order of63// the key-value pairs is undefined, the order of the `routing_parameters` in64// the `RoutingRule` only matters for the evaluation order of the path65// templates when `field` is the same. See the examples below for more details.66//67// Every key and value in the routing header must be percent-encoded,68// and joined together in the following format: `key1=value1&key2=value2`.69// The examples below skip the percent-encoding for readability.70//71// Example 172//73// Extracting a field from the request to put into the routing header74// unchanged, with the key equal to the field name.75//76// annotation:77//78//     option (google.api.routing) = {79//       // Take the `app_profile_id`.80//       routing_parameters {81//         field: "app_profile_id"82//       }83//     };84//85// result:86//87//     x-goog-request-params: app_profile_id=profiles/prof_qux88//89// Example 290//91// Extracting a field from the request to put into the routing header92// unchanged, with the key different from the field name.93//94// annotation:95//96//     option (google.api.routing) = {97//       // Take the `app_profile_id`, but name it `routing_id` in the header.98//       routing_parameters {99//         field: "app_profile_id"100//         path_template: "{routing_id=**}"101//       }102//     };103//104// result:105//106//     x-goog-request-params: routing_id=profiles/prof_qux107//108// Example 3109//110// Extracting a field from the request to put into the routing111// header, while matching a path template syntax on the field's value.112//113// NB: it is more useful to send nothing than to send garbage for the purpose114// of dynamic routing, since garbage pollutes cache. Thus the matching.115//116// Sub-example 3a117//118// The field matches the template.119//120// annotation:121//122//     option (google.api.routing) = {123//       // Take the `table_name`, if it's well-formed (with project-based124//       // syntax).125//       routing_parameters {126//         field: "table_name"127//         path_template: "{table_name=projects/*/instances/*/**}"128//       }129//     };130//131// result:132//133//     x-goog-request-params:134//     table_name=projects/proj_foo/instances/instance_bar/table/table_baz135//136// Sub-example 3b137//138// The field does not match the template.139//140// annotation:141//142//     option (google.api.routing) = {143//       // Take the `table_name`, if it's well-formed (with region-based144//       // syntax).145//       routing_parameters {146//         field: "table_name"147//         path_template: "{table_name=regions/*/zones/*/**}"148//       }149//     };150//151// result:152//153//     <no routing header will be sent>154//155// Sub-example 3c156//157// Multiple alternative conflictingly named path templates are158// specified. The one that matches is used to construct the header.159//160// annotation:161//162//     option (google.api.routing) = {163//       // Take the `table_name`, if it's well-formed, whether164//       // using the region- or projects-based syntax.165//166//       routing_parameters {167//         field: "table_name"168//         path_template: "{table_name=regions/*/zones/*/**}"169//       }170//       routing_parameters {171//         field: "table_name"172//         path_template: "{table_name=projects/*/instances/*/**}"173//       }174//     };175//176// result:177//178//     x-goog-request-params:179//     table_name=projects/proj_foo/instances/instance_bar/table/table_baz180//181// Example 4182//183// Extracting a single routing header key-value pair by matching a184// template syntax on (a part of) a single request field.185//186// annotation:187//188//     option (google.api.routing) = {189//       // Take just the project id from the `table_name` field.190//       routing_parameters {191//         field: "table_name"192//         path_template: "{routing_id=projects/*}/**"193//       }194//     };195//196// result:197//198//     x-goog-request-params: routing_id=projects/proj_foo199//200// Example 5201//202// Extracting a single routing header key-value pair by matching203// several conflictingly named path templates on (parts of) a single request204// field. The last template to match "wins" the conflict.205//206// annotation:207//208//     option (google.api.routing) = {209//       // If the `table_name` does not have instances information,210//       // take just the project id for routing.211//       // Otherwise take project + instance.212//213//       routing_parameters {214//         field: "table_name"215//         path_template: "{routing_id=projects/*}/**"216//       }217//       routing_parameters {218//         field: "table_name"219//         path_template: "{routing_id=projects/*/instances/*}/**"220//       }221//     };222//223// result:224//225//     x-goog-request-params:226//     routing_id=projects/proj_foo/instances/instance_bar227//228// Example 6229//230// Extracting multiple routing header key-value pairs by matching231// several non-conflicting path templates on (parts of) a single request field.232//233// Sub-example 6a234//235// Make the templates strict, so that if the `table_name` does not236// have an instance information, nothing is sent.237//238// annotation:239//240//     option (google.api.routing) = {241//       // The routing code needs two keys instead of one composite242//       // but works only for the tables with the "project-instance" name243//       // syntax.244//245//       routing_parameters {246//         field: "table_name"247//         path_template: "{project_id=projects/*}/instances/*/**"248//       }249//       routing_parameters {250//         field: "table_name"251//         path_template: "projects/*/{instance_id=instances/*}/**"252//       }253//     };254//255// result:256//257//     x-goog-request-params:258//     project_id=projects/proj_foo&instance_id=instances/instance_bar259//260// Sub-example 6b261//262// Make the templates loose, so that if the `table_name` does not263// have an instance information, just the project id part is sent.264//265// annotation:266//267//     option (google.api.routing) = {268//       // The routing code wants two keys instead of one composite269//       // but will work with just the `project_id` for tables without270//       // an instance in the `table_name`.271//272//       routing_parameters {273//         field: "table_name"274//         path_template: "{project_id=projects/*}/**"275//       }276//       routing_parameters {277//         field: "table_name"278//         path_template: "projects/*/{instance_id=instances/*}/**"279//       }280//     };281//282// result (is the same as 6a for our example message because it has the instance283// information):284//285//     x-goog-request-params:286//     project_id=projects/proj_foo&instance_id=instances/instance_bar287//288// Example 7289//290// Extracting multiple routing header key-value pairs by matching291// several path templates on multiple request fields.292//293// NB: note that here there is no way to specify sending nothing if one of the294// fields does not match its template. E.g. if the `table_name` is in the wrong295// format, the `project_id` will not be sent, but the `routing_id` will be.296// The backend routing code has to be aware of that and be prepared to not297// receive a full complement of keys if it expects multiple.298//299// annotation:300//301//     option (google.api.routing) = {302//       // The routing needs both `project_id` and `routing_id`303//       // (from the `app_profile_id` field) for routing.304//305//       routing_parameters {306//         field: "table_name"307//         path_template: "{project_id=projects/*}/**"308//       }309//       routing_parameters {310//         field: "app_profile_id"311//         path_template: "{routing_id=**}"312//       }313//     };314//315// result:316//317//     x-goog-request-params:318//     project_id=projects/proj_foo&routing_id=profiles/prof_qux319//320// Example 8321//322// Extracting a single routing header key-value pair by matching323// several conflictingly named path templates on several request fields. The324// last template to match "wins" the conflict.325//326// annotation:327//328//     option (google.api.routing) = {329//       // The `routing_id` can be a project id or a region id depending on330//       // the table name format, but only if the `app_profile_id` is not set.331//       // If `app_profile_id` is set it should be used instead.332//333//       routing_parameters {334//         field: "table_name"335//         path_template: "{routing_id=projects/*}/**"336//       }337//       routing_parameters {338//          field: "table_name"339//          path_template: "{routing_id=regions/*}/**"340//       }341//       routing_parameters {342//         field: "app_profile_id"343//         path_template: "{routing_id=**}"344//       }345//     };346//347// result:348//349//     x-goog-request-params: routing_id=profiles/prof_qux350//351// Example 9352//353// Bringing it all together.354//355// annotation:356//357//     option (google.api.routing) = {358//       // For routing both `table_location` and a `routing_id` are needed.359//       //360//       // table_location can be either an instance id or a region+zone id.361//       //362//       // For `routing_id`, take the value of `app_profile_id`363//       // - If it's in the format `profiles/<profile_id>`, send364//       // just the `<profile_id>` part.365//       // - If it's any other literal, send it as is.366//       // If the `app_profile_id` is empty, and the `table_name` starts with367//       // the project_id, send that instead.368//369//       routing_parameters {370//         field: "table_name"371//         path_template: "projects/*/{table_location=instances/*}/tables/*"372//       }373//       routing_parameters {374//         field: "table_name"375//         path_template: "{table_location=regions/*/zones/*}/tables/*"376//       }377//       routing_parameters {378//         field: "table_name"379//         path_template: "{routing_id=projects/*}/**"380//       }381//       routing_parameters {382//         field: "app_profile_id"383//         path_template: "{routing_id=**}"384//       }385//       routing_parameters {386//         field: "app_profile_id"387//         path_template: "profiles/{routing_id=*}"388//       }389//     };390//391// result:392//393//     x-goog-request-params:394//     table_location=instances/instance_bar&routing_id=prof_qux395message RoutingRule {396  // A collection of Routing Parameter specifications.397  // **NOTE:** If multiple Routing Parameters describe the same key398  // (via the `path_template` field or via the `field` field when399  // `path_template` is not provided), "last one wins" rule400  // determines which Parameter gets used.401  // See the examples for more details.402  repeated RoutingParameter routing_parameters = 2;403}404 405// A projection from an input message to the GRPC or REST header.406message RoutingParameter {407  // A request field to extract the header key-value pair from.408  string field = 1;409 410  // A pattern matching the key-value field. Optional.411  // If not specified, the whole field specified in the `field` field will be412  // taken as value, and its name used as key. If specified, it MUST contain413  // exactly one named segment (along with any number of unnamed segments) The414  // pattern will be matched over the field specified in the `field` field, then415  // if the match is successful:416  // - the name of the single named segment will be used as a header name,417  // - the match value of the segment will be used as a header value;418  // if the match is NOT successful, nothing will be sent.419  //420  // Example:421  //422  //               -- This is a field in the request message423  //              |   that the header value will be extracted from.424  //              |425  //              |                     -- This is the key name in the426  //              |                    |   routing header.427  //              V                    |428  //     field: "table_name"           v429  //     path_template: "projects/*/{table_location=instances/*}/tables/*"430  //                                                ^            ^431  //                                                |            |432  //       In the {} brackets is the pattern that --             |433  //       specifies what to extract from the                    |434  //       field as a value to be sent.                          |435  //                                                             |436  //      The string in the field must match the whole pattern --437  //      before brackets, inside brackets, after brackets.438  //439  // When looking at this specific example, we can see that:440  // - A key-value pair with the key `table_location`441  //   and the value matching `instances/*` should be added442  //   to the x-goog-request-params routing header.443  // - The value is extracted from the request message's `table_name` field444  //   if it matches the full pattern specified:445  //   `projects/*/instances/*/tables/*`.446  //447  // **NB:** If the `path_template` field is not provided, the key name is448  // equal to the field name, and the whole field should be sent as a value.449  // This makes the pattern for the field and the value functionally equivalent450  // to `**`, and the configuration451  //452  //     {453  //       field: "table_name"454  //     }455  //456  // is a functionally equivalent shorthand to:457  //458  //     {459  //       field: "table_name"460  //       path_template: "{table_name=**}"461  //     }462  //463  // See Example 1 for more details.464  string path_template = 2;465}466