# Illustrative Istio EnvoyFilter v3 API example; NOT an installed OBRH manifest.
# Reconcile the existing filter instead of installing a second local limiter.
# Intended scope: the HTTP inbound listener of each matching Pod Envoy.
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
  name: example-obrh-local-rate-limit
  namespace: obrh-example
spec:
  workloadSelector:
    labels:
      app: obrh-direct-example
  configPatches:
  - applyTo: HTTP_FILTER
    match:
      context: SIDECAR_INBOUND
      listener:
        portNumber: 8080
        filterChain:
          filter:
            name: envoy.filters.network.http_connection_manager
            subFilter:
              name: envoy.filters.http.router
    patch:
      operation: INSERT_BEFORE
      value:
        name: envoy.filters.http.local_ratelimit
        typed_config:
          '@type': type.googleapis.com/envoy.extensions.filters.http.local_ratelimit.v3.LocalRateLimit
          stat_prefix: obrh_local_admission
          # One proxy-process bucket, not a quota shared by replicas.
          local_rate_limit_per_downstream_connection: false
          token_bucket:
            max_tokens: 100 # Illustrative initial/burst allowance.
            tokens_per_fill: 100 # Illustrative refill, not a concurrency setting.
            fill_interval: 1s
          filter_enabled:
            runtime_key: obrh_local_admission_enabled
            default_value:
              numerator: 100
              denominator: HUNDRED
          filter_enforced:
            runtime_key: obrh_local_admission_enforced
            default_value:
              numerator: 100
              denominator: HUNDRED
# This simple example intentionally has no URL/group descriptors.
# Preserve existing descriptor buckets/actions when adapting the real policy.
# INSERT_BEFORE router alone does not prove placement before a body-buffer filter.
# Verify actual filter order; choose the intended pre-buffer admission placement.
