diff --git a/versioned_docs/version-4.0.0/developer/coverage.md b/versioned_docs/version-4.0.0/developer/coverage.md index 4f1352554..c4831ac2c 100644 --- a/versioned_docs/version-4.0.0/developer/coverage.md +++ b/versioned_docs/version-4.0.0/developer/coverage.md @@ -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. diff --git a/versioned_docs/version-4.0.0/developer/record.md b/versioned_docs/version-4.0.0/developer/record.md index 8504fe911..ed60f308a 100644 --- a/versioned_docs/version-4.0.0/developer/record.md +++ b/versioned_docs/version-4.0.0/developer/record.md @@ -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). diff --git a/versioned_docs/version-4.0.0/keploy-cloud/deduplication.md b/versioned_docs/version-4.0.0/keploy-cloud/deduplication.md index 2bd585041..e6aa393e5 100644 --- a/versioned_docs/version-4.0.0/keploy-cloud/deduplication.md +++ b/versioned_docs/version-4.0.0/keploy-cloud/deduplication.md @@ -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" ``` @@ -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 @@ -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 ``. + +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 ``` @@ -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 @@ -168,41 +144,22 @@ curl -L -o target/jacocoagent.jar \ io.keploy keploy-sdk - 2.0.6 + 2.4.0 ${project.build.directory} keploy-sdk.jar - - copy-jacoco-agent - package - copy - - - - org.jacoco - org.jacoco.agent - 0.8.12 - runtime - jar - ${project.build.directory} - jacocoagent.jar - - - - ``` -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 ``` @@ -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"] ``` @@ -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. @@ -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. diff --git a/versioned_docs/version-4.0.0/server/sdk-installation/go.md b/versioned_docs/version-4.0.0/server/sdk-installation/go.md index 916b907ab..8032b602b 100644 --- a/versioned_docs/version-4.0.0/server/sdk-installation/go.md +++ b/versioned_docs/version-4.0.0/server/sdk-installation/go.md @@ -125,6 +125,17 @@ To get the coverage related information for merged coverage data : go tool cover -func combined-coverage.txt ``` +## 3. Dynamic Deduplication with `go-sdk` + +Dynamic deduplication is available on the Enterprise plan. For per-test code paths and dynamic deduplication (`keploy test --dedup` or Kubernetes auto-replay), install `github.com/keploy/go-sdk/v3` (**`>= v3.4.1`**), blank-import `github.com/keploy/go-sdk/v3/keploy` in your `main` package, and build with `-cover -covermode=atomic -coverpkg=./...`: + +```bash +go get github.com/keploy/go-sdk/v3@latest +go build -cover -covermode=atomic -coverpkg=./... -o main . +``` + +See [Dynamic Deduplication for Golang Applications](/docs/keploy-cloud/deduplication/#for-golang-applications) for the full native and Docker setup. + ## Related - [Java Agent for Dynamic Deduplication](/docs/server/sdk-installation/java/) — the Java SDK. diff --git a/versioned_docs/version-4.0.0/server/sdk-installation/java.md b/versioned_docs/version-4.0.0/server/sdk-installation/java.md index 9ff74100f..740075659 100644 --- a/versioned_docs/version-4.0.0/server/sdk-installation/java.md +++ b/versioned_docs/version-4.0.0/server/sdk-installation/java.md @@ -20,13 +20,13 @@ import HowTo from '@site/src/components/HowTo'; = 2.3.0, current 2.4.0) into your build."}, +{name: "Run with keploy-sdk.jar", text: "Start the application with -javaagent:target/keploy-sdk.jar attached so coverage is recorded automatically without a separate JaCoCo agent."}, +{name: "Replay with dedup", text: "Run keploy test with --dedup, then keploy dedup to list the duplicates and keploy dedup --rm to remove them."}, ]} visible={false} /> @@ -39,18 +39,18 @@ The Keploy Java SDK is used as a Java agent for dynamic deduplication (available The Java agent does not record API traffic or mock dependencies. Record your Keploy tests separately, commit the generated test fixtures when you use them in CI, and run Java dedup during `keploy test --dedup`. -Because the SDK is a Java agent, it is framework-agnostic. It can be attached to Spring Boot apps, Dropwizard/Jersey apps, plain executable jars, classpath-based apps, servlet/WAR-style archives, and other JVM frameworks as long as the application JVM also runs the JaCoCo agent. +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. `keploy-sdk.jar` bundles the JaCoCo runtime agent and starts it automatically scoped to your application's own classes — do **not** attach a separate `-javaagent:...jacocoagent.jar`, which overrides the SDK's scoped embedded agent; Keploy then doesn't measure the run's code coverage. ## Requirements -- Java 8, 17, or 21 -- `io.keploy:keploy-sdk` `2.0.6` (or newer with Java-agent support) -- JaCoCo runtime agent (tested with `0.8.12`) +- JVM application compiled for Java 27 or below (tested in CI on Java 8, 11, 17, 21, and 27; `keploy-sdk` `2.4.0` bundles JaCoCo `0.8.16`) +- `io.keploy:keploy-sdk` `>= 2.3.0` (current release: `2.4.0`) — required for safe duplicate removal +- Do **not** attach a separate `jacocoagent.jar` - Keploy, signed in to an account on the Enterprise plan, with dynamic deduplication enabled -## Copy the Keploy SDK and JaCoCo Agents +## Copy the Keploy Java Agent -Both jars are runtime agents. Copy them into `target/` at build time. Do not add the Keploy SDK under `` and do not import Keploy classes from your code. +`keploy-sdk.jar` is a runtime Java agent. Copy it into `target/` at build time. Do not add `io.keploy:keploy-sdk` under `` and do not import Keploy classes from your code. ```xml @@ -67,43 +67,24 @@ Both jars are runtime agents. Copy them into `target/` at build time. Do not add io.keploy keploy-sdk - 2.0.6 + 2.4.0 ${project.build.directory} keploy-sdk.jar - - copy-jacoco-agent - package - copy - - - - org.jacoco - org.jacoco.agent - 0.8.12 - runtime - jar - ${project.build.directory} - jacocoagent.jar - - - - ``` -## Run with Both Agents +## Run with the Keploy Java Agent -Attach both agents in the application JVM. The Keploy agent reads coverage in-process via JaCoCo's runtime API, so order doesn't matter as long as both are present: +Attach only `keploy-sdk.jar` in the application JVM. It starts its bundled JaCoCo agent automatically scoped to your application classes; do not add a second `-javaagent:...jacocoagent.jar`: ```bash java \ -javaagent:target/keploy-sdk.jar \ - -javaagent:target/jacocoagent.jar \ -jar target/app.jar ``` @@ -117,7 +98,7 @@ export KEPLOY_JAVA_CLASS_DIRS=/absolute/path/to/target/classes ```bash keploy test \ - -c "java -javaagent:target/keploy-sdk.jar -javaagent:target/jacocoagent.jar -jar target/app.jar" \ + -c "java -javaagent:target/keploy-sdk.jar -jar target/app.jar" \ --dedup \ --language java ```