Skip to content

Commit 4235c5e

Browse files
authored
Fix incorrect log warning when exporting monitoring via HTTP without authentication (#57279)
1 parent 24ab3a1 commit 4235c5e

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExporter.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,9 +763,15 @@ public static List<String> loadSettings(Settings settings) {
763763
* @throws SettingsException if the username is missing, but a password is supplied
764764
*/
765765
@Nullable
766-
private static CredentialsProvider createCredentialsProvider(final Config config) {
766+
// visible for testing
767+
static CredentialsProvider createCredentialsProvider(final Config config) {
767768
final String username = AUTH_USERNAME_SETTING.getConcreteSettingForNamespace(config.name()).get(config.settings());
768769

770+
if (Strings.isNullOrEmpty(username)) {
771+
// nothing to configure; default situation for most users
772+
return null;
773+
}
774+
769775
final String deprecatedPassword = AUTH_PASSWORD_SETTING.getConcreteSettingForNamespace(config.name()).get(config.settings());
770776
final SecureString securePassword = SECURE_AUTH_PASSWORDS.get(config.name());
771777
final String password;

x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExporterTests.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
package org.elasticsearch.xpack.monitoring.exporter.http;
77

8+
import org.apache.http.client.CredentialsProvider;
89
import org.apache.http.entity.ContentType;
910
import org.apache.http.entity.StringEntity;
1011
import org.apache.http.nio.conn.ssl.SSLIOSessionStrategy;
@@ -356,6 +357,17 @@ public void testCreateRestClient() throws IOException {
356357
}
357358
}
358359

360+
public void testCreateCredentialsProviderWithoutSecurity() {
361+
final Settings.Builder builder = Settings.builder()
362+
.put("xpack.monitoring.exporters._http.type", "http")
363+
.put("xpack.monitoring.exporters._http.host", "http://localhost:9200");
364+
365+
final Config config = createConfig(builder.build());
366+
CredentialsProvider provider = HttpExporter.createCredentialsProvider(config);
367+
368+
assertNull(provider);
369+
}
370+
359371
public void testCreateSnifferDisabledByDefault() {
360372
final Config config = createConfig(Settings.EMPTY);
361373
final RestClient client = mock(RestClient.class);

0 commit comments

Comments
 (0)