hashicorp / hashicorp/consul

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

Open
#16,454 2 comments 0 reactions 0 assignees View on GitHub
theme/api-gw
Dominant language
Go
Stars
30.1k
Forks
4.6k
Avg merge
1d 18h
Merged PRs (30d)
39

Description

#### 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:

```hcl
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.

Contributor guide

Open the contributing guide

Research direction

Start in agent/consul/discoverychain/gateway_httproute.go around lines 131-133, 156-158, and 168-171, then reproduce the issue with an HTTPRoute whose referenced services all have zero weight. Done means unspecified or zero weights normalize to 1 and the router does not reference a splitter that was not added, eliminating the reported protocol mismatch.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.