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

tracing: enhance custom tags source #8279

Merged
merged 52 commits into from Dec 3, 2019
Merged

tracing: enhance custom tags source #8279

merged 52 commits into from Dec 3, 2019

Conversation

yittg
Copy link
Contributor

@yittg yittg commented Sep 18, 2019

Signed-off-by: Yi Tang ssnailtang@gmail.com

Description:

  • Support to set custom tag from literal string, environment, request header, and metadata associated with request and route in tracing.
  • Support to config custom tags at the route level also, which would be merged with the connection manager tracing configuration before applied. The former takes priority if configured with the same tag.

Deprecated:

  • The request_headers_for_tags field in HTTP connection manager has been deprecated in favor of the custom_tags field.

Risk Level: Medium
Testing: unit test
Docs Changes: proto docs
Fixes #8224

@repokitteh-read-only
Copy link

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

🐱

Caused by: #8279 was synchronize by yittg.

see: more, trace.

Copy link
Contributor

@objectiser objectiser left a comment

Choose a reason for hiding this comment

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

From a quick look, it seems like a good start. Couple of general points:

  1. Could you rename the field from additional_tags to custom_tags - so the name of the field and type is consistent.
  2. Sampling config can now also be set at the route level - not necessarily for this PR, but might also be good to consider whether we want these custom tags to also be configurable at that level. If so - we need to decide how the route level custom tags are handled - probably override/merge based on whether common tag names are used.

@yittg
Copy link
Contributor Author

yittg commented Sep 18, 2019

@objectiser thanks.

  1. Could you rename the field from additional_tags to custom_tags - so the name of the field and type is consistent.

Fixed.

  1. Sampling config can now also be set at the route level - not necessarily for this PR, but might also be good to consider whether we want these custom tags to also be configurable at that level. If so - we need to decide how the route level custom tags are handled - probably override/merge based on whether common tag names are used.

I'll have a look.

@zuercher
Copy link
Member

@snowp can you have a look?

Copy link
Contributor

@snowp snowp 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 looks reasonable to me.

source/common/config/filter_json.cc Outdated Show resolved Hide resolved
source/common/json/config_schemas.cc Outdated Show resolved Hide resolved
@yittg yittg changed the title tracing: enhance additional tags source tracing: enhance custom tags source Sep 19, 2019
@yittg
Copy link
Contributor Author

yittg commented Sep 20, 2019

ping @snowp , would you have another look please?

snowp
snowp previously requested changes Sep 20, 2019
Copy link
Contributor

@snowp snowp left a comment

Choose a reason for hiding this comment

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

Thanks for iterating on this! Definitely moving in the right direction

api/envoy/api/v2/route/route.proto Outdated Show resolved Hide resolved
api/envoy/api/v2/route/route.proto Outdated Show resolved Hide resolved
include/envoy/tracing/http_tracer.h Outdated Show resolved Hide resolved
source/common/http/conn_manager_impl.cc Outdated Show resolved Hide resolved
source/common/http/conn_manager_impl.cc Outdated Show resolved Hide resolved
source/common/http/conn_manager_impl.cc Outdated Show resolved Hide resolved
source/common/tracing/http_tracer_impl.cc Outdated Show resolved Hide resolved
api/envoy/api/v2/route/route.proto Outdated Show resolved Hide resolved
test/common/http/conn_manager_impl_test.cc Outdated Show resolved Hide resolved
@mattklein123 mattklein123 self-assigned this Sep 23, 2019
Copy link
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 for working on this. Flushing out some API level comments. Let's nail that first and then we can move on to code review. Also please merge mater to pick up the new formatter tooling.

/wait

@yittg
Copy link
Contributor Author

yittg commented Sep 25, 2019

thanks @mattklein123 , maybe we should new a PR for the API(protos) change first, then do the implementation?

@mattklein123
Copy link
Member

thanks @mattklein123 , maybe we should new a PR for the API(protos) change first, then do the implementation?

I think it's fine to do it in this PR, but let's lock down the API first even if CI is not passing.

/wait

@kyessenov
Copy link
Contributor

Should we also expose ability to set tags from dynamic metadata from the node, route, or route entry?

@yittg
Copy link
Contributor Author

yittg commented Sep 26, 2019

@kyessenov @mandarjog I think you are describing the same point, both for some kind of dynamic metadata?

Copy link
Contributor

@objectiser objectiser left a comment

Choose a reason for hiding this comment

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

Looking good - thanks for all the hard work on this!

// environment variable name to obtain the value to populate the tag value.
string name = 1 [(validate.rules).string = {min_bytes: 1}];

// used to populate the tag value is the environment variable is not found.
Copy link
Contributor

Choose a reason for hiding this comment

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

"value if the ..."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

}

// RouteMetadata type custom tag with namespace, path, and default value.
message RouteMetadata {
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like an exact copy of the RequestMetadata - would be better to just have message Metadata and use for both request_metadata and route_metadata fields below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

unified

string default_value = 4;
}

reserved 2, 3;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are these reserved when this is a new proto message?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

EnvironmentCustomTag::EnvironmentCustomTag(const std::string& tag, const std::string& name,
const std::string& default_value)
: DynamicCustomTag(tag, default_value), name_(name) {}
absl::string_view EnvironmentCustomTag::obtainValue(const CustomTagContext&) const {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: line above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

outdated

const std::string& default_value)
: DynamicCustomTag(tag, default_value), name_(name) {}
absl::string_view EnvironmentCustomTag::obtainValue(const CustomTagContext&) const {
return std::getenv(name_.data());
Copy link
Contributor

Choose a reason for hiding this comment

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

Might want to only call this on initialisation, rather than per request - to avoid unnecessary system call. This was raised as a point on the istio P&T call when discussing this feature - to ensure it is as efficient as possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

@yittg yittg closed this Sep 27, 2019
@yittg yittg reopened this Sep 27, 2019
Copy link
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, looking good. Flushing out some high level API/interface comments.

/wait

// environment variable name to obtain the value to populate the tag value.
string name = 1 [(validate.rules).string = {min_bytes: 1}];

// used to populate the tag value if the environment variable is not found.
Copy link
Member

Choose a reason for hiding this comment

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

Should this be required? If not, what is the behavior if this is empty? Does the tag get populated with an empty value? Not populated? Please document.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

commented

// request header name to obtain the value to populate the tag value.
string name = 1 [(validate.rules).string = {min_bytes: 1}];

// used to populate the tag value if the name is not found in request header map.
Copy link
Member

Choose a reason for hiding this comment

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

Same comment here as above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

commented

message TracingCustomTag {
// Literal type custom tag with literal value for tag value.
message Literal {
// literal value to populate the tag value.
Copy link
Member

Choose a reason for hiding this comment

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

nit: Please use proper grammar for all doc comments including starting sentence with a capital letter. Same elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

// specify the separator for the full path.
string path_separator = 3;

// used to populate the tag value if no metadata found.
Copy link
Member

Choose a reason for hiding this comment

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

Same comment here as above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

commented

include/envoy/router/router.h Outdated Show resolved Hide resolved
string default_value = 2;
}

// Metadata type custom tag with namespace, path, and default value.
Copy link
Member

Choose a reason for hiding this comment

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

Can you flesh out the docs for this including potentially a full YAML example? It's confusing to me with these docs to understand how this actually works, what path is, path_separator, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

documented.

Signed-off-by: Yi Tang <ssnailtang@gmail.com>
Copy link
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 looks good. Few more comments.

/wait

Copy link
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

@envoyproxy/api-shepherds API LGTM

Signed-off-by: Yi Tang <ssnailtang@gmail.com>
Signed-off-by: Yi Tang <ssnailtang@gmail.com>
Signed-off-by: Yi Tang <ssnailtang@gmail.com>
Signed-off-by: Yi Tang <ssnailtang@gmail.com>
Signed-off-by: Yi Tang <ssnailtang@gmail.com>
Signed-off-by: Yi Tang <ssnailtang@gmail.com>
Copy link
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, LGTM with 2 small comments.

/wait

@@ -33,6 +33,14 @@ parseHttpConnectionManagerFromV2Yaml(const std::string& yaml) {
return http_connection_manager;
}

envoy::config::filter::network::http_connection_manager::v2::HttpConnectionManager
parseHttpConnectionManagerFromV2YamlAndValidate(const std::string& yaml) {
Copy link
Member

Choose a reason for hiding this comment

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

Sorry I meant for you to just change the previous parseHttpConnectionManagerFromV2Yaml to always validate vs. add a new function. Can you do that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I can't, or it should be done in another PR, some other case will fail by validating

Copy link
Member

Choose a reason for hiding this comment

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

OK no problem, let's do this in a follow up please. Can you add a TODO?

@@ -1346,15 +1346,15 @@ void ConnectionManagerImpl::ActiveStream::refreshCachedTracingCustomTags() {
if (!connection_manager_.config_.tracingConfig()) {
return;
}
Tracing::CustomTagMap& customTagMap = getOrMakeTracingCustomTagMap();
Tracing::CustomTagMap& custom_tag_map = getOrMakeTracingCustomTagMap();
Copy link
Member

Choose a reason for hiding this comment

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

In many cases there will be no custom tags. Can we avoid creating the map until we know there are custom tags on the route or HCM level below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I did like it before IIRC :), I'll add it back.
PS, checking the tracing config before all even though there are custom tags on the route level is needed, the tracing will be processed only when tracing in HCM configured.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Signed-off-by: Yi Tang <ssnailtang@gmail.com>
Copy link
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.

Awesome work. 2 small comments and let's ship!

/wait

if (hasCachedRoute() && cached_route_.value()->tracingConfig()) {
route_tags = &cached_route_.value()->tracingConfig()->getCustomTags();
}
bool configured_in_conn = !conn_manager_tags.empty();
Copy link
Member

Choose a reason for hiding this comment

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

nit: const here and next line

@@ -33,6 +33,14 @@ parseHttpConnectionManagerFromV2Yaml(const std::string& yaml) {
return http_connection_manager;
}

envoy::config::filter::network::http_connection_manager::v2::HttpConnectionManager
parseHttpConnectionManagerFromV2YamlAndValidate(const std::string& yaml) {
Copy link
Member

Choose a reason for hiding this comment

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

OK no problem, let's do this in a follow up please. Can you add a TODO?

Signed-off-by: Yi Tang <ssnailtang@gmail.com>
Signed-off-by: Yi Tang <ssnailtang@gmail.com>
@yittg
Copy link
Contributor Author

yittg commented Dec 3, 2019

/retest

@repokitteh-read-only
Copy link

🙀 Error while processing event:

evaluation error
error: function error error: user: combined status is failure, but no failed builds.
🐱

Caused by: a #8279 (comment) was created by @yittg.

see: more, trace.

Copy link
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!

@repokitteh-read-only repokitteh-read-only bot removed the api label Dec 3, 2019
@mattklein123 mattklein123 merged commit 222890c into envoyproxy:master Dec 3, 2019
@yittg yittg deleted the tracing-additional-tags branch December 3, 2019 22:53
@yittg
Copy link
Contributor Author

yittg commented Dec 3, 2019

Thank you all for your help in the long way, :) .

@objectiser
Copy link
Contributor

Great job @yittg !

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.

Allow setting a list of constant tags for Tracing
9 participants