Skip to content

Commit e5b68cf

Browse files
committed
Make memorylimiter a GRPC interceptor
1 parent f7888f5 commit e5b68cf

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

extension/memorylimiterextension/memorylimiter.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import (
88
"net/http"
99

1010
"go.uber.org/zap"
11+
"google.golang.org/grpc"
12+
"google.golang.org/grpc/codes"
13+
"google.golang.org/grpc/status"
1114

1215
"go.opentelemetry.io/collector/component"
1316
"go.opentelemetry.io/collector/internal/memorylimiter"
@@ -49,3 +52,14 @@ func (ml *memoryLimiterExtension) GetHTTPHandler(base http.Handler) (http.Handle
4952
base.ServeHTTP(resp, req)
5053
}), nil
5154
}
55+
56+
func (ml *memoryLimiterExtension) GetGRPCServerOptions() ([]grpc.ServerOption, error) {
57+
return []grpc.ServerOption{grpc.UnaryInterceptor(
58+
func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp any, err error) {
59+
if ml.MustRefuse() {
60+
return nil, status.Errorf(codes.ResourceExhausted, "RESOURCE_EXHAUSTED")
61+
}
62+
return handler(ctx, req)
63+
},
64+
)}, nil
65+
}

0 commit comments

Comments
 (0)