Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Init benchmarks #451

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions benchmark/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# How to run benchmarks

* Setup your cortex instance with a user and api key
* Copy the `application.conf.sample` file to `application.conf` and fill in the details
* Run with sbt `benchmark/Gatling/testOnly <your-scenario>`
1 change: 1 addition & 0 deletions benchmark/src/test/resources/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
application.conf
11 changes: 11 additions & 0 deletions benchmark/src/test/resources/application.conf.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
user {
login = "[email protected]"
password = gatling
# Set value
apiKey = ""
}

baseUrl = "http://localhost:9000"

# Id of an analyzer
analyzer = ""
25 changes: 25 additions & 0 deletions benchmark/src/test/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>

<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%-5level] %logger{15} - %msg%n%rEx</pattern>
</encoder>
<immediateFlush>false</immediateFlush>
</appender>

<!-- uncomment and set to DEBUG to log all failing HTTP requests -->
<!-- uncomment and set to TRACE to log all HTTP requests -->
<!--<logger name="io.gatling.http.engine.response" level="TRACE" />-->

<!-- uncomment to log WebSocket events -->
<!--<logger name="io.gatling.http.action.ws.fsm" level="DEBUG" />-->

<!-- uncomment to log SSE events -->
<!--<logger name="io.gatling.http.action.sse.fsm" level="DEBUG" />-->

<root level="WARN">
<appender-ref ref="CONSOLE" />
</root>

</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.thp.cortex.benchmark

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

import java.util.UUID
import scala.concurrent.duration.DurationInt

class AnalyzerSimulation extends Simulation {

val httpProtocal = http
.baseUrl(Configuration.baseUrl)
.authorizationHeader(s"Bearer ${Configuration.userApiKey}")

val analyzer = Configuration.conf.getString("analyzer")

val random = UUID.randomUUID()

val scn = scenario("Analyzer")
.exec(
http("launch analyzer")
.post(s"/api/analyzer/${analyzer}/run")
.body(StringBody { session =>
s"""{
| "dataType": "domain",
| "data": "${random}-${session.userId}",
| "pap": 2,
| "tlp": 2,
| "message": "",
| "parameters": {}
|}""".stripMargin
})
.asJson
.check(status.is(200))
.check(bodyString.saveAs("job"))
.check(jsonPath("$._id").saveAs("jobId"))
)
.exitHereIfFailed
.exec(session => session.set("i", 0))
.exec(
doWhile(session => session("i").as[Int] < 10 && session("jobStatus").asOption[String].contains("Waiting")) {
exec(
http("get job status")
.get("/api/job/#{jobId}/waitreport?atMost=1seconds")
.check(jsonPath("$.status").saveAs("jobStatus"))
).exec(session => session.set("i", session("i").as[Int] + 1))
}
)

setUp(
scn.inject(constantConcurrentUsers(6).during(60.seconds))
).protocols(httpProtocal)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.thp.cortex.benchmark

import com.typesafe.config.{Config, ConfigFactory}

object Configuration {
val conf: Config = ConfigFactory.load()

val userLogin = conf.getString("user.login")
val userPassword = conf.getString("user.password")
val userApiKey = conf.getString("user.apiKey")

val baseUrl = conf.getString("baseUrl")
}
11 changes: 11 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,14 @@ lazy val cortexWithDeps = (project in file("target/docker-withdeps"))
Docker / version := version.value + "-withdeps",
Docker / packageName := "cortex"
)

lazy val benchmark = (project in file("benchmark"))
.enablePlugins(GatlingPlugin)
.settings(
scalaVersion := "2.13.11",
dependencyOverrides := Seq.empty,
libraryDependencies ++= Seq(
Dependencies.gatlingHighcharts % Test,
Dependencies.gatlingTestFramework % Test
)
)
2 changes: 1 addition & 1 deletion conf/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%coloredLevel %logger{15} - %message%n%xException{10}
<pattern>%coloredLevel %logger{15} - %message%n%xException
</pattern>
</encoder>
</appender>
Expand Down
3 changes: 3 additions & 0 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ object Dependencies {
val dockerClient = "com.spotify" % "docker-client" % "8.16.0"
val akkaCluster = "com.typesafe.akka" %% "akka-cluster" % play.core.PlayVersion.akkaVersion
val akkaClusterTyped = "com.typesafe.akka" %% "akka-cluster-typed" % play.core.PlayVersion.akkaVersion

val gatlingHighcharts = "io.gatling.highcharts" % "gatling-charts-highcharts" % "3.9.5"
val gatlingTestFramework = "io.gatling" % "gatling-test-framework" % "3.9.5"
}
1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.19")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6")
addSbtPlugin("org.thehive-project" % "sbt-github-changelog" % "0.4.0")
addSbtPlugin("io.github.siculo" %% "sbt-bom" % "0.3.0")
addSbtPlugin("io.gatling" % "gatling-sbt" % "4.4.0")