Skip to content

Commit 8bf934f

Browse files
committed
Merge branch '1.15.x'
2 parents 0a26998 + 9f9d0d0 commit 8bf934f

File tree

5 files changed

+42
-45
lines changed

5 files changed

+42
-45
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ subprojects {
8888

8989
error("BadImport",
9090
"DefaultCharset",
91+
"InlineFormatString",
9192
"LongDoubleConversion",
9293
"MissingOverride",
9394
"NullAway",

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ grpcKotlin = "1.4.3"
2222
guava = "32.1.3-jre"
2323
guice = "5.1.0"
2424
h2 = "2.3.232"
25-
hazelcast = "5.3.2"
25+
hazelcast = "5.3.8"
2626
hdrhistogram = "2.2.2"
2727
hibernate = "5.6.15.Final"
2828
# 2.6.0 requires JDK 11

implementations/micrometer-registry-elastic/src/main/java/io/micrometer/elastic/DefaultIndexTemplateCreator.java

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,6 @@ class DefaultIndexTemplateCreator implements IndexTemplateCreator {
3333

3434
private final Logger logger = LoggerFactory.getLogger(DefaultIndexTemplateCreator.class);
3535

36-
private final String indexTemplateRequest = "{\n" + " \"index_patterns\": [\"%s*\"],\n" + " \"template\": {\n"
37-
+ " \"mappings\": {\n" + " \"_source\": {\n" + " \"enabled\": %b\n" + " },\n"
38-
+ " \"properties\": {\n" + " \"name\": { \"type\": \"keyword\" },\n"
39-
+ " \"count\": { \"type\": \"double\", \"index\": false },\n"
40-
+ " \"value\": { \"type\": \"double\", \"index\": false },\n"
41-
+ " \"sum\": { \"type\": \"double\", \"index\": false },\n"
42-
+ " \"mean\": { \"type\": \"double\", \"index\": false },\n"
43-
+ " \"duration\": { \"type\": \"double\", \"index\": false},\n"
44-
+ " \"max\": { \"type\": \"double\", \"index\": false },\n"
45-
+ " \"total\": { \"type\": \"double\", \"index\": false },\n"
46-
+ " \"unknown\": { \"type\": \"double\", \"index\": false },\n"
47-
+ " \"active\": { \"type\": \"double\", \"index\": false }\n" + " }\n" + " }\n" + " }\n"
48-
+ "}";
49-
5036
private final HttpSender httpClient;
5137

5238
DefaultIndexTemplateCreator(HttpSender httpClient) {
@@ -84,9 +70,25 @@ public void createIndexTemplate(ElasticConfig configuration) throws Throwable {
8470
boolean enableSource = configuration.enableSource();
8571
HttpSender.Request.Builder request = this.httpClient.put(configuration.host() + INDEX_TEMPLATE_PATH);
8672
configureAuthentication(configuration, request);
87-
request.withJsonContent(String.format(indexTemplateRequest, indexPattern, enableSource))
73+
request.withJsonContent(createIndexTemplateRequestBody(indexPattern, enableSource))
8874
.send()
8975
.onError(response -> logger.error("Failed to create index template in Elastic: {}", response.body()));
9076
}
9177

78+
private String createIndexTemplateRequestBody(String indexPattern, boolean enableSource) {
79+
return String.format("{\n" + " \"index_patterns\": [\"%s*\"],\n" + " \"template\": {\n"
80+
+ " \"mappings\": {\n" + " \"_source\": {\n" + " \"enabled\": %b\n" + " },\n"
81+
+ " \"properties\": {\n" + " \"name\": { \"type\": \"keyword\" },\n"
82+
+ " \"count\": { \"type\": \"double\", \"index\": false },\n"
83+
+ " \"value\": { \"type\": \"double\", \"index\": false },\n"
84+
+ " \"sum\": { \"type\": \"double\", \"index\": false },\n"
85+
+ " \"mean\": { \"type\": \"double\", \"index\": false },\n"
86+
+ " \"duration\": { \"type\": \"double\", \"index\": false},\n"
87+
+ " \"max\": { \"type\": \"double\", \"index\": false },\n"
88+
+ " \"total\": { \"type\": \"double\", \"index\": false },\n"
89+
+ " \"unknown\": { \"type\": \"double\", \"index\": false },\n"
90+
+ " \"active\": { \"type\": \"double\", \"index\": false }\n" + " }\n" + " }\n" + " }\n"
91+
+ "}", indexPattern, enableSource);
92+
}
93+
9294
}

implementations/micrometer-registry-elastic/src/main/java/io/micrometer/elastic/LegacyIndexTemplateCreator.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,6 @@ class LegacyIndexTemplateCreator implements IndexTemplateCreator {
3333

3434
private final Logger logger = LoggerFactory.getLogger(LegacyIndexTemplateCreator.class);
3535

36-
private final String indexTemplateRequest = "{\n" + " \"index_patterns\": [\"%s*\"],\n" + " \"mappings\": {\n"
37-
+ " \"_source\": {\n" + " \"enabled\": %b\n" + " },\n" + " \"properties\": {\n"
38-
+ " \"name\": { \"type\": \"keyword\" },\n"
39-
+ " \"count\": { \"type\": \"double\", \"index\": false },\n"
40-
+ " \"value\": { \"type\": \"double\", \"index\": false },\n"
41-
+ " \"sum\": { \"type\": \"double\", \"index\": false },\n"
42-
+ " \"mean\": { \"type\": \"double\", \"index\": false },\n"
43-
+ " \"duration\": { \"type\": \"double\", \"index\": false},\n"
44-
+ " \"max\": { \"type\": \"double\", \"index\": false },\n"
45-
+ " \"total\": { \"type\": \"double\", \"index\": false },\n"
46-
+ " \"unknown\": { \"type\": \"double\", \"index\": false },\n"
47-
+ " \"active\": { \"type\": \"double\", \"index\": false }\n" + " }\n" + " }\n" + "}";
48-
4936
private final HttpSender httpClient;
5037

5138
LegacyIndexTemplateCreator(HttpSender httpClient) {
@@ -83,9 +70,26 @@ public void createIndexTemplate(ElasticConfig configuration) throws Throwable {
8370
boolean enableSource = configuration.enableSource();
8471
HttpSender.Request.Builder request = this.httpClient.put(configuration.host() + INDEX_TEMPLATE_PATH);
8572
configureAuthentication(configuration, request);
86-
request.withJsonContent(String.format(indexTemplateRequest, indexPattern, enableSource))
73+
request.withJsonContent(createIndexTemplateRequestBody(indexPattern, enableSource))
8774
.send()
8875
.onError(response -> logger.error("Failed to create index template in Elastic: {}", response.body()));
8976
}
9077

78+
private String createIndexTemplateRequestBody(String indexPattern, boolean enableSource) {
79+
return String.format(
80+
"{\n" + " \"index_patterns\": [\"%s*\"],\n" + " \"mappings\": {\n" + " \"_source\": {\n"
81+
+ " \"enabled\": %b\n" + " },\n" + " \"properties\": {\n"
82+
+ " \"name\": { \"type\": \"keyword\" },\n"
83+
+ " \"count\": { \"type\": \"double\", \"index\": false },\n"
84+
+ " \"value\": { \"type\": \"double\", \"index\": false },\n"
85+
+ " \"sum\": { \"type\": \"double\", \"index\": false },\n"
86+
+ " \"mean\": { \"type\": \"double\", \"index\": false },\n"
87+
+ " \"duration\": { \"type\": \"double\", \"index\": false},\n"
88+
+ " \"max\": { \"type\": \"double\", \"index\": false },\n"
89+
+ " \"total\": { \"type\": \"double\", \"index\": false },\n"
90+
+ " \"unknown\": { \"type\": \"double\", \"index\": false },\n"
91+
+ " \"active\": { \"type\": \"double\", \"index\": false }\n" + " }\n" + " }\n" + "}",
92+
indexPattern, enableSource);
93+
}
94+
9195
}

implementations/micrometer-registry-influx/src/main/java/io/micrometer/influx/CreateDatabaseQueryBuilder.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,8 @@
3131
*/
3232
class CreateDatabaseQueryBuilder {
3333

34-
private static final String QUERY_MANDATORY_TEMPLATE = "CREATE DATABASE \"%s\"";
35-
3634
private static final String RETENTION_POLICY_INTRODUCTION = " WITH";
3735

38-
private static final String DURATION_CLAUSE_TEMPLATE = " DURATION %s";
39-
40-
private static final String REPLICATION_FACTOR_CLAUSE_TEMPLATE = " REPLICATION %d";
41-
42-
private static final String SHARD_DURATION_CLAUSE_TEMPLATE = " SHARD DURATION %s";
43-
44-
private static final String NAME_CLAUSE_TEMPLATE = " NAME %s";
45-
4636
private final String databaseName;
4737

4838
private final String[] retentionPolicyClauses = new String[4];
@@ -56,34 +46,34 @@ class CreateDatabaseQueryBuilder {
5646

5747
CreateDatabaseQueryBuilder setRetentionDuration(@Nullable String retentionDuration) {
5848
if (!isEmpty(retentionDuration)) {
59-
retentionPolicyClauses[0] = String.format(DURATION_CLAUSE_TEMPLATE, retentionDuration);
49+
retentionPolicyClauses[0] = String.format(" DURATION %s", retentionDuration);
6050
}
6151
return this;
6252
}
6353

6454
CreateDatabaseQueryBuilder setRetentionReplicationFactor(@Nullable Integer retentionReplicationFactor) {
6555
if (retentionReplicationFactor != null) {
66-
retentionPolicyClauses[1] = String.format(REPLICATION_FACTOR_CLAUSE_TEMPLATE, retentionReplicationFactor);
56+
retentionPolicyClauses[1] = String.format(" REPLICATION %d", retentionReplicationFactor);
6757
}
6858
return this;
6959
}
7060

7161
CreateDatabaseQueryBuilder setRetentionShardDuration(@Nullable String retentionShardDuration) {
7262
if (!isEmpty(retentionShardDuration)) {
73-
retentionPolicyClauses[2] = String.format(SHARD_DURATION_CLAUSE_TEMPLATE, retentionShardDuration);
63+
retentionPolicyClauses[2] = String.format(" SHARD DURATION %s", retentionShardDuration);
7464
}
7565
return this;
7666
}
7767

7868
CreateDatabaseQueryBuilder setRetentionPolicyName(@Nullable String retentionPolicyName) {
7969
if (!isEmpty(retentionPolicyName)) {
80-
retentionPolicyClauses[3] = String.format(NAME_CLAUSE_TEMPLATE, retentionPolicyName);
70+
retentionPolicyClauses[3] = String.format(" NAME %s", retentionPolicyName);
8171
}
8272
return this;
8373
}
8474

8575
String build() {
86-
StringBuilder queryStringBuilder = new StringBuilder(String.format(QUERY_MANDATORY_TEMPLATE, databaseName));
76+
StringBuilder queryStringBuilder = new StringBuilder(String.format("CREATE DATABASE \"%s\"", databaseName));
8777
if (hasAnyRetentionPolicy()) {
8878
String retentionPolicyClause = Stream.of(retentionPolicyClauses)
8979
.filter(Objects::nonNull)

0 commit comments

Comments
 (0)