diff options
author | Igor Wiedler <iwiedler@gitlab.com> | 2021-03-04 20:26:59 +0300 |
---|---|---|
committer | Igor Wiedler <iwiedler@gitlab.com> | 2021-03-16 13:05:13 +0300 |
commit | b2bebb9733332031654f203a42c9912831d49a15 (patch) | |
tree | 39beb853574b6beddb573371a36e2411304a7b9a | |
parent | 3d68f89c6ef3c7d3cd13838e4ab521301ac5754e (diff) |
Instrument limit listener for saturation monitoring
Changelog: added
-rw-r--r-- | internal/netutil/shared_limit_listener.go | 12 | ||||
-rw-r--r-- | metrics/metrics.go | 25 |
2 files changed, 36 insertions, 1 deletions
diff --git a/internal/netutil/shared_limit_listener.go b/internal/netutil/shared_limit_listener.go index 3f88e591..7d36e36f 100644 --- a/internal/netutil/shared_limit_listener.go +++ b/internal/netutil/shared_limit_listener.go @@ -5,6 +5,8 @@ import ( "net" "sync" "time" + + "gitlab.com/gitlab-org/gitlab-pages/metrics" ) var ( @@ -30,6 +32,7 @@ type Limiter struct { // NewLimiter creates a Limiter with the given capacity func NewLimiter(n int) *Limiter { + metrics.LimitListenerMaxConns.Set(float64(n)) return &Limiter{ sem: make(chan struct{}, n), } @@ -46,14 +49,21 @@ type sharedLimitListener struct { // accquired, false if the listener is closed and the semaphore is not // acquired. func (l *sharedLimitListener) acquire() bool { + metrics.LimitListenerWaiting.Inc() + defer metrics.LimitListenerWaiting.Dec() + select { case <-l.done: return false case l.limiter.sem <- struct{}{}: + metrics.LimitListenerConcurrentConns.Inc() return true } } -func (l *sharedLimitListener) release() { <-l.limiter.sem } +func (l *sharedLimitListener) release() { + <-l.limiter.sem + metrics.LimitListenerConcurrentConns.Dec() +} func (l *sharedLimitListener) Accept() (net.Conn, error) { acquired := l.acquire() diff --git a/metrics/metrics.go b/metrics/metrics.go index 045ff26e..b17e8946 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -206,6 +206,27 @@ var ( Help: "The number of requests with unknown HTTP method which were rejected", }, ) + + LimitListenerMaxConns = prometheus.NewGauge( + prometheus.GaugeOpts{ + Name: "gitlab_pages_limit_listener_max_conns", + Help: "The maximum concurrent connections allowed by the limit listener.", + }, + ) + + LimitListenerConcurrentConns = prometheus.NewGauge( + prometheus.GaugeOpts{ + Name: "gitlab_pages_limit_listener_concurrent_conns", + Help: "The number of concurrent connections.", + }, + ) + + LimitListenerWaiting = prometheus.NewGauge( + prometheus.GaugeOpts{ + Name: "gitlab_pages_limit_listener_waiting_conns", + Help: "The number of backlogged connections waiting on concurrency limit.", + }, + ) ) // MustRegister collectors with the Prometheus client @@ -236,5 +257,9 @@ func MustRegister() { ZipCacheRequests, ZipArchiveEntriesCached, ZipCachedEntries, + RejectedRequestsCount, + LimitListenerMaxConns, + LimitListenerConcurrentConns, + LimitListenerWaiting, ) } |