fabiolb / fabio

Consul Load-Balancing made simple
https://fabiolb.net
MIT License
7.25k stars 619 forks source link

Add `only=` tag #757

Open RickyGrassmuck opened 4 years ago

RickyGrassmuck commented 4 years ago

The new tag only= allows the user to have more granular control over which checked services get added to the routing table.

Example: Nomad publishes service checks for the HTTP, RPC, and Serf services to consul. Registering the tag below results in a routing table that splits requests for nomad.service.example.com between the three different protocols.

Service Tag

    "urlprefix-nomad.service.example.com:443/ proto=https tlsskipverify=true"

Resulting Routing Table Entries

nomad        nomad.service.example.com:443/        https://172.16.1.8:4646        tlsskipverify=true        33%
nomad        nomad.service.example.com:443/        https://172.16.1.8:4647        tlsskipverify=true        33%
nomad        nomad.service.example.com:443/        https://172.16.1.8:4648        tlsskipverify=true        33%

Since we really only want to route the HTTP traffic, this commit allows you to use the rule below to only generate a single routing table entry based on the port number associated with our HTTP port.

Service Tag

    "urlprefix-nomad-0.service.example.com:443/ proto=https only=4646 tlsskipverify=true"

Resulting Routing Table Entries

nomad        nomad.service.example.com:443/        https://172.16.1.8:4646        tlsskipverify=true        100.00%
CLAassistant commented 4 years ago

CLA assistant check
All committers have signed the CLA.

RickyGrassmuck commented 3 years ago

@nathanejohnson Sorry, I had signed the CLA but had accidentally messed up the email address in one of the commits so it wasn't registering. Went ahead and squashed everything down to 1 commit and re-signed the CLA so it should be good now.

nathanejohnson commented 3 years ago

@rigrassm tentatively this looks good, could you add a test case in routecmd_test.go to cover this option. Now the interesting part here is this means consul registry will have a route option that doesn't exist otherwise. On the other hand, filtering doesn't make much sense in other cases. I went looking for documentation specific to consul tags and it's not really there other than a brief mention in the Quickstart. I would have asked you to update that documentation, but since it doesn't exist I'll make it a point to create that page and roll it out with the next release.

TLDR; add a test case and I'll merge this.