0

I have the following url I want to redirect to another hostname but also change the query parameters if possible.

It's basically change a url for prometheus to work in grafana. So the prometheus url is

https://prom-to-grafana.foobar.com/graph?g0.expr=vector(1)&g0.range_input=1h&g0.tab=0

I need to extrace the g0.expr to use it in the following

https://grafana.foobar.com/explore?orgId=1&left={"datasource":"AbfTenkVk","queries":[{"expr":"vector(1)"}]}

Basically the vector(1) query ends up in the expr json blob for grafana.

I've tried something like

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: grafana-redirect
  annotations:
    nginx.ingress.kubernetes.io/use-forwarded-headers: "true"
    nginx.ingress.kubernetes.io/server-snippet: |          
        location ~* "^/graph.*" {
          rewrite ^/graph\?g0\.expr=(.*)\&g0.range_input(.*)$ "https://grafana.foobar.com/explore?orgId=1&left={\"datasource\":\"AbfTenkVk\",\"queries\":[{\"expr\":\"$1\"}]}" break;
        }
spec:
  ingressClassName: ingress-nginx
  rules:
    - host: prom-to-grafana.foobar.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: app
                port: 
                  name: api
Mike
  • 22,310
  • 7
  • 56
  • 79

0 Answers0