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));
}
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));
}
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());
}
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");
}
}
}
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);
}
}
Aggregations