Skip to content

Commit 13c068e

Browse files
Improve logging of workflow scheduling (#802)
* Use `scala-logging` instead of `slf4j` directly * Add log messages to the workflow scheduling part * Standardize logs to some extent so we can track logs for a particular workflow id. Closes #802 --------- Co-authored-by: jozefbakus <[email protected]>
1 parent 1c9dc98 commit 13c068e

37 files changed

+350
-203
lines changed

pom.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
<quartz.version>2.3.2</quartz.version>
8787
<log4j.version>2.17.1</log4j.version>
8888
<slf4j.log4j2.version>1.7.26</slf4j.log4j2.version>
89+
<scala-logging.version>3.9.5</scala-logging.version>
8990
<spring.security.ldap.version>5.6.1</spring.security.ldap.version>
9091
<spring.kerberos.version>1.0.1.RELEASE</spring.kerberos.version>
9192
<scalatest.version>3.0.5</scalatest.version>
@@ -153,6 +154,29 @@
153154
<artifactId>log4j-to-slf4j</artifactId>
154155
<version>${log4j.version}</version>
155156
</dependency>
157+
<dependency>
158+
<groupId>com.typesafe.scala-logging</groupId>
159+
<artifactId>scala-logging_${scala.compat.version}</artifactId>
160+
<version>${scala-logging.version}</version>
161+
<exclusions>
162+
<exclusion>
163+
<groupId>org.scalatestplus</groupId>
164+
<artifactId>mockito-3-4_2.12</artifactId>
165+
</exclusion>
166+
<exclusion>
167+
<groupId>org.scalatest</groupId>
168+
<artifactId>scalatest_2.12</artifactId>
169+
</exclusion>
170+
<exclusion>
171+
<groupId>org.scala-lang</groupId>
172+
<artifactId>scala-library</artifactId>
173+
</exclusion>
174+
<exclusion>
175+
<groupId>org.scala-lang</groupId>
176+
<artifactId>scala-reflect</artifactId>
177+
</exclusion>
178+
</exclusions>
179+
</dependency>
156180
<dependency>
157181
<groupId>com.fasterxml.jackson.module</groupId>
158182
<artifactId>jackson-module-scala_${scala.compat.version}</artifactId>

src/main/scala/org/apache/spark/launcher/NoBackendConnectionInProcessLauncher.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@
1515

1616
package org.apache.spark.launcher
1717

18-
import org.slf4j.LoggerFactory
18+
import com.typesafe.scalalogging.LazyLogging
1919

20-
class NoBackendConnectionInProcessLauncher extends InProcessLauncher {
20+
class NoBackendConnectionInProcessLauncher extends InProcessLauncher with LazyLogging {
2121

22-
private val logger = LoggerFactory.getLogger(this.getClass)
2322
override def startApplication(listeners: SparkAppHandle.Listener*): SparkAppHandle = {
2423
import scala.collection.JavaConverters._
2524
if (builder.isClientMode(Map[String, String]().asJava)) {

src/main/scala/za/co/absa/hyperdrive/trigger/api/rest/WebSecurityConfig.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515

1616
package za.co.absa.hyperdrive.trigger.api.rest
1717

18-
import javax.inject.Inject
19-
import javax.servlet.http.{HttpServletRequest, HttpServletResponse}
20-
import org.slf4j.LoggerFactory
18+
import com.typesafe.scalalogging.LazyLogging
2119
import org.springframework.beans.factory.BeanFactory
2220
import org.springframework.context.annotation.{Bean, Configuration}
2321
import org.springframework.http.HttpStatus
@@ -49,10 +47,12 @@ import za.co.absa.hyperdrive.trigger.api.rest.auth.{
4947
}
5048
import za.co.absa.hyperdrive.trigger.configuration.application.AuthConfig
5149

50+
import javax.inject.Inject
51+
import javax.servlet.http.{HttpServletRequest, HttpServletResponse}
52+
5253
@EnableWebSecurity
5354
@EnableGlobalMethodSecurity(prePostEnabled = true)
54-
class WebSecurityConfig @Inject() (val beanFactory: BeanFactory, authConfig: AuthConfig) {
55-
private val logger = LoggerFactory.getLogger(this.getClass)
55+
class WebSecurityConfig @Inject() (val beanFactory: BeanFactory, authConfig: AuthConfig) extends LazyLogging {
5656

5757
val authMechanism: String = authConfig.mechanism
5858

src/main/scala/za/co/absa/hyperdrive/trigger/api/rest/client/AuthClient.scala

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515

1616
package za.co.absa.hyperdrive.trigger.api.rest.client
1717

18-
import org.slf4j.Logger
19-
import org.slf4j.LoggerFactory
20-
import org.springframework.http.{HttpEntity, HttpHeaders, HttpMethod, HttpStatus, ResponseEntity}
18+
import com.typesafe.scalalogging.{AnyLogging, LazyLogging}
19+
import org.springframework.http._
2120
import org.springframework.security.kerberos.client.KerberosRestTemplate
2221
import org.springframework.util.LinkedMultiValueMap
2322
import org.springframework.web.client.RestTemplate
@@ -71,8 +70,7 @@ sealed abstract class AuthClient(
7170
restTemplate: RestTemplate,
7271
apiCaller: ApiCaller,
7372
url: String => String
74-
) {
75-
protected val logger: Logger = LoggerFactory.getLogger(this.getClass)
73+
) extends AnyLogging {
7674

7775
@throws[UnauthorizedException]
7876
def authenticate(): HttpHeaders =
@@ -118,7 +116,8 @@ class SpnegoAuthClient(
118116
restTemplate: RestTemplate,
119117
apiCaller: ApiCaller,
120118
path: String
121-
) extends AuthClient(credentials, restTemplate, apiCaller, baseUrl => s"$baseUrl$path") {
119+
) extends AuthClient(credentials, restTemplate, apiCaller, baseUrl => s"$baseUrl$path")
120+
with LazyLogging {
122121
override protected def requestAuthentication(url: String): ResponseEntity[String] = {
123122
logger.info(
124123
s"Authenticating via SPNEGO ($url): user `${credentials.username}`, with keytab `${credentials.keytabLocation}`"
@@ -132,7 +131,8 @@ class StandardAuthClient(
132131
restTemplate: RestTemplate,
133132
apiCaller: ApiCaller,
134133
path: String
135-
) extends AuthClient(credentials, restTemplate, apiCaller, baseUrl => s"$baseUrl$path") {
134+
) extends AuthClient(credentials, restTemplate, apiCaller, baseUrl => s"$baseUrl$path")
135+
with LazyLogging {
136136
override protected def requestAuthentication(url: String): ResponseEntity[String] = {
137137
val requestParts = new LinkedMultiValueMap[String, String]
138138
requestParts.add("username", credentials.username)
@@ -148,7 +148,8 @@ class StandardBase64AuthClient(
148148
restTemplate: RestTemplate,
149149
apiCaller: ApiCaller,
150150
path: String
151-
) extends AuthClient(credentials, restTemplate, apiCaller, baseUrl => s"$baseUrl$path") {
151+
) extends AuthClient(credentials, restTemplate, apiCaller, baseUrl => s"$baseUrl$path")
152+
with LazyLogging {
152153
override protected def requestAuthentication(url: String): ResponseEntity[String] = {
153154
val headers = new HttpHeaders()
154155
headers.add("Authorization", "Basic " + credentials.base64Credentials)

src/main/scala/za/co/absa/hyperdrive/trigger/api/rest/client/CrossHostApiCaller.scala

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,17 @@
1515

1616
package za.co.absa.hyperdrive.trigger.api.rest.client
1717

18+
import com.typesafe.scalalogging.Logger
1819
import org.apache.commons.lang3.exception.ExceptionUtils
19-
import org.slf4j.LoggerFactory
2020
import org.springframework.web.client
2121
import org.springframework.web.client.ResourceAccessException
22-
import za.co.absa.hyperdrive.trigger.api.rest.client.CrossHostApiCaller.logger
2322

2423
import scala.annotation.tailrec
25-
import scala.util.Failure
26-
import scala.util.Random
27-
import scala.util.Try
24+
import scala.util.{Failure, Random, Try}
2825

2926
class CrossHostApiCaller private (apiBaseUrls: Vector[String], maxTryCount: Int, private var currentHostIndex: Int)
3027
extends ApiCaller {
28+
import CrossHostApiCaller._
3129
def baseUrlsCount: Int = apiBaseUrls.size
3230

3331
def currentBaseUrl: String = apiBaseUrls(currentHostIndex)
@@ -69,7 +67,7 @@ class CrossHostApiCaller private (apiBaseUrls: Vector[String], maxTryCount: Int,
6967
}
7068

7169
object CrossHostApiCaller {
72-
private val logger = LoggerFactory.getLogger(classOf[CrossHostApiCaller])
70+
private val logger = Logger[CrossHostApiCaller]
7371

7472
final val DefaultUrlsRetryCount: Int = 0
7573

src/main/scala/za/co/absa/hyperdrive/trigger/api/rest/client/RestClient.scala

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,14 @@
1515

1616
package za.co.absa.hyperdrive.trigger.api.rest.client
1717

18-
import org.slf4j.LoggerFactory
19-
import org.springframework.http.HttpEntity
20-
import org.springframework.http.HttpHeaders
21-
import org.springframework.http.HttpMethod
22-
import org.springframework.http.HttpStatus
18+
import com.typesafe.scalalogging.LazyLogging
19+
import org.springframework.http.{HttpEntity, HttpHeaders, HttpMethod, HttpStatus}
2320
import org.springframework.web.client.RestTemplate
2421

2522
import scala.annotation.tailrec
2623
import scala.reflect.ClassTag
2724

28-
class RestClient(authClient: AuthClient, restTemplate: RestTemplate) {
29-
private val logger = LoggerFactory.getLogger(this.getClass)
25+
class RestClient(authClient: AuthClient, restTemplate: RestTemplate) extends LazyLogging {
3026

3127
private var authHeaders = new HttpHeaders()
3228

src/main/scala/za/co/absa/hyperdrive/trigger/api/rest/controllers/RestErrorHandler.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,15 @@
1515

1616
package za.co.absa.hyperdrive.trigger.api.rest.controllers
1717

18-
import org.slf4j.LoggerFactory
18+
import com.typesafe.scalalogging.LazyLogging
1919
import org.springframework.http.converter.HttpMessageNotReadableException
2020
import org.springframework.http.{HttpStatus, ResponseEntity}
2121
import org.springframework.security.access.AccessDeniedException
2222
import org.springframework.web.bind.annotation.{ExceptionHandler, RestControllerAdvice}
2323
import org.springframework.web.context.request.WebRequest
2424
import za.co.absa.hyperdrive.trigger.models.errors.ApiException
2525
@RestControllerAdvice
26-
class RestErrorHandler {
27-
private val logger = LoggerFactory.getLogger(this.getClass)
26+
class RestErrorHandler extends LazyLogging {
2827

2928
@ExceptionHandler(Array(classOf[ApiException]))
3029
def handleApiException(ex: ApiException, request: WebRequest): ResponseEntity[Object] = {

src/main/scala/za/co/absa/hyperdrive/trigger/api/rest/controllers/WorkflowController.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@
1515

1616
package za.co.absa.hyperdrive.trigger.api.rest.controllers
1717

18-
import java.io.{ByteArrayInputStream, ByteArrayOutputStream}
19-
import java.util.concurrent.CompletableFuture
20-
import java.util.zip.{ZipEntry, ZipInputStream, ZipOutputStream}
21-
import javax.inject.Inject
22-
import org.slf4j.LoggerFactory
18+
import com.typesafe.scalalogging.LazyLogging
2319
import org.springframework.core.io.ByteArrayResource
2420
import org.springframework.http.{HttpHeaders, MediaType, ResponseEntity}
2521
import org.springframework.web.bind.annotation._
@@ -31,15 +27,19 @@ import za.co.absa.hyperdrive.trigger.models._
3127
import za.co.absa.hyperdrive.trigger.models.errors.{ApiException, BulkOperationError, GenericError}
3228
import za.co.absa.hyperdrive.trigger.models.search.{TableSearchRequest, TableSearchResponse}
3329

30+
import java.io.{ByteArrayInputStream, ByteArrayOutputStream}
31+
import java.util.concurrent.CompletableFuture
32+
import java.util.zip.{ZipEntry, ZipInputStream, ZipOutputStream}
33+
import javax.inject.Inject
3434
import scala.collection.mutable.ArrayBuffer
3535
import scala.compat.java8.FutureConverters._
3636
import scala.concurrent.ExecutionContext
3737
import scala.concurrent.ExecutionContext.Implicits.global
3838
import scala.util.Try
3939

4040
@RestController
41-
class WorkflowController @Inject() (workflowService: WorkflowService, generalConfig: GeneralConfig) {
42-
private val logger = LoggerFactory.getLogger(this.getClass)
41+
class WorkflowController @Inject() (workflowService: WorkflowService, generalConfig: GeneralConfig)
42+
extends LazyLogging {
4343

4444
val environment: String = generalConfig.environment
4545

src/main/scala/za/co/absa/hyperdrive/trigger/api/rest/health/DatabaseConnectionHealthIndicator.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
package za.co.absa.hyperdrive.trigger.api.rest.health
1717

18-
import org.slf4j.LoggerFactory
18+
import com.typesafe.scalalogging.Logger
1919
import org.springframework.boot.actuate.health.{Health, HealthIndicator}
2020
import org.springframework.stereotype.Component
2121
import za.co.absa.hyperdrive.trigger.configuration.application.HealthConfig
@@ -32,7 +32,7 @@ class DatabaseConnectionHealthIndicator @Inject() (val dbProvider: DatabaseProvi
3232
extends HealthIndicator
3333
with Repository {
3434
import api._
35-
private val log = LoggerFactory.getLogger(this.getClass)
35+
private val log = Logger(this.getClass)
3636
val dbConnection: Duration = Duration(healthConfig.databaseConnectionTimeoutMillis, TimeUnit.MILLISECONDS)
3737
override protected def health(): Health =
3838
Try {

src/main/scala/za/co/absa/hyperdrive/trigger/api/rest/services/CheckpointService.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515

1616
package za.co.absa.hyperdrive.trigger.api.rest.services
1717

18+
import com.typesafe.scalalogging.LazyLogging
1819
import org.apache.hadoop.fs.{Path, PathFilter}
1920
import org.apache.hadoop.security.UserGroupInformation
2021
import org.json4s.jackson.Serialization
2122
import org.json4s.{Formats, NoTypeHints}
22-
import org.slf4j.LoggerFactory
2323
import org.springframework.context.annotation.Lazy
2424
import org.springframework.stereotype.Service
2525
import za.co.absa.hyperdrive.trigger.api.rest.utils.ScalaUtil.swap
@@ -48,8 +48,7 @@ class HdfsParameters(
4848

4949
@Lazy
5050
@Service
51-
class CheckpointServiceImpl @Inject() (@Lazy hdfsService: HdfsService) extends CheckpointService {
52-
private val logger = LoggerFactory.getLogger(this.getClass)
51+
class CheckpointServiceImpl @Inject() (@Lazy hdfsService: HdfsService) extends CheckpointService with LazyLogging {
5352
private val offsetsDirName = "offsets"
5453
private val commitsDirName = "commits"
5554
private implicit val formats: Formats = Serialization.formats(NoTypeHints)

0 commit comments

Comments
 (0)