Skip to content

Commit 6c0171f

Browse files
authored
rls: Update rls protos and code/test to reflect those changes. (#3832)
1 parent d16bb4c commit 6c0171f

File tree

6 files changed

+430
-549
lines changed

6 files changed

+430
-549
lines changed

balancer/rls/internal/config.go

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ type lbConfig struct {
6161
maxAge time.Duration
6262
staleAge time.Duration
6363
cacheSizeBytes int64
64-
rpStrategy rlspb.RouteLookupConfig_RequestProcessingStrategy
6564
defaultTarget string
6665
cpName string
6766
cpTargetField string
@@ -75,7 +74,6 @@ func (lbCfg *lbConfig) Equal(other *lbConfig) bool {
7574
lbCfg.maxAge == other.maxAge &&
7675
lbCfg.staleAge == other.staleAge &&
7776
lbCfg.cacheSizeBytes == other.cacheSizeBytes &&
78-
lbCfg.rpStrategy == other.rpStrategy &&
7977
lbCfg.defaultTarget == other.defaultTarget &&
8078
lbCfg.cpName == other.cpName &&
8179
lbCfg.cpTargetField == other.cpTargetField &&
@@ -167,11 +165,6 @@ func (l *loadBalancingConfig) UnmarshalJSON(data []byte) error {
167165
// - must be greater than zero
168166
// - TODO(easwars): Define a minimum value for this field, to be used when
169167
// left unspecified
170-
// ** request_processing_strategy field:
171-
// - must have a value other than STRATEGY_UNSPECIFIED
172-
// - if set to SYNC_LOOKUP_DEFAULT_TARGET_ON_ERROR or
173-
// ASYNC_LOOKUP_DEFAULT_TARGET_ON_MISS, the default_target field must be
174-
// set to a non-empty value
175168
// * childPolicy field:
176169
// - must find a valid child policy with a valid config (the child policy must
177170
// be able to parse the provided config successfully when we pass it a dummy
@@ -242,22 +235,10 @@ func (*rlsBB) ParseConfig(c json.RawMessage) (serviceconfig.LoadBalancingConfig,
242235
logger.Infof("rls: max_age in service config is %v, using %v", maxAge, maxMaxAge)
243236
maxAge = maxMaxAge
244237
}
245-
246238
cacheSizeBytes := rlsProto.GetCacheSizeBytes()
247239
if cacheSizeBytes <= 0 {
248240
return nil, fmt.Errorf("rls: cache_size_bytes must be greater than 0 in service config {%+v}", string(c))
249241
}
250-
251-
rpStrategy := rlsProto.GetRequestProcessingStrategy()
252-
if rpStrategy == rlspb.RouteLookupConfig_STRATEGY_UNSPECIFIED {
253-
return nil, fmt.Errorf("rls: request_processing_strategy cannot be left unspecified in service config {%+v}", string(c))
254-
}
255-
defaultTarget := rlsProto.GetDefaultTarget()
256-
if (rpStrategy == rlspb.RouteLookupConfig_SYNC_LOOKUP_DEFAULT_TARGET_ON_ERROR ||
257-
rpStrategy == rlspb.RouteLookupConfig_ASYNC_LOOKUP_DEFAULT_TARGET_ON_MISS) && defaultTarget == "" {
258-
return nil, fmt.Errorf("rls: request_processing_strategy is %s, but default_target is not set", rpStrategy.String())
259-
}
260-
261242
if childPolicy == nil {
262243
return nil, fmt.Errorf("rls: childPolicy is invalid in service config {%+v}", string(c))
263244
}
@@ -283,8 +264,7 @@ func (*rlsBB) ParseConfig(c json.RawMessage) (serviceconfig.LoadBalancingConfig,
283264
maxAge: maxAge,
284265
staleAge: staleAge,
285266
cacheSizeBytes: cacheSizeBytes,
286-
rpStrategy: rpStrategy,
287-
defaultTarget: defaultTarget,
267+
defaultTarget: rlsProto.GetDefaultTarget(),
288268
// TODO(easwars): Once we refactor validateChildPolicyConfig and make
289269
// it a method on the lbConfig object, we could directly store the
290270
// balancer.Builder and/or balancer.ConfigParser here instead of the

balancer/rls/internal/config_test.go

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ import (
2828
"github.com/google/go-cmp/cmp"
2929

3030
"google.golang.org/grpc/balancer"
31-
_ "google.golang.org/grpc/balancer/grpclb" // grpclb for config parsing.
32-
rlspb "google.golang.org/grpc/balancer/rls/internal/proto/grpc_lookup_v1"
31+
_ "google.golang.org/grpc/balancer/grpclb" // grpclb for config parsing.
3332
_ "google.golang.org/grpc/internal/resolver/passthrough" // passthrough resolver.
3433
)
3534

@@ -58,7 +57,6 @@ func testEqual(a, b *lbConfig) bool {
5857
a.maxAge == b.maxAge &&
5958
a.staleAge == b.staleAge &&
6059
a.cacheSizeBytes == b.cacheSizeBytes &&
61-
a.rpStrategy == b.rpStrategy &&
6260
a.defaultTarget == b.defaultTarget &&
6361
a.cpName == b.cpName &&
6462
a.cpTargetField == b.cpTargetField &&
@@ -91,7 +89,6 @@ func TestParseConfig(t *testing.T) {
9189
"maxAge" : "500s",
9290
"staleAge": "600s",
9391
"cacheSizeBytes": 1000,
94-
"request_processing_strategy": "ASYNC_LOOKUP_DEFAULT_TARGET_ON_MISS",
9592
"defaultTarget": "passthrough:///default"
9693
},
9794
"childPolicy": [
@@ -107,7 +104,6 @@ func TestParseConfig(t *testing.T) {
107104
maxAge: 5 * time.Minute, // This is max maxAge.
108105
staleAge: time.Duration(0), // StaleAge is ignore because it was higher than maxAge.
109106
cacheSizeBytes: 1000,
110-
rpStrategy: rlspb.RouteLookupConfig_ASYNC_LOOKUP_DEFAULT_TARGET_ON_MISS,
111107
defaultTarget: "passthrough:///default",
112108
cpName: "grpclb",
113109
cpTargetField: "service_name",
@@ -127,7 +123,6 @@ func TestParseConfig(t *testing.T) {
127123
"maxAge": "60s",
128124
"staleAge" : "50s",
129125
"cacheSizeBytes": 1000,
130-
"request_processing_strategy": "ASYNC_LOOKUP_DEFAULT_TARGET_ON_MISS",
131126
"defaultTarget": "passthrough:///default"
132127
},
133128
"childPolicy": [{"grpclb": {"childPolicy": [{"pickfirst": {}}]}}],
@@ -139,7 +134,6 @@ func TestParseConfig(t *testing.T) {
139134
maxAge: 60 * time.Second,
140135
staleAge: 50 * time.Second,
141136
cacheSizeBytes: 1000,
142-
rpStrategy: rlspb.RouteLookupConfig_ASYNC_LOOKUP_DEFAULT_TARGET_ON_MISS,
143137
defaultTarget: "passthrough:///default",
144138
cpName: "grpclb",
145139
cpTargetField: "service_name",
@@ -288,41 +282,6 @@ func TestParseConfigErrors(t *testing.T) {
288282
}`),
289283
wantErr: "rls: cache_size_bytes must be greater than 0 in service config",
290284
},
291-
{
292-
desc: "invalid request processing strategy",
293-
input: []byte(`{
294-
"routeLookupConfig": {
295-
"grpcKeybuilders": [{
296-
"names": [{"service": "service", "method": "method"}],
297-
"headers": [{"key": "k1", "names": ["v1"]}]
298-
}],
299-
"lookupService": "passthrough:///target",
300-
"lookupServiceTimeout" : "10s",
301-
"maxAge": "30s",
302-
"staleAge" : "25s",
303-
"cacheSizeBytes": 1000
304-
}
305-
}`),
306-
wantErr: "rls: request_processing_strategy cannot be left unspecified in service config",
307-
},
308-
{
309-
desc: "request processing strategy without default target",
310-
input: []byte(`{
311-
"routeLookupConfig": {
312-
"grpcKeybuilders": [{
313-
"names": [{"service": "service", "method": "method"}],
314-
"headers": [{"key": "k1", "names": ["v1"]}]
315-
}],
316-
"lookupService": "passthrough:///target",
317-
"lookupServiceTimeout" : "10s",
318-
"maxAge": "30s",
319-
"staleAge" : "25s",
320-
"cacheSizeBytes": 1000,
321-
"request_processing_strategy": "ASYNC_LOOKUP_DEFAULT_TARGET_ON_MISS"
322-
}
323-
}`),
324-
wantErr: "default_target is not set",
325-
},
326285
{
327286
desc: "no child policy",
328287
input: []byte(`{
@@ -336,7 +295,6 @@ func TestParseConfigErrors(t *testing.T) {
336295
"maxAge": "30s",
337296
"staleAge" : "25s",
338297
"cacheSizeBytes": 1000,
339-
"request_processing_strategy": "ASYNC_LOOKUP_DEFAULT_TARGET_ON_MISS",
340298
"defaultTarget": "passthrough:///default"
341299
}
342300
}`),
@@ -355,7 +313,6 @@ func TestParseConfigErrors(t *testing.T) {
355313
"maxAge": "30s",
356314
"staleAge" : "25s",
357315
"cacheSizeBytes": 1000,
358-
"request_processing_strategy": "ASYNC_LOOKUP_DEFAULT_TARGET_ON_MISS",
359316
"defaultTarget": "passthrough:///default"
360317
},
361318
"childPolicy": [
@@ -378,7 +335,6 @@ func TestParseConfigErrors(t *testing.T) {
378335
"maxAge": "30s",
379336
"staleAge" : "25s",
380337
"cacheSizeBytes": 1000,
381-
"request_processing_strategy": "ASYNC_LOOKUP_DEFAULT_TARGET_ON_MISS",
382338
"defaultTarget": "passthrough:///default"
383339
},
384340
"childPolicy": [
@@ -402,7 +358,6 @@ func TestParseConfigErrors(t *testing.T) {
402358
"maxAge": "30s",
403359
"staleAge" : "25s",
404360
"cacheSizeBytes": 1000,
405-
"request_processing_strategy": "ASYNC_LOOKUP_DEFAULT_TARGET_ON_MISS",
406361
"defaultTarget": "passthrough:///default"
407362
},
408363
"childPolicy": [

balancer/rls/internal/picker.go

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"google.golang.org/grpc/balancer"
2626
"google.golang.org/grpc/balancer/rls/internal/cache"
2727
"google.golang.org/grpc/balancer/rls/internal/keys"
28-
rlspb "google.golang.org/grpc/balancer/rls/internal/proto/grpc_lookup_v1"
2928
"google.golang.org/grpc/metadata"
3029
)
3130

@@ -42,10 +41,6 @@ type rlsPicker struct {
4241
// The keyBuilder map used to generate RLS keys for the RPC. This is built
4342
// by the LB policy based on the received ServiceConfig.
4443
kbm keys.BuilderMap
45-
// This is the request processing strategy as indicated by the LB policy's
46-
// ServiceConfig. This controls how to process a RPC when the data required
47-
// to make the pick decision is not in the cache.
48-
strategy rlspb.RouteLookupConfig_RequestProcessingStrategy
4944

5045
// The following hooks are setup by the LB policy to enable the rlsPicker to
5146
// access state stored in the policy. This approach has the following
@@ -79,15 +74,6 @@ type rlsPicker struct {
7974
defaultPick func(balancer.PickInfo) (balancer.PickResult, error)
8075
}
8176

82-
// This helper function decides if the pick should delegate to the default
83-
// rlsPicker based on the request processing strategy. This is used when the
84-
// data cache does not have a valid entry for the current RPC and the RLS
85-
// request is throttled, or if the current data cache entry is in backoff.
86-
func (p *rlsPicker) shouldDelegateToDefault() bool {
87-
return p.strategy == rlspb.RouteLookupConfig_SYNC_LOOKUP_DEFAULT_TARGET_ON_ERROR ||
88-
p.strategy == rlspb.RouteLookupConfig_ASYNC_LOOKUP_DEFAULT_TARGET_ON_MISS
89-
}
90-
9177
// Pick makes the routing decision for every outbound RPC.
9278
func (p *rlsPicker) Pick(info balancer.PickInfo) (balancer.PickResult, error) {
9379
// For every incoming request, we first build the RLS keys using the
@@ -123,9 +109,9 @@ func (p *rlsPicker) Pick(info balancer.PickInfo) (balancer.PickResult, error) {
123109
if p.shouldThrottle() {
124110
// The entry doesn't exist or has expired and the new RLS request
125111
// has been throttled. Treat it as an error and delegate to default
126-
// pick or fail the pick, based on the request processing strategy.
112+
// pick, if one exists, or fail the pick.
127113
if entry == nil || entry.ExpiryTime.Before(now) {
128-
if p.shouldDelegateToDefault() {
114+
if p.defaultPick != nil {
129115
return p.defaultPick(info)
130116
}
131117
return balancer.PickResult{}, errRLSThrottled
@@ -144,25 +130,20 @@ func (p *rlsPicker) Pick(info balancer.PickInfo) (balancer.PickResult, error) {
144130
// this cache entry.
145131
return entry.ChildPicker.Pick(info)
146132
} else if entry.BackoffTime.After(now) {
147-
// The entry has expired, but is in backoff. We either delegate to
148-
// the default rlsPicker or return the error from the last failed
149-
// RLS request for this entry.
150-
if p.shouldDelegateToDefault() {
133+
// The entry has expired, but is in backoff. We delegate to the
134+
// default pick, if one exists, or return the error from the last
135+
// failed RLS request for this entry.
136+
if p.defaultPick != nil {
151137
return p.defaultPick(info)
152138
}
153139
return balancer.PickResult{}, entry.CallStatus
154140
}
155141
}
156142

157-
// Either we didn't find an entry or found an entry which had expired and
158-
// was not in backoff (which is also essentially equivalent to not finding
159-
// an entry), and we started an RLS request in the background. We either
160-
// queue the pick or delegate to the default pick. In the former case, upon
161-
// receipt of an RLS response, the LB policy will send a new rlsPicker to
162-
// the channel, and the pick will be retried.
163-
if p.strategy == rlspb.RouteLookupConfig_SYNC_LOOKUP_DEFAULT_TARGET_ON_ERROR ||
164-
p.strategy == rlspb.RouteLookupConfig_SYNC_LOOKUP_CLIENT_SEES_ERROR {
165-
return balancer.PickResult{}, balancer.ErrNoSubConnAvailable
166-
}
167-
return p.defaultPick(info)
143+
// We get here only in the following cases:
144+
// * No data cache entry or expired entry, RLS request sent out
145+
// * No valid data cache entry and Pending cache entry exists
146+
// We need to queue to pick which will be handled once the RLS response is
147+
// received.
148+
return balancer.PickResult{}, balancer.ErrNoSubConnAvailable
168149
}

0 commit comments

Comments
 (0)