21285: Send all SSH and tunnel endpoints to tunnel queue.
[arvados.git] / lib / service / cmd.go
index e40b47acbbb6d4bb1b96a9de1bf2d625e28b2430..82e95fe0b4c38b8ab0e7cfa49ab6c17da386da00 100644 (file)
@@ -16,6 +16,7 @@ import (
        _ "net/http/pprof"
        "net/url"
        "os"
+       "regexp"
        "strings"
        "time"
 
@@ -297,7 +298,7 @@ func (c *command) requestLimiter(handler http.Handler, cluster *arvados.Cluster,
                Priority: c.requestPriority,
                Registry: reg,
                Queue: func(req *http.Request) *httpserver.RequestQueue {
-                       if strings.HasPrefix(req.URL.Path, "/arvados/v1/connect/") {
+                       if req.Method == http.MethodPost && reTunnelPath.MatchString(req.URL.Path) {
                                return rqTunnel
                        } else {
                                return rqAPI
@@ -306,6 +307,25 @@ func (c *command) requestLimiter(handler http.Handler, cluster *arvados.Cluster,
        }
 }
 
+// reTunnelPath matches paths of API endpoints that go in the "tunnel"
+// queue.
+var reTunnelPath = regexp.MustCompile(func() string {
+       rePathVar := regexp.MustCompile(`{.*?}`)
+       out := ""
+       for _, endpoint := range []arvados.APIEndpoint{
+               arvados.EndpointContainerGatewayTunnel,
+               arvados.EndpointContainerGatewayTunnelCompat,
+               arvados.EndpointContainerSSH,
+               arvados.EndpointContainerSSHCompat,
+       } {
+               if out != "" {
+                       out += "|"
+               }
+               out += `\Q/` + rePathVar.ReplaceAllString(endpoint.Path, `\E[^/]*\Q`) + `\E`
+       }
+       return "^(" + out + ")$"
+}())
+
 func (c *command) requestPriority(req *http.Request, queued time.Time) int64 {
        switch {
        case req.Method == http.MethodPost && strings.HasPrefix(req.URL.Path, "/arvados/v1/containers/") && strings.HasSuffix(req.URL.Path, "/lock"):