Skip to content

Commit 2e2cbad

Browse files
feat: attach Java dedup agent in sample
1 parent 659c400 commit 2e2cbad

7 files changed

Lines changed: 96 additions & 16 deletions

File tree

.github/workflows/java-dedup.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Java Dedup Sample
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
push:
7+
branches: [main]
8+
9+
jobs:
10+
build:
11+
name: JDK ${{ matrix.java-version }}
12+
runs-on: ubuntu-latest
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
java-version: ["8", "17", "21"]
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
22+
- name: Set up JDK ${{ matrix.java-version }}
23+
uses: actions/setup-java@v4
24+
with:
25+
distribution: temurin
26+
java-version: ${{ matrix.java-version }}
27+
cache: maven
28+
29+
- name: Build java-dedup without Keploy compile dependency
30+
working-directory: java-dedup
31+
run: mvn -B -DskipTests clean package
32+
33+
- name: Verify Keploy is not a compile-time dependency
34+
working-directory: java-dedup
35+
run: |
36+
set -euo pipefail
37+
mvn -B dependency:tree -Dincludes=io.keploy:keploy-sdk -DoutputFile=target/keploy-dependency-tree.txt
38+
if grep -q "io.keploy:keploy-sdk" target/keploy-dependency-tree.txt; then
39+
cat target/keploy-dependency-tree.txt
40+
exit 1
41+
fi
42+
if grep -R "io.keploy\\.dedup\\|io.keploy\\.servlet\\|KeployDedupAgent\\|KeployMiddleware" src/main/java; then
43+
exit 1
44+
fi

java-dedup/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ RUN groupadd --gid 10001 appuser \
77
&& useradd --uid 10001 --gid 10001 --home-dir /home/appuser --create-home --shell /usr/sbin/nologin appuser
88

99
COPY --chown=10001:10001 target/java-dedup-0.0.1-SNAPSHOT.jar /app/app.jar
10+
COPY --chown=10001:10001 target/keploy-sdk.jar /app/keploy-sdk.jar
1011
COPY --chown=10001:10001 target/jacocoagent.jar /app/jacocoagent.jar
1112
EXPOSE 8080
1213
USER 10001:10001
13-
ENTRYPOINT ["java", "-javaagent:/app/jacocoagent.jar=destfile=/tmp/jacoco.exec", "-jar", "/app/app.jar"]
14+
ENTRYPOINT ["java", "-javaagent:/app/keploy-sdk.jar", "-javaagent:/app/jacocoagent.jar=destfile=/tmp/jacoco.exec", "-jar", "/app/app.jar"]

java-dedup/Dockerfile.classpath

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ RUN groupadd --gid 10001 appuser \
88

99
COPY --chown=10001:10001 target/classes /app/classes
1010
COPY --chown=10001:10001 target/dependency /app/libs
11+
COPY --chown=10001:10001 target/keploy-sdk.jar /app/keploy-sdk.jar
1112
COPY --chown=10001:10001 target/jacocoagent.jar /app/jacocoagent.jar
1213

1314
ENV KEPLOY_JAVA_CLASS_DIRS=/app/classes
1415

1516
EXPOSE 8080
1617
USER 10001:10001
17-
ENTRYPOINT ["java", "-javaagent:/app/jacocoagent.jar=destfile=/tmp/jacoco.exec", "-cp", "/app/classes:/app/libs/*", "io.keploy.samples.javadedup.JavaDedupApplication"]
18+
ENTRYPOINT ["java", "-javaagent:/app/keploy-sdk.jar", "-javaagent:/app/jacocoagent.jar=destfile=/tmp/jacoco.exec", "-cp", "/app/classes:/app/libs/*", "io.keploy.samples.javadedup.JavaDedupApplication"]

java-dedup/Dockerfile.distroless

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ FROM gcr.io/distroless/java17-debian12:nonroot
33
WORKDIR /app
44

55
COPY --chown=10001:10001 target/java-dedup-0.0.1-SNAPSHOT.jar /app/app.jar
6+
COPY --chown=10001:10001 target/keploy-sdk.jar /app/keploy-sdk.jar
67
COPY --chown=10001:10001 target/jacocoagent.jar /app/jacocoagent.jar
78

89
EXPOSE 8080
910
USER 10001:10001
10-
ENTRYPOINT ["java", "-javaagent:/app/jacocoagent.jar=destfile=/tmp/jacoco.exec", "-jar", "/app/app.jar"]
11+
ENTRYPOINT ["java", "-javaagent:/app/keploy-sdk.jar", "-javaagent:/app/jacocoagent.jar=destfile=/tmp/jacoco.exec", "-jar", "/app/app.jar"]

java-dedup/README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,23 @@ A Spring Boot application used by Keploy CI to validate Java dynamic deduplicati
44

55
CI does not record this sample. The `keploy/` directory is checked in so the pipeline only builds the app and runs replay with `--dedup`.
66

7-
The Java SDK reads JaCoCo coverage in-process via `org.jacoco.agent.rt.RT.getAgent().getExecutionData(...)`, so attaching the JaCoCo Java agent is enough — no TCP server, no port choice, no `--pass-through-ports`.
7+
The Keploy Java SDK is attached as a Java agent at replay time. The sample does not compile against `io.keploy:keploy-sdk` and does not import Keploy classes in application code.
8+
9+
The SDK reads JaCoCo coverage in-process via `org.jacoco.agent.rt.RT.getAgent().getExecutionData(...)`, so attach both agents when running dynamic deduplication: the Keploy agent for the control/data socket protocol, and the JaCoCo agent for runtime coverage.
810

911
## Setup
1012

1113
```bash
12-
mvn -B -DskipTests clean package
14+
mvn -B -DskipTests -Dkeploy.agent.version=2.0.1 clean package
1315
```
1416

15-
This builds the sample against the released Keploy Java SDK, produces `target/java-dedup-0.0.1-SNAPSHOT.jar`, and copies `target/jacocoagent.jar` next to it.
17+
This produces `target/java-dedup-0.0.1-SNAPSHOT.jar`, copies `target/keploy-sdk.jar`, and copies `target/jacocoagent.jar` next to it. Use the released Keploy Java SDK version that includes Java-agent support.
1618

1719
## Run dedup natively
1820

1921
```bash
2022
keploy test \
21-
-c "java -javaagent:target/jacocoagent.jar -jar target/java-dedup-0.0.1-SNAPSHOT.jar" \
23+
-c "java -javaagent:target/keploy-sdk.jar -javaagent:target/jacocoagent.jar -jar target/java-dedup-0.0.1-SNAPSHOT.jar" \
2224
--dedup --language java --delay 1 \
2325
--health-url "http://127.0.0.1:8080/healthz" \
2426
--health-poll-timeout 30s \

java-dedup/pom.xml

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
<properties>
2121
<java.version>1.8</java.version>
22-
<keploy.sdk.version>2.0.0</keploy.sdk.version>
2322
<jacoco.version>0.8.12</jacoco.version>
2423
</properties>
2524

@@ -28,11 +27,6 @@
2827
<groupId>org.springframework.boot</groupId>
2928
<artifactId>spring-boot-starter-web</artifactId>
3029
</dependency>
31-
<dependency>
32-
<groupId>io.keploy</groupId>
33-
<artifactId>keploy-sdk</artifactId>
34-
<version>${keploy.sdk.version}</version>
35-
</dependency>
3630
</dependencies>
3731

3832
<build>
@@ -81,4 +75,44 @@
8175
</plugin>
8276
</plugins>
8377
</build>
78+
79+
<profiles>
80+
<profile>
81+
<id>copy-keploy-agent</id>
82+
<activation>
83+
<property>
84+
<name>keploy.agent.version</name>
85+
</property>
86+
</activation>
87+
<build>
88+
<plugins>
89+
<plugin>
90+
<groupId>org.apache.maven.plugins</groupId>
91+
<artifactId>maven-dependency-plugin</artifactId>
92+
<version>3.6.1</version>
93+
<executions>
94+
<execution>
95+
<id>copy-keploy-java-agent</id>
96+
<phase>package</phase>
97+
<goals>
98+
<goal>copy</goal>
99+
</goals>
100+
<configuration>
101+
<artifactItems>
102+
<artifactItem>
103+
<groupId>io.keploy</groupId>
104+
<artifactId>keploy-sdk</artifactId>
105+
<version>${keploy.agent.version}</version>
106+
<outputDirectory>${project.build.directory}</outputDirectory>
107+
<destFileName>keploy-sdk.jar</destFileName>
108+
</artifactItem>
109+
</artifactItems>
110+
</configuration>
111+
</execution>
112+
</executions>
113+
</plugin>
114+
</plugins>
115+
</build>
116+
</profile>
117+
</profiles>
84118
</project>

java-dedup/src/main/java/io/keploy/samples/javadedup/JavaDedupApplication.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
package io.keploy.samples.javadedup;
22

3-
import io.keploy.servlet.KeployMiddleware;
43
import org.springframework.boot.SpringApplication;
54
import org.springframework.boot.autoconfigure.SpringBootApplication;
6-
import org.springframework.context.annotation.Import;
75

86
@SpringBootApplication
9-
@Import(KeployMiddleware.class)
107
public class JavaDedupApplication {
118

129
public static void main(String[] args) {

0 commit comments

Comments
 (0)