From 11f26061f55d2590b152eaf161e16d472fa7aa98 Mon Sep 17 00:00:00 2001 From: Jon Schneider Date: Wed, 18 Jul 2018 21:11:20 -0500 Subject: [PATCH] Add Influx retention policy property bindings to spring legacy module --- .../influx/CreateDatabaseQueryBuilder.java | 6 +-- .../io/micrometer/influx/InfluxConfig.java | 13 ++++--- .../CreateDatabaseQueryBuilderTest.java | 2 +- .../export/influx/InfluxProperties.java | 39 +++++++++++++++++++ .../influx/InfluxPropertiesConfigAdapter.java | 18 ++++++++- 5 files changed, 66 insertions(+), 12 deletions(-) diff --git a/implementations/micrometer-registry-influx/src/main/java/io/micrometer/influx/CreateDatabaseQueryBuilder.java b/implementations/micrometer-registry-influx/src/main/java/io/micrometer/influx/CreateDatabaseQueryBuilder.java index 509251f497..acce24a39c 100644 --- a/implementations/micrometer-registry-influx/src/main/java/io/micrometer/influx/CreateDatabaseQueryBuilder.java +++ b/implementations/micrometer-registry-influx/src/main/java/io/micrometer/influx/CreateDatabaseQueryBuilder.java @@ -33,7 +33,7 @@ class CreateDatabaseQueryBuilder { private static final String QUERY_MANDATORY_TEMPLATE = "CREATE DATABASE %s"; private static final String RETENTION_POLICY_INTRODUCTION = " WITH"; private static final String DURATION_CLAUSE_TEMPLATE = " DURATION %s"; - private static final String REPLICATION_FACTOR_CLAUSE_TEMPLATE = " REPLICATION %s"; + private static final String REPLICATION_FACTOR_CLAUSE_TEMPLATE = " REPLICATION %d"; private static final String SHARD_DURATION_CLAUSE_TEMPLATE = " SHARD DURATION %s"; private static final String NAME_CLAUSE_TEMPLATE = " NAME %s"; @@ -54,8 +54,8 @@ CreateDatabaseQueryBuilder setRetentionDuration(@Nullable String retentionDurati return this; } - CreateDatabaseQueryBuilder setRetentionReplicationFactor(@Nullable String retentionReplicationFactor) { - if (!isEmpty(retentionReplicationFactor)) { + CreateDatabaseQueryBuilder setRetentionReplicationFactor(@Nullable Integer retentionReplicationFactor) { + if (retentionReplicationFactor != null) { retentionPolicyClauses[1] = String.format(REPLICATION_FACTOR_CLAUSE_TEMPLATE, retentionReplicationFactor); } return this; diff --git a/implementations/micrometer-registry-influx/src/main/java/io/micrometer/influx/InfluxConfig.java b/implementations/micrometer-registry-influx/src/main/java/io/micrometer/influx/InfluxConfig.java index 1624de790c..46ce09ee77 100644 --- a/implementations/micrometer-registry-influx/src/main/java/io/micrometer/influx/InfluxConfig.java +++ b/implementations/micrometer-registry-influx/src/main/java/io/micrometer/influx/InfluxConfig.java @@ -80,7 +80,7 @@ default String retentionPolicy() { } /** - * @return time period for which influx should retain data in the current database (e.g. 2h, 52w) + * @return Time period for which influx should retain data in the current database (e.g. 2h, 52w). */ @Nullable default String retentionDuration(){ @@ -88,15 +88,16 @@ default String retentionDuration(){ } /** - * @return how many copies of the data are stored in the cluster. Must be 1 for a single node instance + * @return How many copies of the data are stored in the cluster. Must be 1 for a single node instance. */ @Nullable - default String retentionReplicationFactor(){ - return get(prefix() + ".retentionReplicationFactor"); + default Integer retentionReplicationFactor(){ + String v = get(prefix() + ".retentionReplicationFactor"); + return v == null ? null : Integer.parseInt(v); } - /** - * @return the time range covered by a shard group + /** + * @return The time range covered by a shard group (e.g. 2h, 52w). */ @Nullable default String retentionShardDuration(){ diff --git a/implementations/micrometer-registry-influx/src/test/java/io/micrometer/influx/CreateDatabaseQueryBuilderTest.java b/implementations/micrometer-registry-influx/src/test/java/io/micrometer/influx/CreateDatabaseQueryBuilderTest.java index d2871ff9b6..33466bedd4 100644 --- a/implementations/micrometer-registry-influx/src/test/java/io/micrometer/influx/CreateDatabaseQueryBuilderTest.java +++ b/implementations/micrometer-registry-influx/src/test/java/io/micrometer/influx/CreateDatabaseQueryBuilderTest.java @@ -59,7 +59,7 @@ void oneClauseInRetentionPolicy() { void allClausesInRetentionPolicy() { String query = createDatabaseQueryBuilder.setRetentionPolicyName("dummy_policy") .setRetentionDuration("2d") - .setRetentionReplicationFactor("1") + .setRetentionReplicationFactor(1) .setRetentionShardDuration("3") .build(); assertEquals("CREATE DATABASE dummy_database_0 WITH DURATION 2d REPLICATION 1 SHARD DURATION 3 NAME dummy_policy", query); diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/influx/InfluxProperties.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/influx/InfluxProperties.java index f76fb371bc..58441e1052 100644 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/influx/InfluxProperties.java +++ b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/influx/InfluxProperties.java @@ -69,6 +69,21 @@ public class InfluxProperties extends StepRegistryProperties { */ private Boolean autoCreateDb; + /** + * Time period for which influx should retain data in the current database (e.g. 2h, 52w) + */ + private String retentionDuration; + + /** + * How many copies of the data are stored in the cluster. Must be 1 for a single node instance. + */ + private Integer retentionReplicationFactor; + + /** + * The time range covered by a shard group (e.g. 2h, 52w). + */ + private String retentionShardDuration; + public String getDb() { return this.db; } @@ -132,4 +147,28 @@ public Boolean getAutoCreateDb() { public void setAutoCreateDb(Boolean autoCreateDb) { this.autoCreateDb = autoCreateDb; } + + public String getRetentionDuration() { + return retentionDuration; + } + + public void setRetentionDuration(String retentionDuration) { + this.retentionDuration = retentionDuration; + } + + public Integer getRetentionReplicationFactor() { + return retentionReplicationFactor; + } + + public void setRetentionReplicationFactor(Integer retentionReplicationFactor) { + this.retentionReplicationFactor = retentionReplicationFactor; + } + + public String getRetentionShardDuration() { + return retentionShardDuration; + } + + public void setRetentionShardDuration(String retentionShardDuration) { + this.retentionShardDuration = retentionShardDuration; + } } diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/influx/InfluxPropertiesConfigAdapter.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/influx/InfluxPropertiesConfigAdapter.java index a96db48f6d..fc56715bb7 100644 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/influx/InfluxPropertiesConfigAdapter.java +++ b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/influx/InfluxPropertiesConfigAdapter.java @@ -53,8 +53,22 @@ public String password() { @Override public String retentionPolicy() { - return get(InfluxProperties::getRetentionPolicy, - InfluxConfig.super::retentionPolicy); + return get(InfluxProperties::getRetentionPolicy, InfluxConfig.super::retentionPolicy); + } + + @Override + public Integer retentionReplicationFactor() { + return get(InfluxProperties::getRetentionReplicationFactor, InfluxConfig.super::retentionReplicationFactor); + } + + @Override + public String retentionDuration() { + return get(InfluxProperties::getRetentionDuration, InfluxConfig.super::retentionDuration); + } + + @Override + public String retentionShardDuration() { + return get(InfluxProperties::getRetentionShardDuration, InfluxConfig.super::retentionShardDuration); } @Override