Skip to content

Commit

Permalink
Thread group label (#123)
Browse files Browse the repository at this point in the history
Prometheus Listener now supports value 'threadGroup' in the Labels column.
Updated some dependencies.

Co-authored-by: John Walker <jwalker@taxhawk.com>
  • Loading branch information
johndwalker and John Walker committed Jul 29, 2023
1 parent 70b3893 commit 6022eef
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
21 changes: 19 additions & 2 deletions pom.xml
Expand Up @@ -9,7 +9,7 @@

<properties>
<prometheus.version>0.6.0</prometheus.version>
<jmeter.version>5.1.1</jmeter.version>
<jmeter.version>5.5</jmeter.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -77,6 +77,23 @@
<version>${jmeter.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.jmeter/ApacheJMeter_components -->
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter_components</artifactId>
<version>${jmeter.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.7</version>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient</artifactId>
Expand Down Expand Up @@ -124,7 +141,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<version>3.1.0</version>
<configuration>
<parallel>methods</parallel>
<threadCount>4</threadCount>
Expand Down
Expand Up @@ -73,24 +73,26 @@ protected String[] labelValues(SampleEvent event) {
String[] values = new String[labels.length];
JMeterVariables vars = JMeterContextService.getContext().getVariables();

for(int i = 0; i < labels.length; i++) {
for (int i = 0; i < labels.length; i++) {
String name = labels[i];
String value = null;

// reserved keyword for the sampler's label (the name)
if(name.equalsIgnoreCase("label")) {
if (name.equalsIgnoreCase("label")) {
value = event.getResult().getSampleLabel();

} else if(name.equalsIgnoreCase("code")) { // code also reserved
} else if (name.equalsIgnoreCase("code")) {
// code also reserved
value = event.getResult().getResponseCode();
} else if (name.equalsIgnoreCase("threadGroup")) {
value = event.getThreadGroup();

// try to find it as a plain'ol variable.
} else if (this.varIndexLookup.get(name) != null){
} else if (this.varIndexLookup.get(name) != null) {
int idx = this.varIndexLookup.get(name);
value = event.getVarValue(idx);

// lastly look in sample_variables
}else if (vars != null){
} else if (vars != null) {
value = vars.get(name);
}

Expand Down

0 comments on commit 6022eef

Please sign in to comment.