Use DamlContextualizedErrorLogger.forTesting (#13137)

changelog_begin
changelog_end
This commit is contained in:
pbatko-da 2022-03-04 12:24:08 +01:00 committed by GitHub
parent 0002b7ebae
commit 15aa300fba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 17 additions and 42 deletions

View File

@ -24,11 +24,12 @@ trait ContextualizedErrorLogger {
object DamlContextualizedErrorLogger {
def forTesting(clazz: Class[_]) = new DamlContextualizedErrorLogger(
ContextualizedLogger.get(clazz),
LoggingContext.ForTesting,
None,
)
def forTesting(clazz: Class[_], correlationId: Option[String] = None) =
new DamlContextualizedErrorLogger(
ContextualizedLogger.get(clazz),
LoggingContext.ForTesting,
correlationId,
)
}
/** Implementation of [[ContextualizedErrorLogger]] leveraging the //libs-scala/contextualized-logging

View File

@ -8,7 +8,6 @@ import com.daml.error.ErrorCategory.TransientServerFailure
import com.daml.error.utils.ErrorDetails
import com.daml.error.utils.testpackage.SeriousError
import com.daml.error.utils.testpackage.subpackage.MildErrorsParent.MildErrors.NotSoSeriousError
import com.daml.logging.{ContextualizedLogger, LoggingContext}
import com.daml.platform.testing.LogCollector.ExpectedLogEntry
import com.daml.platform.testing.{LogCollector, LogCollectorAssertions}
import io.grpc.StatusRuntimeException
@ -23,11 +22,9 @@ class ErrorCodeSpec
with LogCollectorAssertions
with ErrorAssertionsWithLogCollectorAssertions {
implicit private val testLoggingContext: LoggingContext = LoggingContext.ForTesting
private val logger = ContextualizedLogger.get(getClass)
private val contextualizedErrorLoggerF =
(correlationId: Option[String]) =>
new DamlContextualizedErrorLogger(logger, testLoggingContext, correlationId)
DamlContextualizedErrorLogger.forTesting(getClass, correlationId)
private val className = classOf[ErrorCode].getSimpleName

View File

@ -4,7 +4,6 @@
package com.daml.error.utils.testpackage.subpackage
import com.daml.error._
import com.daml.logging.LoggingContext
@Explanation("Mild error parent explanation")
object MildErrorsParent extends ErrorGroup()(ErrorClass.root()) {
@ -24,8 +23,7 @@ object MildErrorsParent extends ErrorGroup()(ErrorClass.root()) {
someErrArg: String,
override val context: Map[String, String],
override val definiteAnswerO: Option[Boolean] = Some(true),
)(implicit val loggingContext: LoggingContext)
extends BaseError {
) extends BaseError {
override def code: ErrorCode = NotSoSeriousError.code

View File

@ -8,7 +8,6 @@ import com.daml.grpc.GrpcStatus
import com.daml.ledger.api.v1.completion.Completion
import com.daml.ledger.client.services.commands.tracker.CompletionResponse._
import com.daml.ledger.grpc.GrpcStatuses
import com.daml.logging.{ContextualizedLogger, LoggingContext}
import com.google.protobuf.any.Any
import com.google.rpc.error_details.{ErrorInfo, RequestInfo}
import com.google.rpc.status.Status
@ -72,11 +71,8 @@ class CompletionResponseTest extends AnyWordSpec with Matchers {
}
"convert to exception" should {
val logger: ContextualizedLogger = ContextualizedLogger.get(getClass)
implicit val loggingContext: LoggingContext = LoggingContext.ForTesting
implicit val contextualizedErrorLogger: ContextualizedErrorLogger =
new DamlContextualizedErrorLogger(logger, loggingContext, None)
DamlContextualizedErrorLogger.forTesting(getClass)
"convert queue completion failure" in {
val exception =

View File

@ -19,7 +19,6 @@ import com.daml.error.{
import com.daml.ledger.api.domain.LedgerId
import com.daml.ledger.offset.Offset
import com.daml.lf.data.Ref
import com.daml.logging.{ContextualizedLogger, LoggingContext}
import com.daml.platform.server.api.validation.ErrorFactories._
import com.daml.platform.testing.LogCollector.ExpectedLogEntry
import com.daml.platform.testing.{LogCollector, LogCollectorAssertions}
@ -47,14 +46,11 @@ class ErrorFactoriesSpec
with LogCollectorAssertions
with ErrorAssertionsWithLogCollectorAssertions {
private val logger = ContextualizedLogger.get(getClass)
private val loggingContext = LoggingContext.ForTesting
private val originalCorrelationId = "cor-id-12345679"
private val truncatedCorrelationId = "cor-id-1"
private implicit val contextualizedErrorLogger: ContextualizedErrorLogger =
new DamlContextualizedErrorLogger(logger, loggingContext, Some(originalCorrelationId))
DamlContextualizedErrorLogger.forTesting(getClass, Some(originalCorrelationId))
private val expectedCorrelationIdRequestInfo =
ErrorDetails.RequestInfoDetail(originalCorrelationId)

View File

@ -12,7 +12,6 @@ import com.daml.grpc.sampleservice.implementations.HelloServiceReferenceImplemen
import com.daml.ledger.client.GrpcChannel
import com.daml.ledger.client.configuration.LedgerClientChannelConfiguration
import com.daml.ledger.resources.{ResourceOwner, TestResourceContext}
import com.daml.logging.{ContextualizedLogger, LoggingContext}
import com.daml.metrics.Metrics
import com.daml.platform.apiserver.GrpcServerSpec._
import com.daml.platform.hello.{HelloRequest, HelloResponse, HelloServiceGrpc}
@ -90,14 +89,12 @@ final class GrpcServerSpec extends AsyncWordSpec with Matchers with TestResource
object GrpcServerSpec {
private val logger = ContextualizedLogger.get(getClass)
private val maxInboundMessageSize = 4 * 1024 * 1024 /* copied from the Sandbox configuration */
class TestedHelloService extends HelloServiceReferenceImplementation {
override def fails(request: HelloRequest): Future[HelloResponse] = {
val errorLogger =
new DamlContextualizedErrorLogger(logger, LoggingContext.newLoggingContext(identity), None)
DamlContextualizedErrorLogger.forTesting(getClass)
Future.failed(
LedgerApiErrors.RequestValidation.InvalidArgument
.Reject(request.payload.toStringUtf8)(errorLogger)

View File

@ -23,7 +23,6 @@ import com.daml.grpc.adapter.server.akka.ServerAdapter
import com.daml.grpc.sampleservice.HelloServiceResponding
import com.daml.ledger.api.testing.utils.AkkaBeforeAndAfterAll
import com.daml.ledger.resources.{Resource, ResourceContext, ResourceOwner, TestResourceContext}
import com.daml.logging.{ContextualizedLogger, LoggingContext}
import com.daml.platform.apiserver.services.GrpcClientResource
import com.daml.platform.hello.HelloServiceGrpc.HelloService
import com.daml.platform.hello.{HelloRequest, HelloResponse, HelloServiceGrpc}
@ -252,11 +251,8 @@ object ErrorInterceptorSpec {
trait HelloService_Base extends BindableService {
self: HelloService =>
private val logger = ContextualizedLogger.get(getClass)
private val emptyLoggingContext = LoggingContext.newLoggingContext(identity)
implicit protected val damlLogger: DamlContextualizedErrorLogger =
new DamlContextualizedErrorLogger(logger, emptyLoggingContext, None)
DamlContextualizedErrorLogger.forTesting(getClass)
override def bindService(): ServerServiceDefinition =
HelloServiceGrpc.bindService(this, scala.concurrent.ExecutionContext.Implicits.global)

View File

@ -31,7 +31,6 @@ import com.daml.lf.kv.contracts.RawContractInstance
import com.daml.lf.transaction.{BlindingInfo, NodeId, TransactionOuterClass, TransactionVersion}
import com.daml.lf.value.Value.ContractId
import com.daml.lf.value.ValueOuterClass
import com.daml.logging.{ContextualizedLogger, LoggingContext}
import com.google.rpc.error_details.{ErrorInfo, ResourceInfo}
import io.grpc.Status.Code
import org.scalatest.OptionValues
@ -46,10 +45,8 @@ import scala.jdk.CollectionConverters._
@nowarn("msg=deprecated")
class ConversionsSpec extends AnyWordSpec with Matchers with OptionValues {
implicit private val testLoggingContext: LoggingContext = LoggingContext.ForTesting
private val logger = ContextualizedLogger.get(getClass)
implicit private val errorLoggingContext: DamlContextualizedErrorLogger =
new DamlContextualizedErrorLogger(logger, testLoggingContext, None)
DamlContextualizedErrorLogger.forTesting(getClass)
"Conversions" should {
"correctly and deterministically encode Blindinginfo" in {

View File

@ -21,7 +21,7 @@ import com.daml.lf.transaction.test.TransactionBuilder
import com.daml.lf.transaction.{BlindingInfo, GlobalKey, Transaction}
import com.daml.lf.value.Value
import com.daml.lf.value.Value.ContractId
import com.daml.logging.{ContextualizedLogger, LoggingContext}
import com.daml.logging.LoggingContext
import com.daml.metrics.Metrics
import org.mockito.{ArgumentMatchersSugar, MockitoSugar}
import org.scalatest.FixtureContext
@ -147,12 +147,10 @@ class ConflictCheckWithCommittedSpec
}
private class TestContext extends FixtureContext {
implicit val logger: ContextualizedLogger =
ContextualizedLogger.get(getClass)
implicit val loggingContext: LoggingContext =
LoggingContext.ForTesting
implicit val contextualizedErrorLogger: ContextualizedErrorLogger =
new DamlContextualizedErrorLogger(logger, loggingContext, None)
DamlContextualizedErrorLogger.forTesting(getClass)
val indexServiceMock: IndexService = mock[IndexService]

View File

@ -21,7 +21,7 @@ import com.daml.lf.transaction.test.TransactionBuilder
import com.daml.lf.transaction.{GlobalKey, SubmittedTransaction}
import com.daml.lf.value.Value
import com.daml.lf.value.Value.{ContractId, ValueNil}
import com.daml.logging.{ContextualizedLogger, LoggingContext}
import com.daml.logging.LoggingContext
import com.daml.metrics.Metrics
import org.mockito.MockitoSugar.mock
import org.scalatest.flatspec.AsyncFlatSpec
@ -31,9 +31,8 @@ import java.time.Duration
class PrepareSubmissionSpec extends AsyncFlatSpec with Matchers {
private implicit val loggingContext: LoggingContext = LoggingContext.ForTesting
private val logger = ContextualizedLogger.get(getClass)
private implicit val errorLogger: ContextualizedErrorLogger =
new DamlContextualizedErrorLogger(logger, loggingContext, None)
DamlContextualizedErrorLogger.forTesting(getClass)
private val prepareSubmission = new PrepareSubmissionImpl(
new BridgeMetrics(new Metrics(new MetricRegistry))