hashicorp / consul

Consul is a distributed, highly available, and data center aware solution to connect and configure applications across dynamic, distributed infrastructure.
https://www.consul.io
Other
28.24k stars 4.41k forks source link

service-router dynamic path based routing #9712

Open seanamosw opened 3 years ago

seanamosw commented 3 years ago

Feature Description

Service routers currently require a static PathPrefix and destination Service eg:

Kind = "service-router"
Name = "internal-api"
Routes = [
  {
    Match {
      HTTP {
        PathPrefix = "/service1"
      }
    }

    Destination {
      Service = "service1"
    }
  },
  ...
]

What I would like to be able to do is something like:

Kind = "service-router"
Name = "internal-api"
Routes = [
  {
    Match {
      HTTP {
        PathPrefix = "/{svc}/"
      }
    }

    Destination {
      Service = "{svc}"
      PathPrefix = "/"
    }
  }
]

Use Case(s)

We currently have a linkerd installation across some our legacy (non-docker) and newer (docker) systems. These legacy systems are all accessing the linkerd service mesh via path based routing: http://localhost:4140/{servicename}/path, {servicename} is resolved from Consul via linkerd.

Since we have Consul rolled out for some time now, we would like to consolidate on Consul/Connect and this would be the simplest migration for those legacy services.

jkirschner-hashicorp commented 3 years ago

Potentially related to https://github.com/hashicorp/consul/issues/6702

takeda commented 1 year ago

Any update on this ticket? This is also feature that would be useful for my use case. I want to be able to have something slightly more advanced, for example:

Kind = "service-router"
Name = "service1"
Routes = [
  {
    Match {
      HTTP {
        Header {
          Name = "X-Account-ID"
          Regex = "(?P<account>acc-([0-9af]{8}))"
        }
      }
    }

    Destination {
      Service = "service1-\g{account}"
      PathPrefix = "/"
    }
  }
]

Essentially I want to use a header to dynamically control the service that I want to talk to.

So for example:

curl -H "X-Account-ID: acc-12345678" http://localhost:8080/status

Will invoke /status on service1-acc-12345678