Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UpdateThrottlerConfig --unthrottle-app ... #13494

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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] [--[un]throttle-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.Time{})
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 @@ -702,7 +702,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>",
mattlord marked this conversation as resolved.
Show resolved Hide resolved
help: "Update the table throttler configuration for all cells and tablets of a given keyspace",
},
{
Expand Down Expand Up @@ -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)")
Expand All @@ -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")
}
Expand All @@ -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.Time{}),
}
}
_, err = wr.VtctldServer().UpdateThrottlerConfig(ctx, req)
return err
Expand Down