Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Allow weight tag in Consul #42

Closed
composer22 opened this issue Jan 26, 2016 · 14 comments
Closed

Feature: Allow weight tag in Consul #42

composer22 opened this issue Jan 26, 2016 · 14 comments
Milestone

Comments

@composer22
Copy link

"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%
@magiconair
Copy link
Contributor

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

@composer22
Copy link
Author

@magiconair I like it.

Let your imagination fly!

@tiago-msilva
Copy link

Hi guys,

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

Thanks!

@nanoz
Copy link

nanoz commented Jun 18, 2017

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

/path weight=xxx ?

magiconair added a commit that referenced this issue Jun 19, 2017
This patch adds support for a 'weight=f' option on the url tag
which gets translated to a 'weight f' option on the 'route add'
command. This should eventually move into the options to unify
the config option syntax.

Fixes #42
@magiconair
Copy link
Contributor

@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.

@tiago-msilva
Copy link

@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?

@magiconair
Copy link
Contributor

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

@magiconair
Copy link
Contributor

= go1.8.3

@tiago-msilva
Copy link

Thanks!

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

@tiago-msilva
Copy link

tiago-msilva commented Jun 28, 2017

@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?

@magiconair
Copy link
Contributor

@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.

@magiconair
Copy link
Contributor

merged to master

@magiconair magiconair added this to the 1.5.1 milestone Oct 10, 2017
@jarrettj
Copy link

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

@magiconair
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants