Commit 926414a0 by Bertrand Renuart

GH1155: remove Guava ImmutableMap in favour of Collections.unmodifiableMap()

Make sanitizeUrlTemplate() protected for easy sub-classing
parent 3991c8c5
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
package org.springframework.cloud.netflix.metrics; package org.springframework.cloud.netflix.metrics;
import java.io.IOException; import java.io.IOException;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -25,8 +26,6 @@ import org.springframework.http.client.ClientHttpResponse; ...@@ -25,8 +26,6 @@ import org.springframework.http.client.ClientHttpResponse;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.servlet.HandlerMapping; import org.springframework.web.servlet.HandlerMapping;
import com.google.common.collect.ImmutableMap;
/** /**
* @author Jon Schneider * @author Jon Schneider
*/ */
...@@ -49,14 +48,19 @@ public class DefaultMetricsTagProvider implements MetricsTagProvider { ...@@ -49,14 +48,19 @@ public class DefaultMetricsTagProvider implements MetricsTagProvider {
} }
String host = request.getURI().getHost(); String host = request.getURI().getHost();
if( host == null ) {
host = "none";
}
String strippedUrlTemplate = urlTemplate.replaceAll("^https?://[^/]+/", ""); String strippedUrlTemplate = urlTemplate.replaceAll("^https?://[^/]+/", "");
//@formatter:off
return ImmutableMap.of("method", request.getMethod().name(), Map<String, String> tags = new HashMap<>();
"uri", sanitizeUrlTemplate(strippedUrlTemplate), tags.put("method", request.getMethod().name());
"status", status, "clientName", tags.put("uri", sanitizeUrlTemplate(strippedUrlTemplate));
host != null ? host : "none"); tags.put("status", status);
//@formatter:on tags.put("clientName", host);
return Collections.unmodifiableMap(tags);
} }
@Override @Override
...@@ -94,7 +98,7 @@ public class DefaultMetricsTagProvider implements MetricsTagProvider { ...@@ -94,7 +98,7 @@ public class DefaultMetricsTagProvider implements MetricsTagProvider {
* As is, the urlTemplate is not suitable for use with Atlas, as all interactions with * As is, the urlTemplate is not suitable for use with Atlas, as all interactions with
* Atlas take place via query parameters * Atlas take place via query parameters
*/ */
private String sanitizeUrlTemplate(String urlTemplate) { protected String sanitizeUrlTemplate(String urlTemplate) {
String sanitized = urlTemplate.replaceAll("/", "_").replaceAll("[{}]", "-"); String sanitized = urlTemplate.replaceAll("/", "_").replaceAll("[{}]", "-");
if (!StringUtils.hasText(sanitized)) { if (!StringUtils.hasText(sanitized)) {
sanitized = "none"; sanitized = "none";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment