forked from openzipkin/zipkin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds gRPC endpoint /zipkin.proto3.SpanService/Report (openzipkin#2328)
This adds an opt-in gRPC endpoint for reporting spans. A request to the gRPC `/zipkin.proto3.SpanService/Report` service is the same proto used with our `POST /api/v2/spans`, `Content-Type: application/x-protobuf` endpoint: `zipkin.proto3.ListOfSpans`. This is currently disabled by default, as the feature is experimental. Enable it like so: ```bash $ COLLECTOR_GRPC_ENABLED=true java -jar zipkin.jar ``` Under the scenes the runtime is the same as the POST endpoint (Armeria), and uses the same port (9411).
- Loading branch information
Showing
9 changed files
with
317 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
zipkin-server/src/main/java/zipkin2/server/internal/ZipkinGrpcCollector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package zipkin2.server.internal; | ||
|
||
import com.linecorp.armeria.common.grpc.protocol.AbstractUnaryGrpcService; | ||
import com.linecorp.armeria.spring.ArmeriaServerConfigurator; | ||
import java.util.concurrent.CompletableFuture; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Bean; | ||
import zipkin2.Callback; | ||
import zipkin2.codec.SpanBytesDecoder; | ||
import zipkin2.collector.Collector; | ||
import zipkin2.collector.CollectorMetrics; | ||
import zipkin2.collector.CollectorSampler; | ||
import zipkin2.storage.StorageComponent; | ||
|
||
/** Collector for receiving spans on a gRPC endpoint. */ | ||
@ConditionalOnProperty(name = "zipkin.collector.grpc.enabled") // disabled by default | ||
final class ZipkinGrpcCollector { | ||
static final byte[] EMPTY = new byte[0]; | ||
|
||
@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)); | ||
} | ||
|
||
static final class SpanService extends AbstractUnaryGrpcService { | ||
|
||
final Collector collector; | ||
final CollectorMetrics metrics; | ||
|
||
SpanService(Collector collector, CollectorMetrics metrics) { | ||
this.collector = collector; | ||
this.metrics = metrics; | ||
} | ||
|
||
@Override protected CompletableFuture<byte[]> handleMessage(byte[] bytes) { | ||
metrics.incrementMessages(); | ||
CompletableFutureCallback result = new CompletableFutureCallback(); | ||
collector.acceptSpans(bytes, SpanBytesDecoder.PROTO3, result); | ||
return result; | ||
} | ||
} | ||
|
||
static final class CompletableFutureCallback extends CompletableFuture<byte[]> | ||
implements Callback<Void> { | ||
|
||
@Override public void onSuccess(Void value) { | ||
complete(EMPTY); | ||
} | ||
|
||
@Override public void onError(Throwable t) { | ||
completeExceptionally(t); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.