-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #236 from tsegismont/jira/HWKMETRICS-115
HWKMETRICS-115 Create a Gatling load testing scenario
- Loading branch information
Showing
5 changed files
with
198 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
load-tests/src/test/scala/org/hawkular/metrics/loadtest/MetricsSimulation.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters