Search in sources :

Example 1 with PreprocessorRuleMetrics

use of com.wavefront.agent.preprocessor.PreprocessorRuleMetrics in project java by wavefrontHQ.

the class JaegerGrpcCollectorHandlerTest method testJaegerPreprocessedDerivedMetrics.

/**
 * Test for derived metrics emitted from Jaeger trace listeners. Derived metrics should report
 * tag values post applying preprocessing rules to the span.
 */
@Test
public void testJaegerPreprocessedDerivedMetrics() throws Exception {
    reset(mockTraceHandler, mockWavefrontSender);
    mockTraceHandler.report(Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(4000).setName("HTTP GET").setSource(PREPROCESSED_SOURCE_VALUE).setSpanId("00000000-0000-0000-0000-00000012d687").setTraceId("00000000-4996-02d2-0000-011f71fb04cb").setAnnotations(ImmutableList.of(new Annotation("ip", "10.0.0.1"), new Annotation("service", PREPROCESSED_SERVICE_TAG_VALUE), new Annotation("application", PREPROCESSED_APPLICATION_TAG_VALUE), new Annotation("cluster", PREPROCESSED_CLUSTER_TAG_VALUE), new Annotation("shard", PREPROCESSED_SHARD_TAG_VALUE))).build());
    expectLastCall();
    Capture<HashMap<String, String>> tagsCapture = EasyMock.newCapture();
    mockWavefrontSender.sendMetric(eq(HEART_BEAT_METRIC), eq(1.0), anyLong(), eq(PREPROCESSED_SOURCE_VALUE), EasyMock.capture(tagsCapture));
    expectLastCall().anyTimes();
    replay(mockTraceHandler, mockWavefrontSender);
    Supplier<ReportableEntityPreprocessor> preprocessorSupplier = () -> {
        ReportableEntityPreprocessor preprocessor = new ReportableEntityPreprocessor();
        PreprocessorRuleMetrics preprocessorRuleMetrics = new PreprocessorRuleMetrics(null, null, null);
        preprocessor.forSpan().addTransformer(new SpanReplaceRegexTransformer(APPLICATION_TAG_KEY, "^Jaeger.*", PREPROCESSED_APPLICATION_TAG_VALUE, null, null, false, x -> true, preprocessorRuleMetrics));
        preprocessor.forSpan().addTransformer(new SpanReplaceRegexTransformer(SERVICE_TAG_KEY, "^test.*", PREPROCESSED_SERVICE_TAG_VALUE, null, null, false, x -> true, preprocessorRuleMetrics));
        preprocessor.forSpan().addTransformer(new SpanReplaceRegexTransformer("sourceName", "^jaeger.*", PREPROCESSED_SOURCE_VALUE, null, null, false, x -> true, preprocessorRuleMetrics));
        preprocessor.forSpan().addTransformer(new SpanReplaceRegexTransformer(CLUSTER_TAG_KEY, "^none.*", PREPROCESSED_CLUSTER_TAG_VALUE, null, null, false, x -> true, preprocessorRuleMetrics));
        preprocessor.forSpan().addTransformer(new SpanReplaceRegexTransformer(SHARD_TAG_KEY, "^none.*", PREPROCESSED_SHARD_TAG_VALUE, null, null, false, x -> true, preprocessorRuleMetrics));
        return preprocessor;
    };
    JaegerGrpcCollectorHandler handler = new JaegerGrpcCollectorHandler("9876", mockTraceHandler, mockTraceLogsHandler, mockWavefrontSender, () -> false, () -> false, preprocessorSupplier, new SpanSampler(new RateSampler(1.0D), () -> null), null, null);
    Model.KeyValue ipTag = Model.KeyValue.newBuilder().setKey("ip").setVStr("10.0.0.1").setVType(Model.ValueType.STRING).build();
    ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES * 2);
    buffer.putLong(1234567890L);
    buffer.putLong(1234567890123L);
    ByteString traceId = ByteString.copyFrom(buffer.array());
    buffer = ByteBuffer.allocate(Long.BYTES);
    buffer.putLong(1234567L);
    ByteString span2Id = ByteString.copyFrom(buffer.array());
    Model.Span span2 = Model.Span.newBuilder().setTraceId(traceId).setSpanId(span2Id).setDuration(Duration.newBuilder().setSeconds(4L).build()).setOperationName("HTTP GET").setStartTime(fromMillis(startTime)).build();
    Model.Batch testBatch = Model.Batch.newBuilder().setProcess(Model.Process.newBuilder().setServiceName("testService").addTags(ipTag).build()).addAllSpans(ImmutableList.of(span2)).build();
    Collector.PostSpansRequest batches = Collector.PostSpansRequest.newBuilder().setBatch(testBatch).build();
    handler.postSpans(batches, emptyStreamObserver);
    handler.run();
    verifyWithTimeout(500, mockTraceHandler, mockWavefrontSender);
    HashMap<String, String> tagsReturned = tagsCapture.getValue();
    assertEquals(PREPROCESSED_APPLICATION_TAG_VALUE, tagsReturned.get(APPLICATION_TAG_KEY));
    assertEquals(PREPROCESSED_SERVICE_TAG_VALUE, tagsReturned.get(SERVICE_TAG_KEY));
    assertEquals(PREPROCESSED_CLUSTER_TAG_VALUE, tagsReturned.get(CLUSTER_TAG_KEY));
    assertEquals(PREPROCESSED_SHARD_TAG_VALUE, tagsReturned.get(SHARD_TAG_KEY));
}
Also used : ReportableEntityPreprocessor(com.wavefront.agent.preprocessor.ReportableEntityPreprocessor) HashMap(java.util.HashMap) RateSampler(com.wavefront.sdk.entities.tracing.sampling.RateSampler) ByteString(com.google.protobuf.ByteString) SpanSampler(com.wavefront.agent.sampler.SpanSampler) ByteString(com.google.protobuf.ByteString) ByteBuffer(java.nio.ByteBuffer) Annotation(wavefront.report.Annotation) PreprocessorRuleMetrics(com.wavefront.agent.preprocessor.PreprocessorRuleMetrics) Model(io.opentelemetry.exporters.jaeger.proto.api_v2.Model) Collector(io.opentelemetry.exporters.jaeger.proto.api_v2.Collector) SpanReplaceRegexTransformer(com.wavefront.agent.preprocessor.SpanReplaceRegexTransformer) Test(org.junit.Test)

Example 2 with PreprocessorRuleMetrics

use of com.wavefront.agent.preprocessor.PreprocessorRuleMetrics in project java by wavefrontHQ.

the class JaegerPortUnificationHandlerTest method testJaegerPreprocessedDerivedMetrics.

/**
 * Test for derived metrics emitted from Jaeger trace listeners. Derived metrics should report
 * tag values post applying preprocessing rules to the span.
 */
@Test
public void testJaegerPreprocessedDerivedMetrics() throws Exception {
    Supplier<ReportableEntityPreprocessor> preprocessorSupplier = () -> {
        ReportableEntityPreprocessor preprocessor = new ReportableEntityPreprocessor();
        PreprocessorRuleMetrics preprocessorRuleMetrics = new PreprocessorRuleMetrics(null, null, null);
        preprocessor.forSpan().addTransformer(new SpanReplaceRegexTransformer(APPLICATION_TAG_KEY, "^Jaeger.*", PREPROCESSED_APPLICATION_TAG_VALUE, null, null, false, x -> true, preprocessorRuleMetrics));
        preprocessor.forSpan().addTransformer(new SpanReplaceRegexTransformer(SERVICE_TAG_KEY, "^test.*", PREPROCESSED_SERVICE_TAG_VALUE, null, null, false, x -> true, preprocessorRuleMetrics));
        preprocessor.forSpan().addTransformer(new SpanReplaceRegexTransformer("sourceName", "^jaeger.*", PREPROCESSED_SOURCE_VALUE, null, null, false, x -> true, preprocessorRuleMetrics));
        preprocessor.forSpan().addTransformer(new SpanReplaceRegexTransformer(CLUSTER_TAG_KEY, "^none.*", PREPROCESSED_CLUSTER_TAG_VALUE, null, null, false, x -> true, preprocessorRuleMetrics));
        preprocessor.forSpan().addTransformer(new SpanReplaceRegexTransformer(SHARD_TAG_KEY, "^none.*", PREPROCESSED_SHARD_TAG_VALUE, null, null, false, x -> true, preprocessorRuleMetrics));
        return preprocessor;
    };
    JaegerPortUnificationHandler handler = new JaegerPortUnificationHandler("14268", TokenAuthenticatorBuilder.create().build(), new NoopHealthCheckManager(), mockTraceHandler, mockTraceSpanLogsHandler, mockWavefrontSender, () -> false, () -> false, preprocessorSupplier, new SpanSampler(new RateSampler(1.0D), () -> null), null, null);
    io.jaegertracing.thriftjava.Span span1 = new io.jaegertracing.thriftjava.Span(1234567890123L, 1234567890L, 1234567L, 0L, "HTTP GET", 1, startTime * 1000, 1234 * 1000);
    Batch testBatch = new Batch();
    testBatch.process = new Process();
    testBatch.process.serviceName = "testService";
    testBatch.setSpans(ImmutableList.of(span1));
    // Reset mock
    reset(mockCtx, mockTraceHandler, mockWavefrontSender);
    // Set Expectation
    Span expectedSpan1 = Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(1234).setName("HTTP GET").setSource(PREPROCESSED_SOURCE_VALUE).setSpanId("00000000-0000-0000-0000-00000012d687").setTraceId("00000000-4996-02d2-0000-011f71fb04cb").setAnnotations(ImmutableList.of(new Annotation("jaegerSpanId", "12d687"), new Annotation("jaegerTraceId", "499602d20000011f71fb04cb"), new Annotation("service", PREPROCESSED_SERVICE_TAG_VALUE), new Annotation("application", PREPROCESSED_APPLICATION_TAG_VALUE), new Annotation("cluster", PREPROCESSED_CLUSTER_TAG_VALUE), new Annotation("shard", PREPROCESSED_SHARD_TAG_VALUE))).build();
    mockTraceHandler.report(expectedSpan1);
    expectLastCall();
    Capture<HashMap<String, String>> tagsCapture = EasyMock.newCapture();
    mockWavefrontSender.sendMetric(eq(HEART_BEAT_METRIC), eq(1.0), anyLong(), eq(PREPROCESSED_SOURCE_VALUE), EasyMock.capture(tagsCapture));
    expectLastCall().anyTimes();
    replay(mockCtx, mockTraceHandler, mockWavefrontSender);
    ByteBuf content = Unpooled.copiedBuffer(new TSerializer().serialize(testBatch));
    FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "http://localhost:14268/api/traces", content, true);
    handler.handleHttpMessage(mockCtx, httpRequest);
    handler.run();
    verifyWithTimeout(500, mockTraceHandler, mockWavefrontSender);
    HashMap<String, String> tagsReturned = tagsCapture.getValue();
    assertEquals(PREPROCESSED_APPLICATION_TAG_VALUE, tagsReturned.get(APPLICATION_TAG_KEY));
    assertEquals(PREPROCESSED_SERVICE_TAG_VALUE, tagsReturned.get(SERVICE_TAG_KEY));
    assertEquals(PREPROCESSED_CLUSTER_TAG_VALUE, tagsReturned.get(CLUSTER_TAG_KEY));
    assertEquals(PREPROCESSED_SHARD_TAG_VALUE, tagsReturned.get(SHARD_TAG_KEY));
}
Also used : ReportableEntityPreprocessor(com.wavefront.agent.preprocessor.ReportableEntityPreprocessor) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) RateSampler(com.wavefront.sdk.entities.tracing.sampling.RateSampler) HashMap(java.util.HashMap) SpanSampler(com.wavefront.agent.sampler.SpanSampler) Process(io.jaegertracing.thriftjava.Process) ByteBuf(io.netty.buffer.ByteBuf) Span(wavefront.report.Span) Annotation(wavefront.report.Annotation) PreprocessorRuleMetrics(com.wavefront.agent.preprocessor.PreprocessorRuleMetrics) TSerializer(org.apache.thrift.TSerializer) Batch(io.jaegertracing.thriftjava.Batch) NoopHealthCheckManager(com.wavefront.agent.channel.NoopHealthCheckManager) SpanReplaceRegexTransformer(com.wavefront.agent.preprocessor.SpanReplaceRegexTransformer) Test(org.junit.Test)

Example 3 with PreprocessorRuleMetrics

use of com.wavefront.agent.preprocessor.PreprocessorRuleMetrics in project java by wavefrontHQ.

the class ZipkinPortUnificationHandlerTest method testZipkinPreprocessedDerivedMetrics.

/**
 * Test for derived metrics emitted from Zipkin trace listeners. Derived metrics should report
 * tag values post applying preprocessing rules to the span.
 */
@Test
public void testZipkinPreprocessedDerivedMetrics() throws Exception {
    Supplier<ReportableEntityPreprocessor> preprocessorSupplier = () -> {
        ReportableEntityPreprocessor preprocessor = new ReportableEntityPreprocessor();
        PreprocessorRuleMetrics preprocessorRuleMetrics = new PreprocessorRuleMetrics(null, null, null);
        preprocessor.forSpan().addTransformer(new SpanReplaceRegexTransformer(APPLICATION_TAG_KEY, "^Zipkin.*", PREPROCESSED_APPLICATION_TAG_VALUE, null, null, false, x -> true, preprocessorRuleMetrics));
        preprocessor.forSpan().addTransformer(new SpanReplaceRegexTransformer(SERVICE_TAG_KEY, "^test.*", PREPROCESSED_SERVICE_TAG_VALUE, null, null, false, x -> true, preprocessorRuleMetrics));
        preprocessor.forSpan().addTransformer(new SpanReplaceRegexTransformer("sourceName", "^zipkin.*", PREPROCESSED_SOURCE_VALUE, null, null, false, x -> true, preprocessorRuleMetrics));
        preprocessor.forSpan().addTransformer(new SpanReplaceRegexTransformer(CLUSTER_TAG_KEY, "^none.*", PREPROCESSED_CLUSTER_TAG_VALUE, null, null, false, x -> true, preprocessorRuleMetrics));
        preprocessor.forSpan().addTransformer(new SpanReplaceRegexTransformer(SHARD_TAG_KEY, "^none.*", PREPROCESSED_SHARD_TAG_VALUE, null, null, false, x -> true, preprocessorRuleMetrics));
        return preprocessor;
    };
    ZipkinPortUnificationHandler handler = new ZipkinPortUnificationHandler("9411", new NoopHealthCheckManager(), mockTraceHandler, mockTraceSpanLogsHandler, mockWavefrontSender, () -> false, () -> false, preprocessorSupplier, new SpanSampler(new RateSampler(1.0D), () -> null), null, null);
    Endpoint localEndpoint1 = Endpoint.newBuilder().serviceName("testService").ip("10.0.0.1").build();
    zipkin2.Span spanServer1 = zipkin2.Span.newBuilder().traceId("2822889fe47043bd").id("2822889fe47043bd").kind(zipkin2.Span.Kind.SERVER).name("getservice").timestamp(startTime * 1000).duration(1234 * 1000).localEndpoint(localEndpoint1).build();
    List<zipkin2.Span> zipkinSpanList = ImmutableList.of(spanServer1);
    // Reset mock
    reset(mockTraceHandler, mockWavefrontSender);
    // Set Expectation
    mockTraceHandler.report(Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(1234).setName("getservice").setSource(PREPROCESSED_SOURCE_VALUE).setSpanId("00000000-0000-0000-2822-889fe47043bd").setTraceId("00000000-0000-0000-2822-889fe47043bd").setAnnotations(ImmutableList.of(new Annotation("zipkinSpanId", "2822889fe47043bd"), new Annotation("zipkinTraceId", "2822889fe47043bd"), new Annotation("span.kind", "server"), new Annotation("service", PREPROCESSED_SERVICE_TAG_VALUE), new Annotation("application", PREPROCESSED_APPLICATION_TAG_VALUE), new Annotation("cluster", PREPROCESSED_CLUSTER_TAG_VALUE), new Annotation("shard", PREPROCESSED_SHARD_TAG_VALUE), new Annotation("ipv4", "10.0.0.1"))).build());
    expectLastCall();
    Capture<HashMap<String, String>> tagsCapture = EasyMock.newCapture();
    mockWavefrontSender.sendMetric(eq(HEART_BEAT_METRIC), eq(1.0), anyLong(), eq(PREPROCESSED_SOURCE_VALUE), EasyMock.capture(tagsCapture));
    expectLastCall().anyTimes();
    replay(mockTraceHandler, mockWavefrontSender);
    ChannelHandlerContext mockCtx = createNiceMock(ChannelHandlerContext.class);
    doMockLifecycle(mockCtx);
    ByteBuf content = Unpooled.copiedBuffer(SpanBytesEncoder.JSON_V2.encodeList(zipkinSpanList));
    FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "http://localhost:9411/api/v2/spans", content, true);
    handler.handleHttpMessage(mockCtx, httpRequest);
    handler.run();
    verifyWithTimeout(500, mockTraceHandler, mockWavefrontSender);
    HashMap<String, String> tagsReturned = tagsCapture.getValue();
    assertEquals(PREPROCESSED_APPLICATION_TAG_VALUE, tagsReturned.get(APPLICATION_TAG_KEY));
    assertEquals(PREPROCESSED_SERVICE_TAG_VALUE, tagsReturned.get(SERVICE_TAG_KEY));
    assertEquals(PREPROCESSED_CLUSTER_TAG_VALUE, tagsReturned.get(CLUSTER_TAG_KEY));
    assertEquals(PREPROCESSED_SHARD_TAG_VALUE, tagsReturned.get(SHARD_TAG_KEY));
}
Also used : ReportableEntityPreprocessor(com.wavefront.agent.preprocessor.ReportableEntityPreprocessor) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) RateSampler(com.wavefront.sdk.entities.tracing.sampling.RateSampler) HashMap(java.util.HashMap) SpanSampler(com.wavefront.agent.sampler.SpanSampler) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ByteBuf(io.netty.buffer.ByteBuf) Span(wavefront.report.Span) Annotation(wavefront.report.Annotation) PreprocessorRuleMetrics(com.wavefront.agent.preprocessor.PreprocessorRuleMetrics) Endpoint(zipkin2.Endpoint) NoopHealthCheckManager(com.wavefront.agent.channel.NoopHealthCheckManager) SpanReplaceRegexTransformer(com.wavefront.agent.preprocessor.SpanReplaceRegexTransformer) Test(org.junit.Test)

Example 4 with PreprocessorRuleMetrics

use of com.wavefront.agent.preprocessor.PreprocessorRuleMetrics in project java by wavefrontHQ.

the class PushAgent method startListeners.

@Override
protected void startListeners() throws Exception {
    blockedPointsLogger = Logger.getLogger(proxyConfig.getBlockedPointsLoggerName());
    blockedHistogramsLogger = Logger.getLogger(proxyConfig.getBlockedHistogramsLoggerName());
    blockedSpansLogger = Logger.getLogger(proxyConfig.getBlockedSpansLoggerName());
    if (proxyConfig.getSoLingerTime() >= 0) {
        childChannelOptions.put(ChannelOption.SO_LINGER, proxyConfig.getSoLingerTime());
    }
    hostnameResolver = new CachingHostnameLookupResolver(proxyConfig.isDisableRdnsLookup(), ExpectedAgentMetric.RDNS_CACHE_SIZE.metricName);
    if (proxyConfig.isSqsQueueBuffer()) {
        taskQueueFactory = new SQSQueueFactoryImpl(proxyConfig.getSqsQueueNameTemplate(), proxyConfig.getSqsQueueRegion(), proxyConfig.getSqsQueueIdentifier(), proxyConfig.isPurgeBuffer());
    } else {
        taskQueueFactory = new TaskQueueFactoryImpl(proxyConfig.getBufferFile(), proxyConfig.isPurgeBuffer(), proxyConfig.isDisableBufferSharding(), proxyConfig.getBufferShardSize());
    }
    remoteHostAnnotator = new SharedGraphiteHostAnnotator(proxyConfig.getCustomSourceTags(), hostnameResolver);
    queueingFactory = new QueueingFactoryImpl(apiContainer, agentId, taskQueueFactory, entityProps);
    senderTaskFactory = new SenderTaskFactoryImpl(apiContainer, agentId, taskQueueFactory, queueingFactory, entityProps);
    if (proxyConfig.isHistogramPassthroughRecompression()) {
        histogramRecompressor = new HistogramRecompressor(() -> entityProps.getGlobalProperties().getHistogramStorageAccuracy());
    }
    handlerFactory = new ReportableEntityHandlerFactoryImpl(senderTaskFactory, proxyConfig.getPushBlockedSamples(), validationConfiguration, blockedPointsLogger, blockedHistogramsLogger, blockedSpansLogger, histogramRecompressor, entityProps);
    if (proxyConfig.isTrafficShaping()) {
        new TrafficShapingRateLimitAdjuster(entityProps, proxyConfig.getTrafficShapingWindowSeconds(), proxyConfig.getTrafficShapingHeadroom()).start();
    }
    healthCheckManager = new HealthCheckManagerImpl(proxyConfig);
    tokenAuthenticator = configureTokenAuthenticator();
    shutdownTasks.add(() -> senderTaskFactory.shutdown());
    shutdownTasks.add(() -> senderTaskFactory.drainBuffersToQueue(null));
    // sampler for spans
    rateSampler.setSamplingRate(entityProps.getGlobalProperties().getTraceSamplingRate());
    Sampler durationSampler = SpanSamplerUtils.getDurationSampler(proxyConfig.getTraceSamplingDuration());
    List<Sampler> samplers = SpanSamplerUtils.fromSamplers(rateSampler, durationSampler);
    SpanSampler spanSampler = new SpanSampler(new CompositeSampler(samplers), () -> entityProps.getGlobalProperties().getActiveSpanSamplingPolicies());
    if (proxyConfig.getAdminApiListenerPort() > 0) {
        startAdminListener(proxyConfig.getAdminApiListenerPort());
    }
    csvToList(proxyConfig.getHttpHealthCheckPorts()).forEach(strPort -> startHealthCheckListener(Integer.parseInt(strPort)));
    csvToList(proxyConfig.getPushListenerPorts()).forEach(strPort -> {
        startGraphiteListener(strPort, handlerFactory, remoteHostAnnotator, spanSampler);
        logger.info("listening on port: " + strPort + " for Wavefront metrics");
    });
    csvToList(proxyConfig.getDeltaCountersAggregationListenerPorts()).forEach(strPort -> {
        startDeltaCounterListener(strPort, remoteHostAnnotator, senderTaskFactory, spanSampler);
        logger.info("listening on port: " + strPort + " for Wavefront delta counter metrics");
    });
    {
        // Histogram bootstrap.
        List<String> histMinPorts = csvToList(proxyConfig.getHistogramMinuteListenerPorts());
        List<String> histHourPorts = csvToList(proxyConfig.getHistogramHourListenerPorts());
        List<String> histDayPorts = csvToList(proxyConfig.getHistogramDayListenerPorts());
        List<String> histDistPorts = csvToList(proxyConfig.getHistogramDistListenerPorts());
        int activeHistogramAggregationTypes = (histDayPorts.size() > 0 ? 1 : 0) + (histHourPorts.size() > 0 ? 1 : 0) + (histMinPorts.size() > 0 ? 1 : 0) + (histDistPorts.size() > 0 ? 1 : 0);
        if (activeHistogramAggregationTypes > 0) {
            /*Histograms enabled*/
            histogramExecutor = Executors.newScheduledThreadPool(1 + activeHistogramAggregationTypes, new NamedThreadFactory("histogram-service"));
            histogramFlushExecutor = Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors() / 2, new NamedThreadFactory("histogram-flush"));
            managedExecutors.add(histogramExecutor);
            managedExecutors.add(histogramFlushExecutor);
            File baseDirectory = new File(proxyConfig.getHistogramStateDirectory());
            // Central dispatch
            ReportableEntityHandler<ReportPoint, String> pointHandler = handlerFactory.getHandler(HandlerKey.of(ReportableEntityType.HISTOGRAM, "histogram_ports"));
            startHistogramListeners(histMinPorts, pointHandler, remoteHostAnnotator, Granularity.MINUTE, proxyConfig.getHistogramMinuteFlushSecs(), proxyConfig.isHistogramMinuteMemoryCache(), baseDirectory, proxyConfig.getHistogramMinuteAccumulatorSize(), proxyConfig.getHistogramMinuteAvgKeyBytes(), proxyConfig.getHistogramMinuteAvgDigestBytes(), proxyConfig.getHistogramMinuteCompression(), proxyConfig.isHistogramMinuteAccumulatorPersisted(), spanSampler);
            startHistogramListeners(histHourPorts, pointHandler, remoteHostAnnotator, Granularity.HOUR, proxyConfig.getHistogramHourFlushSecs(), proxyConfig.isHistogramHourMemoryCache(), baseDirectory, proxyConfig.getHistogramHourAccumulatorSize(), proxyConfig.getHistogramHourAvgKeyBytes(), proxyConfig.getHistogramHourAvgDigestBytes(), proxyConfig.getHistogramHourCompression(), proxyConfig.isHistogramHourAccumulatorPersisted(), spanSampler);
            startHistogramListeners(histDayPorts, pointHandler, remoteHostAnnotator, Granularity.DAY, proxyConfig.getHistogramDayFlushSecs(), proxyConfig.isHistogramDayMemoryCache(), baseDirectory, proxyConfig.getHistogramDayAccumulatorSize(), proxyConfig.getHistogramDayAvgKeyBytes(), proxyConfig.getHistogramDayAvgDigestBytes(), proxyConfig.getHistogramDayCompression(), proxyConfig.isHistogramDayAccumulatorPersisted(), spanSampler);
            startHistogramListeners(histDistPorts, pointHandler, remoteHostAnnotator, null, proxyConfig.getHistogramDistFlushSecs(), proxyConfig.isHistogramDistMemoryCache(), baseDirectory, proxyConfig.getHistogramDistAccumulatorSize(), proxyConfig.getHistogramDistAvgKeyBytes(), proxyConfig.getHistogramDistAvgDigestBytes(), proxyConfig.getHistogramDistCompression(), proxyConfig.isHistogramDistAccumulatorPersisted(), spanSampler);
        }
    }
    if (StringUtils.isNotBlank(proxyConfig.getGraphitePorts()) || StringUtils.isNotBlank(proxyConfig.getPicklePorts())) {
        if (tokenAuthenticator.authRequired()) {
            logger.warning("Graphite mode is not compatible with HTTP authentication, ignoring");
        } else {
            Preconditions.checkNotNull(proxyConfig.getGraphiteFormat(), "graphiteFormat must be supplied to enable graphite support");
            Preconditions.checkNotNull(proxyConfig.getGraphiteDelimiters(), "graphiteDelimiters must be supplied to enable graphite support");
            GraphiteFormatter graphiteFormatter = new GraphiteFormatter(proxyConfig.getGraphiteFormat(), proxyConfig.getGraphiteDelimiters(), proxyConfig.getGraphiteFieldsToRemove());
            csvToList(proxyConfig.getGraphitePorts()).forEach(strPort -> {
                preprocessors.getSystemPreprocessor(strPort).forPointLine().addTransformer(0, graphiteFormatter);
                startGraphiteListener(strPort, handlerFactory, null, spanSampler);
                logger.info("listening on port: " + strPort + " for graphite metrics");
            });
            csvToList(proxyConfig.getPicklePorts()).forEach(strPort -> startPickleListener(strPort, handlerFactory, graphiteFormatter));
        }
    }
    csvToList(proxyConfig.getOpentsdbPorts()).forEach(strPort -> startOpenTsdbListener(strPort, handlerFactory));
    if (proxyConfig.getDataDogJsonPorts() != null) {
        HttpClient httpClient = HttpClientBuilder.create().useSystemProperties().setUserAgent(proxyConfig.getHttpUserAgent()).setConnectionTimeToLive(1, TimeUnit.MINUTES).setMaxConnPerRoute(100).setMaxConnTotal(100).setRetryHandler(new DefaultHttpRequestRetryHandler(proxyConfig.getHttpAutoRetries(), true)).setDefaultRequestConfig(RequestConfig.custom().setContentCompressionEnabled(true).setRedirectsEnabled(true).setConnectTimeout(proxyConfig.getHttpConnectTimeout()).setConnectionRequestTimeout(proxyConfig.getHttpConnectTimeout()).setSocketTimeout(proxyConfig.getHttpRequestTimeout()).build()).build();
        csvToList(proxyConfig.getDataDogJsonPorts()).forEach(strPort -> startDataDogListener(strPort, handlerFactory, httpClient));
    }
    csvToList(proxyConfig.getTraceListenerPorts()).forEach(strPort -> startTraceListener(strPort, handlerFactory, spanSampler));
    csvToList(proxyConfig.getCustomTracingListenerPorts()).forEach(strPort -> startCustomTracingListener(strPort, handlerFactory, new InternalProxyWavefrontClient(handlerFactory, strPort), spanSampler));
    csvToList(proxyConfig.getTraceJaegerListenerPorts()).forEach(strPort -> {
        PreprocessorRuleMetrics ruleMetrics = new PreprocessorRuleMetrics(Metrics.newCounter(new TaggedMetricName("point.spanSanitize", "count", "port", strPort)), null, null);
        preprocessors.getSystemPreprocessor(strPort).forSpan().addTransformer(new SpanSanitizeTransformer(ruleMetrics));
        startTraceJaegerListener(strPort, handlerFactory, new InternalProxyWavefrontClient(handlerFactory, strPort), spanSampler);
    });
    csvToList(proxyConfig.getTraceJaegerGrpcListenerPorts()).forEach(strPort -> {
        PreprocessorRuleMetrics ruleMetrics = new PreprocessorRuleMetrics(Metrics.newCounter(new TaggedMetricName("point.spanSanitize", "count", "port", strPort)), null, null);
        preprocessors.getSystemPreprocessor(strPort).forSpan().addTransformer(new SpanSanitizeTransformer(ruleMetrics));
        startTraceJaegerGrpcListener(strPort, handlerFactory, new InternalProxyWavefrontClient(handlerFactory, strPort), spanSampler);
    });
    csvToList(proxyConfig.getTraceJaegerHttpListenerPorts()).forEach(strPort -> {
        PreprocessorRuleMetrics ruleMetrics = new PreprocessorRuleMetrics(Metrics.newCounter(new TaggedMetricName("point.spanSanitize", "count", "port", strPort)), null, null);
        preprocessors.getSystemPreprocessor(strPort).forSpan().addTransformer(new SpanSanitizeTransformer(ruleMetrics));
        startTraceJaegerHttpListener(strPort, handlerFactory, new InternalProxyWavefrontClient(handlerFactory, strPort), spanSampler);
    });
    csvToList(proxyConfig.getTraceZipkinListenerPorts()).forEach(strPort -> {
        PreprocessorRuleMetrics ruleMetrics = new PreprocessorRuleMetrics(Metrics.newCounter(new TaggedMetricName("point.spanSanitize", "count", "port", strPort)), null, null);
        preprocessors.getSystemPreprocessor(strPort).forSpan().addTransformer(new SpanSanitizeTransformer(ruleMetrics));
        startTraceZipkinListener(strPort, handlerFactory, new InternalProxyWavefrontClient(handlerFactory, strPort), spanSampler);
    });
    csvToList(proxyConfig.getPushRelayListenerPorts()).forEach(strPort -> startRelayListener(strPort, handlerFactory, remoteHostAnnotator));
    csvToList(proxyConfig.getJsonListenerPorts()).forEach(strPort -> startJsonListener(strPort, handlerFactory));
    csvToList(proxyConfig.getWriteHttpJsonListenerPorts()).forEach(strPort -> startWriteHttpJsonListener(strPort, handlerFactory));
    // Logs ingestion.
    if (proxyConfig.getFilebeatPort() > 0 || proxyConfig.getRawLogsPort() > 0) {
        if (loadLogsIngestionConfig() != null) {
            logger.info("Initializing logs ingestion");
            try {
                final LogsIngester logsIngester = new LogsIngester(handlerFactory, this::loadLogsIngestionConfig, proxyConfig.getPrefix());
                logsIngester.start();
                if (proxyConfig.getFilebeatPort() > 0) {
                    startLogsIngestionListener(proxyConfig.getFilebeatPort(), logsIngester);
                }
                if (proxyConfig.getRawLogsPort() > 0) {
                    startRawLogsIngestionListener(proxyConfig.getRawLogsPort(), logsIngester);
                }
            } catch (ConfigurationException e) {
                logger.log(Level.SEVERE, "Cannot start logsIngestion", e);
            }
        } else {
            logger.warning("Cannot start logsIngestion: invalid configuration or no config specified");
        }
    }
    setupMemoryGuard();
}
Also used : DefaultHttpRequestRetryHandler(org.apache.http.impl.client.DefaultHttpRequestRetryHandler) SharedGraphiteHostAnnotator(com.wavefront.agent.channel.SharedGraphiteHostAnnotator) CompositeSampler(com.wavefront.sdk.entities.tracing.sampling.CompositeSampler) TaggedMetricName(com.wavefront.common.TaggedMetricName) ReportableEntityHandler(com.wavefront.agent.handlers.ReportableEntityHandler) ReportableEntityHandlerFactoryImpl(com.wavefront.agent.handlers.ReportableEntityHandlerFactoryImpl) DelegatingReportableEntityHandlerFactoryImpl(com.wavefront.agent.handlers.DelegatingReportableEntityHandlerFactoryImpl) PreprocessorRuleMetrics(com.wavefront.agent.preprocessor.PreprocessorRuleMetrics) ConfigurationException(com.wavefront.agent.config.ConfigurationException) HistogramRecompressor(com.wavefront.agent.histogram.HistogramRecompressor) ArrayList(java.util.ArrayList) Utils.csvToList(com.wavefront.common.Utils.csvToList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) HealthCheckManagerImpl(com.wavefront.agent.channel.HealthCheckManagerImpl) LogsIngester(com.wavefront.agent.logsharvesting.LogsIngester) TaskQueueFactoryImpl(com.wavefront.agent.queueing.TaskQueueFactoryImpl) GraphiteFormatter(com.wavefront.agent.formatter.GraphiteFormatter) NamedThreadFactory(com.wavefront.common.NamedThreadFactory) SpanSampler(com.wavefront.agent.sampler.SpanSampler) SQSQueueFactoryImpl(com.wavefront.agent.queueing.SQSQueueFactoryImpl) TrafficShapingRateLimitAdjuster(com.wavefront.agent.handlers.TrafficShapingRateLimitAdjuster) QueueingFactoryImpl(com.wavefront.agent.queueing.QueueingFactoryImpl) CachingHostnameLookupResolver(com.wavefront.agent.channel.CachingHostnameLookupResolver) SenderTaskFactoryImpl(com.wavefront.agent.handlers.SenderTaskFactoryImpl) CompositeSampler(com.wavefront.sdk.entities.tracing.sampling.CompositeSampler) SpanSampler(com.wavefront.agent.sampler.SpanSampler) Sampler(com.wavefront.sdk.entities.tracing.sampling.Sampler) RateSampler(com.wavefront.sdk.entities.tracing.sampling.RateSampler) HttpClient(org.apache.http.client.HttpClient) SpanSanitizeTransformer(com.wavefront.agent.preprocessor.SpanSanitizeTransformer) File(java.io.File) InternalProxyWavefrontClient(com.wavefront.agent.handlers.InternalProxyWavefrontClient)

Example 5 with PreprocessorRuleMetrics

use of com.wavefront.agent.preprocessor.PreprocessorRuleMetrics in project java by wavefrontHQ.

the class PushAgentTest method setUserPreprocessorForTraceDerivedREDMetrics.

private void setUserPreprocessorForTraceDerivedREDMetrics(int port) {
    ReportableEntityPreprocessor preprocessor = new ReportableEntityPreprocessor();
    PreprocessorRuleMetrics preprocessorRuleMetrics = new PreprocessorRuleMetrics(null, null, null);
    preprocessor.forSpan().addTransformer(new SpanAddAnnotationIfNotExistsTransformer("application", PREPROCESSED_APPLICATION_TAG_VALUE, x -> true, preprocessorRuleMetrics));
    preprocessor.forSpan().addTransformer(new SpanAddAnnotationIfNotExistsTransformer("service", PREPROCESSED_SERVICE_TAG_VALUE, x -> true, preprocessorRuleMetrics));
    preprocessor.forSpan().addTransformer(new SpanAddAnnotationIfNotExistsTransformer("cluster", PREPROCESSED_CLUSTER_TAG_VALUE, x -> true, preprocessorRuleMetrics));
    preprocessor.forSpan().addTransformer(new SpanAddAnnotationIfNotExistsTransformer("shard", PREPROCESSED_SHARD_TAG_VALUE, x -> true, preprocessorRuleMetrics));
    preprocessor.forSpan().addTransformer(new SpanReplaceRegexTransformer("sourceName", "^test.*", PREPROCESSED_SOURCE_VALUE, null, null, false, x -> true, preprocessorRuleMetrics));
    Map<String, ReportableEntityPreprocessor> userPreprocessorMap = new HashMap<>();
    userPreprocessorMap.put(String.valueOf(port), preprocessor);
    proxy.preprocessors.userPreprocessors = userPreprocessorMap;
}
Also used : PreprocessorRuleMetrics(com.wavefront.agent.preprocessor.PreprocessorRuleMetrics) QueueingReason(com.wavefront.agent.data.QueueingReason) MockReportableEntityHandlerFactory(com.wavefront.agent.handlers.MockReportableEntityHandlerFactory) HttpPost(org.apache.http.client.methods.HttpPost) SSLContext(javax.net.ssl.SSLContext) TestUtils.httpPost(com.wavefront.agent.TestUtils.httpPost) TrustManager(javax.net.ssl.TrustManager) ReportEvent(wavefront.report.ReportEvent) TestUtils.findAvailablePort(com.wavefront.agent.TestUtils.findAvailablePort) StatusLine(org.apache.http.StatusLine) SecureRandom(java.security.SecureRandom) APPLICATION_TAG_KEY(com.wavefront.sdk.common.Constants.APPLICATION_TAG_KEY) DurationSampler(com.wavefront.sdk.entities.tracing.sampling.DurationSampler) ReportableEntityHandler(com.wavefront.agent.handlers.ReportableEntityHandler) EasyMock.reset(org.easymock.EasyMock.reset) After(org.junit.After) Map(java.util.Map) HandlerKey(com.wavefront.agent.handlers.HandlerKey) ReportPoint(wavefront.report.ReportPoint) TestUtils.getResource(com.wavefront.agent.TestUtils.getResource) Assert.fail(org.junit.Assert.fail) TestUtils.verifyWithTimeout(com.wavefront.agent.TestUtils.verifyWithTimeout) HEART_BEAT_METRIC(com.wavefront.sdk.common.Constants.HEART_BEAT_METRIC) EasyMock.eq(org.easymock.EasyMock.eq) SpanAddAnnotationIfNotExistsTransformer(com.wavefront.agent.preprocessor.SpanAddAnnotationIfNotExistsTransformer) HealthCheckManagerImpl(com.wavefront.agent.channel.HealthCheckManagerImpl) SHARD_TAG_KEY(com.wavefront.sdk.common.Constants.SHARD_TAG_KEY) SenderTask(com.wavefront.agent.handlers.SenderTask) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) ReportableEntityPreprocessor(com.wavefront.agent.preprocessor.ReportableEntityPreprocessor) StringEntity(org.apache.http.entity.StringEntity) UUID(java.util.UUID) Span(wavefront.report.Span) Logger(java.util.logging.Logger) NotThreadSafe(net.jcip.annotations.NotThreadSafe) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) SourceTag(com.wavefront.dto.SourceTag) SocketFactory(javax.net.SocketFactory) ReportableEntityType(com.wavefront.data.ReportableEntityType) AgentConfiguration(com.wavefront.api.agent.AgentConfiguration) List(java.util.List) SERVICE_TAG_KEY(com.wavefront.sdk.common.Constants.SERVICE_TAG_KEY) Assert.assertFalse(org.junit.Assert.assertFalse) GZIPOutputStream(java.util.zip.GZIPOutputStream) CLUSTER_TAG_KEY(com.wavefront.sdk.common.Constants.CLUSTER_TAG_KEY) SourceTagAction(wavefront.report.SourceTagAction) Annotation(wavefront.report.Annotation) PreprocessorRuleMetrics(com.wavefront.agent.preprocessor.PreprocessorRuleMetrics) Socket(java.net.Socket) BeforeClass(org.junit.BeforeClass) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ReportSourceTag(wavefront.report.ReportSourceTag) SpanSampler(com.wavefront.agent.sampler.SpanSampler) HashMap(java.util.HashMap) SpanLogs(wavefront.report.SpanLogs) SourceOperationType(wavefront.report.SourceOperationType) BufferedOutputStream(java.io.BufferedOutputStream) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Event(com.wavefront.dto.Event) HttpClient(org.apache.http.client.HttpClient) EasyMock.replay(org.easymock.EasyMock.replay) EasyMock.startsWith(org.easymock.EasyMock.startsWith) NaiveTrustManager(com.wavefront.agent.tls.NaiveTrustManager) TestUtils.httpGet(com.wavefront.agent.TestUtils.httpGet) Nonnull(javax.annotation.Nonnull) Before(org.junit.Before) EasyMock.anyObject(org.easymock.EasyMock.anyObject) Capture(org.easymock.Capture) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) SenderTaskFactory(com.wavefront.agent.handlers.SenderTaskFactory) EasyMock.anyString(org.easymock.EasyMock.anyString) WavefrontSender(com.wavefront.sdk.common.WavefrontSender) TestUtils.gzippedHttpPost(com.wavefront.agent.TestUtils.gzippedHttpPost) Assert.assertTrue(org.junit.Assert.assertTrue) AssertionFailedError(junit.framework.AssertionFailedError) Test(org.junit.Test) DeltaCounterAccumulationHandlerImpl(com.wavefront.agent.handlers.DeltaCounterAccumulationHandlerImpl) EasyMock(org.easymock.EasyMock) EasyMock.expect(org.easymock.EasyMock.expect) SpanLog(wavefront.report.SpanLog) KeyManager(javax.net.ssl.KeyManager) EasyMock.expectLastCall(org.easymock.EasyMock.expectLastCall) RateSampler(com.wavefront.sdk.entities.tracing.sampling.RateSampler) CaptureType(org.easymock.CaptureType) ReportableEntityHandlerFactory(com.wavefront.agent.handlers.ReportableEntityHandlerFactory) TestUtils.waitUntilListenerIsOnline(com.wavefront.agent.TestUtils.waitUntilListenerIsOnline) EasyMock.anyLong(org.easymock.EasyMock.anyLong) HttpResponse(org.apache.http.HttpResponse) EasyMock.verify(org.easymock.EasyMock.verify) Histogram(wavefront.report.Histogram) HistogramType(wavefront.report.HistogramType) Assert.assertEquals(org.junit.Assert.assertEquals) SpanReplaceRegexTransformer(com.wavefront.agent.preprocessor.SpanReplaceRegexTransformer) ReportableEntityPreprocessor(com.wavefront.agent.preprocessor.ReportableEntityPreprocessor) HashMap(java.util.HashMap) SpanAddAnnotationIfNotExistsTransformer(com.wavefront.agent.preprocessor.SpanAddAnnotationIfNotExistsTransformer) EasyMock.anyString(org.easymock.EasyMock.anyString) SpanReplaceRegexTransformer(com.wavefront.agent.preprocessor.SpanReplaceRegexTransformer)

Aggregations

PreprocessorRuleMetrics (com.wavefront.agent.preprocessor.PreprocessorRuleMetrics)9 ReportableEntityPreprocessor (com.wavefront.agent.preprocessor.ReportableEntityPreprocessor)8 Test (org.junit.Test)8 HashMap (java.util.HashMap)6 SpanSampler (com.wavefront.agent.sampler.SpanSampler)5 Annotation (wavefront.report.Annotation)5 SpanReplaceRegexTransformer (com.wavefront.agent.preprocessor.SpanReplaceRegexTransformer)4 RateSampler (com.wavefront.sdk.entities.tracing.sampling.RateSampler)4 Span (wavefront.report.Span)4 SpanBlockFilter (com.wavefront.agent.preprocessor.SpanBlockFilter)3 SpanLogs (wavefront.report.SpanLogs)3 ImmutableList (com.google.common.collect.ImmutableList)2 HealthCheckManagerImpl (com.wavefront.agent.channel.HealthCheckManagerImpl)2 NoopHealthCheckManager (com.wavefront.agent.channel.NoopHealthCheckManager)2 ReportableEntityHandler (com.wavefront.agent.handlers.ReportableEntityHandler)2 SpanUtils.handleSpanLogs (com.wavefront.agent.listeners.tracing.SpanUtils.handleSpanLogs)2 ByteBuf (io.netty.buffer.ByteBuf)2 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)2 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)2 ImmutableMap (com.google.common.collect.ImmutableMap)1