Skip to content

Commit 19bd018

Browse files
AlucardleVashAlucardleVash
andauthored
feat: add error threshold as config (#48)
Co-authored-by: AlucardleVash <[email protected]>
1 parent 52f9023 commit 19bd018

File tree

6 files changed

+45
-3
lines changed

6 files changed

+45
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ Let’s explain the plugin fields:
118118
* `influxDBToken` - the influxdb bucket token, the default value should be updated, copy it from InfluxDB site.
119119
* `influxDBFlushInterval` - its interval to send data to InfluxDB, the default value is 4000 (4 seconds).
120120
* `influxDBMaxBatchSize` - the max size of the batch with metrics, the default 2000 (2000 items of JMeter results).
121-
121+
* `influxDBThresholdError` - the error threshold before stopping the import, the default value is 5. (see [Important notes](#important-notes) for more detail.)
122122

123123
![](img/influx3.png)
124124

build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ publishing {
120120
name = 'Mike Derevianko'
121121
122122
}
123+
developer {
124+
id = 'AlucardleVash'
125+
name = 'Pierre Brun'
126+
127+
}
123128
}
124129
scm {
125130
connection = 'scm:git:git:github.com/mderevyankoaqa/jmeter-influxdb2-listener-plugin.git'

gradlew

100644100755
File mode changed.

src/main/java/io/github/mderevyankoaqa/influxdb2/visualizer/InfluxDatabaseBackendListenerClient.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ public Arguments getDefaultParameters() {
157157
arguments.addArgument(InfluxDBConfig.KEY_INFLUX_DB_BUCKET, InfluxDBConfig.DEFAULT_BUCKET);
158158
arguments.addArgument(InfluxDBConfig.KEY_INFLUX_DB_FLUSH_INTERVAL, String.valueOf(InfluxDBConfig.DEFAULT_INFLUX_DB_FLUSH_INTERVAL));
159159
arguments.addArgument(InfluxDBConfig.KEY_INFLUX_DB_MAX_BATCH_SIZE, String.valueOf(InfluxDBConfig.DEFAULT_INFLUX_DB_MAX_BATCH_SIZE));
160+
arguments.addArgument(InfluxDBConfig.KEY_INFLUX_DB_THRESHOLD_ERROR, Integer.toString(InfluxDBConfig.DEFAULT_THRESHOLD_ERROR));
160161
arguments.addArgument(KEY_SAMPLERS_LIST, ".*");
161162
arguments.addArgument(KEY_USE_REGEX_FOR_SAMPLER_LIST, "true");
162163
arguments.addArgument(KEY_RECORD_SUB_SAMPLES, "true");

src/main/java/io/github/mderevyankoaqa/influxdb2/visualizer/config/InfluxDBConfig.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ public class InfluxDBConfig {
2727
*/
2828
public static final int DEFAULT_PORT = 8086;
2929

30+
/**
31+
* Default threshold error.
32+
*/
33+
public static final int DEFAULT_THRESHOLD_ERROR = 5;
34+
3035
/**
3136
* Default token.
3237
*/
@@ -88,6 +93,11 @@ public class InfluxDBConfig {
8893
*/
8994
public static final String KEY_INFLUX_DB_FLUSH_INTERVAL = "influxDBFlushInterval";
9095

96+
/**
97+
* Config key error threshold.
98+
*/
99+
public static final String KEY_INFLUX_DB_THRESHOLD_ERROR = "influxDBThresholdError";
100+
91101
/**
92102
* InfluxDB Host.
93103
*/
@@ -128,6 +138,11 @@ public class InfluxDBConfig {
128138
*/
129139
private int influxdbFlushInterval;
130140

141+
/**
142+
* Default protection to avoid OOM error.
143+
*/
144+
private int influxdbThresholdError;
145+
131146
/**
132147
* Creates the new instance of {@link InfluxDBConfig}
133148
*
@@ -164,6 +179,9 @@ public InfluxDBConfig(BackendListenerContext context) {
164179
Arguments.checkNotNegativeNumber(influxdbFlushInterval, KEY_INFLUX_DB_FLUSH_INTERVAL);
165180
this.setInfluxdbFlushInterval(influxdbFlushInterval);
166181

182+
int influxdbThresholdError = context.getIntParameter(KEY_INFLUX_DB_THRESHOLD_ERROR, InfluxDBConfig.DEFAULT_THRESHOLD_ERROR);
183+
Arguments.checkNotNegativeNumber(influxdbThresholdError, KEY_INFLUX_DB_THRESHOLD_ERROR);
184+
this.setInfluxdbThresholdError(influxdbThresholdError);
167185
}
168186

169187
/**
@@ -309,4 +327,22 @@ public int getInfluxdbFlushInterval() {
309327
public void setInfluxdbFlushInterval(int influxdbFlushInterval) {
310328
this.influxdbFlushInterval = influxdbFlushInterval;
311329
}
330+
331+
/**
332+
* Sets error threshold.
333+
*
334+
* @param influxdbThresholdError is the threshold of error to stop sending data to influx db to avoid OOM error.
335+
*/
336+
public void setInfluxdbThresholdError(int influxdbThresholdError) {
337+
this.influxdbThresholdError = influxdbThresholdError;
338+
}
339+
340+
/**
341+
* Gets threshold error to stop InfluxDB import.
342+
*
343+
* @return Threshold of error represented in the int.
344+
*/
345+
public int getInfluxdbThresholdError() {
346+
return influxdbThresholdError;
347+
}
312348
}

src/main/java/io/github/mderevyankoaqa/influxdb2/visualizer/influxdb/client/InfluxDatabaseClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ public synchronized void close() {
100100
*/
101101
public synchronized void importData() {
102102

103-
if (this.errorsAmount.size() >= 5)
103+
if (this.errorsAmount.size() >= this.influxDBConfig.getInfluxdbThresholdError())
104104
{
105105
this.points.clear();
106106
this.LOGGER.warn("Importing of the results to Influx DB is skipping since 5 errors, has occurred!");
107107
}
108108

109-
if (this.points.size() != 0 && this.errorsAmount.size() <= 5) {
109+
if (this.points.size() != 0 && this.errorsAmount.size() <= this.influxDBConfig.getInfluxdbThresholdError()) {
110110
try {
111111

112112
long start = System.currentTimeMillis();

0 commit comments

Comments
 (0)