Skip to content

network filters: add tcp bandwidth limit#42996

Open
AntonKanug wants to merge 4 commits intoenvoyproxy:mainfrom
AntonKanug:antonk/tcp-bandwidth
Open

network filters: add tcp bandwidth limit#42996
AntonKanug wants to merge 4 commits intoenvoyproxy:mainfrom
AntonKanug:antonk/tcp-bandwidth

Conversation

@AntonKanug
Copy link
Contributor

@AntonKanug AntonKanug commented Jan 13, 2026

Fixes #26754

Commit Message: network filters: add tcp bandwidth limit
Additional Description:
Risk Level:
Testing:
Docs Changes:
Release Notes:
Platform Specific Features:

@repokitteh-read-only
Copy link

As a reminder, PRs marked as draft will not be automatically assigned reviewers,
or be handled by maintainer-oncall triage.

Please mark your PR as ready when you want it to be reviewed!

🐱

Caused by: #42996 was opened by AntonKanug.

see: more, trace.

@repokitteh-read-only
Copy link

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to (api/envoy/|docs/root/api-docs/).
envoyproxy/api-shepherds assignee is @markdroth
CC @envoyproxy/api-watchers: FYI only for changes made to (api/envoy/|docs/root/api-docs/).

🐱

Caused by: #42996 was opened by AntonKanug.

see: more, trace.

@AntonKanug AntonKanug force-pushed the antonk/tcp-bandwidth branch 6 times, most recently from 185fc45 to 10215ba Compare January 14, 2026 00:22
@AntonKanug
Copy link
Contributor Author

/coverage

@repokitteh-read-only
Copy link

Coverage for this Pull Request will be rendered here:

https://storage.googleapis.com/envoy-cncf-pr/42996/coverage/index.html

For comparison, current coverage on main branch is here:

https://storage.googleapis.com/envoy-cncf-postsubmit/main/coverage/index.html

The coverage results are (re-)rendered each time the CI Envoy/Checks (coverage) job completes.

🐱

Caused by: a #42996 (comment) was created by @AntonKanug.

see: more, trace.

@AntonKanug AntonKanug force-pushed the antonk/tcp-bandwidth branch 8 times, most recently from 9527d53 to 8b858b4 Compare January 14, 2026 22:52
@AntonKanug AntonKanug marked this pull request as ready for review January 15, 2026 00:10
@AntonKanug AntonKanug force-pushed the antonk/tcp-bandwidth branch 2 times, most recently from 15062e0 to 449992c Compare January 15, 2026 11:01
CODEOWNERS Outdated
/*/extensions/retry/priority/previous_priorities @ravenblackx @mattklein123
/*/extensions/retry/host @ravenblackx @mattklein123
/*/extensions/filters/network/http_connection_manager @yanavlasov @mattklein123
/*/extensions/filters/network/tcp_bandwidth_limit @UNOWNED @UNOWNED
Copy link
Member

@tyxia tyxia Jan 18, 2026

Choose a reason for hiding this comment

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

@AntonKanug Thanks for your contribution!

We will need owner here as well as maintainer sponsorship.

cc HTTP bandwith_limit owners @nitgoy @mattklein123 @yanavlasov @tonya11en for inputs

Copy link
Member

@agrawroh agrawroh Jan 22, 2026

Choose a reason for hiding this comment

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

@AntonKanug Did you consider using Dynamic Modules for this use-case instead?

cc @wbpcode as well. I think these use-cases could be easily built on top of Dynamic Modules now and we should have a discussion to come up with a policy on new CPP extensions as they do add some maintenance burden on the maintainers.

Copy link
Member

Choose a reason for hiding this comment

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

cc @ggreenway (who may be interested to sponsor this extension)

Copy link
Contributor

Choose a reason for hiding this comment

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

I can sponsor this filter.

Copy link
Member

Choose a reason for hiding this comment

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

@AntonKanug please add @yanavlasov and @nezdolik and yourself as code owners. But next time before starting to write the code for new extension you should first find sponsors (among maintainers). Envoy extension policy: https://github.com/envoyproxy/envoy/blob/main/EXTENSION_POLICY.md

@KBaichoo
Copy link
Contributor

KBaichoo commented Feb 6, 2026

/wait-any

This seems to be pending either finding a maintainer to sponsor or authoring this as a dynamic module.

@yanavlasov yanavlasov self-assigned this Feb 10, 2026
@nezdolik nezdolik self-assigned this Feb 16, 2026

The filter supports the following configuration options:

* **download_limit_kbps**: The limit for download bandwidth in KiB/s (kibibytes per second).
Copy link
Member

Choose a reason for hiding this comment

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

this section is repetitive with what we already have in api proto file (api/envoy/extensions/filters/network/tcp_bandwidth_limit/v3/tcp_bandwidth_limit.proto). Could you move the missing information there?

: runtime_(runtime), time_source_(time_source),
has_download_limit_(config.has_download_limit_kbps()),
has_upload_limit_(config.has_upload_limit_kbps()),
download_limit_kbps_(PROTOBUF_GET_WRAPPED_OR_DEFAULT(config, download_limit_kbps, 0)),
Copy link
Member

Choose a reason for hiding this comment

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

you could get rid of 2 boolean fields has_download_limit_, has_upload_limit_ and instead initialize relevant fields like this:

download_token_bucket_(config.has_download_limit_kbps() ? std::make_shared<SharedTokenBucketImpl>(
        limit_bytes_per_sec, time_source_, static_cast<double>(kiloBytesToBytes(download_limit_kbps_))) : nullptr)

Buffer::OwnedImpl upload_buffer_;

// Timers for processing buffered data
Event::TimerPtr download_timer_;
Copy link
Member

Choose a reason for hiding this comment

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

in filter destructor you will need to disable the timers like so (to avoid any race conditions when filter is being destroyed and timer gets invoked on half destroyed object):

   if (download_timer_) {
      download_timer_->disableTimer();
      download_timer_.reset();
}

Network::WriteFilterCallbacks* write_callbacks_{};

// Buffered data waiting for tokens
Buffer::OwnedImpl download_buffer_;
Copy link
Member

Choose a reason for hiding this comment

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

i think we want to use watermark buffer (Buffer::WatermarkBuffer) here?

@markdroth
Copy link
Contributor

/lgtm api

Copy link
Contributor

@yanavlasov yanavlasov left a comment

Choose a reason for hiding this comment

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

Looks good. Would you be able to also add an integration test, that tests this filter in a complete Envoy setup, please? It does not need to be complicated, maybe just two tests for upload and download.

/wait-any

@AntonKanug
Copy link
Contributor Author

AntonKanug commented Feb 19, 2026

@yanavlasov @nezdolik ready for review, addressed the comments and added integrations tests.

precheck is failing but its failing with same error on main as well, tests are passing locally (edit: rebased with the fix)

Signed-off-by: Anton Kanugalawattage <antondilon@gmail.com>
Signed-off-by: Anton Kanugalawattage <antondilon@gmail.com>
Signed-off-by: Anton Kanugalawattage <antondilon@gmail.com>
Signed-off-by: Anton Kanugalawattage <antondilon@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TCP bandwidth limit

7 participants

Comments