Skip to content
This repository was archived by the owner on Jun 28, 2022. It is now read-only.

Allow sending tags when building the HTTP request#40

Merged
morrisonlevi merged 3 commits into
mainfrom
levi/send-tags
Mar 31, 2022
Merged

Allow sending tags when building the HTTP request#40
morrisonlevi merged 3 commits into
mainfrom
levi/send-tags

Conversation

@morrisonlevi

@morrisonlevi morrisonlevi commented Mar 28, 2022

Copy link
Copy Markdown
Collaborator

What does this PR do?

Allow sending tags when building the HTTP request. Deduplicate tags and
prefer earlier tags from later tags.

Potentially, add FFI API for building tags dynamically.

Updates examples and clang-format's them, which is why the diff is large.

Motivation

For some clients, sending tags when the HTTP request is built is a more
natural place to do it than when the exporter is created. For others,
there are both static and dynamic tags and it's nice to have two places
to add tags so that you aren't forced to combine them.

Overall, I think it's much nicer this way.

Additional Notes

I will add an API for creating and managing Vec<Tag> later.

How to test the change?

You'll have to update the build calls to also have a slice of tags,
even if it's empty. Otherwise, it's the same as before.

@gleocadie gleocadie left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

Comment thread ddprof-exporter/src/lib.rs Outdated
for tag in self.tags.iter() {
form.add_text("tags[]", format!("{}:{}", tag.name, tag.value));
// Iterate over self.tags and additional_tags, only adding unique tag names.
let mut prev_tags = HashSet::with_capacity(self.tags.len() + additional_tags.len());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[Minor] Perhaps additional_tags should have precedence over self.tags

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 if I had not looked at the code, my expectation would be that the ones on the build override the previous ones. Silently using the old ones yet seems like a really sharp edge :)

@morrisonlevi morrisonlevi Mar 29, 2022

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

After looking around, it seems most tracers and other contexts like this use a hashmap and preserve the later one. However, in certain other contexts, duplicate tag names are fine.

Given this, I'm inclined to send everything and let the profiling backend decide what to do with it; it's also cheaper to not care here. FWIW, I sent state:utah,state:uh and both tags appeared in the Runtime Info tab.

@ivoanjo ivoanjo left a comment

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.

Came in last, added two minor notes :D

Comment thread ddprof-exporter/src/lib.rs Outdated
Comment on lines 34 to 44
/// All tags are optional. Here are the currently known tag names:
/// * service
/// * language
/// * env
/// * version
/// * host - the agent will overwrite this; only useful in practice if the
/// experimental agent-less mode is being used.
/// * language
/// * profiler_version
/// * runtime-id
/// * service
/// * version
/// Other tags may be used, such as the ones specified by the user in the
/// `DD_TAGS` env.

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.

Minor: It's not often that I advocate removing comments, but to be honest, by itself this description is so bare that I don't think it ends up being very helpful. So... I would just suggest removing it entirely. (The other alternative would be to improve the documentation here, but it also doesn't seem the right place to do it)

Comment thread ddprof-exporter/src/lib.rs Outdated
for tag in self.tags.iter() {
form.add_text("tags[]", format!("{}:{}", tag.name, tag.value));
// Iterate over self.tags and additional_tags, only adding unique tag names.
let mut prev_tags = HashSet::with_capacity(self.tags.len() + additional_tags.len());

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 if I had not looked at the code, my expectation would be that the ones on the build override the previous ones. Silently using the old ones yet seems like a really sharp edge :)

@morrisonlevi
morrisonlevi marked this pull request as ready for review March 29, 2022 21:15
form.add_text("family", String::from(&self.family));

for tag in self.tags.iter() {
for tag in self.tags.iter().chain(additional_tags.iter()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

neat operator !

Comment thread examples/ffi/exporter.cpp Outdated

@r1viollet r1viollet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@morrisonlevi
morrisonlevi merged commit 30be6f9 into main Mar 31, 2022
@morrisonlevi
morrisonlevi deleted the levi/send-tags branch March 31, 2022 15:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants