Expose Elastic's pipeline and indexDateSeparator properties

Closes gh-20852
This commit is contained in:
Stephane Nicoll 2020-04-06 17:01:16 +02:00
parent f293f6ad9b
commit f64f5a0f55
4 changed files with 57 additions and 6 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -40,11 +40,15 @@ public class ElasticProperties extends StepRegistryProperties {
private String index = "metrics"; private String index = "metrics";
/** /**
* Index date format used for rolling indices. Appended to the index name, preceded by * Index date format used for rolling indices. Appended to the index name.
* a '-'.
*/ */
private String indexDateFormat = "yyyy-MM"; private String indexDateFormat = "yyyy-MM";
/**
* Prefix to separate the index name from the date format used for rolling indices.
*/
private String indexDateSeparator = "-";
/** /**
* Name of the timestamp field. * Name of the timestamp field.
*/ */
@ -65,6 +69,11 @@ public class ElasticProperties extends StepRegistryProperties {
*/ */
private String password = ""; private String password = "";
/**
* Ingest pipeline name. By default, events are not pre-processed.
*/
private String pipeline = "";
public String getHost() { public String getHost() {
return this.host; return this.host;
} }
@ -89,6 +98,14 @@ public class ElasticProperties extends StepRegistryProperties {
this.indexDateFormat = indexDateFormat; this.indexDateFormat = indexDateFormat;
} }
public String getIndexDateSeparator() {
return this.indexDateSeparator;
}
public void setIndexDateSeparator(String indexDateSeparator) {
this.indexDateSeparator = indexDateSeparator;
}
public String getTimestampFieldName() { public String getTimestampFieldName() {
return this.timestampFieldName; return this.timestampFieldName;
} }
@ -121,4 +138,12 @@ public class ElasticProperties extends StepRegistryProperties {
this.password = password; this.password = password;
} }
public String getPipeline() {
return this.pipeline;
}
public void setPipeline(String pipeline) {
this.pipeline = pipeline;
}
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -47,6 +47,11 @@ class ElasticPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter
return get(ElasticProperties::getIndexDateFormat, ElasticConfig.super::indexDateFormat); return get(ElasticProperties::getIndexDateFormat, ElasticConfig.super::indexDateFormat);
} }
@Override
public String indexDateSeparator() {
return get(ElasticProperties::getIndexDateSeparator, ElasticConfig.super::indexDateSeparator);
}
@Override @Override
public String timestampFieldName() { public String timestampFieldName() {
return get(ElasticProperties::getTimestampFieldName, ElasticConfig.super::timestampFieldName); return get(ElasticProperties::getTimestampFieldName, ElasticConfig.super::timestampFieldName);
@ -67,4 +72,9 @@ class ElasticPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter
return get(ElasticProperties::getPassword, ElasticConfig.super::password); return get(ElasticProperties::getPassword, ElasticConfig.super::password);
} }
@Override
public String pipeline() {
return get(ElasticProperties::getPipeline, ElasticConfig.super::pipeline);
}
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -48,6 +48,13 @@ class ElasticPropertiesConfigAdapterTests {
assertThat(new ElasticPropertiesConfigAdapter(properties).indexDateFormat()).isEqualTo("yyyy"); assertThat(new ElasticPropertiesConfigAdapter(properties).indexDateFormat()).isEqualTo("yyyy");
} }
@Test
void whenPropertiesIndexDateSeparatorIsSetAdapterIndexDateFormatReturnsIt() {
ElasticProperties properties = new ElasticProperties();
properties.setIndexDateSeparator("*");
assertThat(new ElasticPropertiesConfigAdapter(properties).indexDateSeparator()).isEqualTo("*");
}
@Test @Test
void whenPropertiesTimestampFieldNameIsSetAdapterTimestampFieldNameReturnsIt() { void whenPropertiesTimestampFieldNameIsSetAdapterTimestampFieldNameReturnsIt() {
ElasticProperties properties = new ElasticProperties(); ElasticProperties properties = new ElasticProperties();
@ -76,4 +83,11 @@ class ElasticPropertiesConfigAdapterTests {
assertThat(new ElasticPropertiesConfigAdapter(properties).password()).isEqualTo("secret"); assertThat(new ElasticPropertiesConfigAdapter(properties).password()).isEqualTo("secret");
} }
@Test
void whenPropertiesPipelineIsSetAdapterPasswordReturnsIt() {
ElasticProperties properties = new ElasticProperties();
properties.setPipeline("testPipeline");
assertThat(new ElasticPropertiesConfigAdapter(properties).pipeline()).isEqualTo("testPipeline");
}
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -38,10 +38,12 @@ class ElasticPropertiesTests extends StepRegistryPropertiesTests {
assertThat(properties.getHost()).isEqualTo(config.host()); assertThat(properties.getHost()).isEqualTo(config.host());
assertThat(properties.getIndex()).isEqualTo(config.index()); assertThat(properties.getIndex()).isEqualTo(config.index());
assertThat(properties.getIndexDateFormat()).isEqualTo(config.indexDateFormat()); assertThat(properties.getIndexDateFormat()).isEqualTo(config.indexDateFormat());
assertThat(properties.getIndexDateSeparator()).isEqualTo(config.indexDateSeparator());
assertThat(properties.getPassword()).isEqualTo(config.password()); assertThat(properties.getPassword()).isEqualTo(config.password());
assertThat(properties.getTimestampFieldName()).isEqualTo(config.timestampFieldName()); assertThat(properties.getTimestampFieldName()).isEqualTo(config.timestampFieldName());
assertThat(properties.getUserName()).isEqualTo(config.userName()); assertThat(properties.getUserName()).isEqualTo(config.userName());
assertThat(properties.isAutoCreateIndex()).isEqualTo(config.autoCreateIndex()); assertThat(properties.isAutoCreateIndex()).isEqualTo(config.autoCreateIndex());
assertThat(properties.getPipeline()).isEqualTo(config.pipeline());
} }
} }