-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
15 changed files
with
204 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...pectit-ocelot-eum-server/src/main/java/rocks/inspectit/oce/eum/server/utils/TagUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package rocks.inspectit.oce.eum.server.utils; | ||
|
||
import io.opencensus.internal.StringUtils; | ||
import io.opencensus.tags.TagValue; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
public final class TagUtils { | ||
|
||
private static boolean isWarningPrinted = false; | ||
|
||
private TagUtils() { | ||
// empty private default constructor for util class | ||
} | ||
|
||
/** | ||
* Constructs a {@code io.opencensus.tags.TagValue} from the given string. | ||
* If String is not valid an <code><invalid></code> TagName is created. | ||
* | ||
* @param v the tag value | ||
* @return the created TagValue with 'v' or '<invalid>' | ||
*/ | ||
public static TagValue createTagValue(String v) { | ||
if (isTagValueValid(v)) { | ||
return TagValue.create(v); | ||
} | ||
printWarningOnce(); | ||
return TagValue.create("<invalid>"); | ||
} | ||
|
||
private static boolean isTagValueValid(String value) { | ||
return value.length() <= TagValue.MAX_LENGTH && StringUtils.isPrintableString(value); | ||
} | ||
|
||
private static void printWarningOnce() { | ||
if (!isWarningPrinted) { | ||
log.warn("illegal tag value converted to <invalid>"); | ||
isWarningPrinted = true; | ||
} | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
...it-ocelot-eum-server/src/test/java/rocks/inspectit/oce/eum/server/utils/TagUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package rocks.inspectit.oce.eum.server.utils; | ||
|
||
import io.opencensus.tags.TagValue; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class TagUtilsTest { | ||
|
||
@Test | ||
public void createTagValue() { | ||
assertThat(TagUtils.createTagValue("my-tag-value")).isEqualTo(TagValue.create("my-tag-value")); | ||
} | ||
|
||
@Test | ||
public void createTagValue_tooLong() { | ||
assertThat(TagUtils.createTagValue("this-value-is-over-255-characters-long ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------")) | ||
.isEqualTo(TagValue.create("<invalid>")); | ||
} | ||
|
||
@Test | ||
public void createTagValue_nonPrintableCharacter() { | ||
assertThat(TagUtils.createTagValue("non-printable-character-\u007f")) | ||
.isEqualTo(TagValue.create("<invalid>")); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.