Skip to content

Commit b831d55

Browse files
committed
[jmx-scraper] Gradle task integration with weaver
- directly invoke weaver as a gradle task - removed weaver from Makefile
1 parent c26bffd commit b831d55

File tree

2 files changed

+40
-57
lines changed

2 files changed

+40
-57
lines changed

jmx-scraper/Makefile

Lines changed: 0 additions & 56 deletions
This file was deleted.

jmx-scraper/build.gradle.kts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ dependencies {
2525
runtimeOnly("org.terracotta:jmxremote_optional-tc:1.0.8")
2626

2727
implementation("io.opentelemetry.instrumentation:opentelemetry-jmx-metrics")
28-
2928
implementation("io.opentelemetry.semconv:opentelemetry-semconv-incubating")
3029

3130
testImplementation("org.junit-pioneer:junit-pioneer")
@@ -99,6 +98,46 @@ tasks {
9998
}
10099
}
101100

101+
//
102+
// task that run weaver within gradle;
103+
tasks.register("runWeaver", Exec::class) {
104+
standardOutput = System.out
105+
executable = "docker"
106+
107+
val WEAVER_CONTAINER = "otel/weaver@sha256:5425ade81dc22ddd840902b0638b4b6a9186fb654c5b50c1d1ccd31299437390"
108+
val projectRoot = project.layout.projectDirectory.asFile.absolutePath
109+
val modelPath = project.layout.projectDirectory.dir("model").asFile.absolutePath
110+
val templatePath = project.layout.projectDirectory.dir("templates").asFile.absolutePath
111+
val outputPath = project.layout.projectDirectory.file("src/main/resources").asFile.absolutePath
112+
113+
val file_args = if (org.gradle.internal.os.OperatingSystem.current().isWindows())
114+
// Don't need to worry about file system permissions in docker.
115+
listOf()
116+
else {
117+
// Make sure we run as local file user
118+
val unix = com.sun.security.auth.module.UnixSystem()
119+
val uid = unix.getUid() // $(id -u $USERNAME)
120+
val gid = unix.getGid() // $(id -g $USERNAME)
121+
listOf("-u", "$uid:$gid")
122+
}
123+
124+
val weaver_args = listOf(
125+
"--rm",
126+
"--platform=linux/x86_64",
127+
"--mount", "type=bind,source=${modelPath},target=/home/weaver/source,readonly",
128+
"--mount", "type=bind,source=${templatePath},target=/home/weaver/templates,readonly",
129+
"--mount", "type=bind,source=${outputPath},target=/home/weaver/target",
130+
"--mount", "type=bind,source=${projectRoot},target=/home/weaver",
131+
"${WEAVER_CONTAINER}",
132+
"registry", "generate",
133+
"--registry=/home/weaver/source",
134+
"--templates=/home/weaver/templates",
135+
"rules",
136+
"/home/weaver/target/")
137+
138+
setArgs(listOf("run") + file_args + weaver_args)
139+
}
140+
102141
// Don't publish non-shadowed jar (shadowJar is in shadowRuntimeElements)
103142
with(components["java"] as AdhocComponentWithVariants) {
104143
configurations.forEach {

0 commit comments

Comments
 (0)