Skip to content

Commit

Permalink
Added the ability to set the required percentiles for InfluxDb (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndanilin authored Jan 17, 2024
1 parent 03f2385 commit e5cb479
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package us.abstracta.jmeter.javadsl.core.listeners;

import static java.util.stream.Collectors.joining;
import static java.util.stream.IntStream.range;

import java.lang.reflect.Method;
import java.time.Instant;
import java.util.HashMap;
Expand All @@ -24,13 +27,15 @@ public class InfluxDbBackendListener extends DslBackendListener<InfluxDbBackendL
private static final String TOKEN_ARG = "influxdbToken";
private static final String SAMPLERS_REGEX_ARG = "samplersRegex";
private static final String TAG_ARGS_PREFIX = "TAG_";
private static final String PCT_ARG = "percentiles";

protected String title = "Test jmeter-java-dsl " + Instant.now().toString();
protected String token;
protected final Map<String, String> tags = new HashMap<>();
protected String samplersRegex;
protected String measurement;
protected String applicationName;
protected String percentiles;

public InfluxDbBackendListener(String url) {
super(InfluxdbBackendListenerClient.class, url);
Expand Down Expand Up @@ -125,6 +130,19 @@ public InfluxDbBackendListener tag(String name, String value) {
return this;
}

/**
* Allows specifying a list of percentiles that will be calculated and sent to InfluxDb.
*
* @param percentiles specifies a list of percentiles as float values.
* @return the listener for further configuration or usage.
*/
public InfluxDbBackendListener percentiles(float... percentiles) {
this.percentiles = range(0, percentiles.length)
.mapToObj(i -> Float.toString(percentiles[i]))
.collect(joining(";"));
return this;
}

@Override
protected Arguments buildListenerArguments() {
Arguments ret = new Arguments();
Expand All @@ -143,6 +161,9 @@ protected Arguments buildListenerArguments() {
if (samplersRegex != null) {
ret.addArgument(SAMPLERS_REGEX_ARG, samplersRegex);
}
if (percentiles != null) {
ret.addArgument(PCT_ARG, percentiles);
}
tags.forEach((name, value) -> ret.addArgument(TAG_ARGS_PREFIX + name, value));
return ret;
}
Expand All @@ -160,7 +181,8 @@ protected MethodCall buildBackendListenerCall(Map<String, String> args,
.chain("title", buildArgParam(TITLE_ARG, args, defaultValues))
.chain("application", buildArgParam(APPLICATION_ARG, args, defaultValues))
.chain("measurement", buildArgParam(MEASUREMENT_ARG, args, defaultValues))
.chain("samplersRegex", buildArgParam(SAMPLERS_REGEX_ARG, args, defaultValues));
.chain("samplersRegex", buildArgParam(SAMPLERS_REGEX_ARG, args, defaultValues))
.chain("percentiles", buildArgParam(PCT_ARG, args, defaultValues));
args.entrySet().stream()
.filter(e -> e.getKey().startsWith(TAG_ARGS_PREFIX))
.forEach(
Expand Down

0 comments on commit e5cb479

Please sign in to comment.