Can't get Consul's service-router to work

Hello there !

I’ve been trying to make service-router work.
Basically, I have a service “api” which can call a service “sandbox” through consul connect

Each service is started with the following command :

/usr/bin/consul agent -config-dir=/etc/consul.d/ -dev

This is the service definitions :
api.json

{
    "service": {
        "id": "api",
        "name": "api",
        "tags": ["api"],
        "connect": {
            "sidecar_service": {
                "proxy": {
                    "upstreams": [
                        {"destination_name": "sandbox", "local_bind_port": 51224}
                    ]
                }
            }
        },
        "port": 8000,
    }
}

sandbox.json

{
    "service": {
        "id": "sandbox",
        "name": "sandbox",
        "tags": ["sandbox"],
        "connect": {
            "sidecar_service": {
                "proxy": {
                    "upstreams": [
                        {"destination_name": "api", "local_bind_port": 51222},
                    ]
                }
            }
        },
        "port": 8000,
    }
}

My BIG problem is : This ALWAYS works

requests.post("http://localhost:51224/v0/tasks")

(this basically sends a POST requests to the “http://localhost:51224/v0/tasks” URL, localhost:51224 is the URL to the sidecar-proxy to the sandbox service)

Here is my service-router.hcl :

Kind = "service-router"
Name = "sandbox"
Routes = [
  {
    Match {
      HTTP {
        PathPrefix = "/v0"
      }
    }

    Destination {
      Service = "database"
    }
  },
]

(database here is a different service which does not have the API deployed on it, so the POST call should fail)

And the service-defaults.hcl

Kind = "service-defaults"
Name = "sandbox"
Protocol  = "http"

What I tried so far :

  • Using either HCL or JSON for the service-router, doesn’t change anything and shouldn’t be the cause of the problem since it was displayed correctly when using consul config read -kind service-router -name sandbox
  • Using name = api in the service-router.hcl, I’m almost sure it should be equal to “sandbox” here since my understanding is “service-router.hcl is defined for the service that you want to call, not for the service that will call other services”
  • Using all possible matches in the Match section of the service-router.hcl, I tried path prefixes, HTTP headers
  • Using a default destination with no match section, still does not work
  • Using either a subnet as destination or another service, none works
  • Using consul reload before and after the consul write service-router.hcl same with systemctl stop consul; systemctl start consul, or simply consul write service-router.hcl without reloading anything
  • Trying with or without the -dev flag in consul command
  • Adding "connect": {"enabled": True}, "ports": {"grpc": 8502} to each node configuration