Io.l5d.path identifier with variable number of segments?

Hi,

I need to route incoming requests based on paths:

/service1 -> should go to service1
/sub/{service} -> should go to the service identified in the second segment.

Can this somehow be done using io.l5d.path? I can do it using io.l5d.methodAndHost but I’m worried about the performance warning in the documentation.

If it’s relevant, I’m using a io.l5d.consul namer.

Thanks,
Dejan

Hi @dejan! Yep, this can be done via the path identifier.
You would need to configure it with segments: 2, and add a dtab rule, so something like this:

- protocol: http
  identifier:
    kind: io.l5d.path
    segments: 2
  dtab: |
    /svc=>/#/io.l5d.consul/dc1;
    /http=>/svc;
    /http/sub=>/svc;
  servers:
  - port: 4140
    ip: 0.0.0.0

(For more on how these rules work, see https://linkerd.io/1/advanced/dtabs/)
You can visit the linkerd dtab playground at http://(location of admin ui)/delegator and test these rules out.
Hope that helps!

Hey @marzipan, thanks for the reply. I tried this, but I got an error when invoking /service1 “not enough segments in path”.

I would need something that supports both /service1 and /sub/{service}

Dejan

Ah right! The identifier section can take a list of identifiers, so I think you’ll need to list both a path identifier with segments: 1 and another with segments: 2, e.g.

  identifier:
    - kind: io.l5d.path
      segments: 2
    - kind: io.l5d.path
      segments: 1

Also, I noticed that I’d used http as the prefix in my example, but if you don’t specify a dstPrefix, the default prefix is /svc. So something like the following should work:

routers:
- protocol: http
  label: test
  identifier:
    - kind: io.l5d.path
      segments: 2      
    - kind: io.l5d.path
      segments: 1
  dtab: |
    /svc=>/#/io.l5d.consul/dc1;
    /svc/sub=>/svc/{yourservice};
  servers:
  - port: 4140
    ip: 0.0.0.0

Having two identifiers solved the problem, thanks a lot!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.