This solution from Martin seems to be exactly what I need:
1- If only /prometheus is provided (which is originally the listen_path), then I need rewrite to /prometheus/graph
2- If anything else is provided, like /prometheus/graph or /prometheus/alerts-> rewrite to /prometheus/$1.
"proxy": {
"listen_path": "/prometheus/",
"preserve_host_header": false,
"target_url": "http://tyk-tests-kube-prometheus-prometheus.tyk-tests.svc.cluster.local:9090/prometheus/",
"strip_listen_path": true,
"disable_strip_slash": false
},
This is how I’m defining url_rewrites:
"extended_paths": {
"url_rewrites": [
{
"path": "/prometheus/",
"method": "GET",
"match_pattern": "prometheus",
"rewrite_to": "/graph/"
},
{
"path": "/prometheus/",
"method": "GET",
"match_pattern": "/prometheus/(\\w+)",
"rewrite_to": "$1"
}
]
},
Then, if just /prometheus is typed, goes to too many redirects loop.
If I manually hit /prometheus/graph, it works fine.