@@ -215,7 +215,7 @@ func warmUpHeartbeat(t *testing.T) tabletmanagerdatapb.CheckThrottlerResponseCod
215
215
}
216
216
217
217
// waitForThrottleCheckStatus waits for the tablet to return the provided HTTP code in a throttle check
218
- func waitForThrottleCheckStatus (t * testing.T , tablet * cluster.Vttablet , wantCode tabletmanagerdatapb.CheckThrottlerResponseCode ) bool {
218
+ func waitForThrottleCheckStatus (t * testing.T , tablet * cluster.Vttablet , wantCode tabletmanagerdatapb.CheckThrottlerResponseCode ) ( * tabletmanagerdatapb. CheckThrottlerResponse , bool ) {
219
219
_ = warmUpHeartbeat (t )
220
220
ctx , cancel := context .WithTimeout (context .Background (), onDemandHeartbeatDuration * 4 )
221
221
defer cancel ()
@@ -229,11 +229,11 @@ func waitForThrottleCheckStatus(t *testing.T, tablet *cluster.Vttablet, wantCode
229
229
if wantCode == resp .Check .ResponseCode {
230
230
// Wait for any cached check values to be cleared and the new
231
231
// status value to be in effect everywhere before returning.
232
- return true
232
+ return resp . Check , true
233
233
}
234
234
select {
235
235
case <- ctx .Done ():
236
- return assert . EqualValues ( t , wantCode , resp .Check . StatusCode , "response: %+v" , resp )
236
+ return resp .Check , false
237
237
case <- ticker .C :
238
238
}
239
239
}
@@ -779,16 +779,16 @@ func TestUpdateAppCheckedMetrics(t *testing.T) {
779
779
}
780
780
waitForThrottleCheckStatus (t , primaryTablet , tabletmanagerdatapb .CheckThrottlerResponseCode_THRESHOLD_EXCEEDED )
781
781
})
782
- t .Run ("assigning 'loadavg ' metrics to 'test' app" , func (t * testing.T ) {
782
+ t .Run ("assigning 'threads_running ' metrics to 'test' app" , func (t * testing.T ) {
783
783
{
784
- req := & vtctldatapb.UpdateThrottlerConfigRequest {MetricName : "loadavg" , Threshold : 7777 }
784
+ req := & vtctldatapb.UpdateThrottlerConfigRequest {MetricName : base . ThreadsRunningMetricName . String () , Threshold : 7777 }
785
785
_ , err := throttler .UpdateThrottlerTopoConfig (clusterInstance , req , nil , nil )
786
786
assert .NoError (t , err )
787
787
}
788
788
{
789
789
req := & vtctldatapb.UpdateThrottlerConfigRequest {}
790
790
appCheckedMetrics := map [string ]* topodatapb.ThrottlerConfig_MetricNames {
791
- testAppName .String (): {Names : []string {"loadavg" }},
791
+ testAppName .String (): {Names : []string {base . ThreadsRunningMetricName . String () }},
792
792
}
793
793
_ , err := throttler .UpdateThrottlerTopoConfig (clusterInstance , req , nil , appCheckedMetrics )
794
794
assert .NoError (t , err )
@@ -802,18 +802,18 @@ func TestUpdateAppCheckedMetrics(t *testing.T) {
802
802
for _ , tablet := range []cluster.Vttablet {* primaryTablet , * replicaTablet } {
803
803
throttler .WaitForThrottlerStatusEnabled (t , & clusterInstance .VtctldClientProcess , & tablet , true , & throttler.Config {Query : throttler .DefaultQuery , Threshold : unreasonablyLowThreshold .Seconds ()}, throttlerEnabledTimeout )
804
804
}
805
- t .Run ("validating OK response from throttler since it's checking loadavg " , func (t * testing.T ) {
806
- if ! waitForThrottleCheckStatus (t , primaryTablet , tabletmanagerdatapb .CheckThrottlerResponseCode_OK ) {
805
+ t .Run ("validating OK response from throttler since it's checking threads_running " , func (t * testing.T ) {
806
+ if _ , ok := waitForThrottleCheckStatus (t , primaryTablet , tabletmanagerdatapb .CheckThrottlerResponseCode_OK ); ! ok {
807
807
t .Logf ("throttler primary status: %+v" , throttleStatus (t , primaryTablet ))
808
808
t .Logf ("throttler replica status: %+v" , throttleStatus (t , replicaTablet ))
809
809
}
810
810
})
811
811
})
812
- t .Run ("assigning 'loadavg ,lag' metrics to 'test' app" , func (t * testing.T ) {
812
+ t .Run ("assigning 'threads_running ,lag' metrics to 'test' app" , func (t * testing.T ) {
813
813
{
814
814
req := & vtctldatapb.UpdateThrottlerConfigRequest {}
815
815
appCheckedMetrics := map [string ]* topodatapb.ThrottlerConfig_MetricNames {
816
- testAppName .String (): {Names : []string {"loadavg,lag" }},
816
+ testAppName .String (): {Names : []string {base . ThreadsRunningMetricName . String (), base . LagMetricName . String () }},
817
817
}
818
818
_ , err := throttler .UpdateThrottlerTopoConfig (clusterInstance , req , nil , appCheckedMetrics )
819
819
assert .NoError (t , err )
@@ -831,9 +831,51 @@ func TestUpdateAppCheckedMetrics(t *testing.T) {
831
831
waitForThrottleCheckStatus (t , primaryTablet , tabletmanagerdatapb .CheckThrottlerResponseCode_THRESHOLD_EXCEEDED )
832
832
})
833
833
})
834
+ t .Run ("assigning 'mysqld-loadavg,mysqld-datadir-used-ratio' metrics to 'test' app" , func (t * testing.T ) {
835
+ {
836
+ req := & vtctldatapb.UpdateThrottlerConfigRequest {MetricName : base .MysqldDatadirUsedRatioMetricName .String (), Threshold : 0.9999 }
837
+ _ , err := throttler .UpdateThrottlerTopoConfig (clusterInstance , req , nil , nil )
838
+ assert .NoError (t , err )
839
+ }
840
+ {
841
+ req := & vtctldatapb.UpdateThrottlerConfigRequest {MetricName : base .MysqldLoadAvgMetricName .String (), Threshold : 5555 }
842
+ _ , err := throttler .UpdateThrottlerTopoConfig (clusterInstance , req , nil , nil )
843
+ assert .NoError (t , err )
844
+ }
845
+ {
846
+ req := & vtctldatapb.UpdateThrottlerConfigRequest {}
847
+ appCheckedMetrics := map [string ]* topodatapb.ThrottlerConfig_MetricNames {
848
+ testAppName .String (): {Names : []string {base .MysqldDatadirUsedRatioMetricName .String (), base .MysqldLoadAvgMetricName .String ()}},
849
+ }
850
+ _ , err := throttler .UpdateThrottlerTopoConfig (clusterInstance , req , nil , appCheckedMetrics )
851
+ assert .NoError (t , err )
852
+ }
853
+ {
854
+ req := & vtctldatapb.UpdateThrottlerConfigRequest {Threshold : extremelyHighThreshold .Seconds ()}
855
+ _ , err := throttler .UpdateThrottlerTopoConfig (clusterInstance , req , nil , nil )
856
+ assert .NoError (t , err )
857
+ }
858
+ // Wait for the throttler to be enabled everywhere with new config.
859
+ for _ , tablet := range []cluster.Vttablet {* primaryTablet , * replicaTablet } {
860
+ throttler .WaitForThrottlerStatusEnabled (t , & clusterInstance .VtctldClientProcess , & tablet , true , & throttler.Config {Query : throttler .DefaultQuery , Threshold : extremelyHighThreshold .Seconds ()}, throttlerEnabledTimeout )
861
+ }
862
+ t .Run ("validating OK response from throttler since it's checking mysqld-loadavg,mysqld-datadir-used-ratio" , func (t * testing.T ) {
863
+ resp , ok := waitForThrottleCheckStatus (t , primaryTablet , tabletmanagerdatapb .CheckThrottlerResponseCode_OK )
864
+ if ! ok {
865
+ t .Logf ("response: %+v" , resp )
866
+ t .Logf ("throttler primary status: %+v" , throttleStatus (t , primaryTablet ))
867
+ t .Logf ("throttler replica status: %+v" , throttleStatus (t , replicaTablet ))
868
+ }
869
+ require .Contains (t , resp .Metrics , base .MysqldDatadirUsedRatioMetricName .String ())
870
+ require .Contains (t , resp .Metrics , base .MysqldLoadAvgMetricName .String ())
871
+ assert .NotContains (t , resp .Metrics , base .ThreadsRunningMetricName .String ())
872
+
873
+ assert .NotZero (t , resp .Metrics [base .MysqldDatadirUsedRatioMetricName .String ()].Value )
874
+ })
875
+ })
834
876
t .Run ("removing assignment from 'test' app and restoring defaults" , func (t * testing.T ) {
835
877
{
836
- req := & vtctldatapb.UpdateThrottlerConfigRequest {MetricName : "loadavg" , Threshold : 0 }
878
+ req := & vtctldatapb.UpdateThrottlerConfigRequest {MetricName : base . ThreadsRunningMetricName . String () , Threshold : 0 }
837
879
_ , err := throttler .UpdateThrottlerTopoConfig (clusterInstance , req , nil , nil )
838
880
assert .NoError (t , err )
839
881
}
0 commit comments