Skip to content

Commit 88b268c

Browse files
authored
workqueue rate limiting (#446)
1 parent 144bcdb commit 88b268c

File tree

7 files changed

+170
-124
lines changed

7 files changed

+170
-124
lines changed

cmd/agent/args/args.go

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ const (
2929
defaultProbeAddress = ":9001"
3030
defaultMetricsAddress = ":8000"
3131

32+
defaultWorkqueueBaseDelay = "5ms"
33+
defaultWorkqueueBaseDelayDuration = 5 * time.Millisecond
34+
35+
defaultWorkqueueMaxDelay = "1000s"
36+
defaultWorkqueueMaxDelayDuration = 1000 * time.Second
37+
3238
defaultProcessingTimeout = "1m"
3339
defaultProcessingTimeoutDuration = time.Minute
3440

@@ -96,8 +102,11 @@ var (
96102
argPyroscopeAddress = flag.String("pyroscope-address", defaultPyroscopeAddress, "The address of the Pyroscope server.")
97103
argDatadogHost = flag.String("datadog-host", defaultDatadogHost, "The address of the Datadog server.")
98104
argDatadogEnv = flag.String("datadog-env", defaultDatadogEnv, "The environment of the Datadog server.")
99-
100-
serviceSet containers.Set[string]
105+
argWorkqueueBaseDelay = flag.String("workqueue-base-delay", defaultWorkqueueBaseDelay, "The base delay for the workqueue.")
106+
argWorkqueueMaxDelay = flag.String("workqueue-max-delay", defaultWorkqueueMaxDelay, "The maximum delay for the workqueue.")
107+
argWorkqueueQPS = flag.Int("workqueue-qps", 10, "The maximum number of items to process per second.")
108+
argWorkqueueBurst = flag.Int("workqueue-burst", 50, "The maximum number of items to process at a time.")
109+
serviceSet containers.Set[string]
101110
)
102111

103112
func Init() {
@@ -332,3 +341,31 @@ func ensureOrDie(argName string, arg *string) {
332341
panic(fmt.Sprintf("%s arg is required", argName))
333342
}
334343
}
344+
345+
func WorkqueueBaseDelay() time.Duration {
346+
baseDelay, err := time.ParseDuration(*argWorkqueueBaseDelay)
347+
if err != nil {
348+
klog.ErrorS(err, "Could not parse workqueue-base-delay", "value", *argWorkqueueBaseDelay, "default", defaultWorkqueueBaseDelayDuration)
349+
return defaultWorkqueueBaseDelayDuration
350+
}
351+
352+
return baseDelay
353+
}
354+
355+
func WorkqueueMaxDelay() time.Duration {
356+
delay, err := time.ParseDuration(*argWorkqueueMaxDelay)
357+
if err != nil {
358+
klog.ErrorS(err, "Could not parse workqueue-max-delay", "value", *argWorkqueueMaxDelay, "default", defaultWorkqueueMaxDelayDuration)
359+
return defaultWorkqueueMaxDelayDuration
360+
}
361+
362+
return delay
363+
}
364+
365+
func WorkqueueQPS() int {
366+
return *argWorkqueueQPS
367+
}
368+
369+
func WorkqueueBurst() int {
370+
return *argWorkqueueBurst
371+
}

cmd/agent/console.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func registerConsoleReconcilersOrDie(
5454
consoleClient client.Client,
5555
) {
5656
mgr.AddReconcilerOrDie(service.Identifier, func() (v1.Reconciler, error) {
57-
r, err := service.NewServiceReconciler(consoleClient, k8sClient, config, args.ControllerCacheTTL(), args.ManifestCacheTTL(), args.ManifestCacheJitter(), args.RestoreNamespace(), args.ConsoleUrl())
57+
r, err := service.NewServiceReconciler(consoleClient, k8sClient, config, args.ControllerCacheTTL(), args.ManifestCacheTTL(), args.ManifestCacheJitter(), args.WorkqueueBaseDelay(), args.WorkqueueMaxDelay(), args.RestoreNamespace(), args.ConsoleUrl(), args.WorkqueueQPS(), args.WorkqueueBurst())
5858
return r, err
5959
})
6060

go.mod

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,17 @@ require (
4040
github.com/pluralsh/controller-reconcile-helper v0.1.0
4141
github.com/pluralsh/gophoenix v0.1.3-0.20231201014135-dff1b4309e34
4242
github.com/pluralsh/polly v0.2.0
43-
github.com/prometheus/client_golang v1.20.5
43+
github.com/prometheus/client_golang v1.21.1
4444
github.com/samber/lo v1.49.0
4545
github.com/sirupsen/logrus v1.9.3
46-
github.com/spf13/pflag v1.0.5
46+
github.com/spf13/pflag v1.0.6
4747
github.com/stretchr/testify v1.10.0
4848
github.com/vektah/gqlparser/v2 v2.5.22
4949
github.com/vektra/mockery/v2 v2.45.1
5050
github.com/vmware-tanzu/velero v1.14.1
5151
github.com/yuin/gopher-lua v1.1.1
5252
golang.org/x/exp v0.0.0-20250210185358-939b2ce775ac
53+
golang.org/x/time v0.11.0
5354
gopkg.in/yaml.v3 v3.0.1
5455
helm.sh/helm/v3 v3.17.3
5556
k8s.io/api v0.32.2
@@ -75,14 +76,14 @@ require (
7576
require (
7677
4d63.com/gocheckcompilerdirectives v1.2.1 // indirect
7778
4d63.com/gochecknoglobals v0.2.1 // indirect
78-
cel.dev/expr v0.19.0 // indirect
79+
cel.dev/expr v0.19.1 // indirect
7980
cloud.google.com/go v0.116.0 // indirect
8081
cloud.google.com/go/auth v0.13.0 // indirect
8182
cloud.google.com/go/auth/oauth2adapt v0.2.6 // indirect
8283
cloud.google.com/go/compute/metadata v0.6.0 // indirect
8384
cloud.google.com/go/iam v1.2.2 // indirect
8485
cloud.google.com/go/monitoring v1.21.2 // indirect
85-
cloud.google.com/go/storage v1.45.0 // indirect
86+
cloud.google.com/go/storage v1.49.0 // indirect
8687
dario.cat/mergo v1.0.1 // indirect
8788
github.com/4meepo/tagalign v1.4.1 // indirect
8889
github.com/99designs/gqlgen v0.17.64 // indirect
@@ -123,11 +124,10 @@ require (
123124
github.com/Masterminds/sprig v2.22.0+incompatible // indirect
124125
github.com/Masterminds/squirrel v1.5.4 // indirect
125126
github.com/Microsoft/go-winio v0.6.2 // indirect
126-
github.com/OneOfOne/xxhash v1.2.8 // indirect
127127
github.com/OpenPeeDeeP/depguard/v2 v2.2.0 // indirect
128128
github.com/ProtonMail/go-crypto v1.1.5 // indirect
129129
github.com/agext/levenshtein v1.2.3 // indirect
130-
github.com/agnivade/levenshtein v1.2.0 // indirect
130+
github.com/agnivade/levenshtein v1.2.1 // indirect
131131
github.com/alecthomas/chroma v0.10.0 // indirect
132132
github.com/alecthomas/go-check-sumtype v0.3.1 // indirect
133133
github.com/alexkohler/nakedret/v2 v2.0.5 // indirect
@@ -174,7 +174,6 @@ require (
174174
github.com/catenacyber/perfsprint v0.7.1 // indirect
175175
github.com/ccojocar/zxcvbn-go v1.0.2 // indirect
176176
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
177-
github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect
178177
github.com/cespare/xxhash/v2 v2.3.0 // indirect
179178
github.com/chai2010/gettext-go v1.0.2 // indirect
180179
github.com/charithe/durationcheck v0.0.10 // indirect
@@ -185,8 +184,8 @@ require (
185184
github.com/cloudflare/circl v1.5.0 // indirect
186185
github.com/cloudwego/base64x v0.1.4 // indirect
187186
github.com/cloudwego/iasm v0.2.0 // indirect
188-
github.com/cncf/xds/go v0.0.0-20240905190251-b4127c9b8d78 // indirect
189-
github.com/containerd/containerd v1.7.25 // indirect
187+
github.com/cncf/xds/go v0.0.0-20241223141626-cff3c89139a3 // indirect
188+
github.com/containerd/containerd v1.7.27 // indirect
190189
github.com/containerd/errdefs v1.0.0 // indirect
191190
github.com/containerd/log v0.1.0 // indirect
192191
github.com/containerd/platforms v1.0.0-rc.1 // indirect
@@ -210,8 +209,8 @@ require (
210209
github.com/ebitengine/purego v0.8.2 // indirect
211210
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
212211
github.com/emirpasic/gods v1.18.1 // indirect
213-
github.com/envoyproxy/go-control-plane v0.13.1 // indirect
214-
github.com/envoyproxy/protoc-gen-validate v1.1.0 // indirect
212+
github.com/envoyproxy/go-control-plane/envoy v1.32.4 // indirect
213+
github.com/envoyproxy/protoc-gen-validate v1.2.1 // indirect
215214
github.com/ettle/strcase v0.2.0 // indirect
216215
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
217216
github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f // indirect
@@ -267,7 +266,7 @@ require (
267266
github.com/golangci/unconvert v0.0.0-20240309020433-c5143eacb3ed // indirect
268267
github.com/google/btree v1.1.2 // indirect
269268
github.com/google/cel-go v0.22.0 // indirect
270-
github.com/google/go-cmp v0.6.0 // indirect
269+
github.com/google/go-cmp v0.7.0 // indirect
271270
github.com/google/go-containerregistry v0.20.3 // indirect
272271
github.com/google/gofuzz v1.2.0 // indirect
273272
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad // indirect
@@ -295,7 +294,6 @@ require (
295294
github.com/hashicorp/go-uuid v1.0.3 // indirect
296295
github.com/hashicorp/go-version v1.7.0 // indirect
297296
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
298-
github.com/hashicorp/hcl v1.0.1-vault-7 // indirect
299297
github.com/hashicorp/hcl/v2 v2.23.0 // indirect
300298
github.com/hexops/gotextdiff v1.0.3 // indirect
301299
github.com/huandu/xstrings v1.5.0 // indirect
@@ -320,7 +318,7 @@ require (
320318
github.com/kevinburke/ssh_config v1.2.0 // indirect
321319
github.com/kisielk/errcheck v1.8.0 // indirect
322320
github.com/kkHAIKE/contextcheck v1.1.5 // indirect
323-
github.com/klauspost/compress v1.17.11 // indirect
321+
github.com/klauspost/compress v1.18.0 // indirect
324322
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
325323
github.com/kulti/thelper v0.6.3 // indirect
326324
github.com/kunwardeep/paralleltest v1.0.10 // indirect
@@ -341,7 +339,6 @@ require (
341339
github.com/lufia/plan9stats v0.0.0-20240226150601-1dcf7310316a // indirect
342340
github.com/lunixbochs/struc v0.0.0-20200707160740-784aaebc1d40 // indirect
343341
github.com/macabu/inamedparam v0.1.3 // indirect
344-
github.com/magiconair/properties v1.8.9 // indirect
345342
github.com/mailru/easyjson v0.7.7 // indirect
346343
github.com/maratori/testableexamples v1.0.0 // indirect
347344
github.com/maratori/testpackage v1.1.1 // indirect
@@ -377,7 +374,7 @@ require (
377374
github.com/olekukonko/tablewriter v0.0.5 // indirect
378375
github.com/open-policy-agent/opa v1.1.0 // indirect
379376
github.com/opencontainers/go-digest v1.0.0 // indirect
380-
github.com/opencontainers/image-spec v1.1.0 // indirect
377+
github.com/opencontainers/image-spec v1.1.1 // indirect
381378
github.com/osteele/liquid v1.4.0 // indirect
382379
github.com/osteele/tuesday v1.0.3 // indirect
383380
github.com/outcaste-io/ristretto v0.2.3 // indirect
@@ -393,7 +390,7 @@ require (
393390
github.com/polyfloyd/go-errorlint v1.7.0 // indirect
394391
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
395392
github.com/prometheus/client_model v0.6.1 // indirect
396-
github.com/prometheus/common v0.61.0 // indirect
393+
github.com/prometheus/common v0.62.0 // indirect
397394
github.com/prometheus/procfs v0.15.1 // indirect
398395
github.com/puzpuzpuz/xsync/v3 v3.5.1 // indirect
399396
github.com/quasilyte/go-ruleguard v0.4.3-0.20240823090925-0fe6f58b47b1 // indirect
@@ -412,8 +409,7 @@ require (
412409
github.com/russross/blackfriday/v2 v2.1.0 // indirect
413410
github.com/ryancurrah/gomodguard v1.3.5 // indirect
414411
github.com/ryanrolds/sqlclosecheck v0.5.1 // indirect
415-
github.com/sagikazarmark/locafero v0.6.0 // indirect
416-
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
412+
github.com/sagikazarmark/locafero v0.7.0 // indirect
417413
github.com/sanposhiho/wastedassign/v2 v2.1.0 // indirect
418414
github.com/santhosh-tekuri/jsonschema/v6 v6.0.1 // indirect
419415
github.com/sashamelentyev/interfacebloat v1.1.0 // indirect
@@ -432,10 +428,10 @@ require (
432428
github.com/sourcegraph/conc v0.3.0 // indirect
433429
github.com/sourcegraph/go-diff v0.7.0 // indirect
434430
github.com/spaolacci/murmur3 v1.1.0 // indirect
435-
github.com/spf13/afero v1.11.0 // indirect
431+
github.com/spf13/afero v1.12.0 // indirect
436432
github.com/spf13/cast v1.7.1 // indirect
437-
github.com/spf13/cobra v1.8.1 // indirect
438-
github.com/spf13/viper v1.19.0 // indirect
433+
github.com/spf13/cobra v1.9.1 // indirect
434+
github.com/spf13/viper v1.20.1 // indirect
439435
github.com/spyzhov/ajson v0.9.1 // indirect
440436
github.com/ssgreg/nlreturn/v2 v2.2.1 // indirect
441437
github.com/stbenjam/no-sprintf-host-port v0.2.0 // indirect
@@ -485,14 +481,14 @@ require (
485481
go.opentelemetry.io/collector/pdata v1.26.0 // indirect
486482
go.opentelemetry.io/collector/pdata/pprofile v0.120.0 // indirect
487483
go.opentelemetry.io/collector/semconv v0.120.0 // indirect
488-
go.opentelemetry.io/contrib/detectors/gcp v1.32.0 // indirect
484+
go.opentelemetry.io/contrib/detectors/gcp v1.34.0 // indirect
489485
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.56.0 // indirect
490-
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0 // indirect
491-
go.opentelemetry.io/otel v1.34.0 // indirect
492-
go.opentelemetry.io/otel/metric v1.34.0 // indirect
493-
go.opentelemetry.io/otel/sdk v1.34.0 // indirect
494-
go.opentelemetry.io/otel/sdk/metric v1.34.0 // indirect
495-
go.opentelemetry.io/otel/trace v1.34.0 // indirect
486+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.60.0 // indirect
487+
go.opentelemetry.io/otel v1.35.0 // indirect
488+
go.opentelemetry.io/otel/metric v1.35.0 // indirect
489+
go.opentelemetry.io/otel/sdk v1.35.0 // indirect
490+
go.opentelemetry.io/otel/sdk/metric v1.35.0 // indirect
491+
go.opentelemetry.io/otel/trace v1.35.0 // indirect
496492
go.uber.org/atomic v1.11.0 // indirect
497493
go.uber.org/automaxprocs v1.6.0 // indirect
498494
go.uber.org/multierr v1.11.0 // indirect
@@ -501,22 +497,21 @@ require (
501497
golang.org/x/crypto v0.36.0 // indirect
502498
golang.org/x/exp/typeparams v0.0.0-20241108190413-2d47ceb2692f // indirect
503499
golang.org/x/mod v0.23.0 // indirect
504-
golang.org/x/net v0.37.0 // indirect
500+
golang.org/x/net v0.38.0 // indirect
505501
golang.org/x/oauth2 v0.25.0 // indirect
506502
golang.org/x/sync v0.12.0 // indirect
507503
golang.org/x/sys v0.31.0 // indirect
508504
golang.org/x/term v0.30.0 // indirect
509505
golang.org/x/text v0.23.0 // indirect
510-
golang.org/x/time v0.9.0 // indirect
511506
golang.org/x/tools v0.30.0 // indirect
512507
golang.org/x/xerrors v0.0.0-20240716161551-93cc26a95ae9 // indirect
513508
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
514509
google.golang.org/api v0.216.0 // indirect
515510
google.golang.org/genproto v0.0.0-20241118233622-e639e219e697 // indirect
516-
google.golang.org/genproto/googleapis/api v0.0.0-20250115164207-1a7da9e5054f // indirect
511+
google.golang.org/genproto/googleapis/api v0.0.0-20250218202821-56aae31c358a // indirect
517512
google.golang.org/genproto/googleapis/rpc v0.0.0-20250219182151-9fdb1cabc7b2 // indirect
518-
google.golang.org/grpc v1.70.0 // indirect
519-
google.golang.org/protobuf v1.36.5 // indirect
513+
google.golang.org/grpc v1.71.1 // indirect
514+
google.golang.org/protobuf v1.36.6 // indirect
520515
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
521516
gopkg.in/inf.v0 v0.9.1 // indirect
522517
gopkg.in/ini.v1 v1.67.0 // indirect
@@ -541,6 +536,8 @@ require (
541536
)
542537

543538
replace (
539+
github.com/containerd/containerd => github.com/containerd/containerd v1.7.27
540+
github.com/open-policy-agent/opa => github.com/open-policy-agent/opa v1.4.0
544541
k8s.io/cloud-provider => k8s.io/cloud-provider v0.31.1
545542
k8s.io/kubelet => k8s.io/kubelet v0.31.1
546543
)

0 commit comments

Comments
 (0)