Search in sources :

Example 16 with ReportableEntityPreprocessor

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

the class SpanUtilsTest method testSpanTagBlockPreprocessor.

@Test
public void testSpanTagBlockPreprocessor() {
    Supplier<ReportableEntityPreprocessor> preprocessorSupplier = () -> {
        ReportableEntityPreprocessor preprocessor = new ReportableEntityPreprocessor();
        PreprocessorRuleMetrics preprocessorRuleMetrics = new PreprocessorRuleMetrics(null, null, null);
        preprocessor.forSpan().addFilter(new SpanBlockFilter(SERVICE_TAG_KEY, "^test.*", null, preprocessorRuleMetrics));
        return preprocessor;
    };
    String spanLine = "\"valid.metric\" \"source\"=\"localdev\" " + "\"spanId\"=\"4217104a-690d-4927-baff-d9aa779414c2\" " + "\"traceId\"=\"d5355bf7-fc8d-48d1-b761-75b170f396e0\" " + "\"application\"=\"app\" \"service\"=\"test\" " + startTime + " 100";
    mockTraceHandler.block(new Span("valid.metric", "4217104a-690d-4927-baff" + "-d9aa779414c2", "d5355bf7-fc8d-48d1-b761-75b170f396e0", startTime, 100L, "localdev", "dummy", ImmutableList.of(new Annotation("application", "app"), new Annotation("service", "test"))));
    expectLastCall();
    replay(mockTraceHandler, mockTraceSpanLogsHandler);
    preprocessAndHandleSpan(spanLine, spanDecoder, mockTraceHandler, mockTraceHandler::report, preprocessorSupplier, null, span -> true);
    verify(mockTraceHandler);
}
Also used : PreprocessorRuleMetrics(com.wavefront.agent.preprocessor.PreprocessorRuleMetrics) ReportableEntityPreprocessor(com.wavefront.agent.preprocessor.ReportableEntityPreprocessor) SpanBlockFilter(com.wavefront.agent.preprocessor.SpanBlockFilter) SpanUtils.preprocessAndHandleSpan(com.wavefront.agent.listeners.tracing.SpanUtils.preprocessAndHandleSpan) Span(wavefront.report.Span) Annotation(wavefront.report.Annotation) Test(org.junit.Test)

Example 17 with ReportableEntityPreprocessor

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

the class SpanUtilsTest method testSpanLineDataBlockPreprocessor.

@Test
public void testSpanLineDataBlockPreprocessor() {
    Supplier<ReportableEntityPreprocessor> preprocessorSupplier = () -> {
        ReportableEntityPreprocessor preprocessor = new ReportableEntityPreprocessor();
        PreprocessorRuleMetrics preprocessorRuleMetrics = new PreprocessorRuleMetrics(null, null, null);
        preprocessor.forPointLine().addFilter(new LineBasedAllowFilter("^valid.*", preprocessorRuleMetrics));
        preprocessor.forSpan().addFilter(new SpanBlockFilter(SERVICE_TAG_KEY, "^test.*", null, preprocessorRuleMetrics));
        return preprocessor;
    };
    String spanLine = "\"valid.metric\" \"source\"=\"localdev\" " + "\"spanId\"=\"4217104a-690d-4927-baff-d9aa779414c2\" " + "\"traceId\"=\"d5355bf7-fc8d-48d1-b761-75b170f396e0\" " + "\"application\"=\"app\" \"service\"=\"svc\" " + startTime + " 100";
    mockTraceHandler.block(null, spanLine);
    expectLastCall();
    replay(mockTraceHandler, mockTraceSpanLogsHandler);
    preprocessAndHandleSpan(spanLine, spanDecoder, mockTraceHandler, mockTraceHandler::report, preprocessorSupplier, null, span -> true);
    verify(mockTraceHandler);
}
Also used : PreprocessorRuleMetrics(com.wavefront.agent.preprocessor.PreprocessorRuleMetrics) ReportableEntityPreprocessor(com.wavefront.agent.preprocessor.ReportableEntityPreprocessor) LineBasedAllowFilter(com.wavefront.agent.preprocessor.LineBasedAllowFilter) SpanBlockFilter(com.wavefront.agent.preprocessor.SpanBlockFilter) Test(org.junit.Test)

Example 18 with ReportableEntityPreprocessor

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

the class SpanUtilsTest method testSpanLogsLineDataBlockPreprocessor.

@Test
public void testSpanLogsLineDataBlockPreprocessor() {
    Supplier<ReportableEntityPreprocessor> preprocessorSupplier = () -> {
        ReportableEntityPreprocessor preprocessor = new ReportableEntityPreprocessor();
        PreprocessorRuleMetrics preprocessorRuleMetrics = new PreprocessorRuleMetrics(null, null, null);
        preprocessor.forPointLine().addFilter(new LineBasedBlockFilter(".*invalid.*", preprocessorRuleMetrics));
        return preprocessor;
    };
    String spanLine = "\"invalid.metric\" \"source\"=\"localdev\" " + "\"spanId\"=\"4217104a-690d-4927-baff-d9aa779414c2\" " + "\"traceId\"=\"d5355bf7-fc8d-48d1-b761-75b170f396e0\" " + "\"application\"=\"app\" \"service\"=\"svc\" " + startTime + " 100";
    String spanLogsLine = "{" + "\"customer\":\"dummy\"," + "\"traceId\":\"d5355bf7-fc8d-48d1-b761-75b170f396e0\"," + "\"spanId\":\"4217104a-690d-4927-baff-d9aa779414c2\"," + "\"logs\":[{\"timestamp\":" + startTime + ",\"fields\":{\"error" + ".kind\":\"exception\", \"event\":\"error\"}}]," + "\"span\":\"\\\"invalid.metric\\\" \\\"source\\\"=\\\"localdev\\\" " + "\\\"spanId\\\"=\\\"4217104a-690d-4927-baff-d9aa779414c2\\\" " + "\\\"traceId\\\"=\\\"d5355bf7-fc8d-48d1-b761-75b170f396e0\\\" " + "\\\"application\\\"=\\\"app\\\" \\\"service\\\"=\\\"svc\\\" " + startTime + " 100\"" + "}";
    SpanLogs spanLogs = SpanLogs.newBuilder().setSpan(spanLine).setTraceId("d5355bf7-fc8d-48d1-b761-75b170f396e0").setSpanId("4217104a-690d-4927-baff-d9aa779414c2").setCustomer("dummy").setLogs(ImmutableList.of(SpanLog.newBuilder().setFields(new HashMap<String, String>() {

        {
            put("error.kind", "exception");
            put("event", "error");
        }
    }).setTimestamp(startTime).build())).build();
    mockTraceSpanLogsHandler.block(spanLogs);
    expectLastCall();
    replay(mockTraceHandler, mockTraceSpanLogsHandler);
    handleSpanLogs(spanLogsLine, spanLogsDocoder, spanDecoder, mockTraceSpanLogsHandler, preprocessorSupplier, null, span -> true);
    verify(mockTraceSpanLogsHandler);
}
Also used : PreprocessorRuleMetrics(com.wavefront.agent.preprocessor.PreprocessorRuleMetrics) ReportableEntityPreprocessor(com.wavefront.agent.preprocessor.ReportableEntityPreprocessor) LineBasedBlockFilter(com.wavefront.agent.preprocessor.LineBasedBlockFilter) HashMap(java.util.HashMap) SpanLogs(wavefront.report.SpanLogs) SpanUtils.handleSpanLogs(com.wavefront.agent.listeners.tracing.SpanUtils.handleSpanLogs) Test(org.junit.Test)

Example 19 with ReportableEntityPreprocessor

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

the class SpanUtilsTest method testSpanLogsTagBlockPreprocessor.

@Test
public void testSpanLogsTagBlockPreprocessor() {
    Supplier<ReportableEntityPreprocessor> preprocessorSupplier = () -> {
        ReportableEntityPreprocessor preprocessor = new ReportableEntityPreprocessor();
        PreprocessorRuleMetrics preprocessorRuleMetrics = new PreprocessorRuleMetrics(null, null, null);
        preprocessor.forSpan().addFilter(new SpanBlockFilter(SERVICE_TAG_KEY, "^test.*", null, preprocessorRuleMetrics));
        return preprocessor;
    };
    String spanLine = "\"invalid.metric\" \"source\"=\"localdev\" " + "\"spanId\"=\"4217104a-690d-4927-baff-d9aa779414c2\" " + "\"traceId\"=\"d5355bf7-fc8d-48d1-b761-75b170f396e0\" " + "\"application\"=\"app\" \"service\"=\"test\" " + startTime + " 100";
    String spanLogsLine = "{" + "\"customer\":\"dummy\"," + "\"traceId\":\"d5355bf7-fc8d-48d1-b761-75b170f396e0\"," + "\"spanId\":\"4217104a-690d-4927-baff-d9aa779414c2\"," + "\"logs\":[{\"timestamp\":" + startTime + ",\"fields\":{\"error" + ".kind\":\"exception\", \"event\":\"error\"}}]," + "\"span\":\"\\\"invalid.metric\\\" \\\"source\\\"=\\\"localdev\\\" " + "\\\"spanId\\\"=\\\"4217104a-690d-4927-baff-d9aa779414c2\\\" " + "\\\"traceId\\\"=\\\"d5355bf7-fc8d-48d1-b761-75b170f396e0\\\" " + "\\\"application\\\"=\\\"app\\\" \\\"service\\\"=\\\"test\\\" " + startTime + " 100\"" + "}";
    SpanLogs spanLogs = SpanLogs.newBuilder().setSpan(spanLine).setTraceId("d5355bf7-fc8d-48d1-b761-75b170f396e0").setSpanId("4217104a-690d-4927-baff-d9aa779414c2").setCustomer("dummy").setLogs(ImmutableList.of(SpanLog.newBuilder().setFields(new HashMap<String, String>() {

        {
            put("error.kind", "exception");
            put("event", "error");
        }
    }).setTimestamp(startTime).build())).build();
    mockTraceSpanLogsHandler.block(spanLogs);
    expectLastCall();
    replay(mockTraceHandler, mockTraceSpanLogsHandler);
    handleSpanLogs(spanLogsLine, spanLogsDocoder, spanDecoder, mockTraceSpanLogsHandler, preprocessorSupplier, null, span -> true);
    verify(mockTraceSpanLogsHandler);
}
Also used : PreprocessorRuleMetrics(com.wavefront.agent.preprocessor.PreprocessorRuleMetrics) ReportableEntityPreprocessor(com.wavefront.agent.preprocessor.ReportableEntityPreprocessor) HashMap(java.util.HashMap) SpanLogs(wavefront.report.SpanLogs) SpanUtils.handleSpanLogs(com.wavefront.agent.listeners.tracing.SpanUtils.handleSpanLogs) SpanBlockFilter(com.wavefront.agent.preprocessor.SpanBlockFilter) Test(org.junit.Test)

Example 20 with ReportableEntityPreprocessor

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

the class DataDogPortUnificationHandler method reportValue.

private void reportValue(String metricName, String hostName, Map<String, String> tags, JsonNode valueNode, long timestamp, AtomicInteger pointCounter, int interval) {
    if (valueNode == null || valueNode.isNull())
        return;
    double value;
    if (valueNode.isTextual()) {
        try {
            value = Double.parseDouble(valueNode.textValue());
        } catch (NumberFormatException nfe) {
            return;
        }
    } else if (valueNode.isBoolean()) {
        value = valueNode.asBoolean() ? 1.0d : 0.0d;
    } else if (valueNode.isDouble()) {
        value = valueNode.asDouble();
    } else {
        value = valueNode.asLong();
    }
    // interval will normally be 1 unless the metric was a rate type with a specified interval
    value = value * interval;
    ReportPoint point = ReportPoint.newBuilder().setTable("dummy").setMetric(metricName).setHost(hostName).setTimestamp(timestamp).setAnnotations(tags).setValue(value).build();
    if (pointCounter != null) {
        pointCounter.incrementAndGet();
    }
    if (preprocessorSupplier != null) {
        ReportableEntityPreprocessor preprocessor = preprocessorSupplier.get();
        String[] messageHolder = new String[1];
        preprocessor.forReportPoint().transform(point);
        if (!preprocessor.forReportPoint().filter(point, messageHolder)) {
            if (messageHolder[0] != null) {
                blockedPointsLogger.warning(ReportPointSerializer.pointToString(point));
                pointHandler.reject(point, messageHolder[0]);
            } else {
                blockedPointsLogger.info(ReportPointSerializer.pointToString(point));
                pointHandler.block(point);
            }
            return;
        }
    }
    pointHandler.report(point);
}
Also used : ReportableEntityPreprocessor(com.wavefront.agent.preprocessor.ReportableEntityPreprocessor) ReportPoint(wavefront.report.ReportPoint)

Aggregations

ReportableEntityPreprocessor (com.wavefront.agent.preprocessor.ReportableEntityPreprocessor)20 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)9 Span (wavefront.report.Span)9 PreprocessorRuleMetrics (com.wavefront.agent.preprocessor.PreprocessorRuleMetrics)8 Test (org.junit.Test)8 Annotation (wavefront.report.Annotation)8 SpanSampler (com.wavefront.agent.sampler.SpanSampler)7 SpanLogs (wavefront.report.SpanLogs)7 Map (java.util.Map)6 ReportableEntityHandler (com.wavefront.agent.handlers.ReportableEntityHandler)5 List (java.util.List)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 ImmutableSet (com.google.common.collect.ImmutableSet)4 APPLICATION_TAG_KEY (com.wavefront.sdk.common.Constants.APPLICATION_TAG_KEY)4 CLUSTER_TAG_KEY (com.wavefront.sdk.common.Constants.CLUSTER_TAG_KEY)4 SERVICE_TAG_KEY (com.wavefront.sdk.common.Constants.SERVICE_TAG_KEY)4 SHARD_TAG_KEY (com.wavefront.sdk.common.Constants.SHARD_TAG_KEY)4 Set (java.util.Set)4 Supplier (java.util.function.Supplier)4