Repository navigation
feat(router): support different throttler per event type - #6181
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #6181 +/- ##
==========================================
+ Coverage 76.53% 76.70% +0.16%
==========================================
Files 514 520 +6
Lines 70682 70891 +209
==========================================
+ Hits 54099 54377 +278
+ Misses 13680 13622 -58
+ Partials 2903 2892 -11 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
e26c760 to
115c12b
Compare
There was a problem hiding this comment.
Why is there a cache for allEventsAlgorithm and not for perEventAlgorithm?
There was a problem hiding this comment.
For 1 destination we are going to create N throttlers, where N the number of event types.
In case of the allEventsAlgorithm, all N throttlers need to share the same algorithm implementation, i.e. gather 429 statistics for all event types and adjust throttling factor globally. This doesn't stand true for perEventAlgorithm where each throttler needs to have its own algorithm.
hint: even though we're creating different throttlers per event type, each throttler will be using the same limiter, but, will be trying to limit based on the same (all events) or different (per event) throttling keys per case.
There was a problem hiding this comment.
understood:
for destination d1 and eventType throttling disabled
we get event with type t1
we will check f.throttlers["d1:t1"] it is not present in the map
we create a algo for d1 and cache it in f.allEventTypesAlgos["d1"]
next time an event with type t2 and destination d1 comes we will check f.throttlers["d1:t2"]
it will not be present in the map and we will check for algo in f.allEventTypesAlgos["d1"] it will be there we will use it
There was a problem hiding this comment.
Yes. So for this example, we are going to have:
- 2 throttlers for d1, one for t1 & another for t2
- Both throttlers share the same algorithm
- Both throttlers are using the same throttling key, effectively applying the same rate limit for jobs of destination d1 regardless of the event type
115c12b to
f56a9b7
Compare
There was a problem hiding this comment.
where are we using eventType? is this only for tests?
There was a problem hiding this comment.
yes not really needed
55d2980 to
b785100
Compare
b785100 to
7144f66
Compare
| anotherDestID := "dest789" | ||
|
|
||
| // No specific config for dest789 or destination type, should use global config | ||
| c.Set("Router.throttler.throttlerPerEventType", true) |
There was a problem hiding this comment.
[nitpick] we're sharing a conf here, not great for test isolation. it's ok for now since there is no need to run these in parallel but I think tests should be designed with complete isolation in mind in the first place.
| wh.Server = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| body, err := io.ReadAll(r.Body) | ||
| require.NoError(t, err, "should be able to read the request body") | ||
| typeResult := gjson.GetBytes(body, "type") |
There was a problem hiding this comment.
We can start using the kit jsonparser. Once it's used everywhere we can even have rules to enforce it like we did for jsonrs.
There was a problem hiding this comment.
using jsonparser, but not in test since it is convenient to use gjson here
f61f87a to
46c9f3d
Compare
# Description Our only means of disabling throttling for a destination type or destination id is by setting the limit or window to zero. Thus it makes no sense to emit a warning log in case some throttler is disabled. Renamed `validConfiguration` to `enabled` to avoid any confusion in the future. Regression introduced by #6181 ## Security - [x] The code changed/added as part of this pull request won't create any security issues with how the software is being used.
🤖 I have created a release *beep* *boop* --- ## [1.57.0-rc.1](v1.56.0...v1.57.0-rc.1) (2025-08-18) ### Features * add support for manual sync mode in warehouse ([#6199](#6199)) ([6f87119](6f87119)) * **router:** support different throttler per event type ([#6181](#6181)) ([12254bb](12254bb)) * warehouse grpc API to get namespace mappings of a destination ([#6200](#6200)) ([9613236](9613236)) ### Bug Fixes * adaptive throttling not applying dynamic throttling limits consistently ([#6219](#6219)) ([478b2e1](478b2e1)) * error extractor to handle nested JSON responses ([#6209](#6209)) ([ffc0d7a](ffc0d7a)) * getting occasional unauthenticated errors from googlepubsub ([#6228](#6228)) ([cc39306](cc39306)) * handle snowpipe service restarts in destination polling logic ([#6236](#6236)) ([b76bc7f](b76bc7f)) * handling empty schema for table level schemas ([#6233](#6233)) ([cc39306](cc39306)) * histogram buckets for schema snapshots ([#6234](#6234)) ([cc39306](cc39306)) * warehouse source empty jobs ([#6204](#6204)) ([42f5ae4](42f5ae4)) ### Miscellaneous * bump the go-dependencies group with 12 updates ([#6189](#6189)) ([e6e2bcd](e6e2bcd)) * enforcing non-sugared logger ([#6066](#6066)) ([b24ded8](b24ded8)) * force new MTU metrics from 1st September 2025 onwards ([#6227](#6227)) ([154d2c3](154d2c3)) * implement configurable deduplication mirror mode ([#6224](#6224)) ([c97ad7a](c97ad7a)) * refactor Google Pub/Sub to add retry logic for auth errors ([#6229](#6229)) ([cc39306](cc39306)) * remove enableV2NotifierJob flag support ([#6196](#6196)) ([8be54bf](8be54bf)) * remove event blocking flag ([#6240](#6240)) ([e668e14](e668e14)) * remove queryWithUploadId flag support for load files ([#6192](#6192)) ([e6e2bcd](e6e2bcd)) * revert "fix: snowpipe events getting duplicated if status API fails" ([#6211](#6211)) ([777b08e](777b08e)) * skip warehouse destinations from version deprecation error extraction ([#6226](#6226)) ([87c3320](87c3320)) * stop collecting errors in proc_error jobsdb ([#6232](#6232)) ([c600968](c600968)) * throttler should emit no warning if not enabled ([#6223](#6223)) ([0773168](0773168)) * update keydb dependency ([#6222](#6222)) ([d1d64bc](d1d64bc)) * use harbor to pull docker images ([#6210](#6210)) ([6c324cf](6c324cf)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
🤖 I have created a release *beep* *boop* --- ## [1.57.0-rc.2](v1.56.0...v1.57.0-rc.2) (2025-08-19) ### Features * add support for manual sync mode in warehouse ([#6199](#6199)) ([6f87119](6f87119)) * enable oauthV2 by removing oauthV2enabled variable ([#6175](#6175)) ([caad8f0](caad8f0)) * **router:** support different throttler per event type ([#6181](#6181)) ([12254bb](12254bb)) * warehouse grpc API to get namespace mappings of a destination ([#6200](#6200)) ([9613236](9613236)) ### Bug Fixes * adaptive throttling not applying dynamic throttling limits consistently ([#6219](#6219)) ([478b2e1](478b2e1)) * error extractor to handle nested JSON responses ([#6209](#6209)) ([ffc0d7a](ffc0d7a)) * getting occasional unauthenticated errors from googlepubsub ([#6228](#6228)) ([cc39306](cc39306)) * handle snowpipe service restarts in destination polling logic ([#6236](#6236)) ([b76bc7f](b76bc7f)) * handling empty schema for table level schemas ([#6233](#6233)) ([cc39306](cc39306)) * histogram buckets for schema snapshots ([#6234](#6234)) ([cc39306](cc39306)) * warehouse source empty jobs ([#6204](#6204)) ([42f5ae4](42f5ae4)) ### Miscellaneous * bump the go-dependencies group with 12 updates ([#6189](#6189)) ([e6e2bcd](e6e2bcd)) * enforcing non-sugared logger ([#6066](#6066)) ([b24ded8](b24ded8)) * force new MTU metrics from 1st September 2025 onwards ([#6227](#6227)) ([154d2c3](154d2c3)) * implement configurable deduplication mirror mode ([#6224](#6224)) ([c97ad7a](c97ad7a)) * refactor Google Pub/Sub to add retry logic for auth errors ([#6229](#6229)) ([cc39306](cc39306)) * remove enableV2NotifierJob flag support ([#6196](#6196)) ([8be54bf](8be54bf)) * remove event blocking flag ([#6240](#6240)) ([e668e14](e668e14)) * remove queryWithUploadId flag support for load files ([#6192](#6192)) ([e6e2bcd](e6e2bcd)) * revert "fix: snowpipe events getting duplicated if status API fails" ([#6211](#6211)) ([777b08e](777b08e)) * skip warehouse destinations from version deprecation error extraction ([#6226](#6226)) ([87c3320](87c3320)) * stop collecting errors in proc_error jobsdb ([#6232](#6232)) ([c600968](c600968)) * throttler should emit no warning if not enabled ([#6223](#6223)) ([0773168](0773168)) * update keydb dependency ([#6222](#6222)) ([d1d64bc](d1d64bc)) * use harbor to pull docker images ([#6210](#6210)) ([6c324cf](6c324cf)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
🤖 I have created a release *beep* *boop* --- ## [1.57.0](v1.56.0...v1.57.0) (2025-08-19) ### Features * add support for manual sync mode in warehouse ([#6199](#6199)) ([6f87119](6f87119)) * enable oauthV2 by removing oauthV2enabled variable ([#6175](#6175)) ([caad8f0](caad8f0)) * **router:** support different throttler per event type ([#6181](#6181)) ([12254bb](12254bb)) * warehouse grpc API to get namespace mappings of a destination ([#6200](#6200)) ([9613236](9613236)) ### Bug Fixes * adaptive throttling not applying dynamic throttling limits consistently ([#6219](#6219)) ([478b2e1](478b2e1)) * error extractor to handle nested JSON responses ([#6209](#6209)) ([ffc0d7a](ffc0d7a)) * getting occasional unauthenticated errors from googlepubsub ([#6228](#6228)) ([cc39306](cc39306)) * handle snowpipe service restarts in destination polling logic ([#6236](#6236)) ([b76bc7f](b76bc7f)) * handling empty schema for table level schemas ([#6233](#6233)) ([cc39306](cc39306)) * histogram buckets for schema snapshots ([#6234](#6234)) ([cc39306](cc39306)) * warehouse source empty jobs ([#6204](#6204)) ([42f5ae4](42f5ae4)) ### Miscellaneous * bump the go-dependencies group with 12 updates ([#6189](#6189)) ([e6e2bcd](e6e2bcd)) * enforcing non-sugared logger ([#6066](#6066)) ([b24ded8](b24ded8)) * force new MTU metrics from 1st September 2025 onwards ([#6227](#6227)) ([154d2c3](154d2c3)) * implement configurable deduplication mirror mode ([#6224](#6224)) ([c97ad7a](c97ad7a)) * refactor Google Pub/Sub to add retry logic for auth errors ([#6229](#6229)) ([cc39306](cc39306)) * remove enableV2NotifierJob flag support ([#6196](#6196)) ([8be54bf](8be54bf)) * remove event blocking flag ([#6240](#6240)) ([e668e14](e668e14)) * remove queryWithUploadId flag support for load files ([#6192](#6192)) ([e6e2bcd](e6e2bcd)) * revert "fix: snowpipe events getting duplicated if status API fails" ([#6211](#6211)) ([777b08e](777b08e)) * skip warehouse destinations from version deprecation error extraction ([#6226](#6226)) ([87c3320](87c3320)) * stop collecting errors in proc_error jobsdb ([#6232](#6232)) ([c600968](c600968)) * throttler should emit no warning if not enabled ([#6223](#6223)) ([0773168](0773168)) * update keydb dependency ([#6222](#6222)) ([d1d64bc](d1d64bc)) * use harbor to pull docker images ([#6210](#6210)) ([6c324cf](6c324cf)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Description
The router can now assign a different throttler—either static or adaptive—to each event type for a given destination, and dynamically switch between throttler configurations at runtime. This enables the system to adjust throttling rates per event type as needed.
When throttling is applied per event type, the router no longer stops iterating over fetched jobs as soon as one is discarded due to throttling. Instead, it continues scanning the pre-fetched jobs, looking for others with higher throttling rates. While it avoids fetching more jobs from the database, it fully processes the current batch to maximize throughput across event types.
Configuration
Enabling/disabling throttlerPerEventType:
Router.throttler.<destType>.<destinationID>.throttlerPerEventTypeoverrides at destination id levelRouter.throttler.<destType>.throttlerPerEventTypeoverrides at destination type levelRouter.throttler.throttlerPerEventTypeglobal configuration for all destination typesSetting different limits per event type:
Other improvements
throttlerpackage for proper separation of concerns, reusability and comprehensive testingLinear Ticket
resolves PIPE-2094
Security