@@ -60,8 +60,8 @@ func (s) TestParseConfig(t *testing.T) {
60
60
// - A top-level unknown field should not fail.
61
61
// - An unknown field in routeLookupConfig proto should not fail.
62
62
// - lookupServiceTimeout is set to its default value, since it is not specified in the input.
63
- // - maxAge is set to maxMaxAge since the value is too large in the input .
64
- // - staleAge is ignore because it is higher than maxAge in the input.
63
+ // - maxAge is clamped to maxMaxAge if staleAge is not set .
64
+ // - staleAge is ignored because it is higher than maxAge in the input.
65
65
// - cacheSizeBytes is greater than the hard upper limit of 5MB
66
66
desc : "with transformations 1" ,
67
67
input : []byte (`{
@@ -87,9 +87,9 @@ func (s) TestParseConfig(t *testing.T) {
87
87
}` ),
88
88
wantCfg : & lbConfig {
89
89
lookupService : ":///target" ,
90
- lookupServiceTimeout : 10 * time .Second , // This is the default value.
91
- maxAge : 5 * time .Minute , // This is max maxAge .
92
- staleAge : time .Duration ( 0 ) , // StaleAge is ignore because it was higher than maxAge .
90
+ lookupServiceTimeout : 10 * time .Second , // This is the default value.
91
+ maxAge : 500 * time .Second , // Max age is not clamped when stale age is set .
92
+ staleAge : 300 * time .Second , // StaleAge is clamped because it was higher than maxMaxAge .
93
93
cacheSizeBytes : maxCacheSize ,
94
94
defaultTarget : "passthrough:///default" ,
95
95
childPolicyName : "grpclb" ,
@@ -100,6 +100,69 @@ func (s) TestParseConfig(t *testing.T) {
100
100
},
101
101
},
102
102
},
103
+ {
104
+ desc : "maxAge not clamped when staleAge is set" ,
105
+ input : []byte (`{
106
+ "routeLookupConfig": {
107
+ "grpcKeybuilders": [{
108
+ "names": [{"service": "service", "method": "method"}],
109
+ "headers": [{"key": "k1", "names": ["v1"]}]
110
+ }],
111
+ "lookupService": ":///target",
112
+ "maxAge" : "500s",
113
+ "staleAge": "200s",
114
+ "cacheSizeBytes": 100000000
115
+ },
116
+ "childPolicy": [
117
+ {"grpclb": {"childPolicy": [{"pickfirst": {}}]}}
118
+ ],
119
+ "childPolicyConfigTargetFieldName": "serviceName"
120
+ }` ),
121
+ wantCfg : & lbConfig {
122
+ lookupService : ":///target" ,
123
+ lookupServiceTimeout : 10 * time .Second , // This is the default value.
124
+ maxAge : 500 * time .Second , // Max age is not clamped when stale age is set.
125
+ staleAge : 200 * time .Second , // This is stale age within maxMaxAge.
126
+ cacheSizeBytes : maxCacheSize ,
127
+ childPolicyName : "grpclb" ,
128
+ childPolicyTargetField : "serviceName" ,
129
+ childPolicyConfig : map [string ]json.RawMessage {
130
+ "childPolicy" : json .RawMessage (`[{"pickfirst": {}}]` ),
131
+ "serviceName" : json .RawMessage (childPolicyTargetFieldVal ),
132
+ },
133
+ },
134
+ },
135
+ {
136
+ desc : "maxAge clamped when staleAge is not set" ,
137
+ input : []byte (`{
138
+ "routeLookupConfig": {
139
+ "grpcKeybuilders": [{
140
+ "names": [{"service": "service", "method": "method"}],
141
+ "headers": [{"key": "k1", "names": ["v1"]}]
142
+ }],
143
+ "lookupService": ":///target",
144
+ "maxAge" : "500s",
145
+ "cacheSizeBytes": 100000000
146
+ },
147
+ "childPolicy": [
148
+ {"grpclb": {"childPolicy": [{"pickfirst": {}}]}}
149
+ ],
150
+ "childPolicyConfigTargetFieldName": "serviceName"
151
+ }` ),
152
+ wantCfg : & lbConfig {
153
+ lookupService : ":///target" ,
154
+ lookupServiceTimeout : 10 * time .Second , // This is the default value.
155
+ maxAge : 300 * time .Second , // Max age is clamped when stale age is not set.
156
+ staleAge : 300 * time .Second ,
157
+ cacheSizeBytes : maxCacheSize ,
158
+ childPolicyName : "grpclb" ,
159
+ childPolicyTargetField : "serviceName" ,
160
+ childPolicyConfig : map [string ]json.RawMessage {
161
+ "childPolicy" : json .RawMessage (`[{"pickfirst": {}}]` ),
162
+ "serviceName" : json .RawMessage (childPolicyTargetFieldVal ),
163
+ },
164
+ },
165
+ },
103
166
{
104
167
desc : "without transformations" ,
105
168
input : []byte (`{
0 commit comments