in apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/ApmServerConfigurationSource.java [185:235]
private String tryFetchConfig(ConfigurationRegistry configurationRegistry, HttpURLConnection connection) throws IOException, DslJsonSerializer.UninitializedException {
if (logger.isDebugEnabled()) {
logger.debug("Reloading configuration from APM Server {}", connection.getURL());
}
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestMethod("POST");
connection.setDoOutput(true);
if (etag != null) {
connection.setRequestProperty("If-None-Match", etag);
}
payloadSerializer.setOutputStream(connection.getOutputStream());
payloadSerializer.appendMetadataToStream();
payloadSerializer.fullFlush();
etag = connection.getHeaderField("ETag");
final int status = connection.getResponseCode();
switch (status) {
case SC_OK:
InputStream is = connection.getInputStream();
final JsonReader<Object> reader = dslJson.newReader(is, buffer);
reader.startObject();
config = MapConverter.deserialize(reader);
configurationRegistry.reloadDynamicConfigurationOptions();
logger.info("Received new configuration from APM Server: {}", config);
for (Map.Entry<String, String> entry : config.entrySet()) {
ConfigurationOption<?> conf = configurationRegistry.getConfigurationOptionByKey(entry.getKey());
if (IGNORED_REMOTE_KEYS.contains(entry.getKey())) {
logger.debug("Received ignored remote configuration key {}", entry.getKey());
} else if (conf == null) {
logger.warn("Received unknown remote configuration key {}", entry.getKey());
} else if (!conf.isDynamic()) {
logger.warn("Can't apply remote configuration {} as this option is not dynamic (aka. reloadable)", entry.getKey());
}
}
break;
case SC_NOT_MODIFIED:
logger.debug("Configuration did not change");
break;
case SC_NOT_FOUND:
logger.debug("This APM Server does not support central configuration. Update to APM Server 7.3+");
break;
case SC_FORBIDDEN:
logger.debug("Central configuration is disabled. Set kibana.enabled: true in your APM Server configuration.");
break;
case SC_SERVICE_UNAVAILABLE:
throw new IllegalStateException("Remote configuration is not available. Check the connection between APM Server and Kibana.");
default:
throw new IllegalStateException("Unexpected status " + status + " while fetching configuration");
}
return connection.getHeaderField("Cache-Control");
}