Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .chloggen/fix-memorylimiter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. receiver/otlp)
component: extension/memory_limiter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add support for streaming services.

# One or more tracking issues or pull requests related to the change
issues: [14634]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
25 changes: 25 additions & 0 deletions .chloggen/fix-memorylimiter_interceptor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. receiver/otlp)
component: extension/memory_limiter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Use ChainUnaryInterceptor instead of UnaryInterceptor to allow multiple interceptors.

# One or more tracking issues or pull requests related to the change
issues: [14634]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: If multiple extensions that use the UnaryInterceptor are set the binary panics at start time.

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
24 changes: 16 additions & 8 deletions extension/memorylimiterextension/memorylimiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,20 @@ func (ml *memoryLimiterExtension) GetHTTPHandler(base http.Handler) (http.Handle
}

func (ml *memoryLimiterExtension) GetGRPCServerOptions() ([]grpc.ServerOption, error) {
return []grpc.ServerOption{grpc.UnaryInterceptor(
func(ctx context.Context, req any, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp any, err error) {
if ml.MustRefuse() {
return nil, status.Errorf(codes.ResourceExhausted, "RESOURCE_EXHAUSTED")
}
return handler(ctx, req)
},
)}, nil
return []grpc.ServerOption{
grpc.ChainUnaryInterceptor(
func(ctx context.Context, req any, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp any, err error) {
if ml.MustRefuse() {
return nil, status.Errorf(codes.ResourceExhausted, "RESOURCE_EXHAUSTED")
}
return handler(ctx, req)
}),
grpc.ChainStreamInterceptor(
Comment thread
bogdandrutu marked this conversation as resolved.
func(srv any, ss grpc.ServerStream, _ *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
if ml.MustRefuse() {
return status.Errorf(codes.ResourceExhausted, "RESOURCE_EXHAUSTED")
}
return handler(srv, ss)
}),
}, nil
}
Loading