Skip to content

Commit

Permalink
Fix Trends links, close gatling/gatling#3505
Browse files Browse the repository at this point in the history
Motivations:
- Trends links were broken
- Trends graph name was changed incorrectly to the last run name

Modifications:
- Added the simulation directory name to the Point class
  • Loading branch information
Cédric Cousseran committed Aug 3, 2018
1 parent c46b156 commit be23a1b
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 11 deletions.
1 change: 0 additions & 1 deletion src/main/java/io/gatling/jenkins/GatlingBuildAction.java
Expand Up @@ -87,7 +87,6 @@ public String getReportURL(BuildSimulation simulation) {
}

private BuildSimulation getSimulationByReportName(String reportName) {
// this isn't the most efficient implementation in the world :)
for (BuildSimulation sim : this.getSimulations()) {
if (sim.getSimulationDirectory().getName().equals(reportName)) {
return sim;
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/io/gatling/jenkins/chart/Graph.java
Expand Up @@ -43,11 +43,12 @@ public Graph(Job<?, ?> job, int maxBuildsToDisplay) {
if (action != null) {
numberOfBuild++;
for (BuildSimulation sim : action.getSimulations()) {
SerieName name = new SerieName(sim.getSimulationName());
if (!series.containsKey(name))
series.put(name, new Serie<Integer, Y>());
SerieName serieName = new SerieName(sim.getSimulationName(), sim.getSimulationDirectory().getName());
if (!series.containsKey(serieName)) {
series.put(serieName, new Serie<Integer, Y>());
}

series.get(name).addPoint(run.getNumber(), getValue(sim.getRequestReport()));
series.get(serieName).addPoint(run.getNumber(), getValue(sim.getRequestReport()), serieName.path);
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/main/java/io/gatling/jenkins/chart/Point.java
Expand Up @@ -25,10 +25,12 @@
public class Point<X extends Number, Y extends Number> implements JsonSerializable {
private final X x;
private final Y y;
private final String name;

public Point(X x, Y y) {
public Point(X x, Y y, String name) {
this.x = x;
this.y = y;
this.name = name;
}

public X getX() {
Expand All @@ -39,10 +41,15 @@ public Y getY() {
return y;
}

public String getName() {
return name;
}

public void serialize(JsonGenerator jgen, SerializerProvider provider) throws IOException {
jgen.writeStartArray();
jgen.writeObject(x);
jgen.writeObject(y);
jgen.writeObject(name);
jgen.writeEndArray();
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/gatling/jenkins/chart/Serie.java
Expand Up @@ -28,8 +28,8 @@
public class Serie<X extends Number, Y extends Number> implements JsonSerializable {
private final List<Point<X, Y>> points = new ArrayList<Point<X, Y>>();

public void addPoint(X x, Y y) {
points.add(new Point<X, Y>(x, y));
public void addPoint(X x, Y y, String name) {
points.add(new Point<X, Y>(x, y, name));
}

public void serialize(JsonGenerator jgen, SerializerProvider provider) throws IOException {
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/io/gatling/jenkins/chart/SerieName.java
Expand Up @@ -16,6 +16,7 @@
package io.gatling.jenkins.chart;

import java.io.IOException;
import java.util.Objects;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializable;
Expand All @@ -24,15 +25,18 @@

public class SerieName implements JsonSerializable, Comparable<SerieName> {
final String name;
final String path;

public SerieName(String name) {
public SerieName(String name, String path) {
this.name = name;
this.path = path;
}

public void serialize(JsonGenerator jgen, SerializerProvider provider) throws IOException {
jgen.disable(JsonGenerator.Feature.QUOTE_FIELD_NAMES);
jgen.writeStartObject();
jgen.writeStringField("label", name);
jgen.writeStringField("path", path);
jgen.writeEndObject();
}

Expand Down
Expand Up @@ -9,12 +9,11 @@
</div>

<script>
var dashboardSeriesNames = ${action.dashboardGraph.seriesNamesJSON};
var dashboardSeriesValues = ${action.dashboardGraph.seriesJSON};
jQueryGatling('#dashboardGatling').bind('jqplotDataClick',
function (ev, seriesIndex, pointIndex, data) {
var xAxisArray = dashboardSeriesValues[seriesIndex];
var url = xAxisArray[pointIndex][0] + "/gatling/report/" + dashboardSeriesNames[seriesIndex].label + "/";
var url = xAxisArray[pointIndex][0] + "/gatling/report/" + xAxisArray[pointIndex][2] + "/";
var win = window.open(url, '_blank');
win.focus();
}
Expand Down

0 comments on commit be23a1b

Please sign in to comment.