use of com.wavefront.api.agent.AgentConfiguration in project java by wavefrontHQ.
the class AbstractAgent method fetchConfig.
/**
* Fetch configuration of the daemon from remote server.
*
* @return Fetched configuration. {@code null} if the configuration is invalid.
*/
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
private AgentConfiguration fetchConfig() {
AgentConfiguration newConfig = null;
JsonNode agentMetricsWorkingCopy;
long agentMetricsCaptureTsWorkingCopy;
synchronized (agentConfigurationExecutor) {
if (agentMetrics == null)
return null;
agentMetricsWorkingCopy = agentMetrics;
agentMetricsCaptureTsWorkingCopy = agentMetricsCaptureTs;
agentMetrics = null;
}
logger.info("fetching configuration from server at: " + server);
try {
newConfig = agentAPI.checkin(agentId, hostname, token, props.getString("build.version"), agentMetricsCaptureTsWorkingCopy, localAgent, agentMetricsWorkingCopy, pushAgent, ephemeral);
agentMetricsWorkingCopy = null;
} catch (NotAuthorizedException ex) {
fetchConfigError("HTTP 401 Unauthorized: Please verify that your server and token settings", "are correct and that the token has Proxy Management permission!");
return null;
} catch (ClientErrorException ex) {
if (ex.getResponse().getStatus() == 407) {
fetchConfigError("HTTP 407 Proxy Authentication Required: Please verify that proxyUser and proxyPassword", "settings are correct and make sure your HTTP proxy is not rate limiting!");
return null;
}
if (ex.getResponse().getStatus() == 404) {
fetchConfigError("HTTP 404 Not Found: Please verify that your server setting is correct: " + server, null);
return null;
}
fetchConfigError("HTTP " + ex.getResponse().getStatus() + " error: Unable to retrieve proxy configuration!", server + ": " + Throwables.getRootCause(ex).getMessage());
return null;
} catch (ProcessingException ex) {
Throwable rootCause = Throwables.getRootCause(ex);
if (rootCause instanceof UnknownHostException) {
fetchConfigError("Unknown host: " + server + ". Please verify your DNS and network settings!", null);
return null;
}
if (rootCause instanceof ConnectException || rootCause instanceof SocketTimeoutException) {
fetchConfigError("Unable to connect to " + server + ": " + rootCause.getMessage(), "Please verify your network/firewall settings!");
return null;
}
fetchConfigError("Request processing error: Unable to retrieve proxy configuration!", server + ": " + rootCause);
return null;
} catch (Exception ex) {
fetchConfigError("Unable to retrieve proxy configuration from remote server!", server + ": " + Throwables.getRootCause(ex));
return null;
} finally {
synchronized (agentConfigurationExecutor) {
// not been updated yet, restore last known set of agent metrics to be retried
if (agentMetricsWorkingCopy != null && agentMetrics == null) {
agentMetrics = agentMetricsWorkingCopy;
}
}
}
try {
if (newConfig.currentTime != null) {
Clock.set(newConfig.currentTime);
}
newConfig.validate(localAgent);
} catch (Exception ex) {
logger.log(Level.WARNING, "configuration file read from server is invalid", ex);
try {
agentAPI.agentError(agentId, "Configuration file is invalid: " + ex.toString());
} catch (Exception e) {
logger.log(Level.WARNING, "cannot report error to collector", e);
}
return null;
}
return newConfig;
}
use of com.wavefront.api.agent.AgentConfiguration in project java by wavefrontHQ.
the class PushAgentTest method testIgnoreBackendSpanHeadSamplingPercent.
@Test
public void testIgnoreBackendSpanHeadSamplingPercent() {
proxy.proxyConfig.backendSpanHeadSamplingPercentIgnored = true;
proxy.proxyConfig.traceSamplingRate = 1.0;
AgentConfiguration agentConfiguration = new AgentConfiguration();
agentConfiguration.setSpanSamplingRate(0.5);
proxy.processConfiguration(agentConfiguration);
assertEquals(1.0, proxy.entityProps.getGlobalProperties().getTraceSamplingRate(), 1e-3);
proxy.proxyConfig.backendSpanHeadSamplingPercentIgnored = false;
proxy.processConfiguration(agentConfiguration);
assertEquals(0.5, proxy.entityProps.getGlobalProperties().getTraceSamplingRate(), 1e-3);
}
use of com.wavefront.api.agent.AgentConfiguration in project java by wavefrontHQ.
the class ProxyCheckInSchedulerTest method testDontRetryCheckinOnBadCredentials.
@Test
public void testDontRetryCheckinOnBadCredentials() {
ProxyConfig proxyConfig = EasyMock.createMock(ProxyConfig.class);
ProxyV2API proxyV2API = EasyMock.createMock(ProxyV2API.class);
APIContainer apiContainer = EasyMock.createMock(APIContainer.class);
reset(proxyConfig, proxyV2API, proxyConfig);
expect(proxyConfig.getServer()).andReturn("https://acme.corp/api").anyTimes();
expect(proxyConfig.getToken()).andReturn("abcde12345").anyTimes();
expect(proxyConfig.getHostname()).andReturn("proxyHost").anyTimes();
expect(proxyConfig.isEphemeral()).andReturn(true).anyTimes();
expect(proxyConfig.getAgentMetricsPointTags()).andReturn(Collections.emptyMap()).anyTimes();
String authHeader = "Bearer abcde12345";
AgentConfiguration returnConfig = new AgentConfiguration();
returnConfig.setPointsPerBatch(1234567L);
replay(proxyConfig);
UUID proxyId = ProxyUtil.getOrCreateProxyId(proxyConfig);
expect(apiContainer.getProxyV2API()).andReturn(proxyV2API).anyTimes();
expect(proxyV2API.proxyCheckin(eq(proxyId), eq(authHeader), eq("proxyHost"), eq(getBuildVersion()), anyLong(), anyObject(), eq(true))).andThrow(new ClientErrorException(Response.status(401).build())).once();
replay(proxyV2API, apiContainer);
try {
ProxyCheckInScheduler scheduler = new ProxyCheckInScheduler(proxyId, proxyConfig, apiContainer, x -> fail("We are not supposed to get here"), () -> {
}, () -> {
});
fail("We're not supposed to get here");
} catch (RuntimeException e) {
//
}
verify(proxyConfig, proxyV2API, apiContainer);
}
use of com.wavefront.api.agent.AgentConfiguration in project java by wavefrontHQ.
the class ProxyCheckInSchedulerTest method testDontRetryCheckinOnMisconfiguredUrlThatEndsWithApi.
@Test
public void testDontRetryCheckinOnMisconfiguredUrlThatEndsWithApi() {
ProxyConfig proxyConfig = EasyMock.createMock(ProxyConfig.class);
ProxyV2API proxyV2API = EasyMock.createMock(ProxyV2API.class);
APIContainer apiContainer = EasyMock.createMock(APIContainer.class);
reset(proxyConfig, proxyV2API, proxyConfig);
expect(proxyConfig.getServer()).andReturn("https://acme.corp/api").anyTimes();
expect(proxyConfig.getToken()).andReturn("abcde12345").anyTimes();
expect(proxyConfig.getHostname()).andReturn("proxyHost").anyTimes();
expect(proxyConfig.isEphemeral()).andReturn(true).anyTimes();
expect(proxyConfig.getAgentMetricsPointTags()).andReturn(Collections.emptyMap()).anyTimes();
String authHeader = "Bearer abcde12345";
AgentConfiguration returnConfig = new AgentConfiguration();
returnConfig.setPointsPerBatch(1234567L);
replay(proxyConfig);
UUID proxyId = ProxyUtil.getOrCreateProxyId(proxyConfig);
expect(apiContainer.getProxyV2API()).andReturn(proxyV2API).anyTimes();
expect(proxyV2API.proxyCheckin(eq(proxyId), eq(authHeader), eq("proxyHost"), eq(getBuildVersion()), anyLong(), anyObject(), eq(true))).andThrow(new ClientErrorException(Response.status(404).build())).once();
replay(proxyV2API, apiContainer);
try {
ProxyCheckInScheduler scheduler = new ProxyCheckInScheduler(proxyId, proxyConfig, apiContainer, x -> fail("We are not supposed to get here"), () -> {
}, () -> {
});
fail();
} catch (RuntimeException e) {
//
}
verify(proxyConfig, proxyV2API, apiContainer);
}
use of com.wavefront.api.agent.AgentConfiguration in project java by wavefrontHQ.
the class ProxyCheckInSchedulerTest method testNormalCheckinWithRemoteShutdown.
@Test
public void testNormalCheckinWithRemoteShutdown() {
ProxyConfig proxyConfig = EasyMock.createMock(ProxyConfig.class);
ProxyV2API proxyV2API = EasyMock.createMock(ProxyV2API.class);
APIContainer apiContainer = EasyMock.createMock(APIContainer.class);
reset(proxyConfig, proxyV2API, proxyConfig);
expect(proxyConfig.getServer()).andReturn("https://acme.corp/api/").anyTimes();
expect(proxyConfig.getToken()).andReturn("abcde12345").anyTimes();
expect(proxyConfig.getHostname()).andReturn("proxyHost").anyTimes();
expect(proxyConfig.isEphemeral()).andReturn(true).anyTimes();
expect(proxyConfig.getAgentMetricsPointTags()).andReturn(Collections.emptyMap()).anyTimes();
String authHeader = "Bearer abcde12345";
AgentConfiguration returnConfig = new AgentConfiguration();
returnConfig.setShutOffAgents(true);
replay(proxyConfig);
UUID proxyId = ProxyUtil.getOrCreateProxyId(proxyConfig);
expect(proxyV2API.proxyCheckin(eq(proxyId), eq(authHeader), eq("proxyHost"), eq(getBuildVersion()), anyLong(), anyObject(), eq(true))).andReturn(returnConfig).anyTimes();
expect(apiContainer.getProxyV2API()).andReturn(proxyV2API).anyTimes();
replay(proxyV2API, apiContainer);
AtomicBoolean shutdown = new AtomicBoolean(false);
ProxyCheckInScheduler scheduler = new ProxyCheckInScheduler(proxyId, proxyConfig, apiContainer, x -> {
}, () -> shutdown.set(true), () -> {
});
scheduler.updateProxyMetrics();
scheduler.updateConfiguration();
verify(proxyConfig, proxyV2API, apiContainer);
assertTrue(shutdown.get());
}
Aggregations