From 9010f80bf628b83a28178f5f1ecf64f3ab132843 Mon Sep 17 00:00:00 2001 From: Jiri Date: Mon, 3 Jun 2024 16:54:21 +0200 Subject: [PATCH] FIXME Implemented very basic linking to the diff tool --- .../main/comparator/StackTraceCompare.java | 30 +++++++++++++----- .../plugins/report/jtreg/CommonOptions.java | 31 +++++++++++++++++++ .../plugins/report/jtreg/Constants.java | 18 ++++++----- .../plugins/report/jtreg/main/Service.java | 7 +++-- .../jtreg/model/UrlsProviderPlugin.java | 7 +++-- .../jtreg/BuildReportExtendedPluginTest.java | 6 ++-- 6 files changed, 76 insertions(+), 23 deletions(-) diff --git a/report-jtreg-comparator/src/main/java/io/jenkins/plugins/report/jtreg/main/comparator/StackTraceCompare.java b/report-jtreg-comparator/src/main/java/io/jenkins/plugins/report/jtreg/main/comparator/StackTraceCompare.java index 8217b2d..fe45ceb 100644 --- a/report-jtreg-comparator/src/main/java/io/jenkins/plugins/report/jtreg/main/comparator/StackTraceCompare.java +++ b/report-jtreg-comparator/src/main/java/io/jenkins/plugins/report/jtreg/main/comparator/StackTraceCompare.java @@ -1,6 +1,7 @@ package io.jenkins.plugins.report.jtreg.main.comparator; import io.jenkins.plugins.report.jtreg.BuildSummaryParser; +import io.jenkins.plugins.report.jtreg.CommonOptions; import io.jenkins.plugins.report.jtreg.ConfigFinder; import io.jenkins.plugins.report.jtreg.utils.StackTraceTools; import io.jenkins.plugins.report.jtreg.formatters.JtregPluginServicesCell; @@ -101,7 +102,7 @@ public static void compareTraces(Map> failedMap, Optio String jobId = Builds.getBuildNumber(new File(jobBuilds.get(column-1))); String id = "comapre-" + test + "-" + buildName + "-" + jobId; List maybeSeveralComaprisons = new ArrayList<>(); - maybeSeveralComaprisons.add(new JtregPluginServicesLinkWithTooltip(stringToPut, null, id, createTooltip(test, buildName, jobId, column, id, options.getJenkinsUrl()), true)); + maybeSeveralComaprisons.add(new JtregPluginServicesLinkWithTooltip(stringToPut, null, id, createTooltip(test, buildName, jobId, test, column, id, options.getJenkinsUrl(), options.getDiffUrl()), true)); //you can add more links simply by //maybeSeveralComaprisons.add(new JtregPluginServicesLinkWithTooltip("X2", "test", null, getLinksTooltip(), true)); //maybeSeveralComaprisons.add(new JtregPluginServicesLinkWithTooltip("X3", "test", null, getLinksTooltip(), true)); @@ -113,7 +114,7 @@ public static void compareTraces(Map> failedMap, Optio } // TODO delete, just for debug logging - System.err.println("Test " + (i - 1) + "/" + failedTests.size() + " - " + (int)((i - 1)/(double)failedTests.size() * 100) + "%"); + System.err.println("Test " + (i - 1) + "/" + failedTests.size() + " - " + (int) ((i - 1) / (double) failedTests.size() * 100) + "%"); i++; } @@ -122,15 +123,30 @@ public static void compareTraces(Map> failedMap, Optio options.getFormatter().printTable(table, failedTests.size() + 1, jobBuilds.size() + 1); } - private static List createTooltip(String result, String buildName, String buildId, int column, String id, String url) { - List list = VirtualJobsResults.createTooltip(result, buildName, buildId, column, id, url); + private static List createTooltip(String result, String buildName, String buildId, String test, int column, String id, String jenkinsUrl, String comapratorUrl) { + List list = VirtualJobsResults.createTooltip(result, buildName, buildId, column, id, jenkinsUrl); list.add(new JtregPluginServicesLinkWithTooltip("*** comapre links ***")); - list.add(new JtregPluginServicesLinkWithTooltip(" * use this as base", "some link", null)); - list.add(new JtregPluginServicesLinkWithTooltip(" * show diff agaisnt base", "some otjer link", null)); - list.add(new JtregPluginServicesLinkWithTooltip(" * show diff in different setup", "other link", null)); + list.add(new JtregPluginServicesLinkWithTooltip(" * show diff against self", getSelfDiffLink(buildName, buildId, test, comapratorUrl))); + list.add(new JtregPluginServicesLinkWithTooltip(" * show diff against base", "other link", null)); + list.add(new JtregPluginServicesLinkWithTooltip(" * show diff against right one", "other link", null)); + list.add(new JtregPluginServicesLinkWithTooltip(" * show diff against left one", "other link", null)); + list.add(new JtregPluginServicesLinkWithTooltip(" * use this as base (not yet working)", "must reconstruct parameters map, and add/replace ++--set-referential+build:id. May be good idea to append anchor of #test-job-id (where #==%23", null)); return list; } + private static String getSelfDiffLink(String buildName, String buildId, String test, String comapratorUrl) { + return getDiffLink(buildName, buildId, buildName, buildId, test, comapratorUrl); + } + + private static String getDiffLink(String buildName1, String buildId1, String buildName2, String buildId2, String test, String comapratorUrl) { + return comapratorUrl + "?generated-part=&custom-part=" + + "++--formatting+html" + + "++--diff-format+sidebyside" + + "++--trace-from+" + buildName1 + "%3A"/*:*/ + buildId1 + + "++--trace-to+" + buildName2 + "%3A"/*:*/ + buildId2 + + "++--exact-tests+" + test.replaceAll("#", "%23"); + } + private static int getTraceSimilarity(String one, String two) { // TODO: // - try the second, memory efficient algorithm (maybe give the user a choice?) diff --git a/report-jtreg-lib/src/main/java/io/jenkins/plugins/report/jtreg/CommonOptions.java b/report-jtreg-lib/src/main/java/io/jenkins/plugins/report/jtreg/CommonOptions.java index 99df455..9e0e50f 100644 --- a/report-jtreg-lib/src/main/java/io/jenkins/plugins/report/jtreg/CommonOptions.java +++ b/report-jtreg-lib/src/main/java/io/jenkins/plugins/report/jtreg/CommonOptions.java @@ -76,6 +76,37 @@ public void setJenkinsUrl(String jenkinsUrl) { this.jenkinsUrl = jenkinsUrl; } + /** + * FIXME; this is terribly hackish an incredibnly wrong + * But considering the nature of our CGI wrapper, th "self" url is not bubblibng down + * unless it would be passed in similarly as jenkins url. + *

+ * Already port is out of scope here:( + * + * @return nonsense + */ + public String getSelfUrl() { + final String wrongGuessedDefaultPort = "9090"; + if (jenkinsUrl != null) { + if (jenkinsUrl.contains(":")) { + return jenkinsUrl.replaceAll(":8080.*", ":" + wrongGuessedDefaultPort); + } else { + return jenkinsUrl + ":" + wrongGuessedDefaultPort; + } + } else { + return "http://localhost:" + wrongGuessedDefaultPort; + } + } + + public String getDiffUrl() { + return getSelfUrl() + Constants.DIFF_BACKEND; + } + + public String getComparatorUrl() { + return getSelfUrl() + Constants.COMPARATOR_BACKEND; + } + + public enum Side { Head, HeadEach, Tail, TailEach } diff --git a/report-jtreg-lib/src/main/java/io/jenkins/plugins/report/jtreg/Constants.java b/report-jtreg-lib/src/main/java/io/jenkins/plugins/report/jtreg/Constants.java index a4f8eee..57bb27e 100644 --- a/report-jtreg-lib/src/main/java/io/jenkins/plugins/report/jtreg/Constants.java +++ b/report-jtreg-lib/src/main/java/io/jenkins/plugins/report/jtreg/Constants.java @@ -28,16 +28,20 @@ final public class Constants { public static final String REPORT_JSON = "report.json"; public static final String REPORT_TESTS_LIST_JSON = "tests-list.json"; public static final String IRRELEVANT_GLOB_STRING = "report-{runtime,devtools,compiler}.xml.gz"; + + public static final String LIST_BACKEND = "/list.html"; + public static final String COMPARATOR_BACKEND = "/comp.html"; + public static final String DIFF_BACKEND = "/diff.html"; public static final double VAGUE_QUERY_THRESHOLD = 0.5; public static final int VAGUE_QUERY_LENGTH_THRESHOLD = 4; public static final String COMPARATOR_TABLE_CSS = - "