MCPcopy
hub / github.com/grafana/dskit / DialOption

Method DialOption

grpcclient/grpcclient.go:125–196  ·  view source on GitHub ↗

DialOption returns the config as a grpc.DialOptions. The passed interceptors wrap around the configured middleware. It requires an InvalidClusterValidationReporter for reporting the cluster validation issues back to the caller, if cluster validation is enabled. If a nil InvalidClusterValidationRepor

(unaryClientInterceptors []grpc.UnaryClientInterceptor, streamClientInterceptors []grpc.StreamClientInterceptor, invalidClusterValidationReporter middleware.InvalidClusterValidationReporter)

Source from the content-addressed store, hash-verified

123// if cluster validation is enabled.
124// If a nil InvalidClusterValidationReporter is provided, a NoOpInvalidClusterValidationReporter is used.
125func (cfg *Config) DialOption(unaryClientInterceptors []grpc.UnaryClientInterceptor, streamClientInterceptors []grpc.StreamClientInterceptor, invalidClusterValidationReporter middleware.InvalidClusterValidationReporter) ([]grpc.DialOption, error) {
126 if invalidClusterValidationReporter == nil {
127 invalidClusterValidationReporter = middleware.NoOpInvalidClusterValidationReporter
128 }
129 var opts []grpc.DialOption
130 tlsOpts, err := cfg.TLS.GetGRPCDialOptions(cfg.TLSEnabled)
131 if err != nil {
132 return nil, err
133 }
134 opts = append(opts, tlsOpts...)
135
136 unaryClientInterceptors = append(unaryClientInterceptors, cfg.Middleware...)
137 streamClientInterceptors = append(streamClientInterceptors, cfg.StreamMiddleware...)
138
139 if cfg.BackoffOnRatelimits {
140 unaryClientInterceptors = append([]grpc.UnaryClientInterceptor{NewRateLimitRetrier(cfg.BackoffConfig)}, unaryClientInterceptors...)
141 }
142
143 if cfg.RateLimit > 0 {
144 unaryClientInterceptors = append([]grpc.UnaryClientInterceptor{NewRateLimiter(cfg)}, unaryClientInterceptors...)
145 }
146
147 // If cluster validation is enabled, ClusterUnaryClientInterceptor must be the last UnaryClientInterceptor
148 // to wrap the real call.
149 if cfg.ClusterValidation.Label != "" {
150 // For client side, we use the primary label as our cluster identity
151 cfg.clusterUnaryClientInterceptor = middleware.ClusterUnaryClientInterceptor(cfg.ClusterValidation.Label, invalidClusterValidationReporter)
152 unaryClientInterceptors = append(unaryClientInterceptors, cfg.clusterUnaryClientInterceptor)
153 }
154
155 if cfg.ConnectTimeout > 0 {
156 defaultCfg := grpcbackoff.DefaultConfig
157
158 if cfg.ConnectBackoffBaseDelay > 0 {
159 defaultCfg.BaseDelay = cfg.ConnectBackoffBaseDelay
160 }
161
162 if cfg.ConnectBackoffMaxDelay > 0 {
163 defaultCfg.MaxDelay = cfg.ConnectBackoffMaxDelay
164 }
165
166 opts = append(
167 opts,
168 grpc.WithConnectParams(grpc.ConnectParams{
169 Backoff: defaultCfg,
170 MinConnectTimeout: cfg.ConnectTimeout,
171 }),
172 )
173 }
174
175 if cfg.InitialStreamWindowSize > defaultInitialWindowSize {
176 // We only want to explicitly set the window size if it's not the default, as setting the window size (even to the default) always disables the BDP estimator.
177 opts = append(opts, grpc.WithInitialWindowSize(int32(cfg.InitialStreamWindowSize)))
178 }
179
180 if cfg.InitialConnectionWindowSize > defaultInitialWindowSize {
181 // We only want to explicitly set the window size if it's not the default, as setting the window size (even to the default) always disables the BDP estimator.
182 opts = append(opts, grpc.WithInitialConnWindowSize(int32(cfg.InitialConnectionWindowSize)))

Callers 1

Calls 5

CallOptionsMethod · 0.95
NewRateLimitRetrierFunction · 0.85
GetGRPCDialOptionsMethod · 0.80
NewRateLimiterFunction · 0.70

Tested by 1