Fabio: Feature: Allow weight tag in Consul

Created on 26 Jan 2016  路  14Comments  路  Source: fabiolb/fabio

"registrator" of paths into consul should also allow weight parameter to be passed so that traffic can be balanced to env needs. Some services may be running on nodes with less resources. Right now, rebalancing is distributed evenly.

Enhancement example:

docker run -d
-e "SERVICE_TAGS=urlprefix-/hello-world:0" 
--name hello_world_1  \

results in...

/hello-world
  /hello_world_1   100%

adding another specific weighted service...

docker run -d
-e "SERVICE_TAGS=urlprefix-/hello-world:20" 
--name hello_world_2  \

would result in...

/hello-world
  /hello_world_1   80%
  /hello_world_2   20%
enhancement

Most helpful comment

@magiconair
Fantastic.
I tried it with a simples 20/80 weight distribution and it worked.

Moreover I tested it with my use case.
We're going to have a fallback TCP port like in haproxy, when one service is down just move to the fallback so I got one with weight=100 and another with 0.
It worked perfectly.
Only the 100 weighted service got traffic when it was up but if I killed it, once it went down on the consul check, only the 0 weighted service started getting traffic.

Thank you so much.
Great work.

Any idea when this will be on an official release?

All 14 comments

I like the idea but would prefer a different syntax. Especially with the idea of the tcp proxy I'm thinking about using a URL for this:

p-[scheme]://[host][:port][/path][?opt=val[&opt=val]...]

Examples:

p-tcp://host:port
p-http://host:port/hello
p-https://host/hello
p-ws:///hello
p-/hello (equivalent to p-http:///hello)
p-/hello?weight=0.8
...

urlprefix-host/path then translates to p-http://host/path and p-https://host/path

@magiconair I like it.

Let your imagination fly!

Hi guys,

Any news on this matter?
I'm really interested in getting weights on TCP proxy mode.

Thanks!

Maybe we can help developing this feature ? If so, what would be the syntax ?

/path weight=xxx ?

@nanoz and @tiago-msilva I thought that this would be more work but the route add command already supports a weight option which does the right thing. The only thing missing was to expose this via the urlprefix- tag. You can now add a weight=.x option to specify a weight on a target, e.g. urlprefix-:3306 weight=0.2 proto=tcp

Sorry, @nanoz I did not want to take the opportunity for contributing away from you but was done pretty much when I looked at the the place which I wanted to point out to you.

To illustrate this I've added a new detail option for the log.routes.format which you can use to dump the routing table in a different format.

./fabio -log.routes.format detail
2017/06/19 11:51:14 [INFO] Updated config to
+-- host=:3306
|   +-- path=
|       |-- addr=127.0.0.1:5001 weight 0.20 slots 2000/10000
|       +-- addr=127.0.0.1:5000 weight 0.80 slots 8000/10000
+-- host=:3307
    +-- path=
        +-- addr=127.0.0.1:5002 weight 1.00 slots 1/1

Would you mind testing this? This is on the issue-42-weigh-targets branch.

@magiconair
First of all thank you for looking into this matter.

I don't know a thing about go.
I tried to build this with:
git clone ...
git checkout issue-42-weigh-targets
cd fabio
go build .
and I got this:
./main.go:399: t.Dump undefined (type route.Table has no field or method Dump)
Does this help out?

try this:

mkdir ~/go
go get -u github.com/fabiolb/fabio
cd ~/go/src/github.com/fabiolb/fabio
git checkout issue-42-weigh-targets
go install
ls ~/go/bin/fabio

= go1.8.3

Thanks!

I also set the GOPATH to "~/go" and cd to it before running go get.
Yep, it' worked.
Will test this now.

@magiconair
Fantastic.
I tried it with a simples 20/80 weight distribution and it worked.

Moreover I tested it with my use case.
We're going to have a fallback TCP port like in haproxy, when one service is down just move to the fallback so I got one with weight=100 and another with 0.
It worked perfectly.
Only the 100 weighted service got traffic when it was up but if I killed it, once it went down on the consul check, only the 0 weighted service started getting traffic.

Thank you so much.
Great work.

Any idea when this will be on an official release?

@tiago-msilva Thanks for testing this. I try to do a release a month. It has been three weeks since the last release. I'll have a look what else is on the list and could shoot for a 1.5.1 next week.

merged to master

Hi,

Good day.

Could you maybe add a working example? I tried:

tags = [ "fabio-:6379 weight=1 proto=tcp" ]
tags = [ "fabio-:6379 weight=1.0 proto=tcp" ]
tags = [ "fabio-:6379 weight=100 proto=tcp" ]

I start fabio with:

        args = [
                "-proxy.addr", ":11211;proto=tcp, :6379;proto=tcp",
                "-registry.consul.tagprefix", "fabio-"
                ]

I'm using

https://github.com/fabiolb/fabio/releases/download/v1.5.10/fabio-1.5.10-go1.11.1-linux_amd64

The weights are not update though. Might be missing something simple? Thanks.

Regards.
JJ

@jarrettj you need to register service instances with different weights. If they all have the same then this won't have an effect.

Was this page helpful?
0 / 5 - 0 ratings