Search in sources :

Example 1 with ArmeriaServerConfigurator

use of com.linecorp.armeria.spring.ArmeriaServerConfigurator in project zipkin by openzipkin.

the class ZipkinUiConfiguration method uiServerConfigurator.

@Bean
ArmeriaServerConfigurator uiServerConfigurator(HttpService indexService, Optional<MeterRegistry> meterRegistry) throws IOException {
    ServerCacheControl maxAgeYear = ServerCacheControl.builder().maxAgeSeconds(TimeUnit.DAYS.toSeconds(365)).build();
    HttpService uiFileService = FileService.builder(getClass().getClassLoader(), "zipkin-lens").cacheControl(maxAgeYear).build();
    String config = writeConfig(ui);
    return sb -> {
        sb.service("/zipkin/config.json", HttpFile.builder(HttpData.ofUtf8(config)).cacheControl(ServerCacheControl.builder().maxAgeSeconds(600).build()).contentType(MediaType.JSON_UTF_8).build().asService());
        sb.serviceUnder("/zipkin/", uiFileService);
        // TODO This approach requires maintenance when new UI routes are added. Change to the following:
        // If the path is a a file w/an extension, treat normally.
        // Otherwise instead of returning 404, forward to the index.
        // See https://github.com/twitter/finatra/blob/458c6b639c3afb4e29873d123125eeeb2b02e2cd/http/src/main/scala/com/twitter/finatra/http/response/ResponseBuilder.scala#L321
        sb.service("/zipkin/", indexService).service("/zipkin/index.html", indexService).service("/zipkin/traces/{id}", indexService).service("/zipkin/dependency", indexService).service("/zipkin/traceViewer", indexService);
        sb.service("/favicon.ico", new RedirectService(HttpStatus.FOUND, "/zipkin/favicon.ico")).service("/", new RedirectService(HttpStatus.FOUND, "/zipkin/")).service("/zipkin", new RedirectService(HttpStatus.FOUND, "/zipkin/"));
        // don't add metrics for favicon
        meterRegistry.ifPresent(m -> m.config().meterFilter(MeterFilter.deny(id -> {
            String uri = id.getTag("uri");
            return uri != null && uri.startsWith("/favicon.ico");
        })));
    };
}
Also used : MeterFilter(io.micrometer.core.instrument.config.MeterFilter) ArmeriaServerConfigurator(com.linecorp.armeria.spring.ArmeriaServerConfigurator) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) FileService(com.linecorp.armeria.server.file.FileService) Autowired(org.springframework.beans.factory.annotation.Autowired) DEFAULT_BASEPATH(zipkin2.server.internal.ui.ZipkinUiProperties.DEFAULT_BASEPATH) MediaType(com.linecorp.armeria.common.MediaType) HttpFile(com.linecorp.armeria.server.file.HttpFile) Value(org.springframework.beans.factory.annotation.Value) HttpStatus(com.linecorp.armeria.common.HttpStatus) BeanCreationException(org.springframework.beans.factory.BeanCreationException) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) HttpService(com.linecorp.armeria.server.HttpService) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty) Resource(org.springframework.core.io.Resource) HttpData(com.linecorp.armeria.common.HttpData) StreamUtils(org.springframework.util.StreamUtils) ServerCacheControl(com.linecorp.armeria.common.ServerCacheControl) UTF_8(java.nio.charset.StandardCharsets.UTF_8) RedirectService(com.linecorp.armeria.server.RedirectService) StringWriter(java.io.StringWriter) IOException(java.io.IOException) TimeUnit(java.util.concurrent.TimeUnit) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) JsonUtil(zipkin2.server.internal.JsonUtil) Optional(java.util.Optional) Bean(org.springframework.context.annotation.Bean) InputStream(java.io.InputStream) HttpService(com.linecorp.armeria.server.HttpService) RedirectService(com.linecorp.armeria.server.RedirectService) ServerCacheControl(com.linecorp.armeria.common.ServerCacheControl) Bean(org.springframework.context.annotation.Bean)

Example 2 with ArmeriaServerConfigurator

use of com.linecorp.armeria.spring.ArmeriaServerConfigurator in project zipkin by openzipkin.

the class ZipkinGrpcCollector method grpcCollectorConfigurator.

@Bean
ArmeriaServerConfigurator grpcCollectorConfigurator(StorageComponent storage, CollectorSampler sampler, CollectorMetrics metrics) {
    CollectorMetrics grpcMetrics = metrics.forTransport("grpc");
    Collector collector = Collector.newBuilder(getClass()).storage(storage).sampler(sampler).metrics(grpcMetrics).build();
    return sb -> sb.service("/zipkin.proto3.SpanService/Report", new SpanService(collector, grpcMetrics));
}
Also used : CommonPools(com.linecorp.armeria.common.CommonPools) CollectorSampler(zipkin2.collector.CollectorSampler) SpanBytesDecoder(zipkin2.codec.SpanBytesDecoder) Collector(zipkin2.collector.Collector) AbstractUnsafeUnaryGrpcService(com.linecorp.armeria.server.grpc.protocol.AbstractUnsafeUnaryGrpcService) ArmeriaServerConfigurator(com.linecorp.armeria.spring.ArmeriaServerConfigurator) ServiceRequestContext(com.linecorp.armeria.server.ServiceRequestContext) Executor(java.util.concurrent.Executor) CompletableFuture(java.util.concurrent.CompletableFuture) Unpooled(io.netty.buffer.Unpooled) CompletionStage(java.util.concurrent.CompletionStage) ByteBuf(io.netty.buffer.ByteBuf) Callback(zipkin2.Callback) Bean(org.springframework.context.annotation.Bean) CollectorMetrics(zipkin2.collector.CollectorMetrics) StorageComponent(zipkin2.storage.StorageComponent) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty) Collector(zipkin2.collector.Collector) CollectorMetrics(zipkin2.collector.CollectorMetrics) Bean(org.springframework.context.annotation.Bean)

Aggregations

ArmeriaServerConfigurator (com.linecorp.armeria.spring.ArmeriaServerConfigurator)2 ConditionalOnProperty (org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)2 Bean (org.springframework.context.annotation.Bean)2 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 CommonPools (com.linecorp.armeria.common.CommonPools)1 HttpData (com.linecorp.armeria.common.HttpData)1 HttpStatus (com.linecorp.armeria.common.HttpStatus)1 MediaType (com.linecorp.armeria.common.MediaType)1 ServerCacheControl (com.linecorp.armeria.common.ServerCacheControl)1 HttpService (com.linecorp.armeria.server.HttpService)1 RedirectService (com.linecorp.armeria.server.RedirectService)1 ServiceRequestContext (com.linecorp.armeria.server.ServiceRequestContext)1 FileService (com.linecorp.armeria.server.file.FileService)1 HttpFile (com.linecorp.armeria.server.file.HttpFile)1 AbstractUnsafeUnaryGrpcService (com.linecorp.armeria.server.grpc.protocol.AbstractUnsafeUnaryGrpcService)1 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)1 MeterFilter (io.micrometer.core.instrument.config.MeterFilter)1 ByteBuf (io.netty.buffer.ByteBuf)1 Unpooled (io.netty.buffer.Unpooled)1 IOException (java.io.IOException)1