vitess.io/vitess@v0.16.2/go/vt/grpccommon/options.go (about) 1 /* 2 Copyright 2019 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 grpccommon 18 19 import ( 20 "github.com/spf13/pflag" 21 "google.golang.org/grpc" 22 23 "vitess.io/vitess/go/stats" 24 ) 25 26 var ( 27 // maxMessageSize is the maximum message size which the gRPC server will 28 // accept. Larger messages will be rejected. 29 // Note: We're using 16 MiB as default value because that's the default in MySQL 30 maxMessageSize = 16 * 1024 * 1024 31 // enablePrometheus sets a flag to enable grpc client/server grpc monitoring. 32 enablePrometheus bool 33 ) 34 35 // RegisterFlags installs grpccommon flags on the given FlagSet. 36 // 37 // `go/cmd/*` entrypoints should either use servenv.ParseFlags(WithArgs)? which 38 // calls this function, or call this function directly before parsing 39 // command-line arguments. 40 func RegisterFlags(fs *pflag.FlagSet) { 41 fs.IntVar(&maxMessageSize, "grpc_max_message_size", maxMessageSize, "Maximum allowed RPC message size. Larger messages will be rejected by gRPC with the error 'exceeding the max size'.") 42 fs.BoolVar(&grpc.EnableTracing, "grpc_enable_tracing", grpc.EnableTracing, "Enable gRPC tracing.") 43 fs.BoolVar(&enablePrometheus, "grpc_prometheus", enablePrometheus, "Enable gRPC monitoring with Prometheus.") 44 } 45 46 // EnableGRPCPrometheus returns the value of the --grpc_prometheus flag. 47 func EnableGRPCPrometheus() bool { 48 return enablePrometheus 49 } 50 51 // MaxMessageSize returns the value of the --grpc_max_message_size flag. 52 func MaxMessageSize() int { 53 return maxMessageSize 54 } 55 56 func init() { 57 stats.NewString("GrpcVersion").Set(grpc.Version) 58 }