Skip to content
This repository has been archived by the owner on Jul 16, 2019. It is now read-only.

Routing to wrong back end #30

Closed
AndyWNorris opened this issue Jan 26, 2018 · 5 comments
Closed

Routing to wrong back end #30

AndyWNorris opened this issue Jan 26, 2018 · 5 comments

Comments

@AndyWNorris
Copy link

AndyWNorris commented Jan 26, 2018

I have a Service Fabric Application consisting of two services that I am trying to route with using Traefik

One is an MVC app that provides a UI and the other a Web API.

Extensions for the MVC is set up as below from service manifest.
<StatelessServiceType ServiceTypeName="TodoWebType" UseImplicitHost="true" > <Extensions> <Extension Name="Traefik"> <Labels xmlns="http://schemas.microsoft.com/2015/03/fabact-no-schema"> <Label Key="traefik.frontend.rule.Web">ReplacePathRegex: /web /</Label> <Label Key="traefik.expose">true</Label> <Label Key="traefik.frontend.passHostHeader">true</Label> </Labels> </Extension> </Extensions> </StatelessServiceType>

For the API:
<StatelessServiceType ServiceTypeName="TodoApiType" UseImplicitHost="true" > <Extensions> <Extension Name="Traefik"> <Labels xmlns="http://schemas.microsoft.com/2015/03/fabact-no-schema"> <Label Key="traefik.frontend.rule.example">ReplacePathRegex: /api/index /api/Todo</Label> <Label Key="traefik.expose">true</Label> <Label Key="traefik.frontend.passHostHeader">true</Label> </Labels> </Extension> </Extensions> </StatelessServiceType>

When deployed the portal shows each rule associated with the correct back end.

At run time, the API request is correctly routed and generates the following entry in the Traefik debug log:
10.1.1.4 - - [26/Jan/2018:12:08:28 +0000] "GET /api/index HTTP/1.1" 200 344 - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.119 Safari/537.36" 113 "fabric:/TodoApp/TodoApi" "http://AndyNDev2016:8081/" 96ms

The MVC one fails with the following log
10.1.1.4 - - [26/Jan/2018:11:56:01 +0000] "GET /web HTTP/1.1" 404 0 - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.119 Safari/537.36" 100 "fabric:/TodoApp/TodoApi" "http://AndyNDev2016:8081/" 3ms

It appears that the wrong back end has been selected. Is this a configuration issue or a bug?

@lawrencegripper
Copy link
Collaborator

Hi,

Haven't had a chance to repro this first but my suspicion is that this is because your using a "modifier" not a "matcher".

Matcher rules determine if a particular request should be forwarded to a backend.
Modifier rules only modify the request. They do not have any impact on routing decisions being made.

Can you give it a try and let us know?

@AndyWNorris
Copy link
Author

AndyWNorris commented Jan 26, 2018

Have tried all of the matcher rules, in all cases it is attempting to forward to the other service.

Below is the rule set to <Label Key="traefik.frontend.rule.Web">Path: /web</Label>

time="2018-01-26T17:29:21Z" level=debug msg="vulcand/oxy/roundrobin/rebalancer: begin ServeHttp on request" Request="{"Method":"GET","URL":{"Scheme":"","Opaque":"","User":null,"Host":"","Path":"/Web","RawPath":"","ForceQuery":false,"RawQuery":"","Fragment":""},"Proto":"HTTP/1.1","ProtoMajor":1,"ProtoMinor":1,"Header":{"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8"],"Accept-Encoding":["gzip, deflate"],"Accept-Language":["en-US,en;q=0.9"],"Connection":["keep-alive"],"Upgrade-Insecure-Requests":["1"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.119 Safari/537.36"]},"ContentLength":0,"TransferEncoding":null,"Host":"andyndev2016","Form":null,"PostForm":null,"MultipartForm":null,"Trailer":null,"RemoteAddr":"10.1.1.4:53058","RequestURI":"/Web","TLS":null}"
time="2018-01-26T17:29:21Z" level=debug msg="vulcand/oxy/roundrobin/rebalancer: Forwarding this request to URL" Request="{"Method":"GET","URL":{"Scheme":"","Opaque":"","User":null,"Host":"","Path":"/Web","RawPath":"","ForceQuery":false,"RawQuery":"","Fragment":""},"Proto":"HTTP/1.1","ProtoMajor":1,"ProtoMinor":1,"Header":{"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8"],"Accept-Encoding":["gzip, deflate"],"Accept-Language":["en-US,en;q=0.9"],"Connection":["keep-alive"],"Upgrade-Insecure-Requests":["1"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.119 Safari/537.36"]},"ContentLength":0,"TransferEncoding":null,"Host":"andyndev2016","Form":null,"PostForm":null,"MultipartForm":null,"Trailer":null,"RemoteAddr":"10.1.1.4:53058","RequestURI":"/Web","TLS":null}" ForwardURL=http://AndyNDev2016:8081/
time="2018-01-26T17:29:21Z" level=debug msg="vulcand/oxy/forward: begin ServeHttp on request" Request="{"Method":"GET","URL":{"Scheme":"http","Opaque":"","User":null,"Host":"AndyNDev2016:8081","Path":"/","RawPath":"","ForceQuery":false,"RawQuery":"","Fragment":""},"Proto":"HTTP/1.1","ProtoMajor":1,"ProtoMinor":1,"Header":{"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8"],"Accept-Encoding":["gzip, deflate"],"Accept-Language":["en-US,en;q=0.9"],"Connection":["keep-alive"],"Upgrade-Insecure-Requests":["1"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.119 Safari/537.36"]},"ContentLength":0,"TransferEncoding":null,"Host":"andyndev2016","Form":null,"PostForm":null,"MultipartForm":null,"Trailer":null,"RemoteAddr":"10.1.1.4:53058","RequestURI":"/Web","TLS":null}"
time="2018-01-26T17:29:21Z" level=debug msg="vulcand/oxy/forward/http: begin ServeHttp on request" Request="{"Method":"GET","URL":{"Scheme":"http","Opaque":"","User":null,"Host":"AndyNDev2016:8081","Path":"/","RawPath":"","ForceQuery":false,"RawQuery":"","Fragment":""},"Proto":"HTTP/1.1","ProtoMajor":1,"ProtoMinor":1,"Header":{"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8"],"Accept-Encoding":["gzip, deflate"],"Accept-Language":["en-US,en;q=0.9"],"Connection":["keep-alive"],"Upgrade-Insecure-Requests":["1"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.119 Safari/537.36"]},"ContentLength":0,"TransferEncoding":null,"Host":"andyndev2016","Form":null,"PostForm":null,"MultipartForm":null,"Trailer":null,"RemoteAddr":"10.1.1.4:53058","RequestURI":"/Web","TLS":null}"
time="2018-01-26T17:29:21Z" level=info msg="vulcand/oxy/forward/http: Round trip: http://AndyNDev2016:8081/, code: 404, Length: 0, duration: 499.0006ms"
time="2018-01-26T17:29:21Z" level=debug msg="vulcand/oxy/forward/http: completed ServeHttp on request" Request="{"Method":"GET","URL":{"Scheme":"http","Opaque":"","User":null,"Host":"AndyNDev2016:8081","Path":"/","RawPath":"","ForceQuery":false,"RawQuery":"","Fragment":""},"Proto":"HTTP/1.1","ProtoMajor":1,"ProtoMinor":1,"Header":{"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8"],"Accept-Encoding":["gzip, deflate"],"Accept-Language":["en-US,en;q=0.9"],"Connection":["keep-alive"],"Upgrade-Insecure-Requests":["1"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.119 Safari/537.36"]},"ContentLength":0,"TransferEncoding":null,"Host":"andyndev2016","Form":null,"PostForm":null,"MultipartForm":null,"Trailer":null,"RemoteAddr":"10.1.1.4:53058","RequestURI":"/Web","TLS":null}"
time="2018-01-26T17:29:21Z" level=debug msg="vulcand/oxy/forward: competed ServeHttp on request" Request="{"Method":"GET","URL":{"Scheme":"http","Opaque":"","User":null,"Host":"AndyNDev2016:8081","Path":"/","RawPath":"","ForceQuery":false,"RawQuery":"","Fragment":""},"Proto":"HTTP/1.1","ProtoMajor":1,"ProtoMinor":1,"Header":{"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8"],"Accept-Encoding":["gzip, deflate"],"Accept-Language":["en-US,en;q=0.9"],"Connection":["keep-alive"],"Upgrade-Insecure-Requests":["1"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.119 Safari/537.36"]},"ContentLength":0,"TransferEncoding":null,"Host":"andyndev2016","Form":null,"PostForm":null,"MultipartForm":null,"Trailer":null,"RemoteAddr":"10.1.1.4:53058","RequestURI":"/Web","TLS":null}"
time="2018-01-26T17:29:21Z" level=debug msg="vulcand/oxy/roundrobin/rebalancer: competed ServeHttp on request" Request="{"Method":"GET","URL":{"Scheme":"","Opaque":"","User":null,"Host":"","Path":"/Web","RawPath":"","ForceQuery":false,"RawQuery":"","Fragment":""},"Proto":"HTTP/1.1","ProtoMajor":1,"ProtoMinor":1,"Header":{"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8"],"Accept-Encoding":["gzip, deflate"],"Accept-Language":["en-US,en;q=0.9"],"Connection":["keep-alive"],"Upgrade-Insecure-Requests":["1"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.119 Safari/537.36"]},"ContentLength":0,"TransferEncoding":null,"Host":"andyndev2016","Form":null,"PostForm":null,"MultipartForm":null,"Trailer":null,"RemoteAddr":"10.1.1.4:53058","RequestURI":"/Web","TLS":null}"
10.1.1.4 - - [26/Jan/2018:17:29:21 +0000] "GET /Web HTTP/1.1" 404 0 - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.119 Safari/537.36" 304 "fabric:/TodoApp/TodoApi" "http://AndyNDev2016:8081/" 499ms

@jjcollinge
Copy link
Owner

@AndyWNorris - Just clarify what you're trying to achieve:
/api/index --> /api/todo (to match against the Web API controller backend)
/web --> / (to match against the MVC root)

I couldn't reproduce your issue - but if I have understood your intent correctly - I have verified the setup below works:

MVC App
Will match on /web, then strip this prefix and forward to the backends on / - NOTE no static assets (js,css, images) will render correctly as the browser will try to download them from the root / path. Traefik passes the stripped prefix (/web) in a header to the backend so that you can dynamically update your static paths to correctly load.

<StatelessServiceType ServiceTypeName="todoMVCType">
      <Extensions>
        <Extension Name="Traefik">
          <Labels xmlns="http://schemas.microsoft.com/2015/03/fabact-no-schema">
            <Label Key="traefik.frontend.rule.web">PathPrefixStrip: /web </Label>
            <Label Key="traefik.expose">true</Label>
            <Label Key="traefik.frontend.passHostHeader">true</Label>
          </Labels>
        </Extension>
      </Extensions>
    </StatelessServiceType>
  </ServiceTypes>

Web API
Will match on /api/index, strip the prefix and then add a new prefix of /api/todo before sending to the Web API backend controller listening on /api/todo.

<StatelessServiceType ServiceTypeName="todoAPIType">
      <Extensions>
        <Extension Name="Traefik">
          <Labels xmlns="http://schemas.microsoft.com/2015/03/fabact-no-schema">
            <Label Key="traefik.frontend.rule.match">PathPrefixStrip: /api/index</Label>
            <Label Key="traefik.frontend.rule.modify">AddPrefix: /api/todo</Label>
            <Label Key="traefik.expose">true</Label>
            <Label Key="traefik.frontend.passHostHeader">true</Label>
          </Labels>
        </Extension>
      </Extensions>
    </StatelessServiceType>
  </ServiceTypes>

This is loaded as below
tra

If this is not the scenario you are trying to satisfy could you please clarify what your intention is.
Hope this helps.

@AndyWNorris
Copy link
Author

Hi Joni,
That is both my scenario and a fix :)

Many thanks for your help.

Andy

@jjcollinge
Copy link
Owner

jjcollinge commented Jan 30, 2018

No worries :) - closing issue.

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

No branches or pull requests

3 participants