Search in sources :

Example 1 with RateSampler

use of com.wavefront.sdk.entities.tracing.sampling.RateSampler in project java by wavefrontHQ.

the class PushAgentTest method testWavefrontUnifiedPortHandlerPlaintextOverHttp.

@Test
public void testWavefrontUnifiedPortHandlerPlaintextOverHttp() throws Exception {
    port = findAvailablePort(2888);
    int securePort = findAvailablePort(2889);
    int healthCheckPort = findAvailablePort(8881);
    proxy.proxyConfig.privateCertPath = getClass().getClassLoader().getResource("demo.cert").getPath();
    proxy.proxyConfig.privateKeyPath = getClass().getClassLoader().getResource("demo.key").getPath();
    proxy.proxyConfig.tlsPorts = "1,23 , 4,   , " + securePort + "  ,6";
    proxy.initSslContext();
    proxy.proxyConfig.pushListenerPorts = port + "," + securePort;
    proxy.proxyConfig.httpHealthCheckPath = "/health";
    proxy.proxyConfig.httpHealthCheckPorts = String.valueOf(healthCheckPort);
    proxy.proxyConfig.httpHealthCheckAllPorts = true;
    proxy.healthCheckManager = new HealthCheckManagerImpl(proxy.proxyConfig);
    SpanSampler sampler = new SpanSampler(new RateSampler(1.0D), () -> null);
    proxy.startGraphiteListener(String.valueOf(port), mockHandlerFactory, null, sampler);
    proxy.startGraphiteListener(String.valueOf(securePort), mockHandlerFactory, null, sampler);
    proxy.startHealthCheckListener(healthCheckPort);
    waitUntilListenerIsOnline(port);
    waitUntilListenerIsOnline(securePort);
    reset(mockPointHandler);
    mockPointHandler.report(ReportPoint.newBuilder().setTable("dummy").setMetric("metric3.test").setHost("test1").setTimestamp(startTime * 1000).setValue(0.0d).build());
    expectLastCall();
    mockPointHandler.report(ReportPoint.newBuilder().setTable("dummy").setMetric("metric3.test").setHost("test2").setTimestamp((startTime + 1) * 1000).setValue(1.0d).build());
    expectLastCall();
    mockPointHandler.report(ReportPoint.newBuilder().setTable("dummy").setMetric("metric3.test").setHost("test3").setTimestamp((startTime + 2) * 1000).setValue(2.0d).build());
    expectLastCall();
    replay(mockPointHandler);
    // try http connection
    String payloadStr = "metric3.test 0 " + startTime + " source=test1\n" + "metric3.test 1 " + (startTime + 1) + " source=test2\n" + "metric3.test 2 " + (startTime + 2) + // note the lack of newline at the end!
    " source=test3";
    assertEquals(202, httpPost("http://localhost:" + port, payloadStr));
    assertEquals(200, httpGet("http://localhost:" + port + "/health"));
    assertEquals(202, httpGet("http://localhost:" + port + "/health2"));
    assertEquals(200, httpGet("http://localhost:" + healthCheckPort + "/health"));
    assertEquals(404, httpGet("http://localhost:" + healthCheckPort + "/health2"));
    verify(mockPointHandler);
    // secure test
    reset(mockPointHandler);
    mockPointHandler.report(ReportPoint.newBuilder().setTable("dummy").setMetric("metric3.test").setHost("test4").setTimestamp(startTime * 1000).setValue(0.0d).build());
    expectLastCall();
    mockPointHandler.report(ReportPoint.newBuilder().setTable("dummy").setMetric("metric3.test").setHost("test5").setTimestamp((startTime + 1) * 1000).setValue(1.0d).build());
    expectLastCall();
    mockPointHandler.report(ReportPoint.newBuilder().setTable("dummy").setMetric("metric3.test").setHost("test6").setTimestamp((startTime + 2) * 1000).setValue(2.0d).build());
    expectLastCall();
    replay(mockPointHandler);
    // try http connection
    payloadStr = "metric3.test 0 " + startTime + " source=test4\n" + "metric3.test 1 " + (startTime + 1) + " source=test5\n" + "metric3.test 2 " + (startTime + 2) + // note the lack of newline at the end!
    " source=test6";
    assertEquals(202, httpPost("https://localhost:" + securePort, payloadStr));
    verify(mockPointHandler);
}
Also used : RateSampler(com.wavefront.sdk.entities.tracing.sampling.RateSampler) SpanSampler(com.wavefront.agent.sampler.SpanSampler) EasyMock.anyString(org.easymock.EasyMock.anyString) HealthCheckManagerImpl(com.wavefront.agent.channel.HealthCheckManagerImpl) ReportPoint(wavefront.report.ReportPoint) Test(org.junit.Test)

Example 2 with RateSampler

use of com.wavefront.sdk.entities.tracing.sampling.RateSampler in project java by wavefrontHQ.

the class PushAgentTest method testCustomTraceUnifiedPortHandlerPlaintext.

@Test
public void testCustomTraceUnifiedPortHandlerPlaintext() throws Exception {
    customTracePort = findAvailablePort(50000);
    proxy.proxyConfig.customTracingListenerPorts = String.valueOf(customTracePort);
    proxy.startCustomTracingListener(proxy.proxyConfig.getCustomTracingListenerPorts(), mockHandlerFactory, mockWavefrontSender, new SpanSampler(new RateSampler(1.0D), () -> null));
    waitUntilListenerIsOnline(customTracePort);
    reset(mockTraceHandler);
    reset(mockTraceSpanLogsHandler);
    reset(mockWavefrontSender);
    String traceId = UUID.randomUUID().toString();
    long timestamp1 = startTime * 1000000 + 12345;
    long timestamp2 = startTime * 1000000 + 23456;
    String spanData = "testSpanName source=testsource spanId=testspanid " + "traceId=\"" + traceId + "\" application=application1 service=service1 " + startTime + " " + (startTime + 1) + "\n";
    mockTraceSpanLogsHandler.report(SpanLogs.newBuilder().setCustomer("dummy").setTraceId(traceId).setSpanId("testspanid").setLogs(ImmutableList.of(SpanLog.newBuilder().setTimestamp(timestamp1).setFields(ImmutableMap.of("key", "value", "key2", "value2")).build(), SpanLog.newBuilder().setTimestamp(timestamp2).setFields(ImmutableMap.of("key3", "value3", "key4", "value4")).build())).build());
    expectLastCall();
    mockTraceSpanLogsHandler.report(SpanLogs.newBuilder().setCustomer("dummy").setTraceId(traceId).setSpanId("testspanid").setLogs(ImmutableList.of(SpanLog.newBuilder().setTimestamp(timestamp1).setFields(ImmutableMap.of("key", "value", "key2", "value2")).build(), SpanLog.newBuilder().setTimestamp(timestamp2).setFields(ImmutableMap.of("key3", "value3", "key4", "value4")).build())).build());
    expectLastCall();
    mockTraceHandler.report(Span.newBuilder().setCustomer("dummy").setStartMillis(startTime * 1000).setDuration(1000).setName("testSpanName").setSource("testsource").setSpanId("testspanid").setTraceId(traceId).setAnnotations(ImmutableList.of(new Annotation("application", "application1"), new Annotation("service", "service1"))).build());
    expectLastCall();
    Capture<HashMap<String, String>> tagsCapture = EasyMock.newCapture();
    mockWavefrontSender.sendMetric(eq(HEART_BEAT_METRIC), eq(1.0), anyLong(), eq("testsource"), EasyMock.capture(tagsCapture));
    EasyMock.expectLastCall().anyTimes();
    replay(mockTraceHandler, mockTraceSpanLogsHandler, mockWavefrontSender);
    Socket socket = SocketFactory.getDefault().createSocket("localhost", customTracePort);
    BufferedOutputStream stream = new BufferedOutputStream(socket.getOutputStream());
    String payloadStr = spanData + "{\"spanId\":\"testspanid\",\"traceId\":\"" + traceId + "\",\"logs\":[{\"timestamp\":" + timestamp1 + ",\"fields\":{\"key\":\"value\",\"key2\":\"value2\"}},{\"timestamp\":" + timestamp2 + ",\"fields\":{\"key3\":\"value3\",\"key4\":\"value4\"}}]}\n" + "{\"spanId\":\"testspanid\",\"traceId\":\"" + traceId + "\",\"logs\":[{\"timestamp\":" + timestamp1 + ",\"fields\":{\"key\":\"value\",\"key2\":\"value2\"}},{\"timestamp\":" + timestamp2 + ",\"fields\":{\"key3\":\"value3\",\"key4\":\"value4\"}}]," + "\"span\":\"" + escapeSpanData(spanData) + "\"}\n";
    stream.write(payloadStr.getBytes());
    stream.flush();
    socket.close();
    verifyWithTimeout(500, mockTraceHandler, mockTraceSpanLogsHandler, mockWavefrontSender);
    HashMap<String, String> tagsReturned = tagsCapture.getValue();
    assertEquals("application1", tagsReturned.get(APPLICATION_TAG_KEY));
    assertEquals("service1", tagsReturned.get(SERVICE_TAG_KEY));
    assertEquals("none", tagsReturned.get(CLUSTER_TAG_KEY));
    assertEquals("none", tagsReturned.get(SHARD_TAG_KEY));
}
Also used : RateSampler(com.wavefront.sdk.entities.tracing.sampling.RateSampler) HashMap(java.util.HashMap) SpanSampler(com.wavefront.agent.sampler.SpanSampler) EasyMock.anyString(org.easymock.EasyMock.anyString) BufferedOutputStream(java.io.BufferedOutputStream) Annotation(wavefront.report.Annotation) Socket(java.net.Socket) Test(org.junit.Test)

Example 3 with RateSampler

use of com.wavefront.sdk.entities.tracing.sampling.RateSampler in project java by wavefrontHQ.

the class PushAgentTest method testDeltaCounterHandlerMixedData.

@Test
public void testDeltaCounterHandlerMixedData() throws Exception {
    deltaPort = findAvailablePort(5888);
    proxy.proxyConfig.deltaCountersAggregationListenerPorts = String.valueOf(deltaPort);
    proxy.proxyConfig.deltaCountersAggregationIntervalSeconds = 10;
    proxy.proxyConfig.pushFlushInterval = 100;
    proxy.startDeltaCounterListener(proxy.proxyConfig.getDeltaCountersAggregationListenerPorts(), null, mockSenderTaskFactory, new SpanSampler(new RateSampler(1.0D), () -> null));
    waitUntilListenerIsOnline(deltaPort);
    reset(mockSenderTask);
    Capture<String> capturedArgument = Capture.newInstance(CaptureType.ALL);
    mockSenderTask.add(EasyMock.capture(capturedArgument));
    expectLastCall().atLeastOnce();
    replay(mockSenderTask);
    String payloadStr1 = "∆test.mixed1 1.0 source=test1\n";
    String payloadStr2 = "∆test.mixed2 2.0 source=test1\n";
    String payloadStr3 = "test.mixed3 3.0 source=test1\n";
    String payloadStr4 = "∆test.mixed3 3.0 source=test1\n";
    assertEquals(202, httpPost("http://localhost:" + deltaPort, payloadStr1 + payloadStr2 + payloadStr2 + payloadStr3 + payloadStr4));
    ReportableEntityHandler<?, ?> handler = proxy.deltaCounterHandlerFactory.getHandler(HandlerKey.of(ReportableEntityType.POINT, String.valueOf(deltaPort)));
    if (handler instanceof DeltaCounterAccumulationHandlerImpl) {
        ((DeltaCounterAccumulationHandlerImpl) handler).flushDeltaCounters();
    }
    verify(mockSenderTask);
    assertEquals(3, capturedArgument.getValues().size());
    assertTrue(capturedArgument.getValues().get(0).startsWith("\"∆test.mixed1\" 1.0"));
    assertTrue(capturedArgument.getValues().get(1).startsWith("\"∆test.mixed2\" 4.0"));
    assertTrue(capturedArgument.getValues().get(2).startsWith("\"∆test.mixed3\" 3.0"));
}
Also used : RateSampler(com.wavefront.sdk.entities.tracing.sampling.RateSampler) SpanSampler(com.wavefront.agent.sampler.SpanSampler) EasyMock.anyString(org.easymock.EasyMock.anyString) DeltaCounterAccumulationHandlerImpl(com.wavefront.agent.handlers.DeltaCounterAccumulationHandlerImpl) Test(org.junit.Test)

Example 4 with RateSampler

use of com.wavefront.sdk.entities.tracing.sampling.RateSampler in project java by wavefrontHQ.

the class PushAgentTest method testWavefrontUnifiedPortHandlerGzippedPlaintextStream.

@Test
public void testWavefrontUnifiedPortHandlerGzippedPlaintextStream() throws Exception {
    port = findAvailablePort(2888);
    int securePort = findAvailablePort(2889);
    proxy.proxyConfig.privateCertPath = getClass().getClassLoader().getResource("demo.cert").getPath();
    proxy.proxyConfig.privateKeyPath = getClass().getClassLoader().getResource("demo.key").getPath();
    proxy.proxyConfig.tlsPorts = "1,23 , 4,   , " + securePort + "  ,6";
    proxy.initSslContext();
    proxy.proxyConfig.pushListenerPorts = port + "," + securePort;
    SpanSampler sampler = new SpanSampler(new RateSampler(1.0D), () -> null);
    proxy.startGraphiteListener(String.valueOf(port), mockHandlerFactory, null, sampler);
    proxy.startGraphiteListener(String.valueOf(securePort), mockHandlerFactory, null, sampler);
    waitUntilListenerIsOnline(port);
    waitUntilListenerIsOnline(securePort);
    reset(mockPointHandler);
    mockPointHandler.report(ReportPoint.newBuilder().setTable("dummy").setMetric("metric2.test").setHost("test1").setTimestamp(startTime * 1000).setValue(0.0d).build());
    expectLastCall();
    mockPointHandler.report(ReportPoint.newBuilder().setTable("dummy").setMetric("metric2.test").setHost("test2").setTimestamp((startTime + 1) * 1000).setValue(1.0d).build());
    expectLastCall();
    replay(mockPointHandler);
    // try gzipped plaintext stream over tcp
    String payloadStr = "metric2.test 0 " + startTime + " source=test1\n" + "metric2.test 1 " + (startTime + 1) + " source=test2\n";
    Socket socket = SocketFactory.getDefault().createSocket("localhost", port);
    ByteArrayOutputStream baos = new ByteArrayOutputStream(payloadStr.length());
    GZIPOutputStream gzip = new GZIPOutputStream(baos);
    gzip.write(payloadStr.getBytes("UTF-8"));
    gzip.close();
    socket.getOutputStream().write(baos.toByteArray());
    socket.getOutputStream().flush();
    socket.close();
    verifyWithTimeout(500, mockPointHandler);
    // secure test
    reset(mockPointHandler);
    mockPointHandler.report(ReportPoint.newBuilder().setTable("dummy").setMetric("metric2.test").setHost("test3").setTimestamp(startTime * 1000).setValue(0.0d).build());
    expectLastCall();
    mockPointHandler.report(ReportPoint.newBuilder().setTable("dummy").setMetric("metric2.test").setHost("test4").setTimestamp((startTime + 1) * 1000).setValue(1.0d).build());
    expectLastCall();
    replay(mockPointHandler);
    // try gzipped plaintext stream over tcp
    payloadStr = "metric2.test 0 " + startTime + " source=test3\n" + "metric2.test 1 " + (startTime + 1) + " source=test4\n";
    socket = sslSocketFactory.createSocket("localhost", securePort);
    baos = new ByteArrayOutputStream(payloadStr.length());
    gzip = new GZIPOutputStream(baos);
    gzip.write(payloadStr.getBytes("UTF-8"));
    gzip.close();
    socket.getOutputStream().write(baos.toByteArray());
    socket.getOutputStream().flush();
    socket.close();
    verifyWithTimeout(500, mockPointHandler);
}
Also used : RateSampler(com.wavefront.sdk.entities.tracing.sampling.RateSampler) GZIPOutputStream(java.util.zip.GZIPOutputStream) SpanSampler(com.wavefront.agent.sampler.SpanSampler) EasyMock.anyString(org.easymock.EasyMock.anyString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ReportPoint(wavefront.report.ReportPoint) Socket(java.net.Socket) Test(org.junit.Test)

Example 5 with RateSampler

use of com.wavefront.sdk.entities.tracing.sampling.RateSampler in project java by wavefrontHQ.

the class PushAgentTest method testTraceUnifiedPortHandlerPlaintextDebugSampling.

@Test
public void testTraceUnifiedPortHandlerPlaintextDebugSampling() throws Exception {
    tracePort = findAvailablePort(3888);
    proxy.proxyConfig.traceListenerPorts = String.valueOf(tracePort);
    proxy.startTraceListener(proxy.proxyConfig.getTraceListenerPorts(), mockHandlerFactory, new SpanSampler(new RateSampler(0.0D), () -> null));
    waitUntilListenerIsOnline(tracePort);
    reset(mockTraceHandler);
    reset(mockTraceSpanLogsHandler);
    String traceId = UUID.randomUUID().toString();
    long timestamp1 = startTime * 1000000 + 12345;
    long timestamp2 = startTime * 1000000 + 23456;
    String spanData = "testSpanName parent=parent1 source=testsource spanId=testspanid " + "traceId=\"" + traceId + "\" debug=true " + startTime + " " + (startTime + 1) + "\n";
    mockTraceSpanLogsHandler.report(SpanLogs.newBuilder().setCustomer("dummy").setTraceId(traceId).setSpanId("testspanid").setLogs(ImmutableList.of(SpanLog.newBuilder().setTimestamp(timestamp1).setFields(ImmutableMap.of("key", "value", "key2", "value2")).build(), SpanLog.newBuilder().setTimestamp(timestamp2).setFields(ImmutableMap.of("key3", "value3", "key4", "value4")).build())).build());
    expectLastCall();
    mockTraceSpanLogsHandler.report(SpanLogs.newBuilder().setCustomer("dummy").setTraceId(traceId).setSpanId("testspanid").setLogs(ImmutableList.of(SpanLog.newBuilder().setTimestamp(timestamp1).setFields(ImmutableMap.of("key", "value", "key2", "value2")).build(), SpanLog.newBuilder().setTimestamp(timestamp2).setFields(ImmutableMap.of("key3", "value3", "key4", "value4")).build())).build());
    expectLastCall();
    mockTraceHandler.report(Span.newBuilder().setCustomer("dummy").setStartMillis(startTime * 1000).setDuration(1000).setName("testSpanName").setSource("testsource").setSpanId("testspanid").setTraceId(traceId).setAnnotations(ImmutableList.of(new Annotation("parent", "parent1"), new Annotation("debug", "true"))).build());
    expectLastCall();
    replay(mockTraceHandler);
    replay(mockTraceSpanLogsHandler);
    Socket socket = SocketFactory.getDefault().createSocket("localhost", tracePort);
    BufferedOutputStream stream = new BufferedOutputStream(socket.getOutputStream());
    String payloadStr = spanData + "{\"spanId\":\"testspanid\",\"traceId\":\"" + traceId + "\",\"logs\":[{\"timestamp\":" + timestamp1 + ",\"fields\":{\"key\":\"value\",\"key2\":\"value2\"}},{\"timestamp\":" + timestamp2 + ",\"fields\":{\"key3\":\"value3\",\"key4\":\"value4\"}}]}\n" + "{\"spanId\":\"testspanid\",\"traceId\":\"" + traceId + "\",\"logs\":[{\"timestamp\":" + timestamp1 + ",\"fields\":{\"key\":\"value\",\"key2\":\"value2\"}},{\"timestamp\":" + timestamp2 + ",\"fields\":{\"key3\":\"value3\",\"key4\":\"value4\"}}]," + "\"span\":\"" + escapeSpanData(spanData) + "\"}\n";
    stream.write(payloadStr.getBytes());
    stream.flush();
    socket.close();
    verifyWithTimeout(500, mockTraceHandler, mockTraceSpanLogsHandler);
}
Also used : RateSampler(com.wavefront.sdk.entities.tracing.sampling.RateSampler) SpanSampler(com.wavefront.agent.sampler.SpanSampler) EasyMock.anyString(org.easymock.EasyMock.anyString) BufferedOutputStream(java.io.BufferedOutputStream) Annotation(wavefront.report.Annotation) Socket(java.net.Socket) Test(org.junit.Test)

Aggregations

SpanSampler (com.wavefront.agent.sampler.SpanSampler)36 RateSampler (com.wavefront.sdk.entities.tracing.sampling.RateSampler)36 Test (org.junit.Test)35 Annotation (wavefront.report.Annotation)23 EasyMock.anyString (org.easymock.EasyMock.anyString)13 Span (wavefront.report.Span)12 Socket (java.net.Socket)10 Batch (io.jaegertracing.thriftjava.Batch)9 Process (io.jaegertracing.thriftjava.Process)9 BufferedOutputStream (java.io.BufferedOutputStream)9 ByteString (com.google.protobuf.ByteString)8 Tag (io.jaegertracing.thriftjava.Tag)8 Collector (io.opentelemetry.exporters.jaeger.proto.api_v2.Collector)8 Model (io.opentelemetry.exporters.jaeger.proto.api_v2.Model)8 ByteBuffer (java.nio.ByteBuffer)8 Collector (io.jaegertracing.thriftjava.Collector)7 ReportPoint (wavefront.report.ReportPoint)7 NoopHealthCheckManager (com.wavefront.agent.channel.NoopHealthCheckManager)5 ByteBuf (io.netty.buffer.ByteBuf)5 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)5