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

aws: check for null values in custom tags #1173

Merged
merged 1 commit into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,21 @@ public SpectatorRequestMetricCollector(Registry registry, Map<String, String> cu
this.customTags = new HashMap<>();
customTags.forEach((key, value) -> {
if (ALL_DEFAULT_TAGS.contains(key)) {
registry.propagate(new IllegalArgumentException("Invalid custom tag " + key
+ " - cannot override built-in tag"));
registry.propagate(new IllegalArgumentException(
"Invalid custom tag " + key + " - cannot override built-in tag"));
} else if (value == null) {
registry.propagate(new NullPointerException(
"Custom tag value for key " + key + " is null"));
} else {
this.customTags.put(key, value);
}
});
Preconditions.checkNotNull(handlerContextKey, "handlerContextKey");
this.handlerContextKey = handlerContextKey;
if (ALL_DEFAULT_TAGS.contains(this.handlerContextKey.getName())) {
registry.propagate(new IllegalArgumentException("Invalid handler context key "
+ this.handlerContextKey.getName()
+ " - cannot override built-in tag"));
final String keyName = this.handlerContextKey.getName();
if (ALL_DEFAULT_TAGS.contains(keyName)) {
registry.propagate(new IllegalArgumentException(
"Invalid handler context key " + keyName + " - cannot override built-in tag"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,15 @@ public void testCustomTags_overrideDefault() {
new SpectatorRequestMetricCollector(new DefaultRegistry(Clock.SYSTEM, config), customTags));
}

@Test
public void testCustomTagsNull() {
Map<String, String> customTags = new HashMap<>();
customTags.put("tagname", null);
collector = new SpectatorRequestMetricCollector(registry, customTags);
execRequest("http://monitoring", 503);
assertEquals(set(), valueSet("tagname"));
}

@Test
public void testHandlerContextKey() {
String contextKeyName = "myContextKey";
Expand Down
Loading