-
Notifications
You must be signed in to change notification settings - Fork 4.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
balancer/rls: allow maxAge to exceed 5m if staleAge is set #8137
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #8137 +/- ##
==========================================
- Coverage 82.34% 82.23% -0.12%
==========================================
Files 389 392 +3
Lines 39103 39153 +50
==========================================
- Hits 32200 32197 -3
- Misses 5579 5628 +49
- Partials 1324 1328 +4
🚀 New features to boost your workflow:
|
logger.Infof("rls: max_age in route lookup config is %v, using %v", maxAge, maxMaxAge) | ||
maxAge = maxMaxAge | ||
} | ||
if staleAge > maxAge { | ||
logger.Infof("rls: stale_age %v is not less than max_age %v, ignoring it", staleAge, maxAge) | ||
staleAge = maxAge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume, ignoring staleAge let us to set it to maxAge and that should be fine.
balancer/rls/config.go
Outdated
@@ -219,7 +219,7 @@ func parseRLSProto(rlsProto *rlspb.RouteLookupConfig) (*lbConfig, error) { | |||
} | |||
|
|||
// Validations performed here: | |||
// - if `max_age` > 5m, it should be set to 5 minutes | |||
// - if `max_age` > 5m, it should be set to 5 minutes only if stale age is not set |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can you make sure to wrap the comments within 80 cols?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any checkstyle failures.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no checker to test but for go 80 cols is limit for comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
go/go-style/decisions#comment-line-length
logger.Infof("rls: max_age in route lookup config is %v, using %v", maxAge, maxMaxAge) | ||
maxAge = maxMaxAge | ||
} | ||
if staleAge > maxAge { | ||
logger.Infof("rls: stale_age %v is not less than max_age %v, ignoring it", staleAge, maxAge) | ||
staleAge = maxAge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't staleAge
be set to 0 because we are ignoring it? That's how its done before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#Comment23 talks about clamping the these values. I think this will be an improvement. Also rls_config.proto has been changed that talks about clamping the stale_age: grpc/grpc-proto@0462d4b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the following logic in C-core
- Internal representatino of
stale_age
andmax_age
both start off with default value of5m
, which is max allowed value - In the JSON configuration, check if
stale_age
andmax_age
are set in the configuration:- If
stale_age
is set, butmax_age
is not set, then throw an error
- If
- Clamp
stale_age
to the max allowed value - If
stale_age
is not set, clampmax_age
to the max allowed value - If
stale_age
is greater than or equal tomax_age
, setstale_age
to be the same asmax_age
In Go, we marshal the JSON configuration into a proto message and perform all validation and build our internal representation from the proto message. Because the proto API in Go does not support checking if a value is set or not, I suggest going with the following approach.
- Read
staleAge
from proto using theconvertDuration
helper function. If the readstaleAge
is non-zero, then setstaleAgeSet
to betrue
. If the readstaleAge
is zero, setstaleAge
tomaxMaxAge
which is5m
.
staleAgeSet := false
staleAge, err := convertDuration(rlsProto.GetStaleAge())
if err != nil {
return nil, fmt.Errorf("rls: failed to parse staleAge in route lookup config %+v: %v", rlsProto, err)
}
if staleAge == 0 {
staleAge = maxMaxAge
} else {
staleAgeSet = true
}
- Do the same thing for
maxAge
- Then check whether both are set or not
If staleAgeSet && !maxAgeSet {
return nil, fmt.Errorf("rls: stale_age is set, but max_age is not in route lookup config %+v", rlsProto)
}
- Clamp
stale_age
to the max allowed value
if staleAge > maxMaxAge {
staleAge = maxMaxAge
}
- If
stale_age
is not set, clampmax_age
to the max allowed value
if !staleAgeSet && maxAge > maxMaxAge {
maxAge = maxMaxAge
}
- If
stale_age
is greater than or equal tomax_age
, setstale_age
to be the same asmax_age
if staleAge > maxAge {
staleAge = maxAge
}
Let me know what you think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this seems ditto logic-wise. The only diff is, we are always assigning some value to staleAge
and that should be fine.
But looks good to use staleAgeSet
and maxAgeSet
. Makes it much easier to understand for the reader.
PS: In java we are not using these extra variables. We are playing with staleAge and maxAge only.
balancer/rls/config.go
Outdated
} | ||
if maxAge == 0 || maxAge > maxMaxAge { | ||
if staleAge == 0 && maxAge > maxMaxAge { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we only need to update this condition at line 239 and leave rest of the stuff as is. Just to make sure we are not doing any unintended changes here and only updating the validation to allow maxAge > 5 but only if staleAge is set. So, may be something like this should suffice?
if maxAge == 0 {
logger.Infof("rls: max_age in route lookup config is %v, using %v", maxAge, maxMaxAge)
maxAge = maxMaxAge
} else if maxAge > maxMaxAge && staleAge == 0 {
logger.Infof("rls: max_age in route lookup config is %v and stale_age is not set, using %v", maxAge, maxMaxAge)
maxAge = maxMaxAge
}
```
We update maxAge to maxMaxAge only if its either not set or its set but staleAge is not set. Otherwise we just keep the value assigned to it.
balancer/rls/config.go
Outdated
@@ -219,7 +219,7 @@ func parseRLSProto(rlsProto *rlspb.RouteLookupConfig) (*lbConfig, error) { | |||
} | |||
|
|||
// Validations performed here: | |||
// - if `max_age` > 5m, it should be set to 5 minutes | |||
// - if `max_age` > 5m, it should be set to 5 minutes only if stale age is not set |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
go/go-style/decisions#comment-line-length
logger.Infof("rls: max_age in route lookup config is %v, using %v", maxAge, maxMaxAge) | ||
maxAge = maxMaxAge | ||
} | ||
if staleAge > maxAge { | ||
logger.Infof("rls: stale_age %v is not less than max_age %v, ignoring it", staleAge, maxAge) | ||
staleAge = maxAge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the following logic in C-core
- Internal representatino of
stale_age
andmax_age
both start off with default value of5m
, which is max allowed value - In the JSON configuration, check if
stale_age
andmax_age
are set in the configuration:- If
stale_age
is set, butmax_age
is not set, then throw an error
- If
- Clamp
stale_age
to the max allowed value - If
stale_age
is not set, clampmax_age
to the max allowed value - If
stale_age
is greater than or equal tomax_age
, setstale_age
to be the same asmax_age
In Go, we marshal the JSON configuration into a proto message and perform all validation and build our internal representation from the proto message. Because the proto API in Go does not support checking if a value is set or not, I suggest going with the following approach.
- Read
staleAge
from proto using theconvertDuration
helper function. If the readstaleAge
is non-zero, then setstaleAgeSet
to betrue
. If the readstaleAge
is zero, setstaleAge
tomaxMaxAge
which is5m
.
staleAgeSet := false
staleAge, err := convertDuration(rlsProto.GetStaleAge())
if err != nil {
return nil, fmt.Errorf("rls: failed to parse staleAge in route lookup config %+v: %v", rlsProto, err)
}
if staleAge == 0 {
staleAge = maxMaxAge
} else {
staleAgeSet = true
}
- Do the same thing for
maxAge
- Then check whether both are set or not
If staleAgeSet && !maxAgeSet {
return nil, fmt.Errorf("rls: stale_age is set, but max_age is not in route lookup config %+v", rlsProto)
}
- Clamp
stale_age
to the max allowed value
if staleAge > maxMaxAge {
staleAge = maxMaxAge
}
- If
stale_age
is not set, clampmax_age
to the max allowed value
if !staleAgeSet && maxAge > maxMaxAge {
maxAge = maxMaxAge
}
- If
stale_age
is greater than or equal tomax_age
, setstale_age
to be the same asmax_age
if staleAge > maxAge {
staleAge = maxAge
}
Let me know what you think.
balancer/rls/config_test.go
Outdated
}, | ||
}, | ||
{ | ||
desc: "with transformations 1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The value for this field needs to be different in each of the sub tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious to know why it didn't fail even with same value with this field! And surprisingly it made it also through github checks!
Now it is getting caught and failing in the editor itself when I'm running the tests.
balancer/rls/config_test.go
Outdated
{ | ||
desc: "with transformations 1", | ||
input: []byte(`{ | ||
"top-level-unknown-field": "unknown-value", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not required for this sub-test.
balancer/rls/config_test.go
Outdated
input: []byte(`{ | ||
"top-level-unknown-field": "unknown-value", | ||
"routeLookupConfig": { | ||
"unknown-field": "unknown-value", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same with this field.
maxAge: 500 * time.Second, // Max age is not clamped when stale age is set. | ||
staleAge: 300 * time.Second, // StaleAge is clamped because it was higher than maxMaxAge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment at the top of this sub-test also needs to change.
balancer/rls/config_test.go
Outdated
{"cds_experimental": {"Cluster": "my-fav-cluster"}}, | ||
{"unknown-policy": {"unknown-field": "unknown-value"}}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can get rid of these two lines because they are not pertinent to this sub-test.
balancer/rls/config_test.go
Outdated
"maxAge" : "500s", | ||
"staleAge": "200s", | ||
"cacheSizeBytes": 100000000, | ||
"defaultTarget": "passthrough:///default" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get rid of the defaultTarget as well. Not pertinent to this sub-test.
balancer/rls/config_test.go
Outdated
"lookupService": ":///target", | ||
"maxAge" : "500s", | ||
"cacheSizeBytes": 100000000, | ||
"defaultTarget": "passthrough:///default" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get rid of the defaultTarget as well. Not pertinent to this sub-test.
balancer/rls/config_test.go
Outdated
{"cds_experimental": {"Cluster": "my-fav-cluster"}}, | ||
{"unknown-policy": {"unknown-field": "unknown-value"}}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can get rid of these two lines because they are not pertinent to this sub-test.
Internal feature request: b/371591767
RELEASE NOTES: