Search in sources :

Example 26 with Annotation

use of wavefront.report.Annotation 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 27 with Annotation

use of wavefront.report.Annotation in project java by wavefrontHQ.

the class SpanSamplerTest method testAlwaysSampleDebug.

@Test
public void testAlwaysSampleDebug() {
    long startTime = System.currentTimeMillis();
    String traceId = UUID.randomUUID().toString();
    Span span = Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(4).setName("testSpanName").setSource("testsource").setSpanId("testspanid").setTraceId(traceId).setAnnotations(ImmutableList.of(new Annotation("debug", "true"))).build();
    SpanSampler sampler = new SpanSampler(new DurationSampler(5), () -> null);
    assertTrue(sampler.sample(span));
}
Also used : Span(wavefront.report.Span) Annotation(wavefront.report.Annotation) DurationSampler(com.wavefront.sdk.entities.tracing.sampling.DurationSampler) Test(org.junit.Test)

Example 28 with Annotation

use of wavefront.report.Annotation in project java by wavefrontHQ.

the class SpanSamplerTest method testMultipleSpanSamplingPolicies.

@Test
public void testMultipleSpanSamplingPolicies() {
    long startTime = System.currentTimeMillis();
    String traceId = UUID.randomUUID().toString();
    Span spanToAllow = Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(4).setName("testSpanName").setSource("testsource").setSpanId("testspanid").setTraceId(traceId).build();
    Span spanToAllowWithDebugTag = Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(4).setName("testSpanName").setSource("testsource").setSpanId("testspanid").setTraceId(traceId).setAnnotations(ImmutableList.of(new Annotation("debug", "true"))).build();
    Span spanToDiscard = Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(4).setName("testSpanName").setSource("source").setSpanId("testspanid").setTraceId(traceId).build();
    List<SpanSamplingPolicy> activeSpanSamplingPolicies = ImmutableList.of(new SpanSamplingPolicy("SpanNamePolicy", "{{spanName}}='testSpanName'", 0), new SpanSamplingPolicy("SpanSourcePolicy", "{{sourceName}}='testsource'", 100));
    SpanSampler sampler = new SpanSampler(new DurationSampler(5), () -> activeSpanSamplingPolicies);
    assertTrue(sampler.sample(spanToAllow));
    assertEquals("SpanSourcePolicy", AnnotationUtils.getValue(spanToAllow.getAnnotations(), "_sampledByPolicy"));
    assertTrue(sampler.sample(spanToAllowWithDebugTag));
    assertNull(AnnotationUtils.getValue(spanToAllowWithDebugTag.getAnnotations(), "_sampledByPolicy"));
    assertFalse(sampler.sample(spanToDiscard));
    assertTrue(spanToDiscard.getAnnotations().isEmpty());
}
Also used : Span(wavefront.report.Span) Annotation(wavefront.report.Annotation) SpanSamplingPolicy(com.wavefront.api.agent.SpanSamplingPolicy) DurationSampler(com.wavefront.sdk.entities.tracing.sampling.DurationSampler) Test(org.junit.Test)

Example 29 with Annotation

use of wavefront.report.Annotation in project java by wavefrontHQ.

the class CustomTracingPortUnificationHandler method report.

@Override
protected void report(Span object) {
    // report converted metrics/histograms from the span
    String applicationName = null;
    String serviceName = null;
    String cluster = NULL_TAG_VAL;
    String shard = NULL_TAG_VAL;
    String componentTagValue = NULL_TAG_VAL;
    String isError = "false";
    List<Annotation> annotations = object.getAnnotations();
    for (Annotation annotation : annotations) {
        switch(annotation.getKey()) {
            case APPLICATION_TAG_KEY:
                applicationName = annotation.getValue();
                continue;
            case SERVICE_TAG_KEY:
                serviceName = annotation.getValue();
                continue;
            case CLUSTER_TAG_KEY:
                cluster = annotation.getValue();
                continue;
            case SHARD_TAG_KEY:
                shard = annotation.getValue();
                continue;
            case COMPONENT_TAG_KEY:
                componentTagValue = annotation.getValue();
                continue;
            case ERROR_TAG_KEY:
                isError = annotation.getValue();
                continue;
        }
    }
    if (applicationName == null || serviceName == null) {
        logger.warning("Ingested spans discarded because span application/service name is " + "missing.");
        discardedSpans.inc();
        return;
    }
    handler.report(object);
    // update application and service for red metrics
    applicationName = firstNonNull(applicationName, proxyLevelApplicationName);
    serviceName = firstNonNull(serviceName, proxyLevelServiceName);
    if (wfInternalReporter != null) {
        List<Pair<String, String>> spanTags = annotations.stream().map(a -> new Pair<>(a.getKey(), a.getValue())).collect(Collectors.toList());
        discoveredHeartbeatMetrics.add(reportWavefrontGeneratedData(wfInternalReporter, object.getName(), applicationName, serviceName, cluster, shard, object.getSource(), componentTagValue, Boolean.parseBoolean(isError), millisToMicros(object.getDuration()), traceDerivedCustomTagKeys, spanTags, true));
        try {
            reportHeartbeats(wfSender, discoveredHeartbeatMetrics, "wavefront-generated");
        } catch (IOException e) {
            logger.log(Level.WARNING, "Cannot report heartbeat metric to wavefront");
        }
    }
}
Also used : Annotation(wavefront.report.Annotation) StringUtils(org.apache.commons.lang.StringUtils) HealthCheckManager(com.wavefront.agent.channel.HealthCheckManager) SpanSampler(com.wavefront.agent.sampler.SpanSampler) NULL_TAG_VAL(com.wavefront.sdk.common.Constants.NULL_TAG_VAL) SpanLogs(wavefront.report.SpanLogs) ERROR_TAG_KEY(com.wavefront.sdk.common.Constants.ERROR_TAG_KEY) Supplier(java.util.function.Supplier) Level(java.util.logging.Level) APPLICATION_TAG_KEY(com.wavefront.sdk.common.Constants.APPLICATION_TAG_KEY) TokenAuthenticator(com.wavefront.agent.auth.TokenAuthenticator) ReportableEntityHandler(com.wavefront.agent.handlers.ReportableEntityHandler) COMPONENT_TAG_KEY(com.wavefront.sdk.common.Constants.COMPONENT_TAG_KEY) Map(java.util.Map) SpanDerivedMetricsUtils.reportWavefrontGeneratedData(com.wavefront.internal.SpanDerivedMetricsUtils.reportWavefrontGeneratedData) HandlerKey(com.wavefront.agent.handlers.HandlerKey) JsonNode(com.fasterxml.jackson.databind.JsonNode) WavefrontInternalReporter(com.wavefront.internal.reporter.WavefrontInternalReporter) Nullable(javax.annotation.Nullable) SHARD_TAG_KEY(com.wavefront.sdk.common.Constants.SHARD_TAG_KEY) WavefrontSender(com.wavefront.sdk.common.WavefrontSender) ReportableEntityPreprocessor(com.wavefront.agent.preprocessor.ReportableEntityPreprocessor) Set(java.util.Set) IOException(java.io.IOException) Span(wavefront.report.Span) ObjectUtils.firstNonNull(org.apache.commons.lang3.ObjectUtils.firstNonNull) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) SpanDerivedMetricsUtils.reportHeartbeats(com.wavefront.internal.SpanDerivedMetricsUtils.reportHeartbeats) ReportableEntityType(com.wavefront.data.ReportableEntityType) List(java.util.List) SERVICE_TAG_KEY(com.wavefront.sdk.common.Constants.SERVICE_TAG_KEY) ReportableEntityHandlerFactory(com.wavefront.agent.handlers.ReportableEntityHandlerFactory) Pair(com.wavefront.sdk.common.Pair) ReportableEntityDecoder(com.wavefront.ingester.ReportableEntityDecoder) ChannelHandler(io.netty.channel.ChannelHandler) VisibleForTesting(com.google.common.annotations.VisibleForTesting) CLUSTER_TAG_KEY(com.wavefront.sdk.common.Constants.CLUSTER_TAG_KEY) IOException(java.io.IOException) Annotation(wavefront.report.Annotation) Pair(com.wavefront.sdk.common.Pair)

Example 30 with Annotation

use of wavefront.report.Annotation in project java by wavefrontHQ.

the class JaegerThriftUtils method processBatch.

public static void processBatch(Batch batch, @Nullable StringBuilder output, String sourceName, String applicationName, ReportableEntityHandler<Span, String> spanHandler, ReportableEntityHandler<SpanLogs, String> spanLogsHandler, @Nullable WavefrontInternalReporter wfInternalReporter, Supplier<Boolean> traceDisabled, Supplier<Boolean> spanLogsDisabled, Supplier<ReportableEntityPreprocessor> preprocessorSupplier, SpanSampler sampler, Set<String> traceDerivedCustomTagKeys, Counter discardedTraces, Counter discardedBatches, Counter discardedSpansBySampler, Set<Pair<Map<String, String>, String>> discoveredHeartbeatMetrics, Counter receivedSpansTotal) {
    String serviceName = batch.getProcess().getServiceName();
    List<Annotation> processAnnotations = new ArrayList<>();
    boolean isSourceProcessTagPresent = false;
    String cluster = NULL_TAG_VAL;
    String shard = NULL_TAG_VAL;
    if (batch.getProcess().getTags() != null) {
        for (Tag tag : batch.getProcess().getTags()) {
            if (tag.getKey().equals(APPLICATION_TAG_KEY) && tag.getVType() == TagType.STRING) {
                applicationName = tag.getVStr();
                continue;
            }
            if (tag.getKey().equals(CLUSTER_TAG_KEY) && tag.getVType() == TagType.STRING) {
                cluster = tag.getVStr();
                continue;
            }
            if (tag.getKey().equals(SHARD_TAG_KEY) && tag.getVType() == TagType.STRING) {
                shard = tag.getVStr();
                continue;
            }
            // "source" in span tag > "source" in process tag > "hostname" in process tag > DEFAULT
            if (tag.getKey().equals("hostname") && tag.getVType() == TagType.STRING) {
                if (!isSourceProcessTagPresent) {
                    sourceName = tag.getVStr();
                }
                continue;
            }
            if (tag.getKey().equals(SOURCE_KEY) && tag.getVType() == TagType.STRING) {
                sourceName = tag.getVStr();
                isSourceProcessTagPresent = true;
                continue;
            }
            if (tag.getKey().equals(SERVICE_TAG_KEY) && tag.getVType() == TagType.STRING) {
                // ignore "service" tags, since service is a field on the span
                continue;
            }
            Annotation annotation = tagToAnnotation(tag);
            processAnnotations.add(annotation);
        }
    }
    if (isFeatureDisabled(traceDisabled, SPAN_DISABLED, discardedBatches, output)) {
        discardedTraces.inc(batch.getSpansSize());
        receivedSpansTotal.inc(batch.getSpansSize());
        return;
    }
    receivedSpansTotal.inc(batch.getSpansSize());
    for (io.jaegertracing.thriftjava.Span span : batch.getSpans()) {
        processSpan(span, serviceName, sourceName, applicationName, cluster, shard, processAnnotations, spanHandler, spanLogsHandler, wfInternalReporter, spanLogsDisabled, preprocessorSupplier, sampler, traceDerivedCustomTagKeys, discardedSpansBySampler, discoveredHeartbeatMetrics);
    }
}
Also used : ArrayList(java.util.ArrayList) Tag(io.jaegertracing.thriftjava.Tag) Annotation(wavefront.report.Annotation)

Aggregations

Annotation (wavefront.report.Annotation)62 Test (org.junit.Test)45 Span (wavefront.report.Span)36 SpanSampler (com.wavefront.agent.sampler.SpanSampler)34 RateSampler (com.wavefront.sdk.entities.tracing.sampling.RateSampler)23 Collectors (java.util.stream.Collectors)13 ByteString (com.google.protobuf.ByteString)12 Batch (io.jaegertracing.thriftjava.Batch)12 Tag (io.jaegertracing.thriftjava.Tag)12 Model (io.opentelemetry.exporters.jaeger.proto.api_v2.Model)12 TestUtils.parseSpan (com.wavefront.agent.TestUtils.parseSpan)11 Process (io.jaegertracing.thriftjava.Process)11 IOException (java.io.IOException)11 ByteBuffer (java.nio.ByteBuffer)11 Collector (io.opentelemetry.exporters.jaeger.proto.api_v2.Collector)10 ImmutableList (com.google.common.collect.ImmutableList)9 DurationSampler (com.wavefront.sdk.entities.tracing.sampling.DurationSampler)9 Collector (io.jaegertracing.thriftjava.Collector)9 InputStream (java.io.InputStream)9 Nullable (javax.annotation.Nullable)9