Skip to content

Conversation

@shivanthzen
Copy link

@shivanthzen shivanthzen commented Oct 23, 2025

Description

This PR augments the memorylimiter extension to be an HTTP/GRPC middleware. The extension can be used as an HTTP/GRPC middleware once this is merged.
Example:

receivers:
  otlp:
    protocols:
      grpc:
        middlewares:
          - id: memory_limiter
      http:
        middlewares:
          - id: memory_limiter

extensions:
  memory_limiter:
    check_interval: 1s
    limit_percentage: 1
    spike_limit_percentage: 0.05

..........

Link to tracking issue

Fixes #9591
Fixes #14081

Testing

Setup a minimal collector to test that the middleware is indeed ratelimiting while the memory usage is closer to limit.

receivers:
  otlp:
    protocols:
      grpc:
        middlewares:
          - id: memory_limiter
      http:
        middlewares:
          - id: memory_limiter
processors:
exporters:
  debug:
    verbosity: detailed
    sampling_initial: 5
    sampling_thereafter: 200
    use_internal_logger: false

extensions:
  memory_limiter:
    check_interval: 1s
    limit_percentage: 1 # this is the minimum possible, since it's an integer. 
    spike_limit_percentage: 0.05

service:
  extensions:
    - memory_limiter
  pipelines:
    metrics:
      receivers: [otlp]
      processors: []
      exporters: [debug]
    traces:
      receivers: [otlp]
      processors: []
      exporters: [debug]
    logs:
      receivers: [otlp]
      processors: []
      exporters: [debug]
  telemetry:
    logs:
      level: debug
      development: false
      disable_caller: false
      disable_stacktrace: false

Documentation

Updated the readme for memory limiter extension.

@shivanthzen shivanthzen changed the title make memory limiter extension a middleware make memory limiter extension an http middleware Oct 23, 2025
@shivanthzen shivanthzen force-pushed the memorylimiter_middleware branch from d296af7 to e5b68cf Compare October 24, 2025 14:27
@shivanthzen shivanthzen changed the title make memory limiter extension an http middleware MemoryLimter extension as an http/grpc middleware Oct 24, 2025
@jmacd
Copy link
Contributor

jmacd commented Oct 27, 2025

@shivanthzen Thank you. This looks like a good step forward. Can we add to the memorylimiter extension README.md with an example for use? Would you add a minimal test, at least to be sure that the extension implements the middleware interface? I am not sure what internal support memorylimiter has for testing, but it would be nice to have a small test for the function itself.

@shivanthzen shivanthzen marked this pull request as ready for review November 10, 2025 12:50
@shivanthzen shivanthzen requested a review from a team as a code owner November 10, 2025 12:50
@shivanthzen shivanthzen requested a review from axw November 10, 2025 12:50
@dmathieu dmathieu changed the title MemoryLimter extension as an http/grpc middleware MemoryLimiter extension as an http/grpc middleware Nov 10, 2025
Copy link
Member

@songy23 songy23 left a comment

Choose a reason for hiding this comment

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

Needs make gotidy

auto-merge was automatically disabled November 11, 2025 10:16

Head branch was pushed to by a user without write access

@codecov
Copy link

codecov bot commented Nov 11, 2025

Codecov Report

❌ Patch coverage is 0% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.20%. Comparing base (a9691ee) to head (c6b0b9b).

Files with missing lines Patch % Lines
extension/memorylimiterextension/memorylimiter.go 0.00% 12 Missing ⚠️

❌ Your patch check has failed because the patch coverage (0.00%) is below the target coverage (95.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14071      +/-   ##
==========================================
- Coverage   92.24%   92.20%   -0.04%     
==========================================
  Files         658      658              
  Lines       41168    41180      +12     
==========================================
- Hits        37977    37972       -5     
- Misses       2184     2199      +15     
- Partials     1007     1009       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

}
}

func TestMiddleware(t *testing.T) {
Copy link
Contributor

@evan-bradley evan-bradley Nov 20, 2025

Choose a reason for hiding this comment

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

Instead of having a test for this, could we use the type checker to assert interface implementation?

You could put the following above line 19 in memorylimiter.go for example:

var _ extensionmiddleware.GRPCServer = (*memoryLimiterExtension)(nil)
var _ extensionmiddleware.HTTPServer = (*memoryLimiterExtension)(nil)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make MemoryLimiter Extension an http/grpc middleware Applying memory_limiter extension

8 participants