You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by mc...@apache.org on 2017/11/21 09:36:30 UTC

svn commit: r1815893 - in /jmeter/trunk: src/components/org/apache/jmeter/visualizers/backend/ src/components/org/apache/jmeter/visualizers/backend/influxdb/ xdocs/ xdocs/usermanual/

Author: mchassagneux
Date: Tue Nov 21 09:36:29 2017
New Revision: 1815893

URL: http://svn.apache.org/viewvc?rev=1815893&view=rev
Log:
[Influxdb] Allow users to add theirs owns tags
Bugzilla Id: 61794

Modified:
    jmeter/trunk/src/components/org/apache/jmeter/visualizers/backend/BackendListenerGui.java
    jmeter/trunk/src/components/org/apache/jmeter/visualizers/backend/influxdb/InfluxdbBackendListenerClient.java
    jmeter/trunk/xdocs/changes.xml
    jmeter/trunk/xdocs/usermanual/component_reference.xml

Modified: jmeter/trunk/src/components/org/apache/jmeter/visualizers/backend/BackendListenerGui.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/visualizers/backend/BackendListenerGui.java?rev=1815893&r1=1815892&r2=1815893&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/visualizers/backend/BackendListenerGui.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/visualizers/backend/BackendListenerGui.java Tue Nov 21 09:36:29 2017
@@ -22,6 +22,7 @@ import java.awt.BorderLayout;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
@@ -71,6 +72,10 @@ public class BackendListenerGui extends
 
     /** A panel allowing the user to set arguments for this test. */
     private ArgumentsPanel argsPanel;
+    
+    /** The current className of the Backend listenenr **/
+    private String className;
+    
 
     /**
      * Create a new BackendListenerGui as a standalone component.
@@ -101,6 +106,7 @@ public class BackendListenerGui extends
         classnameRequestPanel.add(createParameterPanel(), BorderLayout.CENTER);
 
         add(classnameRequestPanel, BorderLayout.CENTER);
+        className = ((String) classnameCombo.getSelectedItem()).trim();
     }
 
     /**
@@ -161,27 +167,36 @@ public class BackendListenerGui extends
     @Override
     public void actionPerformed(ActionEvent event) {
         if (event.getSource() == classnameCombo) {
-            String className = ((String) classnameCombo.getSelectedItem()).trim();
+           
+            String newClassName = ((String) classnameCombo.getSelectedItem()).trim();
             try {
-                BackendListenerClient client = (BackendListenerClient) Class.forName(className, true,
+                BackendListenerClient client = (BackendListenerClient) Class.forName(newClassName, true,
                         Thread.currentThread().getContextClassLoader()).newInstance();
-
+                BackendListenerClient oldClient = (BackendListenerClient) Class.forName(className, true,
+                        Thread.currentThread().getContextClassLoader()).newInstance();
+                
                 Arguments currArgs = new Arguments();
                 argsPanel.modifyTestElement(currArgs);
                 Map<String, String> currArgsMap = currArgs.getArgumentsAsMap();
-
+                Arguments currentUserArgs = new Arguments();
+                
+                Map<String, String> userArgMap = new HashMap<>();
+                userArgMap.putAll(currArgsMap);
                 Arguments newArgs = new Arguments();
-                Arguments testParams = null;
+                Arguments defaultArgs = null;
                 try {
-                    testParams = client.getDefaultParameters();
+                    defaultArgs = client.getDefaultParameters();    
+                    currentUserArgs = oldClient.getDefaultParameters();
                 } catch (AbstractMethodError e) {
                     log.warn("BackendListenerClient doesn't implement "
                             + "getDefaultParameters.  Default parameters won't "
-                            + "be shown.  Please update your client class: {}", className);
+                            + "be shown.  Please update your client class: {}", newClassName);
                 }
-
-                if (testParams != null) {
-                    for (JMeterProperty jMeterProperty : testParams.getArguments()) {
+                userArgMap.keySet().removeAll(currentUserArgs.getArgumentsAsMap().keySet() );
+                
+                
+                if (defaultArgs != null) {
+                    for (JMeterProperty jMeterProperty : defaultArgs.getArguments()) {
                         Argument arg = (Argument) jMeterProperty.getObjectValue();
                         String name = arg.getName();
                         String value = arg.getValue();
@@ -199,10 +214,14 @@ public class BackendListenerGui extends
                         newArgs.addArgument(name, value);
                     }
                 }
-
+                userArgMap.forEach((k,v) -> {
+                    newArgs.addArgument(k, v);
+                });
+                
+                className = newClassName;
                 argsPanel.configure(newArgs);
             } catch (Exception e) {
-                log.error("Error getting argument list for {}", className, e);
+                log.error("Error getting argument list for {}", newClassName, e);
             }
         }
     }
@@ -225,7 +244,7 @@ public class BackendListenerGui extends
 
         argsPanel.configure((Arguments) config.getProperty(BackendListener.ARGUMENTS).getObjectValue());
 
-        String className = config.getPropertyAsString(BackendListener.CLASSNAME);
+        className = config.getPropertyAsString(BackendListener.CLASSNAME);
         if(checkContainsClassName(classnameCombo.getModel(), className)) {
             classnameCombo.setSelectedItem(className);
         } else {

Modified: jmeter/trunk/src/components/org/apache/jmeter/visualizers/backend/influxdb/InfluxdbBackendListenerClient.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/visualizers/backend/influxdb/InfluxdbBackendListenerClient.java?rev=1815893&r1=1815892&r2=1815893&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/visualizers/backend/influxdb/InfluxdbBackendListenerClient.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/visualizers/backend/influxdb/InfluxdbBackendListenerClient.java Tue Nov 21 09:36:29 2017
@@ -21,6 +21,7 @@ package org.apache.jmeter.visualizers.ba
 import java.text.DecimalFormat;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
@@ -92,6 +93,18 @@ public class InfluxdbBackendListenerClie
     private static final int MAX_POOL_SIZE = 1;
     private static final String SEPARATOR = ";"; //$NON-NLS-1$
     private static final Object LOCK = new Object();
+    private static Map<String, String> DEFAULT_ARGS = new LinkedHashMap<>();
+    static {
+        DEFAULT_ARGS.put("influxdbMetricsSender", HttpMetricsSender.class.getName());
+        DEFAULT_ARGS.put("influxdbUrl", "");
+        DEFAULT_ARGS.put("application", "application name");
+        DEFAULT_ARGS.put("measurement", DEFAULT_MEASUREMENT);
+        DEFAULT_ARGS.put("summaryOnly", "false");
+        DEFAULT_ARGS.put("samplersRegex", ".*");
+        DEFAULT_ARGS.put("percentiles", "99;95;90");
+        DEFAULT_ARGS.put("testTitle", "Test name");
+        DEFAULT_ARGS.put("eventTags", "");
+    }
 
     private boolean summaryOnly;
     private String measurement = "DEFAULT_MEASUREMENT";
@@ -105,7 +118,7 @@ public class InfluxdbBackendListenerClie
     private String testTags;
     // Name of the application tested
     private String application = "";
-
+    private String tag_user = "";
     private InfluxdbMetricsSender influxdbMetricsManager;
 
     private ScheduledExecutorService scheduler;
@@ -187,6 +200,7 @@ public class InfluxdbBackendListenerClie
             tag.append(TAG_TRANSACTION).append(transaction);
             tag.append(TAG_RESPONSE_CODE).append(AbstractInfluxdbMetricsSender.tagToStringValue(responseCode));
             tag.append(TAG_RESPONSE_MESSAGE).append(AbstractInfluxdbMetricsSender.tagToStringValue(responseMessage));
+            tag.append(tag_user);
 
             StringBuilder field = new StringBuilder(30);
             field.append(METRIC_COUNT).append(count);
@@ -202,6 +216,8 @@ public class InfluxdbBackendListenerClie
             tag.append(TAG_APPLICATION).append(application);
             tag.append(TAG_STATUS).append(statut);
             tag.append(TAG_TRANSACTION).append(transaction);
+            tag.append(tag_user);
+
             StringBuilder field = new StringBuilder(80);
             field.append(METRIC_COUNT).append(count);
             if (!Double.isNaN(mean)) {
@@ -230,7 +246,8 @@ public class InfluxdbBackendListenerClie
             tag.append(TAG_APPLICATION).append(application);
             tag.append(TAG_TRANSACTION).append(CUMULATED_METRICS);
             tag.append(TAG_STATUS).append(CUMULATED_METRICS);
-            
+            tag.append(tag_user);
+
             field.append(METRIC_COUNT).append(total);
             field.append(",").append(METRIC_COUNT_ERROR).append(metric.getFailures());
 
@@ -318,6 +335,18 @@ public class InfluxdbBackendListenerClie
                 }
             }
         }
+        // Check if more row which started with 'TAG_' are filled ( corresponding to user tag )
+        tag_user = "";
+        context.getParameterNamesIterator().forEachRemaining(name -> {
+            if (StringUtils.isNotBlank(name) && !DEFAULT_ARGS.containsKey(name.trim())
+                    && name.startsWith("TAG_")
+                    && StringUtils.isNotBlank(context.getParameter(name))) {
+                tag_user += "," + AbstractInfluxdbMetricsSender.tagToStringValue(name.trim().substring(4)) + "="
+                        + AbstractInfluxdbMetricsSender.tagToStringValue(context.getParameter(name).trim());
+                log.debug("Adding '{}' tag with '{}' value ", name.trim().substring(4), context.getParameter(name).trim());
+            }
+        });
+
         Class<?> clazz = Class.forName(influxdbMetricsSender);
         this.influxdbMetricsManager = (InfluxdbMetricsSender) clazz.newInstance();
         influxdbMetricsManager.setup(influxdbUrl);
@@ -389,15 +418,9 @@ public class InfluxdbBackendListenerClie
     @Override
     public Arguments getDefaultParameters() {
         Arguments arguments = new Arguments();
-        arguments.addArgument("influxdbMetricsSender", HttpMetricsSender.class.getName());
-        arguments.addArgument("influxdbUrl", "");
-        arguments.addArgument("application", "application name");
-        arguments.addArgument("measurement", DEFAULT_MEASUREMENT);
-        arguments.addArgument("summaryOnly", "false");
-        arguments.addArgument("samplersRegex", ".*");
-        arguments.addArgument("percentiles", "99,95,90");
-        arguments.addArgument("testTitle", "Test name");
-        arguments.addArgument("eventTags", "");
+        DEFAULT_ARGS.forEach((k, v) -> {
+            arguments.addArgument(k, v);
+        });
         return arguments;
     }
 }

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1815893&r1=1815892&r2=1815893&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Tue Nov 21 09:36:29 2017
@@ -116,6 +116,7 @@ Summary
     <li><bug>57760</bug>View Results Tree : Cookie Header is wrongly shown as empty(no cookies) when viewing a recorder Sample Result. Contributed by Ubik Load Pack (support at ubikloadpack.com)</li>
     <li><bug>61769</bug>View Results Tree: Use syntax highlighter in XPath Tester, JSON Path Tester and CSS/JQuery Tester. Contributed by Ubik Load Pack (support at ubikloadpack.com)</li>
     <li><bug>61776</bug>View Results Tree: Expansion of <code>Add expand/collapse all</code> menu in render XML view. Contributed by Maxime Chassagneux and Graham Russell</li>
+    <li><bug>61794</bug>Influxdb backend : Add as many custom tags as wanted by just create new lines and prefix theirs name by "TAG_" on the GUI backend listener</li>
 </ul>
 
 <h3>Timers, Assertions, Config, Pre- &amp; Post-Processors</h3>

Modified: jmeter/trunk/xdocs/usermanual/component_reference.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/usermanual/component_reference.xml?rev=1815893&r1=1815892&r2=1815893&view=diff
==============================================================================
--- jmeter/trunk/xdocs/usermanual/component_reference.xml (original)
+++ jmeter/trunk/xdocs/usermanual/component_reference.xml Tue Nov 21 09:36:29 2017
@@ -3489,22 +3489,23 @@ By default, a Graphite implementation is
     <figure width="1265" height="581" image="grafana_dashboard.png">Grafana dashboard</figure>
     
     
-    <p>Since JMeter 3.2, a new implementation (in Beta state) has been added that allows writing directly in InfluxDB with a custom schema, it is called <code>InfluxdbBackendListenerClient</code> 
+    <p>Since JMeter 3.2, a new implementation has been added that allows writing directly in InfluxDB with a custom schema, it is called <code>InfluxdbBackendListenerClient</code> 
       The following parameters apply to the <a href="../api/org/apache/jmeter/visualizers/backend/influxdb/InfluxdbBackendListenerClient.html">InfluxdbBackendListenerClient</a> implementation:</p>
 
     <properties>
         <property name="influxdbMetricsSender" required="Yes"><code>org.apache.jmeter.visualizers.backend.influxdb.HttpMetricsSender</code></property>
         <property name="influxdbUrl" required="Yes">Influx URL (example : http://influxHost:8086/write?db=jmeter)</property>
-        <property name="application" required="Yes">Name of tested application. This value is stored in the 'events' measurement as a tag named 'application' </property>
+        <property name="application" required="Yes">Name of tested application. This value is stored in the 'events' measurement too as a tag named 'application' </property>
         <property name="measurement" required="Yes">Measurement as per <a href="https://docs.influxdata.com/influxdb/v1.1/write_protocols/line_protocol_reference/">Influx Line Protocol Reference</a>. Defaults to "<code>jmeter</code>."</property>
         <property name="summaryOnly" required="Yes">Only send a summary with no detail. Defaults to <code>true</code>.</property>
         <property name="samplersRegex" required="Yes">Regular expression which will be matched against the names of samples and sent to the back end.</property>
         <property name="testTitle" required="Yes">Test name. Defaults to <code>Test name</code>. This value is stored in the 'events' measurement as a field named 'text'. JMeter generate automatically at the start and the end of the test an annotation with this value ending with ' started' and ' ended'</property>
-        <property name="eventTags" required="No">List of tags. This value is stored in the 'events' measurement as a tag named 'tags'.</property>
+        <property name="eventTags" required="No">Grafana allow to display tag for each annotation. You can fill them here. This value is stored in the 'events' measurement as a tag named 'tags'.</property>
         <property name="percentiles" required="Yes">The percentiles you want to send to the backend.
         A percentile may contain a fractional part, for example <code>12.5</code>.
         (The separator is always ".")
         List must be semicolon separated. Generally 3 or 4 values should be sufficient.</property>
+        <property name="TAG_WhatEverYouWant" required="No">You can add as many custom tags as you want. For each of them, just create a new line and prefix its name by "TAG_"</property>
     </properties>
     <p>See also <a href="realtime-results.html" >Real-time results</a> and <a href="http://docs.grafana.org/reference/annotations/#influxdb-annotations">Influxdb annotations in Grafana</a> for more details.</p>     
 </component>