List routes’ priorities

As the whole rule length / priority / offset thing has long been a source of confusion (e.g. https://github.com/containous/traefik/issues/1962 ) there really should be a way to get a dump of all the rules / routes ordered by priority, so it’s easier to see what’s going where. I can’t find this anywhere. Is it possible to get it out of the logs?

2 Likes

This would be VERY helpful (maybe display it in the UI?)

1 Like

Hello @agilezebra,

There is no mechanism provided by Traefik.

I found some Github issues that can be related to this need:

If you need that, as workaround, you can use the API to fetch and extract the data from the router's configuration. The algorithm is: priority = router.priority || len(router.rule)

2 Likes

I spent a few minutes to make a little one-liner for this, requires curl,jq and the api enabled:
edit: prettied it up using the right endpoint instead of rawdata

curl -sk https://localhost/api/http/routers | jq '[.[]|{name:.name,rule:.rule,priority:(.priority//.rule|length)}]|sort_by(.priority)|reverse' 
unchanged data
curl -sk https://localhost/api/rawdata | jq '[.routers|to_entries[]| {router:.key,rule:.value.rule,priority:.value.priority}]'
[
  {
    "router": "api@docker",
    "rule": "PathPrefix(`/api`) || PathPrefix(`/dashboard`)",
    "priority": null
  },
  {
    "router": "m@docker",
    "rule": "Host(`mine.bar.com`)",
    "priority": null
  },
  {
    "router": "w@docker",
    "rule": "Host(`foo.bar.com`)",
    "priority": null
  },
  {
    "router": "y@docker",
    "rule": "Host(`y.bar.com`)",
    "priority": 30
  }
]
calculated priority
curl -sk https://localhost/api/http/routers | jq '[.[]|{name:.name,rule:.rule,priority:(.priority//.rule|length)}]|sort_by(.priority)|reverse'
  {
    "router": "api@docker",
    "rule": "PathPrefix(`/api`) || PathPrefix(`/dashboard`)",
    "priority": 46
  },
  {
    "router": "y@docker",
    "rule": "Host(`y.bar.com`)",
    "priority": 30
  },
  {
    "router": "m@docker",
    "rule": "Host(`mine.bar.com`)",
    "priority": 20
  },
  {
    "router": "w@docker",
    "rule": "Host(`foo.bar.com`)",
    "priority": 19
  }
]
4 Likes

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