From e994971bec99bd84e4a3e8e2891f9de20ebecf19 Mon Sep 17 00:00:00 2001 From: Jon Schneider Date: Tue, 15 Dec 2015 21:29:20 -0800 Subject: [PATCH] Minor improvements to error messages for netflix.atlas.uri problems --- .../netflix/metrics/atlas/AtlasMetricObserver.java | 11 ++++++++--- .../metrics/atlas/AtlasMetricObserverTests.java | 10 ++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/metrics/atlas/AtlasMetricObserver.java b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/metrics/atlas/AtlasMetricObserver.java index e55be266..cad9f0ac 100644 --- a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/metrics/atlas/AtlasMetricObserver.java +++ b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/metrics/atlas/AtlasMetricObserver.java @@ -95,9 +95,14 @@ public class AtlasMetricObserver implements MetricObserver { } protected static String normalizeAtlasUri(String uri) { - Matcher matcher = Pattern.compile("(.+?)(/api/v1/publish)?/?").matcher(uri); - matcher.matches(); - return matcher.group(1) + "/api/v1/publish"; + if (uri != null) { + Matcher matcher = Pattern.compile("(.+?)(/api/v1/publish)?/?").matcher(uri); + if (matcher.matches()) + return matcher.group(1) + "/api/v1/publish"; + else + throw new IllegalStateException("netflix.atlas.uri is not a valid uri"); + } + throw new IllegalStateException("netflix.atlas.uri was not found in your properties and is required to communicate with Atlas"); } @Override diff --git a/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/metrics/atlas/AtlasMetricObserverTests.java b/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/metrics/atlas/AtlasMetricObserverTests.java index 68bde083..b1c4d3d8 100644 --- a/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/metrics/atlas/AtlasMetricObserverTests.java +++ b/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/metrics/atlas/AtlasMetricObserverTests.java @@ -53,6 +53,16 @@ public class AtlasMetricObserverTests { assertEquals(normalized, AtlasMetricObserver.normalizeAtlasUri("http://localhost:7001/api/v1/publish/")); } + @Test(expected = IllegalStateException.class) + public void emptyAtlasUriThrowsException() { + AtlasMetricObserver.normalizeAtlasUri(""); + } + + @Test(expected = IllegalStateException.class) + public void missingAtlasUriThrowsException() { + AtlasMetricObserver.normalizeAtlasUri(null); + } + @Test public void checkValidityOfTags() { assertTrue(AtlasMetricObserver.validTags(BasicTagList.of("foo", "bar")));