diff --git a/CHANGELOG.md b/CHANGELOG.md index af4fdfb..731bb0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Makefile b/Makefile index 3238c72..b417044 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ .PHONY: build docker_tag=latest +perf_test_name=--simulation=io.github.devatherock.artifactory.controllers.CompositeSimulation clean: rm -rf build @@ -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: diff --git a/src/gatling/java/io/github/devatherock/artifactory/controllers/CompositeSimulation.java b/src/gatling/java/io/github/devatherock/artifactory/controllers/CompositeSimulation.java new file mode 100644 index 0000000..21acff8 --- /dev/null +++ b/src/gatling/java/io/github/devatherock/artifactory/controllers/CompositeSimulation.java @@ -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> feeder = createImageNameFeeder(); + + ChainBuilder suite = exec( + DockerPullsSimulation.buildRequest(), + VersionSimulation.buildRequest()); + + return scenario("All APIs") + .feed(feeder) + .forever() + .on(exec(suite).feed(feeder)); + } +} diff --git a/src/gatling/java/io/github/devatherock/artifactory/controllers/DockerPullsSimulation.java b/src/gatling/java/io/github/devatherock/artifactory/controllers/DockerPullsSimulation.java index 5317bc7..34d9cb0 100644 --- a/src/gatling/java/io/github/devatherock/artifactory/controllers/DockerPullsSimulation.java +++ b/src/gatling/java/io/github/devatherock/artifactory/controllers/DockerPullsSimulation.java @@ -6,11 +6,8 @@ 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; @@ -18,10 +15,10 @@ 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( @@ -32,17 +29,17 @@ public class DockerPullsSimulation extends BaseSimulation { } protected ScenarioBuilder buildScenario() { - Iterator> feeder = Stream.generate( - (Supplier>) () -> Collections.singletonMap("imageName", generateRandomString())) - .iterator(); - - HttpRequestActionBuilder request = http(GET_PULLS) - .get("/docker/pulls?package=devatherock/#{imageName}") - .check(status().is(200)); + Iterator> 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)); } } diff --git a/src/gatling/java/io/github/devatherock/artifactory/controllers/VersionSimulation.java b/src/gatling/java/io/github/devatherock/artifactory/controllers/VersionSimulation.java new file mode 100644 index 0000000..dd7ca80 --- /dev/null +++ b/src/gatling/java/io/github/devatherock/artifactory/controllers/VersionSimulation.java @@ -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> 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)); + } +} diff --git a/src/gatling/java/io/github/devatherock/test/BaseSimulation.java b/src/gatling/java/io/github/devatherock/test/BaseSimulation.java index d0da67a..606f8e9 100644 --- a/src/gatling/java/io/github/devatherock/test/BaseSimulation.java +++ b/src/gatling/java/io/github/devatherock/test/BaseSimulation.java @@ -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; @@ -62,5 +66,11 @@ public static String generateRandomString() { return randomString.toString(); } + public static Iterator> createImageNameFeeder() { + return Stream.generate( + (Supplier>) () -> Collections.singletonMap("imageName", generateRandomString())) + .iterator(); + } + protected abstract ScenarioBuilder buildScenario(); } diff --git a/src/gatling/resources/application-perf.properties b/src/gatling/resources/application-perf.properties index d657b78..cae29cf 100644 --- a/src/gatling/resources/application-perf.properties +++ b/src/gatling/resources/application-perf.properties @@ -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