From 6b7f5f6033382e545f99902165b6ed26a28f452e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Giedrius=20Statkevi=C4=8Dius?= Date: Wed, 18 Jan 2023 14:38:39 +0200 Subject: [PATCH] gate: allow disabling max concurrent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allow disabling max concurrency limit by setting limit to <= 0. Previously it was impossible to disable this limit. Signed-off-by: Giedrius Statkevičius --- pkg/gate/gate.go | 9 ++++++++- pkg/gate/gate_test.go | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 pkg/gate/gate_test.go diff --git a/pkg/gate/gate.go b/pkg/gate/gate.go index 36a16a3112..3df0fc6989 100644 --- a/pkg/gate/gate.go +++ b/pkg/gate/gate.go @@ -89,13 +89,20 @@ func (k *Keeper) NewGate(maxConcurrent int) Gate { func New(reg prometheus.Registerer, maxConcurrent int) Gate { promauto.With(reg).NewGauge(MaxGaugeOpts).Set(float64(maxConcurrent)) + var gate Gate + if maxConcurrent <= 0 { + gate = NewNoop() + } else { + gate = promgate.New(maxConcurrent) + } + return InstrumentGateDuration( promauto.With(reg).NewHistogram(DurationHistogramOpts), InstrumentGateTotal( promauto.With(reg).NewCounter(TotalCounterOpts), InstrumentGateInFlight( promauto.With(reg).NewGauge(InFlightGaugeOpts), - promgate.New(maxConcurrent), + gate, ), ), ) diff --git a/pkg/gate/gate_test.go b/pkg/gate/gate_test.go new file mode 100644 index 0000000000..4159ceec2d --- /dev/null +++ b/pkg/gate/gate_test.go @@ -0,0 +1,19 @@ +// Copyright (c) The Thanos Authors. +// Licensed under the Apache License 2.0. + +package gate + +import ( + "context" + "testing" + + "github.com/prometheus/client_golang/prometheus" + "github.com/stretchr/testify/require" +) + +func TestGateAllowsDisablingLimits(t *testing.T) { + reg := prometheus.NewRegistry() + g := New(reg, 0) + + require.NoError(t, g.Start(context.Background())) +}