Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rough sketch (draft 3) limiter extension and middleware #12700

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

jmacd
Copy link
Contributor

@jmacd jmacd commented Mar 22, 2025

Description

After prior drafts, summarized in #12603, with feedback from @bogdandrutu and @axw, I explored adding limiters via middleware structured as two separate configuration and two separate extensions.

This draft includes only the outline of 6 (six!) new modules, which piece together to support a variety of limiter and interceptor behaviors. While I am concerned about the scope of this (#9591, #7441), this appears to be a good direction:

  • config/configlimiter: this names a limiter extension
  • config/configmiddleware: this names a middleware extension
  • extension/extensionlimiter: this has resource-limiters and rate-limiters
  • extension/extensionmiddleware: this has HTTP and gRPC, unary and stream, plus gRPC stats handlers
  • extension/limitermiddlewareextension: this shows how to turn a limiter into a middleware extension (in all the ways)
  • extension/ratelimiterextension: this is an example token bucket rate limiter

There are implied changes here as well as TODOs:

  • stats handlers vs gRPC interceptors: this is somewhat confusing, needs more clarity or separation
  • limtermiddlewareextension: HTTP network-bytes limiting TODO
  • config/confighttp: would add a list of middlewares, configure them automatically
  • config/configgrpc: would add a list of middlewares, configure them automatically
  • otelgrpc instrumentation can be turned into a middleware extension (at this point)
  • memorylimiterextension: would implement the new limiter interface
  • otlpreceiver: add support for resource limiting

Link to tracking issue

Part of #9591 #7441 #12603

Testing

NONE: for discussion

Documentation

NONE: TODO

jmacd added 9 commits March 20, 2025 13:03
…missed a form of gRPC interceptor. For both client and server gRPC cases in the middleware extension API, introduce a method to obtain a stats handler. ClientStatsHandler() and ServerStatsHandler() methods will be added, returning (grpc.StatsHandler, error).

In limitermiddleware, add support for the two new methods. Implement the StatsHandler interface with empty methods for now.

The type is named stats.Handler, package documented https://pkg.go.dev/google.golang.org/[email protected]/stats#Handler
Copy link
Member

@bogdandrutu bogdandrutu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed extensionmiddleware and extensionlimiter:

  • I have very few comments that we can discuss about;
  • We should merge these asap; matches exactly with what I expected to see.
  • Next on my list will be the configs then the convertors.

Comment on lines +27 to +28
// ClientStatsHandler returns a gRPC stats handler for client-side operations.
ClientStatsHandler() (stats.Handler, error)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this should be part of the GRPCClient or different GRPCStatsClient?

Comment on lines +20 to +21
// Key identifies the type of weight being limited
Key string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use an enum here instead?

//
// On success, it returns a ReleaseFunc that should be called
// when the resources are no longer needed.
Acquire(ctx context.Context, weights []Weight) (ReleaseFunc, error)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand the need of a slice of weights vs just one.

Comment on lines +27 to +28
// ServerStatsHandler returns a gRPC stats handler for server-side operations.
ServerStatsHandler() (stats.Handler, error)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question as for client, not sure if this should be here or a separate interface. Idea is that in general you either have implementations for the 2 interceptors or for the stats handler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants