datawire / bakerstreet

Baker Street is a HAProxy based routing engine for microservice architectures
http://bakerstreet.io
Apache License 2.0
226 stars 22 forks source link

Defining service name without sub folder in service url? #4

Closed ralfonso-directnic closed 9 years ago

ralfonso-directnic commented 9 years ago

I'm just setting this up, so forgive me if I've missed something. I've setup a test service that returns an location lookup for an ip service.

[Watson]
; service_name must uniquely identify your service
service_url: http://ips.foobar.com:8001
liveness_url: http://ips.foobar.com:8001/livecheck
period: 3  ; seconds between liveness checks
; logging level (default in datawire.conf) may be DEBUG, INFO, WARNING, ERROR, or CRITICAL
;logging: WARNING

I would normally request to this server at http://ips.foobar.com:8001/8.8.8.8 and get something like

{"country":"US","country_full":"United States","division":"California","city":"Mountain View","lat":37.386,"log":-122.0838,"tz":"America/Los_Angeles"}

I get a 503 error message with the above config, If I add a "name" to the url

http://ips.foobar.com:8001/iplookup

Then I can call it successfully like so:

http://localhost:8000/iplookup

The application returns an error because that subfolder is being passed, is that the correct understanding?

Any way to define a "name" without making it part of the micro service url? Seems like a odd limitation, perhaps I'm missing something?

ralfonso-directnic commented 9 years ago

Ok, a little more digging, I've found the issue is the use of acl backend in HA proxy, so I'm going to close this issue

richarddli commented 9 years ago

Is there a particular use case that you're trying to accomplish? We could look at adding support for this in the future.

Also, this might be something we want to clarify in the documentation.

ralfonso-directnic commented 9 years ago

Hi @richarddli I have a couple micro services that don't use subdirectories and of course haproxy is doing acl routing with sub directories which makes the whole thing more trouble if I have to re-wire those services to answer on a sub directory url instead of the root url.

I patched the code to instead get a numeric hash of the service_name, turn that into a port, and then write new frontends that bind to a port ie ( bind *:8143) and use the specific backend. Ostensibly now when I wire up mutliple services they would each have their own port bound. The hashing is a bit simple at this point, I'll have to explore how much the possibility of collision is, however that's easily remedied by changing the name. I also changed watson to use a service_name from the config file in support of removing the name from the url

Here is whats in my haproxy conf now

# Last update Tue Aug 11 12:34:25 2015
# //localhost/ips -> (random) http://ips.foobar.com; http://ips.foobar.com; 

global
    daemon
    maxconn 256

defaults
    mode http
    timeout connect 5000ms
    timeout client 50000ms
    timeout server 50000ms

frontend FE_ips
  bind *:8299
  mode http #if you had a tcp service and use tcp://service for url  mode would be tcp
  use_backend BE_ips

backend BE_ips
    server ips.foobar.com_80 ips.foobar.com:80 maxconn 32

You can see the changes here https://github.com/ralfonso-directnic/bakerstreet

plombardi89 commented 9 years ago

Resolved in 0.5 release.