Skip to content

Commit

Permalink
Add option to ignore Elasticsearch publish_address
Browse files Browse the repository at this point in the history
The address is used to address Elasticsearch nodes. When
running in a container environment, the published address
may not match the public address of the container.

This option makes the connector ignore the published address
and use the configured address, instead.

Cherry-pick of trinodb/trino@d04b31c

Co-authored-by: Martin Traverso mtraverso@gmail.com
  • Loading branch information
zhenxiao committed Jun 10, 2020
1 parent 4d436fd commit d7e1df7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,14 @@ public class ElasticsearchClient
private final AtomicBoolean started = new AtomicBoolean();
private final Duration refreshInterval;
private final boolean tlsEnabled;
private final boolean ignorePublishAddress;

@Inject
public ElasticsearchClient(ElasticsearchConfig config, Optional<AwsSecurityConfig> awsSecurityConfig)
{
client = createClient(config, awsSecurityConfig);

this.ignorePublishAddress = config.isIgnorePublishAddress();
this.scrollSize = config.getScrollSize();
this.scrollTimeout = config.getScrollTimeout();
this.refreshInterval = config.getNodeRefreshInterval();
Expand Down Expand Up @@ -155,7 +157,7 @@ private void refreshNodes()
.map(address -> HttpHost.create(format("%s://%s", tlsEnabled ? "https" : "http", address)))
.toArray(HttpHost[]::new);

if (hosts.length > 0) {
if (hosts.length > 0 && !ignorePublishAddress) {
client.getLowLevelClient().setHosts(hosts);
}
this.nodes.set(nodes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public enum Security
private File trustStorePath;
private String keystorePassword;
private String truststorePassword;
private boolean ignorePublishAddress;
private boolean verifyHostnames = true;
private Security security;

Expand Down Expand Up @@ -268,6 +269,18 @@ public ElasticsearchConfig setVerifyHostnames(boolean verify)
return this;
}

public boolean isIgnorePublishAddress()
{
return ignorePublishAddress;
}

@Config("elasticsearch.ignore-publish-address")
public ElasticsearchConfig setIgnorePublishAddress(boolean ignorePublishAddress)
{
this.ignorePublishAddress = ignorePublishAddress;
return this;
}

@NotNull
public Optional<Security> getSecurity()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public void testDefaults()
.setTrustStorePath(null)
.setTruststorePassword(null)
.setVerifyHostnames(true)
.setIgnorePublishAddress(false)
.setSecurity(null));
}

Expand All @@ -72,6 +73,7 @@ public void testExplicitPropertyMappings()
.put("elasticsearch.tls.truststore-path", "/tmp/truststore")
.put("elasticsearch.tls.truststore-password", "truststore-password")
.put("elasticsearch.tls.verify-hostnames", "false")
.put("elasticsearch.ignore-publish-address", "true")
.put("elasticsearch.security", "AWS")
.build();

Expand All @@ -92,6 +94,7 @@ public void testExplicitPropertyMappings()
.setTrustStorePath(new File("/tmp/truststore"))
.setTruststorePassword("truststore-password")
.setVerifyHostnames(false)
.setIgnorePublishAddress(true)
.setSecurity(AWS);

assertFullMapping(properties, expected);
Expand Down

0 comments on commit d7e1df7

Please sign in to comment.