Skip to content

Commit f64f5a0

Browse files
committed
Expose Elastic's pipeline and indexDateSeparator properties
Closes gh-20852
1 parent f293f6a commit f64f5a0

File tree

4 files changed

+57
-6
lines changed

4 files changed

+57
-6
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticProperties.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -40,11 +40,15 @@ public class ElasticProperties extends StepRegistryProperties {
4040
private String index = "metrics";
4141

4242
/**
43-
* Index date format used for rolling indices. Appended to the index name, preceded by
44-
* a '-'.
43+
* Index date format used for rolling indices. Appended to the index name.
4544
*/
4645
private String indexDateFormat = "yyyy-MM";
4746

47+
/**
48+
* Prefix to separate the index name from the date format used for rolling indices.
49+
*/
50+
private String indexDateSeparator = "-";
51+
4852
/**
4953
* Name of the timestamp field.
5054
*/
@@ -65,6 +69,11 @@ public class ElasticProperties extends StepRegistryProperties {
6569
*/
6670
private String password = "";
6771

72+
/**
73+
* Ingest pipeline name. By default, events are not pre-processed.
74+
*/
75+
private String pipeline = "";
76+
6877
public String getHost() {
6978
return this.host;
7079
}
@@ -89,6 +98,14 @@ public void setIndexDateFormat(String indexDateFormat) {
8998
this.indexDateFormat = indexDateFormat;
9099
}
91100

101+
public String getIndexDateSeparator() {
102+
return this.indexDateSeparator;
103+
}
104+
105+
public void setIndexDateSeparator(String indexDateSeparator) {
106+
this.indexDateSeparator = indexDateSeparator;
107+
}
108+
92109
public String getTimestampFieldName() {
93110
return this.timestampFieldName;
94111
}
@@ -121,4 +138,12 @@ public void setPassword(String password) {
121138
this.password = password;
122139
}
123140

141+
public String getPipeline() {
142+
return this.pipeline;
143+
}
144+
145+
public void setPipeline(String pipeline) {
146+
this.pipeline = pipeline;
147+
}
148+
124149
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticPropertiesConfigAdapter.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -47,6 +47,11 @@ public String indexDateFormat() {
4747
return get(ElasticProperties::getIndexDateFormat, ElasticConfig.super::indexDateFormat);
4848
}
4949

50+
@Override
51+
public String indexDateSeparator() {
52+
return get(ElasticProperties::getIndexDateSeparator, ElasticConfig.super::indexDateSeparator);
53+
}
54+
5055
@Override
5156
public String timestampFieldName() {
5257
return get(ElasticProperties::getTimestampFieldName, ElasticConfig.super::timestampFieldName);
@@ -67,4 +72,9 @@ public String password() {
6772
return get(ElasticProperties::getPassword, ElasticConfig.super::password);
6873
}
6974

75+
@Override
76+
public String pipeline() {
77+
return get(ElasticProperties::getPipeline, ElasticConfig.super::pipeline);
78+
}
79+
7080
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticPropertiesConfigAdapterTests.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -48,6 +48,13 @@ void whenPropertiesIndexDateFormatIsSetAdapterIndexDateFormatReturnsIt() {
4848
assertThat(new ElasticPropertiesConfigAdapter(properties).indexDateFormat()).isEqualTo("yyyy");
4949
}
5050

51+
@Test
52+
void whenPropertiesIndexDateSeparatorIsSetAdapterIndexDateFormatReturnsIt() {
53+
ElasticProperties properties = new ElasticProperties();
54+
properties.setIndexDateSeparator("*");
55+
assertThat(new ElasticPropertiesConfigAdapter(properties).indexDateSeparator()).isEqualTo("*");
56+
}
57+
5158
@Test
5259
void whenPropertiesTimestampFieldNameIsSetAdapterTimestampFieldNameReturnsIt() {
5360
ElasticProperties properties = new ElasticProperties();
@@ -76,4 +83,11 @@ void whenPropertiesPasswordIsSetAdapterPasswordReturnsIt() {
7683
assertThat(new ElasticPropertiesConfigAdapter(properties).password()).isEqualTo("secret");
7784
}
7885

86+
@Test
87+
void whenPropertiesPipelineIsSetAdapterPasswordReturnsIt() {
88+
ElasticProperties properties = new ElasticProperties();
89+
properties.setPipeline("testPipeline");
90+
assertThat(new ElasticPropertiesConfigAdapter(properties).pipeline()).isEqualTo("testPipeline");
91+
}
92+
7993
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticPropertiesTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,10 +38,12 @@ void defaultValuesAreConsistent() {
3838
assertThat(properties.getHost()).isEqualTo(config.host());
3939
assertThat(properties.getIndex()).isEqualTo(config.index());
4040
assertThat(properties.getIndexDateFormat()).isEqualTo(config.indexDateFormat());
41+
assertThat(properties.getIndexDateSeparator()).isEqualTo(config.indexDateSeparator());
4142
assertThat(properties.getPassword()).isEqualTo(config.password());
4243
assertThat(properties.getTimestampFieldName()).isEqualTo(config.timestampFieldName());
4344
assertThat(properties.getUserName()).isEqualTo(config.userName());
4445
assertThat(properties.isAutoCreateIndex()).isEqualTo(config.autoCreateIndex());
46+
assertThat(properties.getPipeline()).isEqualTo(config.pipeline());
4547
}
4648

4749
}

0 commit comments

Comments
 (0)