Search in sources :

Example 1 with LatencyBucketBoundaries

use of io.opencensus.trace.export.SampledSpanStore.LatencyBucketBoundaries in project instrumentation-java by census-instrumentation.

the class TracezZPageHandler method emitSummaryTableHeader.

private static void emitSummaryTableHeader(PrintWriter out, Formatter formatter) {
    // First line.
    out.write("<tr class=\"bgcolor\">\n");
    out.write("<td colspan=1 class=\"head\"><b>Span Name</b></td>\n");
    out.write("<td class=\"borderRW\">&nbsp;&nbsp;&nbsp;&nbsp;</td>");
    out.write("<td colspan=1 class=\"head\"><b>Running</b></td>\n");
    out.write("<td class=\"borderLW\">&nbsp;&nbsp;&nbsp;&nbsp;</td>");
    out.write("<td colspan=9 class=\"head\"><b>Latency Samples</b></td>\n");
    out.write("<td class=\"borderRW\">&nbsp;&nbsp;&nbsp;&nbsp;</td>");
    out.write("<td colspan=1 class=\"head\"><b>Error Samples</b></td>\n");
    out.write("</tr>\n");
    // Second line.
    out.write("<tr class=\"bgcolor\">\n");
    out.write("<td colspan=1></td>\n");
    out.write("<td class=\"borderRW\">&nbsp;&nbsp;&nbsp;&nbsp;</td>");
    out.write("<td colspan=1></td>\n");
    out.write("<td class=\"borderLW\">&nbsp;&nbsp;&nbsp;&nbsp;</td>");
    for (LatencyBucketBoundaries latencyBucketsBoundaries : LatencyBucketBoundaries.values()) {
        formatter.format("<td colspan=1 class=\"centerW\"><b>[%s]</b></td>%n", LATENCY_BUCKET_BOUNDARIES_STRING_MAP.get(latencyBucketsBoundaries));
    }
    out.write("<td class=\"borderRW\">&nbsp;&nbsp;&nbsp;&nbsp;</td>");
    out.write("<td colspan=1></td>\n");
    out.write("</tr>\n");
}
Also used : LatencyBucketBoundaries(io.opencensus.trace.export.SampledSpanStore.LatencyBucketBoundaries)

Example 2 with LatencyBucketBoundaries

use of io.opencensus.trace.export.SampledSpanStore.LatencyBucketBoundaries in project instrumentation-java by census-instrumentation.

the class TracezZPageHandler method emitHtmlBody.

private void emitHtmlBody(Map<String, String> queryMap, PrintWriter out) throws UnsupportedEncodingException {
    if (runningSpanStore == null || sampledSpanStore == null) {
        out.write("OpenCensus implementation not available.");
        return;
    }
    Formatter formatter = new Formatter(out, Locale.US);
    emitSummaryTable(out, formatter);
    String spanName = queryMap.get(HEADER_SPAN_NAME);
    if (spanName != null) {
        tracer.getCurrentSpan().addAnnotation("Render spans.", ImmutableMap.<String, AttributeValue>builder().put("SpanName", AttributeValue.stringAttributeValue(spanName)).build());
        String typeStr = queryMap.get(HEADER_SAMPLES_TYPE);
        if (typeStr != null) {
            List<SpanData> spans = null;
            RequestType type = RequestType.fromString(typeStr);
            if (type == RequestType.UNKNOWN) {
                return;
            }
            if (type == RequestType.RUNNING) {
                // Display running.
                spans = new ArrayList<>(runningSpanStore.getRunningSpans(RunningSpanStore.Filter.create(spanName, 0)));
                // Sort active spans incremental.
                Collections.sort(spans, new SpanDataComparator(/* incremental= */
                true));
            } else {
                String subtypeStr = queryMap.get(HEADER_SAMPLES_SUB_TYPE);
                if (subtypeStr != null) {
                    int subtype = Integer.parseInt(subtypeStr);
                    if (type == RequestType.FAILED) {
                        if (subtype < 0 || subtype >= CanonicalCode.values().length) {
                            return;
                        }
                        // Display errors. subtype 0 means all.
                        CanonicalCode code = subtype == 0 ? null : CanonicalCode.values()[subtype];
                        spans = new ArrayList<>(sampledSpanStore.getErrorSampledSpans(ErrorFilter.create(spanName, code, 0)));
                    } else {
                        if (subtype < 0 || subtype >= LatencyBucketBoundaries.values().length) {
                            return;
                        }
                        // Display latency.
                        LatencyBucketBoundaries latencyBucketBoundaries = LatencyBucketBoundaries.values()[subtype];
                        spans = new ArrayList<>(sampledSpanStore.getLatencySampledSpans(LatencyFilter.create(spanName, latencyBucketBoundaries.getLatencyLowerNs(), latencyBucketBoundaries.getLatencyUpperNs(), 0)));
                        // Sort sampled spans decremental.
                        Collections.sort(spans, new SpanDataComparator(/* incremental= */
                        false));
                    }
                }
            }
            emitSpanNameAndCountPages(formatter, spanName, spans == null ? 0 : spans.size(), type);
            if (spans != null) {
                emitSpans(out, formatter, spans);
                emitLegend(out);
            }
        }
    }
}
Also used : SpanData(io.opencensus.trace.export.SpanData) Formatter(java.util.Formatter) CanonicalCode(io.opencensus.trace.Status.CanonicalCode) LatencyBucketBoundaries(io.opencensus.trace.export.SampledSpanStore.LatencyBucketBoundaries)

Example 3 with LatencyBucketBoundaries

use of io.opencensus.trace.export.SampledSpanStore.LatencyBucketBoundaries in project instrumentation-java by census-instrumentation.

the class TracezZPageHandler method emitSummaryTable.

// Emits the summary table with links to all samples.
private void emitSummaryTable(PrintWriter out, Formatter formatter) throws UnsupportedEncodingException {
    if (runningSpanStore == null || sampledSpanStore == null) {
        return;
    }
    RunningSpanStore.Summary runningSpanStoreSummary = runningSpanStore.getSummary();
    SampledSpanStore.Summary sampledSpanStoreSummary = sampledSpanStore.getSummary();
    out.write("<table style='border-spacing: 0;\n");
    out.write("border-left:1px solid #3D3D3D;border-right:1px solid #3D3D3D;'>\n");
    emitSummaryTableHeader(out, formatter);
    Set<String> spanNames = new TreeSet<>(runningSpanStoreSummary.getPerSpanNameSummary().keySet());
    spanNames.addAll(sampledSpanStoreSummary.getPerSpanNameSummary().keySet());
    boolean zebraColor = true;
    for (String spanName : spanNames) {
        out.write("<tr class=\"border\">\n");
        if (!zebraColor) {
            out.write("<tr class=\"border\">\n");
        } else {
            formatter.format("<tr class=\"border\" style=\"background: %s\">%n", ZEBRA_STRIPE_COLOR);
        }
        zebraColor = !zebraColor;
        formatter.format("<td>%s</td>%n", htmlEscaper().escape(spanName));
        // Running
        out.write("<td class=\"borderRL\">&nbsp;&nbsp;&nbsp;&nbsp;</td>");
        RunningSpanStore.PerSpanNameSummary runningSpanStorePerSpanNameSummary = runningSpanStoreSummary.getPerSpanNameSummary().get(spanName);
        // subtype ignored for running requests.
        emitSingleCell(out, formatter, spanName, runningSpanStorePerSpanNameSummary == null ? 0 : runningSpanStorePerSpanNameSummary.getNumRunningSpans(), RequestType.RUNNING, 0);
        SampledSpanStore.PerSpanNameSummary sampledSpanStorePerSpanNameSummary = sampledSpanStoreSummary.getPerSpanNameSummary().get(spanName);
        // Latency based samples
        out.write("<td class=\"borderLC\">&nbsp;&nbsp;&nbsp;&nbsp;</td>");
        Map<LatencyBucketBoundaries, Integer> latencyBucketsSummaries = sampledSpanStorePerSpanNameSummary != null ? sampledSpanStorePerSpanNameSummary.getNumbersOfLatencySampledSpans() : null;
        int subtype = 0;
        for (LatencyBucketBoundaries latencyBucketsBoundaries : LatencyBucketBoundaries.values()) {
            if (latencyBucketsSummaries != null) {
                int numSamples = latencyBucketsSummaries.containsKey(latencyBucketsBoundaries) ? latencyBucketsSummaries.get(latencyBucketsBoundaries) : 0;
                emitSingleCell(out, formatter, spanName, numSamples, RequestType.FINISHED, subtype++);
            } else {
                // numSamples < -1 means "Not Available".
                emitSingleCell(out, formatter, spanName, -1, RequestType.FINISHED, subtype++);
            }
        }
        // Error based samples.
        out.write("<td class=\"borderRL\">&nbsp;&nbsp;&nbsp;&nbsp;</td>");
        if (sampledSpanStorePerSpanNameSummary != null) {
            Map<CanonicalCode, Integer> errorBucketsSummaries = sampledSpanStorePerSpanNameSummary.getNumbersOfErrorSampledSpans();
            int numErrorSamples = 0;
            for (Map.Entry<CanonicalCode, Integer> it : errorBucketsSummaries.entrySet()) {
                numErrorSamples += it.getValue();
            }
            // subtype 0 means all;
            emitSingleCell(out, formatter, spanName, numErrorSamples, RequestType.FAILED, 0);
        } else {
            // numSamples < -1 means "Not Available".
            emitSingleCell(out, formatter, spanName, -1, RequestType.FAILED, 0);
        }
        out.write("</tr>\n");
    }
    out.write("</table>");
}
Also used : SampledSpanStore(io.opencensus.trace.export.SampledSpanStore) RunningSpanStore(io.opencensus.trace.export.RunningSpanStore) LatencyBucketBoundaries(io.opencensus.trace.export.SampledSpanStore.LatencyBucketBoundaries) TreeSet(java.util.TreeSet) CanonicalCode(io.opencensus.trace.Status.CanonicalCode) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 4 with LatencyBucketBoundaries

use of io.opencensus.trace.export.SampledSpanStore.LatencyBucketBoundaries in project instrumentation-java by census-instrumentation.

the class InProcessSampledSpanStoreImplTest method addSpanNameToAllLatencyBuckets.

private void addSpanNameToAllLatencyBuckets(String spanName) {
    for (LatencyBucketBoundaries boundaries : LatencyBucketBoundaries.values()) {
        Span sampledSpan = createSampledSpan(spanName);
        Span notSampledSpan = createNotSampledSpan(spanName);
        if (boundaries.getLatencyLowerNs() < NUM_NANOS_PER_SECOND) {
            testClock.advanceTime(Duration.create(0, (int) boundaries.getLatencyLowerNs()));
        } else {
            testClock.advanceTime(Duration.create(boundaries.getLatencyLowerNs() / NUM_NANOS_PER_SECOND, (int) (boundaries.getLatencyLowerNs() % NUM_NANOS_PER_SECOND)));
        }
        sampledSpan.end();
        notSampledSpan.end();
    }
}
Also used : Span(io.opencensus.trace.Span) LatencyBucketBoundaries(io.opencensus.trace.export.SampledSpanStore.LatencyBucketBoundaries)

Aggregations

LatencyBucketBoundaries (io.opencensus.trace.export.SampledSpanStore.LatencyBucketBoundaries)4 CanonicalCode (io.opencensus.trace.Status.CanonicalCode)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Span (io.opencensus.trace.Span)1 RunningSpanStore (io.opencensus.trace.export.RunningSpanStore)1 SampledSpanStore (io.opencensus.trace.export.SampledSpanStore)1 SpanData (io.opencensus.trace.export.SpanData)1 Formatter (java.util.Formatter)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeSet (java.util.TreeSet)1