# URL concurrency — add a named cluster and a route that selects it
# Documentation copy; all configuration values match the prepared POC manifest.
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
  name: poc-url-concurrency-ef
  namespace: "poc-iut-ns" # Workload selection is limited to this namespace.
spec:
  # Stable ordering; route-policy inheritance is not implied by this priority.
  priority: -10
  workloadSelector:
    labels:
      app: poc-cmc # Configure only these application sidecars.
  configPatches:
  - applyTo: CLUSTER # A cluster owns an upstream endpoint set and resource limits.
    match:
      context: SIDECAR_INBOUND # Patch application-side inbound configuration, not gateways.
    patch:
      operation: ADD # Create a separate Envoy cluster; no Kubernetes Service is created.
      value:
        name: debitCreditTxn-v2 # Cluster identifier referenced by route.cluster below.
        type: STATIC # Endpoint addresses are supplied explicitly in load_assignment.
        load_assignment: # Explicit endpoint membership for this cluster.
          cluster_name: debitCreditTxn-v2 # Associates this assignment with the cluster.
          endpoints: # Endpoint groups; a group may carry locality information.
          - lb_endpoints: # Hosts available to the cluster's load balancer.
            - endpoint:
                address:
                  socket_address:
                    address: 127.0.0.1 # Same Pod network namespace as the application.
                    port_value: 8080 # Same JVM endpoint as the ordinary inbound cluster.
        circuit_breakers: # Resource admission limits, not failure-based host ejection.
          thresholds: # Per routing priority; omitted priority means DEFAULT.
          - max_requests: 50 # Independent active-request allowance; not nested under 200.
  - applyTo: HTTP_ROUTE # A route matches requests and names a cluster; it is not a cluster.
    match:
      context: SIDECAR_INBOUND
      routeConfiguration: # Narrow the configuration objects receiving this patch.
        vhost:
          name: inbound|http|8080 # Select the existing inbound virtual host to patch.
    patch:
      operation: INSERT_FIRST # Specific match before the existing catch-all route.
      value:
        name: debitCreditTxn-v2 # Route identifier; matching the cluster name is optional.
        match:
          prefix: / # Any actual path, provided the exact URL-identity header also matches.
          headers:
          - name: "REQUEST-URL" # Read the trusted gateway-set API identity, after rewrite.
            string_match:
              exact: "/clearing-settlement/casa-payment-upi/debitCreditTxn/v2"
        route:
          cluster: debitCreditTxn-v2 # This reference selects the separately defined cluster.
          timeout: 0s # Disable this route timeout; other timeout mechanisms still apply.

          # Istio merges existing routes before inserting new ones. Carry the
          # enabled descriptor actions here; buckets remain in their own filters.
          rate_limits: # Route descriptor rules; these are not token-bucket definitions.

          - actions:
            - request_headers: # Read an existing header; do not add a new HTTP header.
                header_name: "REQUEST-URL"
                descriptor_key: path # Generate path=<header value> for the existing URL bucket.


          - actions:
            - request_headers: # Separate descriptor action for the existing group bucket.
                header_name: PRODUCT-PROCESSOR
                descriptor_key: pp # Generate pp=<header value>; bucket definitions stay separate.
