-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Add integration test for protobuf #11126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c273a3f
c53cf83
9836ad2
c05f098
091c289
9dcd616
9d33645
ec4e2b3
9b28568
3f7c10b
5b45b6c
5ee72ec
a79dbf6
61cd476
ed62424
2d6da26
4d74cca
e916ebf
e27ec33
a0fdf6e
7590502
fdeb860
9ed15eb
1c92586
7a9edd7
60fc067
32b47c5
ef3a0a4
994e16f
b7d38b6
77dd324
7dec936
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -120,6 +120,12 @@ | |
| <version>${project.parent.version}</version> | ||
| <scope>runtime</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.druid.extensions</groupId> | ||
| <artifactId>druid-protobuf-extensions</artifactId> | ||
| <version>${project.parent.version}</version> | ||
| <scope>runtime</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.druid.extensions</groupId> | ||
| <artifactId>druid-s3-extensions</artifactId> | ||
|
|
@@ -366,6 +372,17 @@ | |
| </exclusion> | ||
| </exclusions> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.confluent</groupId> | ||
| <artifactId>kafka-protobuf-provider</artifactId> | ||
| <version>5.5.1</version> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.google.protobuf</groupId> | ||
| <artifactId>protobuf-java</artifactId> | ||
| <version>3.11.0</version> | ||
| </dependency> | ||
|
Comment on lines
+375
to
+385
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can remove all this by enabling the protobuf extension, no? |
||
|
|
||
| <!-- Tests --> | ||
| <dependency> | ||
|
|
@@ -387,6 +404,12 @@ | |
| <artifactId>easymock</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.github.os72</groupId> | ||
| <artifactId>protobuf-dynamic</artifactId> | ||
| <version>0.9.3</version> | ||
| <scope>compile</scope> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
|
|
@@ -470,6 +493,7 @@ | |
| <DRUID_INTEGRATION_TEST_SKIP_RUN_DOCKER>${docker.run.skip}</DRUID_INTEGRATION_TEST_SKIP_RUN_DOCKER> | ||
| <DRUID_INTEGRATION_TEST_INDEXER>${it.indexer}</DRUID_INTEGRATION_TEST_INDEXER> | ||
| <MYSQL_VERSION>${mysql.version}</MYSQL_VERSION> | ||
| <CONFLUENT_VERSION>5.5.1</CONFLUENT_VERSION> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it might make sense to pull this up all the way to the top level
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, 5.5.1 can support protobuf and in avro extension, its version is 5.5.1 too. In protobuf extension, its version is 6.0.1. I think those two versions are both OK because there is no change for core function. So which version is better?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably best to align the Confluent version with the Kafka version we use since Confluent dependencies often require Kafka dependencies. We still need to exclude those Kafka dependencies, but keeping them close should avoid compatibility issues.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we already define a confluent version here https://github.com/apache/druid/blob/master/extensions-core/protobuf-extensions/pom.xml#L37 which is newer, so we should at least align that |
||
| <KAFKA_VERSION>${apache.kafka.version}</KAFKA_VERSION> | ||
| <ZK_VERSION>${zk.version}</ZK_VERSION> | ||
| </environmentVariables> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| /* | ||
| * 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 org.apache.druid.testing.utils; | ||
|
|
||
| import com.github.os72.protobuf.dynamic.DynamicSchema; | ||
| import com.github.os72.protobuf.dynamic.MessageDefinition; | ||
| import com.google.protobuf.Descriptors; | ||
| import com.google.protobuf.DynamicMessage; | ||
| import org.apache.druid.java.util.common.Pair; | ||
| import org.apache.druid.java.util.common.logger.Logger; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class ProtobufEventSerializer implements EventSerializer | ||
| { | ||
| public static final String TYPE = "protobuf"; | ||
|
|
||
| private static final Logger LOGGER = new Logger(ProtobufEventSerializer.class); | ||
|
|
||
| public static final DynamicSchema SCHEMA; | ||
|
|
||
| static { | ||
| DynamicSchema.Builder schemaBuilder = DynamicSchema.newBuilder(); | ||
| MessageDefinition wikiDef = MessageDefinition.newBuilder("Wikipedia") | ||
| .addField("optional", "string", "timestamp", 1) | ||
| .addField("optional", "string", "page", 2) | ||
| .addField("optional", "string", "language", 3) | ||
| .addField("optional", "string", "user", 4) | ||
| .addField("optional", "string", "unpatrolled", 5) | ||
| .addField("optional", "string", "newPage", 6) | ||
| .addField("optional", "string", "robot", 7) | ||
| .addField("optional", "string", "anonymous", 8) | ||
| .addField("optional", "string", "namespace", 9) | ||
| .addField("optional", "string", "continent", 10) | ||
| .addField("optional", "string", "country", 11) | ||
| .addField("optional", "string", "region", 12) | ||
| .addField("optional", "string", "city", 13) | ||
| .addField("optional", "int32", "added", 14) | ||
| .addField("optional", "int32", "deleted", 15) | ||
| .addField("optional", "int32", "delta", 16) | ||
| .build(); | ||
| schemaBuilder.addMessageDefinition(wikiDef); | ||
| DynamicSchema schema = null; | ||
| try { | ||
| schema = schemaBuilder.build(); | ||
| } | ||
| catch (Descriptors.DescriptorValidationException e) { | ||
| LOGGER.error("Could not init protobuf schema."); | ||
| } | ||
| SCHEMA = schema; | ||
| } | ||
|
|
||
| @Override | ||
| public byte[] serialize(List<Pair<String, Object>> event) | ||
| { | ||
| DynamicMessage.Builder builder = SCHEMA.newMessageBuilder("Wikipedia"); | ||
| Descriptors.Descriptor msgDesc = builder.getDescriptorForType(); | ||
| for (Pair<String, Object> pair : event) { | ||
| builder.setField(msgDesc.findFieldByName(pair.lhs), pair.rhs); | ||
| } | ||
| return builder.build().toByteArray(); | ||
| } | ||
|
|
||
| @Override | ||
| public void close() | ||
| { | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| /* | ||
| * 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 org.apache.druid.testing.utils; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JacksonInject; | ||
| import com.fasterxml.jackson.annotation.JsonCreator; | ||
| import com.google.common.collect.ImmutableMap; | ||
| import com.google.protobuf.Descriptors; | ||
| import com.google.protobuf.DynamicMessage; | ||
| import io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient; | ||
| import io.confluent.kafka.schemaregistry.protobuf.ProtobufSchema; | ||
| import org.apache.druid.java.util.common.Pair; | ||
| import org.apache.druid.java.util.common.RetryUtils; | ||
| import org.apache.druid.java.util.common.StringUtils; | ||
| import org.apache.druid.testing.IntegrationTestingConfig; | ||
|
|
||
| import java.nio.ByteBuffer; | ||
| import java.util.List; | ||
|
|
||
| public class ProtobufSchemaRegistryEventSerializer extends ProtobufEventSerializer | ||
| { | ||
| private static final int MAX_INITIALIZE_RETRIES = 10; | ||
| public static final String TYPE = "protobuf-schema-registry"; | ||
|
|
||
| private final IntegrationTestingConfig config; | ||
| private final CachedSchemaRegistryClient client; | ||
| private int schemaId = -1; | ||
|
|
||
|
|
||
| @JsonCreator | ||
| public ProtobufSchemaRegistryEventSerializer( | ||
| @JacksonInject IntegrationTestingConfig config | ||
| ) | ||
| { | ||
| this.config = config; | ||
| this.client = new CachedSchemaRegistryClient( | ||
| StringUtils.format("http://%s", config.getSchemaRegistryHost()), | ||
| Integer.MAX_VALUE, | ||
| ImmutableMap.of( | ||
| "basic.auth.credentials.source", "USER_INFO", | ||
| "basic.auth.user.info", "druid:diurd" | ||
| ), | ||
| ImmutableMap.of() | ||
| ); | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void initialize(String topic) | ||
| { | ||
| try { | ||
| RetryUtils.retry( | ||
| () -> { | ||
| schemaId = client.register(topic, new ProtobufSchema(ProtobufEventSerializer.SCHEMA.newMessageBuilder("Wikipedia").getDescriptorForType())); | ||
| return 0; | ||
| }, | ||
| (e) -> true, | ||
| MAX_INITIALIZE_RETRIES | ||
| ); | ||
| } | ||
| catch (Exception e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public byte[] serialize(List<Pair<String, Object>> event) | ||
| { | ||
| DynamicMessage.Builder builder = SCHEMA.newMessageBuilder("Wikipedia"); | ||
| Descriptors.Descriptor msgDesc = builder.getDescriptorForType(); | ||
| for (Pair<String, Object> pair : event) { | ||
| builder.setField(msgDesc.findFieldByName(pair.lhs), pair.rhs); | ||
| } | ||
| byte[] bytes = builder.build().toByteArray(); | ||
| ByteBuffer bb = ByteBuffer.allocate(bytes.length + 6).put((byte) 0).putInt(schemaId).put((byte) 0).put(bytes); | ||
| bb.rewind(); | ||
| return bb.array(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "type": "protobuf", | ||
| "protoBytesDecoder": { | ||
| "type": "file", | ||
| "descriptor": "file:///shared/wikiticker-it/wikipedia.desc", | ||
| "protoMessageType": "Wikipedia" | ||
| }, | ||
| "flattenSpec": { | ||
| "useFieldDiscovery": true | ||
| }, | ||
| "binaryAsString": false | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| { | ||
| "type": "protobuf", | ||
| "protoBytesDecoder": { | ||
| "type": "file", | ||
| "descriptor": "file:///shared/wikiticker-it/wikipedia.desc", | ||
| "protoMessageType": "Wikipedia" | ||
| }, | ||
| "parseSpec": { | ||
| "format": "json", | ||
| "timestampSpec": { | ||
| "column": "timestamp", | ||
| "format": "auto" | ||
| }, | ||
| "dimensionsSpec": { | ||
| "dimensions": ["page", "language", "user", "unpatrolled", "newPage", "robot", "anonymous", "namespace", "continent", "country", "region", "city"] | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "type": "protobuf" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| { | ||
| "type": "protobuf", | ||
| "protoBytesDecoder": { | ||
| "type": "schema_registry", | ||
| "url": "%%SCHEMA_REGISTRY_HOST%%", | ||
| "config": { | ||
| "basic.auth.credentials.source": "USER_INFO", | ||
| "basic.auth.user.info": "druid:diurd" | ||
| } | ||
| }, | ||
| "flattenSpec": { | ||
| "useFieldDiscovery": true | ||
| }, | ||
| "binaryAsString": false | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| { | ||
| "type": "protobuf", | ||
| "protoBytesDecoder" : { | ||
| "type": "schema_registry", | ||
| "url": "%%SCHEMA_REGISTRY_HOST%%", | ||
| "config": { | ||
| "basic.auth.credentials.source": "USER_INFO", | ||
| "basic.auth.user.info": "druid:diurd" | ||
| } | ||
| }, | ||
| "parseSpec": { | ||
| "format": "json", | ||
| "timestampSpec": { | ||
| "column": "timestamp", | ||
| "format": "auto" | ||
| }, | ||
| "dimensionsSpec": { | ||
| "dimensions": ["page", "language", "user", "unpatrolled", "newPage", "robot", "anonymous", "namespace", "continent", "country", "region", "city"] | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "type": "protobuf-schema-registry" | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should be able to avoid this by enabling the protobuf-extension which already includes this dependency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't actually include the dependency, there are licensing issues and that jar isn't solely Apache licensed, but actually dual Apache and Confluent community license, so people need to fetch it themselves similar to MySQL, see #10839 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point, I did not realize that. Maybe a comment would be worthwhile