diff --git a/cogboard-app/src/main/kotlin/com/cognifide/cogboard/logStorage/LogController.kt b/cogboard-app/src/main/kotlin/com/cognifide/cogboard/logStorage/LogController.kt index 134ad99c..ee6c0110 100644 --- a/cogboard-app/src/main/kotlin/com/cognifide/cogboard/logStorage/LogController.kt +++ b/cogboard-app/src/main/kotlin/com/cognifide/cogboard/logStorage/LogController.kt @@ -10,8 +10,11 @@ import io.knotx.server.api.handler.RoutingHandlerFactory import io.vertx.core.Handler import io.vertx.core.json.JsonArray import io.vertx.core.json.JsonObject +import io.vertx.core.logging.Logger +import io.vertx.core.logging.LoggerFactory import io.vertx.reactivex.core.Vertx import io.vertx.reactivex.ext.web.RoutingContext +import java.time.Instant class LogController : RoutingHandlerFactory { @@ -33,7 +36,15 @@ class LogController : RoutingHandlerFactory { .getInteger(Props.LOG_LINES) ?: LogViewerWidget.DEFAULT_LOG_LINES.toInt() - return fetchLogs(id, logLines) + return if (LOGGER.isDebugEnabled) { + val start = Instant.now() + val logs = fetchLogs(id, logLines) + val took = Instant.now().minusMillis(start.toEpochMilli()).toEpochMilli() + LOGGER.debug("DB query for $id took $took[ms] for getting $logLines (processed logs: ${logs.size})") + logs + } else { + fetchLogs(id, logLines) + } } private fun fetchLogs(id: String, logLines: Int): List { @@ -45,4 +56,8 @@ class LogController : RoutingHandlerFactory { .map { it.asLog() } .sortedBy { it.seq } } + + companion object { + val LOGGER: Logger = LoggerFactory.getLogger(LogController::class.java) + } } diff --git a/cogboard-app/src/main/kotlin/com/cognifide/cogboard/logStorage/LogStorage.kt b/cogboard-app/src/main/kotlin/com/cognifide/cogboard/logStorage/LogStorage.kt index 6fc99c2f..f977e28a 100644 --- a/cogboard-app/src/main/kotlin/com/cognifide/cogboard/logStorage/LogStorage.kt +++ b/cogboard-app/src/main/kotlin/com/cognifide/cogboard/logStorage/LogStorage.kt @@ -247,7 +247,7 @@ class LogStorage( private const val MONGO_SCHEME = "mongodb" private val MONGO_USERNAME = System.getenv("MONGO_USERNAME") ?: "root" private val MONGO_PASSWORD = System.getenv("MONGO_PASSWORD") ?: "root" - private val MONGO_HOST = System.getenv("MONGO_HOST") ?: "mongo" + private val MONGO_HOST = System.getenv("MONGO_HOST") ?: "mongo-logs-storage" private val MONGO_PORT = System.getenv("MONGO_PORT")?.toIntOrNull() ?: 27017 /** Returns a shared instance of the Mongo client. */ diff --git a/cogboard-local-compose.yml b/cogboard-local-compose.yml index 876a70d8..5b2ab9ac 100644 --- a/cogboard-local-compose.yml +++ b/cogboard-local-compose.yml @@ -5,6 +5,9 @@ networks: driver: overlay attachable: true +volumes: + mongo-data: + services: api-mocks: image: rodolpheche/wiremock @@ -28,7 +31,7 @@ services: - COGBOARD_VERSION=${COGBOARD_VERSION} - MONGO_USERNAME=${MONGO_USER:-root} - MONGO_PASSWORD=${MONGO_PASSWORD:-root} - - MONGO_HOST=mongo + - MONGO_HOST=mongo-logs-storage - MONGO_PORT=27017 volumes: - "./mnt:/data" @@ -37,7 +40,7 @@ services: # ports: # - "18092:18092" - mongo: + mongo-logs-storage: image: mongo:4 restart: always environment: @@ -45,21 +48,21 @@ services: MONGO_INITDB_ROOT_PASSWORD: ${MONGO_PASSWORD:-root} MONGO_INITDB_DATABASE: "logs" volumes: - - "./mnt/mongo:/data/db" + - "mongo-data:/data/db" networks: - cognet - mongo-express: - image: mongo-express - restart: always - ports: - - 8099:8081 - environment: - ME_CONFIG_MONGODB_ADMINUSERNAME: ${MONGO_USER:-root} - ME_CONFIG_MONGODB_ADMINPASSWORD: ${MONGO_PASSWORD:-root} - ME_CONFIG_MONGODB_URL: "mongodb://${MONGO_USER}:${MONGO_PASSWORD}@mongo:27017/" - networks: - - cognet + # mongo-logs-storage-viewer: + # image: mongo-express + # restart: always + # ports: + # - 8099:8081 + # environment: + # ME_CONFIG_MONGODB_ADMINUSERNAME: ${MONGO_USER:-root} + # ME_CONFIG_MONGODB_ADMINPASSWORD: ${MONGO_PASSWORD:-root} + # ME_CONFIG_MONGODB_URL: "mongodb://${MONGO_USER}:${MONGO_PASSWORD}@mongo:27017/" + # networks: + # - cognet frontend: image: "cogboard/cogboard-web:${COGBOARD_VERSION}" diff --git a/gradle/prepareCogboardCompose.gradle.kts b/gradle/prepareCogboardCompose.gradle.kts index f3657d03..236b9baa 100644 --- a/gradle/prepareCogboardCompose.gradle.kts +++ b/gradle/prepareCogboardCompose.gradle.kts @@ -23,8 +23,8 @@ services: volumes: - "./mnt:/data" - mongo: - image: mongo + mongo-logs-storage: + image: mongo:4 restart: always environment: MONGO_INITDB_ROOT_USERNAME: "$user"