Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: johrstrom/jmeter-prometheus-plugin
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.6.2
Choose a base ref
...
head repository: johrstrom/jmeter-prometheus-plugin
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0.7.1
Choose a head ref
  • 7 commits
  • 8 files changed
  • 6 contributors

Commits on Mar 2, 2023

  1. Copy the full SHA
    6109f9f View commit details

Commits on Mar 14, 2023

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    70b3893 View commit details

Commits on Jul 29, 2023

  1. Thread group label (#123)

    Prometheus Listener now supports value 'threadGroup' in the Labels column.
    Updated some dependencies.
    
    Co-authored-by: John Walker <[email protected]>
    johndwalker and John Walker authored Jul 29, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    6022eef View commit details

Commits on Jul 30, 2023

  1. upgraded prometheus to newest version (#122)

    Co-authored-by: Stephan Stiefel <[email protected]>
    Stephan3555 and hawk-stephan-stiefel authored Jul 30, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    4969b8e View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    b2e1e55 View commit details
  3. Change thread group label to snake_case (#130)

    * use snake_case for thread group label
    
    * add test case for thread_group
    johrstrom authored Jul 30, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    f6aa45d View commit details

Commits on Aug 3, 2023

  1. update pom version (#132)

    update the pom version to 0.7.1 for next release.
    johrstrom authored Aug 3, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    66da8f4 View commit details
17 changes: 12 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -2,14 +2,14 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.johrstrom</groupId>
<artifactId>jmeter-prometheus-plugin</artifactId>
<version>0.6.2</version>
<version>0.7.1</version>
<name>Jmeter-Prometheus Listener Plugin</name>
<description>A Jmeter plugin that creates a Prometheus endpoint of results.</description>
<url>https://github.com/johrstrom/jmeter-prometheus-plugin</url>

<properties>
<prometheus.version>0.6.0</prometheus.version>
<jmeter.version>5.1.1</jmeter.version>
<prometheus.version>0.16.0</prometheus.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>
@@ -75,7 +75,14 @@
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter_java</artifactId>
<version>${jmeter.version}</version>
<scope>test</scope>
<scope>provided</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>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
@@ -124,7 +131,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>
Original file line number Diff line number Diff line change
@@ -127,13 +127,13 @@ public QuantileDefinition[] getQuantiles() {
}
}

public long getQuantileWindowLenght() {
public long getQuantileWindowLength() {
String quantiles = getQuantileOrBucket();

if (quantiles == null || quantiles.isEmpty()) {
return DEFAULT_QUANTILE_WINDOW_LENGHT;
} else {
return QuantileDefinition.parseQuantilesWindowLenghtFromString(quantiles);
return QuantileDefinition.parseQuantilesWindowLengthFromString(quantiles);
}
}

@@ -220,7 +220,7 @@ public static Summary newSummary(BaseCollectorConfig cfg) throws Exception {
io.prometheus.client.Summary.Builder builder = new Summary.Builder()
.name(cfg.getMetricName())
.help(cfg.getHelp())
.maxAgeSeconds(cfg.getQuantileWindowLenght());
.maxAgeSeconds(cfg.getQuantileWindowLength());

String[] labels = cfg.getLabels();
if(labels.length != 0) {
@@ -370,7 +370,7 @@ public static class QuantileDefinition {
public static final String QUANTILE_ERROR_SEPERATOR = ",";
public static final String QUANTILE_DEFINITION_SEPERATOR = "|";
public static final String QUANTILE_DEFINITION_SEPERATOR_REGEX = "\\|";
public static final String QUANTILE_LENGHT_SEPERATOR_REGEX = "\\;";
public static final String QUANTILE_LENGTH_SEPERATOR_REGEX = "\\;";

QuantileDefinition(double quantile, double error) {
this.quantile = quantile;
@@ -421,7 +421,7 @@ public static String arrayToString(QuantileDefinition[] definitions) {
}

public static QuantileDefinition[] parseQuantilesFromString(String fullQuantileString) {
String quantileOnlyString = fullQuantileString.split(QUANTILE_LENGHT_SEPERATOR_REGEX)[0];
String quantileOnlyString = fullQuantileString.split(QUANTILE_LENGTH_SEPERATOR_REGEX)[0];
String[] quantileDefStrings = quantileOnlyString.split(QUANTILE_DEFINITION_SEPERATOR_REGEX);
List<QuantileDefinition> quantiles = new ArrayList<QuantileDefinition>();

@@ -444,8 +444,8 @@ public static QuantileDefinition[] parseQuantilesFromString(String fullQuantileS
}


public static long parseQuantilesWindowLenghtFromString(String fullQuantileString) {
String[] quantileDefStrings = fullQuantileString.split(QUANTILE_LENGHT_SEPERATOR_REGEX);
public static long parseQuantilesWindowLengthFromString(String fullQuantileString) {
String[] quantileDefStrings = fullQuantileString.split(QUANTILE_LENGTH_SEPERATOR_REGEX);
if (quantileDefStrings.length < 2) {
log.debug("Using default quantile window lenght of " + DEFAULT_QUANTILE_WINDOW_LENGHT + " seconds");
return DEFAULT_QUANTILE_WINDOW_LENGHT;
Original file line number Diff line number Diff line change
@@ -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")) {
// reserved keywords for the sampler's label name.
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("thread_group")) {
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);
}

Original file line number Diff line number Diff line change
@@ -63,6 +63,24 @@ public void parseMultipleQuantilesCorrectly() {
Assert.assertEquals(0.999, quantiles[2].quantile,0.001);
Assert.assertEquals(0.1, quantiles[2].error,0.001);
}

@Test
public void parseMultipleQuantilesWithWindowCorrectly() {
BaseCollectorConfig cfg = TestUtilities.simpleSummaryCfg();
cfg.setQuantileOrBucket("0.95,0.1|0.99,0.1|0.999,0.1;60");


QuantileDefinition[] quantiles = cfg.getQuantiles();
Assert.assertEquals(3, quantiles.length);
Assert.assertEquals(0.95, quantiles[0].quantile,0.001);
Assert.assertEquals(0.1, quantiles[0].error,0.001);
Assert.assertEquals(0.99, quantiles[1].quantile,0.001);
Assert.assertEquals(0.1, quantiles[1].error,0.001);
Assert.assertEquals(0.999, quantiles[2].quantile,0.001);
Assert.assertEquals(0.1, quantiles[2].error,0.001);

Assert.assertEquals(60, cfg.getQuantileWindowLength());
}

@Test
public void parseQauntileFailsAndGivesDEFAULTs() {
@@ -96,7 +114,6 @@ public void parseReturnsPartialForQuantiles() {
Assert.assertEquals(0.1, quantiles[0].error,0.001);
Assert.assertEquals(0.75, quantiles[1].quantile,0.001);
Assert.assertEquals(0.1, quantiles[1].error,0.001);

}

@Test
@@ -192,5 +209,4 @@ public void setOfElementsTest() {

Assert.assertEquals(leftHash, rightHash);
}

}
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ public void testSuccess() {
foundFailure = true;

break;
case "something_ratio_total":
case "something_ratio":
assertOnSingleFamily(family, 1);
foundTotal = true;

@@ -92,7 +92,7 @@ public void testFailure() {
foundFailure = true;

break;
case "otherthing_ratio_total":
case "otherthing_ratio":
assertOnSingleFamily(family, 1);
foundTotal = true;

@@ -107,7 +107,7 @@ public void testFailure() {
}

private void assertOnSingleFamily(MetricFamilySamples family, double expectedValue) {
Assert.assertEquals(1, family.samples.size());
Assert.assertEquals(2, family.samples.size());
Sample sample = family.samples.get(0);

Assert.assertArrayEquals(labelValues, sample.labelValues.toArray());
Original file line number Diff line number Diff line change
@@ -113,6 +113,7 @@ public void updateAllTypes() {
long latency = 1532;
int responseSize = 1342;
int samplesOccurred = 0;
double expectedCreated = System.currentTimeMillis() / 1000.0;

ResultAndVariables res = TestUtilities.resultWithLabels();
res.result.setConnectTime(connectTime);
@@ -155,42 +156,42 @@ public void updateAllTypes() {

// histograms
case "test_hist_rtime":
assertOnHistogram(reg.getOrCreateAndRegister(cfg), elapsedTime * samplesOccurred, samplesOccurred,
assertOnHistogram(reg.getOrCreateAndRegister(cfg), elapsedTime * samplesOccurred, samplesOccurred, expectedCreated,
elapsedTime);
break;
case "test_hist_rsize":
assertOnHistogram(reg.getOrCreateAndRegister(cfg), responseSize * samplesOccurred, samplesOccurred,
assertOnHistogram(reg.getOrCreateAndRegister(cfg), responseSize * samplesOccurred, samplesOccurred, expectedCreated,
responseSize);
break;
case "test_hist_latency":
assertOnHistogram(reg.getOrCreateAndRegister(cfg), latency * samplesOccurred, samplesOccurred, latency);
assertOnHistogram(reg.getOrCreateAndRegister(cfg), latency * samplesOccurred, samplesOccurred, expectedCreated, latency);
break;
case "test_hist_idle_time":
assertOnHistogram(reg.getOrCreateAndRegister(cfg), idleTime * samplesOccurred, samplesOccurred,
assertOnHistogram(reg.getOrCreateAndRegister(cfg), idleTime * samplesOccurred, samplesOccurred, expectedCreated,
idleTime);
break;
case "test_hist_connect_time":
assertOnHistogram(reg.getOrCreateAndRegister(cfg), connectTime * samplesOccurred, samplesOccurred,
assertOnHistogram(reg.getOrCreateAndRegister(cfg), connectTime * samplesOccurred, samplesOccurred, expectedCreated,
connectTime);
break;

// summaries
case "test_summary_rtime":
assertOnSummary(reg.getOrCreateAndRegister(cfg), elapsedTime * samplesOccurred, samplesOccurred,
assertOnSummary(reg.getOrCreateAndRegister(cfg), elapsedTime * samplesOccurred, samplesOccurred, expectedCreated,
elapsedTime);
break;
case "test_summary_rsize":
assertOnSummary(reg.getOrCreateAndRegister(cfg), responseSize * samplesOccurred, samplesOccurred,
assertOnSummary(reg.getOrCreateAndRegister(cfg), responseSize * samplesOccurred, samplesOccurred, expectedCreated,
responseSize);
break;
case "test_summary_latency":
assertOnSummary(reg.getOrCreateAndRegister(cfg), latency * samplesOccurred, samplesOccurred, latency);
assertOnSummary(reg.getOrCreateAndRegister(cfg), latency * samplesOccurred, samplesOccurred, expectedCreated, latency);
break;
case "test_summary_idle_time":
assertOnSummary(reg.getOrCreateAndRegister(cfg), idleTime * samplesOccurred, samplesOccurred, idleTime);
assertOnSummary(reg.getOrCreateAndRegister(cfg), idleTime * samplesOccurred, samplesOccurred, expectedCreated, idleTime);
break;
case "test_summary_connect_time":
assertOnSummary(reg.getOrCreateAndRegister(cfg), connectTime * samplesOccurred, samplesOccurred,
assertOnSummary(reg.getOrCreateAndRegister(cfg), connectTime * samplesOccurred, samplesOccurred, expectedCreated,
connectTime);
break;

@@ -215,14 +216,14 @@ private void assertOnRatio(ListenerCollectorConfig cfg) {
Assert.assertEquals(2.0, shouldBeTwo, 0.1);
}

protected static void assertOnHistogram(Collector collector, double expectedSum, double expectedCount,
protected static void assertOnHistogram(Collector collector, double expectedSum, double expectedCount, double expectedCreated,
double boundary) {
List<MetricFamilySamples> metrics = collector.collect();
Assert.assertEquals(1, metrics.size());
MetricFamilySamples family = metrics.get(0);

// labels + Inf + count + sum
Assert.assertEquals(TestUtilities.EXPECTED_LABELS.length + 4, family.samples.size());
Assert.assertEquals(TestUtilities.EXPECTED_LABELS.length + 5, family.samples.size());

for (Sample sample : family.samples) {
List<String> values = sample.labelValues;
@@ -245,6 +246,10 @@ protected static void assertOnHistogram(Collector collector, double expectedSum,
Assert.assertTrue(values.size() == labelSize && names.size() == labelSize);
Assert.assertEquals(expectedSum, sample.value, 0.1);

} else if (sample.name.endsWith("created")) {
Assert.assertTrue(values.size() == labelSize && names.size() == labelSize);
Assert.assertEquals(expectedCreated, sample.value, 0.1);

} else {
Assert.assertEquals(values.size(), labelSize + 1);
Assert.assertEquals(names.size(), labelSize + 1);
@@ -265,13 +270,13 @@ protected static void assertOnHistogram(Collector collector, double expectedSum,
}
}

protected void assertOnSummary(Collector collector, double expectedSum, double expectedCount,
protected void assertOnSummary(Collector collector, double expectedSum, double expectedCount, double expectedCreated,
double expectedValue) {

List<MetricFamilySamples> metrics = collector.collect();
Assert.assertEquals(1, metrics.size());
MetricFamilySamples family = metrics.get(0);
Assert.assertEquals(5, family.samples.size()); // 3 quantiles + count + sum
Assert.assertEquals(6, family.samples.size()); // 3 quantiles + count + sum

for (Sample sample : family.samples) {
List<String> values = sample.labelValues;
@@ -291,6 +296,8 @@ protected void assertOnSummary(Collector collector, double expectedSum, double e

} else if (sample.name.endsWith("sum")) {
Assert.assertEquals(expectedSum, sample.value, 0.1);
} else if (sample.name.endsWith("created")) {
Assert.assertEquals(expectedCreated, sample.value, 0.1);
} else {
Assert.assertEquals(values.size(), TestUtilities.EXPECTED_LABELS.length + 1);
Assert.assertEquals(values.size(), TestUtilities.EXPECTED_LABELS.length + 1);
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ public void update(SampleEvent e) {
@Test
public void testKeywords() {
BaseCollectorConfig base = TestUtilities.simpleCounterCfg();
base.setLabels(new String[] {"label","code"});
base.setLabels(new String[] {"label","code", "thread_group"});
ListenerCollectorConfig cfg = new ListenerCollectorConfig(base);

TestUpdater u = new TestUpdater(cfg);
@@ -42,8 +42,8 @@ public void testKeywords() {
String[] labels = u.labelValues(event);


Assert.assertTrue(labels.length == 2);
Assert.assertArrayEquals(new String[] {"test_label", "204"}, labels);
Assert.assertTrue(labels.length == 3);
Assert.assertArrayEquals(new String[] {"test_label", "204", "test_tg"}, labels);
}

@Test
Loading