Skip to content

API: router HeaderMatch "present_match" field is a bool but value is ignored #14656

Closed

Description

@markdroth

The HeaderMatch present_match field is a boolean field, but Envoy does not actually use the field's value at all -- if the field is present in the oneof, then it unconditionally matches if the header is present, regardless of the value.

This means that if present_match=false, it matches when the header is present, which is extremely counter-intuitive. And the behavior is certainly not obvious to someone reading the proto file. In gRPC, we assumed that because it's a boolean field that the value actually mattered, so we implemented it such that if the value is false, the match is true only if the header is not present. This means that Envoy and gRPC are behaving differently here.

@htuch did some digging for me and found that this field was added in #3443, at the same time as the invert_match field. Perhaps the thinking was that since there was a separate way to invert any match type, setting present_match (to any value) and invert_match=true is the right way to match on the absence of a field. However, in that case, it would have made more sense for the present_match field to be of type google.protobuf.Empty instead of being a boolean.

I think we need to choose one of the following options:

  1. Define the correct behavior as gRPC's behavior. This is a boolean field, which means that a value of false indicates that the header must be absent (which means that {present_match=false, invert_match=true} is the same as {present_match=true, invert_match=false}). In this case, we can simply change Envoy's implementation to match gRPC's, and no API changes are needed.

  2. Define the correct behavior as Envoy's behavior. In this case, the API is wrong, and we should deprecate the existing present_match field and replace it with a new one with type google.protobuf.Empty, so that the semantics are no longer confusing.

I'd ideally like to go with (1), because it's less work overall and leaves us with less API cruft. But I don't know what the risk of breaking existing users is, because I don't know if anyone is actually setting this field to false and relying on the existing behavior.

CC @envoyproxy/api-shepherds @voidzcy @menghanl @ashithasantosh

Activity

  1. added
    triage
    on Jan 11, 2021
  2. htuch commented on Jan 12, 2021

    @htuch
    Member

    I would argue (1) is fine, CC @gumpt @mattklein123

  3. added and removed
    triage
    on Jan 12, 2021
  4. mattklein123 commented on Jan 12, 2021

    @mattklein123
    Member

    I think this is just a bug in that the field is missing a validation that forces it to always be true (which is a pattern we have elsewhere versus using Empty but is semantically the same). I don't have a strong opinion. I think (1) is fine, or we can just add a force true validation to the proto which IMO doesn't require a deprecation because it was probably the implied mode of operation.

  5. changed the title [-]API: router HeaderMatch "present" field is a bool but value is ignored[/-] [+]API: router HeaderMatch "present_match" field is a bool but value is ignored[/+] on Jan 12, 2021
  6. markdroth commented on Jan 12, 2021

    @markdroth
    ContributorAuthor

    Using a bool with a validation that forces it to be true seems like an anti-pattern to me. I think that someone reading the API should be able to understand the semantics from the type, and bool implies that there are two possible values, not just one. I think that using Empty is much cleaner for this kind of case.

    Anyway, if we all think that (1) is fine, then let's just go with that. Thanks!

  7. mattklein123 commented on Jan 12, 2021

    @mattklein123
    Member

    Using a bool with a validation that forces it to be true seems like an anti-pattern to me. I think that someone reading the API should be able to understand the semantics from the type, and bool implies that there are two possible values, not just one. I think that using Empty is much cleaner for this kind of case.

    I think you are right, but for better or worse that is not what has been done so far.

  8. htuch commented on Jan 13, 2021

    @htuch
    Member

    @markdroth are you signing up to adjust Envoy's behavior here? :)

  9. soulxu commented on May 22, 2021

    @soulxu
    Member

    @markdroth @htuch I worked out a PR for this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions