Skip to content

Commit

Permalink
Merge pull request #236 from tsegismont/jira/HWKMETRICS-115
Browse files Browse the repository at this point in the history
HWKMETRICS-115 Create a Gatling load testing scenario
  • Loading branch information
jsanda committed Jun 2, 2015
2 parents eb6e3fd + 2fbdf97 commit 3ec5257
Show file tree
Hide file tree
Showing 5 changed files with 198 additions and 0 deletions.
26 changes: 26 additions & 0 deletions load-tests/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
= Hawkular Metrics Load Tests
:type: article

A simple load testing tool for Hawkular Metrics

== Why a Maven project?

Because it makes it easier for developers to fire a load test:
there's no need to download, extract and configure PATH.

== The scenario

The simulation consists in sending metrics reports from a configurable number of clients (like a collector sending
reports periodically). On top of the number of clients, many aspects of the simulation are configurable:
number of loops, interval, number of metrics per report, ... etc.

See the scenario file for the list of options.

== Running

mvn gatling:execute -Dxxx=y ...

Each scenario option can be set with a system property.

The scenario assumes a Metrics server is running somewhere and does not start one.
By default, it tries to connect to `http://localhost:8080`.
61 changes: 61 additions & 0 deletions load-tests/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<!--
Copyright 2014-2015 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");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.hawkular.metrics</groupId>
<artifactId>hawkular-metrics-parent</artifactId>
<version>0.3.5-SNAPSHOT</version>
</parent>

<artifactId>hawkular-metrics-load-tests</artifactId>
<name>Hawkular Metrics Load Tests</name>
<packaging>pom</packaging>

<properties>
<version.io.gatling>2.1.6</version.io.gatling>
</properties>

<dependencies>
<dependency>
<groupId>io.gatling.highcharts</groupId>
<artifactId>gatling-charts-highcharts</artifactId>
<version>${version.io.gatling}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.gatling</groupId>
<artifactId>gatling-maven-plugin</artifactId>
<version>${version.io.gatling}</version>
<configuration>
<simulationClass>org.hawkular.metrics.loadtest.MetricsSimulation</simulationClass>
<propagateSystemProperties>true</propagateSystemProperties>
</configuration>
</plugin>
</plugins>
</build>

</project>
22 changes: 22 additions & 0 deletions load-tests/src/test/resources/gatling.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# Copyright 2014-2015 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");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

gatling {
data {
writers = "file"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
* Copyright 2014-2015 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");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hawkular.metrics.loadtest

import scala.concurrent.duration._

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._

class MetricsSimulation extends Simulation {

// --------------------------- Options

val baseURI = System.getProperty("baseURI", "http://localhost:8080")
val tenant = System.getProperty("tenant", "default")

// Number of concurrent clients (think of collectors on different machines)
val clients = Integer.getInteger("clients", 1)
// Delay before firing up another client
val ramp = java.lang.Long.getLong("ramp", 0L)

// The number of loops for each client
val loops = Integer.getInteger("loops", 10).toInt
// Interval between metrics reports
val interval = Integer.getInteger("interval", 1)

// Number of metrics in a JSON report
val metrics = Integer.getInteger("metrics", 10)
// Number of data points for a metric
val points = Integer.getInteger("points", 1)

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

val httpProtocol = http
.baseURL(baseURI)
.header("Hawkular-Tenant", tenant)
.contentTypeHeader("application/json;charset=utf-8")

val random = new util.Random
val genReport = (m: Int, p: Int) => {
val builder = new StringBuilder
builder += '['
for (i <- 1 to m) {
builder ++= """{"id":"metrics.load.test."""
builder.append(i)
builder ++= """.value","data":["""
for (j <- 1 to p) {
builder ++= """{"timestamp":"""
builder.append(System.currentTimeMillis)
builder ++= ""","value":"""
builder.append(random.nextDouble)
builder += '}'
if (j < p) builder += ','
}
builder ++= "]}"
if (i < m) builder += ','
}
builder += ']'
builder.toString
}

val simulation = repeat(loops, "n") {
exec(http("Report ${n}")
.post("/hawkular/metrics/gauges/data")
.body(StringBody(session => genReport(metrics, points)))
).pause(interval)
}

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

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

1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
<module>rest-tests</module>
<module>clients</module>
<module>containers</module>
<module>load-tests</module>
</modules>

<scm>
Expand Down

0 comments on commit 3ec5257

Please sign in to comment.