diff --git a/mongocamp-cli/src/main/scala/dev/mongocamp/server/cli/StartApplicationCommand.scala b/mongocamp-cli/src/main/scala/dev/mongocamp/server/cli/StartApplicationCommand.scala index 3dd4f8a..87ad407 100755 --- a/mongocamp-cli/src/main/scala/dev/mongocamp/server/cli/StartApplicationCommand.scala +++ b/mongocamp-cli/src/main/scala/dev/mongocamp/server/cli/StartApplicationCommand.scala @@ -2,10 +2,10 @@ package dev.mongocamp.server.cli import better.files.File import com.typesafe.scalalogging.LazyLogging -import dev.mongocamp.server.cli.service.{JvmStartService, ProcessExecutorService, ServerService} +import dev.mongocamp.server.cli.service.{ JvmStartService, ProcessExecutorService, ServerService } import dev.mongocamp.server.service.PluginService import picocli.CommandLine.Help.Ansi -import picocli.CommandLine.{Command, Parameters} +import picocli.CommandLine.{ Command, Parameters } import java.util.concurrent.Callable import scala.sys.process diff --git a/mongocamp-cli/src/main/scala/dev/mongocamp/server/cli/service/JvmStartService.scala b/mongocamp-cli/src/main/scala/dev/mongocamp/server/cli/service/JvmStartService.scala index dda51dd..413223b 100755 --- a/mongocamp-cli/src/main/scala/dev/mongocamp/server/cli/service/JvmStartService.scala +++ b/mongocamp-cli/src/main/scala/dev/mongocamp/server/cli/service/JvmStartService.scala @@ -6,7 +6,7 @@ import dev.mongocamp.server.service.CoursierModuleService object JvmStartService { def startServer(): scala.sys.process.Process = { - val jars = CoursierModuleService.loadServerWithAllDependencies() + val jars = CoursierModuleService.loadServerWithAllDependencies() val runCommand = s"${JvmService.javaHome}/bin/java -cp ${jars.mkString(":")} ${BuildInfo.mainClass}" ProcessExecutorService.stoutProcessBuilder(runCommand) } diff --git a/mongocamp-cli/src/main/scala/dev/mongocamp/server/cli/service/ProcessExecutorService.scala b/mongocamp-cli/src/main/scala/dev/mongocamp/server/cli/service/ProcessExecutorService.scala index c8e98ab..97d44fb 100755 --- a/mongocamp-cli/src/main/scala/dev/mongocamp/server/cli/service/ProcessExecutorService.scala +++ b/mongocamp-cli/src/main/scala/dev/mongocamp/server/cli/service/ProcessExecutorService.scala @@ -20,7 +20,8 @@ object ProcessExecutorService { } var responseString = "" var errorString = "" - val stringProcessLogger = ProcessLogger(stout => responseString = appendString(responseString, stout), sterr => errorString = appendString(errorString, sterr)) + val stringProcessLogger = + ProcessLogger(stout => responseString = appendString(responseString, stout), sterr => errorString = appendString(errorString, sterr)) val responseCode = executable.!(stringProcessLogger) if (responseCode != 0) { throw new RuntimeException(s"Error while executing command: $executable\n$responseString\n$errorString") @@ -37,6 +38,7 @@ object ProcessExecutorService { process } - def stoutProcessLogger: ProcessLogger = ProcessLogger(stout => println(Ansi.AUTO.string(s"@|green $stout|@")), sterr => println(Ansi.AUTO.string(s"@|red $sterr|@"))) + def stoutProcessLogger: ProcessLogger = + ProcessLogger(stout => println(Ansi.AUTO.string(s"@|green $stout|@")), sterr => println(Ansi.AUTO.string(s"@|red $sterr|@"))) } diff --git a/mongocamp-cli/src/main/scala/dev/mongocamp/server/cli/service/ServerService.scala b/mongocamp-cli/src/main/scala/dev/mongocamp/server/cli/service/ServerService.scala index 116de4c..1563808 100644 --- a/mongocamp-cli/src/main/scala/dev/mongocamp/server/cli/service/ServerService.scala +++ b/mongocamp-cli/src/main/scala/dev/mongocamp/server/cli/service/ServerService.scala @@ -32,9 +32,8 @@ object ServerService { val jsonString = file.contentAsString val jsonMapParseResult = decode[Map[String, String]](jsonString) val jsonMap = jsonMapParseResult.getOrElse(throw new Exception(s"Could not parse file ${file.toString()}")) - while (System.currentTimeMillis() < jsonMap("timestamp").toLong) { + while (System.currentTimeMillis() < jsonMap("timestamp").toLong) "wait" - } bootServer(monitoredSystemMode) case EventType.ENTRY_MODIFY => case EventType.ENTRY_DELETE => diff --git a/mongocamp-plugin-micrometer/src/main/scala/dev/mongocamp/server/plugins/monitoring/MetricsConfiguration.scala b/mongocamp-plugin-micrometer/src/main/scala/dev/mongocamp/server/plugins/monitoring/MetricsConfiguration.scala index 6a0ae3e..24e73db 100644 --- a/mongocamp-plugin-micrometer/src/main/scala/dev/mongocamp/server/plugins/monitoring/MetricsConfiguration.scala +++ b/mongocamp-plugin-micrometer/src/main/scala/dev/mongocamp/server/plugins/monitoring/MetricsConfiguration.scala @@ -71,10 +71,18 @@ object MetricsConfiguration { def addEventMeterBinder(meterBinder: MeterBinder): Unit = eventMeterBinder += meterBinder def bindAll(): Unit = { - getJvmMetricsRegistries.foreach(r => jvmMeterBinder.foreach(_.bindTo(r))) - getSystemMetricsRegistries.foreach(r => systemMeterBinder.foreach(_.bindTo(r))) - getMongoDbMetricsRegistries.foreach(r => mongoDbMeterBinder.foreach(_.bindTo(r))) - getEventMetricsRegistries.foreach(r => eventMeterBinder.foreach(_.bindTo(r))) + getJvmMetricsRegistries.foreach( + r => jvmMeterBinder.foreach(_.bindTo(r)) + ) + getSystemMetricsRegistries.foreach( + r => systemMeterBinder.foreach(_.bindTo(r)) + ) + getMongoDbMetricsRegistries.foreach( + r => mongoDbMeterBinder.foreach(_.bindTo(r)) + ) + getEventMetricsRegistries.foreach( + r => eventMeterBinder.foreach(_.bindTo(r)) + ) } } diff --git a/mongocamp-plugin-micrometer/src/main/scala/dev/mongocamp/server/plugins/monitoring/metrics/DefaultMetricsPlugin.scala b/mongocamp-plugin-micrometer/src/main/scala/dev/mongocamp/server/plugins/monitoring/metrics/DefaultMetricsPlugin.scala index 0912580..fe0fa33 100644 --- a/mongocamp-plugin-micrometer/src/main/scala/dev/mongocamp/server/plugins/monitoring/metrics/DefaultMetricsPlugin.scala +++ b/mongocamp-plugin-micrometer/src/main/scala/dev/mongocamp/server/plugins/monitoring/metrics/DefaultMetricsPlugin.scala @@ -1,7 +1,7 @@ package dev.mongocamp.server.plugins.monitoring.metrics import com.typesafe.scalalogging.LazyLogging -import dev.mongocamp.server.event.{Event, EventSystem} +import dev.mongocamp.server.event.{ Event, EventSystem } import dev.mongocamp.server.plugin.ServerPlugin import dev.mongocamp.server.plugins.monitoring.MetricsConfiguration import io.micrometer.core.instrument.simple.SimpleMeterRegistry diff --git a/mongocamp-plugin-micrometer/src/main/scala/dev/mongocamp/server/plugins/monitoring/model/Metric.scala b/mongocamp-plugin-micrometer/src/main/scala/dev/mongocamp/server/plugins/monitoring/model/Metric.scala index 845e47d..f7b8f47 100644 --- a/mongocamp-plugin-micrometer/src/main/scala/dev/mongocamp/server/plugins/monitoring/model/Metric.scala +++ b/mongocamp-plugin-micrometer/src/main/scala/dev/mongocamp/server/plugins/monitoring/model/Metric.scala @@ -18,7 +18,9 @@ object Metric extends LazyLogging { .measure() .asScala .toList - .map(v => Measurement(validStringValue(v.getStatistic.name()), validDoubleValue(v.getValue))) + .map( + v => Measurement(validStringValue(v.getStatistic.name()), validDoubleValue(v.getValue)) + ) ) } diff --git a/mongocamp-plugin-micrometer/src/main/scala/dev/mongocamp/server/plugins/monitoring/mongodb/MongoDbMetricsPlugin.scala b/mongocamp-plugin-micrometer/src/main/scala/dev/mongocamp/server/plugins/monitoring/mongodb/MongoDbMetricsPlugin.scala index 2cd2339..1b83105 100644 --- a/mongocamp-plugin-micrometer/src/main/scala/dev/mongocamp/server/plugins/monitoring/mongodb/MongoDbMetricsPlugin.scala +++ b/mongocamp-plugin-micrometer/src/main/scala/dev/mongocamp/server/plugins/monitoring/mongodb/MongoDbMetricsPlugin.scala @@ -56,36 +56,48 @@ object MongoDbMetricsPlugin extends ServerPlugin with LazyLogging { val registerFunctionsList: ArrayBuffer[() => Unit] = ArrayBuffer() if (ConfigurationService.getConfigValue[Boolean](ConfKeyMetricsCommand)) { - registerFunctionsList += { () => - { - MetricsConfiguration.getMongoDbMetricsRegistries.foreach(r => { - val commandListener = new MongoMetricsCommandListener(r) - MongoDatabase.registerCommandListener(commandListener) - }) - } + registerFunctionsList += { + () => + { + MetricsConfiguration.getMongoDbMetricsRegistries.foreach( + r => { + val commandListener = new MongoMetricsCommandListener(r) + MongoDatabase.registerCommandListener(commandListener) + } + ) + } } } if (ConfigurationService.getConfigValue[Boolean](ConfKeyMetricsConnectionpool)) { - registerFunctionsList += { () => - { - MetricsConfiguration.getMongoDbMetricsRegistries.foreach(r => { - val commandListener = new MongoMetricsConnectionPoolListener(r) - MongoDatabase.registerConnectionPoolListener(commandListener) - }) - } + registerFunctionsList += { + () => + { + MetricsConfiguration.getMongoDbMetricsRegistries.foreach( + r => { + val commandListener = new MongoMetricsConnectionPoolListener(r) + MongoDatabase.registerConnectionPoolListener(commandListener) + } + ) + } } } ConfigurationService .getConfigValue[List[String]](ConfKeyMetricsCollectionList) - .foreach(collection => MetricsConfiguration.addMongoDbBinder(CollectionMetrics(MongoDatabase.databaseProvider.database(), collection))) - - Server.registerAfterStartCallBack(() => { - MetricsConfiguration.bindAll() - registerFunctionsList.foreach(f => f()) - MongoDatabase.createNewDatabaseProvider() - }) + .foreach( + collection => MetricsConfiguration.addMongoDbBinder(CollectionMetrics(MongoDatabase.databaseProvider.database(), collection)) + ) + + Server.registerAfterStartCallBack( + () => { + MetricsConfiguration.bindAll() + registerFunctionsList.foreach( + f => f() + ) + MongoDatabase.createNewDatabaseProvider() + } + ) } } diff --git a/mongocamp-plugin-micrometer/src/main/scala/dev/mongocamp/server/plugins/monitoring/routes/MetricsRoutes.scala b/mongocamp-plugin-micrometer/src/main/scala/dev/mongocamp/server/plugins/monitoring/routes/MetricsRoutes.scala index 49a2d9b..594cf84 100644 --- a/mongocamp-plugin-micrometer/src/main/scala/dev/mongocamp/server/plugins/monitoring/routes/MetricsRoutes.scala +++ b/mongocamp-plugin-micrometer/src/main/scala/dev/mongocamp/server/plugins/monitoring/routes/MetricsRoutes.scala @@ -8,7 +8,7 @@ import dev.mongocamp.server.route.BaseRoute import io.circe.generic.auto._ import sttp.capabilities.WebSockets import sttp.capabilities.pekko.PekkoStreams -import sttp.model.{Method, StatusCode} +import sttp.model.{ Method, StatusCode } import sttp.tapir._ import sttp.tapir.json.circe.jsonBody import sttp.tapir.server.ServerEndpoint @@ -26,7 +26,9 @@ object MetricsRoutes extends BaseRoute with RoutesPlugin { .description("Returns the JVM Metrics of the running MongoCamp Application") .method(Method.GET) .name("jvmMetrics") - .serverLogic(_ => _ => jvmMetrics()) + .serverLogic( + _ => _ => jvmMetrics() + ) def jvmMetrics(): Future[Either[(StatusCode, ErrorDescription, ErrorDescription), List[Metric]]] = { Future.successful(Right({ @@ -42,7 +44,9 @@ object MetricsRoutes extends BaseRoute with RoutesPlugin { .description("Returns the Metrics of the MongoCamp System") .method(Method.GET) .name("systemMetrics") - .serverLogic(_ => _ => systemMetrics()) + .serverLogic( + _ => _ => systemMetrics() + ) def systemMetrics(): Future[Either[(StatusCode, ErrorDescription, ErrorDescription), List[Metric]]] = { Future.successful(Right({ @@ -58,7 +62,9 @@ object MetricsRoutes extends BaseRoute with RoutesPlugin { .description("Returns the MongoDB Metrics of the running MongoCamp Application") .method(Method.GET) .name("mongoDbMetrics") - .serverLogic(_ => _ => mongoDbMetrics()) + .serverLogic( + _ => _ => mongoDbMetrics() + ) def mongoDbMetrics(): Future[Either[(StatusCode, ErrorDescription, ErrorDescription), List[Metric]]] = { Future.successful(Right({ @@ -74,7 +80,9 @@ object MetricsRoutes extends BaseRoute with RoutesPlugin { .description("Returns the Metrics of events of the running MongoCamp Application.") .method(Method.GET) .name("eventMetrics") - .serverLogic(_ => _ => eventMetrics()) + .serverLogic( + _ => _ => eventMetrics() + ) def eventMetrics(): Future[Either[(StatusCode, ErrorDescription, ErrorDescription), List[Metric]]] = { Future.successful(Right({ diff --git a/mongocamp-server/src/main/scala/dev/mongocamp/server/route/ConfigurationRoutes.scala b/mongocamp-server/src/main/scala/dev/mongocamp/server/route/ConfigurationRoutes.scala index 263a27e..4b43759 100755 --- a/mongocamp-server/src/main/scala/dev/mongocamp/server/route/ConfigurationRoutes.scala +++ b/mongocamp-server/src/main/scala/dev/mongocamp/server/route/ConfigurationRoutes.scala @@ -143,9 +143,9 @@ object ConfigurationRoutes extends BaseRoute with RoutesPlugin with LazyLogging Right { Future { if (!force) { - val temp = File(File.temp.pathAsString + s"/mongocamp_${BuildInfo.version}") - val tmpFile = File.newTemporaryFile(parent = Some(temp)) - val pid = ProcessHandle.current.pid + val temp = File(File.temp.pathAsString + s"/mongocamp_${BuildInfo.version}") + val tmpFile = File.newTemporaryFile(parent = Some(temp)) + val pid = ProcessHandle.current.pid val shutdownTimestamp = System.currentTimeMillis() + 1.seconds.toMillis tmpFile.write("{\"event\":\"shutdown\",\"timestamp\":\"" + shutdownTimestamp + "\",\"pid\":\"" + pid + "\"}") tmpFile.appendLine() diff --git a/package.json b/package.json index 0190c13..2891d10 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name" : "mongocamp-server", "organization" : "dev.mongocamp", - "version" : "1.5.10", + "version" : "1.5.11.snapshot", "description" : "", "directories" : { "doc" : "docs"