-
Notifications
You must be signed in to change notification settings - Fork 231
Add BaggageRestrictionManager #217
Changes from 1 commit
ea69588
6379066
e29d837
11c6d86
f113e55
df9b653
4af5607
b644bb6
72c1b84
b24d7de
4d5d98b
495a656
72cbdc5
45d2b58
877120b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
|
||
package com.uber.jaeger; | ||
|
||
import com.uber.jaeger.baggage.SanitizedBaggage; | ||
import io.opentracing.tag.Tags; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
|
@@ -117,21 +118,35 @@ public List<LogData> getLogs() { | |
@Override | ||
public Span setBaggageItem(String key, String value) { | ||
synchronized (this) { | ||
// TODO emit a metric whenever baggage is updated | ||
if (key == null || value == null) { | ||
return this; | ||
} | ||
SanitizedBaggage baggage = this.tracer.getBaggageRestrictionManager().sanitizeBaggage(key, value); | ||
if (!baggage.isValid()) { | ||
this.tracer.getMetrics().baggageUpdateFailure.inc(1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. might be useful to log this to span as well |
||
return this; | ||
} | ||
if (baggage.isTruncated()) { | ||
this.tracer.getMetrics().baggageTruncate.inc(1); | ||
} | ||
String prevItem = this.getBaggageItem(key); | ||
this.context = this.context.withBaggageItem(key, value); | ||
this.context = this.context.withBaggageItem(key, baggage.getSanitizedValue()); | ||
this.tracer.getMetrics().baggageUpdateSuccess.inc(1); | ||
if (context.isSampled()) { | ||
Map<String, String> fields = new HashMap<String, String>(); | ||
fields.put("event", "baggage"); | ||
fields.put("key", key); | ||
fields.put("value", value); | ||
fields.put("value", baggage.getSanitizedValue()); | ||
if (prevItem != null) { | ||
fields.put("override", "true"); | ||
} | ||
if (baggage.isTruncated()) { | ||
fields.put("truncated", "true"); | ||
} | ||
return this.log(fields); | ||
} | ||
return this; | ||
} | ||
return this; | ||
} | ||
|
||
@Override | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright (c) 2017, Uber Technologies, Inc | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
package com.uber.jaeger.baggage; | ||
|
||
public abstract class BaggageRestrictionManager { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add |
||
static final int DEFAULT_MAX_VALUE_LENGTH = 2048; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is only used in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it'll be used in another manager in the follow up PR |
||
|
||
public abstract SanitizedBaggage sanitizeBaggage(String key, String value); | ||
|
||
SanitizedBaggage truncateBaggage(String value, int maxValueLength) { | ||
if (value.length() > maxValueLength) { | ||
return SanitizedBaggage.of(true, value.substring(0, maxValueLength), true); | ||
} | ||
return SanitizedBaggage.of(true, value, false); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (c) 2017, Uber Technologies, Inc | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
package com.uber.jaeger.baggage; | ||
|
||
public class DefaultBaggageRestrictionManager extends BaggageRestrictionManager { | ||
|
||
private final int maxValueLength; | ||
|
||
public DefaultBaggageRestrictionManager() { | ||
this(DEFAULT_MAX_VALUE_LENGTH); | ||
} | ||
|
||
public DefaultBaggageRestrictionManager(int maxValueLength) { | ||
this.maxValueLength = maxValueLength; | ||
} | ||
|
||
@Override | ||
public SanitizedBaggage sanitizeBaggage(String key, String value) { | ||
return truncateBaggage(value, maxValueLength); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (c) 2017, Uber Technologies, Inc | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
package com.uber.jaeger.baggage; | ||
|
||
import lombok.Value; | ||
|
||
@Value(staticConstructor = "of") | ||
public class SanitizedBaggage { | ||
final boolean valid; | ||
final String sanitizedValue; | ||
final boolean truncated; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test doesn't need to be synchronized.