@@ -28,10 +28,11 @@ import (
2828
2929 "vitess.io/vitess/go/mysql"
3030 "vitess.io/vitess/go/sqltypes"
31- "vitess.io/vitess/go/vt/vttablet/tabletserver/throttle/base"
32-
3331 "vitess.io/vitess/go/test/endtoend/cluster"
3432 "vitess.io/vitess/go/test/endtoend/throttler"
33+ "vitess.io/vitess/go/vt/logutil"
34+ topodatapb "vitess.io/vitess/go/vt/proto/topodata"
35+ "vitess.io/vitess/go/vt/vttablet/tabletserver/throttle/base"
3536
3637 "github.com/stretchr/testify/assert"
3738 "github.com/stretchr/testify/require"
@@ -45,6 +46,7 @@ const (
4546 onDemandHeartbeatDuration = 5 * time .Second
4647 throttlerEnabledTimeout = 60 * time .Second
4748 useDefaultQuery = ""
49+ testAppName = "test"
4850)
4951
5052var (
@@ -170,12 +172,12 @@ func throttledApps(tablet *cluster.Vttablet) (resp *http.Response, respBody stri
170172}
171173
172174func throttleCheck (tablet * cluster.Vttablet , skipRequestHeartbeats bool ) (* http.Response , error ) {
173- resp , err := httpClient .Get (fmt .Sprintf ("http://localhost:%d/%s?app=test &s=%t" , tablet .HTTPPort , checkAPIPath , skipRequestHeartbeats ))
175+ resp , err := httpClient .Get (fmt .Sprintf ("http://localhost:%d/%s?app=%s &s=%t" , tablet .HTTPPort , checkAPIPath , testAppName , skipRequestHeartbeats ))
174176 return resp , err
175177}
176178
177179func throttleCheckSelf (tablet * cluster.Vttablet ) (* http.Response , error ) {
178- return httpClient .Get (fmt .Sprintf ("http://localhost:%d/%s?app=test " , tablet .HTTPPort , checkSelfAPIPath ))
180+ return httpClient .Get (fmt .Sprintf ("http://localhost:%d/%s?app=%s " , tablet .HTTPPort , checkSelfAPIPath , testAppName ))
179181}
180182
181183func warmUpHeartbeat (t * testing.T ) (respStatus int ) {
@@ -245,7 +247,7 @@ func TestInitialThrottler(t *testing.T) {
245247 waitForThrottleCheckStatus (t , primaryTablet , http .StatusOK )
246248 })
247249 t .Run ("enabling throttler with very low threshold" , func (t * testing.T ) {
248- _ , err := throttler .UpdateThrottlerTopoConfig (clusterInstance , true , false , unreasonablyLowThreshold .Seconds (), useDefaultQuery )
250+ _ , err := throttler .UpdateThrottlerTopoConfig (clusterInstance , true , false , unreasonablyLowThreshold .Seconds (), useDefaultQuery , nil )
249251 assert .NoError (t , err )
250252
251253 // Wait for the throttler to be enabled everywhere with the new config.
@@ -257,7 +259,7 @@ func TestInitialThrottler(t *testing.T) {
257259 waitForThrottleCheckStatus (t , primaryTablet , http .StatusTooManyRequests )
258260 })
259261 t .Run ("disabling throttler" , func (t * testing.T ) {
260- _ , err := throttler .UpdateThrottlerTopoConfig (clusterInstance , false , true , unreasonablyLowThreshold .Seconds (), useDefaultQuery )
262+ _ , err := throttler .UpdateThrottlerTopoConfig (clusterInstance , false , true , unreasonablyLowThreshold .Seconds (), useDefaultQuery , nil )
261263 assert .NoError (t , err )
262264
263265 // Wait for the throttler to be disabled everywhere.
@@ -271,7 +273,7 @@ func TestInitialThrottler(t *testing.T) {
271273 t .Run ("enabling throttler, again" , func (t * testing.T ) {
272274 // Enable the throttler again with the default query which also moves us back
273275 // to the default threshold.
274- _ , err := throttler .UpdateThrottlerTopoConfig (clusterInstance , true , false , 0 , useDefaultQuery )
276+ _ , err := throttler .UpdateThrottlerTopoConfig (clusterInstance , true , false , 0 , useDefaultQuery , nil )
275277 assert .NoError (t , err )
276278
277279 // Wait for the throttler to be enabled everywhere again with the default config.
@@ -283,7 +285,7 @@ func TestInitialThrottler(t *testing.T) {
283285 waitForThrottleCheckStatus (t , primaryTablet , http .StatusTooManyRequests )
284286 })
285287 t .Run ("setting high threshold" , func (t * testing.T ) {
286- _ , err := throttler .UpdateThrottlerTopoConfig (clusterInstance , false , false , extremelyHighThreshold .Seconds (), useDefaultQuery )
288+ _ , err := throttler .UpdateThrottlerTopoConfig (clusterInstance , false , false , extremelyHighThreshold .Seconds (), useDefaultQuery , nil )
287289 assert .NoError (t , err )
288290
289291 // Wait for the throttler to be enabled everywhere with new config.
@@ -295,7 +297,7 @@ func TestInitialThrottler(t *testing.T) {
295297 waitForThrottleCheckStatus (t , primaryTablet , http .StatusOK )
296298 })
297299 t .Run ("setting low threshold" , func (t * testing.T ) {
298- _ , err := throttler .UpdateThrottlerTopoConfig (clusterInstance , false , false , throttler .DefaultThreshold .Seconds (), useDefaultQuery )
300+ _ , err := throttler .UpdateThrottlerTopoConfig (clusterInstance , false , false , throttler .DefaultThreshold .Seconds (), useDefaultQuery , nil )
299301 assert .NoError (t , err )
300302
301303 // Wait for the throttler to be enabled everywhere with new config.
@@ -392,6 +394,26 @@ func TestLag(t *testing.T) {
392394 defer resp .Body .Close ()
393395 assert .Equalf (t , http .StatusTooManyRequests , resp .StatusCode , "Unexpected response from throttler: %s" , getResponseBody (resp ))
394396 })
397+ t .Run ("exempting test app" , func (t * testing.T ) {
398+ appRule := & topodatapb.ThrottledAppRule {
399+ Name : testAppName ,
400+ ExpiresAt : logutil .TimeToProto (time .Now ().Add (time .Hour )),
401+ Exempt : true ,
402+ }
403+ _ , err := throttler .UpdateThrottlerTopoConfig (clusterInstance , false , false , throttler .DefaultThreshold .Seconds (), useDefaultQuery , appRule )
404+ assert .NoError (t , err )
405+ waitForThrottleCheckStatus (t , primaryTablet , http .StatusOK )
406+ })
407+ t .Run ("unexempting test app" , func (t * testing.T ) {
408+ appRule := & topodatapb.ThrottledAppRule {
409+ Name : testAppName ,
410+ ExpiresAt : logutil .TimeToProto (time .Now ()),
411+ }
412+ _ , err := throttler .UpdateThrottlerTopoConfig (clusterInstance , false , false , throttler .DefaultThreshold .Seconds (), useDefaultQuery , appRule )
413+ assert .NoError (t , err )
414+ waitForThrottleCheckStatus (t , primaryTablet , http .StatusTooManyRequests )
415+ })
416+
395417 t .Run ("starting replication" , func (t * testing.T ) {
396418 err := clusterInstance .VtctlclientProcess .ExecuteCommand ("StartReplication" , replicaTablet .Alias )
397419 assert .NoError (t , err )
@@ -436,7 +458,7 @@ func TestCustomQuery(t *testing.T) {
436458 defer cluster .PanicHandler (t )
437459
438460 t .Run ("enabling throttler with custom query and threshold" , func (t * testing.T ) {
439- _ , err := throttler .UpdateThrottlerTopoConfig (clusterInstance , true , false , customThreshold , customQuery )
461+ _ , err := throttler .UpdateThrottlerTopoConfig (clusterInstance , true , false , customThreshold , customQuery , nil )
440462 assert .NoError (t , err )
441463
442464 // Wait for the throttler to be enabled everywhere with new custom config.
@@ -504,7 +526,7 @@ func TestRestoreDefaultQuery(t *testing.T) {
504526
505527 // Validate going back from custom-query to default-query (replication lag) still works.
506528 t .Run ("enabling throttler with default query and threshold" , func (t * testing.T ) {
507- _ , err := throttler .UpdateThrottlerTopoConfig (clusterInstance , true , false , throttler .DefaultThreshold .Seconds (), useDefaultQuery )
529+ _ , err := throttler .UpdateThrottlerTopoConfig (clusterInstance , true , false , throttler .DefaultThreshold .Seconds (), useDefaultQuery , nil )
508530 assert .NoError (t , err )
509531
510532 // Wait for the throttler to be up and running everywhere again with the default config.
0 commit comments