Skip to content

Replace "protobuf-dynamic" lib with built-in protobuf methods #18401

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

Merged
merged 15 commits into from
Aug 15, 2025
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions codestyle/checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
<suppress checks=".*" files="[\\/]target[\\/]generated-sources[\\/]" />
<suppress checks=".*" files="[\\/]target[\\/]generated-test-sources[\\/]" />

<suppress checks="Indentation" files="ProtoTestEventWrapper.java" />
<suppress checks="Regexp" id="argumentLineBreaking" files="ProtoTestEventWrapper.java" />
<suppress checks="[a-zA-Z0-9]*" files="ProtoTestEventWrapper.java" />
<suppress checks="ConstantName" files="MySubRecord.java" />
<suppress checks="ConstantName" files="SomeAvroDatum.java" />
<suppress checks="ConstantName" files="MyFixed.java" />
Expand Down
67 changes: 67 additions & 0 deletions extensions-core/protobuf-extensions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<!--
~ 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.
-->

# Protobuf Extension

This extension provides support to ingest and understand the Protobuf data format. For more details, read the [Protobuf extension docs](../../docs/development/extensions-core/protobuf.md).

## Test Resources and Code Generation

The `src/test/resources/` directory contains Protocol Buffer (`.proto`) files used in unit tests. For each `.proto` file, we make use of two generated files:

1. **Java wrapper classes**: Generated Java code for working with the protobuf messages, automatically generated during the build process.
2. **Descriptor files** (`.desc`): Binary representation of the protobuf schema with all dependencies, in source-control and manually generated using the process outlined below.

### Automatic Code Generation

The project uses the `io.github.ascopes.protobuf-maven-plugin` to automatically generate Java wrapper classes from `.proto` files. This happens automatically when you run:

```sh
mvn generate-test-sources
# or any lifecycle phase that includes it, like:
mvn test
```

### Descriptor File Generation

Unit tests may require manually generated **descriptor files** (`.desc`) which contain binary representations of the protobuf schema with all dependencies.

#### Prerequisites

- Docker installed and running
- The `Dockerfile` in `src/test/resources/` creates a minimal Alpine Linux image with the correct protoc version

#### Build Docker Image

**Important**: Run all commands from the `protobuf-extensions` project root directory.

```sh
# Build the custom protoc image (only needed once or when Dockerfile changes)
docker build -t protoc-druid src/test/resources/
```

#### Generate Descriptor Files

```sh
docker run --rm -v $PWD:/workspace protoc-druid protoc \
/workspace/src/test/resources/your_file.proto \
--proto_path=/workspace/src/test/resources \
--descriptor_set_out=/workspace/src/test/resources/your_file.desc \
--include_imports
```
33 changes: 23 additions & 10 deletions extensions-core/protobuf-extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,17 @@
</exclusions>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.os72</groupId>
<artifactId>protobuf-dynamic</artifactId>
<version>0.9.3</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
Expand Down Expand Up @@ -186,11 +186,6 @@
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down Expand Up @@ -234,6 +229,24 @@
</nonFilteredFileExtensions>
</configuration>
</plugin>
<plugin>
<groupId>io.github.ascopes</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<protocVersion>${protobuf.version}</protocVersion>
<sourceDirectories>
<sourceDirectory>${project.basedir}/src/test/resources</sourceDirectory>
</sourceDirectories>
</configuration>
<executions>
<execution>
<goals>
<goal>generate-test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Loading
Loading