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
1116esplugin {
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+
1843dependencies {
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}
0 commit comments