diff --git a/go/cmd/vtctldclient/command/throttler.go b/go/cmd/vtctldclient/command/throttler.go index e26986832f6..84943cc9962 100644 --- a/go/cmd/vtctldclient/command/throttler.go +++ b/go/cmd/vtctldclient/command/throttler.go @@ -17,6 +17,7 @@ limitations under the License. package command import ( + "fmt" "time" "github.com/spf13/cobra" @@ -32,7 +33,7 @@ import ( var ( // UpdateThrottlerConfig makes a UpdateThrottlerConfig gRPC call to a vtctld. UpdateThrottlerConfig = &cobra.Command{ - Use: "UpdateThrottlerConfig [--enable|--disable] [--threshold=] [--custom-query=] [--check-as-check-self|--check-as-check-shard] [--throttle-app=] [--throttle-app-ratio=] [--throttle-app-duration=] ", + Use: "UpdateThrottlerConfig [--enable|--disable] [--threshold=] [--custom-query=] [--check-as-check-self|--check-as-check-shard] [--throttle-app|unthrottle-app=] [--throttle-app-ratio=] [--throttle-app-duration=] ", Short: "Update the tablet throttler configuration for all tablets in the given keyspace (across all cells)", DisableFlagsInUseLine: true, Args: cobra.ExactArgs(1), @@ -43,6 +44,7 @@ var ( var ( updateThrottlerConfigOptions vtctldatapb.UpdateThrottlerConfigRequest throttledAppRule topodatapb.ThrottledAppRule + unthrottledAppRule topodatapb.ThrottledAppRule throttledAppDuration time.Duration ) @@ -50,12 +52,19 @@ func commandUpdateThrottlerConfig(cmd *cobra.Command, args []string) error { keyspace := cmd.Flags().Arg(0) cli.FinishedParsing(cmd) + if throttledAppRule.Name != "" && unthrottledAppRule.Name != "" { + return fmt.Errorf("throttle-app and unthrottle-app are mutually exclusive") + } + updateThrottlerConfigOptions.CustomQuerySet = cmd.Flags().Changed("custom-query") updateThrottlerConfigOptions.Keyspace = keyspace - throttledAppRule.ExpiresAt = logutil.TimeToProto(time.Now().Add(throttledAppDuration)) if throttledAppRule.Name != "" { + throttledAppRule.ExpiresAt = logutil.TimeToProto(time.Now().Add(throttledAppDuration)) updateThrottlerConfigOptions.ThrottledApp = &throttledAppRule + } else if unthrottledAppRule.Name != "" { + unthrottledAppRule.ExpiresAt = logutil.TimeToProto(time.Now()) + updateThrottlerConfigOptions.ThrottledApp = &unthrottledAppRule } _, err := client.UpdateThrottlerConfig(commandCtx, &updateThrottlerConfigOptions) @@ -73,6 +82,7 @@ func init() { UpdateThrottlerConfig.Flags().BoolVar(&updateThrottlerConfigOptions.CheckAsCheckSelf, "check-as-check-self", false, "/throttler/check requests behave as is /throttler/check-self was called") UpdateThrottlerConfig.Flags().BoolVar(&updateThrottlerConfigOptions.CheckAsCheckShard, "check-as-check-shard", false, "use standard behavior for /throttler/check requests") + UpdateThrottlerConfig.Flags().StringVar(&unthrottledAppRule.Name, "unthrottle-app", "", "an app name to unthrottle") UpdateThrottlerConfig.Flags().StringVar(&throttledAppRule.Name, "throttle-app", "", "an app name to throttle") UpdateThrottlerConfig.Flags().Float64Var(&throttledAppRule.Ratio, "throttle-app-ratio", throttle.DefaultThrottleRatio, "ratio to throttle app (app specififed in --throttled-app)") UpdateThrottlerConfig.Flags().DurationVar(&throttledAppDuration, "throttle-app-duration", throttle.DefaultAppThrottleDuration, "duration after which throttled app rule expires (app specififed in --throttled-app)") diff --git a/go/test/endtoend/throttler/util.go b/go/test/endtoend/throttler/util.go index 7a2f13cca77..71a6c6454f3 100644 --- a/go/test/endtoend/throttler/util.go +++ b/go/test/endtoend/throttler/util.go @@ -152,12 +152,11 @@ func WaitForSrvKeyspace(clusterInstance *cluster.LocalProcessCluster, cell, keys func throttleAppRaw(vtctldProcess *cluster.VtctldClientProcess, keyspaceName string, throttlerApp throttlerapp.Name, throttle bool) (result string, err error) { args := []string{} args = append(args, "UpdateThrottlerConfig") - args = append(args, "--throttle-app", throttlerApp.String()) - args = append(args, "--throttle-app-duration") if throttle { - args = append(args, "1h") + args = append(args, "--throttle-app", throttlerApp.String()) + args = append(args, "--throttle-app-duration", "1h") } else { - args = append(args, "-1h") + args = append(args, "--unthrottle-app", throttlerApp.String()) } args = append(args, keyspaceName) diff --git a/go/vt/vtctl/vtctl.go b/go/vt/vtctl/vtctl.go index 44c04f0dcb4..d1f5e801388 100644 --- a/go/vt/vtctl/vtctl.go +++ b/go/vt/vtctl/vtctl.go @@ -702,7 +702,7 @@ var commands = []commandGroup{ { name: "UpdateThrottlerConfig", method: commandUpdateThrottlerConfig, - params: "[--enable|--disable] [--threshold=] [--custom-query=] [--check-as-check-self|--check-as-check-shard] [--throttle-app=] [--throttle-app-ratio=] [--throttle-app-duration=] ", + params: "[--enable|--disable] [--threshold=] [--custom-query=] [--check-as-check-self|--check-as-check-shard] [--throttle-app|unthrottle-app=] [--throttle-app-ratio=] [--throttle-app-duration=] ", help: "Update the table throttler configuration for all cells and tablets of a given keyspace", }, { @@ -3555,6 +3555,7 @@ func commandUpdateThrottlerConfig(ctx context.Context, wr *wrangler.Wrangler, su customQuery := subFlags.String("custom-query", "", "custom throttler check query") checkAsCheckSelf := subFlags.Bool("check-as-check-self", false, "/throttler/check requests behave as is /throttler/check-self was called") checkAsCheckShard := subFlags.Bool("check-as-check-shard", false, "use standard behavior for /throttler/check requests") + unthrottledApp := subFlags.String("unthrottle-app", "", "an app name to unthrottle") throttledApp := subFlags.String("throttle-app", "", "an app name to throttle") throttledAppRatio := subFlags.Float64("throttle-app-ratio", throttle.DefaultThrottleRatio, "ratio to throttle app (app specififed in --throttled-app)") throttledAppDuration := subFlags.Duration("throttle-app-duration", throttle.DefaultAppThrottleDuration, "duration after which throttled app rule expires (app specified in --throttled-app)") @@ -3572,6 +3573,9 @@ func commandUpdateThrottlerConfig(ctx context.Context, wr *wrangler.Wrangler, su return fmt.Errorf("--check-as-check-self and --check-as-check-shard are mutually exclusive") } + if *throttledApp != "" && *unthrottledApp != "" { + return fmt.Errorf("--throttle-app and --unthrottle-app are mutually exclusive") + } if subFlags.Changed("throttle-app-ratio") && *throttledApp == "" { return fmt.Errorf("--throttle-app-ratio requires --throttle-app") } @@ -3597,6 +3601,12 @@ func commandUpdateThrottlerConfig(ctx context.Context, wr *wrangler.Wrangler, su Ratio: *throttledAppRatio, ExpiresAt: logutil.TimeToProto(time.Now().Add(*throttledAppDuration)), } + } else if *unthrottledApp != "" { + req.ThrottledApp = &topodatapb.ThrottledAppRule{ + Name: *unthrottledApp, + Ratio: 0, + ExpiresAt: logutil.TimeToProto(time.Now()), + } } _, err = wr.VtctldServer().UpdateThrottlerConfig(ctx, req) return err