20602: Add IneligibleForQueuePriority const. 20602-controller-qos
authorTom Clegg <tom@curii.com>
Mon, 12 Jun 2023 18:47:30 +0000 (14:47 -0400)
committerTom Clegg <tom@curii.com>
Mon, 12 Jun 2023 18:47:30 +0000 (14:47 -0400)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

lib/service/cmd.go
sdk/go/httpserver/request_limiter.go
sdk/go/httpserver/request_limiter_test.go

index 37eac86d253f8324fdd4d029791e9fef8b1db755..c66c279432dc2f0ae6d5777f6776a1c2a3d063fb 100644 (file)
@@ -10,7 +10,6 @@ import (
        "flag"
        "fmt"
        "io"
-       "math"
        "net"
        "net/http"
        "net/http/httptest"
@@ -262,7 +261,7 @@ func (c *command) requestPriority(req *http.Request, queued time.Time) int64 {
                // Return 503 immediately instead of queueing. We want
                // to send feedback to dispatchcloud ASAP to stop
                // bringing up new containers.
-               return math.MinInt64
+               return httpserver.IneligibleForQueuePriority
        case req.Method == http.MethodPost && strings.HasPrefix(req.URL.Path, "/arvados/v1/logs"):
                // "Create log entry" is the most harmless kind of
                // request to drop.
index 402de3e10cac30df68593156882abd10621b467b..cd928e6ea85f6199575563bd552d73eca066a074 100644 (file)
@@ -15,6 +15,8 @@ import (
        "github.com/sirupsen/logrus"
 )
 
+const IneligibleForQueuePriority = math.MinInt64
+
 // RequestLimiter wraps http.Handler, limiting the number of
 // concurrent requests being handled by the wrapped Handler. Requests
 // that arrive when the handler is already at the specified
@@ -194,7 +196,7 @@ func (rl *RequestLimiter) enqueue(req *http.Request) *qent {
                ent.ready <- true
                return ent
        }
-       if priority == math.MinInt64 {
+       if priority == IneligibleForQueuePriority {
                // Priority func is telling us to return 503
                // immediately instead of queueing, regardless of
                // queue size, if we can't handle the request
index fd09c9305afd556ec170186fed3aff2bf7db27da..b04ff57cc176fca18d58773565cee1a55f3a5357 100644 (file)
@@ -6,7 +6,6 @@ package httpserver
 
 import (
        "fmt"
-       "math"
        "net/http"
        "net/http/httptest"
        "strconv"
@@ -135,14 +134,14 @@ func (*Suite) TestRequestLimiterQueuePriority(c *check.C) {
                <-h.inHandler
        }
 
-       c.Logf("starting %d priority=MinInt64 requests (should respond 503 immediately)", rl.MaxQueue)
+       c.Logf("starting %d priority=IneligibleForQueuePriority requests (should respond 503 immediately)", rl.MaxQueue)
        var wgX sync.WaitGroup
        for i := 0; i < rl.MaxQueue; i++ {
                wgX.Add(1)
                go func() {
                        defer wgX.Done()
                        resp := httptest.NewRecorder()
-                       rl.ServeHTTP(resp, &http.Request{Header: http.Header{"Priority": {fmt.Sprintf("%d", math.MinInt64)}}})
+                       rl.ServeHTTP(resp, &http.Request{Header: http.Header{"Priority": {fmt.Sprintf("%d", IneligibleForQueuePriority)}}})
                        c.Check(resp.Code, check.Equals, http.StatusServiceUnavailable)
                }()
        }