Regex based matching in Istio Virtual Service StringMatch under HTTPRequestMatch

Hi Team, I am trying to create a Virtual Service and using a Regex in StringMatch for URI under HTTPMatchRequest.

But somehow I keep getting 404/302. Please see the below Virtual Service YAML file and logs from my gateway.

---
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: monitoring-prometheus-vs
  namespace: monitoring
spec:
  gateways:
  - istio-system/ing-gateway
  hosts:
  - '*'
  http:
  - match:
    - uri:
        regex: '\/prometheus\/*'
    rewrite:
      uri: /
    route:
    - destination:
        host: prometheus-ope-prometheus.monitoring.svc.cluster.local

Ingress Gateway Logs:

{"request_id":"09c6f1e8-6675-438f-a960-d26d90f1481b","authority":"******","method":"GET","path":"/prometheus","connection_termination_details":null,"response_code_details":"via_upstream","upstream_transport_failure_reason":null,"protocol":"HTTP/1.1","response_flags":"-","response_code":302,"duration":0,"upstream_cluster":"outbound|9090||prometheus-ope-prometheus.monitoring.svc.cluster.local","start_time":"2022-06-22T07:10:19.467Z","downstream_local_address":"10.205.54.56:8080","x_forwarded_for":"72.163.220.53,10.205.44.222","upstream_local_address":"10.205.54.56:52318","bytes_sent":40,"bytes_received":0,"upstream_service_time":"0","requested_server_name":null,"user_agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:101.0) Gecko/20100101 Firefox/101.0","upstream_host":"10.205.63.161:9090","route_name":null}

I am really struggling here, can someone please let me know what’s wrong? I have validated the regex and it matches what I need.

Hi,

Please share the istio proxy logs. Also it seems some redirection issues as per 302 code

Regards,
Kalyan

@puli_kalyanteja, I dont have an Istio Proxy sidecar enabled for this pod. The issue here is with regex based matching when I use prefix its working redirection is happening and I do get 200 as status code. But I am getting 302 when I move to regex.

Please update regex as ‘/prometheus/.*’ and let us know if it works. Key here add . before * in Prometheus regex

@puli_kalyanteja, I already tried but it does not work. But still, I see 302.