From 0c739f22a21ed25b010ebec1c435001a2f5ae9b6 Mon Sep 17 00:00:00 2001 From: Aaron Klish Date: Mon, 16 Aug 2021 11:38:54 -0500 Subject: [PATCH 1/2] Enabling better logging --- ws/build.gradle.kts | 4 +++- .../com/yahoo/yavin/ws/security/UserDetailsService.kt | 4 ++++ ws/src/main/resources/logback-access-spring.xml | 2 +- ws/src/main/resources/logback-spring.xml | 9 ++++++--- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/ws/build.gradle.kts b/ws/build.gradle.kts index ab9221e..cfea23a 100644 --- a/ws/build.gradle.kts +++ b/ws/build.gradle.kts @@ -30,8 +30,10 @@ dependencies { } implementation("org.springframework.boot:spring-boot-starter-security") implementation("org.jetbrains.kotlin:kotlin-reflect") - implementation("com.yahoo.elide", "elide-spring-boot-starter", "5.0.2") + implementation("com.yahoo.elide", "elide-spring-boot-starter", "5.0.9") + implementation("org.projectlombok", "lombok", "1.18.20") implementation("com.h2database", "h2", "1.3.176") + implementation("net.rakugakibox.spring.boot:logback-access-spring-boot-starter:2.7.1") // drivers for models runtimeOnly("org.apache.hive","hive-jdbc","3.1.2"){ exclude(group="org.apache.logging.log4j", module = "log4j-slf4j-impl") diff --git a/ws/src/main/kotlin/com/yahoo/yavin/ws/security/UserDetailsService.kt b/ws/src/main/kotlin/com/yahoo/yavin/ws/security/UserDetailsService.kt index 0318c7b..4560ee9 100644 --- a/ws/src/main/kotlin/com/yahoo/yavin/ws/security/UserDetailsService.kt +++ b/ws/src/main/kotlin/com/yahoo/yavin/ws/security/UserDetailsService.kt @@ -5,17 +5,21 @@ package com.yahoo.yavin.ws.security +import lombok.extern.slf4j.Slf4j +import org.slf4j.MDC import org.springframework.security.core.userdetails.UserDetails import org.springframework.security.core.userdetails.UserDetailsService import org.springframework.security.core.userdetails.UsernameNotFoundException import org.springframework.stereotype.Service @Service +@Slf4j class UserDetailsService(private val userRepository: UserRepository) : UserDetailsService { override fun loadUserByUsername(username: String): UserDetails { val user = userRepository.findOneById(username) ?: throw UsernameNotFoundException("User Not Found!") + MDC.put("user", user.id) return UserDetails(user) } } diff --git a/ws/src/main/resources/logback-access-spring.xml b/ws/src/main/resources/logback-access-spring.xml index 7bae3ea..54fa395 100644 --- a/ws/src/main/resources/logback-access-spring.xml +++ b/ws/src/main/resources/logback-access-spring.xml @@ -10,7 +10,7 @@ 100MB - %t{yyyy-MM-dd:HH:mm:ss Z} %remoteIP %user %requestURL %statusCode %bytesSent %elapsedTime %header{X-B3-TraceId} %requestContent %responseContent + %t{yyyy-MM-dd:HH:mm:ss Z} %remoteIP %user %requestURL %statusCode %bytesSent %elapsedTime %header{X-B3-TraceId} %requestContent diff --git a/ws/src/main/resources/logback-spring.xml b/ws/src/main/resources/logback-spring.xml index fff375a..b3d0269 100644 --- a/ws/src/main/resources/logback-spring.xml +++ b/ws/src/main/resources/logback-spring.xml @@ -12,7 +12,7 @@ ${logDir}/server.log - %d{dd-MM-yyyy HH:mm:ss.SSS} [%thread] [${springAppName}, %X{X-B3-TraceId:-}] %-5level %logger{36}.%M - %msg%n + %d{dd-MM-yyyy HH:mm:ss.SSS} [%thread] [${springAppName}, %X{X-B3-TraceId:-}] %-5level %logger{36}.%M %mdc{user} - %msg%n ${logDir}/archived/server_%d{yyyy-MM-dd}.log @@ -26,7 +26,10 @@ - + + + + @@ -36,4 +39,4 @@ - \ No newline at end of file + From 3bcc8788e1b3d7cf6065990a8435dc6dcca290f5 Mon Sep 17 00:00:00 2001 From: Aaron Klish Date: Mon, 16 Aug 2021 11:42:25 -0500 Subject: [PATCH 2/2] Added batch fetching --- ws/src/main/resources/application.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ws/src/main/resources/application.yaml b/ws/src/main/resources/application.yaml index d79a567..d321780 100644 --- a/ws/src/main/resources/application.yaml +++ b/ws/src/main/resources/application.yaml @@ -39,6 +39,9 @@ spring: ddl-auto: 'none' jdbc: use_scrollable_resultset: true + properties: + hibernate: + default_batch_fetch_size: 100 datasource: url: 'jdbc:h2:file:./build/yavin;DB_CLOSE_DELAY=-1' username: 'navidev'