vitess.io/vitess@v0.16.2/go/cmd/vtctldclient/command/throttler.go (about) 1 /* 2 Copyright 2022 The Vitess Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package command 18 19 import ( 20 "github.com/spf13/cobra" 21 22 "vitess.io/vitess/go/cmd/vtctldclient/cli" 23 24 vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata" 25 ) 26 27 var ( 28 // UpdateThrottlerConfig makes a UpdateThrottlerConfig gRPC call to a vtctld. 29 UpdateThrottlerConfig = &cobra.Command{ 30 Use: "UpdateThrottlerConfig [--enable|--disable] [--threshold=<float64>] [--custom-query=<query>] [--check-as-check-self|--check-as-check-shard] <keyspace>", 31 Short: "Update the tablet throttler configuration for all tablets in the given keyspace (across all cells)", 32 DisableFlagsInUseLine: true, 33 Args: cobra.ExactArgs(1), 34 RunE: commandUpdateThrottlerConfig, 35 } 36 ) 37 38 var updateThrottlerConfigOptions vtctldatapb.UpdateThrottlerConfigRequest 39 40 func commandUpdateThrottlerConfig(cmd *cobra.Command, args []string) error { 41 keyspace := cmd.Flags().Arg(0) 42 cli.FinishedParsing(cmd) 43 44 updateThrottlerConfigOptions.CustomQuerySet = cmd.Flags().Changed("custom-query") 45 updateThrottlerConfigOptions.Keyspace = keyspace 46 _, err := client.UpdateThrottlerConfig(commandCtx, &updateThrottlerConfigOptions) 47 if err != nil { 48 return err 49 } 50 return nil 51 } 52 53 func init() { 54 UpdateThrottlerConfig.Flags().BoolVar(&updateThrottlerConfigOptions.Enable, "enable", false, "Enable the throttler") 55 UpdateThrottlerConfig.Flags().BoolVar(&updateThrottlerConfigOptions.Disable, "disable", false, "Disable the throttler") 56 UpdateThrottlerConfig.Flags().Float64Var(&updateThrottlerConfigOptions.Threshold, "threshold", 0, "threshold for the either default check (replication lag seconds) or custom check") 57 UpdateThrottlerConfig.Flags().StringVar(&updateThrottlerConfigOptions.CustomQuery, "custom-query", "", "custom throttler check query") 58 UpdateThrottlerConfig.Flags().BoolVar(&updateThrottlerConfigOptions.CheckAsCheckSelf, "check-as-check-self", false, "/throttler/check requests behave as is /throttler/check-self was called") 59 UpdateThrottlerConfig.Flags().BoolVar(&updateThrottlerConfigOptions.CheckAsCheckShard, "check-as-check-shard", false, "use standard behavior for /throttler/check requests") 60 Root.AddCommand(UpdateThrottlerConfig) 61 }