use of com.wavefront.agent.handlers.SenderTaskFactoryImpl in project java by wavefrontHQ.
the class HttpEndToEndTest method testEndToEndMetrics.
@Test
public void testEndToEndMetrics() throws Exception {
AtomicInteger successfulSteps = new AtomicInteger(0);
AtomicInteger testCounter = new AtomicInteger(0);
long time = Clock.now() / 1000;
proxyPort = findAvailablePort(2898);
String buffer = File.createTempFile("proxyTestBuffer", null).getPath();
proxy = new PushAgent();
proxy.proxyConfig.server = "http://localhost:" + backendPort + "/api/";
proxy.proxyConfig.flushThreads = 1;
proxy.proxyConfig.pushListenerPorts = String.valueOf(proxyPort);
proxy.proxyConfig.pushFlushInterval = 50;
proxy.proxyConfig.bufferFile = buffer;
proxy.proxyConfig.allowRegex = "^.*$";
proxy.proxyConfig.blockRegex = "^.*blocklist.*$";
proxy.proxyConfig.gzipCompression = false;
proxy.start(new String[] {});
waitUntilListenerIsOnline(proxyPort);
if (!(proxy.senderTaskFactory instanceof SenderTaskFactoryImpl))
fail();
if (!(proxy.queueingFactory instanceof QueueingFactoryImpl))
fail();
String payload = "metric.name 1 " + time + " source=metric.source tagk1=tagv1\n" + "metric.name 2 " + time + " source=metric.source tagk1=tagv2\n" + "metric.name 3 " + time + " source=metric.source tagk1=tagv3\n" + "metric.name 4 " + time + " source=metric.source tagk1=tagv4\n";
String expectedTest1part1 = "\"metric.name\" 1.0 " + time + " source=\"metric.source\" \"tagk1\"=\"tagv1\"\n" + "\"metric.name\" 2.0 " + time + " source=\"metric.source\" \"tagk1\"=\"tagv2\"";
String expectedTest1part2 = "\"metric.name\" 3.0 " + time + " source=\"metric.source\" \"tagk1\"=\"tagv3\"\n" + "\"metric.name\" 4.0 " + time + " source=\"metric.source\" \"tagk1\"=\"tagv4\"";
server.update(req -> {
String content = req.content().toString(CharsetUtil.UTF_8);
logger.fine("Content received: " + content);
assertEquals(expectedTest1part1 + "\n" + expectedTest1part2, content);
successfulSteps.incrementAndGet();
return makeResponse(HttpResponseStatus.OK, "");
});
gzippedHttpPost("http://localhost:" + proxyPort + "/", payload);
HandlerKey key = HandlerKey.of(ReportableEntityType.POINT, String.valueOf(proxyPort));
((SenderTaskFactoryImpl) proxy.senderTaskFactory).flushNow(key);
assertEquals(1, successfulSteps.getAndSet(0));
AtomicBoolean part1 = new AtomicBoolean(false);
AtomicBoolean part2 = new AtomicBoolean(false);
server.update(req -> {
String content = req.content().toString(CharsetUtil.UTF_8);
logger.fine("Content received: " + content);
switch(testCounter.incrementAndGet()) {
case 1:
assertEquals(expectedTest1part1 + "\n" + expectedTest1part2, content);
successfulSteps.incrementAndGet();
return makeResponse(HttpResponseStatus.TOO_MANY_REQUESTS, "");
case 2:
assertEquals(expectedTest1part1 + "\n" + expectedTest1part2, content);
successfulSteps.incrementAndGet();
return makeResponse(HttpResponseStatus.OK, "");
case 3:
assertEquals(expectedTest1part1 + "\n" + expectedTest1part2, content);
successfulSteps.incrementAndGet();
return makeResponse(HttpResponseStatus.valueOf(407), "");
case 4:
assertEquals(expectedTest1part1 + "\n" + expectedTest1part2, content);
successfulSteps.incrementAndGet();
return makeResponse(HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE, "");
case 5:
case 6:
if (content.equals(expectedTest1part1))
part1.set(true);
if (content.equals(expectedTest1part2))
part2.set(true);
successfulSteps.incrementAndGet();
return makeResponse(HttpResponseStatus.OK, "");
}
throw new IllegalStateException();
});
gzippedHttpPost("http://localhost:" + proxyPort + "/", payload);
((SenderTaskFactoryImpl) proxy.senderTaskFactory).flushNow(key);
((QueueingFactoryImpl) proxy.queueingFactory).flushNow(key);
gzippedHttpPost("http://localhost:" + proxyPort + "/", payload);
((SenderTaskFactoryImpl) proxy.senderTaskFactory).flushNow(key);
for (int i = 0; i < 3; i++) ((QueueingFactoryImpl) proxy.queueingFactory).flushNow(key);
assertEquals(6, successfulSteps.getAndSet(0));
assertTrue(part1.get());
assertTrue(part2.get());
}
use of com.wavefront.agent.handlers.SenderTaskFactoryImpl in project java by wavefrontHQ.
the class HttpEndToEndTest method testEndToEndSpans_SpanLogsWithSpanField.
@Test
public void testEndToEndSpans_SpanLogsWithSpanField() throws Exception {
long time = Clock.now() / 1000;
proxyPort = findAvailablePort(2898);
proxyPort = findAvailablePort(2898);
String buffer = File.createTempFile("proxyTestBuffer", null).getPath();
proxy = new PushAgent();
proxy.proxyConfig.server = "http://localhost:" + backendPort + "/api/";
proxy.proxyConfig.flushThreads = 1;
proxy.proxyConfig.traceListenerPorts = String.valueOf(proxyPort);
proxy.proxyConfig.pushFlushInterval = 50;
proxy.proxyConfig.bufferFile = buffer;
proxy.start(new String[] {});
waitUntilListenerIsOnline(proxyPort);
if (!(proxy.senderTaskFactory instanceof SenderTaskFactoryImpl))
fail();
if (!(proxy.queueingFactory instanceof QueueingFactoryImpl))
fail();
String traceId = UUID.randomUUID().toString();
long timestamp1 = time * 1000000 + 12345;
long timestamp2 = time * 1000000 + 23456;
String payload = "testSpanName parent=parent1 source=testsource spanId=testspanid " + "traceId=\"" + traceId + "\" parent=parent2 " + time + " " + (time + 1) + "\n" + "{\"spanId\":\"testspanid\",\"traceId\":\"" + traceId + "\",\"logs\":[{\"timestamp\":" + timestamp1 + ",\"fields\":{\"key\":\"value\",\"key2\":\"value2\"}},{\"timestamp\":" + timestamp2 + ",\"fields\":{\"key3\":\"value3\",\"key4\":\"value4\"}}],\"span\":\"" + "testSpanName parent=parent1 source=testsource spanId=testspanid traceId=\\\"" + traceId + "\\\" parent=parent2 " + time + " " + (time + 1) + "\\n\"}\n";
String expectedSpan = "\"testSpanName\" source=\"testsource\" spanId=\"testspanid\" " + "traceId=\"" + traceId + "\" \"parent\"=\"parent1\" \"parent\"=\"parent2\" " + (time * 1000) + " 1000";
String expectedSpanLog = "{\"customer\":\"dummy\",\"traceId\":\"" + traceId + "\",\"spanId" + "\":\"testspanid\",\"spanSecondaryId\":null,\"logs\":[{\"timestamp\":" + timestamp1 + "," + "\"fields\":{\"key\":\"value\",\"key2\":\"value2\"}},{\"timestamp\":" + timestamp2 + "," + "\"fields\":{\"key3\":\"value3\",\"key4\":\"value4\"}}],\"span\":null}";
AtomicBoolean gotSpan = new AtomicBoolean(false);
AtomicBoolean gotSpanLog = new AtomicBoolean(false);
server.update(req -> {
String content = req.content().toString(CharsetUtil.UTF_8);
logger.fine("Content received: " + content);
if (content.equals(expectedSpan))
gotSpan.set(true);
if (content.equals(expectedSpanLog))
gotSpanLog.set(true);
return makeResponse(HttpResponseStatus.OK, "");
});
gzippedHttpPost("http://localhost:" + proxyPort + "/", payload);
((SenderTaskFactoryImpl) proxy.senderTaskFactory).flushNow(HandlerKey.of(ReportableEntityType.TRACE, String.valueOf(proxyPort)));
((SenderTaskFactoryImpl) proxy.senderTaskFactory).flushNow(HandlerKey.of(ReportableEntityType.TRACE_SPAN_LOGS, String.valueOf(proxyPort)));
assertTrueWithTimeout(50, gotSpan::get);
assertTrueWithTimeout(50, gotSpanLog::get);
}
Aggregations