Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions versioned_docs/version-4.0.0/developer/coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ To increase coverage, [record](/docs/developer/record/) traffic that reaches the

Code coverage is available only for Java apps recorded with **Dynamic deduplication** turned on, on the **Record config** step of the **Start Recording** dialog.

Keploy adds its coverage agent to the replay pod by itself. Don't add `keploy-sdk.jar` or a JaCoCo agent to your image.

When the recording ends, Keploy calculates code coverage for each test set. On the **Recordings** page, select a test set to see the percentage of **lines covered** and **branches covered**. Until the numbers are ready, the panel shows **Calculating…**.

If the app runs a newer Java version than Keploy supports, the panel shows **No code coverage**, with the detected and the supported versions.
Expand Down
20 changes: 10 additions & 10 deletions versioned_docs/version-4.0.0/developer/record.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,16 @@ A Service spreads requests across all of a deployment's pods. When you record fe

The dialog remembers the values you used last time for each deployment. The defaults below apply to a deployment's first recording.

| Option | Step | Default | What it does |
| ------------------------ | ------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Number of pods to record | Pods | 1 | How many pods to capture, up to the HPA maximum or the replica count. |
| Record all pods | Pods | Off | Captures every pod. Shown only when the deployment has an HPA. |
| Auto-stop after | Pods | Empty | Stops the recording after this long. When empty, the cluster's maximum recording duration applies if your admin set one; otherwise the recording runs until you stop it. |
| Add filter | Record config | None | Includes or excludes requests by path, host, port, method or header. See [Recording filters](/docs/running-keploy/recording-filters/). |
| Static deduplication | Record config | On | Skips a request when one with the same method, path, header names, status and body structure was already captured. If you saved custom dedup fields on the **Schema** page, it stays on. See [Static Deduplication](/docs/keploy-cloud/static-deduplication/). |
| Dynamic deduplication | Record config | Off | Java apps only. During auto-replay, keeps one test case per unique code path and flags the rest as duplicates. Can't be combined with static deduplication. Also enables [code coverage](/docs/developer/coverage/#check-code-coverage-java). See [Dynamic Deduplication](/docs/keploy-cloud/deduplication/). |
| Smart test set | Record config | On | Adds the recorded flows, deduplicated, to the app's smart test set, which is used for regression testing. Shown only when **Enable Smart Tests** is turned on for your organization in **Settings**. |
| Advanced settings | Record config | Collapsed | Agent memory and CPU, Low Latency Mode (sidecar clusters only), and the containers to capture. |
| Option | Step | Default | What it does |
| ------------------------ | ------------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Number of pods to record | Pods | 1 | How many pods to capture, up to the HPA maximum or the replica count. |
| Record all pods | Pods | Off | Captures every pod. Shown only when the deployment has an HPA. |
| Auto-stop after | Pods | Empty | Stops the recording after this long. When empty, the cluster's maximum recording duration applies if your admin set one; otherwise the recording runs until you stop it. |
| Add filter | Record config | None | Includes or excludes requests by path, host, port, method or header. See [Recording filters](/docs/running-keploy/recording-filters/). |
| Static deduplication | Record config | On | Skips a request when one with the same method, path, header names, status and body structure was already captured. If you saved custom dedup fields on the **Schema** page, it stays on. See [Static Deduplication](/docs/keploy-cloud/static-deduplication/). |
| Dynamic deduplication | Record config | Off | Java and Go apps. During auto-replay, removes a test case when the code it runs is already covered by one that is kept. Removed test cases can't be restored. Java apps need no change. Go apps need a special build, see [Dynamic Deduplication](/docs/keploy-cloud/deduplication/#on-kubernetes). Can't be combined with static deduplication. For Java apps, it also enables [code coverage](/docs/developer/coverage/#check-code-coverage-java). |
| Smart test set | Record config | On | Adds the recorded flows, deduplicated, to the app's smart test set, which is used for regression testing. Shown only when **Enable Smart Tests** is turned on for your organization in **Settings**. |
| Advanced settings | Record config | Collapsed | Agent memory and CPU, Low Latency Mode (sidecar clusters only), and the containers to capture. |

:::note Capture mode is set per cluster
Whether a cluster records with a sidecar or with the DaemonSet is decided when you connect the cluster, not in this dialog. See [Choose a capture mode](/docs/developer/setup/#choose-a-capture-mode).
Expand Down
96 changes: 30 additions & 66 deletions versioned_docs/version-4.0.0/keploy-cloud/deduplication.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,17 @@ keploy test -c "docker compose up" --containerName containerName --dedup

#### 1. Pre-requisite

Install the `keploy/go-sdk/v3/keploy` : -
Install `github.com/keploy/go-sdk/v3` (**`>= v3.4.1`** is required for safe duplicate removal):

```bash
go get github.com/keploy/go-sdk/v3/keploy
go get github.com/keploy/go-sdk/v3@latest
```

Add the following on top of your main application file : -
Ensure your `go.mod` resolves `github.com/keploy/go-sdk/v3` to `v3.4.1` or newer.

```bash
Add the following blank import at the top of your `main` package:

```go
import _ "github.com/keploy/go-sdk/v3/keploy"
```

Expand All @@ -62,30 +64,7 @@ RUN go build -cover -covermode=atomic -coverpkg=./... -o /app/main .

#### 3. Dockerfile Configuration (Important for Docker Users)

If you are using a multi-stage Docker build (e.g., building in one stage and running in a slim image), you **must** ensure the Go toolchain and `go.mod` files are preserved in the final runtime image. The deduplication feature requires access to the Go runtime to map coverage data correctly.

Update your final runtime stage in the `Dockerfile` to include the following:

```dockerfile
# ... inside your final runtime stage ...

# 1. Copy Go toolchain from the builder stage
COPY --from=builder /usr/local/go /usr/local/go

# 2. Set Go environment variables so the app can use internal go tools
ENV GOROOT=/usr/local/go
ENV PATH=/usr/local/go/bin:${PATH}

# 3. Copy go.mod and go.sum (Required for dependency resolution during coverage)
COPY --from=builder /src/go.mod /src/go.sum /app/

# 4. Set the GOMOD environment variable
ENV GOMOD=/app/go.mod

# ... rest of your dockerfile ...
```

> **Note:** If you face issues with toolchain downloads in restricted environments, you may also need to set `ENV GOTOOLCHAIN=local` and configure your `GOPROXY` in the Dockerfile.
The runtime image needs no Go toolchain, so slim and distroless images work. It needs a writable `/tmp`.

#### 4. Run Deduplication

Expand Down Expand Up @@ -117,25 +96,25 @@ In order to remove all the duplicate test cases, run the following command:
keploy dedup --rm
```

`keploy dedup` keeps up to 3 tests of each duplicate group and lists the others. To keep another number, run `keploy dedup --keep N` (1 to 10) before `keploy dedup --rm`; `--rm` itself doesn't use `--keep`. `keploy dedup --rm` moves the listed duplicates to `dedupDropped/`. Run `keploy dedup --restore` within 30 days to bring them back.

### For Java Applications

#### 1. Pre-requisite

Java dynamic deduplication uses JaCoCo runtime coverage. Attach the Keploy Java agent to emit per-test coverage signals, and attach the JaCoCo runtime agent so the SDK can read the coverage data. The Java agent is framework-agnostic across Spring Boot, Dropwizard/Jersey, plain executable jars, classpath-based apps, servlet/WAR archives, etc.
Java dynamic deduplication requires **`io.keploy:keploy-sdk` `>= 2.3.0`** (current release: **`2.4.0`**).

Both agents attach at JVM startup via `-javaagent:`. They do not modify your application bytecode either at compile time or while classes load, so no source code or `pom.xml` changes are required to enable dedup.
`keploy-sdk.jar` bundles the JaCoCo runtime agent (`0.8.16` in `2.4.0`, supporting bytecode up to Java 27) and starts it automatically scoped to your application's own classes. It works with apps that serve HTTP through Tomcat (8.5 to 11), Jetty (9.4 to 12.1) or Undertow (2.2 and 2.3), such as Spring Boot MVC and Dropwizard, as an executable jar, from a classpath or as a WAR (a WAR deployed in an external Tomcat or Jetty needs `KEPLOY_JAVA_CLASS_DIRS`). On other servers, such as Netty (Spring WebFlux), gRPC, Vert.x or Micronaut, Keploy keeps every test case.

You only need `keploy-sdk.jar` and `jacocoagent.jar` available on disk wherever you reference them with `-javaagent:` at runtime. Fetch them in whichever way fits your workflow:
> **Important:** Attach **only** `-javaagent:.../keploy-sdk.jar`. Do **not** download or attach a separate `-javaagent:.../jacocoagent.jar` alongside it — adding a duplicate JaCoCo agent overrides the SDK's scoped embedded agent and can mismatch JaCoCo versions; Keploy then doesn't measure the run's code coverage. Also do not add `io.keploy:keploy-sdk` under `<dependencies>`.

You only need `keploy-sdk.jar` available on disk wherever you reference it with `-javaagent:` at runtime. Fetch it in whichever way fits your workflow:

**Option A**, one-off fetch with the Maven CLI:

```bash
mvn dependency:copy \
-Dartifact=io.keploy:keploy-sdk:2.0.6 \
-DoutputDirectory=target -Dmdep.stripVersion=true

mvn dependency:copy \
-Dartifact=org.jacoco:org.jacoco.agent:0.8.12:jar:runtime \
-Dartifact=io.keploy:keploy-sdk:2.4.0 \
-DoutputDirectory=target -Dmdep.stripVersion=true
```

Expand All @@ -145,13 +124,10 @@ mvn dependency:copy \
mkdir -p target

curl -L -o target/keploy-sdk.jar \
https://repo.maven.apache.org/maven2/io/keploy/keploy-sdk/2.0.6/keploy-sdk-2.0.6.jar

curl -L -o target/jacocoagent.jar \
https://repo.maven.apache.org/maven2/org/jacoco/org.jacoco.agent/0.8.12/org.jacoco.agent-0.8.12-runtime.jar
https://repo.maven.apache.org/maven2/io/keploy/keploy-sdk/2.4.0/keploy-sdk-2.4.0.jar
```

**Option C**, let your Maven build copy them automatically. If you'd rather Maven fetch the agents during your normal build, add the following plugin block to your `pom.xml`. It runs at the `package` phase and only copies the two JARs alongside your app jar; it does not alter the compile classpath, your application bytecode, or any source file:
**Option C**, let your Maven build copy it automatically. If you'd rather Maven fetch the agent during your normal build, add the following plugin block to your `pom.xml`. It runs at the `package` phase and only copies `keploy-sdk.jar` alongside your app jar; it does not alter the compile classpath, your application bytecode, or any source file:

```xml
<plugin>
Expand All @@ -168,41 +144,22 @@ curl -L -o target/jacocoagent.jar \
<artifactItem>
<groupId>io.keploy</groupId>
<artifactId>keploy-sdk</artifactId>
<version>2.0.6</version>
<version>2.4.0</version>
<outputDirectory>${project.build.directory}</outputDirectory>
<destFileName>keploy-sdk.jar</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
<execution>
<id>copy-jacoco-agent</id>
<phase>package</phase>
<goals><goal>copy</goal></goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
<version>0.8.12</version>
<classifier>runtime</classifier>
<type>jar</type>
<outputDirectory>${project.build.directory}</outputDirectory>
<destFileName>jacocoagent.jar</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
```

Run the app with both agents attached:
Run the app with the Keploy Java agent attached:

```bash
java \
-javaagent:target/keploy-sdk.jar \
-javaagent:target/jacocoagent.jar \
-jar target/app.jar
```

Expand All @@ -218,19 +175,17 @@ By default, the SDK scans Maven `target/classes`, Gradle `build/classes/java/mai

#### 3. Dockerfile Configuration (Important for Docker Users)

When you use Docker or Docker Compose, copy four artifacts into the runtime image and attach both agents in the entrypoint:
When you use Docker or Docker Compose, copy your app jar, `keploy-sdk.jar`, and compiled classes into the runtime image, and attach only `keploy-sdk.jar` in the entrypoint:

```dockerfile
COPY target/app.jar /app/app.jar
COPY target/keploy-sdk.jar /app/keploy-sdk.jar
COPY target/jacocoagent.jar /app/jacocoagent.jar
COPY target/classes /app/classes

ENV KEPLOY_JAVA_CLASS_DIRS=/app/classes

ENTRYPOINT ["java", \
"-javaagent:/app/keploy-sdk.jar", \
"-javaagent:/app/jacocoagent.jar", \
"-jar", "/app/app.jar"]
```

Expand All @@ -247,7 +202,7 @@ keploy test -c "docker compose up" --container-name containerName --dedup --lang
For Native, run:

```bash
keploy test -c "java -javaagent:target/keploy-sdk.jar -javaagent:target/jacocoagent.jar -jar target/app.jar" --dedup --language java
keploy test -c "java -javaagent:target/keploy-sdk.jar -jar target/app.jar" --dedup --language java
```

This produces `dedupData.yaml`, a per-testcase coverage map (`testSetID/testCaseID` to executed lines per source file) Keploy uses to compute redundancy.
Expand All @@ -262,6 +217,15 @@ This reads `dedupData.yaml` and writes `duplicates.yaml`, listing the testcases
keploy dedup --rm
```

`keploy dedup` keeps up to 3 tests of each duplicate group and lists the others. To keep another number, run `keploy dedup --keep N` (1 to 10) before `keploy dedup --rm`; `--rm` itself doesn't use `--keep`. `keploy dedup --rm` moves the listed duplicates to `dedupDropped/`. Run `keploy dedup --restore` within 30 days to bring them back.

### On Kubernetes

Turn on **Dynamic deduplication** on the **Record config** step of the **Start Recording** dialog. Keploy removes duplicates during auto-replay. Removed test cases can't be restored.

- **Java**: change nothing in your app. Keploy adds its coverage agent to the replay pod. Don't add `keploy-sdk.jar` or a JaCoCo agent to your image. The app must be compiled for Java 26 or below (Java 27 from k8s-proxy 3.9.0).
- **Go**: build the image as in [For Golang Applications](#for-golang-applications), with `-cover -covermode=atomic`. Your admin sets `dedupCoverage.language: go` in the k8s-proxy Helm values. The setting is for the whole installation: Java or Go.

## Related

- [Static Deduplication](/docs/keploy-cloud/static-deduplication/) — drop duplicate shapes at record time.
Expand Down
Loading
Loading