Skip to content

Commit b4e0b49

Browse files
authored
add runtime hints for graal VM (#7866)
1 parent 42b04c5 commit b4e0b49

File tree

3 files changed

+86
-1
lines changed

3 files changed

+86
-1
lines changed

integration-tests/graal-incubating/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ dependencies {
2424
implementation(project(":sdk:testing"))
2525
implementation(project(":exporters:otlp:all"))
2626
implementation(project(":api:incubator"))
27+
implementation(project(":sdk-extensions:incubator"))
2728
}
2829

2930
// org.graalvm.buildtools.native plugin requires java 17+ as of version 0.11.0

integration-tests/graal-incubating/src/test/java/io/opentelemetry/integrationtests/graal/IncubatingApiTests.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import io.opentelemetry.api.metrics.Meter;
2424
import io.opentelemetry.api.metrics.MeterProvider;
2525
import io.opentelemetry.api.trace.TracerProvider;
26+
import io.opentelemetry.sdk.extension.incubator.fileconfig.DeclarativeConfiguration;
2627
import io.opentelemetry.sdk.logs.SdkLoggerProvider;
2728
import io.opentelemetry.sdk.logs.export.SimpleLogRecordProcessor;
2829
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
@@ -31,6 +32,8 @@
3132
import io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter;
3233
import io.opentelemetry.sdk.trace.SdkTracerProvider;
3334
import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;
35+
import java.io.ByteArrayInputStream;
36+
import java.nio.charset.StandardCharsets;
3437
import org.junit.jupiter.api.Test;
3538

3639
class IncubatingApiTests {
@@ -100,4 +103,28 @@ void incubatingMetricSdk() {
100103
(ExtendedLongGauge) meter.gaugeBuilder("longGauge").ofLongs().build();
101104
longGauge.isEnabled();
102105
}
106+
107+
@Test
108+
void parseDeclarativeConfiguration() {
109+
// make sure to test enums too: "instrument_type: histogram"
110+
String string =
111+
"""
112+
file_format: "1.0-rc.1"
113+
tracer_provider:
114+
processors:
115+
- batch:
116+
exporter:
117+
console: {}
118+
meter_provider:
119+
views:
120+
- selector:
121+
instrument_type: histogram
122+
stream:
123+
aggregation:
124+
drop: {}
125+
""";
126+
// should not throw
127+
DeclarativeConfiguration.parse(
128+
new ByteArrayInputStream(string.getBytes(StandardCharsets.UTF_8)));
129+
}
103130
}

sdk-extensions/incubator/build.gradle.kts

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,65 @@ val deleteJs2pTmp by tasks.registering(Delete::class) {
145145
delete("$buildDirectory/generated/sources/js2p-tmp/")
146146
}
147147

148+
val buildGraalVmReflectionJson = tasks.register("buildGraalVmReflectionJson") {
149+
val targetFile = File(
150+
buildDirectory,
151+
"resources/main/META-INF/native-image/io.opentelemetry/io.opentelemetry.sdk.extension.incubator/reflect-config.json"
152+
)
153+
154+
onlyIf { !targetFile.exists() }
155+
156+
dependsOn("compileJava")
157+
158+
doLast {
159+
println("Generating GraalVM reflection config at: ${targetFile.absolutePath}")
160+
val sourcePackage =
161+
"io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model"
162+
val sourcePackagePath = sourcePackage.replace(".", "/")
163+
164+
val classesDir =
165+
File(
166+
buildDirectory,
167+
"classes/java/main/$sourcePackagePath"
168+
)
169+
170+
val classes = mutableListOf<String>()
171+
fileTree(classesDir).forEach {
172+
val path = it.path
173+
174+
val className = path
175+
.substringAfter(sourcePackagePath)
176+
.removePrefix("/")
177+
.removeSuffix(".class")
178+
.replace("/", ".")
179+
classes.add("$sourcePackage.$className")
180+
}
181+
classes.sort()
182+
183+
targetFile.parentFile.mkdirs()
184+
targetFile.bufferedWriter().use { writer ->
185+
writer.write("[\n")
186+
classes.forEachIndexed { index, className ->
187+
writer.write(" {\n")
188+
writer.write(" \"name\": \"$className\",\n")
189+
writer.write(" \"allDeclaredMethods\": true,\n")
190+
writer.write(" \"allDeclaredFields\": true,\n")
191+
writer.write(" \"allDeclaredConstructors\": true\n")
192+
writer.write(" }")
193+
if (index < classes.size - 1) {
194+
writer.write(",\n")
195+
} else {
196+
writer.write("\n")
197+
}
198+
}
199+
writer.write("]\n")
200+
}
201+
}
202+
}
203+
148204
tasks.getByName("compileJava").dependsOn(deleteJs2pTmp)
149-
tasks.getByName("sourcesJar").dependsOn(deleteJs2pTmp)
205+
tasks.getByName("sourcesJar").dependsOn(deleteJs2pTmp, buildGraalVmReflectionJson)
206+
tasks.getByName("jar").dependsOn(deleteJs2pTmp, buildGraalVmReflectionJson)
150207

151208
// Exclude jsonschema2pojo generated sources from checkstyle
152209
tasks.named<Checkstyle>("checkstyleMain") {

0 commit comments

Comments
 (0)