Skip to content

Commit

Permalink
fix: adding throttling stats in router (#2923)
Browse files Browse the repository at this point in the history
  • Loading branch information
fracasula committed Feb 1, 2023
1 parent ba270c2 commit 6de8862
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
2 changes: 1 addition & 1 deletion config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Router:
MARKETO:
noOfWorkers: 4
throttler:
algorithm: gorate
algorithm: gcra
# redis:
# addr: localhost:6379
# username: ""
Expand Down
32 changes: 13 additions & 19 deletions router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ type HandleT struct {
routerTransformOutputCountStat stats.Measurement
batchInputOutputDiffCountStat stats.Measurement
routerResponseTransformStat stats.Measurement
throttlingErrorStat stats.Measurement
throttledStat stats.Measurement
noOfWorkers int
allowAbortedUserJobsCountForProcessing int
isBackendConfigInitialized bool
Expand Down Expand Up @@ -1282,11 +1284,13 @@ func (rt *HandleT) shouldThrottle(job *jobsdb.JobT, parameters JobParametersT, t
limited, err := throttler.CheckLimitReached(parameters.DestinationID, throttlingCost)
if err != nil {
// we can't throttle, let's hit the destination, worst case we get a 429
rt.throttlingErrorStat.Count(1)
rt.logger.Errorf(`[%v Router] :: Throttler error: %v`, rt.destName, err)
return false
}
if limited {
throttledUserMap[job.UserID] = struct{}{}
rt.throttledStat.Count(1)
rt.logger.Debugf(
"[%v Router] :: Skipping processing of job:%d of user:%s as throttled limits exceeded",
rt.destName, job.JobID, job.UserID,
Expand Down Expand Up @@ -1863,25 +1867,15 @@ func (rt *HandleT) Setup(backendConfig backendconfig.BackendConfig, jobsDB jobsd
// END: Alert configuration
rt.allowAbortedUserJobsCountForProcessing = getRouterConfigInt("allowAbortedUserJobsCountForProcessing", destName, 1)

rt.batchInputCountStat = stats.Default.NewTaggedStat("router_batch_num_input_jobs", stats.CountType, stats.Tags{
"destType": rt.destName,
})
rt.batchOutputCountStat = stats.Default.NewTaggedStat("router_batch_num_output_jobs", stats.CountType, stats.Tags{
"destType": rt.destName,
})

rt.routerTransformInputCountStat = stats.Default.NewTaggedStat("router_transform_num_input_jobs", stats.CountType, stats.Tags{
"destType": rt.destName,
})
rt.routerTransformOutputCountStat = stats.Default.NewTaggedStat("router_transform_num_output_jobs", stats.CountType, stats.Tags{
"destType": rt.destName,
})

rt.batchInputOutputDiffCountStat = stats.Default.NewTaggedStat("router_batch_input_output_diff_jobs", stats.CountType, stats.Tags{
"destType": rt.destName,
})

rt.routerResponseTransformStat = stats.Default.NewTaggedStat("response_transform_latency", stats.TimerType, stats.Tags{"destType": rt.destName})
statTags := stats.Tags{"destType": rt.destName}
rt.batchInputCountStat = stats.Default.NewTaggedStat("router_batch_num_input_jobs", stats.CountType, statTags)
rt.batchOutputCountStat = stats.Default.NewTaggedStat("router_batch_num_output_jobs", stats.CountType, statTags)
rt.routerTransformInputCountStat = stats.Default.NewTaggedStat("router_transform_num_input_jobs", stats.CountType, statTags)
rt.routerTransformOutputCountStat = stats.Default.NewTaggedStat("router_transform_num_output_jobs", stats.CountType, statTags)
rt.batchInputOutputDiffCountStat = stats.Default.NewTaggedStat("router_batch_input_output_diff_jobs", stats.CountType, statTags)
rt.routerResponseTransformStat = stats.Default.NewTaggedStat("response_transform_latency", stats.TimerType, statTags)
rt.throttlingErrorStat = stats.Default.NewTaggedStat("router_throttling_error", stats.CountType, statTags)
rt.throttledStat = stats.Default.NewTaggedStat("router_throttled", stats.CountType, statTags)

rt.transformer = transformer.NewTransformer(rt.netClientTimeout, rt.backendProxyTimeout)

Expand Down

0 comments on commit 6de8862

Please sign in to comment.