jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject [jmeter] 01/01: 64553 When using Transaction Controller, send Bytes and Received Bytes are displayed as 0 in the influxdb(BackendListener)
Date Thu, 06 Aug 2020 06:28:39 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit 847a9cecd1f426106b9b5c6d8d13601ca2a202ad
Author: pmouawad <p.mouawad@ubik-ingenierie.com>
AuthorDate: Thu Aug 6 08:28:13 2020 +0200

    64553 When using Transaction Controller, send Bytes and Received Bytes
    are displayed as 0 in the influxdb(BackendListener)
---
 .../jmeter/visualizers/backend/SamplerMetric.java  | 37 ++++++++++++++--------
 .../graphite/GraphiteBackendListenerClient.java    |  4 +--
 .../backend/influxdb/HttpMetricsSender.java        |  5 +--
 .../influxdb/InfluxdbBackendListenerClient.java    | 18 ++++++-----
 .../backend/SamplerMetricFixedModeTest.java        | 10 +++---
 .../backend/SamplerMetricTimedModeTest.java        |  4 +--
 xdocs/changes.xml                                  |  1 +
 7 files changed, 46 insertions(+), 33 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..e6ad2f0 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
@@ -99,8 +99,9 @@ public class SamplerMetric {
     /**
      * Add a {@link SampleResult} to be used in the statistics
      * @param result {@link SampleResult} to be used
+     * @param isCumulated is the overall Sampler Metric
      */
-    public synchronized void add(SampleResult result) {
+    public synchronized void add(SampleResult result, boolean isCumulated) {
         if(result.isSuccessful()) {
             successes+=result.getSampleCount()-result.getErrorCount();
         } else {
@@ -118,32 +119,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) {
+        if (isCumulated && TransactionController.isFromTransactionController(result)
+                && result.getSubResults().length == 0) { // Transaction controller
without generate parent sampler
+            return;
+        }
+        SampleResult[] subResults = result.getSubResults();
+        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..f6bb597 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
@@ -285,10 +285,10 @@ public class GraphiteBackendListenerClient extends AbstractBackendListenerClient
                     }
                     if (samplersToFilterMatch) {
                         SamplerMetric samplerMetric = getSamplerMetric(sampleResult.getSampleLabel());
-                        samplerMetric.add(sampleResult);
+                        samplerMetric.add(sampleResult, false);
                     }
                 }
-                getSamplerMetric(CUMULATED_METRICS).add(sampleResult);
+                getSamplerMetric(CUMULATED_METRICS).add(sampleResult, true);
             }
         }
     }
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..3651c48 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));
     }
@@ -209,14 +209,15 @@ public class InfluxdbBackendListenerClient extends AbstractBackendListenerClient
     private void addMetric(String transaction, int count,
                            Long sentBytes, Long receivedBytes,
                            String statut, 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(statut);
         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);
         }
@@ -298,10 +300,10 @@ public class InfluxdbBackendListenerClient extends AbstractBackendListenerClient
                 Matcher matcher = samplersToFilter.matcher(sampleResult.getSampleLabel());
                 if (!summaryOnly && (matcher.find())) {
                     SamplerMetric samplerMetric = getSamplerMetricInfluxdb(sampleResult.getSampleLabel());
-                    samplerMetric.add(sampleResult);
+                    samplerMetric.add(sampleResult, false);
                 }
                 SamplerMetric cumulatedMetrics = getSamplerMetricInfluxdb(CUMULATED_METRICS);
-                cumulatedMetrics.add(sampleResult);
+                cumulatedMetrics.add(sampleResult, true);
             }
         }
     }
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..0c25028 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
@@ -36,7 +36,7 @@ public class SamplerMetricFixedModeTest {
     @Test
     public void checkResetOkAndAllStats() throws Exception {
         SamplerMetric metric = new SamplerMetric();
-        metric.add(createSampleResult(true));
+        metric.add(createSampleResult(true), false);
         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);
@@ -56,7 +56,7 @@ public class SamplerMetricFixedModeTest {
     @Test
     public void checkResetKoAndAllStats() throws Exception {
         SamplerMetric metric = new SamplerMetric();
-        metric.add(createSampleResult(false));
+        metric.add(createSampleResult(false), false);
         assertEquals("Before reset  ko.max", DEFAULT_ELAPSED_TIME, metric.getKoMaxTime(),
0.001);
         assertEquals("Before reset all.max", DEFAULT_ELAPSED_TIME, metric.getAllMaxTime(),
0.001);
         assertEquals("Before reset failure", 1, metric.getFailures(), 0.0);
@@ -76,9 +76,9 @@ public class SamplerMetricFixedModeTest {
     @Test
     public void checkErrorsDetailStat() {
         SamplerMetric metric = new SamplerMetric();
-        metric.add(createSampleResult("400", "bad request"));
-        metric.add(createSampleResult("400", "Bad Request "));
-        metric.add(createSampleResult("500", "Internal Server Error"));
+        metric.add(createSampleResult("400", "bad request"), false);
+        metric.add(createSampleResult("400", "Bad Request "), false);
+        metric.add(createSampleResult("500", "Internal Server Error"), false);
         ErrorMetric error = new ErrorMetric(createSampleResult("400", "Bad request"));
         assertEquals("Count for '400 - bad request' error ", 2, metric.getErrors().get(error),
0.0);
         error = new ErrorMetric(createSampleResult("500", "Internal Server Error"));
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..ac4573f 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
@@ -38,7 +38,7 @@ public class SamplerMetricTimedModeTest {
 
         SamplerMetric metric = new SamplerMetric();
 
-        metric.add(createSampleResult(true));
+        metric.add(createSampleResult(true), false);
         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);
@@ -58,7 +58,7 @@ public class SamplerMetricTimedModeTest {
     public void checkResetKoAndAllStats() throws Exception {
 
         SamplerMetric metric = new SamplerMetric();
-        metric.add(createSampleResult(false));
+        metric.add(createSampleResult(false), false);
         assertEquals("Before reset  ko.max", DEFAULT_ELAPSED_TIME, metric.getKoMaxTime(),
0.001);
         assertEquals("Before reset all.max", DEFAULT_ELAPSED_TIME, metric.getAllMaxTime(),
0.001);
         assertEquals("Before reset failure", 1, metric.getFailures(), 0.0);
diff --git a/xdocs/changes.xml b/xdocs/changes.xml
index 6d13466..d037c26 100644
--- a/xdocs/changes.xml
+++ b/xdocs/changes.xml
@@ -166,6 +166,7 @@ Summary
 <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>
 </ul>
 
 <h3>Documentation</h3>


Mime
View raw message