3

I was wondering if there's a way to perform multiple exact matches within envoy ? For e.g. interested in directing traffic to two different clusters based on a header attribute,

- match:
     prefix: "/service/2"
     headers:
     - name: X-SOME-TAG
       exact_match: "SomeString"

This works as expected but is it possible to specify a list of strings in a list to match against in exact_match e.g. exact_match: ["some_string", another"] ?

I can also write it as,

- match:
     prefix: "/service/2"
     headers:
     - name: X-SOME-TAG
       exact_match: "some_string"
  route:
    cluster: service1
- match:
     prefix: "/service/2"
     headers:
     - name: X-SOME-TAG
       exact_match: "another"
  route:
    cluster: service1

But not sure, if this is un-necessarily verbose and the right way.

Or do I have to use something like regex_match for this or patterns ?

Sorry, I just haven't been able to get this to work, testing with the example on the envoy documentation for front-proxies, hence figured would put this out there. Thanks!

Wytrzymały Wiktor
  • 11,492
  • 5
  • 29
  • 37
user1427026
  • 861
  • 2
  • 16
  • 32

2 Answers2

1

I'm not sure based on your question whether you want to AND the matches or OR them. If you want both to have to match (AND), both matches need to be under the same - match: section, otherwise, make them in seperate - match: sections. The second example you provided above would be the equivalent of an OR, i.e. "if X-SOME-TAG == "some_string" OR X-SOME-TAG == "another", route to service1.

Mike Breed
  • 511
  • 3
  • 4
1

You can try:

- match:
     prefix: "/service/2"
     headers:
     - name: X-SOME-TAG
       safe_regex_match:
         google_re2: {}
         regex: "some_string|another"
  route:
    cluster: service1
yuen26
  • 871
  • 11
  • 12