Add more variables to template to compute sampler names#5869
Add more variables to template to compute sampler names#5869vlsi merged 1 commit intoapache:masterfrom
Conversation
4bf162b to
942f14d
Compare
| 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(); |
There was a problem hiding this comment.
I just wonder: is there a real reason to allow "request number" only in case the method is not CONNECT?
What if we always supply the "request number", and we increase "request number" only in case the method matches?
The dance with toArray[size+1] looks strange.
There was a problem hiding this comment.
To answer your first request (not really), I have no idea, I guess, it was to filter out proxy requests.
About your second concern. I wanted to get around using a full blown ArrayList, but it is probably better to go for readability and use it anyway.
| .replaceAll("#\\{method([,}])", "{2$1") | ||
| .replaceAll("#\\{host([,}])", "{3$1") | ||
| .replaceAll("#\\{scheme([,}])", "{4$1") | ||
| .replaceAll("#\\{port([,}])", "{5$1") | ||
| .replaceAll("#\\{url([,}])", "{6$1") | ||
| .replaceAll("#\\{counter([,}])", "{7$1"); |
There was a problem hiding this 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.
There was a problem hiding this comment.
Yes, that would be a nicer option, but I didn't find a way to enable that easily, so I opted to implicitly say: it was never documented and merely an implementation detail.
There was a problem hiding this comment.
How about making a first round of replaces that replaces all {[0-9]+} with their escaped representations?
In other words, let's keep {0} literal since that might be something the user wants to have in the sample name.
A yet another option is to escape all { characters to avoid MessageFormat failures.
There was a problem hiding this comment.
You mean, if the user sets the format string to #{counter} => {0} and expects JMeter to not touch the {0}?
We had no reports into that direction, so I think the chances are low, it is a problem for many people.
There was a problem hiding this comment.
expects JMeter to not touch the {0}?
That is right. I expect if we expose only #{...}, then we should avoid touching things like {0}.
|
TL;DR: adding new language constructs to existing languages is not easy. We should refrain from extending existing languages. MessageFormat.format("Hello {")yields
So we should either declare that the format uses If we go with That means we must not blindly replace |
|
The documentation did mention MessageFormat which implies I would like to move forward here, however, it is sad that we expose unintended placeholders |
|
@FSchumacher , are you goring to merge this? Do you think it is mergeable? |
The new variables are * method - HTTP method of the request * host - host of the URL recorded (called domain in the sampler) * scheme - scheme of the URL recorded (called protocol in the sampler) * port - port of the URL recorded * url - URL as recorded Issue apache#5820 Co-authored-by: Alex Schwartz <alexschwartz01@gmail.com> Guard message formats that might have been given by user As Vladimir pointed out, we might have users, that construct a format string with a part, that might be interpreted by MessageFormat. So let us guard those. asdf
d61b0ec to
ae8c1ec
Compare
|
What do you mean by |
|
I added your name via WDYT? |
Description
Add more variables to the mini template language to name samplers when recording a test via HTTPS Script recorder
The new variables are
Motivation and Context
In Issue #5820 a user asked to provide more variables, specifically the
url.How Has This Been Tested?
Added a unit test
Types of changes
Checklist: