Score:0

nginx-ingress controller redirect with query parameter with a period in it

br flag

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
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.