Skip to content

Commit

Permalink
Merge pull request #712 from jsanda/hwkmetrics-559
Browse files Browse the repository at this point in the history
[HWKMETRICS-559] add support for duration option
  • Loading branch information
stefannegrea committed Dec 19, 2016
2 parents 44217ef + c412280 commit b4fb182
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 19 deletions.
5 changes: 5 additions & 0 deletions integration-tests/load-tests/README.adoc
Expand Up @@ -67,4 +67,9 @@ Authentication is disabled when unset.
|points
|Number of data points for a metric. Defaults to `1`.

|duration
|The number of minutes that the test should run. By default the test does not use this and executes
`loops` for each client. If this option is specified (with a non-zero value) as well as `loops`, the
latter will be ignored.

|===
2 changes: 2 additions & 0 deletions integration-tests/load-tests/pom.xml
Expand Up @@ -36,6 +36,7 @@
<dependency>
<groupId>io.gatling.highcharts</groupId>
<artifactId>gatling-charts-highcharts</artifactId>
<version>2.2.3</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -45,6 +46,7 @@
<plugin>
<groupId>io.gatling</groupId>
<artifactId>gatling-maven-plugin</artifactId>
<version>2.2.1</version>
<configuration>
<simulationClass>org.hawkular.metrics.loadtest.MetricsSimulation</simulationClass>
<propagateSystemProperties>true</propagateSystemProperties>
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/load-tests/src/test/resources/gatling.conf
@@ -1,5 +1,5 @@
#
# Copyright 2014-2015 Red Hat, Inc. and/or its affiliates
# Copyright 2014-2016 Red Hat, Inc. and/or its affiliates
# and other contributors as indicated by the @author tags.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -17,6 +17,6 @@

gatling {
data {
writers = "file"
#writers = "file"
}
}
Expand Up @@ -22,6 +22,7 @@ import java.util.Base64.Encoder

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._

class MetricsSimulation extends Simulation {

Expand All @@ -37,7 +38,7 @@ class MetricsSimulation extends Simulation {
// Number of concurrent clients (think of collectors on different machines)
val clients = Integer.getInteger("clients", 10)
// Delay before firing up another client
val ramp = java.lang.Long.getLong("ramp", 1L)
val ramp = java.lang.Long.getLong("ramp", 1L)

// The number of loops for each client
val loops = Integer.getInteger("loops", 10).toInt
Expand All @@ -49,6 +50,8 @@ class MetricsSimulation extends Simulation {
// Number of data points for a metric
val points = Integer.getInteger("points", 1)

val duration = Integer.getInteger("duration", 0)

// ---------------------------

var httpProtocol = http
Expand All @@ -59,19 +62,19 @@ class MetricsSimulation extends Simulation {

httpProtocol = authType match {
case "openshiftHtpasswd" =>
httpProtocol
.authorizationHeader("Basic " + encoder.encodeToString(s"$user:$password".getBytes(StandardCharsets.UTF_8)))
.header("Hawkular-Tenant", tenant)
httpProtocol
.authorizationHeader("Basic " + encoder.encodeToString(s"$user:$password".getBytes(StandardCharsets.UTF_8)))
.header("Hawkular-Tenant", tenant)
case "openshiftToken" =>
httpProtocol
.authorizationHeader("Bearer $token")
.header("Hawkular-Tenant", tenant)
httpProtocol
.authorizationHeader("Bearer $token")
.header("Hawkular-Tenant", tenant)
case "hawkular" =>
httpProtocol
.authorizationHeader("Basic " + encoder.encodeToString(s"$user:$password".getBytes(StandardCharsets.UTF_8)))
httpProtocol
.authorizationHeader("Basic " + encoder.encodeToString(s"$user:$password".getBytes(StandardCharsets.UTF_8)))
case _ =>
httpProtocol
.header("Hawkular-Tenant", tenant)
httpProtocol
.header("Hawkular-Tenant", tenant)
}

val random = new util.Random
Expand All @@ -97,15 +100,23 @@ class MetricsSimulation extends Simulation {
builder.toString
}

val simulation = repeat(loops, "n") {
exec(http("Report ${n}")
.post("/gauges/raw")
.body(StringBody(session => genReport(metrics, points)))
).pause(interval)
val simulation = doIfOrElse(session => duration > 0) {
during(duration minutes, "n") {
exec(http("Report ${n}")
.post("/gauges/raw")
.body(StringBody(session => genReport(metrics, points)))
).pause(interval)
}
} {
repeat(loops, "n") {
exec(http("Report ${n}")
.post("/gauges/raw")
.body(StringBody(session => genReport(metrics, points)))
).pause(interval)
}
}

val scn = scenario("MetricsSimulation").exec(simulation)

setUp(scn.inject(rampUsers(clients) over (ramp seconds))).protocols(httpProtocol)
}

0 comments on commit b4fb182

Please sign in to comment.