lookup starts a RouteLookup RPC in a separate goroutine and returns the results (and error, if any) in the provided callback. The returned boolean indicates whether the request was throttled by the client-side adaptive throttling algorithm in which case the provided callback will not be invoked.
(reqKeys map[string]string, reason rlspb.RouteLookupRequest_Reason, staleHeaders string, cb lookupCallback)
| 195 | // client-side adaptive throttling algorithm in which case the provided callback |
| 196 | // will not be invoked. |
| 197 | func (cc *controlChannel) lookup(reqKeys map[string]string, reason rlspb.RouteLookupRequest_Reason, staleHeaders string, cb lookupCallback) (throttled bool) { |
| 198 | if cc.throttler.ShouldThrottle() { |
| 199 | cc.logger.Infof("RLS request throttled by client-side adaptive throttling") |
| 200 | return true |
| 201 | } |
| 202 | go func() { |
| 203 | req := &rlspb.RouteLookupRequest{ |
| 204 | TargetType: "grpc", |
| 205 | KeyMap: reqKeys, |
| 206 | Reason: reason, |
| 207 | StaleHeaderData: staleHeaders, |
| 208 | } |
| 209 | if cc.logger.V(2) { |
| 210 | cc.logger.Infof("Sending RLS request %+v", pretty.ToJSON(req)) |
| 211 | } |
| 212 | |
| 213 | ctx, cancel := context.WithTimeout(context.Background(), cc.rpcTimeout) |
| 214 | defer cancel() |
| 215 | resp, err := cc.client.RouteLookup(ctx, req) |
| 216 | cb(resp.GetTargets(), resp.GetHeaderData(), err) |
| 217 | }() |
| 218 | return false |
| 219 | } |