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

Function ClusterUnaryServerInterceptor

middleware/grpc_cluster.go:76–90  ·  view source on GitHub ↗

ClusterUnaryServerInterceptor checks if the incoming gRPC metadata contains any cluster label and if so, checks if the latter corresponds to one of the given cluster labels. If it is the case, the request is further propagated. If empty cluster labels or nil logger are provided, ClusterUnaryServerIn

(clusters []string, softValidation bool, invalidClusterRequests *prometheus.CounterVec, logger log.Logger)

Source from the content-addressed store, hash-verified

74// If the softValidation parameter is true, errors related to the cluster label validation are logged, but not returned.
75// Otherwise, an error is returned.
76func ClusterUnaryServerInterceptor(clusters []string, softValidation bool, invalidClusterRequests *prometheus.CounterVec, logger log.Logger) grpc.UnaryServerInterceptor {
77 validateClusterServerInterceptorInputParameters(clusters, logger)
78 return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
79 // We skip the gRPC health check.
80 if _, ok := info.Server.(healthpb.HealthServer); ok {
81 return handler(ctx, req)
82 }
83
84 if err := checkClusterFromIncomingContext(ctx, info.FullMethod, clusters, softValidation, invalidClusterRequests, logger); err != nil {
85 stat := grpcutil.Status(codes.FailedPrecondition, err.Error(), &grpcutil.ErrorDetails{Cause: grpcutil.WRONG_CLUSTER_VALIDATION_LABEL})
86 return nil, stat.Err()
87 }
88 return handler(ctx, req)
89 }
90}
91
92func validateClusterServerInterceptorInputParameters(clusters []string, logger log.Logger) {
93 if len(clusters) == 0 {

Calls 5

StatusFunction · 0.92
ErrorMethod · 0.45
ErrMethod · 0.45