Skip to content
This repository has been archived by the owner on Jul 1, 2022. It is now read-only.

Support jaeger-baggage header for ad-hoc baggage #525

Merged
merged 2 commits into from
Aug 28, 2018

Conversation

yurishkuro
Copy link
Member

@yurishkuro yurishkuro commented Aug 20, 2018

return context.withBaggage(baggage);
}

private Map<String, String> parseBaggageHeader(String header, Map<String, String> baggage) {
String[] parts = header.split("\\ *,\\ *");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't we have a similar logic for the JAEGER_TAGS?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's similar, but that one has additional variable resolution logic for values.

if (baggage == null) {
baggage = new HashMap<String, String>();
}
baggage.put(kv[0], kv[1]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we place some constraints here, like limiting the number of entries and their size? I can see this being used for DDoS without such constraints, as an attacker needs to send the headers once and they are propagated throughout the whole infra, potentially multiple times.

Copy link
Member Author

Choose a reason for hiding this comment

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

What would you suggest? A limit on the total length of this header?

Alternatively we can just integrate it with baggage restrictions manager.

Copy link
Collaborator

Choose a reason for hiding this comment

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

How about making this configurable? JAEGER_MAX_NUM_BAGGAGE_ITEMS, JAEGER_MAX_SIZE_BAGGAGE_ITEMS, with a default of 10 baggage items and 256 bytes per key and value (512 bytes per pair)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Env vars feel out of place for this. The baggage size policy should be controlled centrally in organization, and we already have a mechanism for that via baggage restrictions manager.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we have it documented somewhere? I never used it myself, wouldn't know how to even start using that.

Copy link
Member Author

Choose a reason for hiding this comment

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

I am going to punt on restrictions, because this change is not adding any new security risks, as the bad actor can just as well send the normal tracing/baggage headers in the request.

@yurishkuro yurishkuro force-pushed the support-jaeger-baggage-header2 branch from 7b98f2f to 779acd8 Compare August 28, 2018 15:42
@yurishkuro yurishkuro closed this Aug 28, 2018
@ghost ghost removed the review label Aug 28, 2018
@yurishkuro yurishkuro reopened this Aug 28, 2018
@ghost ghost added the review label Aug 28, 2018
Signed-off-by: Yuri Shkuro <ys@uber.com>
@jaegertracing jaegertracing deleted a comment from codecov bot Aug 28, 2018
@codecov
Copy link

codecov bot commented Aug 28, 2018

Codecov Report

Merging #525 into master will increase coverage by 0.41%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #525      +/-   ##
============================================
+ Coverage     88.36%   88.78%   +0.41%     
- Complexity      505      516      +11     
============================================
  Files            66       66              
  Lines          1883     1890       +7     
  Branches        239      244       +5     
============================================
+ Hits           1664     1678      +14     
+ Misses          143      139       -4     
+ Partials         76       73       -3
Impacted Files Coverage Δ Complexity Δ
...main/java/io/jaegertracing/internal/Constants.java 0% <ø> (ø) 0 <0> (ø) ⬇️
...a/io/jaegertracing/internal/JaegerSpanContext.java 100% <100%> (+9.09%) 23 <0> (+2) ⬆️
...n/java/io/jaegertracing/internal/JaegerTracer.java 90.31% <100%> (-0.08%) 24 <0> (ø)
...egertracing/internal/propagation/TextMapCodec.java 93.93% <100%> (+2.82%) 31 <4> (+9) ⬆️
...egertracing/internal/reporters/RemoteReporter.java 84.52% <0%> (+2.38%) 7% <0%> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ce175a4...5c7c343. Read the comment docs.

@yurishkuro yurishkuro force-pushed the support-jaeger-baggage-header2 branch from d6600e9 to 1f79d9f Compare August 28, 2018 17:05

private Map<String, String> parseBaggageHeader(String header, Map<String, String> baggage) {
String[] parts = header.split("\\ *,\\ *");
for (int i = 0; i < parts.length; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

minor nit: can be simplified to a range for loop because we don't use the outer index

for (String part : header.split(" *, *")) {

Also, are the regex escapes required here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I means \s, will change.

}

private Map<String, String> parseBaggageHeader(String header, Map<String, String> baggage) {
String[] parts = header.split("\\ *,\\ *");
Copy link
Contributor

Choose a reason for hiding this comment

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

Programmatically set baggage can have , or = in the baggage value while it seems adhoc baggage cannot. While it is obvious, we should call out this limitation in documentation.

Copy link
Member Author

Choose a reason for hiding this comment

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

That seems kind of obvious if you're asked to provide baggage in the k1=v1, k2=v2 format.

Copy link
Contributor

@isaachier isaachier left a comment

Choose a reason for hiding this comment

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

LGTM but still waiting on the \\ => \\s change.

@@ -53,7 +53,7 @@ protected JaegerSpanContext(
String debugId,
JaegerObjectFactory objectFactory) {
if (baggage == null) {
throw new NullPointerException();
baggage = Collections.<String, String>emptyMap();
Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Signed-off-by: Yuri Shkuro <ys@uber.com>
@yurishkuro yurishkuro merged commit 73c8e0e into master Aug 28, 2018
@ghost ghost removed the review label Aug 28, 2018
@yurishkuro yurishkuro deleted the support-jaeger-baggage-header2 branch August 28, 2018 21:17
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.

4 participants