Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to return different response code for different url or cluster in envoy #37996

Open
milocc opened this issue Jan 14, 2025 · 1 comment
Open
Labels
question Questions that are neither investigations, bugs, nor enhancements

Comments

@milocc
Copy link

milocc commented Jan 14, 2025

Description:
I have two clusters defined in envoy yaml, which are for two servers. They map to different url prefix. And they have their own health check logic. When the cluster is unhealthy, the requests will return error code 503. Now, I want envoy returns error code 501 for server2 when server2 is unhealthy. So user will receive 503 if server1 is unhealthy, and receive 501 if server2 is unhealthy.

- match:
    prefix: "/v1"
  route:
    cluster: server1
- match:
    prefix: "/v2"
  route:
    cluster: server2

I don't want do any changes to server2. I tried local_reply_config config, but it impacts both prefixes. Is there a way to get this ?

local_reply_config:
  mappers:
    - filter:
        status_code_filter:
          comparison:
            op: EQ
            value:
              default_value: 503
              runtime_key: key_b
      status_code: 501
@milocc milocc added the triage Issue requires triage label Jan 14, 2025
@agrawroh
Copy link
Contributor

You can try using CEL expressions via extension_filter [Ref]

You basically will have to use both the status_code_filter and extension_filter like below. I haven't tried the config so you might have to adjust it but you get the idea.

local_reply_config:
  mappers:
    - filter:
      and_filter:
        filters:
          - extension_filter:
              name: "envoy.filters.accesslog.cel"
              typed_config:
                "@type": "type.googleapis.com/envoy.extensions.access_loggers.filters.cel.v3.ExpressionFilter"
                expression: "(request.path == '/v2')"
          - status_code_filter:
              comparison:
                op: EQ
                value:
                  default_value: 503
                  runtime_key: key_b
        status_code: 501

A full list of attributes is listed here.

@yanavlasov yanavlasov added question Questions that are neither investigations, bugs, nor enhancements and removed triage Issue requires triage labels Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Questions that are neither investigations, bugs, nor enhancements
Projects
None yet
Development

No branches or pull requests

3 participants