Skip to content

Commit ea8e30d

Browse files
authored
Generate Java classes from OTLP proto files (#133451)
1 parent a560919 commit ea8e30d

File tree

5 files changed

+240
-3
lines changed

5 files changed

+240
-3
lines changed

build-tools-internal/src/main/resources/checkstyle_suppressions.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<suppress files="plugin[/\\]sql[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]sql[/\\]parser[/\\]SqlBase(Base(Listener|Visitor)|Lexer|Listener|Parser|Visitor).java" checks="." />
1414
<suppress files="plugin[/\\]eql[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]eql[/\\]parser[/\\]EqlBase(Base(Listener|Visitor)|Lexer|Listener|Parser|Visitor).java" checks="." />
1515
<suppress files="plugin[/\\]esql[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]esql[/\\]parser[/\\]EsqlBase(Parser|Lexer).*.java" checks="." />
16+
<suppress files="x-pack[/\\]plugin[/\\]otel-data[/\\]build[/\\]generated[/\\]sources[/\\]" checks="." />
1617

1718
<!-- JNA requires the no-argument constructor on JNAKernel32Library.SizeT to be public-->
1819
<suppress files="server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]bootstrap[/\\]JNAKernel32Library.java" checks="RedundantModifier" />

gradle/verification-metadata.xml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,11 @@
707707
<sha256 value="9a4e0b9f4ec4d71a8a1d3641fd481118100fda2eeab712dbdfd4b2a06e9de4ce" origin="Generated by Gradle"/>
708708
</artifact>
709709
</component>
710+
<component group="com.google.gradle" name="osdetector-gradle-plugin" version="1.7.3">
711+
<artifact name="osdetector-gradle-plugin-1.7.3.jar">
712+
<sha256 value="6b4692f913a21b1fb603169ee78ba8f3e4ab2af9d762af9ca88b79126c1c0ad1" origin="Generated by Gradle"/>
713+
</artifact>
714+
</component>
710715
<component group="com.google.guava" name="failureaccess" version="1.0">
711716
<artifact name="failureaccess-1.0.jar">
712717
<sha256 value="d084bef9cd07a8537a1753e4850a69b7e8bab1d1e22e9f3a1e4826309a7a2336" origin="Generated by Gradle"/>
@@ -867,6 +872,11 @@
867872
<sha256 value="193edf97aefa28b93c5892bdc598bac34fa4c396588030084f290b1440e8b98a" origin="Generated by Gradle"/>
868873
</artifact>
869874
</component>
875+
<component group="com.google.protobuf" name="protobuf-gradle-plugin" version="0.9.5">
876+
<artifact name="protobuf-gradle-plugin-0.9.5.jar">
877+
<sha256 value="d007dda81afeaead5dab05c27fe023ccbac97790e4d11787f4be68e6716557f8" origin="Generated by Gradle"/>
878+
</artifact>
879+
</component>
870880
<component group="com.google.protobuf" name="protobuf-java" version="2.5.0">
871881
<artifact name="protobuf-java-2.5.0.jar">
872882
<sha256 value="e0c1c64575c005601725e7c6a02cebf9e1285e888f756b2a1d73ffa8d725cc74" origin="Generated by Gradle"/>
@@ -877,11 +887,48 @@
877887
<sha256 value="8540247fad9e06baefa8fb45eb313802d019f485f14300e0f9d6b556ed88e753" origin="Generated by Gradle"/>
878888
</artifact>
879889
</component>
890+
<component group="com.google.protobuf" name="protobuf-java" version="4.32.0">
891+
<artifact name="protobuf-java-4.32.0.jar">
892+
<sha256 value="e902c91b454812b7d056b8d303a572733bf0587576ff157c1049116c9626241d" origin="Generated by Gradle"/>
893+
</artifact>
894+
</component>
880895
<component group="com.google.protobuf" name="protobuf-java-util" version="3.25.5">
881896
<artifact name="protobuf-java-util-3.25.5.jar">
882897
<sha256 value="dacc58b2c3d2fa8d4bddc1acb881e78d6cf7c137dd78bc1d67f6aca732436a8d" origin="Generated by Gradle"/>
883898
</artifact>
884899
</component>
900+
<component group="com.google.protobuf" name="protoc" version="4.32.0">
901+
<artifact name="protoc-4.32.0-linux-aarch_64.exe">
902+
<sha256 value="bc95ab180ef088eed3f97c30b213ac6439ccac01989d18f9e908eb5233432136" origin="Generated by Gradle"/>
903+
</artifact>
904+
<artifact name="protoc-4.32.0-linux-ppcle_64.exe">
905+
<sha256 value="37d1c923270dcea474423994cae32e127d9aeb0cf97d40ccf652bd671358dc74" origin="Generated by Gradle"/>
906+
</artifact>
907+
<artifact name="protoc-4.32.0-linux-s390_64.exe">
908+
<sha256 value="0b97e27d36456e8a29855f10e6dfacd27043131d44bed460b921641c7201ec0a" origin="Generated by Gradle"/>
909+
</artifact>
910+
<artifact name="protoc-4.32.0-linux-x86_32.exe">
911+
<sha256 value="75abfd89ae91a12cfbd40fe9aca20a698cc6134fbc7bef999f5c8f3b8c604b13" origin="Generated by Gradle"/>
912+
</artifact>
913+
<artifact name="protoc-4.32.0-linux-x86_64.exe">
914+
<sha256 value="373c7da2c1cae98ac1a494a8a53e28100af70450ab55c064daa92ba48af5fe23" origin="Generated by Gradle"/>
915+
</artifact>
916+
<artifact name="protoc-4.32.0-osx-aarch_64.exe">
917+
<sha256 value="96c06aac6eb7e247a78f2ffe8b3aaf4419a6765e3d96d724cc3db0e296e7aa94" origin="Generated by Gradle"/>
918+
</artifact>
919+
<artifact name="protoc-4.32.0-osx-universal_binary.exe">
920+
<sha256 value="35f98ecc7c0efeb7d63427a6f3b9f7f2adc9f59d79275c3f0ae87030876c187c" origin="Generated by Gradle"/>
921+
</artifact>
922+
<artifact name="protoc-4.32.0-osx-x86_64.exe">
923+
<sha256 value="91b2b3b5ad84cfed2869c69830c926130d312e357b4f128796504b5448a6534c" origin="Generated by Gradle"/>
924+
</artifact>
925+
<artifact name="protoc-4.32.0-windows-x86_32.exe">
926+
<sha256 value="dc71390eb8a113f37a24275bc57cc59ddaceeac39b98af2181c94755f2f411f9" origin="Generated by Gradle"/>
927+
</artifact>
928+
<artifact name="protoc-4.32.0-windows-x86_64.exe">
929+
<sha256 value="a1e25d1b71e805233daefabba72a21566580354a192539cdab43bbf191dbf951" origin="Generated by Gradle"/>
930+
</artifact>
931+
</component>
885932
<component group="com.google.re2j" name="re2j" version="1.1">
886933
<artifact name="re2j-1.1.jar">
887934
<sha256 value="24ada84d1b5de584e3e84b06f0c7dd562cee6eafe8dea8083bd8eb123823bbe7" origin="Generated by Gradle"/>
@@ -1869,6 +1916,11 @@
18691916
<sha256 value="8e495b634469d64fb8acfa3495a065cbacc8a0fff55ce1e31007be4c16dc57d3" origin="Generated by Gradle"/>
18701917
</artifact>
18711918
</component>
1919+
<component group="kr.motd.maven" name="os-maven-plugin" version="1.7.1">
1920+
<artifact name="os-maven-plugin-1.7.1.jar">
1921+
<sha256 value="f47aeef86821e52b2b18758978bd045f03d722292e32e747082122c6228952e0" origin="Generated by Gradle"/>
1922+
</artifact>
1923+
</component>
18721924
<component group="krallin" name="tini" version="0.19.0">
18731925
<artifact name="tini-0.19.0-amd64.jar">
18741926
<sha256 value="93dcc18adc78c65a028a84799ecf8ad40c936fdfc5f2a57b1acda5a8117fa82c" origin="Generated by Gradle"/>
@@ -2002,6 +2054,11 @@
20022054
<sha256 value="0a4aa0f2606bd6292a7ccd7d67a0db914bf5874dfb8a6184df3e6d63cdc93702" origin="Generated by Gradle"/>
20032055
</artifact>
20042056
</component>
2057+
<component group="open-telemetry" name="opentelemetry-proto" version="1.7.0">
2058+
<artifact name="opentelemetry-proto-1.7.0.zip">
2059+
<sha256 value="ddb80357ff146f5e3bda584907185b1f635412a4b31edf6f96b102a18b8e05dc" origin="Generated by Gradle"/>
2060+
</artifact>
2061+
</component>
20052062
<component group="org.abego.treelayout" name="org.abego.treelayout.core" version="1.0.3">
20062063
<artifact name="org.abego.treelayout.core-1.0.3.jar">
20072064
<sha256 value="fa5e31395c39c2e7d46aca0f81f72060931607b2fa41bd36038eb2cb6fb93326" origin="Generated by Gradle"/>

x-pack/plugin/otel-data/build.gradle

Lines changed: 118 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@
44
* 2.0; you may not use this file except in compliance with the Elastic License
55
* 2.0.
66
*/
7-
apply plugin: 'elasticsearch.internal-es-plugin'
8-
apply plugin: 'elasticsearch.internal-yaml-rest-test'
9-
apply plugin: 'elasticsearch.internal-cluster-test'
7+
import org.elasticsearch.gradle.transform.UnzipTransform
8+
import com.google.protobuf.gradle.GenerateProtoTask
9+
plugins {
10+
id 'elasticsearch.internal-es-plugin'
11+
id 'elasticsearch.internal-yaml-rest-test'
12+
id 'elasticsearch.internal-cluster-test'
13+
id('com.google.protobuf') version '0.9.5'
14+
}
1015

1116
esplugin {
1217
name = 'x-pack-otel-data'
@@ -15,7 +20,33 @@ esplugin {
1520
extendedPlugins = ['x-pack-core']
1621
}
1722

23+
repositories {
24+
ivy {
25+
url = uri("https://github.com/open-telemetry/opentelemetry-proto/archive/")
26+
patternLayout { artifact("v[revision].[ext]") }
27+
metadataSources { artifact() }
28+
content {
29+
includeModule("open-telemetry", "opentelemetry-proto") // only this GAV comes from here
30+
}
31+
}
32+
}
33+
34+
configurations {
35+
opentelemetryProtobuf {
36+
attributes.attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.DIRECTORY_TYPE)
37+
canBeConsumed = false
38+
}
39+
}
40+
41+
def protobufVersion = "4.32.0"
42+
1843
dependencies {
44+
registerTransform(UnzipTransform, transformSpec -> {
45+
transformSpec.getFrom().attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.ZIP_TYPE);
46+
transformSpec.getTo().attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.DIRECTORY_TYPE);
47+
});
48+
opentelemetryProtobuf "open-telemetry:opentelemetry-proto:1.7.0@zip"
49+
1950
compileOnly project(path: xpackModule('core'))
2051
testImplementation project(path: ':x-pack:plugin:stack')
2152
testImplementation(testArtifact(project(xpackModule('core'))))
@@ -34,4 +65,88 @@ dependencies {
3465
clusterModules project(xpackModule('stack'))
3566
clusterModules project(xpackModule('wildcard'))
3667
clusterModules project(xpackModule('mapper-version'))
68+
69+
implementation "com.google.protobuf:protobuf-java:${protobufVersion}"
70+
// The protobuf plugin only adds a dependency for the variant relevant for the current platform.
71+
// Without explicitly adding all classifiers, the --write-verification-metadata task would only add the one for the current platform.
72+
// Therefore, the verification check would fail on other platforms, like on CI or for contributors that work on another platform.
73+
testRuntimeOnly "com.google.protobuf:protoc:${protobufVersion}:linux-aarch_64@exe"
74+
testRuntimeOnly "com.google.protobuf:protoc:${protobufVersion}:linux-ppcle_64@exe"
75+
testRuntimeOnly "com.google.protobuf:protoc:${protobufVersion}:linux-s390_64@exe"
76+
testRuntimeOnly "com.google.protobuf:protoc:${protobufVersion}:linux-x86_32@exe"
77+
testRuntimeOnly "com.google.protobuf:protoc:${protobufVersion}:linux-x86_64@exe"
78+
testRuntimeOnly "com.google.protobuf:protoc:${protobufVersion}:osx-aarch_64@exe"
79+
testRuntimeOnly "com.google.protobuf:protoc:${protobufVersion}:osx-universal_binary@exe"
80+
testRuntimeOnly "com.google.protobuf:protoc:${protobufVersion}:osx-x86_64@exe"
81+
testRuntimeOnly "com.google.protobuf:protoc:${protobufVersion}:windows-x86_32@exe"
82+
testRuntimeOnly "com.google.protobuf:protoc:${protobufVersion}:windows-x86_64@exe"
83+
}
84+
85+
protobuf {
86+
protoc {
87+
// The artifact spec for the Protobuf Compiler
88+
artifact = "com.google.protobuf:protoc:${protobufVersion}"
89+
}
90+
}
91+
92+
def extractOtelProtos = tasks.register("extractOtelProtos", Copy) {
93+
from(configurations.opentelemetryProtobuf) {
94+
include "**/*.proto"
95+
eachFile { fileCopyDetails ->
96+
// strip the leading directory (opentelemetry-proto-<version>)
97+
def segments = fileCopyDetails.path.split('/')
98+
fileCopyDetails.path = segments.length > 1 ? segments[1..-1].join('/') : fileCopyDetails.name
99+
}
100+
includeEmptyDirs = false
101+
}
102+
into(layout.buildDirectory.dir("protos/otel"))
103+
}
104+
105+
106+
sourceSets {
107+
main {
108+
proto {
109+
srcDir(extractOtelProtos)
110+
}
111+
}
112+
}
113+
114+
tasks.withType(GenerateProtoTask.class).matching { it.name == "generateProto" }.configureEach {
115+
// Avoid unnecessary String allocations in the generated AnyValue class
116+
// We always need the ByteString (UTF-8) representation of string attributes
117+
doLast {
118+
ant.replace(
119+
file: 'build/generated/sources/proto/main/java/io/opentelemetry/proto/common/v1/AnyValue.java',
120+
token: 'java.lang.String s = input.readStringRequireUtf8();',
121+
value: 'com.google.protobuf.ByteString s = input.readBytes();',
122+
encoding: 'UTF-8'
123+
)
124+
}
125+
}
126+
127+
idea {
128+
module {
129+
sourceDirs += layout.buildDirectory.dir("generated/sources/proto/main/java").get().asFile
130+
}
131+
}
132+
133+
tasks.named("dependencyLicenses").configure {
134+
mapping from: /protobuf.*/, to: 'protobuf'
135+
}
136+
137+
tasks.named("thirdPartyAudit").configure {
138+
ignoreViolations(
139+
// uses internal java api: sun.misc.Unsafe
140+
'com.google.protobuf.MessageSchema',
141+
'com.google.protobuf.UnsafeUtil',
142+
'com.google.protobuf.UnsafeUtil$1',
143+
'com.google.protobuf.UnsafeUtil$Android32MemoryAccessor',
144+
'com.google.protobuf.UnsafeUtil$Android64MemoryAccessor',
145+
'com.google.protobuf.UnsafeUtil$JvmMemoryAccessor',
146+
'com.google.protobuf.UnsafeUtil$MemoryAccessor'
147+
)
148+
}
149+
150+
tasks.named("licenseHeaders").configure {
151+
excludes << 'io/opentelemetry/proto/**/*'
37152
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Copyright 2008 Google Inc. All rights reserved.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are
5+
met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above
10+
copyright notice, this list of conditions and the following disclaimer
11+
in the documentation and/or other materials provided with the
12+
distribution.
13+
* Neither the name of Google Inc. nor the names of its
14+
contributors may be used to endorse or promote products derived from
15+
this software without specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
29+
Code generated by the Protocol Buffer compiler is owned by the owner
30+
of the input file used when generating it. This code is not
31+
standalone and requires a support library to be linked with it. This
32+
support library is itself covered by the above license.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Copyright 2008 Google Inc. All rights reserved.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are
5+
met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above
10+
copyright notice, this list of conditions and the following disclaimer
11+
in the documentation and/or other materials provided with the
12+
distribution.
13+
* Neither the name of Google Inc. nor the names of its
14+
contributors may be used to endorse or promote products derived from
15+
this software without specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
29+
Code generated by the Protocol Buffer compiler is owned by the owner
30+
of the input file used when generating it. This code is not
31+
standalone and requires a support library to be linked with it. This
32+
support library is itself covered by the above license.

0 commit comments

Comments
 (0)