Search in sources :

Example 6 with SenderTaskFactoryImpl

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());
}
Also used : HandlerKey(com.wavefront.agent.handlers.HandlerKey) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SenderTaskFactoryImpl(com.wavefront.agent.handlers.SenderTaskFactoryImpl) QueueingFactoryImpl(com.wavefront.agent.queueing.QueueingFactoryImpl) Test(org.junit.Test)

Example 7 with SenderTaskFactoryImpl

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);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SenderTaskFactoryImpl(com.wavefront.agent.handlers.SenderTaskFactoryImpl) QueueingFactoryImpl(com.wavefront.agent.queueing.QueueingFactoryImpl) Test(org.junit.Test)

Aggregations

SenderTaskFactoryImpl (com.wavefront.agent.handlers.SenderTaskFactoryImpl)7 QueueingFactoryImpl (com.wavefront.agent.queueing.QueueingFactoryImpl)7 Test (org.junit.Test)6 HandlerKey (com.wavefront.agent.handlers.HandlerKey)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 URI (java.net.URI)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 ImmutableList (com.google.common.collect.ImmutableList)1 CachingHostnameLookupResolver (com.wavefront.agent.channel.CachingHostnameLookupResolver)1 HealthCheckManagerImpl (com.wavefront.agent.channel.HealthCheckManagerImpl)1 SharedGraphiteHostAnnotator (com.wavefront.agent.channel.SharedGraphiteHostAnnotator)1 ConfigurationException (com.wavefront.agent.config.ConfigurationException)1 GraphiteFormatter (com.wavefront.agent.formatter.GraphiteFormatter)1 DelegatingReportableEntityHandlerFactoryImpl (com.wavefront.agent.handlers.DelegatingReportableEntityHandlerFactoryImpl)1 InternalProxyWavefrontClient (com.wavefront.agent.handlers.InternalProxyWavefrontClient)1 ReportableEntityHandler (com.wavefront.agent.handlers.ReportableEntityHandler)1 ReportableEntityHandlerFactoryImpl (com.wavefront.agent.handlers.ReportableEntityHandlerFactoryImpl)1 TrafficShapingRateLimitAdjuster (com.wavefront.agent.handlers.TrafficShapingRateLimitAdjuster)1 HistogramRecompressor (com.wavefront.agent.histogram.HistogramRecompressor)1 LogsIngester (com.wavefront.agent.logsharvesting.LogsIngester)1