You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2018/07/03 20:06:47 UTC
svn commit: r1835018 - in /jmeter/trunk/src/core/org/apache/jmeter:
report/dashboard/HtmlTemplateExporter.java
report/processor/graph/impl/CustomGraphConsumer.java save/CSVSaveService.java
Author: pmouawad
Date: Tue Jul 3 20:06:47 2018
New Revision: 1835018
URL: http://svn.apache.org/viewvc?rev=1835018&view=rev
Log:
Bug 62166 - Report/Dashboard: Provide ability to register custom graphs and metrics in the JMeter Dashboard
Fix Sonar warnings
Make code clearer and use CSVSaveService constants
Bugzilla Id: 62166
Modified:
jmeter/trunk/src/core/org/apache/jmeter/report/dashboard/HtmlTemplateExporter.java
jmeter/trunk/src/core/org/apache/jmeter/report/processor/graph/impl/CustomGraphConsumer.java
jmeter/trunk/src/core/org/apache/jmeter/save/CSVSaveService.java
Modified: jmeter/trunk/src/core/org/apache/jmeter/report/dashboard/HtmlTemplateExporter.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/report/dashboard/HtmlTemplateExporter.java?rev=1835018&r1=1835017&r2=1835018&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/report/dashboard/HtmlTemplateExporter.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/report/dashboard/HtmlTemplateExporter.java Tue Jul 3 20:06:47 2018
@@ -61,6 +61,8 @@ import freemarker.template.TemplateExcep
*/
public class HtmlTemplateExporter extends AbstractDataExporter {
+ private static final String CUSTOM_GRAPH_PREFIX = "custom_";
+
/** Format used for non null check of parameters. */
private static final String MUST_NOT_BE_NULL = "%s must not be null";
@@ -459,7 +461,7 @@ public class HtmlTemplateExporter extend
graphConfiguration.excludesControllers());
checker.setGraphId(graphId);
mapConfiguration.put(graphId, graphConfiguration);
- if(graphId.substring(0,7).equals("custom_")) {
+ if(graphId.startsWith(CUSTOM_GRAPH_PREFIX)) {
addResultToContext(graphId, storedData, customGraphs, jsonizer,
customizer, checker);
} else {
Modified: jmeter/trunk/src/core/org/apache/jmeter/report/processor/graph/impl/CustomGraphConsumer.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/report/processor/graph/impl/CustomGraphConsumer.java?rev=1835018&r1=1835017&r2=1835018&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/report/processor/graph/impl/CustomGraphConsumer.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/report/processor/graph/impl/CustomGraphConsumer.java Tue Jul 3 20:06:47 2018
@@ -19,7 +19,9 @@ package org.apache.jmeter.report.process
import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.report.core.ConvertException;
@@ -35,6 +37,7 @@ import org.apache.jmeter.report.processo
import org.apache.jmeter.report.processor.graph.GraphValueSelector;
import org.apache.jmeter.report.processor.graph.GroupInfo;
import org.apache.jmeter.report.processor.graph.TimeStampKeysSelector;
+import org.apache.jmeter.save.CSVSaveService;
/**
* The class CustomGraphConsumer is added by the custom Graphs plugin.
@@ -51,6 +54,20 @@ public class CustomGraphConsumer extends
public static final String RESULT_CONTENT_MESSAGE = "content_Message"; //$NON-NLS-1$
public static final String REPORT_GENERATOR_PROPERTIES = "jmeter.reportgenerator.graph.customGraph.property"; //$NON-NLS-1$
+ private static final Set<String> NATIVE_VARIABLES =
+ new HashSet<>(Arrays.asList(CSVSaveService.DATA_TYPE,
+ CSVSaveService.FAILURE_MESSAGE, CSVSaveService.LABEL,
+ CSVSaveService.RESPONSE_CODE, CSVSaveService.RESPONSE_MESSAGE,
+ CSVSaveService.SUCCESSFUL, CSVSaveService.THREAD_NAME,
+ CSVSaveService.TIME_STAMP, CSVSaveService.CSV_ELAPSED,
+ CSVSaveService.CSV_BYTES, CSVSaveService.CSV_SENT_BYTES,
+ CSVSaveService.CSV_THREAD_COUNT1, CSVSaveService.CSV_THREAD_COUNT2,
+ CSVSaveService.CSV_SAMPLE_COUNT, CSVSaveService.CSV_ERROR_COUNT,
+ CSVSaveService.CSV_URL, CSVSaveService.CSV_FILENAME,
+ CSVSaveService.CSV_LATENCY, CSVSaveService.CSV_CONNECT_TIME,
+ CSVSaveService.CSV_ENCODING, CSVSaveService.CSV_HOSTNAME,
+ CSVSaveService.CSV_IDLETIME));
+
private String yAxis;
private String xAxis;
private String contentMessage;
@@ -143,19 +160,7 @@ public class CustomGraphConsumer extends
*/
public void setSampleVariableName(String sampleVarName) {
sampleVariableName = sampleVarName;
- // this if contains every native sample variables names
- if(sampleVarName.equals("timeStamp") || sampleVarName.equals("elapsed")
- || sampleVarName.equals("label") || sampleVarName.equals("responseCode")
- || sampleVarName.equals("threadName") || sampleVarName.equals("success")
- || sampleVarName.equals("failureMessage") || sampleVarName.equals("bytes")
- || sampleVarName.equals("sentBytes") || sampleVarName.equals("grpThreads")
- || sampleVarName.equals("allThreads") || sampleVarName.equals("URL")
- || sampleVarName.equals("Latency") || sampleVarName.equals("IdleTime")
- || sampleVarName.equals("Connect")) {
- isNativeSampleVariableName = true;
- }else {
- isNativeSampleVariableName = false;
- }
+ isNativeSampleVariableName = NATIVE_VARIABLES.contains(sampleVarName);
}
@@ -207,13 +212,15 @@ public class CustomGraphConsumer extends
new GraphValueSelector() {
@Override
public Double select(String series, Sample sample) {
- String value="";
+ String value;
if(isNativeSampleVariableName) {
value = sample.getData(sampleVariableName);
}else {
- value = sample.getData("\""+sampleVariableName+"\"");
+ value = sample.getData(CSVSaveService.VARIABLE_NAME_QUOTE_CHAR
+ + sampleVariableName
+ + CSVSaveService.VARIABLE_NAME_QUOTE_CHAR);
}
- if(StringUtils.isEmpty(value) || value.equals("null")) {
+ if(StringUtils.isEmpty(value) || "null".equals(value)) {
return null;
}
else {
Modified: jmeter/trunk/src/core/org/apache/jmeter/save/CSVSaveService.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/save/CSVSaveService.java?rev=1835018&r1=1835017&r2=1835018&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/save/CSVSaveService.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/save/CSVSaveService.java Tue Jul 3 20:06:47 2018
@@ -99,7 +99,7 @@ public final class CSVSaveService {
// Used to enclose variable name labels, to distinguish from any of the
// above labels
- private static final String VARIABLE_NAME_QUOTE_CHAR = "\""; // $NON-NLS-1$
+ public static final String VARIABLE_NAME_QUOTE_CHAR = "\""; // $NON-NLS-1$
// Initial config from properties
private static final SampleSaveConfiguration _saveConfig = SampleSaveConfiguration