Skip to content

Commit

Permalink
UpdateThrottlerConfig --unthrottle-app ... (#13494)
Browse files Browse the repository at this point in the history
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
  • Loading branch information
shlomi-noach authored Jul 31, 2023
1 parent 35da5dd commit e3ad55a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
14 changes: 12 additions & 2 deletions go/cmd/vtctldclient/command/throttler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package command

import (
"fmt"
"time"

"github.com/spf13/cobra"
Expand All @@ -32,7 +33,7 @@ import (
var (
// UpdateThrottlerConfig makes a UpdateThrottlerConfig gRPC call to a vtctld.
UpdateThrottlerConfig = &cobra.Command{
Use: "UpdateThrottlerConfig [--enable|--disable] [--threshold=<float64>] [--custom-query=<query>] [--check-as-check-self|--check-as-check-shard] [--throttle-app=<name>] [--throttle-app-ratio=<float, range [0..1]>] [--throttle-app-duration=<duration>] <keyspace>",
Use: "UpdateThrottlerConfig [--enable|--disable] [--threshold=<float64>] [--custom-query=<query>] [--check-as-check-self|--check-as-check-shard] [--throttle-app|unthrottle-app=<name>] [--throttle-app-ratio=<float, range [0..1]>] [--throttle-app-duration=<duration>] <keyspace>",
Short: "Update the tablet throttler configuration for all tablets in the given keyspace (across all cells)",
DisableFlagsInUseLine: true,
Args: cobra.ExactArgs(1),
Expand All @@ -43,19 +44,27 @@ var (
var (
updateThrottlerConfigOptions vtctldatapb.UpdateThrottlerConfigRequest
throttledAppRule topodatapb.ThrottledAppRule
unthrottledAppRule topodatapb.ThrottledAppRule
throttledAppDuration time.Duration
)

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)
Expand All @@ -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)")
Expand Down
7 changes: 3 additions & 4 deletions go/test/endtoend/throttler/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
12 changes: 11 additions & 1 deletion go/vt/vtctl/vtctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ var commands = []commandGroup{
{
name: "UpdateThrottlerConfig",
method: commandUpdateThrottlerConfig,
params: "[--enable|--disable] [--threshold=<float64>] [--custom-query=<query>] [--check-as-check-self|--check-as-check-shard] [--throttle-app=<name>] [--throttle-app-ratio=<float, range [0..1]>] [--throttle-app-duration=<duration>] <keyspace>",
params: "[--enable|--disable] [--threshold=<float64>] [--custom-query=<query>] [--check-as-check-self|--check-as-check-shard] [--throttle-app|unthrottle-app=<name>] [--throttle-app-ratio=<float, range [0..1]>] [--throttle-app-duration=<duration>] <keyspace>",
help: "Update the table throttler configuration for all cells and tablets of a given keyspace",
},
{
Expand Down Expand Up @@ -3567,6 +3567,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)")
Expand All @@ -3584,6 +3585,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")
}
Expand All @@ -3609,6 +3613,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
Expand Down

0 comments on commit e3ad55a

Please sign in to comment.