mirror of https://github.com/hykilpikonna/AquaDX
[O] Optimize logging
parent
c32d334aab
commit
685129fede
|
@ -37,6 +37,7 @@ class TokenChecker(
|
||||||
|
|
||||||
private val currentSession = ThreadLocal<KeychipSession?>()
|
private val currentSession = ThreadLocal<KeychipSession?>()
|
||||||
fun getCurrentSession() = currentSession.get()
|
fun getCurrentSession() = currentSession.get()
|
||||||
|
fun tokenShort() = getCurrentSession()?.token?.substring(0, 6) ?: "NO-TOKEN"
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -59,19 +59,19 @@ class ChusanController(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (api.startsWith("CM") && api !in handlers) api = api.removePrefix("CM")
|
if (api.startsWith("CM") && api !in handlers) api = api.removePrefix("CM")
|
||||||
val token = TokenChecker.getCurrentSession()?.token?.substring(0, 6) ?: "NO-TOKEN"
|
val token = TokenChecker.tokenShort()
|
||||||
log.info("Chu3 < $api : ${data.toJson()} : [$token]")
|
log.info("$token : $api < ${data.toJson()}")
|
||||||
|
|
||||||
val noop = """{"returnCode":"1","apiName":"$api"}"""
|
val noop = """{"returnCode":"1","apiName":"$api"}"""
|
||||||
if (api !in noopEndpoint && !handlers.containsKey(api)) {
|
if (api !in noopEndpoint && !handlers.containsKey(api)) {
|
||||||
log.warn("Chu3 > $api not found")
|
log.warn("$token : $api > not found")
|
||||||
return noop
|
return noop
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only record the counter metrics if the API is known.
|
// Only record the counter metrics if the API is known.
|
||||||
Metrics.counter("aquadx_chusan_api_call", "api" to api).increment()
|
Metrics.counter("aquadx_chusan_api_call", "api" to api).increment()
|
||||||
if (api in noopEndpoint) {
|
if (api in noopEndpoint) {
|
||||||
log.info("Chu3 > $api no-op")
|
log.info("$token : $api > no-op")
|
||||||
return noop
|
return noop
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,14 +79,11 @@ class ChusanController(
|
||||||
Metrics.timer("aquadx_chusan_api_latency", "api" to api).recordCallable {
|
Metrics.timer("aquadx_chusan_api_latency", "api" to api).recordCallable {
|
||||||
serialize(api, handlers[api]!!(ctx) ?: noop).also {
|
serialize(api, handlers[api]!!(ctx) ?: noop).also {
|
||||||
if (api !in setOf("GetUserItemApi", "GetGameEventApi"))
|
if (api !in setOf("GetUserItemApi", "GetGameEventApi"))
|
||||||
log.info("Chu3 > $api : $it")
|
log.info("$token : $api > ${it.truncate(500)}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Metrics.counter(
|
Metrics.counter("aquadx_chusan_api_error", "api" to api, "error" to e.simpleDescribe()).increment()
|
||||||
"aquadx_chusan_api_error",
|
|
||||||
"api" to api, "error" to e.simpleDescribe()
|
|
||||||
).increment()
|
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,13 +4,13 @@ import ext.*
|
||||||
import icu.samnyan.aqua.net.games.mai2.Maimai2
|
import icu.samnyan.aqua.net.games.mai2.Maimai2
|
||||||
import icu.samnyan.aqua.net.utils.ApiException
|
import icu.samnyan.aqua.net.utils.ApiException
|
||||||
import icu.samnyan.aqua.net.utils.simpleDescribe
|
import icu.samnyan.aqua.net.utils.simpleDescribe
|
||||||
|
import icu.samnyan.aqua.sega.allnet.TokenChecker
|
||||||
import icu.samnyan.aqua.sega.general.*
|
import icu.samnyan.aqua.sega.general.*
|
||||||
import icu.samnyan.aqua.sega.maimai2.handler.*
|
import icu.samnyan.aqua.sega.maimai2.handler.*
|
||||||
import icu.samnyan.aqua.sega.maimai2.model.Mai2Repos
|
import icu.samnyan.aqua.sega.maimai2.model.Mai2Repos
|
||||||
import icu.samnyan.aqua.spring.Metrics
|
import icu.samnyan.aqua.spring.Metrics
|
||||||
import io.ktor.client.request.*
|
import io.ktor.client.request.*
|
||||||
import jakarta.servlet.http.HttpServletRequest
|
import jakarta.servlet.http.HttpServletRequest
|
||||||
import org.slf4j.LoggerFactory
|
|
||||||
import org.springframework.web.bind.annotation.*
|
import org.springframework.web.bind.annotation.*
|
||||||
import java.time.format.DateTimeFormatter
|
import java.time.format.DateTimeFormatter
|
||||||
import kotlin.reflect.full.declaredMemberProperties
|
import kotlin.reflect.full.declaredMemberProperties
|
||||||
|
@ -38,7 +38,7 @@ class Maimai2ServletController(
|
||||||
): MeowApi(serialize = { _, resp -> if (resp is String) resp else resp.toJson() }) {
|
): MeowApi(serialize = { _, resp -> if (resp is String) resp else resp.toJson() }) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val logger = LoggerFactory.getLogger(Maimai2ServletController::class.java)
|
private val log = logger()
|
||||||
private val empty = listOf<Any>()
|
private val empty = listOf<Any>()
|
||||||
private val GAME_SETTING_DATE_FMT = DateTimeFormatter.ofPattern("2010-01-01 HH:mm:00.0")
|
private val GAME_SETTING_DATE_FMT = DateTimeFormatter.ofPattern("2010-01-01 HH:mm:00.0")
|
||||||
private val GAME_SETTING_TIME_FMT = DateTimeFormatter.ofPattern("HH:mm:00")
|
private val GAME_SETTING_TIME_FMT = DateTimeFormatter.ofPattern("HH:mm:00")
|
||||||
|
@ -67,10 +67,12 @@ class Maimai2ServletController(
|
||||||
|
|
||||||
@API("/{api}")
|
@API("/{api}")
|
||||||
fun handle(@PathVariable api: String, @RequestBody data: Map<String, Any>, req: HttpServletRequest): Any {
|
fun handle(@PathVariable api: String, @RequestBody data: Map<String, Any>, req: HttpServletRequest): Any {
|
||||||
logger.info("Mai2 < $api : ${data.toJson()}") // TODO: Optimize logging
|
val token = TokenChecker.tokenShort()
|
||||||
|
log.info("$token : $api < ${data.toJson()}")
|
||||||
|
|
||||||
val noop = """{"returnCode":1,"apiName":"com.sega.maimai2servlet.api.$api"}"""
|
val noop = """{"returnCode":1,"apiName":"com.sega.maimai2servlet.api.$api"}"""
|
||||||
if (api !in noopEndpoint && !handlers.containsKey(api)) {
|
if (api !in noopEndpoint && !handlers.containsKey(api)) {
|
||||||
logger.warn("Mai2 > $api not found")
|
log.warn("$token : $api > not found")
|
||||||
return noop
|
return noop
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +80,7 @@ class Maimai2ServletController(
|
||||||
Metrics.counter("aquadx_maimai2_api_call", "api" to api).increment()
|
Metrics.counter("aquadx_maimai2_api_call", "api" to api).increment()
|
||||||
|
|
||||||
if (api in noopEndpoint) {
|
if (api in noopEndpoint) {
|
||||||
logger.info("Mai2 > $api no-op")
|
log.info("$token : $api > no-op")
|
||||||
return noop
|
return noop
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +88,7 @@ class Maimai2ServletController(
|
||||||
Metrics.timer("aquadx_maimai2_api_latency", "api" to api).recordCallable {
|
Metrics.timer("aquadx_maimai2_api_latency", "api" to api).recordCallable {
|
||||||
val ctx = RequestContext(req, data.mut)
|
val ctx = RequestContext(req, data.mut)
|
||||||
serialize(api, handlers[api]!!(ctx) ?: noop).also {
|
serialize(api, handlers[api]!!(ctx) ?: noop).also {
|
||||||
logger.info("Mai2 > $api : ${it.truncate(1000)}")
|
log.info("$token : $api > ${it.truncate(500)}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
|
|
@ -38,19 +38,19 @@ class OngekiController(
|
||||||
val ctx = RequestContext(req, data)
|
val ctx = RequestContext(req, data)
|
||||||
version?.let { data["version"] = it }
|
version?.let { data["version"] = it }
|
||||||
|
|
||||||
val token = TokenChecker.getCurrentSession()?.token?.substring(0, 6) ?: "NO-TOKEN"
|
val token = TokenChecker.tokenShort()
|
||||||
log.info("< $api : ${data.toJson()} : [$token]")
|
log.info("$token : $api < ${data.toJson()}")
|
||||||
|
|
||||||
val noop = """{"returnCode":"1","apiName":"$api"}"""
|
val noop = """{"returnCode":"1","apiName":"${api.substringBefore("Api").firstCharLower()}"}"""
|
||||||
if (api !in noopEndpoint && !handlers.containsKey(api)) {
|
if (api !in noopEndpoint && !handlers.containsKey(api)) {
|
||||||
log.warn("> $api not found")
|
log.warn("$token : $api > not found")
|
||||||
return noop
|
return noop
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only record the counter metrics if the API is known.
|
// Only record the counter metrics if the API is known.
|
||||||
Metrics.counter("aquadx_ongeki_api_call", "api" to api).increment()
|
Metrics.counter("aquadx_ongeki_api_call", "api" to api).increment()
|
||||||
if (api in noopEndpoint) {
|
if (api in noopEndpoint) {
|
||||||
log.info("> $api no-op")
|
log.info("$token : $api > no-op")
|
||||||
return noop
|
return noop
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,14 +58,11 @@ class OngekiController(
|
||||||
Metrics.timer("aquadx_ongeki_api_latency", "api" to api).recordCallable {
|
Metrics.timer("aquadx_ongeki_api_latency", "api" to api).recordCallable {
|
||||||
serialize(api, handlers[api]!!(ctx) ?: noop).also {
|
serialize(api, handlers[api]!!(ctx) ?: noop).also {
|
||||||
if (api !in setOf("GetUserItemApi", "GetGameEventApi"))
|
if (api !in setOf("GetUserItemApi", "GetGameEventApi"))
|
||||||
log.info("> $api : $it")
|
log.info("$token : $api > ${it.truncate(500)}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Metrics.counter(
|
Metrics.counter("aquadx_ongeki_api_error", "api" to api, "error" to e.simpleDescribe()).increment()
|
||||||
"aquadx_ongeki_api_error",
|
|
||||||
"api" to api, "error" to e.simpleDescribe()
|
|
||||||
).increment()
|
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,6 @@ class OngekiUserEntity : BaseEntity(), IUserEntity<UserData> {
|
||||||
override var user: UserData = UserData()
|
override var user: UserData = UserData()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Entity(name = "OngekiUserData")
|
@Entity(name = "OngekiUserData")
|
||||||
@Table(name = "ongeki_user_data")
|
@Table(name = "ongeki_user_data")
|
||||||
class UserData : IUserData {
|
class UserData : IUserData {
|
||||||
|
@ -503,9 +502,6 @@ class UserEventMap : OngekiUserEntity() {
|
||||||
var totalUsePoint = 0
|
var totalUsePoint = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @author samnyan (privateamusement@protonmail.com)
|
|
||||||
*/
|
|
||||||
@Entity(name = "OngekiUserSkin")
|
@Entity(name = "OngekiUserSkin")
|
||||||
@Table(name = "ongeki_user_skin")
|
@Table(name = "ongeki_user_skin")
|
||||||
class UserSkin : OngekiUserEntity() {
|
class UserSkin : OngekiUserEntity() {
|
||||||
|
|
Loading…
Reference in New Issue