Skip to content

Commit

Permalink
group transactions by txName and testScriptID in trending report
Browse files Browse the repository at this point in the history
backward compatible in html

show testScriptID+txName pair in latest run only
  • Loading branch information
narcotics726 committed Oct 17, 2023
1 parent 27989cc commit 26de434
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ public final class TransactionData implements Serializable {
private int passed;
private int failed;

private int testScriptID;

//#region accessors
public String getName() {
return name;
Expand Down Expand Up @@ -189,6 +191,14 @@ public double getFailed() {
public void setFailed(final int failed) {
this.failed = failed;
}

public int getTestScriptID() {
return testScriptID;
}

public void setTestScriptID(final int testScriptID) {
this.testScriptID = testScriptID;
}
//#endregion

public TransactionData(final JsonObject json) {
Expand All @@ -208,6 +218,7 @@ public TransactionData(final JsonObject json) {
public TransactionData(final TestRunTransactionsResponse tx) {
this.name = tx.getName();
this.script = tx.getScriptName();
this.testScriptID = tx.getLoadTestScriptId();
this.min = tx.getMinTRT();
this.max = tx.getMaxTRT();
this.avg = tx.getAvgTRT();
Expand Down
34 changes: 22 additions & 12 deletions src/main/java/com/microfocus/lrc/jenkins/TrendingReport.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.microfocus.lrc.core.Constants
import com.microfocus.lrc.core.HTMLTemplate
import com.microfocus.lrc.core.entity.TrendingConfiguration
import com.microfocus.lrc.core.entity.TrendingDataWrapper
import com.microfocus.lrc.core.entity.TrendingDataWrapper.TransactionData
import hudson.model.Job
import hudson.model.Run
import jenkins.model.Jenkins
Expand Down Expand Up @@ -117,6 +118,7 @@ class TrendingReport {
}
)

val latestTrans = latestBuildAction.trendingDataWrapper.trendingData.transactions
var latestBenchmark: TrendingDataWrapper.TrendingData? = latestBuildAction.trendingDataWrapper.benchmark
if (latestBenchmark == null) {
LoggerProxy.sysLogger.log(
Expand Down Expand Up @@ -154,7 +156,7 @@ class TrendingReport {
}

val trts = JsonArray()
val transactionsGroup: Map<Pair<String, String>, List<JsonObject>> =
val transactionsGroup: Map<Pair<String, Int>, List<JsonObject>> =
trendingDataWrapperList.stream().flatMap { t: JsonObject ->
(Gson().fromJson(
t.get("data").asString,
Expand All @@ -168,30 +170,35 @@ class TrendingReport {
tempTrans.addProperty("buildId", t.get("buildId").asInt)
tempTrans.addProperty("runId", trendingDataWrapper.trendingData.runId)
tempTrans.addProperty("percentile", trendingDataWrapper.trendingData.percentile)
tempTrans
return@map tempTrans
}
}.filter{transJSON ->
val trans = Gson().fromJson(transJSON.get("data").asString, TrendingDataWrapper.TransactionData::class.java)
return@filter latestTrans.stream().anyMatch{ x -> x.testScriptID == trans.testScriptID }
}.collect(
Collectors.groupingBy { transJSON ->
val trans: TrendingDataWrapper.TransactionData =
Gson().fromJson(
transJSON.get("data").asString,
TrendingDataWrapper.TransactionData::class.java
)
return@groupingBy Pair(trans.name, trans.script)
return@groupingBy Pair(trans.name, trans.testScriptID)
}
)

transactionsGroup.forEach { (transScriptName: Pair<String?, String?>, transJSONList: List<JsonObject>) ->
transactionsGroup.forEach { (transScriptPair: Pair<String, Int>, transJSONList: List<JsonObject>) ->
generatorLogs.append(
String.format(
"processing transaction group: %1\$s - %2\$s%n",
transScriptName.first,
transScriptName.second
transScriptPair.first,
transScriptPair.second,
)
)
val trtGroup = JsonObject()
trtGroup.addProperty("transactionName", transScriptName.first)
trtGroup.addProperty("scriptName", transScriptName.second)
trtGroup.addProperty("transactionName", transScriptPair.first)
trtGroup.addProperty("testScriptID", transScriptPair.second)
val trans = Gson().fromJson(transJSONList[0].get("data").asString, TransactionData::class.java)
trtGroup.addProperty("scriptName", trans.script)
trtGroup.add("trtDataArr", JsonArray())
//transJSONList: {buildId, runId, percentile, data: TransactionData}[]
transJSONList.stream()
Expand All @@ -204,7 +211,10 @@ class TrendingReport {
)
//here is the default benchmark transaction
var benchmarkTrans: TrendingDataWrapper.TransactionData? = benchmark.transactions.stream()
.filter { t -> (transScriptName.first == t.name) && (transScriptName.second == t.script) }
.filter { t ->
(transScriptPair.first == t.name)
&& (transScriptPair.second == t.testScriptID)
}
.findAny().orElse(null)
var benchmarkRunId: Int = benchmark.runId
if (latestBuildAction.trendingDataWrapper.benchmarkId == null) {
Expand Down Expand Up @@ -239,8 +249,8 @@ class TrendingReport {
generatorLogs.append(
String.format(
"\t\t\t\tcannot find benchmark for %1\$s - %2\$s%n",
transScriptName.first,
transScriptName.second
transScriptPair.first,
transScriptPair.second
)
)
}
Expand All @@ -257,7 +267,7 @@ class TrendingReport {
benchmarkTrans,
trendingConfig
)
trt
return@map trt
}.forEach { trtJSON ->
trtGroup.getAsJsonArray("trtDataArr").add(trtJSON)
}
Expand Down
30 changes: 30 additions & 0 deletions src/main/resources/trending_report/run_report.twig
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,36 @@
});
}
// filter out those old tx data (testScriptID = 0), assign testScriptID according to others with same
// scriptName & txName
orderedTrt = _.chain(orderedTrt)
.forEach(function (x) {
if (x.testScriptID !== 0) {
return;
}
const sameScriptName = orderedTrt.find(function (y) {
return y.scriptName === x.scriptName
&& y.transactionName === x.transactionName
&& y.testScriptID !== 0;
});
if (sameScriptName) {
sameScriptName.trtDataArr = sameScriptName.trtDataArr.concat(x.trtDataArr);
x.testScriptID = -1;
}
}).filter(function (x) { return x.testScriptID !== -1; }).value();
orderedTrt.forEach(function (x) {
var sameScriptNames = orderedTrt.filter(function (y) {
return y.scriptName === x.scriptName && y.transactionName === x.transactionName;
});
if (sameScriptNames.length > 1) {
sameScriptNames.forEach(function (item) {
item.scriptName = item.testScriptID + '_' + item.scriptName;
});
}
});
_.each(orderedTrt, function (item) {
var rowDOM = document.createElement('tr');
var colNode = document.createElement('td');
Expand Down

0 comments on commit 26de434

Please sign in to comment.