List routes’ priorities

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