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.4k stars 4.43k forks source link

[API Gateway] HTTPRoute - when all services have 0 weight, we get protocol mismatches #16454

Open andrewstucki opened 1 year ago

andrewstucki commented 1 year ago

Overview of the Issue

Two issues we have with HTTPRoute services is that we:

  1. Seem to have failed to normalize the weight of a given service to 1 by default (it stays 0 if unspecified)
  2. Additionally, when a service is skipped in our discoverychain construction code:

https://github.com/hashicorp/consul/blob/73b9b407ba357f99cd02b5387fa15e159ab24327/agent/consul/discoverychain/gateway_httproute.go#L131-L133

we can potentially wind up with no service splits (if we have no services with non-zero weight), and we fail to append a corresponding splitter here:

https://github.com/hashicorp/consul/blob/73b9b407ba357f99cd02b5387fa15e159ab24327/agent/consul/discoverychain/gateway_httproute.go#L156-L158

that winds up with our synthetic router referencing a service route for a splitter that doesn't exist:

https://github.com/hashicorp/consul/blob/73b9b407ba357f99cd02b5387fa15e159ab24327/agent/consul/discoverychain/gateway_httproute.go#L168-L171

and we wind up with envoy spitting out tcp/http mismatch protocol errors (due to the compiled discovery chain thinking that the referenced, non-existent splitter should be treated as a TCP-resolver discovery node).

Reproduction Steps

Create and attach an HTTPRoute with referencing two services in a routing rule where each has 0 weight, such as:

Rules = [
  {
    Services = [
      {
        Name = "service-one"
      },
      {
        Name = "service-two"
      }
    ]
  }
]

Attach to a gateway and watch Consul logs for protocol mismatch errors.

This should be fixed in two ways:

  1. We should normalize to, Weight = 1, and
  2. We shouldn't add a route to the router if no corresponding splitter was added.
missylbytes commented 1 year ago

I think we will also need to update the docs, we don't really talk about it being 1.

wahyugnc commented 3 weeks ago

Can API Gateway with http route expose GRPC service?