Search in sources :

Example 1 with Get

use of com.linecorp.armeria.server.annotation.Get in project zipkin by openzipkin.

the class ZipkinMetricsController method fetchMetricsFromMicrometer.

// Extracts Zipkin metrics to provide backward compatibility
@Get("/metrics")
public HttpResponse fetchMetricsFromMicrometer() throws IOException {
    StringWriter writer = new StringWriter();
    JsonGenerator generator = JsonUtil.createGenerator(writer);
    generator.writeStartObject();
    // Get the Zipkin Custom meters for constructing the Metrics endpoint
    for (Meter meter : meterRegistry.getMeters()) {
        String name = meter.getId().getName();
        if (!name.startsWith("zipkin_collector"))
            continue;
        String transport = meter.getId().getTag("transport");
        if (transport == null)
            continue;
        Meter.Type type = meter.getId().getType();
        if (type == Meter.Type.COUNTER) {
            generator.writeNumberField("counter." + name + "." + transport, ((Counter) meter).count());
        } else if (type == Meter.Type.GAUGE) {
            generator.writeNumberField("gauge." + name + "." + transport, ((Gauge) meter).value());
        }
    // We only use counters and gauges
    }
    generator.writeEndObject();
    // instead of using try/finally as extra indent causes lines to wrap
    generator.flush();
    return HttpResponse.of(HttpStatus.OK, MediaType.JSON, writer.toString());
}
Also used : StringWriter(java.io.StringWriter) Meter(io.micrometer.core.instrument.Meter) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) Gauge(io.micrometer.core.instrument.Gauge) Get(com.linecorp.armeria.server.annotation.Get)

Example 2 with Get

use of com.linecorp.armeria.server.annotation.Get in project zipkin by openzipkin.

the class ZipkinQueryApiV2 method getTraces.

@Get("/api/v2/traces")
@Blocking
public AggregatedHttpResponse getTraces(@Param("serviceName") Optional<String> serviceName, @Param("remoteServiceName") Optional<String> remoteServiceName, @Param("spanName") Optional<String> spanName, @Param("annotationQuery") Optional<String> annotationQuery, @Param("minDuration") Optional<Long> minDuration, @Param("maxDuration") Optional<Long> maxDuration, @Param("endTs") Optional<Long> endTs, @Param("lookback") Optional<Long> lookback, @Default("10") @Param("limit") int limit) throws IOException {
    QueryRequest queryRequest = QueryRequest.newBuilder().serviceName(serviceName.orElse(null)).remoteServiceName(remoteServiceName.orElse(null)).spanName(spanName.orElse(null)).parseAnnotationQuery(annotationQuery.orElse(null)).minDuration(minDuration.orElse(null)).maxDuration(maxDuration.orElse(null)).endTs(endTs.orElse(System.currentTimeMillis())).lookback(lookback.orElse(defaultLookback)).limit(limit).build();
    List<List<Span>> traces = storage.spanStore().getTraces(queryRequest).execute();
    return jsonResponse(writeTraces(SpanBytesEncoder.JSON_V2, traces));
}
Also used : QueryRequest(zipkin2.storage.QueryRequest) List(java.util.List) Get(com.linecorp.armeria.server.annotation.Get) Blocking(com.linecorp.armeria.server.annotation.Blocking)

Aggregations

Get (com.linecorp.armeria.server.annotation.Get)2 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 Blocking (com.linecorp.armeria.server.annotation.Blocking)1 Gauge (io.micrometer.core.instrument.Gauge)1 Meter (io.micrometer.core.instrument.Meter)1 StringWriter (java.io.StringWriter)1 List (java.util.List)1 QueryRequest (zipkin2.storage.QueryRequest)1