jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject [jmeter] branch master updated: Bug 64553 When using Transaction Controller, send Bytes and Received Bytes are displayed as 0 in the influxdb(BackendListener) (#608)
Date Sun, 30 Aug 2020 12:59:06 GMT
This is an automated email from the ASF dual-hosted git repository.

pmouawad pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git


The following commit(s) were added to refs/heads/master by this push:
     new 3617f49  Bug 64553 When using Transaction Controller, send Bytes and Received Bytes
are displayed as 0 in the influxdb(BackendListener) (#608)
3617f49 is described below

commit 3617f49087201c7d060be10cc3b4c95919c78956
Author: Philippe M <pmouawad@users.noreply.github.com>
AuthorDate: Sun Aug 30 14:58:59 2020 +0200

    Bug 64553 When using Transaction Controller, send Bytes and Received Bytes are displayed
as 0 in the influxdb(BackendListener) (#608)
    
    * 64553 When using Transaction Controller, send Bytes and Received Bytes
    are displayed as 0 in the influxdb(BackendListener)
    
    * Fix typo of parameter name
    
    * Give the cumulated add its own method
    
    * Add test cases for new method addCumulated
    
    * Method getSubResults constructs new arrays, so call only once inside method
    
    * Fix conflict
    
    Co-authored-by: Felix Schumacher <felix.schumacher@internetallee.de>
---
 .../jmeter/visualizers/backend/SamplerMetric.java  | 51 +++++++++++-----
 .../graphite/GraphiteBackendListenerClient.java    |  2 +-
 .../backend/influxdb/HttpMetricsSender.java        |  5 +-
 .../influxdb/InfluxdbBackendListenerClient.java    | 18 +++---
 .../backend/SamplerMetricFixedModeTest.java        | 62 ++++++++++++++++++++
 .../backend/SamplerMetricTimedModeTest.java        | 68 +++++++++++++++++++++-
 xdocs/changes.xml                                  |  1 +
 7 files changed, 180 insertions(+), 27 deletions(-)

diff --git a/src/components/src/main/java/org/apache/jmeter/visualizers/backend/SamplerMetric.java
b/src/components/src/main/java/org/apache/jmeter/visualizers/backend/SamplerMetric.java
index b41d41e..a279310 100644
--- a/src/components/src/main/java/org/apache/jmeter/visualizers/backend/SamplerMetric.java
+++ b/src/components/src/main/java/org/apache/jmeter/visualizers/backend/SamplerMetric.java
@@ -101,6 +101,23 @@ public class SamplerMetric {
      * @param result {@link SampleResult} to be used
      */
     public synchronized void add(SampleResult result) {
+        add(result, false);
+    }
+
+    /**
+     * Add a {@link SampleResult} and its sub-results to be used in the statistics
+     * @param result {@link SampleResult} to be used
+     */
+    public synchronized void addCumulated(SampleResult result) {
+        add(result, true);
+    }
+
+    /**
+     * Add a {@link SampleResult} to be used in the statistics
+     * @param result {@link SampleResult} to be used
+     * @param isCumulated is the overall Sampler Metric
+     */
+    private synchronized void add(SampleResult result, boolean isCumulated) {
         if(result.isSuccessful()) {
             successes+=result.getSampleCount()-result.getErrorCount();
         } else {
@@ -118,32 +135,40 @@ public class SamplerMetric {
         }else {
             koResponsesStats.addValue(time);
         }
-        addHits(result);
-        addNetworkData(result);
+        addHits(result, isCumulated);
+        addNetworkData(result, isCumulated);
     }
 
     /**
      * Increment traffic metrics. A Parent sampler cumulates its children metrics.
      * @param result SampleResult
+     * @param isCumulated related to the overall sampler metric
      */
-    private void addNetworkData(SampleResult result) {
-        if (!TransactionController.isFromTransactionController(result)) {
-            sentBytes += result.getSentBytes();
-            receivedBytes += result.getBytesAsLong();
+    private void addNetworkData(SampleResult result, boolean isCumulated) {
+        if (isCumulated && TransactionController.isFromTransactionController(result)
+                && result.getSubResults().length == 0) { // Transaction controller
without generate parent sampler
+            return;
         }
+        sentBytes += result.getSentBytes();
+        receivedBytes += result.getBytesAsLong();
     }
 
     /**
-     * Compute hits from res
-     * @param res {@link SampleResult}
+     * Compute hits from result
+     * @param result {@link SampleResult}
+     * @param isCumulated related to the overall sampler metric
      */
-    private void addHits(SampleResult res) {
-        SampleResult[] subResults = res.getSubResults();
-        if (!TransactionController.isFromTransactionController(res)) {
-            hits += 1;
+    private void addHits(SampleResult result, boolean isCumulated) {
+        SampleResult[] subResults = result.getSubResults();
+        if (isCumulated && TransactionController.isFromTransactionController(result)
+                && subResults.length == 0) { // Transaction controller without generate
parent sampler
+            return;
+        }
+        if (!(TransactionController.isFromTransactionController(result) && subResults.length
> 0)) {
+            hits += result.getSampleCount();
         }
         for (SampleResult subResult : subResults) {
-            addHits(subResult);
+            addHits(subResult, isCumulated);
         }
     }
 
diff --git a/src/components/src/main/java/org/apache/jmeter/visualizers/backend/graphite/GraphiteBackendListenerClient.java
b/src/components/src/main/java/org/apache/jmeter/visualizers/backend/graphite/GraphiteBackendListenerClient.java
index 50abbe0..16d8b4a 100644
--- a/src/components/src/main/java/org/apache/jmeter/visualizers/backend/graphite/GraphiteBackendListenerClient.java
+++ b/src/components/src/main/java/org/apache/jmeter/visualizers/backend/graphite/GraphiteBackendListenerClient.java
@@ -288,7 +288,7 @@ public class GraphiteBackendListenerClient extends AbstractBackendListenerClient
                         samplerMetric.add(sampleResult);
                     }
                 }
-                getSamplerMetric(CUMULATED_METRICS).add(sampleResult);
+                getSamplerMetric(CUMULATED_METRICS).addCumulated(sampleResult);
             }
         }
     }
diff --git a/src/components/src/main/java/org/apache/jmeter/visualizers/backend/influxdb/HttpMetricsSender.java
b/src/components/src/main/java/org/apache/jmeter/visualizers/backend/influxdb/HttpMetricsSender.java
index 0b6202e..a40c114 100644
--- a/src/components/src/main/java/org/apache/jmeter/visualizers/backend/influxdb/HttpMetricsSender.java
+++ b/src/components/src/main/java/org/apache/jmeter/visualizers/backend/influxdb/HttpMetricsSender.java
@@ -185,8 +185,9 @@ class HttpMetricsSender extends AbstractInfluxdbMetricsSender {
                         .append("000000")
                         .append("\n"); //$NON-NLS-1$
             }
-
-            httpRequest.setEntity(new StringEntity(sb.toString(), StandardCharsets.UTF_8));
+            String data = sb.toString();
+            log.debug("Sending to influxdb:{}", data);
+            httpRequest.setEntity(new StringEntity(data, StandardCharsets.UTF_8));
             lastRequest = httpClient.execute(httpRequest, new FutureCallback<HttpResponse>()
{
                 @Override
                 public void completed(final HttpResponse response) {
diff --git a/src/components/src/main/java/org/apache/jmeter/visualizers/backend/influxdb/InfluxdbBackendListenerClient.java
b/src/components/src/main/java/org/apache/jmeter/visualizers/backend/influxdb/InfluxdbBackendListenerClient.java
index 02c6dc1..0c61e97 100644
--- a/src/components/src/main/java/org/apache/jmeter/visualizers/backend/influxdb/InfluxdbBackendListenerClient.java
+++ b/src/components/src/main/java/org/apache/jmeter/visualizers/backend/influxdb/InfluxdbBackendListenerClient.java
@@ -177,15 +177,15 @@ public class InfluxdbBackendListenerClient extends AbstractBackendListenerClient
         // ALL
         addMetric(transaction, metric.getTotal(), metric.getSentBytes(), metric.getReceivedBytes(),
                 TAG_ALL, metric.getAllMean(), metric.getAllMinTime(),
-                metric.getAllMaxTime(), allPercentiles.values(), metric::getAllPercentile);
+                metric.getAllMaxTime(), metric.getHits(), allPercentiles.values(), metric::getAllPercentile);
         // OK
-        addMetric(transaction, metric.getSuccesses(), null, null,
+        addMetric(transaction, metric.getSuccesses(), metric.getSentBytes(), metric.getReceivedBytes(),
                 TAG_OK, metric.getOkMean(), metric.getOkMinTime(),
-                metric.getOkMaxTime(), okPercentiles.values(), metric::getOkPercentile);
+                metric.getOkMaxTime(), metric.getHits(), okPercentiles.values(), metric::getOkPercentile);
         // KO
-        addMetric(transaction, metric.getFailures(), null, null,
+        addMetric(transaction, metric.getFailures(), metric.getSentBytes(), metric.getReceivedBytes(),
                 TAG_KO, metric.getKoMean(), metric.getKoMinTime(),
-                metric.getKoMaxTime(), koPercentiles.values(), metric::getKoPercentile);
+                metric.getKoMaxTime(), metric.getHits(), koPercentiles.values(), metric::getKoPercentile);
 
         metric.getErrors().forEach((err, count) -> addErrorMetric(transaction, err, count));
     }
@@ -208,15 +208,16 @@ public class InfluxdbBackendListenerClient extends AbstractBackendListenerClient
 
     private void addMetric(String transaction, int count,
                            Long sentBytes, Long receivedBytes,
-                           String statut, double mean, double minTime, double maxTime,
+                           String status, double mean, double minTime, double maxTime,
+                           int hits,
                            Collection<Float> pcts, PercentileProvider percentileProvider)
{
         if (count <= 0) {
             return;
         }
         StringBuilder tag = new StringBuilder(95);
         tag.append(TAG_APPLICATION).append(applicationName);
-        tag.append(TAG_STATUS).append(statut);
         tag.append(TAG_TRANSACTION).append(transaction);
+        tag.append(TAG_STATUS).append(status);
         tag.append(userTag);
 
         StringBuilder field = new StringBuilder(80);
@@ -230,6 +231,7 @@ public class InfluxdbBackendListenerClient extends AbstractBackendListenerClient
         if (!Double.isNaN(maxTime)) {
             field.append(',').append(METRIC_MAX).append(maxTime);
         }
+        field.append(',').append(METRIC_HIT).append(hits);
         if (sentBytes != null) {
             field.append(',').append(METRIC_SENT_BYTES).append(sentBytes);
         }
@@ -301,7 +303,7 @@ public class InfluxdbBackendListenerClient extends AbstractBackendListenerClient
                     samplerMetric.add(sampleResult);
                 }
                 SamplerMetric cumulatedMetrics = getSamplerMetricInfluxdb(CUMULATED_METRICS);
-                cumulatedMetrics.add(sampleResult);
+                cumulatedMetrics.addCumulated(sampleResult);
             }
         }
     }
diff --git a/src/components/src/test/java/org/apache/jmeter/visualizers/backend/SamplerMetricFixedModeTest.java
b/src/components/src/test/java/org/apache/jmeter/visualizers/backend/SamplerMetricFixedModeTest.java
index 6f479f3..61ed8a0 100644
--- a/src/components/src/test/java/org/apache/jmeter/visualizers/backend/SamplerMetricFixedModeTest.java
+++ b/src/components/src/test/java/org/apache/jmeter/visualizers/backend/SamplerMetricFixedModeTest.java
@@ -19,6 +19,9 @@ package org.apache.jmeter.visualizers.backend;
 
 import static org.junit.Assert.assertEquals;
 
+import java.util.Arrays;
+
+import org.apache.jmeter.control.TransactionController;
 import org.apache.jmeter.samplers.SampleResult;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
@@ -103,4 +106,63 @@ public class SamplerMetricFixedModeTest {
         result.setResponseMessage(errorMessage);
         return result;
     }
+
+    private SampleResult createSampleResultWithSubresults(boolean success) {
+        SampleResult result = new SampleResult();
+        result.sampleStart();
+        result.setSampleCount(1);
+        result.setErrorCount(success ? 0 : 1);
+        result.setSuccessful(success);
+        result.addSubResult(createSampleResult(success));
+        result.addSubResult(createSampleResult(success));
+        result.setEndTime(Arrays.stream(result.getSubResults()).mapToLong(SampleResult::getEndTime).max().orElse(0));
+        result.setBytes(Arrays.stream(result.getSubResults()).mapToLong(SampleResult::getBytesAsLong).sum());
+        result.setSentBytes(Arrays.stream(result.getSubResults()).mapToLong(SampleResult::getSentBytes).sum());
+        result.setResponseMessage("Number of samples in transaction : "); // This is a constant
in TransactionController
+        return result;
+    }
+
+    @Test
+    public void checkAddCumulatedOk() throws Exception {
+        SamplerMetric metric = new SamplerMetric();
+        SampleResult sample = createSampleResultWithSubresults(true);
+        assertEquals("We are recognized as a TransactionController made sample", Boolean.TRUE,
+                Boolean.valueOf(TransactionController.isFromTransactionController(sample)));
+        metric.addCumulated(sample);
+        assertEquals("Before reset  ok.max", DEFAULT_ELAPSED_TIME, metric.getOkMaxTime(),
2.001);
+        assertEquals("Before reset all.max", DEFAULT_ELAPSED_TIME, metric.getAllMaxTime(),
2.001);
+        assertEquals("Before reset hits", 2, metric.getHits(), 0.0);
+        assertEquals("Before reset sent bytes", 2000, metric.getSentBytes(), 0.0);
+        assertEquals("Before reset received bytes", 4000, metric.getReceivedBytes(), 0.0);
+
+        metric.resetForTimeInterval();
+
+        assertEquals("After reset in TIMED mode ok.max", DEFAULT_ELAPSED_TIME, metric.getOkMaxTime(),
0.0);
+        assertEquals("After reset in TIMED mode all.max", DEFAULT_ELAPSED_TIME, metric.getAllMaxTime(),
0.0);
+        assertEquals("After reset hits", 0, metric.getHits(), 0.0);
+        assertEquals("After reset sent bytes", 0, metric.getSentBytes(), 0.0);
+        assertEquals("After reset received bytes", 0, metric.getReceivedBytes(), 0.0);
+    }
+
+    @Test
+    public void checkAddCumulatedKo() throws Exception {
+        SamplerMetric metric = new SamplerMetric();
+        SampleResult sample = createSampleResultWithSubresults(false);
+        assertEquals("We are recognized as a TransactionController made sample", Boolean.TRUE,
+                Boolean.valueOf(TransactionController.isFromTransactionController(sample)));
+        metric.addCumulated(sample);
+        assertEquals("Before reset  ko.max", DEFAULT_ELAPSED_TIME, metric.getKoMaxTime(),
2.001);
+        assertEquals("Before reset all.max", DEFAULT_ELAPSED_TIME, metric.getAllMaxTime(),
2.001);
+        assertEquals("Before reset failures", 1, metric.getFailures(), 0.0);
+        assertEquals("Before reset sent bytes", 2000, metric.getSentBytes(), 0.0);
+        assertEquals("Before reset received bytes", 4000, metric.getReceivedBytes(), 0.0);
+
+        metric.resetForTimeInterval();
+
+        assertEquals("After reset in TIMED mode ko.max", DEFAULT_ELAPSED_TIME, metric.getKoMaxTime(),
2.0);
+        assertEquals("After reset in TIMED mode all.max", DEFAULT_ELAPSED_TIME, metric.getAllMaxTime(),
2.0);
+        assertEquals("After reset failures", 0, metric.getFailures(), 0.0);
+        assertEquals("After reset sent bytes", 0, metric.getSentBytes(), 0.0);
+        assertEquals("After reset received bytes", 0, metric.getReceivedBytes(), 0.0);
+    }
 }
diff --git a/src/components/src/test/java/org/apache/jmeter/visualizers/backend/SamplerMetricTimedModeTest.java
b/src/components/src/test/java/org/apache/jmeter/visualizers/backend/SamplerMetricTimedModeTest.java
index 82ca45d..17a90a7 100644
--- a/src/components/src/test/java/org/apache/jmeter/visualizers/backend/SamplerMetricTimedModeTest.java
+++ b/src/components/src/test/java/org/apache/jmeter/visualizers/backend/SamplerMetricTimedModeTest.java
@@ -19,6 +19,9 @@ package org.apache.jmeter.visualizers.backend;
 
 import static org.junit.Assert.assertEquals;
 
+import java.util.Arrays;
+
+import org.apache.jmeter.control.TransactionController;
 import org.apache.jmeter.samplers.SampleResult;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
@@ -29,7 +32,7 @@ public class SamplerMetricTimedModeTest {
 
     @BeforeEach
     public void initMode() throws Exception {
-        //noinspection deprecation
+        // noinspection deprecation
         SamplerMetric.setDefaultWindowMode(WindowMode.TIMED);
     }
 
@@ -41,7 +44,7 @@ public class SamplerMetricTimedModeTest {
         metric.add(createSampleResult(true));
         assertEquals("Before reset  ok.max", DEFAULT_ELAPSED_TIME, metric.getOkMaxTime(),
0.001);
         assertEquals("Before reset all.max", DEFAULT_ELAPSED_TIME, metric.getAllMaxTime(),
0.001);
-        assertEquals("Before reset failure", 1, metric.getHits(), 0.0);
+        assertEquals("Before reset hits", 1, metric.getHits(), 0.0);
         assertEquals("Before reset sent bytes", 1000, metric.getSentBytes(), 0.0);
         assertEquals("Before reset received bytes", 2000, metric.getReceivedBytes(), 0.0);
 
@@ -49,7 +52,7 @@ public class SamplerMetricTimedModeTest {
 
         assertEquals("After reset in TIMED mode ok.max", Double.NaN, metric.getOkMaxTime(),
0.0);
         assertEquals("After reset in TIMED mode all.max", Double.NaN, metric.getAllMaxTime(),
0.0);
-        assertEquals("After reset failure", 0, metric.getHits(), 0.0);
+        assertEquals("After reset hits", 0, metric.getHits(), 0.0);
         assertEquals("After reset sent bytes", 0, metric.getSentBytes(), 0.0);
         assertEquals("After reset received bytes", 0, metric.getReceivedBytes(), 0.0);
     }
@@ -86,4 +89,63 @@ public class SamplerMetricTimedModeTest {
         return result;
     }
 
+    private SampleResult createSampleResultWithSubresults(boolean success) {
+        SampleResult result = new SampleResult();
+        result.sampleStart();
+        result.setSampleCount(1);
+        result.setErrorCount(success ? 0 : 1);
+        result.setSuccessful(success);
+        result.addSubResult(createSampleResult(success));
+        result.addSubResult(createSampleResult(success));
+        result.setEndTime(Arrays.stream(result.getSubResults()).mapToLong(SampleResult::getEndTime).max().orElse(0));
+        result.setBytes(Arrays.stream(result.getSubResults()).mapToLong(SampleResult::getBytesAsLong).sum());
+        result.setSentBytes(Arrays.stream(result.getSubResults()).mapToLong(SampleResult::getSentBytes).sum());
+        result.setResponseMessage("Number of samples in transaction : "); // This is a constant
in TransactionController
+        return result;
+    }
+
+    @Test
+    public void checkAddCumulatedOk() throws Exception {
+        SamplerMetric metric = new SamplerMetric();
+        SampleResult sample = createSampleResultWithSubresults(true);
+        assertEquals("We are recognized as a TransactionController made sample", Boolean.TRUE,
+                Boolean.valueOf(TransactionController.isFromTransactionController(sample)));
+        metric.addCumulated(sample);
+        assertEquals("Before reset  ok.max", DEFAULT_ELAPSED_TIME, metric.getOkMaxTime(),
2.001);
+        assertEquals("Before reset all.max", DEFAULT_ELAPSED_TIME, metric.getAllMaxTime(),
2.001);
+        assertEquals("Before reset hits", 2, metric.getHits(), 0.0);
+        assertEquals("Before reset sent bytes", 2000, metric.getSentBytes(), 0.0);
+        assertEquals("Before reset received bytes", 4000, metric.getReceivedBytes(), 0.0);
+
+        metric.resetForTimeInterval();
+
+        assertEquals("After reset in TIMED mode ok.max", Double.NaN, metric.getOkMaxTime(),
0.0);
+        assertEquals("After reset in TIMED mode all.max", Double.NaN, metric.getAllMaxTime(),
0.0);
+        assertEquals("After reset hits", 0, metric.getHits(), 0.0);
+        assertEquals("After reset sent bytes", 0, metric.getSentBytes(), 0.0);
+        assertEquals("After reset received bytes", 0, metric.getReceivedBytes(), 0.0);
+    }
+
+    @Test
+    public void checkAddCumulatedKo() throws Exception {
+        SamplerMetric metric = new SamplerMetric();
+        SampleResult sample = createSampleResultWithSubresults(false);
+        assertEquals("We are recognized as a TransactionController made sample", Boolean.TRUE,
+                Boolean.valueOf(TransactionController.isFromTransactionController(sample)));
+        metric.addCumulated(sample);
+        assertEquals("Before reset  ko.max", DEFAULT_ELAPSED_TIME, metric.getKoMaxTime(),
2.001);
+        assertEquals("Before reset all.max", DEFAULT_ELAPSED_TIME, metric.getAllMaxTime(),
2.001);
+        assertEquals("Before reset failures", 1, metric.getFailures(), 0.0);
+        assertEquals("Before reset sent bytes", 2000, metric.getSentBytes(), 0.0);
+        assertEquals("Before reset received bytes", 4000, metric.getReceivedBytes(), 0.0);
+
+        metric.resetForTimeInterval();
+
+        assertEquals("After reset in TIMED mode ko.max", Double.NaN, metric.getKoMaxTime(),
0.0);
+        assertEquals("After reset in TIMED mode all.max", Double.NaN, metric.getAllMaxTime(),
0.0);
+        assertEquals("After reset failures", 0, metric.getFailures(), 0.0);
+        assertEquals("After reset sent bytes", 0, metric.getSentBytes(), 0.0);
+        assertEquals("After reset received bytes", 0, metric.getReceivedBytes(), 0.0);
+    }
+
 }
diff --git a/xdocs/changes.xml b/xdocs/changes.xml
index 3445b9b..9e6ca2d 100644
--- a/xdocs/changes.xml
+++ b/xdocs/changes.xml
@@ -190,6 +190,7 @@ applications when JMeter is starting up.</p>
 <ul>
     <li><bug>64547</bug>Report/Dashboard: Ensure graphs Response codes
per second is not broken by empty response code in SampleResult. Contributed by Ubik Load
Pack (https://ubikloadpack.com)</li>
     <li><bug>64617</bug>HTML report: In graph Response Time Percentiles
Over Time 90,95,99th percentile correspond in reality to 0.90, 0.95 and 0.99 percentiles</li>
+    <li>64553<bug>When using Transaction Controller, send Bytes and Received
Bytes are displayed as 0 in the influxdb(BackendListener)</bug></li>
     <li><bug>64624</bug>Use less aggressive escaping for JSON Strings in
reports error messages</li>
 </ul>
 


Mime
View raw message