Skip to content

Commit

Permalink
grpc: enables collector by default (#3732)
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Cole <adrian@tetrate.io>
  • Loading branch information
codefromthecrypt committed Feb 21, 2024
1 parent d43412e commit 0970acb
Show file tree
Hide file tree
Showing 22 changed files with 76 additions and 60 deletions.
2 changes: 1 addition & 1 deletion benchmarks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>io.zipkin</groupId>
<artifactId>zipkin-parent</artifactId>
<version>3.0.7-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
</parent>

<artifactId>benchmarks</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<groupId>io.zipkin</groupId>
<artifactId>zipkin-parent</artifactId>
<version>3.0.7-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<modules>
Expand Down
2 changes: 1 addition & 1 deletion zipkin-collector/activemq/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>io.zipkin.zipkin2</groupId>
<artifactId>zipkin-collector-parent</artifactId>
<version>3.0.7-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
</parent>

<artifactId>zipkin-collector-activemq</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion zipkin-collector/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>io.zipkin.zipkin2</groupId>
<artifactId>zipkin-collector-parent</artifactId>
<version>3.0.7-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
</parent>

<artifactId>zipkin-collector</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion zipkin-collector/kafka/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>io.zipkin.zipkin2</groupId>
<artifactId>zipkin-collector-parent</artifactId>
<version>3.0.7-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
</parent>

<artifactId>zipkin-collector-kafka</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion zipkin-collector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>io.zipkin</groupId>
<artifactId>zipkin-parent</artifactId>
<version>3.0.7-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
</parent>

<groupId>io.zipkin.zipkin2</groupId>
Expand Down
2 changes: 1 addition & 1 deletion zipkin-collector/rabbitmq/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>io.zipkin.zipkin2</groupId>
<artifactId>zipkin-collector-parent</artifactId>
<version>3.0.7-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
</parent>

<artifactId>zipkin-collector-rabbitmq</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion zipkin-collector/scribe/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>io.zipkin.zipkin2</groupId>
<artifactId>zipkin-collector-parent</artifactId>
<version>3.0.7-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
</parent>

<artifactId>zipkin-collector-scribe</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion zipkin-junit5/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>io.zipkin</groupId>
<artifactId>zipkin-parent</artifactId>
<version>3.0.7-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
</parent>

<groupId>io.zipkin.zipkin2</groupId>
Expand Down
2 changes: 1 addition & 1 deletion zipkin-lens/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>io.zipkin</groupId>
<artifactId>zipkin-parent</artifactId>
<version>3.0.7-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
</parent>

<artifactId>zipkin-lens</artifactId>
Expand Down
24 changes: 14 additions & 10 deletions zipkin-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ exposition [text format version 0.0.4](https://prometheus.io/docs/instrumenting/
### Collector
Collector metrics are broken down by transport. The following are exported to the "/metrics" endpoint:
Collector metrics are broken down by transport, where the defaults are "http" and "grpc". The
following are exported to the "/metrics" endpoint:
| Metric | Description |
|------------------------------------------------------|---------------------------------------------------------------------------------------|
Expand Down Expand Up @@ -378,7 +379,9 @@ As this feature is experimental, it is not recommended to run this in production
## Collector

### HTTP Collector
The HTTP collector is enabled by default. It accepts spans via `POST /api/v1/spans` and `POST /api/v2/spans`.
The HTTP collector is enabled by default. It accepts spans via `POST /api/v1/spans` and
`POST /api/v2/spans`, on the `${QUERY_PORT}` which defaults to 9411.

The HTTP collector supports the following configuration:

| Property | Environment Variable | Description |
Expand Down Expand Up @@ -494,17 +497,18 @@ Example usage:
$ RABBIT_ADDRESSES=localhost java -jar zipkin.jar
```

### gRPC Collector (Experimental)
You can enable a gRPC span collector endpoint by setting `COLLECTOR_GRPC_ENABLED=true`. The
`zipkin.proto3.SpanService/Report` endpoint will run on the same port as normal HTTP (9411).
### gRPC Collector

Example usage:
The gRPC collector is enabled by default. It accepts spans via `zipkin.proto3.SpanService/Report`,
on the `${QUERY_PORT}` which defaults to 9411.

```bash
$ COLLECTOR_GRPC_ENABLED=true java -jar zipkin.jar
```
The gRPC collector supports the following configuration:

| Variable | Description |
|--------------------------|--------------------------------------------------------|
| `COLLECTOR_GRPC_ENABLED` | `false` disables the gRPC service. Defaults to `true`. |

As this service is experimental, it is not recommended to run this in production environments.
The proto definition is here: https://github.com/openzipkin/zipkin-api/blob/master/zipkin.proto

## Service Registration

Expand Down
2 changes: 1 addition & 1 deletion zipkin-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>io.zipkin</groupId>
<artifactId>zipkin-parent</artifactId>
<version>3.0.7-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
</parent>

<artifactId>zipkin-server</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import zipkin2.storage.StorageComponent;

/** Collector for receiving spans on a gRPC endpoint. */
@ConditionalOnProperty(name = "zipkin.collector.grpc.enabled") // disabled by default
@ConditionalOnProperty(name = "zipkin.collector.grpc.enabled", matchIfMissing = true)
final class ZipkinGrpcCollector {

@Bean ArmeriaServerConfigurator grpcCollectorConfigurator(StorageComponent storage,
Expand All @@ -56,7 +56,8 @@ static final class SpanService extends AbstractUnsafeUnaryGrpcService {
this.metrics = metrics;
}

@Override protected CompletionStage<ByteBuf> handleMessage(ServiceRequestContext ctx, ByteBuf bytes) {
@Override
protected CompletionStage<ByteBuf> handleMessage(ServiceRequestContext ctx, ByteBuf bytes) {
metrics.incrementMessages();
metrics.incrementBytes(bytes.readableBytes());

Expand Down
6 changes: 3 additions & 3 deletions zipkin-server/src/main/resources/zipkin-server-shared.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ zipkin:
# Optional password to connect to the broker
password: ${ACTIVEMQ_PASSWORD:}
http:
# Set to false to disable creation of spans via HTTP collector API
# Set false to disable creation of spans via HTTP collector API
enabled: ${COLLECTOR_HTTP_ENABLED:${HTTP_COLLECTOR_ENABLED:true}}
grpc:
# Set to true to enable the GRPC collector
enabled: ${COLLECTOR_GRPC_ENABLED:false}
# Set false to disable the GRPC collector
enabled: ${COLLECTOR_GRPC_ENABLED:true}
kafka:
enabled: ${COLLECTOR_KAFKA_ENABLED:true}
# Kafka bootstrap broker list, comma-separated host:port values. Setting this activates the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import zipkin2.codec.SpanBytesDecoder;
import zipkin2.codec.SpanBytesEncoder;
import zipkin2.proto3.ListOfSpans;
import zipkin2.proto3.ReportResponse;
import zipkin2.storage.InMemoryStorage;

import static okhttp3.Protocol.H2_PRIOR_KNOWLEDGE;
Expand All @@ -48,7 +47,6 @@
"server.port=0",
"spring.config.name=zipkin-server",
"spring.main.banner-mode=off",
"zipkin.collector.grpc.enabled=true"
}
)
class ITZipkinGrpcCollector {
Expand All @@ -61,17 +59,17 @@ class ITZipkinGrpcCollector {

OkHttpClient client = new OkHttpClient.Builder().protocols(List.of(H2_PRIOR_KNOWLEDGE)).build();

ListOfSpans request;
ListOfSpans grpcRequest;

@BeforeEach void sanityCheckCodecCompatible() throws IOException {
request = ListOfSpans.ADAPTER.decode(SpanBytesEncoder.PROTO3.encodeList(TestObjects.TRACE));
grpcRequest = ListOfSpans.ADAPTER.decode(SpanBytesEncoder.PROTO3.encodeList(TestObjects.TRACE));

assertThat(SpanBytesDecoder.PROTO3.decodeList(request.encode()))
assertThat(SpanBytesDecoder.PROTO3.decodeList(grpcRequest.encode()))
.containsExactlyElementsOf(TestObjects.TRACE); // sanity check codec compatible
}

@Test void report_trace() throws IOException {
callReport(request); // Result is effectively void
callReport(grpcRequest); // Result is effectively void

awaitSpans();

Expand All @@ -80,30 +78,36 @@ class ITZipkinGrpcCollector {
}

@Test void report_emptyIsOk() throws IOException {

callReport(new ListOfSpans.Builder().build());
}

ReportResponse callReport(ListOfSpans spans) throws IOException {
Buffer requestBody = new Buffer();
requestBody.writeByte(0 /* compressedFlag */);
Buffer encodedMessage = new Buffer();
ListOfSpans.ADAPTER.encode(encodedMessage, spans);
requestBody.writeInt((int) encodedMessage.size());
requestBody.writeAll(encodedMessage);

Response response = client.newCall(new Request.Builder()
.url(url(server, "/zipkin.proto3.SpanService/Report"))
.addHeader("te", "trailers")
.post(RequestBody.create(requestBody.snapshot(), MediaType.get("application/grpc")))
.build())
.execute();

BufferedSource responseBody = response.body().source();
assertThat((int) responseBody.readByte()).isEqualTo(0); // uncompressed
long encodedLength = responseBody.readInt() & 0xffffffffL;

return ReportResponse.ADAPTER.decode(responseBody);
void callReport(ListOfSpans spans) throws IOException {
try (Buffer requestBody = new Buffer(); Buffer encodedMessage = new Buffer()) {
requestBody.writeByte(0 /* compressedFlag */);

ListOfSpans.ADAPTER.encode(encodedMessage, spans);
requestBody.writeInt((int) encodedMessage.size());
requestBody.writeAll(encodedMessage);

Request request = new Request.Builder()
.url(url(server, "/zipkin.proto3.SpanService/Report"))
.addHeader("te", "trailers")
.post(RequestBody.create(requestBody.snapshot(), MediaType.get("application/grpc")))
.build();
try (Response response = client.newCall(request).execute();
BufferedSource responseBody = response.body().source()) {

// We expect this is a valid gRPC over HTTP2 response (Length-Prefixed-Message).
// See https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#responses
byte compressedFlag = responseBody.readByte();
long messageLength = responseBody.readInt() & 0xffffffffL;
assertThat(responseBody.exhausted()).isTrue(); // We expect a single response

// Now, verify the Length-Prefixed-Message
assertThat(compressedFlag).isZero(); // server didn't compress
assertThat(messageLength).isZero(); // there are no fields in ReportResponse
}
}
}

void awaitSpans() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,14 @@ String scrape() throws Exception {
String metrics = getAsString("/metrics");

assertThat(readJson(metrics)).containsOnlyKeys(
"gauge.zipkin_collector.message_spans.http"
"gauge.zipkin_collector.message_spans.grpc"
, "gauge.zipkin_collector.message_bytes.grpc"
, "counter.zipkin_collector.messages.grpc"
, "counter.zipkin_collector.bytes.grpc"
, "counter.zipkin_collector.spans.grpc"
, "counter.zipkin_collector.messages_dropped.grpc"
, "counter.zipkin_collector.spans_dropped.grpc"
, "gauge.zipkin_collector.message_spans.http"
, "gauge.zipkin_collector.message_bytes.http"
, "counter.zipkin_collector.messages.http"
, "counter.zipkin_collector.bytes.http"
Expand Down
2 changes: 1 addition & 1 deletion zipkin-storage/cassandra/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>io.zipkin.zipkin2</groupId>
<artifactId>zipkin-storage-parent</artifactId>
<version>3.0.7-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
</parent>

<artifactId>zipkin-storage-cassandra</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion zipkin-storage/elasticsearch/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>io.zipkin.zipkin2</groupId>
<artifactId>zipkin-storage-parent</artifactId>
<version>3.0.7-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
</parent>

<artifactId>zipkin-storage-elasticsearch</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion zipkin-storage/mysql-v1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>io.zipkin.zipkin2</groupId>
<artifactId>zipkin-storage-parent</artifactId>
<version>3.0.7-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
</parent>

<artifactId>zipkin-storage-mysql-v1</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion zipkin-storage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>io.zipkin</groupId>
<artifactId>zipkin-parent</artifactId>
<version>3.0.7-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
</parent>

<groupId>io.zipkin.zipkin2</groupId>
Expand Down
2 changes: 1 addition & 1 deletion zipkin-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>io.zipkin</groupId>
<artifactId>zipkin-parent</artifactId>
<version>3.0.7-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
</parent>

<groupId>io.zipkin.zipkin2</groupId>
Expand Down
2 changes: 1 addition & 1 deletion zipkin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>io.zipkin</groupId>
<artifactId>zipkin-parent</artifactId>
<version>3.0.7-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
</parent>

<groupId>io.zipkin.zipkin2</groupId>
Expand Down

0 comments on commit 0970acb

Please sign in to comment.