Skip to content

request_id_utils: add new extension system#10429

Merged
mattklein123 merged 45 commits intoenvoyproxy:masterfrom
euroelessar:request-id-utils
Mar 27, 2020
Merged

request_id_utils: add new extension system#10429
mattklein123 merged 45 commits intoenvoyproxy:masterfrom
euroelessar:request-id-utils

Conversation

@euroelessar
Copy link
Copy Markdown
Contributor

@euroelessar euroelessar commented Mar 18, 2020

Description: Allows for extensions to customize the behavior of Request ID manipulation. This replaces the UUIDUtils class and makes it generic. This makes it possible to customize how request IDs are used for tracing and logging.

Fixes #7624

Risk Level: Medium/High. Default behavior is kept the same but UUIDUtils are abstracted away.
Testing: Add unit tests
Docs Changes: Updated
Release Notes:

Ross Delinger and others added 13 commits February 23, 2020 19:37
…in issue envoyproxy#7624.

Signed-off-by: Ross Delinger <rossd@dropbox.com>
Signed-off-by: Ross Delinger <rossd@dropbox.com>
Signed-off-by: Ross Delinger <rossd@dropbox.com>
Signed-off-by: Ross Delinger <rossd@dropbox.com>
Signed-off-by: Ross Delinger <rossd@dropbox.com>
Signed-off-by: Ross Delinger <rossd@dropbox.com>
…utils

Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
…utils

Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
@repokitteh-read-only
Copy link
Copy Markdown

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to api/.

🐱

Caused by: #10429 was opened by euroelessar.

see: more, trace.

Ruslan Nigmatullin added 2 commits March 18, 2020 11:39
…utils

Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

At a high level this looks good. Flushing out some comments from a first pass. Thank you!

/wait

//
// 3. Tracing decision (sampled, forced, etc) is set in 14th byte of the UUID.

message UUIDConfig {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think we need a config for this. Can we just have this be the default class/impl that is loaded if there is no typed_config specified?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Any recommendation where should I put a documentation about the default behavior in that case? That and increasing amount of shared logic (between default and custom implementations) were main motivations for introduction of this proto package.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe just move the documentation above the typed_config field to explain what the behavior is if it's not set?

"Either routeConfigProvider or scopedRouteConfigProvider should be set in "
"ConnectionManagerImpl.");

stream_info_.setRequestIDUtils(connection_manager.config_.requestIDUtils());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why does stream info need the request ID utiltiies? I'm wondering if whatever stat it is being used for can be stored instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Looks like it's used in two cases:

  1. AccessLog::TraceableRequestFilter and ConnectionManagerImpl::ActiveStream to determine if request is traced (using Tracing::HttpTracerUtility)
  2. AccessLog::RuntimeFilter uses it for making deterministic logging sampling decision

Given that AccessLog instances are shared across all L4/L5 connection managers, and RequestIDUtils is configured on per-manager basis we need a side channel for passing this information.

I'm worried about preserving derivatives (boolean isTraced and raw sampling number) as they can become out of sync if request id is changed mid-flight. It doesn't look like any existing extensions currently do it though.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

OK fair enough I think that's fine.

Ruslan Nigmatullin added 2 commits March 18, 2020 16:10
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
CR
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>

void UUIDUtils::maybePreserveRequestIDInResponse(Http::ResponseHeaderMap& response_headers,
const Http::RequestHeaderMap& request_headers) {
if (request_headers.EnvoyForceTrace() && request_headers.RequestId()) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Alternatively check request_headers.EnvoyForceTrace() can be kept outside of this implementation. In that case we add a configuration option in separate pull request to allow always sending request ID header back even without forced tracing. This way we will be able omit "maybe" part of the method and keep if logic outside.

It's generally useful for correlating requests with client-side logs even if tracing itself is disabled for this particular request.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Agreed that makes sense to me and has been a requested feature before.

Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
// generation, validation, and associated tracing operations.
//
// If not set, Envoy uses the :ref:`default UUID-based behavior <extension_envoy.request_id_utils.uuid>`.
RequestIDUtils request_id_utils = 36;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Playing naming poker, I think something like RequestIdExtension is probably a better message/field name. The "utils" concept is strictly less descriptive.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure, can rename it. What's about relevant classes in code, should I keep them as is?

Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
@euroelessar
Copy link
Copy Markdown
Contributor Author

Something is wrong with circleci, why did it take 6 hours to run tests?..

Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thanks this is super awesome. Just some small comments and I think we can ship!

/wait

virtual void set(Http::RequestHeaderMap& request_headers) PURE;

/**
* Ensure that a request is configured with a request id. Do not override an ID if request has one
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1 let's merge set/ensure and just have a boolean param? I think that would be simpler to understand.

// 2. Request ID is a universally unique identifier (UUID).
//
// 3. Tracing decision (sampled, forced, etc) is set in 14th byte of the UUID.
RequestIDExtension request_id_extension = 36;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you add a release note about this? Potentially also update https://www.envoyproxy.io/docs/envoy/latest/extending/extending as well as maybe mention this extensibility somewhere in the HTTP/tracing arch docs?

namespace Envoy {
namespace Http {

class UUIDRequestIDExtension : public RequestIDExtension {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: small comment above that this is the default implementation if none is configured?


if (!request_headers.RequestId()) {
Http::RequestIDExtensionSharedPtr rid_extension = stream_info.getRequestIDExtension();
if (rid_extension == nullptr) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This can't happen, right? Or can it happen earlier in server load? If so maybe comment? It seems like maybe this should actually be a function call into the extension to check for something and this might be a bug?


"envoy.filters.udp_listener.udp_proxy": "//source/extensions/filters/udp/udp_proxy:config",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: revert since no file changes.

Ruslan Nigmatullin added 4 commits March 26, 2020 17:26
…utils

Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
fmt
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
Ruslan Nigmatullin added 3 commits March 26, 2020 19:42
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
@mattklein123
Copy link
Copy Markdown
Member

Thanks awesome work. Can you merge master again which should fix clang-tidy (and also fix any issues that show up as a result of that).

/wait

…utils

Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
@euroelessar
Copy link
Copy Markdown
Contributor Author

It looks like clang-tidy has either false-positive or unrelated errors, e.g. it complains about using throw at envoy/buffer/buffer.h (not touched by this pr), or about using virtual in virtual ~RequestIDExtensionFactory() = default; definition.

@mattklein123
Copy link
Copy Markdown
Member

The throw issue should be fixed. Did you fully merge orgin/master? cc @lizan

@euroelessar
Copy link
Copy Markdown
Contributor Author

euroelessar commented Mar 27, 2020

I've merged 913afb0, 4e16a37 is part of it

@mattklein123
Copy link
Copy Markdown
Member

OK I guess there is another issue here. cc @lizan

We can force merge if there is no real issue to fix.

Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thank you!!

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tracing: Make request id format and tracing behavior configurable

3 participants