Repository navigation
Description
Title: Simple extension to add dynamic metadata
Description:
This extension simply allows to add user-defined dynamic metadata. This is intended to be used with matchers, so that the "result" of a matching process can imply specific metadata.
I have implemented a Proof-of-Concept of this here: curiefense@6fdd5c0
Here is a usage example: curiefense@26f8480#diff-e7b7df56dda737de6cebca4a1ebe1b9d391811c12d2ff1a782409a8d6f8e9f5dR42-R79
I would like some advices before going further:
-
as we can see here curiefense@26f8480#diff-e7b7df56dda737de6cebca4a1ebe1b9d391811c12d2ff1a782409a8d6f8e9f5dR50 , the user can describe a "key hierarchy". Said differently, we split the string with ".", and recursively lookup in the current metadata to get the actual value to modify. That might be more explicit with the code actually doing this: curiefense@6fdd5c0#diff-00ef507aad11d8c16a5ab4dc4eb28495d8b2da99453dc476af9675fcd2db040bR37-R43 . It works, the only issue is that you can't really match a key which has a dot in it. I haven't find any other places in envoy doing such a thing. My questions are: Is there a "recommended" way to get this behavior? If no, should I write a more "serious" parser that could handle something like "a.b".c ?
-
for the actual value, I use a
google.protobuf.Valueobject (curiefense@6fdd5c0#diff-bce37684028f001c3ab5e59114840a1ce519b9b35642fe87936cdb8ce022cd5cR26), so that it can handle everything JSON would handle.headers-to-metadatais doing something more complex, with an extra field for the type (which, IMO, is already handled bygoogle.protobuf.Value(https://github.com/envoyproxy/envoy/blob/main/api/envoy/extensions/filters/http/header_to_metadata/v3/header_to_metadata.proto#L69-L85). Should I do something similar for the sake of consistency?
Thanks for any insights!
Regards,
cc @snowp
Activity
snowp commentedon May 4, 2021
SGTM, happy to sponsor this. High level this sounds right, we can flesh out the details in PR reviews
For your first point I think you could achieve this nesting by having the API specify the Struct to set instead of a specific Value? That way you get more flexibility in setting multiple values, and solve the hierarchy issue. This raises some questions around wanting to have multiple filters set the same fields, but I think a simple merge -> last write wins mechanism would work well initially, with other merging strategies possible via configuration down the line.
aguinet commentedon May 5, 2021
I tried merging two struct objects with Protobuf's
Struct::mergeFromfunction, but it seems too aggressive for what we want to do.In our case, the example is for instance two matchers that would create unique tags. One way to describe this would something like this:
In this case,
MergeFromwould just replace the full content oftagswith the new subobject. For instance, if the two filters are executed, we end up with:whereas we would have liked:
I was thinking instead implementing a "recursive merge" behavior, where only the last values in the object tree are replaced if they already exists, with a proper documentation explaining what is happening.
I'm afraid this would make a specific behavior for this filter, which might be different from what currently exists in Envoy. What do you think?
Thanks!
Set-Metadata HTTP filter (#16400)
Set-Metadata HTTP filter (envoyproxy#16400)