-
Notifications
You must be signed in to change notification settings - Fork 25.4k
Generate Java classes from OTLP proto files #133451
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 2 commits
6b5a588
77604a4
71f86a7
b6065dc
edac103
9f4045f
adfe475
0567486
4abd202
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 |
---|---|---|
|
@@ -4,9 +4,12 @@ | |
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
apply plugin: 'elasticsearch.internal-es-plugin' | ||
apply plugin: 'elasticsearch.internal-yaml-rest-test' | ||
apply plugin: 'elasticsearch.internal-cluster-test' | ||
plugins { | ||
id 'elasticsearch.internal-es-plugin' | ||
id 'elasticsearch.internal-yaml-rest-test' | ||
id 'elasticsearch.internal-cluster-test' | ||
id('com.google.protobuf') version '0.9.5' | ||
} | ||
|
||
esplugin { | ||
name = 'x-pack-otel-data' | ||
|
@@ -15,6 +18,11 @@ esplugin { | |
extendedPlugins = ['x-pack-core'] | ||
} | ||
|
||
// Manually update verification-metadata.xml via dev-tools/protoc_exe_sha256.sh when updating the protobuf version. | ||
// That's because the protobuf gradle plugin is only using the protoc version for the current platform. | ||
// We need to add all platforms to verification-metadata.xml so that the appropriate metadata for the platform used by | ||
// CI and other collaborators is present. | ||
def protobufVersion = "4.32.0" | ||
dependencies { | ||
compileOnly project(path: xpackModule('core')) | ||
testImplementation project(path: ':x-pack:plugin:stack') | ||
|
@@ -34,4 +42,100 @@ dependencies { | |
clusterModules project(xpackModule('stack')) | ||
clusterModules project(xpackModule('wildcard')) | ||
clusterModules project(xpackModule('mapper-version')) | ||
|
||
implementation "com.google.protobuf:protobuf-java:${protobufVersion}" | ||
} | ||
|
||
protobuf { | ||
protoc { | ||
// The artifact spec for the Protobuf Compiler | ||
artifact = "com.google.protobuf:protoc:${protobufVersion}" | ||
} | ||
} | ||
|
||
def otlpProtoVersion = "1.7.0" | ||
|
||
// To generate the checksum, download the file and run "shasum -a 256 ~/path/to/opentelemetry-proto-<version>.zip" | ||
def protoChecksum = "ddb80357ff146f5e3bda584907185b1f635412a4b31edf6f96b102a18b8e05dc" | ||
def protoArchivePath = layout.buildDirectory.file("archives/opentelemetry-proto-${otlpProtoVersion}.zip") | ||
|
||
def downloadProtoArchive = tasks.register("downloadProtoArchive") { | ||
outputs.file(protoArchivePath) | ||
onlyIf { protoArchivePath.get().asFile.exists() == false } | ||
doLast { | ||
protoArchivePath.get().asFile.parentFile.mkdirs() | ||
"https://github.com/open-telemetry/opentelemetry-proto/archive/v${otlpProtoVersion}.zip".toURL() | ||
.withInputStream { is -> | ||
protoArchivePath.get().asFile.withOutputStream {os -> os << is } | ||
} | ||
} | ||
} | ||
|
||
def verifyProtoArchive = tasks.register("verifyProtoArchive") { | ||
dependsOn(downloadProtoArchive) | ||
doLast { | ||
protoArchivePath.get().asFile.withInputStream { inputStream -> | ||
def sha256 = inputStream.readAllBytes().digest("SHA-256") | ||
if (sha256 != protoChecksum) { | ||
throw new GradleException("Checksum verification failed for $protoArchivePath: expected $protoChecksum, got $sha256") | ||
} | ||
} | ||
} | ||
} | ||
|
||
def unzipProtoArchive = tasks.register("unzipProtoArchive", Copy) { | ||
dependsOn(verifyProtoArchive) | ||
from zipTree(protoArchivePath) | ||
into layout.buildDirectory.dir("protos") | ||
} | ||
|
||
// Avoid unnecessary String allocations in the generated AnyValue class | ||
// We always need the ByteString (UTF-8) representation of string attributes | ||
def adjustAnyValueBuilder = tasks.register("adjustAnyValueBuilder") { | ||
doLast { | ||
ant.replace( | ||
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 are in the process of removing all usages of antBuilder in our build scripts as it has a couple of flaws and breaks new features in gradle. |
||
file: 'build/generated/sources/proto/main/java/io/opentelemetry/proto/common/v1/AnyValue.java', | ||
token: 'java.lang.String s = input.readStringRequireUtf8();', | ||
value: 'com.google.protobuf.ByteString s = input.readBytes();', | ||
encoding: 'UTF-8' | ||
) | ||
} | ||
} | ||
|
||
sourceSets { | ||
main { | ||
proto { | ||
srcDir layout.buildDirectory.dir("protos/opentelemetry-proto-${otlpProtoVersion}") | ||
} | ||
} | ||
} | ||
|
||
afterEvaluate { | ||
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 want avoid afterEvaluate as its kind of deprecated gradle api. I understand the external plugin relies on it. |
||
tasks.named("generateProto") { | ||
felixbarny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
dependsOn(unzipProtoArchive) | ||
finalizedBy(adjustAnyValueBuilder) | ||
} | ||
} | ||
|
||
idea { | ||
module { | ||
sourceDirs += layout.buildDirectory.dir("generated/sources/proto/main/java").get().asFile | ||
} | ||
} | ||
|
||
tasks.named("dependencyLicenses").configure { | ||
mapping from: /protobuf.*/, to: 'protobuf' | ||
} | ||
|
||
tasks.named("thirdPartyAudit").configure { | ||
ignoreViolations( | ||
// uses internal java api: sun.misc.Unsafe | ||
'com.google.protobuf.MessageSchema', | ||
'com.google.protobuf.UnsafeUtil', | ||
'com.google.protobuf.UnsafeUtil$1', | ||
'com.google.protobuf.UnsafeUtil$Android32MemoryAccessor', | ||
'com.google.protobuf.UnsafeUtil$Android64MemoryAccessor', | ||
'com.google.protobuf.UnsafeUtil$JvmMemoryAccessor', | ||
'com.google.protobuf.UnsafeUtil$MemoryAccessor' | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/bin/bash | ||
felixbarny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# | ||
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
# or more contributor license agreements. Licensed under the "Elastic License | ||
# 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
# Public License v 1"; you may not use this file except in compliance with, at | ||
# your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
# License v3.0 only", or the "Server Side Public License, v 1". | ||
# | ||
|
||
# Script to download all .exe files from protobuf protoc repository and generate SHA256 checksums | ||
# URL to download from | ||
VERSION="4.32.0" | ||
URL="https://repo1.maven.org/maven2/com/google/protobuf/protoc/${VERSION}/" | ||
DOWNLOAD_DIR="protoc-${VERSION}-executables" | ||
|
||
# Create download directory if it doesn't exist | ||
mkdir -p "${DOWNLOAD_DIR}" | ||
cd "${DOWNLOAD_DIR}" || { echo "Failed to create/enter download directory"; exit 1; } | ||
|
||
# Get the HTML content, extract links to .exe files (but not .exe.md5 etc.) | ||
# Using grep with lookahead assertion to ensure we don't match .exe followed by something else | ||
curl -s "${URL}" | grep -o 'href="[^"]*\.exe"' | grep -v -E 'jsonl' | grep -v -E '\.exe\.[^"]+' | sed 's/href="//g' | sed 's/"//g' > exe_files.txt | ||
|
||
if [ ! -s exe_files.txt ]; then | ||
echo "No .exe files found at ${URL}" | ||
exit 1 | ||
fi | ||
|
||
echo "Found $(wc -l < exe_files.txt | tr -d ' ') .exe files. Downloading..." | ||
|
||
# Download each file | ||
while IFS= read -r file; do | ||
curl -s -O "${URL}${file}" | ||
done < exe_files.txt | ||
|
||
echo "Generating SHA256 checksums..." | ||
|
||
# Generate SHA256 checksums for all downloaded .exe files | ||
if command -v shasum &> /dev/null; then | ||
# macOS/some Linux | ||
shasum -a 256 *.exe > SHA256SUMS.txt | ||
elif command -v sha256sum &> /dev/null; then | ||
# Most Linux distributions | ||
sha256sum *.exe > SHA256SUMS.txt | ||
else | ||
echo "Neither shasum nor sha256sum command found. Cannot generate checksums." | ||
exit 1 | ||
fi | ||
|
||
# Print the checksums | ||
cat SHA256SUMS.txt | ||
|
||
cd .. | ||
rm -rf "${DOWNLOAD_DIR}" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
Copyright 2008 Google Inc. All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are | ||
met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following disclaimer | ||
in the documentation and/or other materials provided with the | ||
distribution. | ||
* Neither the name of Google Inc. nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
Code generated by the Protocol Buffer compiler is owned by the owner | ||
of the input file used when generating it. This code is not | ||
standalone and requires a support library to be linked with it. This | ||
support library is itself covered by the above license. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
Copyright 2008 Google Inc. All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are | ||
met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following disclaimer | ||
in the documentation and/or other materials provided with the | ||
distribution. | ||
* Neither the name of Google Inc. nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
Code generated by the Protocol Buffer compiler is owned by the owner | ||
of the input file used when generating it. This code is not | ||
standalone and requires a support library to be linked with it. This | ||
support library is itself covered by the above license. |
Uh oh!
There was an error while loading. Please reload this page.