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

#414 - LogsViewer - fixes #482

Merged
merged 4 commits into from
Jan 18, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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<Log> {
Expand All @@ -45,4 +56,8 @@ class LogController : RoutingHandlerFactory {
.map { it.asLog() }
.sortedBy { it.seq }
}

companion object {
val LOGGER: Logger = LoggerFactory.getLogger(LogController::class.java)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
31 changes: 17 additions & 14 deletions cogboard-local-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ networks:
driver: overlay
attachable: true

volumes:
mongo-data:

services:
api-mocks:
image: rodolpheche/wiremock
Expand All @@ -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"
Expand All @@ -37,29 +40,29 @@ services:
# ports:
# - "18092:18092"

mongo:
mongo-logs-storage:
image: mongo:4
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: ${MONGO_USER:-root}
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}"
Expand Down
4 changes: 2 additions & 2 deletions gradle/prepareCogboardCompose.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down