diff --git a/implementations/micrometer-registry-kairos/src/main/java/io/micrometer/kairos/KairosConfig.java b/implementations/micrometer-registry-kairos/src/main/java/io/micrometer/kairos/KairosConfig.java index 1e275006cc..b25a3eef8c 100644 --- a/implementations/micrometer-registry-kairos/src/main/java/io/micrometer/kairos/KairosConfig.java +++ b/implementations/micrometer-registry-kairos/src/main/java/io/micrometer/kairos/KairosConfig.java @@ -1,5 +1,5 @@ /** - * Copyright 2017 Pivotal Software, Inc. + * Copyright 2018 Pivotal Software, Inc. *
* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package io.micrometer.kairos; import io.micrometer.core.instrument.step.StepRegistryConfig; +import io.micrometer.core.lang.Nullable; /** * @author Anton Ilinchik @@ -37,35 +38,30 @@ default String prefix() { } /** - * The host to send the metrics to - * Default is "http://localhost:8080" + * The URI to send the metrics to. * - * @return host + * @return uri */ - default String host() { - String v = get(prefix() + ".host"); + default String uri() { + String v = get(prefix() + ".uri"); return v == null ? "http://localhost:8080/api/v1/datapoints" : v; } /** - * The Basic Authentication username. - * Default is: "" (= do not perform Basic Authentication) - * - * @return username for Basic Authentication + * @return Authenticate requests with this user. By default is {@code null}, and the registry will not + * attempt to present credentials to KairosDB. */ + @Nullable default String userName() { - String v = get(prefix() + ".userName"); - return v == null ? "" : v; + return get(prefix() + ".userName"); } /** - * The Basic Authentication password. - * Default is: "" (= do not perform Basic Authentication) - * - * @return password for Basic Authentication + * @return Authenticate requests with this password. By default is {@code null}, and the registry will not + * attempt to present credentials to KairosDB. */ + @Nullable default String password() { - String v = get(prefix() + ".password"); - return v == null ? "" : v; + return get(prefix() + ".password"); } } diff --git a/implementations/micrometer-registry-kairos/src/main/java/io/micrometer/kairos/KairosMeterRegistry.java b/implementations/micrometer-registry-kairos/src/main/java/io/micrometer/kairos/KairosMeterRegistry.java index 99cfde573c..effd3676ed 100644 --- a/implementations/micrometer-registry-kairos/src/main/java/io/micrometer/kairos/KairosMeterRegistry.java +++ b/implementations/micrometer-registry-kairos/src/main/java/io/micrometer/kairos/KairosMeterRegistry.java @@ -1,5 +1,5 @@ /** - * Copyright 2017 Pivotal Software, Inc. + * Copyright 2018 Pivotal Software, Inc. *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,34 +15,16 @@
*/
package io.micrometer.kairos;
-import io.micrometer.core.instrument.Clock;
-import io.micrometer.core.instrument.Counter;
-import io.micrometer.core.instrument.DistributionSummary;
-import io.micrometer.core.instrument.FunctionCounter;
-import io.micrometer.core.instrument.FunctionTimer;
-import io.micrometer.core.instrument.Gauge;
-import io.micrometer.core.instrument.LongTaskTimer;
-import io.micrometer.core.instrument.Meter;
-import io.micrometer.core.instrument.Tag;
-import io.micrometer.core.instrument.TimeGauge;
-import io.micrometer.core.instrument.Timer;
+import io.micrometer.core.instrument.*;
import io.micrometer.core.instrument.step.StepMeterRegistry;
-import io.micrometer.core.instrument.util.HttpHeader;
-import io.micrometer.core.instrument.util.HttpMethod;
-import io.micrometer.core.instrument.util.MediaType;
import io.micrometer.core.instrument.util.MeterPartition;
-import io.micrometer.core.instrument.util.StringUtils;
-import io.micrometer.core.lang.Nullable;
+import io.micrometer.core.ipc.http.HttpClient;
+import io.micrometer.core.ipc.http.HttpUrlConnectionClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.OutputStream;
-import java.net.HttpURLConnection;
import java.net.InetAddress;
-import java.net.URL;
import java.net.UnknownHostException;
-import java.nio.charset.StandardCharsets;
-import java.util.Base64;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
@@ -51,117 +33,58 @@
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
-import static java.util.Objects.requireNonNull;
+import static io.micrometer.core.instrument.Meter.Type.match;
/**
* @author Anton Ilinchik
*/
public class KairosMeterRegistry extends StepMeterRegistry {
-
private final Logger logger = LoggerFactory.getLogger(KairosMeterRegistry.class);
-
private final KairosConfig config;
-
- public KairosMeterRegistry(KairosConfig config) {
- this(config, Clock.SYSTEM);
- }
+ private final HttpClient httpClient;
public KairosMeterRegistry(KairosConfig config, Clock clock) {
- this(config, clock, Executors.defaultThreadFactory());
+ this(config, clock, Executors.defaultThreadFactory(), new HttpUrlConnectionClient(config.connectTimeout(), config.readTimeout()));
}
- public KairosMeterRegistry(KairosConfig config, Clock clock, ThreadFactory threadFactory) {
+ private KairosMeterRegistry(KairosConfig config, Clock clock, ThreadFactory threadFactory, HttpClient httpClient) {
super(config, clock);
- requireNonNull(config, "config must not be null");
- requireNonNull(threadFactory, "threadFactory must not be null");
+
+ this.config().namingConvention(new KairosNamingConvention());
this.config = config;
- config().namingConvention(new KairosNamingConvention());
- start(threadFactory);
+ this.httpClient = httpClient;
+
+ if (config.enabled())
+ start(threadFactory);
}
@Override
protected void publish() {
for (List
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
import io.micrometer.core.instrument.Meter;
import io.micrometer.core.instrument.config.NamingConvention;
import io.micrometer.core.instrument.util.StringEscapeUtils;
+import io.micrometer.core.lang.Nullable;
import java.util.regex.Pattern;
@@ -25,8 +26,7 @@
* @author Anton Ilinchik
*/
public class KairosNamingConvention implements NamingConvention {
-
- private static final Pattern blacklistedChars = Pattern.compile("[{}():,=\\[\\]]");
+ private static final Pattern BLACKLISTED_CHARS = Pattern.compile("[{}():,=\\[\\]]");
private final NamingConvention delegate;
@@ -40,22 +40,21 @@ public KairosNamingConvention(NamingConvention delegate) {
private String format(String name) {
String normalized = StringEscapeUtils.escapeJson(name);
- return blacklistedChars.matcher(normalized).replaceAll("_");
+ return BLACKLISTED_CHARS.matcher(normalized).replaceAll("_");
}
@Override
- public String name(String name, Meter.Type type, String baseUnit) {
- return delegate.name(format(name), type, baseUnit);
+ public String name(String name, Meter.Type type, @Nullable String baseUnit) {
+ return format(delegate.name(name, type, baseUnit));
}
@Override
public String tagKey(String key) {
- return format(key);
+ return format(delegate.tagKey(key));
}
@Override
public String tagValue(String value) {
- return format(value);
+ return format(delegate.tagValue(value));
}
-
}
diff --git a/implementations/micrometer-registry-kairos/src/main/java/io/micrometer/kairos/package-info.java b/implementations/micrometer-registry-kairos/src/main/java/io/micrometer/kairos/package-info.java
index d918fd2eea..f956c0978d 100644
--- a/implementations/micrometer-registry-kairos/src/main/java/io/micrometer/kairos/package-info.java
+++ b/implementations/micrometer-registry-kairos/src/main/java/io/micrometer/kairos/package-info.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2017 Pivotal Software, Inc.
+ * Copyright 2018 Pivotal Software, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,4 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+@NonNullApi
+@NonNullFields
package io.micrometer.kairos;
+
+import io.micrometer.core.lang.NonNullApi;
+import io.micrometer.core.lang.NonNullFields;
\ No newline at end of file
diff --git a/implementations/micrometer-registry-kairos/src/test/java/io/micrometer/kairos/KairosNamingConventionTest.java b/implementations/micrometer-registry-kairos/src/test/java/io/micrometer/kairos/KairosNamingConventionTest.java
index 475749e768..e373308c62 100644
--- a/implementations/micrometer-registry-kairos/src/test/java/io/micrometer/kairos/KairosNamingConventionTest.java
+++ b/implementations/micrometer-registry-kairos/src/test/java/io/micrometer/kairos/KairosNamingConventionTest.java
@@ -24,12 +24,10 @@
* @author Anton Ilinchik
*/
class KairosNamingConventionTest {
-
private KairosNamingConvention convention = new KairosNamingConvention();
@Test
- void dotNotationIsConvertedToSnakeCase() {
+ void defaultToSnakeCase() {
assertThat(convention.name("gauge.size", Meter.Type.GAUGE)).isEqualTo("gauge_size");
}
-
}
\ No newline at end of file
diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/kairos/KairosMetricsExportAutoConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/kairos/KairosMetricsExportAutoConfiguration.java
index e904ee906b..0456422e4b 100644
--- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/kairos/KairosMetricsExportAutoConfiguration.java
+++ b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/kairos/KairosMetricsExportAutoConfiguration.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2017 Pivotal Software, Inc.
+ * Copyright 2018 Pivotal Software, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/kairos/KairosProperties.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/kairos/KairosProperties.java
index 0ab9bdf3d6..c9ff53e39e 100644
--- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/kairos/KairosProperties.java
+++ b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/kairos/KairosProperties.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2017 Pivotal Software, Inc.
+ * Copyright 2018 Pivotal Software, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,9 +27,9 @@
public class KairosProperties extends StepRegistryProperties {
/**
- * The host to send the metrics to
+ * URI to ship metrics to.
*/
- private String host;
+ private String uri;
/**
* The Basic Authentication username.
@@ -41,12 +41,12 @@ public class KairosProperties extends StepRegistryProperties {
*/
private String password;
- public String getHost() {
- return host;
+ public String getUri() {
+ return uri;
}
- public void setHost(String host) {
- this.host = host;
+ public void setUri(String uri) {
+ this.uri = uri;
}
public String getUserName() {
diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/kairos/KairosPropertiesConfigAdapter.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/kairos/KairosPropertiesConfigAdapter.java
index 83fb8a83de..496dcb1f30 100644
--- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/kairos/KairosPropertiesConfigAdapter.java
+++ b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/kairos/KairosPropertiesConfigAdapter.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2017 Pivotal Software, Inc.
+ * Copyright 2018 Pivotal Software, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,8 +30,8 @@ public KairosPropertiesConfigAdapter(KairosProperties properties) {
}
@Override
- public String host() {
- return get(KairosProperties::getHost, KairosConfig.super::host);
+ public String uri() {
+ return get(KairosProperties::getUri, KairosConfig.super::uri);
}
@Override
diff --git a/samples/micrometer-samples-core/src/main/java/io/micrometer/core/samples/utils/SampleConfig.java b/samples/micrometer-samples-core/src/main/java/io/micrometer/core/samples/utils/SampleConfig.java
index ba74bb9307..fde10e233c 100644
--- a/samples/micrometer-samples-core/src/main/java/io/micrometer/core/samples/utils/SampleConfig.java
+++ b/samples/micrometer-samples-core/src/main/java/io/micrometer/core/samples/utils/SampleConfig.java
@@ -22,6 +22,6 @@
public class SampleConfig {
public static MeterRegistry myMonitoringSystem() {
// Pick a monitoring system here to use in your samples.
- return SampleRegistries.atlas();
+ return SampleRegistries.kairos();
}
}
diff --git a/samples/micrometer-samples-core/src/main/java/io/micrometer/core/samples/utils/SampleRegistries.java b/samples/micrometer-samples-core/src/main/java/io/micrometer/core/samples/utils/SampleRegistries.java
index 19feba075a..911e98bd89 100644
--- a/samples/micrometer-samples-core/src/main/java/io/micrometer/core/samples/utils/SampleRegistries.java
+++ b/samples/micrometer-samples-core/src/main/java/io/micrometer/core/samples/utils/SampleRegistries.java
@@ -41,6 +41,8 @@
import io.micrometer.influx.InfluxMeterRegistry;
import io.micrometer.jmx.JmxConfig;
import io.micrometer.jmx.JmxMeterRegistry;
+import io.micrometer.kairos.KairosConfig;
+import io.micrometer.kairos.KairosMeterRegistry;
import io.micrometer.newrelic.NewRelicConfig;
import io.micrometer.newrelic.NewRelicMeterRegistry;
import io.micrometer.prometheus.PrometheusConfig;
@@ -66,7 +68,9 @@ public static MeterRegistry pickOne() {
public static AppOpticsMeterRegistry appOptics(String apiToken) {
return new AppOpticsMeterRegistry(new AppOpticsConfig() {
@Override
- public String token() { return apiToken; }
+ public String token() {
+ return apiToken;
+ }
@Override
public Duration step() {
@@ -436,4 +440,23 @@ public String apiToken() {
}
}, Clock.SYSTEM);
}
+
+ public static KairosMeterRegistry kairos() {
+ return new KairosMeterRegistry(new KairosConfig() {
+ @Override
+ public String get(String key) {
+ return null;
+ }
+
+ @Override
+ public String uri() {
+ return "http://localhost:8083/api/v1/datapoints";
+ }
+
+ @Override
+ public Duration step() {
+ return Duration.ofSeconds(10);
+ }
+ }, Clock.SYSTEM);
+ }
}
diff --git a/scripts/cassandra.sh b/scripts/cassandra.sh
new file mode 100755
index 0000000000..0a1bf4c90d
--- /dev/null
+++ b/scripts/cassandra.sh
@@ -0,0 +1,2 @@
+#!/usr/bin/env bash
+docker run --name my_cassandra -e "CASSANDRA_START_RPC=true" cassandra
\ No newline at end of file
diff --git a/scripts/kairosdb.sh b/scripts/kairosdb.sh
new file mode 100755
index 0000000000..faf1a0e648
--- /dev/null
+++ b/scripts/kairosdb.sh
@@ -0,0 +1,2 @@
+#!/usr/bin/env bash
+docker run --link my_cassandra:cassandra -e "CASSANDRA_HOST_LIST=cassandra:9160" -p 8083:8083 jimtonic/kairosdb