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

Allow setting custom_tags for traces #4181

Closed

Conversation

psalaberria002
Copy link
Contributor

@psalaberria002 psalaberria002 commented Apr 1, 2022

It allows setting trace tags based on literal values, environment variables, or request headers.

Based on https://www.envoyproxy.io/docs/envoy/latest/api-v3/type/tracing/v3/custom_tag.proto#custom-tag

tag_headers should be deprecated in favor of custom_tags. I haven't worked with CRDs and field deprecations. What's the procedure?

When it comes to updating the documentation, where is that handled? I cannot find any reference to TracingService inside the docs folder.

@psalaberria002 psalaberria002 force-pushed the custom-tags branch 2 times, most recently from 8543df2 to c89902e Compare April 1, 2022 13:16
@psalaberria002
Copy link
Contributor Author

I have experimented with a couple of alternatives, and I am not sure which one if preferred.

Option 1: Custom conversions

When storing from v3alpha1 into v2, convert DeprecatedTagHeaders into custom tags and append to CustomTags,
and store as v2 v3CustomTags.

When reading back from v2 to v3alpha1, convert TagHeaders into custom tags and append to v3CustomTags,
then copy that into v3alpha1 CustomTags.

Whatever you put in v3alpha1 goes cleanly into v2, but when converting it back again to v3alpha1 the objectdoes not have the exact same data. The v3alpha1 DeprecatedTagHeaders will always be empty.

Option 2: No need for custom conversions

v2 TagHeaders <-> v3alpha1 DeprecatedTagHeaders
v2 V3CustomTags <-> v3alpha1 CustomTags

Whatever you put in v3alpha1 goes cleanly into v2, and when converting it back again to v3alpha1 the object has the exact same data. The TestConvert fn in conversion_test.go assumes this behavior.

@LukeShu LukeShu requested review from LukeShu and removed request for LukeShu April 19, 2022 19:42
@kflynn
Copy link
Member

kflynn commented May 9, 2022

Hey @psalaberria002! As I understand it:

  • Any TagHeader can be expressed as a CustomHeader, but not the other way around; and
  • Transforming a TagHeader to a CustomHeader is trivial and mechanical.

That implies to me that the best answer here is:

  • v3alpha1 should consider TagHeader to be deprecated

    • if only CustomHeader is set, great
    • if only TagHeader is set, translate to CustomHeader
    • if both TagHeader and CustomHeader are set, log a warning, ignore TagHeader, and use CustomHeader
    • you should rename the TagHeader field internally to DeprecatedTagHeader, but leave the JSON tag as TagHeader
  • v2 should gain a V3CustomHeader field, used only for translations

  • When translating from v3alpha1 to v2:

    • the v3alpha1 CustomHeader field should be saved unaltered as the v2 V3CustomHeader field
  • When translating from v2 to v3alpha1:

    • if v2 V3CustomHeader is set, it should be copied unaltered to v3alpha1 CustomHeader
    • otherwise, if v2 TagHeader is set, it should be translated to v3alpha1 CustomHeader
    • the translation code must never set v3alpha1 DeprecatedTagHeader
  • In v3 final, the DeprecatedTagHeader field will go away.

How does that sound?

@psalaberria002 psalaberria002 force-pushed the custom-tags branch 4 times, most recently from e8da8d9 to 3a8684f Compare May 9, 2022 19:02
@psalaberria002
Copy link
Contributor Author

Hey @psalaberria002! As I understand it:

  • Any TagHeader can be expressed as a CustomHeader, but not the other way around; and
  • Transforming a TagHeader to a CustomHeader is trivial and mechanical.

That implies to me that the best answer here is:

  • v3alpha1 should consider TagHeader to be deprecated

    • if only CustomHeader is set, great
    • if only TagHeader is set, translate to CustomHeader
    • if both TagHeader and CustomHeader are set, log a warning, ignore TagHeader, and use CustomHeader
    • you should rename the TagHeader field internally to DeprecatedTagHeader, but leave the JSON tag as TagHeader
  • v2 should gain a V3CustomHeader field, used only for translations

  • When translating from v3alpha1 to v2:

    • the v3alpha1 CustomHeader field should be saved unaltered as the v2 V3CustomHeader field
  • When translating from v2 to v3alpha1:

    • if v2 V3CustomHeader is set, it should be copied unaltered to v3alpha1 CustomHeader
    • otherwise, if v2 TagHeader is set, it should be translated to v3alpha1 CustomHeader
    • the translation code must never set v3alpha1 DeprecatedTagHeader
  • In v3 final, the DeprecatedTagHeader field will go away.

How does that sound?

Makes sense. I have tried to follow that approach in the last commit. It would be nice to have CI for this PR :)

@LanceEa
Copy link
Contributor

LanceEa commented Jun 7, 2022

@psalaberria002 - Thanks for being patient on this. With the recent release master has diverged quite a bit. Can you please rebase this back on master and push it. I will then get CI running on it.

Note: it's probably good to run git fetch origin --prune to ensure you are not holding onto any old refs for master before re- pulling it. I had that issue ☹️ .

@psalaberria002
Copy link
Contributor Author

Already pulled from master, cherry picked my change, and force pushed.

Copy link
Contributor

@LanceEa LanceEa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@psalaberria002 - it looks pretty good and seems to line up with the discussion between Flynn and you.

I have a few open items I want to check with the team to make sure I understand historical context and a left a few nits as well.

We may want a pytest/kat test for when both req_hdrs and custom_tags but let me find out more on whether that is necessary.

@LanceEa
Copy link
Contributor

LanceEa commented Jul 5, 2022

@psalaberria002 - lets get this rebased on master and update the release notes so that it will land on the upcoming 3.1.0 release. Once that is done I will pull it in and get CI running to make sure all is still green. I want to get a second review from one of the teammates as well.

Again thanks for the patience on this.

@psalaberria002
Copy link
Contributor Author

@psalaberria002 - lets get this rebased on master and update the release notes so that it will land on the upcoming 3.1.0 release. Once that is done I will pull it in and get CI running to make sure all is still green. I want to get a second review from one of the teammates as well.

Again thanks for the patience on this.

Rebased. I am not able to run tests locally. It would be great if you could run this in CI.

Copy link
Contributor

@LanceEa LanceEa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple final last nits and then I'm all good. If you could make those changes and then I will pull them in, verify CI is still green and we can get this merged!

Thanks for all the help and putting up with the painful process!

docs/releaseNotes.yml Outdated Show resolved Hide resolved
pkg/api/getambassador.io/v2/handwritten.conversion.go Outdated Show resolved Hide resolved
StatsName string `json:"stats_name,omitempty"`
Service string `json:"service,omitempty"`
Sampling *TraceSampling `json:"sampling,omitempty"`
// tag_headers is deprecated. Use custom_tags instead.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks kubebuilder has no notion of deprecation validation so let's at least take advantage of Golangs doc comments for deprecated.

https://stackoverflow.com/questions/7849663/how-do-you-mark-code-as-deprecated-in-go

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is a little bit tricky. The comments endup in the CRD specs. The Deprecated convention in Go is for the struct fields, not the json fields. I am not sure if this is worth it. If so, can you write down here the expected comment string?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, the reason I suggested the Go Doc comment is that these objects can be used in the future where we have a transformation engine that is written in Go. This way if objects are being instantiated via Go code the IDE is going to yell you.

However, I was reading through the docs this morning and it looks like there is a deprecated special marker. It says on-type so it might not work on fields but ideally it can be applied to a field too.
https://book.kubebuilder.io/reference/markers/crd.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+kubebuilder:deprecatedversion doesn't seem to do anything on fields. I am gonna add the Go deprecation comment and use the json fields in the description since those are visible both in the CRD schema and the Go code.

It allows setting trace tags based on
literal values, environment variables, or request headers.

Based on https://www.envoyproxy.io/docs/envoy/latest/api-v3/type/tracing/v3/custom_tag.proto#custom-tag

Signed-off-by: Paul Salaberria <psalaberria002@gmail.com>
Signed-off-by: Paul Salaberria <psalaberria002@gmail.com>
Simplification in listener v3 to be tested.

Signed-off-by: Paul Salaberria <psalaberria002@gmail.com>
Signed-off-by: Paul Salaberria <psalaberria002@gmail.com>
Signed-off-by: Paul Salaberria <psalaberria002@gmail.com>
Signed-off-by: Paul Salaberria <psalaberria002@gmail.com>
Signed-off-by: Paul Salaberria <psalaberria002@gmail.com>
Signed-off-by: Paul Salaberria <psalaberria002@gmail.com>
Signed-off-by: Paul Salaberria <psalaberria002@gmail.com>
Signed-off-by: Paul Salaberria <psalaberria002@gmail.com>
@LanceEa
Copy link
Contributor

LanceEa commented Sep 21, 2022

@psalaberria002 - Landed this in #4268 per our discussion in slack. Closing this one out.

@LanceEa LanceEa closed this Sep 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants