From 5b59d0c4ecabc992266c20cf36b9bdc3d1fe7e92 Mon Sep 17 00:00:00 2001 From: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> Date: Thu, 13 Jul 2023 16:16:00 +0300 Subject: [PATCH 1/5] support --unthrottle-app flag Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> --- go/cmd/vtctldclient/command/throttler.go | 12 +++++++++++- go/vt/vtctl/vtctl.go | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/go/cmd/vtctldclient/command/throttler.go b/go/cmd/vtctldclient/command/throttler.go index e26986832f6..453787505c6 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" @@ -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().Add(-time.Second)) + 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/vt/vtctl/vtctl.go b/go/vt/vtctl/vtctl.go index 8113e5856ba..fb94dbdc770 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] [--unthrottle-app=] [--throttle-app=] [--throttle-app-ratio=] [--throttle-app-duration=] ", help: "Update the table throttler configuration for all cells and tablets of a given keyspace", }, { @@ -3556,6 +3556,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)") @@ -3573,6 +3574,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") } @@ -3598,6 +3602,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().Add(-time.Second)), + } } _, err = wr.VtctldServer().UpdateThrottlerConfig(ctx, req) return err From 2d115bff7b5902f24f23829c6565d440a00ef05a Mon Sep 17 00:00:00 2001 From: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> Date: Thu, 13 Jul 2023 16:40:06 +0300 Subject: [PATCH 2/5] endtoend Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> --- go/test/endtoend/throttler/util.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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) From 2901c7e991de087965fbd605e21aeea321366bc9 Mon Sep 17 00:00:00 2001 From: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> Date: Thu, 13 Jul 2023 16:40:30 +0300 Subject: [PATCH 3/5] update usage; use zero time when unthrottling Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> --- go/cmd/vtctldclient/command/throttler.go | 4 ++-- go/vt/vtctl/vtctl.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go/cmd/vtctldclient/command/throttler.go b/go/cmd/vtctldclient/command/throttler.go index 453787505c6..98884039ef4 100644 --- a/go/cmd/vtctldclient/command/throttler.go +++ b/go/cmd/vtctldclient/command/throttler.go @@ -33,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] [--[un]throttle-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), @@ -63,7 +63,7 @@ func commandUpdateThrottlerConfig(cmd *cobra.Command, args []string) error { throttledAppRule.ExpiresAt = logutil.TimeToProto(time.Now().Add(throttledAppDuration)) updateThrottlerConfigOptions.ThrottledApp = &throttledAppRule } else if unthrottledAppRule.Name != "" { - unthrottledAppRule.ExpiresAt = logutil.TimeToProto(time.Now().Add(-time.Second)) + unthrottledAppRule.ExpiresAt = logutil.TimeToProto(time.Time{}) updateThrottlerConfigOptions.ThrottledApp = &unthrottledAppRule } diff --git a/go/vt/vtctl/vtctl.go b/go/vt/vtctl/vtctl.go index e98e232ced9..6ff046ca489 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] [--unthrottle-app=] [--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", }, { @@ -3605,7 +3605,7 @@ func commandUpdateThrottlerConfig(ctx context.Context, wr *wrangler.Wrangler, su req.ThrottledApp = &topodatapb.ThrottledAppRule{ Name: *unthrottledApp, Ratio: 0, - ExpiresAt: logutil.TimeToProto(time.Now().Add(-time.Second)), + ExpiresAt: logutil.TimeToProto(time.Time{}), } } _, err = wr.VtctldServer().UpdateThrottlerConfig(ctx, req) From beb9124b7e8cbc8bbd8f5665b1ca1657278a6885 Mon Sep 17 00:00:00 2001 From: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> Date: Thu, 13 Jul 2023 19:06:45 +0300 Subject: [PATCH 4/5] updating usage Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> --- go/cmd/vtctldclient/command/throttler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/cmd/vtctldclient/command/throttler.go b/go/cmd/vtctldclient/command/throttler.go index 98884039ef4..81480cf2ec8 100644 --- a/go/cmd/vtctldclient/command/throttler.go +++ b/go/cmd/vtctldclient/command/throttler.go @@ -33,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] [--[un]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), From fbf388b25d664395a73c89445727484f5e9c5d2e Mon Sep 17 00:00:00 2001 From: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> Date: Sun, 16 Jul 2023 12:38:12 +0300 Subject: [PATCH 5/5] using time.Now() instead of zero-time Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> --- go/cmd/vtctldclient/command/throttler.go | 2 +- go/vt/vtctl/vtctl.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/go/cmd/vtctldclient/command/throttler.go b/go/cmd/vtctldclient/command/throttler.go index 81480cf2ec8..84943cc9962 100644 --- a/go/cmd/vtctldclient/command/throttler.go +++ b/go/cmd/vtctldclient/command/throttler.go @@ -63,7 +63,7 @@ func commandUpdateThrottlerConfig(cmd *cobra.Command, args []string) error { throttledAppRule.ExpiresAt = logutil.TimeToProto(time.Now().Add(throttledAppDuration)) updateThrottlerConfigOptions.ThrottledApp = &throttledAppRule } else if unthrottledAppRule.Name != "" { - unthrottledAppRule.ExpiresAt = logutil.TimeToProto(time.Time{}) + unthrottledAppRule.ExpiresAt = logutil.TimeToProto(time.Now()) updateThrottlerConfigOptions.ThrottledApp = &unthrottledAppRule } diff --git a/go/vt/vtctl/vtctl.go b/go/vt/vtctl/vtctl.go index 6ff046ca489..d1f5e801388 100644 --- a/go/vt/vtctl/vtctl.go +++ b/go/vt/vtctl/vtctl.go @@ -3605,7 +3605,7 @@ func commandUpdateThrottlerConfig(ctx context.Context, wr *wrangler.Wrangler, su req.ThrottledApp = &topodatapb.ThrottledAppRule{ Name: *unthrottledApp, Ratio: 0, - ExpiresAt: logutil.TimeToProto(time.Time{}), + ExpiresAt: logutil.TimeToProto(time.Now()), } } _, err = wr.VtctldServer().UpdateThrottlerConfig(ctx, req)