Skip to content

Commit

Permalink
fix(playground): handle query future for metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Zitrone44 committed Nov 12, 2023
1 parent 60a3905 commit c1f0c66
Showing 1 changed file with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import io.vertx.core.json.JsonObject
import io.vertx.lang.scala.{ScalaLogger, ScalaVerticle}
import io.vertx.scala.core.eventbus.Message
import io.vertx.scala.ext.jdbc.JDBCClient
import io.vertx.scala.ext.sql.ResultSet

import java.sql.{SQLException, SQLTimeoutException}
import java.util.Date
Expand All @@ -34,7 +35,7 @@ class SqlPlaygroundVerticle extends ScalaVerticle {
private var sqlPools = Map[String, SqlPoolWithConfig]()
private val meter = Metrics.openTelemetry.meterBuilder("de.thm.mni.ii.fbs.verticles.runner.playground").build()
private val processingCounter = meter.upDownCounterBuilder("processingCount").setDescription("Processing Requests").build()
private val processingTimeCounter = meter.histogramBuilder("processingTime").ofLongs().setDescription("Time for processing").build()
private val processingTimeCounter = meter.histogramBuilder("processingTime").ofLongs().setDescription("Time for processing").setUnit("ms").build()
private val errorCounter = meter.counterBuilder("errorCount").setDescription("Error Count").build()

Check warning on line 39 in modules/fbs-runner/checker/src/main/scala/de/thm/ii/fbs/verticles/runner/SqlPlaygroundVerticle.scala

View check run for this annotation

Codecov / codecov/patch

modules/fbs-runner/checker/src/main/scala/de/thm/ii/fbs/verticles/runner/SqlPlaygroundVerticle.scala#L36-L39

Added lines #L36 - L39 were not covered by tests

/**
Expand Down Expand Up @@ -63,22 +64,32 @@ class SqlPlaygroundVerticle extends ScalaVerticle {

processingCounter.add(1)
val startTime = new Date().getTime
val end = (failure: Boolean) => {
val endTime = new Date().getTime
processingTimeCounter.record(endTime - startTime)
processingCounter.add(-1)

Check warning on line 70 in modules/fbs-runner/checker/src/main/scala/de/thm/ii/fbs/verticles/runner/SqlPlaygroundVerticle.scala

View check run for this annotation

Codecov / codecov/patch

modules/fbs-runner/checker/src/main/scala/de/thm/ii/fbs/verticles/runner/SqlPlaygroundVerticle.scala#L65-L70

Added lines #L65 - L70 were not covered by tests
if (failure) errorCounter.add(1)
}

try {
logger.info(s"SqlPlayground received execution ${runArgs.executionId}")

val con = getConnection(runArgs)

if (con.isDefined) {
executeQueries(runArgs, con.get)
executeQueries(runArgs, con.get) onComplete {

Check warning on line 80 in modules/fbs-runner/checker/src/main/scala/de/thm/ii/fbs/verticles/runner/SqlPlaygroundVerticle.scala

View check run for this annotation

Codecov / codecov/patch

modules/fbs-runner/checker/src/main/scala/de/thm/ii/fbs/verticles/runner/SqlPlaygroundVerticle.scala#L80

Added line #L80 was not covered by tests
case Success(_) =>
end(false)

Check warning on line 82 in modules/fbs-runner/checker/src/main/scala/de/thm/ii/fbs/verticles/runner/SqlPlaygroundVerticle.scala

View check run for this annotation

Codecov / codecov/patch

modules/fbs-runner/checker/src/main/scala/de/thm/ii/fbs/verticles/runner/SqlPlaygroundVerticle.scala#L82

Added line #L82 was not covered by tests
case Failure(_) =>
end(true)

Check warning on line 84 in modules/fbs-runner/checker/src/main/scala/de/thm/ii/fbs/verticles/runner/SqlPlaygroundVerticle.scala

View check run for this annotation

Codecov / codecov/patch

modules/fbs-runner/checker/src/main/scala/de/thm/ii/fbs/verticles/runner/SqlPlaygroundVerticle.scala#L84

Added line #L84 was not covered by tests
}
} else {
end(false)

Check warning on line 87 in modules/fbs-runner/checker/src/main/scala/de/thm/ii/fbs/verticles/runner/SqlPlaygroundVerticle.scala

View check run for this annotation

Codecov / codecov/patch

modules/fbs-runner/checker/src/main/scala/de/thm/ii/fbs/verticles/runner/SqlPlaygroundVerticle.scala#L87

Added line #L87 was not covered by tests
}
} catch {
case e: Throwable =>
errorCounter.add(1)
end(true)
handleError(runArgs, e)

Check warning on line 92 in modules/fbs-runner/checker/src/main/scala/de/thm/ii/fbs/verticles/runner/SqlPlaygroundVerticle.scala

View check run for this annotation

Codecov / codecov/patch

modules/fbs-runner/checker/src/main/scala/de/thm/ii/fbs/verticles/runner/SqlPlaygroundVerticle.scala#L91-L92

Added lines #L91 - L92 were not covered by tests
} finally {
val endTime = new Date().getTime
processingCounter.add(-1)
processingTimeCounter.record(endTime - startTime)
}
}

Expand All @@ -93,10 +104,10 @@ class SqlPlaygroundVerticle extends ScalaVerticle {
}
}

private def executeQueries(runArgs: SqlPlaygroundRunArgs, con: PlaygroundDBConnections): Unit = {
private def executeQueries(runArgs: SqlPlaygroundRunArgs, con: PlaygroundDBConnections): Future[(ResultSet, ResultSet)] = {
val sqlPlayground = new SQLPlaygroundService(runArgs, con, config.getInteger("SQL_QUERY_TIMEOUT_S", 1))

Check warning on line 108 in modules/fbs-runner/checker/src/main/scala/de/thm/ii/fbs/verticles/runner/SqlPlaygroundVerticle.scala

View check run for this annotation

Codecov / codecov/patch

modules/fbs-runner/checker/src/main/scala/de/thm/ii/fbs/verticles/runner/SqlPlaygroundVerticle.scala#L107-L108

Added lines #L107 - L108 were not covered by tests

sqlPlayground.executeStatement().onComplete({
sqlPlayground.executeStatement() andThen {
case Success(value) =>
try {
logger.info(s"Execution-${runArgs.executionId} Finished")
Expand All @@ -112,7 +123,7 @@ class SqlPlaygroundVerticle extends ScalaVerticle {
handleError(runArgs, ex, getSQLErrorMsg(runArgs, ex))
case Failure(ex) =>
handleError(runArgs, ex)
})
}
}

private def handleError(runArgs: SqlPlaygroundRunArgs, e: Throwable, msg: String = "Die Ausführung des Statements ist fehlgeschlagen."): Unit = {
Expand Down

0 comments on commit c1f0c66

Please sign in to comment.