Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: send graphql request to update report with coverage data #176

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
72 changes: 60 additions & 12 deletions v2/src/main/java/io/keploy/Keploy.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,17 +221,16 @@ public static void FindCoverage(String testSet) throws IOException, InterruptedE
String dest = "target/" + testSet + ".exec";
String jacocoCliPath = getJacococliPath();
List<String> command = Arrays.asList(
"java",
"-jar",
jacocoCliPath,
"dump",
"--address",
"localhost",
"--port",
"36320",
"--destfile",
dest
);
"java",
"-jar",
jacocoCliPath,
"dump",
"--address",
"localhost",
"--port",
"36320",
"--destfile",
dest);

// Start the command using ProcessBuilder
ProcessBuilder processBuilder = new ProcessBuilder(command);
Expand Down Expand Up @@ -552,6 +551,11 @@ public static void runTests(String jarPath, RunOptions runOptions) {
if (appErr != null) {
throw new AssertionError("error stopping user application: " + appErr);
}

Boolean updateReportResult = udpateReportWithCoverage(testRunId, testSet);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck> reported by reviewdog 🐶
Line is longer than 80 characters (found 90).

if (!updateReportResult) {
throw new AssertionError("error updating report with coverage data");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck> reported by reviewdog 🐶
Line is longer than 80 characters (found 89).

}
}
// unload the ebpf hooks from the kernel
// delete jacoco files
Expand All @@ -566,7 +570,7 @@ public static void startKeploy(String runCmd, int delay, boolean debug, int port
Runnable task = () -> runKeploy(runCmd, delay, debug, port);
Thread thread = new Thread(task);
thread.start();
return ;
return;
}

public static void runKeploy(String runCmd, int delay, boolean debug, int port) {
Expand Down Expand Up @@ -805,6 +809,50 @@ public static RunTestSetResult runTestSet(String testRunId, String testSetId, St
}
}

public static Boolean udpateReportWithCoverage(String testRunId, String testSetId) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck> reported by reviewdog 🐶
Line is longer than 80 characters (found 88).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck> reported by reviewdog 🐶
Missing a Javadoc comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.FinalParametersCheck> reported by reviewdog 🐶
Parameter testRunId should be final.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.FinalParametersCheck> reported by reviewdog 🐶
Parameter testSetId should be final.

HttpURLConnection conn = setHttpClient();
if (conn == null) {
logger.error("Could not initialize HTTP connection.");
return false;
}

String payload = String.format(
"{\"query\": \"mutation updateReportWithCov{ updateReportWithCov(testRunId: \\\"%s\\\", testSetId: \\\"%s\\\", language: \\\"java\\\") }\"}",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck> reported by reviewdog 🐶
Line is longer than 80 characters (found 157).

testRunId, testSetId);

try {
conn.setDoOutput(true);
try (OutputStream os = conn.getOutputStream()) {
os.write(payload.getBytes());
os.flush();
}

int responseCode = conn.getResponseCode();
logger.debug("Status code received: " + responseCode);

if (responseCode >= 200 && responseCode < 300) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck> reported by reviewdog 🐶
'200' is a magic number.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck> reported by reviewdog 🐶
'300' is a magic number.

String resBody = getResponseBody(conn);
logger.debug("Response body received: " + resBody);

// Parse the response body using Gson
Gson gson = new Gson();
GraphQLResponse response = gson.fromJson(resBody, GraphQLResponse.class);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck> reported by reviewdog 🐶
Line is longer than 80 characters (found 89).


if (response.data == null) {
return false;
}

return true;
} else {
logger.error("Failed to update report with coverage data. Status code: " + responseCode);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck> reported by reviewdog 🐶
Line is longer than 80 characters (found 105).

return false;
}
} catch (Exception e) {
logger.error("Error updating report with coverage data: " + e.getMessage(), e);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck> reported by reviewdog 🐶
Line is longer than 80 characters (found 91).

return false;
}
}

public static class StopHooksResult {
Boolean success;
String error;
Expand Down
Loading