-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
receive: use grpc to forward remote write requests
Signed-off-by: Brett Jones <[email protected]>
- Loading branch information
Showing
11 changed files
with
848 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package extgrpc | ||
|
||
import ( | ||
"math" | ||
|
||
"github.com/go-kit/kit/log" | ||
"github.com/go-kit/kit/log/level" | ||
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware" | ||
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus" | ||
opentracing "github.com/opentracing/opentracing-go" | ||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/thanos-io/thanos/pkg/tls" | ||
"github.com/thanos-io/thanos/pkg/tracing" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/credentials" | ||
) | ||
|
||
// StoreClientGRPCOpts creates gRPC dial options for connecting to a store client. | ||
func StoreClientGRPCOpts(logger log.Logger, reg *prometheus.Registry, tracer opentracing.Tracer, secure bool, cert, key, caCert, serverName string) ([]grpc.DialOption, error) { | ||
grpcMets := grpc_prometheus.NewClientMetrics() | ||
grpcMets.EnableClientHandlingTimeHistogram( | ||
grpc_prometheus.WithHistogramBuckets([]float64{0.001, 0.01, 0.1, 0.3, 0.6, 1, 3, 6, 9, 20, 30, 60, 90, 120}), | ||
) | ||
dialOpts := []grpc.DialOption{ | ||
// We want to make sure that we can receive huge gRPC messages from storeAPI. | ||
// On TCP level we can be fine, but the gRPC overhead for huge messages could be significant. | ||
// Current limit is ~2GB. | ||
// TODO(bplotka): Split sent chunks on store node per max 4MB chunks if needed. | ||
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(math.MaxInt32)), | ||
grpc.WithUnaryInterceptor( | ||
grpc_middleware.ChainUnaryClient( | ||
grpcMets.UnaryClientInterceptor(), | ||
tracing.UnaryClientInterceptor(tracer), | ||
), | ||
), | ||
grpc.WithStreamInterceptor( | ||
grpc_middleware.ChainStreamClient( | ||
grpcMets.StreamClientInterceptor(), | ||
tracing.StreamClientInterceptor(tracer), | ||
), | ||
), | ||
} | ||
|
||
if reg != nil { | ||
reg.MustRegister(grpcMets) | ||
} | ||
|
||
if !secure { | ||
return append(dialOpts, grpc.WithInsecure()), nil | ||
} | ||
|
||
level.Info(logger).Log("msg", "enabling client to server TLS") | ||
|
||
tlsCfg, err := tls.NewClientConfig(logger, cert, key, caCert, serverName) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return append(dialOpts, grpc.WithTransportCredentials(credentials.NewTLS(tlsCfg))), nil | ||
} |
Oops, something went wrong.