Skip to content

Commit

Permalink
Merge pull request #363 from devatherock/versions-perf-test
Browse files Browse the repository at this point in the history
test: Added perf test for the /version endpoint
  • Loading branch information
devatherock authored Oct 15, 2024
2 parents 4c085e1 + 46d2e5e commit 133b1eb
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 17 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## [Unreleased]
### Added
- Tests to verify log format
- Performance tests using gatling
- Performance tests for `/docker/pulls` and `/version` endpoints using gatling

### Changed
- fix(deps): update dependency org.objenesis:objenesis to v3.4
Expand Down
13 changes: 10 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.PHONY: build

docker_tag=latest
perf_test_name=--simulation=io.github.devatherock.artifactory.controllers.CompositeSimulation

clean:
rm -rf build
Expand All @@ -15,13 +16,19 @@ remote-integration-test:
DOCKER_TAG=$(docker_tag) docker compose -f docker-compose-remote.yml up --wait
docker logs -f artifactory-badge-intg-remote > logs-intg-remote.txt &
./gradlew integrationTest --tests '*RemoteUrlsIntegrationSpec*'
docker-compose down
docker compose -f docker-compose-remote.yml down
perf-test:
make perf-compose-up
make perf-run
make perf-compose-down
perf-run:
./gradlew gatlingRun $(perf_test_name) $(additional_gradle_args)
perf-compose-up:
rm -rf logs-perf.txt
DOCKER_TAG=$(docker_tag) docker compose -f docker-compose-perf.yml up --wait
docker logs -f artifactory-badge-perf > logs-perf.txt &
./gradlew gatlingRun --all $(additional_gradle_args)
docker compose down
perf-compose-down:
docker compose -f docker-compose-perf.yml down
build:
./gradlew build
fast-build:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.github.devatherock.artifactory.controllers;

import static io.gatling.javaapi.core.CoreDsl.exec;
import static io.gatling.javaapi.core.CoreDsl.rampUsers;
import static io.gatling.javaapi.core.CoreDsl.scenario;

import java.util.Iterator;
import java.util.Map;

import io.github.devatherock.test.BaseSimulation;

import io.gatling.javaapi.core.ChainBuilder;
import io.gatling.javaapi.core.ScenarioBuilder;

public class CompositeSimulation extends BaseSimulation {

{
setUp(buildScenario().injectOpen(
rampUsers(Integer.parseInt(getConfig("perf.users")))
.during(1)))
.protocols(buildProtocol())
.maxDuration(Long.parseLong(getConfig("perf.duration")));
}

protected ScenarioBuilder buildScenario() {
Iterator<Map<String, Object>> feeder = createImageNameFeeder();

ChainBuilder suite = exec(
DockerPullsSimulation.buildRequest(),
VersionSimulation.buildRequest());

return scenario("All APIs")
.feed(feeder)
.forever()
.on(exec(suite).feed(feeder));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,19 @@
import static io.gatling.javaapi.http.HttpDsl.http;
import static io.gatling.javaapi.http.HttpDsl.status;

import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.function.Supplier;
import java.util.stream.Stream;

import io.github.devatherock.test.BaseSimulation;

import io.gatling.javaapi.core.ScenarioBuilder;
import io.gatling.javaapi.http.HttpRequestActionBuilder;

/**
* Perf tests for the {@code docker/pulls} endpoint
* Perf tests for the {@code /docker/pulls} endpoint
*/
public class DockerPullsSimulation extends BaseSimulation {
private static final String GET_PULLS = "GET /docker/pulls";
static final String GET_PULLS = "GET /docker/pulls";

{
setUp(buildScenario().injectOpen(
Expand All @@ -32,17 +29,17 @@ public class DockerPullsSimulation extends BaseSimulation {
}

protected ScenarioBuilder buildScenario() {
Iterator<Map<String, Object>> feeder = Stream.generate(
(Supplier<Map<String, Object>>) () -> Collections.singletonMap("imageName", generateRandomString()))
.iterator();

HttpRequestActionBuilder request = http(GET_PULLS)
.get("/docker/pulls?package=devatherock/#{imageName}")
.check(status().is(200));
Iterator<Map<String, Object>> feeder = createImageNameFeeder();

return scenario(GET_PULLS)
.feed(feeder)
.forever()
.on(exec(request).feed(feeder));
.on(exec(buildRequest()).feed(feeder));
}

static HttpRequestActionBuilder buildRequest() {
return http(GET_PULLS)
.get("/docker/pulls?package=devatherock/#{imageName}")
.check(status().is(200));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.github.devatherock.artifactory.controllers;

import static io.gatling.javaapi.core.CoreDsl.exec;
import static io.gatling.javaapi.core.CoreDsl.rampUsers;
import static io.gatling.javaapi.core.CoreDsl.scenario;
import static io.gatling.javaapi.http.HttpDsl.http;
import static io.gatling.javaapi.http.HttpDsl.status;

import java.util.Iterator;
import java.util.Map;

import io.github.devatherock.test.BaseSimulation;

import io.gatling.javaapi.core.ScenarioBuilder;
import io.gatling.javaapi.http.HttpRequestActionBuilder;

/**
* Perf tests for the {@code /version} endpoint
*/
public class VersionSimulation extends BaseSimulation {
static final String GET_VERSION = "GET /version";

{
setUp(buildScenario().injectOpen(
rampUsers(Integer.parseInt(getConfig("perf.version.users")))
.during(1)))
.protocols(buildProtocol())
.maxDuration(Long.parseLong(getConfig("perf.version.duration")));
}

protected ScenarioBuilder buildScenario() {
Iterator<Map<String, Object>> feeder = createImageNameFeeder();

return scenario(GET_VERSION)
.feed(feeder)
.forever()
.on(exec(buildRequest()).feed(feeder));
}

static HttpRequestActionBuilder buildRequest() {
return http(GET_VERSION)
.get("/version?package=devatherock/#{imageName}")
.check(status().is(200));
}
}
10 changes: 10 additions & 0 deletions src/gatling/java/io/github/devatherock/test/BaseSimulation.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@

import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;
import java.util.stream.Stream;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -62,5 +66,11 @@ public static String generateRandomString() {
return randomString.toString();
}

public static Iterator<Map<String, Object>> createImageNameFeeder() {
return Stream.generate(
(Supplier<Map<String, Object>>) () -> Collections.singletonMap("imageName", generateRandomString()))
.iterator();
}

protected abstract ScenarioBuilder buildScenario();
}
4 changes: 4 additions & 0 deletions src/gatling/resources/application-perf.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
perf.base.url=http://localhost:8080
perf.docker-pulls.users=10
perf.docker-pulls.duration=600
perf.version.users=10
perf.version.duration=600
perf.users=10
perf.duration=600

0 comments on commit 133b1eb

Please sign in to comment.