vlsi commented on code in PR #5869:
URL: https://github.com/apache/jmeter/pull/5869#discussion_r1186134805


##########
src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/DefaultSamplerCreator.java:
##########
@@ -359,18 +361,42 @@ protected void computeSamplerName(HTTPSamplerBase sampler,
         String prefix = StringUtils.defaultString(request.getPrefix(), "");
         int httpSampleNameMode = request.getHttpSampleNameMode();
         String format = getFormat(httpSampleNameMode, 
request.getHttpSampleNameFormat());
+        String url = null;
+        try {
+            url = sampler.getUrl().toString();
+        } catch (MalformedURLException e) {
+            url = "MALFORMED-URL";
+            log.warn("Could not get URL to name sample", e);
+        }
+        List<Object> values = Arrays.asList(
+                prefix,
+                sampler.getPath(),
+                sampler.getMethod(),
+                sampler.getDomain(),
+                sampler.getProtocol(),
+                sampler.getPort(),
+                url
+        );
+        Object[] valuesArray;
         if (!HTTPConstants.CONNECT.equals(request.getMethod()) && 
isNumberRequests()) {
-            sampler.setName(MessageFormat.format(format, prefix, 
sampler.getPath(), incrementRequestNumberAndGet()));
+            valuesArray = values.toArray(new Object[values.size() + 1]);
+            valuesArray[values.size()] = incrementRequestNumberAndGet();
         } else {
-            sampler.setName(MessageFormat.format(format, prefix, 
sampler.getPath()));
+            valuesArray = values.toArray();
         }
+        sampler.setName(MessageFormat.format(format,valuesArray));
     }
 
     private String getFormat(int httpSampleNameMode, String format) {
         if (httpSampleNameMode == SAMPLER_NAME_NAMING_MODE_FORMATTER) {
             return format.replaceAll("#\\{name([,}])", "{0$1")
                     .replaceAll("#\\{path([,}])", "{1$1")
-                    .replaceAll("#\\{counter([,}])", "{2$1");
+                    .replaceAll("#\\{method([,}])", "{2$1")
+                    .replaceAll("#\\{host([,}])", "{3$1")
+                    .replaceAll("#\\{scheme([,}])", "{4$1")
+                    .replaceAll("#\\{port([,}])", "{5$1")
+                    .replaceAll("#\\{url([,}])", "{6$1")
+                    .replaceAll("#\\{counter([,}])", "{7$1");

Review Comment:
   In theory, users might have used `{2}` in their scripts for "counter", and 
if we move counter to `{7}` that would break their scripts.
   
   I wonder if we can keep `#{counter}` at position `{2}` even thought that was 
not properly documented.



##########
src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/DefaultSamplerCreator.java:
##########
@@ -359,18 +361,42 @@ protected void computeSamplerName(HTTPSamplerBase sampler,
         String prefix = StringUtils.defaultString(request.getPrefix(), "");
         int httpSampleNameMode = request.getHttpSampleNameMode();
         String format = getFormat(httpSampleNameMode, 
request.getHttpSampleNameFormat());
+        String url = null;
+        try {
+            url = sampler.getUrl().toString();
+        } catch (MalformedURLException e) {
+            url = "MALFORMED-URL";
+            log.warn("Could not get URL to name sample", e);
+        }
+        List<Object> values = Arrays.asList(
+                prefix,
+                sampler.getPath(),
+                sampler.getMethod(),
+                sampler.getDomain(),
+                sampler.getProtocol(),
+                sampler.getPort(),
+                url
+        );
+        Object[] valuesArray;
         if (!HTTPConstants.CONNECT.equals(request.getMethod()) && 
isNumberRequests()) {
-            sampler.setName(MessageFormat.format(format, prefix, 
sampler.getPath(), incrementRequestNumberAndGet()));
+            valuesArray = values.toArray(new Object[values.size() + 1]);
+            valuesArray[values.size()] = incrementRequestNumberAndGet();
         } else {
-            sampler.setName(MessageFormat.format(format, prefix, 
sampler.getPath()));
+            valuesArray = values.toArray();
         }
+        sampler.setName(MessageFormat.format(format,valuesArray));
     }
 
     private String getFormat(int httpSampleNameMode, String format) {
         if (httpSampleNameMode == SAMPLER_NAME_NAMING_MODE_FORMATTER) {
             return format.replaceAll("#\\{name([,}])", "{0$1")
                     .replaceAll("#\\{path([,}])", "{1$1")
-                    .replaceAll("#\\{counter([,}])", "{2$1");
+                    .replaceAll("#\\{method([,}])", "{2$1")
+                    .replaceAll("#\\{host([,}])", "{3$1")
+                    .replaceAll("#\\{scheme([,}])", "{4$1")
+                    .replaceAll("#\\{port([,}])", "{5$1")
+                    .replaceAll("#\\{url([,}])", "{6$1")
+                    .replaceAll("#\\{counter([,}])", "{7$1");

Review Comment:
   In theory, users might have used `{2}` in their scripts for "counter", and 
if we move counter to `{7}` that would break their scripts.
   
   I wonder if we can keep `#{counter}` at position `{2}` even though that was 
not properly documented.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@jmeter.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to