diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/audit/AuditingTool.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/audit/AuditingTool.scala index 08fb820756..87c2bf1dfe 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/audit/AuditingTool.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/audit/AuditingTool.scala @@ -20,7 +20,7 @@ import cats.Show import cats.data.{NonEmptyList, Validated, ValidatedNel} import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.json.JSONObject import tech.beshu.ror.accesscontrol.audit.AuditingTool.AuditSettings.AuditSink import tech.beshu.ror.accesscontrol.audit.AuditingTool.AuditSettings.AuditSink.{Disabled, Enabled} @@ -148,7 +148,7 @@ final class AuditingTool private(auditSinks: NonEmptyList[BaseAuditSink]) } -object AuditingTool extends Logging { +object AuditingTool extends RequestIdAwareLogging { final case class AuditSettings(auditSinks: NonEmptyList[AuditSettings.AuditSink]) @@ -212,10 +212,10 @@ object AuditingTool extends Logging { createAuditSinks(settings, auditSinkServiceCreator).map { _.map { case Some(auditSinks) => - logger.info(s"The audit is enabled with the given outputs: [${auditSinks.toList.show}]") + noRequestIdLogger.info(s"The audit is enabled with the given outputs: [${auditSinks.toList.show}]") Some(new AuditingTool(auditSinks)) case None => - logger.info("The audit is disabled because no output is enabled") + noRequestIdLogger.info("The audit is disabled because no output is enabled") None } .toEither diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/audit/configurable/AuditFieldValueDescriptorParser.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/audit/configurable/AuditFieldValueDescriptorParser.scala index f9789306df..d87cd22e03 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/audit/configurable/AuditFieldValueDescriptorParser.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/audit/configurable/AuditFieldValueDescriptorParser.scala @@ -18,10 +18,10 @@ package tech.beshu.ror.accesscontrol.audit.configurable import cats.parse.{Parser0, Parser as P} import cats.syntax.list.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.audit.utils.AuditSerializationHelper.AuditFieldValueDescriptor -object AuditFieldValueDescriptorParser extends Logging { +object AuditFieldValueDescriptorParser extends RequestIdAwareLogging { private val lbrace = P.char('{') private val rbrace = P.char('}') @@ -62,7 +62,7 @@ object AuditFieldValueDescriptorParser extends Logging { case "ECS_EVENT_OUTCOME" => Some(AuditFieldValueDescriptor.EcsEventOutcome) case "REASON" => Some(AuditFieldValueDescriptor.Reason) case "USER" => - logger.warn( + noRequestIdLogger.warn( """The USER audit value placeholder is deprecated and should not be used in the configurable audit log serializer. |Please use LOGGED_USER or PRESENTED_IDENTITY instead. Check the list of available placeholders in the documentation: |https://docs.readonlyrest.com/elasticsearch/audit#using-configurable-serializer. diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/audit/sink/AuditDataStreamCreator.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/audit/sink/AuditDataStreamCreator.scala index 2bf2e7b4f4..f864190541 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/audit/sink/AuditDataStreamCreator.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/audit/sink/AuditDataStreamCreator.scala @@ -21,7 +21,7 @@ import cats.data.{NonEmptyList, Validated} import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.audit.sink.AuditDataStreamCreator.ErrorMessage import tech.beshu.ror.accesscontrol.domain.{DataStreamName, RorAuditDataStream, TemplateName} import tech.beshu.ror.es.DataStreamService @@ -32,7 +32,7 @@ import tech.beshu.ror.utils.RefinedUtils.* import java.util.concurrent.TimeUnit -final class AuditDataStreamCreator(services: NonEmptyList[DataStreamService]) extends Logging { +final class AuditDataStreamCreator(services: NonEmptyList[DataStreamService]) extends RequestIdAwareLogging { def createIfNotExists(dataStreamName: RorAuditDataStream): Task[Either[NonEmptyList[ErrorMessage], Unit]] = { services @@ -47,7 +47,7 @@ final class AuditDataStreamCreator(services: NonEmptyList[DataStreamService]) ex .checkDataStreamExists(dataStreamName.dataStream) .flatMap { case true => - Task.delay(logger.info(s"Data stream ${dataStreamName.dataStream.show} already exists")) + Task.delay(noRequestIdLogger.info(s"Data stream ${dataStreamName.dataStream.show} already exists")) .as(Valid(())) case false => val settings = defaultSettingsFor(dataStreamName.dataStream) @@ -57,19 +57,19 @@ final class AuditDataStreamCreator(services: NonEmptyList[DataStreamService]) ex private def setupDataStream(service: DataStreamService, settings: DataStreamSettings): Task[Validated[ErrorMessage, Unit]] = { for { - _ <- Task.delay(logger.info(s"Trying to setup ROR audit data stream ${settings.dataStreamName.show} with default settings..")) + _ <- Task.delay(noRequestIdLogger.info(s"Trying to setup ROR audit data stream ${settings.dataStreamName.show} with default settings..")) result <- service.fullySetupDataStream(settings).attempt finalResult <- result match { case Right(DataStreamSetupResult.Success) => - Task.delay(logger.info(s"ROR audit data stream ${settings.dataStreamName.show} created.")) + Task.delay(noRequestIdLogger.info(s"ROR audit data stream ${settings.dataStreamName.show} created.")) .as(Valid(())) case Right(DataStreamSetupResult.Failure(reason)) => val message = s"Failed to setup ROR audit data stream ${settings.dataStreamName.show}. Reason: ${reason.show}" - Task.delay(logger.error(message)) + Task.delay(noRequestIdLogger.error(message)) .as(ErrorMessage(message).invalid) case Left(ex) => val message = s"An unexpected error occurred while setting up the ROR audit data stream ${settings.dataStreamName.show}. Details: ${ex.getMessage}" - Task.delay(logger.error(message, ex)) + Task.delay(noRequestIdLogger.error(message, ex)) .as(ErrorMessage(message).invalid) } } yield finalResult diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/Block.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/Block.scala index 3ee8db3b07..72e7ed4d91 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/Block.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/Block.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.accesscontrol.blocks import cats.data.{NonEmptyList, Validated, WriterT} import cats.{Eq, Show} import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.audit.LoggingContext import tech.beshu.ror.accesscontrol.blocks.Block.* import tech.beshu.ror.accesscontrol.blocks.Block.ExecutionResult.{Matched, Mismatched} @@ -43,7 +43,7 @@ class Block(val name: Name, val audit: Audit, val rules: NonEmptyList[Rule]) (implicit val loggingContext: LoggingContext) - extends Logging { + extends RequestIdAwareLogging { import Lifter.* @@ -73,7 +73,7 @@ class Block(val name: Name, val ruleResult = rule .check[B](blockContext) .recover { case e => - logger.error(s"[${blockContext.requestContext.id.show}] ${name.show}: ${rule.name.show} rule matching got an error ${e.getMessage}", e) + logger.error(s"${name.show}: ${rule.name.show} rule matching got an error ${e.getMessage}", e)(blockContext) RuleResult.Rejected[B]() } lift[B](ruleResult) diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/BlockContext.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/BlockContext.scala index 924a634b84..192ad37b72 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/BlockContext.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/BlockContext.scala @@ -27,7 +27,9 @@ import tech.beshu.ror.accesscontrol.domain.GroupsLogic.{Combined, NegativeGroups import tech.beshu.ror.accesscontrol.request.RequestContext import tech.beshu.ror.syntax.* -sealed trait BlockContext { +sealed trait BlockContext extends HasRequestId { + override def requestId: RequestId = requestContext.id.toRequestId + def requestContext: RequestContext def userMetadata: UserMetadata diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/RuleOrdering.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/RuleOrdering.scala index 29ff885cb2..c5ad05dc62 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/RuleOrdering.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/RuleOrdering.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.accesscontrol.blocks import cats.Order import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.rules.Rule import tech.beshu.ror.accesscontrol.blocks.rules.auth.* import tech.beshu.ror.accesscontrol.blocks.rules.elasticsearch.* @@ -29,20 +29,20 @@ import tech.beshu.ror.accesscontrol.blocks.rules.tranport.* import tech.beshu.ror.accesscontrol.domain.GroupsLogic.* import tech.beshu.ror.accesscontrol.orders.* -class RuleOrdering extends Ordering[Rule] with Logging { +class RuleOrdering extends Ordering[Rule] with RequestIdAwareLogging { override def compare(rule1: Rule, rule2: Rule): Int = { val rule1TypeIndex = RuleOrdering.orderedListOrRuleType.indexOf(rule1.getClass) val rule2TypeIndex = RuleOrdering.orderedListOrRuleType.indexOf(rule2.getClass) (rule1TypeIndex, rule2TypeIndex) match { case (-1, -1) => - logger.warn(s"No order defined for rules: ${rule1.name.show}, ${rule1.name.show}") + noRequestIdLogger.warn(s"No order defined for rules: ${rule1.name.show}, ${rule1.name.show}") implicitly[Order[Rule.Name]].compare(rule1.name, rule2.name) case (-1, _) => - logger.warn(s"No order defined for rule: ${rule1.name.show}") + noRequestIdLogger.warn(s"No order defined for rule: ${rule1.name.show}") 1 case (_, -1) => - logger.warn(s"No order defined for rule: ${rule2.name.show}") + noRequestIdLogger.warn(s"No order defined for rule: ${rule2.name.show}") -1 case (i1, i2) => i1 compareTo i2 diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ExternalAuthorizationService.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ExternalAuthorizationService.scala index 7ffa4a78ed..5d2df6d53e 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ExternalAuthorizationService.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ExternalAuthorizationService.scala @@ -21,7 +21,7 @@ import eu.timepit.refined.auto.* import eu.timepit.refined.types.string.NonEmptyString import io.lemonlabs.uri.Url import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.definitions.ExternalAuthorizationService.Name import tech.beshu.ror.accesscontrol.blocks.definitions.HttpExternalAuthorizationService.* import tech.beshu.ror.accesscontrol.blocks.definitions.HttpExternalAuthorizationService.Config.* @@ -62,7 +62,7 @@ final class HttpExternalAuthorizationService(override val id: ExternalAuthorizat val config: HttpExternalAuthorizationService.Config, httpClient: HttpClient) extends ExternalAuthorizationService - with Logging { + with RequestIdAwareLogging { override def grantsFor(userId: User.Id) (implicit requestId: RequestId): Task[UniqueList[Group]] = { @@ -106,10 +106,10 @@ final class HttpExternalAuthorizationService(override val id: ExternalAuthorizat val groupsFromBody = groupsFrom(body) groupsFromBody match { case Success(groups) => - logger.debug(s"[${requestId.show}] Groups returned by groups provider '${id.show}': ${groups.show}") + logger.debug(s"Groups returned by groups provider '${id.show}': ${groups.show}") UniqueList.from(groups) case Failure(ex) => - logger.debug(s"[${requestId.show}] Group based authorization response exception - provider '${id.show}'", ex) + logger.debug(s"Group based authorization response exception - provider '${id.show}'", ex) UniqueList.empty } } diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ldap/CircuitBreakerLdapAuthServiceDecorator.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ldap/CircuitBreakerLdapAuthServiceDecorator.scala index fba0cea28c..5480069987 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ldap/CircuitBreakerLdapAuthServiceDecorator.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ldap/CircuitBreakerLdapAuthServiceDecorator.scala @@ -20,7 +20,7 @@ import cats.Show import cats.implicits.toShow import monix.catnap.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.definitions.CircuitBreakerConfig import tech.beshu.ror.accesscontrol.domain import tech.beshu.ror.accesscontrol.domain.{Group, GroupIdLike, RequestId, User} @@ -113,7 +113,7 @@ class CircuitBreakerLdapUsersServiceDecorator(val underlying: LdapUsersService, override def serviceTimeout: PositiveFiniteDuration = underlying.serviceTimeout } -trait LdapCircuitBreaker extends Logging { +trait LdapCircuitBreaker extends RequestIdAwareLogging { this: LdapService => protected def circuitBreakerConfig: CircuitBreakerConfig @@ -126,16 +126,16 @@ trait LdapCircuitBreaker extends Logging { maxFailures = maxFailures.value, resetTimeout = resetDuration.value, onRejected = Task { - logger.debug(s"LDAP ${id.show} circuit breaker rejected task (Open or HalfOpen state)") + noRequestIdLogger.debug(s"LDAP ${id.show} circuit breaker rejected task (Open or HalfOpen state)") }, onClosed = Task { - logger.debug(s"LDAP ${id.show} circuit breaker is accepting tasks again (switched to Close state)") + noRequestIdLogger.debug(s"LDAP ${id.show} circuit breaker is accepting tasks again (switched to Close state)") }, onHalfOpen = Task { - logger.debug(s"LDAP ${id.show} circuit breaker accepted one task for testing (switched to HalfOpen state)") + noRequestIdLogger.debug(s"LDAP ${id.show} circuit breaker accepted one task for testing (switched to HalfOpen state)") }, onOpen = Task { - logger.debug(s"LDAP ${id.show} circuit breaker rejected task (switched to Open state)") + noRequestIdLogger.debug(s"LDAP ${id.show} circuit breaker rejected task (switched to Open state)") } ) } diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ldap/LoggableLdapServiceDecorator.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ldap/LoggableLdapServiceDecorator.scala index 317a433699..6839b9d496 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ldap/LoggableLdapServiceDecorator.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ldap/LoggableLdapServiceDecorator.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.accesscontrol.blocks.definitions.ldap import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.domain import tech.beshu.ror.accesscontrol.domain.{Group, GroupIdLike, RequestId, User} import tech.beshu.ror.implicits.* @@ -29,17 +29,17 @@ import scala.util.{Failure, Success} class LoggableLdapAuthenticationServiceDecorator(val underlying: LdapAuthenticationService) extends LdapAuthenticationService - with Logging { + with RequestIdAwareLogging { override def authenticate(user: User.Id, secret: domain.PlainTextSecret)(implicit requestId: RequestId): Task[Boolean] = { - logger.debug(s"[${requestId.show}] Trying to authenticate user [${user.show}] with LDAP [${id.show}]") + logger.debug(s"Trying to authenticate user [${user.show}] with LDAP [${id.show}]") underlying .authenticate(user, secret) .andThen { case Success(authenticationResult) => - logger.debug(s"[${requestId.show}] User [${user.show}]${if (authenticationResult) "" else " not"} authenticated by LDAP [${id.show}]") + logger.debug(s"User [${user.show}]${if (authenticationResult) "" else " not"} authenticated by LDAP [${id.show}]") case Failure(ex) => - logger.debug(s"[${requestId.show}] LDAP authentication failed:", ex) + logger.debug(s"LDAP authentication failed:", ex) } } @@ -63,18 +63,18 @@ object LoggableLdapAuthorizationService { class WithoutGroupsFilteringDecorator(val underlying: LdapAuthorizationService.WithoutGroupsFiltering) extends LdapAuthorizationService.WithoutGroupsFiltering - with Logging { + with RequestIdAwareLogging { override def groupsOf(userId: User.Id) (implicit requestId: RequestId): Task[UniqueList[Group]] = { - logger.debug(s"[${requestId.show}] Trying to fetch user [id=${userId.show}] groups from LDAP [${id.show}]") + logger.debug(s"Trying to fetch user [id=${userId.show}] groups from LDAP [${id.show}]") underlying .groupsOf(userId) .andThen { case Success(groups) => - logger.debug(s"[${requestId.show}] LDAP [${id.show}] returned for user [${userId.show}] following groups: [${groups.show}]") + logger.debug(s"LDAP [${id.show}] returned for user [${userId.show}] following groups: [${groups.show}]") case Failure(ex) => - logger.debug(s"[${requestId.show}] Fetching LDAP user's groups failed:", ex) + logger.debug(s"Fetching LDAP user's groups failed:", ex) } } @@ -87,18 +87,18 @@ object LoggableLdapAuthorizationService { class WithGroupsFilteringDecorator(val underlying: LdapAuthorizationService.WithGroupsFiltering) extends LdapAuthorizationService.WithGroupsFiltering - with Logging { + with RequestIdAwareLogging { override def groupsOf(userId: User.Id, filteringGroupIds: Set[GroupIdLike]) (implicit requestId: RequestId): Task[UniqueList[Group]] = { - logger.debug(s"[${requestId.show}] Trying to fetch user [id=${userId.show}] groups from LDAP [${id.show}] (assuming that filtered group IDs are [${filteringGroupIds.show}])") + logger.debug(s"Trying to fetch user [id=${userId.show}] groups from LDAP [${id.show}] (assuming that filtered group IDs are [${filteringGroupIds.show}])") underlying .groupsOf(userId, filteringGroupIds) .andThen { case Success(groups) => - logger.debug(s"[${requestId.show}] LDAP [${id.show}] returned for user [${userId.show}] following groups: [${groups.show}]") + logger.debug(s"LDAP [${id.show}] returned for user [${userId.show}] following groups: [${groups.show}]") case Failure(ex) => - logger.debug(s"[${requestId.show}] Fetching LDAP user's groups failed:", ex) + logger.debug(s"Fetching LDAP user's groups failed:", ex) } } @@ -113,20 +113,20 @@ object LoggableLdapAuthorizationService { private class LoggableLdapUsersServiceDecorator(underlying: LdapUsersService) extends LdapUsersService - with Logging { + with RequestIdAwareLogging { override def ldapUserBy(userId: User.Id)(implicit requestId: RequestId): Task[Option[LdapUser]] = { - logger.debug(s"[${requestId.show}] Trying to fetch user with identifier [${userId.show}] from LDAP [${id.show}]") + logger.debug(s"Trying to fetch user with identifier [${userId.show}] from LDAP [${id.show}]") underlying .ldapUserBy(userId) .andThen { case Success(ldapUser) => ldapUser match { - case Some(user) => logger.debug(s"[${requestId.show}] User with identifier [${userId.show}] found [dn = ${user.dn.show}]") - case None => logger.debug(s"[${requestId.show}] User with identifier [${userId.show}] not found") + case Some(user) => logger.debug(s"User with identifier [${userId.show}] found [dn = ${user.dn.show}]") + case None => logger.debug(s"User with identifier [${userId.show}] not found") } case Failure(ex) => - logger.debug(s"[${requestId.show}] Fetching LDAP user failed:", ex) + logger.debug(s"Fetching LDAP user failed:", ex) } } diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ldap/implementations/UnboundidLdapAuthenticationService.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ldap/implementations/UnboundidLdapAuthenticationService.scala index aa5ddc31b2..15d6b78e6b 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ldap/implementations/UnboundidLdapAuthenticationService.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ldap/implementations/UnboundidLdapAuthenticationService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.accesscontrol.blocks.definitions.ldap.implementations import com.unboundid.ldap.sdk.{LDAPBindException, ResultCode, SimpleBindRequest} import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.definitions.ldap.implementations.UnboundidLdapConnectionPoolProvider.{ConnectionError, LdapConnectionConfig} import tech.beshu.ror.accesscontrol.blocks.definitions.ldap.{LdapAuthenticationService, LdapService, LdapUser, LdapUsersService} import tech.beshu.ror.accesscontrol.domain.{PlainTextSecret, RequestId, User} @@ -33,13 +33,13 @@ class UnboundidLdapAuthenticationService private(override val id: LdapService#Id connectionPool: UnboundidLdapConnectionPool, override val serviceTimeout: PositiveFiniteDuration) (implicit clock: Clock) - extends LdapAuthenticationService with Logging { + extends LdapAuthenticationService with RequestIdAwareLogging { override def authenticate(user: User.Id, secret: PlainTextSecret)(implicit requestId: RequestId): Task[Boolean] = { Task.measure( doAuthenticate(user, secret), measurement => Task.delay { - logger.debug(s"[${requestId.show}] LDAP authentication took ${measurement.show}") + logger.debug(s"LDAP authentication took ${measurement.show}") } ) } @@ -56,12 +56,12 @@ class UnboundidLdapAuthenticationService private(override val id: LdapService#Id } private def ldapAuthenticate(user: LdapUser, password: PlainTextSecret)(implicit requestId: RequestId) = { - logger.debug(s"[${requestId.show}] LDAP simple bind [user DN: ${user.dn.show}]") + logger.debug(s"LDAP simple bind [user DN: ${user.dn.show}]") connectionPool .asyncBind(new SimpleBindRequest(user.dn.value.value, password.value.value)) .map(_.getResultCode == ResultCode.SUCCESS) .onError { case ex => - Task(logger.error(s"[${requestId.show}] LDAP authenticate operation failed - cause [${ex.getMessage.show}]", ex)) + Task(logger.error(s"LDAP authenticate operation failed - cause [${ex.getMessage.show}]", ex)) } .recover { case ex: LDAPBindException if ex.getResultCode == ResultCode.INVALID_CREDENTIALS => diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ldap/implementations/UnboundidLdapConnectionPool.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ldap/implementations/UnboundidLdapConnectionPool.scala index 9f07be972d..7bd379261f 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ldap/implementations/UnboundidLdapConnectionPool.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ldap/implementations/UnboundidLdapConnectionPool.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.accesscontrol.blocks.definitions.ldap.implementations import com.unboundid.ldap.sdk.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.definitions.ldap.implementations.UnboundidLdapConnectionPoolProvider.LdapConnectionConfig.BindRequestUser import tech.beshu.ror.utils.DurationOps.PositiveFiniteDuration @@ -28,7 +28,7 @@ import scala.jdk.CollectionConverters.* class UnboundidLdapConnectionPool(connectionPool: LDAPConnectionPool, bindRequestUser: BindRequestUser) - extends Logging { + extends RequestIdAwareLogging { def asyncBind(request: BindRequest): Task[BindResult] = { bindRequestUser match { diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ldap/implementations/UnboundidLdapConnectionPoolProvider.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ldap/implementations/UnboundidLdapConnectionPoolProvider.scala index e8b277d3b2..1c8deaf043 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ldap/implementations/UnboundidLdapConnectionPoolProvider.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ldap/implementations/UnboundidLdapConnectionPoolProvider.scala @@ -26,7 +26,7 @@ import eu.timepit.refined.api.Refined import eu.timepit.refined.numeric.Positive import io.lemonlabs.uri.UrlWithAuthority import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.definitions.CircuitBreakerConfig import tech.beshu.ror.accesscontrol.blocks.definitions.ldap.implementations.UnboundidLdapConnectionPoolProvider.ConnectionError.{BindingTestError, CannotConnectError, HostResolvingError, UnexpectedConnectionError} import tech.beshu.ror.accesscontrol.blocks.definitions.ldap.implementations.UnboundidLdapConnectionPoolProvider.LdapConnectionConfig.{BindRequestUser, ConnectionMethod, HaMethod, LdapHost} @@ -84,7 +84,7 @@ class UnboundidLdapConnectionPoolProvider { } -object UnboundidLdapConnectionPoolProvider extends Logging { +object UnboundidLdapConnectionPoolProvider extends RequestIdAwareLogging { final case class LdapConnectionConfig(poolName: LdapService.Name, connectionMethod: ConnectionMethod, @@ -246,7 +246,7 @@ object UnboundidLdapConnectionPoolProvider extends Logging { .map(conn => Resource.make(Task(conn))(c => Task.delay(c.close()))) .left .map { ex => - logger.warnEx("Problem during getting LDAP connection", ex) + noRequestIdLogger.warnEx("Problem during getting LDAP connection", ex) CannotConnectError(connectionConfig.poolName, connectionConfig.connectionMethod) } }.timeout(connectionTimeout) diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ldap/implementations/UnboundidLdapDefaultGroupSearchAuthorizationServiceWithServerSideGroupsFiltering.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ldap/implementations/UnboundidLdapDefaultGroupSearchAuthorizationServiceWithServerSideGroupsFiltering.scala index 495b47eec0..360aeba362 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ldap/implementations/UnboundidLdapDefaultGroupSearchAuthorizationServiceWithServerSideGroupsFiltering.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ldap/implementations/UnboundidLdapDefaultGroupSearchAuthorizationServiceWithServerSideGroupsFiltering.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.accesscontrol.blocks.definitions.ldap.implementations import com.unboundid.ldap.sdk.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.definitions.ldap.implementations.SearchResultEntryOps.* import tech.beshu.ror.accesscontrol.blocks.definitions.ldap.implementations.UnboundidLdapConnectionPoolProvider.{ConnectionError, LdapConnectionConfig} import tech.beshu.ror.accesscontrol.blocks.definitions.ldap.implementations.UserGroupsSearchFilterConfig.UserGroupsSearchMode.* @@ -41,7 +41,7 @@ class UnboundidLdapDefaultGroupSearchAuthorizationServiceWithServerSideGroupsFil override val serviceTimeout: PositiveFiniteDuration) (implicit clock: Clock) extends LdapAuthorizationService.WithGroupsFiltering - with Logging { + with RequestIdAwareLogging { private val nestedGroupsService = nestedGroupsConfig .map(new UnboundidLdapNestedGroupsService(connectionPool, _, serviceTimeout)) @@ -51,7 +51,7 @@ class UnboundidLdapDefaultGroupSearchAuthorizationServiceWithServerSideGroupsFil Task.measure( doFetchGroupsOf(id, filteringGroupIds), measurement => Task.delay { - logger.debug(s"[${requestId.show}] LDAP groups fetching took ${measurement.show}") + logger.debug(s"LDAP groups fetching took ${measurement.show}") } ) } @@ -82,7 +82,7 @@ class UnboundidLdapDefaultGroupSearchAuthorizationServiceWithServerSideGroupsFil UniqueList.from(allGroups.map(_.group)) } case Left(errorResult) => - logger.error(s"[${requestId.show}] LDAP getting user groups returned error: [code=${errorResult.getResultCode.toString.show}, cause=${errorResult.getResultString.show}]") + logger.error(s"LDAP getting user groups returned error: [code=${errorResult.getResultCode.toString.show}, cause=${errorResult.getResultString.show}]") Task.raiseError(LdapUnexpectedResult(errorResult.getResultCode, errorResult.getResultString)) } } @@ -96,7 +96,7 @@ class UnboundidLdapDefaultGroupSearchAuthorizationServiceWithServerSideGroupsFil val scope = SearchScope.SUB val searchFilter = searchUserGroupsLdapFilerFrom(mode, user, filteringGroupIds) val groupAttributes = attributesFrom(mode.groupAttribute) - logger.debug(s"[${requestId.show}] LDAP search [base DN: ${baseDn.show}, scope: ${scope.getName().show}, search filter: ${searchFilter.show}, attributes: ${groupAttributes.show}]") + logger.debug(s"LDAP search [base DN: ${baseDn.show}, scope: ${scope.getName().show}, search filter: ${searchFilter.show}, attributes: ${groupAttributes.show}]") new SearchRequest(listener, baseDn, scope, searchFilter, groupAttributes.toSeq*) } diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ldap/implementations/UnboundidLdapGroupsFromUserEntryAuthorizationService.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ldap/implementations/UnboundidLdapGroupsFromUserEntryAuthorizationService.scala index ce72956ea4..2817d9f3df 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ldap/implementations/UnboundidLdapGroupsFromUserEntryAuthorizationService.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ldap/implementations/UnboundidLdapGroupsFromUserEntryAuthorizationService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.accesscontrol.blocks.definitions.ldap.implementations import com.unboundid.ldap.sdk.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.definitions.ldap.implementations.SearchResultEntryOps.* import tech.beshu.ror.accesscontrol.blocks.definitions.ldap.implementations.UnboundidLdapConnectionPoolProvider.{ConnectionError, LdapConnectionConfig} import tech.beshu.ror.accesscontrol.blocks.definitions.ldap.implementations.UserGroupsSearchFilterConfig.UserGroupsSearchMode.* @@ -40,7 +40,7 @@ class UnboundidLdapGroupsFromUserEntryAuthorizationService private(override val val nestedGroupsConfig: Option[NestedGroupsConfig], override val serviceTimeout: PositiveFiniteDuration) (implicit clock: Clock) - extends LdapAuthorizationService.WithoutGroupsFiltering with Logging { + extends LdapAuthorizationService.WithoutGroupsFiltering with RequestIdAwareLogging { private val nestedGroupsService = nestedGroupsConfig .map(new UnboundidLdapNestedGroupsService(connectionPool, _, serviceTimeout)) @@ -50,7 +50,7 @@ class UnboundidLdapGroupsFromUserEntryAuthorizationService private(override val Task.measure( doFetchGroupsOf(id), measurement => Task.delay { - logger.debug(s"[${requestId.show}] LDAP groups fetching took ${measurement.show}") + logger.debug(s"LDAP groups fetching took ${measurement.show}") } ) } @@ -80,10 +80,10 @@ class UnboundidLdapGroupsFromUserEntryAuthorizationService private(override val UniqueList.from(allGroups.map(_.group)) } case Left(errorResult) if errorResult.getResultCode == ResultCode.NO_SUCH_OBJECT && !user.confirmed => - logger.error(s"[${requestId.show}] LDAP getting user groups returned error [${errorResult.show}]") + logger.error(s"LDAP getting user groups returned error [${errorResult.show}]") Task.now(UniqueList.empty[Group]) case Left(errorResult) => - logger.error(s"[${requestId.show}] LDAP getting user groups returned error [${errorResult.show}]") + logger.error(s"LDAP getting user groups returned error [${errorResult.show}]") Task.raiseError(LdapUnexpectedResult(errorResult.getResultCode, errorResult.getResultString)) } } @@ -96,7 +96,7 @@ class UnboundidLdapGroupsFromUserEntryAuthorizationService private(override val val scope = SearchScope.BASE val searchFilter = mode.groupSearchFilter.value.value val attribute = mode.groupsFromUserAttribute.value.value - logger.debug(s"[${requestId.show}] LDAP search [base DN: ${baseDn.show}, scope: ${scope.show}, search filter: ${searchFilter.show}, attributes: ${attribute.show}]") + logger.debug(s"LDAP search [base DN: ${baseDn.show}, scope: ${scope.show}, search filter: ${searchFilter.show}, attributes: ${attribute.show}]") new SearchRequest(listener, baseDn, scope, searchFilter, attribute) } diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ldap/implementations/UnboundidLdapNestedGroupsService.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ldap/implementations/UnboundidLdapNestedGroupsService.scala index 53736f8583..9add619c05 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ldap/implementations/UnboundidLdapNestedGroupsService.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ldap/implementations/UnboundidLdapNestedGroupsService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.accesscontrol.blocks.definitions.ldap.implementations import com.unboundid.ldap.sdk.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.definitions.ldap.implementations.SearchResultEntryOps.* import tech.beshu.ror.accesscontrol.blocks.definitions.ldap.implementations.UserGroupsSearchFilterConfig.UserGroupsSearchMode.* import tech.beshu.ror.accesscontrol.blocks.definitions.ldap.implementations.domain.LdapGroup @@ -32,7 +32,7 @@ import tech.beshu.ror.utils.LoggerOps.toLoggerOps private[implementations] class UnboundidLdapNestedGroupsService(connectionPool: UnboundidLdapConnectionPool, config: NestedGroupsConfig, serviceTimeout: PositiveFiniteDuration) - extends Logging { + extends RequestIdAwareLogging { private val ldapGroupsExplorer = new GraphNodeAncestorsExplorer[LdapGroup]( kinshipLevel = config.nestedLevels, @@ -55,11 +55,11 @@ private[implementations] class UnboundidLdapNestedGroupsService(connectionPool: results.flatMap(_.toLdapGroup(config.groupAttribute)).toSet } case Left(errorResult) => - logger.error(s"[${requestId.show}] LDAP getting groups of [${group.group.show}] group returned error: [${errorResult.show}]") + logger.error(s"LDAP getting groups of [${group.group.show}] group returned error: [${errorResult.show}]") Task.raiseError(LdapUnexpectedResult(errorResult.getResultCode, errorResult.getResultString)) } .onError { case ex => - Task(logger.errorEx(s"[${requestId.show}] LDAP getting groups of [${group.group.show}] group returned error", ex)) + Task(logger.errorEx(s"LDAP getting groups of [${group.group.show}] group returned error", ex)) } } @@ -70,7 +70,7 @@ private[implementations] class UnboundidLdapNestedGroupsService(connectionPool: val scope = SearchScope.SUB val searchFilter = searchFilterFrom(config.groupSearchFilter, config.memberAttribute, ldapGroup) val groupAttributes = attributesFrom(config.groupAttribute) - logger.debug(s"[${requestId.show}] LDAP search [base DN: ${baseDn.show}, scope: ${scope.show}, search filter: ${searchFilter.show}, attributes: ${groupAttributes.show}]") + logger.debug(s"LDAP search [base DN: ${baseDn.show}, scope: ${scope.show}, search filter: ${searchFilter.show}, attributes: ${groupAttributes.show}]") new SearchRequest(listener, baseDn, scope, searchFilter, groupAttributes.toSeq*) } diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ldap/implementations/UnboundidLdapUsersService.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ldap/implementations/UnboundidLdapUsersService.scala index 4b8dbcd1f0..c0df4354aa 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ldap/implementations/UnboundidLdapUsersService.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/definitions/ldap/implementations/UnboundidLdapUsersService.scala @@ -21,7 +21,7 @@ import eu.timepit.refined.api.Refined import eu.timepit.refined.numeric.Positive import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.definitions.ldap.* import tech.beshu.ror.accesscontrol.blocks.definitions.ldap.implementations.UnboundidLdapConnectionPoolProvider.{ConnectionError, LdapConnectionConfig} import tech.beshu.ror.accesscontrol.blocks.definitions.ldap.implementations.UserGroupsSearchFilterConfig.UserGroupsSearchMode @@ -37,7 +37,7 @@ class UnboundidLdapUsersService private(override val id: LdapService#Id, connectionPool: UnboundidLdapConnectionPool, userSearchFiler: UserSearchFilterConfig, override val serviceTimeout: PositiveFiniteDuration) - extends LdapUsersService with Logging { + extends LdapUsersService with RequestIdAwareLogging { override def ldapUserBy(userId: User.Id)(implicit requestId: RequestId): Task[Option[LdapUser]] = { userSearchFiler.userIdAttribute match { @@ -65,15 +65,15 @@ class UnboundidLdapUsersService private(override val id: LdapService#Id, .process(searchUserLdapRequest(_, userSearchFiler.searchUserBaseDN, uidAttribute, userId), serviceTimeout) .flatMap { case Right(Nil) => - logger.debug(s"[${requestId.show}] LDAP search user - no entries returned") + logger.debug(s"LDAP search user - no entries returned") Task.now(None) case Right(user :: Nil) => Task(Some(LdapUser(userId, Dn(NonEmptyString.unsafeFrom(user.getDN)), confirmed = true))) case Right(all@user :: _) => - logger.warn(s"[${requestId.show}] LDAP search user - more than one user was returned: ${all.toSet.show}. Picking first") + logger.warn(s"LDAP search user - more than one user was returned: ${all.toSet.show}. Picking first") Task(Some(LdapUser(userId, Dn(NonEmptyString.unsafeFrom(user.getDN)), confirmed = true))) case Left(errorResult) => - logger.error(s"[${requestId.show}] LDAP search user - returned error: [${errorResult.show}]") + logger.error(s"LDAP search user - returned error: [${errorResult.show}]") Task.raiseError(LdapUnexpectedResult(errorResult.getResultCode, errorResult.getResultString)) } } @@ -86,7 +86,7 @@ class UnboundidLdapUsersService private(override val id: LdapService#Id, val baseDn = searchUserBaseDN.value.value val scope = SearchScope.SUB val searchFilter = s"${uidAttribute.name.value}=${Filter.encodeValue(userId.value.value)}" - logger.debug(s"[${requestId.show}] LDAP search [base DN: ${baseDn.show}, scope: ${scope.show}, search filter: ${searchFilter.show}]") + logger.debug(s"LDAP search [base DN: ${baseDn.show}, scope: ${scope.show}, search filter: ${searchFilter.show}]") new SearchRequest(listener, baseDn, scope, searchFilter) } } diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/auth/AuthKeyHashingRule.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/auth/AuthKeyHashingRule.scala index b8fb6cbd7f..bb74726c05 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/auth/AuthKeyHashingRule.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/auth/AuthKeyHashingRule.scala @@ -20,7 +20,7 @@ import cats.Eq import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.mocks.MocksProvider import tech.beshu.ror.accesscontrol.blocks.rules.Rule import tech.beshu.ror.accesscontrol.blocks.rules.Rule.AuthenticationRule.EligibleUsersSupport @@ -38,7 +38,7 @@ sealed abstract class AuthKeyHashingRule(override val settings: BasicAuthenticat implicit override val userIdCaseSensitivity: CaseSensitivity, hasher: Hasher) extends BasicAuthenticationRule(settings) - with Logging { + with RequestIdAwareLogging { override protected def compare(configuredCredentials: HashedCredentials, credentials: Credentials): Task[Boolean] = Task { diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/auth/AuthKeyRule.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/auth/AuthKeyRule.scala index 883ec752ee..229f90453a 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/auth/AuthKeyRule.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/auth/AuthKeyRule.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.accesscontrol.blocks.rules.auth import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.mocks.MocksProvider import tech.beshu.ror.accesscontrol.blocks.rules.Rule import tech.beshu.ror.accesscontrol.blocks.rules.Rule.AuthenticationRule.EligibleUsersSupport @@ -33,7 +33,7 @@ final class AuthKeyRule(override val settings: BasicAuthenticationRule.Settings[ override implicit val userIdCaseSensitivity: CaseSensitivity, override val impersonation: Impersonation) extends BasicAuthenticationRule(settings) - with Logging { + with RequestIdAwareLogging { override val name: Rule.Name = AuthKeyRule.Name.name diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/auth/JwtAuthRule.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/auth/JwtAuthRule.scala index 803ff69b99..d466fccecc 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/auth/JwtAuthRule.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/auth/JwtAuthRule.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.accesscontrol.blocks.rules.auth import io.jsonwebtoken.Jwts import io.jsonwebtoken.security.Keys import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.definitions.JwtDef import tech.beshu.ror.accesscontrol.blocks.definitions.JwtDef.SignatureCheckMethod.* import tech.beshu.ror.accesscontrol.blocks.rules.Rule @@ -46,7 +46,7 @@ final class JwtAuthRule(val settings: JwtAuthRule.Settings, extends AuthRule with AuthenticationImpersonationCustomSupport with AuthorizationImpersonationCustomSupport - with Logging { + with RequestIdAwareLogging { override val name: Rule.Name = JwtAuthRule.Name.name @@ -80,7 +80,7 @@ final class JwtAuthRule(val settings: JwtAuthRule.Settings, private def authorizeUsingJwtToken[B <: BlockContext : BlockContextUpdater](blockContext: B): Task[RuleResult[B]] = { jwtTokenFrom(blockContext.requestContext) match { case None => - logger.debug(s"[${blockContext.requestContext.id.show}] Authorization header '${settings.jwt.authorizationTokenDef.headerName.show}' is missing or does not contain a JWT token") + logger.debug(s"Authorization header '${settings.jwt.authorizationTokenDef.headerName.show}' is missing or does not contain a JWT token")(blockContext) Task.now(Rejected()) case Some(token) => process(token, blockContext) @@ -129,7 +129,7 @@ final class JwtAuthRule(val settings: JwtAuthRule.Settings, (implicit requestId: RequestId): Unit = { (settings.jwt.userClaim, user) match { case (Some(userClaim), Some(u)) => - logger.debug(s"[${requestId.show}] JWT resolved user for claim ${userClaim.name.rawPath}: ${u.show}") + logger.debug(s"JWT resolved user for claim ${userClaim.name.rawPath}: ${u.show}") case _ => } (settings.jwt.groupsConfig, groups) match { @@ -138,7 +138,7 @@ final class JwtAuthRule(val settings: JwtAuthRule.Settings, case Some(namesClaim) => s"claims (id:'${groupsConfig.idsClaim.name.show}',name:'${namesClaim.name.show}')" case None => s"claim '${groupsConfig.idsClaim.name.show}'" } - logger.debug(s"[${requestId.show}] JWT resolved groups for ${claimsDescription.show}: ${g.show}") + logger.debug(s"JWT resolved groups for ${claimsDescription.show}: ${g.show}") case _ => } } @@ -160,7 +160,7 @@ final class JwtAuthRule(val settings: JwtAuthRule.Settings, else { token.show } - logger.debug(s"[${requestId.show}] JWT token '${printableToken.show}' parsing error: ${ex.getClass.getSimpleName.show} ${ex.getMessage.show}") + logger.debug(s"JWT token '${printableToken.show}' parsing error: ${ex.getClass.getSimpleName.show} ${ex.getMessage.show}") } private def claimsFrom(token: Jwt.Token) @@ -188,7 +188,8 @@ final class JwtAuthRule(val settings: JwtAuthRule.Settings, settings.jwt.userClaim.map(payload.claims.userIdClaim) } - private def groupsFrom(payload: Jwt.Payload) = { + private def groupsFrom(payload: Jwt.Payload) + (implicit requestId: RequestId) = { settings.jwt.groupsConfig.map(groupsConfig => payload.claims.groupsClaim(groupsConfig.idsClaim, groupsConfig.namesClaim) ) diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/auth/ProxyAuthRule.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/auth/ProxyAuthRule.scala index 3b0b165d2d..9c026112cf 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/auth/ProxyAuthRule.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/auth/ProxyAuthRule.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.accesscontrol.blocks.rules.auth import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.mocks.MocksProvider import tech.beshu.ror.accesscontrol.blocks.rules.Rule import tech.beshu.ror.accesscontrol.blocks.rules.Rule.AuthenticationRule.EligibleUsersSupport @@ -41,7 +41,7 @@ final class ProxyAuthRule(val settings: Settings, override implicit val userIdCaseSensitivity: CaseSensitivity, override val impersonation: Impersonation) extends BaseAuthenticationRule - with Logging { + with RequestIdAwareLogging { private val userMatcher = PatternsMatcher.create(settings.userIds) diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/auth/TokenAuthenticationRule.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/auth/TokenAuthenticationRule.scala index bc23854836..17d73fc3ae 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/auth/TokenAuthenticationRule.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/auth/TokenAuthenticationRule.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.accesscontrol.blocks.rules.auth import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.mocks.MocksProvider import tech.beshu.ror.accesscontrol.blocks.rules.Rule import tech.beshu.ror.accesscontrol.blocks.rules.Rule.AuthenticationRule.EligibleUsersSupport @@ -38,7 +38,7 @@ final class TokenAuthenticationRule(val settings: Settings, override implicit val userIdCaseSensitivity: CaseSensitivity, override val impersonation: Impersonation) extends BaseAuthenticationRule - with Logging { + with RequestIdAwareLogging { override val name: Rule.Name = TokenAuthenticationRule.Name.name diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/auth/base/BaseBasicAuthAuthenticationRule.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/auth/base/BaseBasicAuthAuthenticationRule.scala index 60da0a7bd1..9ff3bb92a4 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/auth/base/BaseBasicAuthAuthenticationRule.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/auth/base/BaseBasicAuthAuthenticationRule.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.accesscontrol.blocks.rules.auth.base import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.rules.Rule.RuleResult import tech.beshu.ror.accesscontrol.blocks.rules.Rule.RuleResult.{Fulfilled, Rejected} import tech.beshu.ror.accesscontrol.blocks.rules.auth.base.BasicAuthenticationRule.Settings @@ -29,7 +29,7 @@ import tech.beshu.ror.implicits.* private [auth] abstract class BaseBasicAuthAuthenticationRule extends BaseAuthenticationRule - with Logging { + with RequestIdAwareLogging { protected def authenticateUsing(credentials: Credentials) (implicit requestId: RequestId): Task[Boolean] @@ -42,14 +42,14 @@ private [auth] abstract class BaseBasicAuthAuthenticationRule implicit val requestId: RequestId = requestContext.id.toRequestId requestContext.basicAuth.map(_.credentials) match { case Some(credentials) => - logger.debug(s"[${requestId.show}] Attempting Login as: ${credentials.user.show}") + logger.debug(s"Attempting Login as: ${credentials.user.show}") authenticateUsing(credentials) .map { case true => Fulfilled(blockContext.withUserMetadata(_.withLoggedUser(DirectlyLoggedUser(credentials.user)))) case false => Rejected() } case None => - logger.debug(s"[${requestId.show}] No basic auth") + logger.debug(s"No basic auth") Task.now(Rejected()) } } diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/auth/base/BaseGroupsRule.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/auth/base/BaseGroupsRule.scala index a29858bb53..6057e278f3 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/auth/base/BaseGroupsRule.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/auth/base/BaseGroupsRule.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.accesscontrol.blocks.rules.auth.base import cats.data.{NonEmptyList, OptionT} import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.definitions.UserDef import tech.beshu.ror.accesscontrol.blocks.definitions.UserDef.Mode.WithGroupsMapping.Auth import tech.beshu.ror.accesscontrol.blocks.definitions.UserDef.{GroupMappings, Mode} @@ -42,7 +42,7 @@ abstract class BaseGroupsRule[+GL <: GroupsLogic](override val name: Rule.Name, extends AuthRule with AuthenticationImpersonationCustomSupport with AuthorizationImpersonationCustomSupport - with Logging { + with RequestIdAwareLogging { override val eligibleUsers: EligibleUsersSupport = EligibleUsersSupport.NotAvailable @@ -158,7 +158,7 @@ abstract class BaseGroupsRule[+GL <: GroupsLogic](override val name: Rule.Name, None } .onErrorRecover { case ex => - logger.debug(s"[${blockContext.requestContext.id.show}] Authentication error", ex) + logger.debug(s"Authentication error", ex)(blockContext) None } } @@ -182,7 +182,7 @@ abstract class BaseGroupsRule[+GL <: GroupsLogic](override val name: Rule.Name, None } .onErrorRecover { case ex => - logger.debug(s"[${blockContext.requestContext.id.show}] Authentication & Authorization error", ex) + logger.debug(s"Authentication & Authorization error", ex)(blockContext) None } } @@ -218,7 +218,7 @@ abstract class BaseGroupsRule[+GL <: GroupsLogic](override val name: Rule.Name, None } .onErrorRecover { case ex => - logger.debug(s"[${blockContext.requestContext.id.show}] Authentication & Authorization error", ex) + logger.debug(s"Authentication & Authorization error", ex)(blockContext) Option.empty[B] } } diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/auth/base/BaseRorKbnRule.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/auth/base/BaseRorKbnRule.scala index e9acd80377..58e8600c15 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/auth/base/BaseRorKbnRule.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/auth/base/BaseRorKbnRule.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.accesscontrol.blocks.rules.auth.base import cats.implicits.toShow import io.jsonwebtoken.Jwts import io.jsonwebtoken.security.Keys -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.BlockContext import tech.beshu.ror.accesscontrol.blocks.definitions.RorKbnDef import tech.beshu.ror.accesscontrol.blocks.definitions.RorKbnDef.SignatureCheckMethod.{Ec, Hmac, Rsa} @@ -35,7 +35,7 @@ import tech.beshu.ror.utils.uniquelist.UniqueList import scala.util.Try -trait BaseRorKbnRule extends Logging { +trait BaseRorKbnRule extends RequestIdAwareLogging { protected def processUsingJwtToken[B <: BlockContext](blockContext: B, rorKbnDef: RorKbnDef) @@ -43,7 +43,7 @@ trait BaseRorKbnRule extends Logging { val authHeaderName = Header.Name.authorization blockContext.requestContext.bearerToken.map(h => Jwt.Token(h.value)) match { case None => - logger.debug(s"[${blockContext.requestContext.id.show}] Authorization header '${authHeaderName.show}' is missing or does not contain a bearer token") + logger.debug(s"Authorization header '${authHeaderName.show}' is missing or does not contain a bearer token")(blockContext) Rejected() case Some(token) => implicit val requestId: RequestId = blockContext.requestContext.id.toRequestId @@ -80,7 +80,7 @@ trait BaseRorKbnRule extends Logging { Try(parser(rorKbn).parseSignedClaims(token.value.value).getPayload) .toEither .map(Jwt.Payload.apply) - .left.map { ex => logger.debug(s"[${requestId.show}] JWT token '${token.show}' parsing error " + ex.getClass.getSimpleName) } + .left.map { ex => logger.debug(s"JWT token '${token.show}' parsing error " + ex.getClass.getSimpleName) } } private def parser(rorKbn: RorKbnDef) = rorKbn.checkMethod match { diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/ActionsRule.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/ActionsRule.scala index 815f1ac6a8..ef6b5cc8a2 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/ActionsRule.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/ActionsRule.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.accesscontrol.blocks.rules.elasticsearch import cats.data.NonEmptySet import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.rules.Rule import tech.beshu.ror.accesscontrol.blocks.rules.Rule.{RegularRule, RuleName, RuleResult} import tech.beshu.ror.accesscontrol.blocks.rules.elasticsearch.ActionsRule.Settings @@ -28,7 +28,7 @@ import tech.beshu.ror.accesscontrol.matchers.PatternsMatcher import tech.beshu.ror.implicits.* class ActionsRule(val settings: Settings) - extends RegularRule with Logging { + extends RegularRule with RequestIdAwareLogging { override val name: Rule.Name = ActionsRule.Name.name @@ -40,7 +40,7 @@ class ActionsRule(val settings: Settings) RuleResult.Fulfilled(blockContext) } else { implicit val requestId: RequestId = blockContext.requestContext.id.toRequestId - logger.debug(s"[${requestId.show}] This request uses the action '${requestContext.action.show}' and none of them is on the list.") + logger.debug(s"This request uses the action '${requestContext.action.show}' and none of them is on the list.") RuleResult.Rejected() } } diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/DataStreamsRule.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/DataStreamsRule.scala index 13c053ea23..692ccb0529 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/DataStreamsRule.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/DataStreamsRule.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.accesscontrol.blocks.rules.elasticsearch import cats.data.NonEmptySet import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.BlockContext.DataStreamRequestBlockContext import tech.beshu.ror.accesscontrol.blocks.rules.Rule import tech.beshu.ror.accesscontrol.blocks.rules.Rule.RuleResult.{Fulfilled, Rejected} @@ -37,7 +37,7 @@ import tech.beshu.ror.utils.ZeroKnowledgeIndexFilter class DataStreamsRule(val settings: Settings) extends RegularRule - with Logging { + with RequestIdAwareLogging { override val name: Rule.Name = DataStreamsRule.Name.name @@ -83,12 +83,12 @@ class DataStreamsRule(val settings: Settings) case CheckResult.Ok(processedDataStreams) => val filteredOutDataStreams = dataStreamsToCheck.diff(processedDataStreams) logger.debug( - s"[${requestContext.id.show}] Write request with data streams cannot proceed because some of the data streams " + + s"Write request with data streams cannot proceed because some of the data streams " + s"[${filteredOutDataStreams.show}] were filtered out by ACL. The request will be rejected.." - ) + )(requestContext) Left(()) case CheckResult.Failed => - logger.debug(s"[${requestContext.id.show}] The processed data streams do not match the allowed data streams. The request will be rejected..") + logger.debug(s"The processed data streams do not match the allowed data streams. The request will be rejected..")(requestContext) Left(()) } } diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/FieldsRule.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/FieldsRule.scala index c81ae3e690..f2ef401866 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/FieldsRule.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/FieldsRule.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.accesscontrol.blocks.rules.elasticsearch import cats.data.NonEmptyList import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.BlockContext.AllowsFieldsInRequest import tech.beshu.ror.accesscontrol.blocks.BlockContext.AllowsFieldsInRequest.* import tech.beshu.ror.accesscontrol.blocks.BlockContextUpdater.* @@ -42,7 +42,7 @@ import tech.beshu.ror.utils.uniquelist.UniqueNonEmptyList class FieldsRule(val settings: Settings) extends RegularRule - with Logging { + with RequestIdAwareLogging { override val name: Rule.Name = FieldsRule.Name.name @@ -76,7 +76,7 @@ class FieldsRule(val settings: Settings) case Some(resolvedFields) => processBlockContextUsingDefinedFLSMode(blockContext, resolvedFields) case None => - logger.warn(s"[${blockContext.requestContext.id.show}] Could not resolve any variable for field rule.") + logger.warn(s"Could not resolve any variable for field rule.")(blockContext) RuleResult.Rejected() } } @@ -101,7 +101,7 @@ class FieldsRule(val settings: Settings) case basedOnBlockContext: BasedOnBlockContextOnly => fulfillRuleWithResolvedStrategy(blockContext, fieldsRestrictions, resolvedStrategy = basedOnBlockContext) case Strategy.FlsAtLuceneLevelApproach => - logger.warn(s"[${blockContext.requestContext.id.show}] Could not use fls at lucene level with ES engine. Rejected.") + logger.warn(s"Could not use fls at lucene level with ES engine. Rejected.")(blockContext) RuleResult.Rejected() } } diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/FilterRule.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/FilterRule.scala index 3fb6bf10f9..c343e4b8b7 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/FilterRule.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/FilterRule.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.accesscontrol.blocks.rules.elasticsearch import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.BlockContextUpdater.* import tech.beshu.ror.accesscontrol.blocks.BlockContextWithFilterUpdater.{FilterableBlockContextWithFilterUpdater, FilterableMultiRequestBlockContextWithFilterUpdater} import tech.beshu.ror.accesscontrol.blocks.rules.Rule @@ -33,7 +33,7 @@ import tech.beshu.ror.accesscontrol.domain.Filter * Document level security (DLS) rule. */ class FilterRule(val settings: Settings) - extends RegularRule with Logging { + extends RegularRule with RequestIdAwareLogging { override val name: Rule.Name = FilterRule.Name.name diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/RepositoriesRule.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/RepositoriesRule.scala index 3d0ed12753..8f8659b8f6 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/RepositoriesRule.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/RepositoriesRule.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.accesscontrol.blocks.rules.elasticsearch import cats.data.NonEmptySet import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.BlockContext.* import tech.beshu.ror.accesscontrol.blocks.rules.Rule import tech.beshu.ror.accesscontrol.blocks.rules.Rule.RuleResult.{Fulfilled, Rejected} @@ -37,7 +37,7 @@ import tech.beshu.ror.utils.ZeroKnowledgeIndexFilter class RepositoriesRule(val settings: Settings) extends RegularRule - with Logging { + with RequestIdAwareLogging { override val name: Rule.Name = RepositoriesRule.Name.name @@ -95,12 +95,12 @@ class RepositoriesRule(val settings: Settings) case CheckResult.Ok(processedRepositories) => val filteredOutRepositories = repositoriesToCheck.diff(processedRepositories).map(_.show) logger.debug( - s"[${requestContext.id.show}] Write request with repositories cannot proceed because some of the repositories " + + s"Write request with repositories cannot proceed because some of the repositories " + s"[${filteredOutRepositories.show}] were filtered out by ACL. The request will be rejected.." - ) + )(requestContext) Left(()) case CheckResult.Failed => - logger.debug(s"[${requestContext.id.show}] The processed repositories do not match the allowed repositories. The request will be rejected..") + logger.debug(s"The processed repositories do not match the allowed repositories. The request will be rejected..")(requestContext) Left(()) } } diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/indices/IndicesRule.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/indices/IndicesRule.scala index 02fe40fe02..f951422306 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/indices/IndicesRule.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/indices/IndicesRule.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.accesscontrol.blocks.rules.elasticsearch.indices import cats.data.NonEmptySet import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.BlockContext.* import tech.beshu.ror.accesscontrol.blocks.BlockContext.DataStreamRequestBlockContext.BackingIndices import tech.beshu.ror.accesscontrol.blocks.BlockContext.HasIndexPacks.{indexPacksFromFilterableMultiBlockContext, indexPacksFromMultiIndexBlockContext} @@ -47,7 +47,7 @@ class IndicesRule(override val settings: Settings, extends RegularRule with AllClusterIndices with AllTemplateIndices - with Logging { + with RequestIdAwareLogging { import IndicesRule.* diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/indices/clusterindices/AllClusterIndices.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/indices/clusterindices/AllClusterIndices.scala index 0ceacee438..eb05b77e01 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/indices/clusterindices/AllClusterIndices.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/indices/clusterindices/AllClusterIndices.scala @@ -68,7 +68,7 @@ trait AllClusterIndices extends BaseIndicesProcessor { requestContext, PatternsMatcher.create(allAllowedIndices) ) - logger.debug(s"[${requestContext.id.show}] Checking local indices (allowed: [${allAllowedIndices.show}], requested: [${requestedIndices.show}])") + logger.debug(s"Checking local indices (allowed: [${allAllowedIndices.show}], requested: [${requestedIndices.show}])")(requestContext) canPass[ClusterIndexName.Local](requestContext, determinedKibanaIndex, requestedIndices) .map { case CanPass.Yes(narrowedIndices) => @@ -88,7 +88,7 @@ trait AllClusterIndices extends BaseIndicesProcessor { requestContext, PatternsMatcher.create(allAllowedIndices) ) - logger.debug(s"[${requestContext.id.show}] Checking remote indices (allowed: [${allAllowedIndices.show}], requested: [${requestedIndices.show}])") + logger.debug(s"Checking remote indices (allowed: [${allAllowedIndices.show}], requested: [${requestedIndices.show}])")(requestContext) canPass(requestContext, determinedKibanaIndex, requestedIndices) .map { case CanPass.Yes(narrowedIndices) => diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/indices/clusterindices/BaseIndicesProcessor.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/indices/clusterindices/BaseIndicesProcessor.scala index 75757e8ea7..d7d0ddea21 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/indices/clusterindices/BaseIndicesProcessor.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/indices/clusterindices/BaseIndicesProcessor.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.accesscontrol.blocks.rules.elasticsearch.indices.clusteri import cats.Show import cats.data.EitherT import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.rules.elasticsearch.indices.domain.CanPass.No.Reason import tech.beshu.ror.accesscontrol.blocks.rules.elasticsearch.indices.domain.CanPass.No.Reason.IndexNotExist import tech.beshu.ror.accesscontrol.blocks.rules.elasticsearch.indices.domain.IndicesCheckContinuation.{continue, stop} @@ -34,7 +34,7 @@ import tech.beshu.ror.syntax.* import tech.beshu.ror.utils.uniquelist.UniqueNonEmptyList trait BaseIndicesProcessor { - this: Logging => + this: RequestIdAwareLogging => import BaseIndicesProcessor.* @@ -73,13 +73,13 @@ trait BaseIndicesProcessor { determinedKibanaIndex match { case Some(kibanaIndexName) => import KibanaIndexName.* - logger.debug(s"[${requestId.show}] Checking - all requested indices relate to Kibana indices ...") + logger.debug(s"Checking - all requested indices relate to Kibana indices ...") val allKibanaRelatedIndices = requestedIndices.forall(_.name.isRelatedToKibanaIndex(kibanaIndexName)) if (allKibanaRelatedIndices) { - logger.debug(s"[${requestId.show}] ... matched [indices: ${requestedIndices.show}]. Stop") + logger.debug(s"... matched [indices: ${requestedIndices.show}]. Stop") stop(CanPass.Yes(requestedIndices.toCovariantSet)) } else { - logger.debug(s"[${requestId.show}] ... not matched. Continue") + logger.debug(s"... not matched. Continue") continue[Set[RequestedIndex[T]]] } case None => @@ -91,25 +91,25 @@ trait BaseIndicesProcessor { (implicit requestId: RequestContext.Id, allowedIndicesManager: IndicesManager[T]): Task[CheckContinuation[Set[RequestedIndex[T]]]] = { Task.delay { - logger.debug(s"[${requestId.show}] Checking - none or all indices ...") + logger.debug(s"Checking - none or all indices ...") } >> allowedIndicesManager .allIndicesAndAliasesAndDataStreams .map { allIndicesAndAliasesAndDataStreams => - logger.debug(s"[${requestId.show}] ... indices, aliases and data streams: [${allIndicesAndAliasesAndDataStreams.show}]") + logger.debug(s"... indices, aliases and data streams: [${allIndicesAndAliasesAndDataStreams.show}]") if (requestedIndices.exists(_.name.allIndicesRequested)) { val allowedIndices = allowedIndicesManager.allowedIndicesMatcher.filter(allIndicesAndAliasesAndDataStreams) stop( if (allowedIndices.nonEmpty) { - logger.debug(s"[${requestId.show}] ... matched [indices: ${requestedIndices.show}]. Stop") + logger.debug(s"... matched [indices: ${requestedIndices.show}]. Stop") CanPass.Yes(allowedIndices.map(RequestedIndex(_, excluded = false))) } else { - logger.debug(s"[${requestId.show}] ... not matched. Index not found. Stop") + logger.debug(s"... not matched. Index not found. Stop") CanPass.No(IndexNotExist) } ) } else { - logger.debug(s"[${requestId.show}] ... not matched. Continue") + logger.debug(s"... not matched. Continue") continue[Set[RequestedIndex[T]]] } } @@ -120,22 +120,22 @@ trait BaseIndicesProcessor { allowedIndicesManager: IndicesManager[T]): Task[CheckContinuation[Set[RequestedIndex[T]]]] = Task.delay { implicit val conversion: PatternsMatcher[T]#Conversion[RequestedIndex[T]] = PatternsMatcher.Conversion.from(_.name) - logger.debug(s"[${requestId.show}] Checking if all indices are matched ...") + logger.debug(s"Checking if all indices are matched ...") requestedIndices.toList match { case requestedIndex :: Nil if !requestedIndex.name.hasWildcard => if (allowedIndicesManager.allowedIndicesMatcher.`match`(requestedIndex)(_.name)) { - logger.debug(s"[${requestId.show}] ... matched [indices: ${requestedIndex.show}]. Stop") + logger.debug(s"... matched [indices: ${requestedIndex.show}]. Stop") stop(CanPass.Yes(Set(requestedIndex))) } else { - logger.debug(s"[${requestId.show}] ... not matched. Continue") + logger.debug(s"... not matched. Continue") continue } case _ if requestedIndices.iterator.forall(i => !i.name.hasWildcard) && allowedIndicesManager.allowedIndicesMatcher.filter(requestedIndices) == requestedIndices.toCovariantSet => - logger.debug(s"[${requestId.show}] ... matched [indices: ${requestedIndices.show}]. Stop") + logger.debug(s"... matched [indices: ${requestedIndices.show}]. Stop") stop(CanPass.Yes(requestedIndices.toCovariantSet)) case _ => - logger.debug(s"[${requestId.show}] ... not matched. Continue") + logger.debug(s"... not matched. Continue") continue[Set[RequestedIndex[T]]] } } @@ -145,7 +145,7 @@ trait BaseIndicesProcessor { allowedIndicesManager: IndicesManager[T]): Task[CheckContinuation[Set[RequestedIndex[T]]]] = { Task .delay { - logger.debug(s"[${requestId.show}] Checking - indices & aliases & data streams...") + logger.debug(s"Checking - indices & aliases & data streams...") } >> Task .sequence( // indices requested @@ -167,10 +167,10 @@ trait BaseIndicesProcessor { .map(_.flatten.toCovariantSet) .map { allowedRealIndices => if (allowedRealIndices.nonEmpty) { - logger.debug(s"[${requestId.show}] ... matched [indices: ${allowedRealIndices.show}]. Stop") + logger.debug(s"... matched [indices: ${allowedRealIndices.show}]. Stop") stop(CanPass.Yes(allowedRealIndices)) } else { - logger.debug(s"[${requestId.show}] ... not matched. Stop!") + logger.debug(s"... not matched. Stop!") stop(CanPass.No(Reason.IndexNotExist)) } } @@ -376,22 +376,22 @@ trait BaseIndicesProcessor { (implicit requestId: RequestContext.Id, allowedIndicesManager: IndicesManager[T]): Task[CheckContinuation[Set[RequestedIndex[T]]]] = { Task.delay { - logger.debug(s"[${requestId.show}] Checking - write request ...") + logger.debug(s"Checking - write request ...") // Write requests - logger.debug(s"[${requestId.show}] Stage 7") + logger.debug(s"Stage 7") if (requestedIndices.isEmpty && allowedIndicesManager.allowedIndicesMatcher.contains("")) { - logger.debug(s"[${requestId.show}] ... matched [indices: ${requestedIndices.show}]. Stop") + logger.debug(s"... matched [indices: ${requestedIndices.show}]. Stop") stop(CanPass.Yes(requestedIndices.toCovariantSet)) } else { // Reject write if at least one requested index is not allowed by the rule conf - logger.debug(s"[${requestId.show}] Stage 8") + logger.debug(s"Stage 8") stop { requestedIndices.find(requestedIndex => !allowedIndicesManager.allowedIndicesMatcher.`match`(requestedIndex.name)) match { case Some(_) => - logger.debug(s"[${requestId.show}] ... not matched. Stop") + logger.debug(s"... not matched. Stop") CanPass.No() case None => - logger.debug(s"[${requestId.show}] ... matched [indices: ${requestedIndices.show}]. Stop") + logger.debug(s"... matched [indices: ${requestedIndices.show}]. Stop") CanPass.Yes(requestedIndices.toCovariantSet) } } diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/indices/templates/AllTemplateIndices.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/indices/templates/AllTemplateIndices.scala index a2ecd92dc0..0c1c98c1b4 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/indices/templates/AllTemplateIndices.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/indices/templates/AllTemplateIndices.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.accesscontrol.blocks.rules.elasticsearch.indices.template import cats.data.NonEmptySet import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.BlockContext.TemplateRequestBlockContext import tech.beshu.ror.accesscontrol.blocks.rules.Rule.RuleResult import tech.beshu.ror.accesscontrol.blocks.rules.elasticsearch.indices.IndicesRule.Settings @@ -35,7 +35,7 @@ private[indices] trait AllTemplateIndices extends IndexTemplateIndices with ComponentTemplateIndices with LegacyTemplatesIndices - with Logging { + with RequestIdAwareLogging { protected def settings: Settings @@ -43,11 +43,11 @@ private[indices] trait AllTemplateIndices protected def processTemplateRequest(blockContext: TemplateRequestBlockContext): Task[RuleResult[TemplateRequestBlockContext]] = Task.now { implicit val allowedIndices: AllowedIndices = new AllowedIndices(settings.allowedIndices, blockContext) + implicit val _blockContext = blockContext logger.debug( - s"""[${blockContext.requestContext.id.show}] Checking - indices and aliases in Template related request. + s"""Checking - indices and aliases in Template related request. | Allowed indices by the rule: [${allowedIndices.resolved.show}]:""".oneLiner ) - implicit val _blockContext = blockContext val result = blockContext.templateOperation match { case GettingLegacyAndIndexTemplates(gettingLegacyTemplates, gettingIndexTemplates) => gettingLegacyAndIndexTemplates(gettingLegacyTemplates, gettingIndexTemplates) diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/indices/templates/ComponentTemplateIndices.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/indices/templates/ComponentTemplateIndices.scala index c0a4c13b23..6cd808956f 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/indices/templates/ComponentTemplateIndices.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/indices/templates/ComponentTemplateIndices.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.accesscontrol.blocks.rules.elasticsearch.indices.templates import cats.data.NonEmptyList -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.BlockContext.TemplateRequestBlockContext import tech.beshu.ror.accesscontrol.blocks.rules.Rule.RuleResult import tech.beshu.ror.accesscontrol.blocks.rules.Rule.RuleResult.resultBasedOnCondition @@ -27,19 +27,19 @@ import tech.beshu.ror.syntax.* import tech.beshu.ror.utils.ScalaOps.* private[indices] trait ComponentTemplateIndices - extends Logging { + extends RequestIdAwareLogging { this: AllTemplateIndices => protected def gettingComponentTemplates(templateNamePatterns: NonEmptyList[TemplateNamePattern]) (implicit blockContext: TemplateRequestBlockContext, allowedIndices: AllowedIndices): RuleResult[TemplateRequestBlockContext] = { logger.debug( - s"""[${blockContext.requestContext.id.show}] * getting Component Templates for name patterns [${templateNamePatterns.show}] ...""".oneLiner + s"""* getting Component Templates for name patterns [${templateNamePatterns.show}] ...""".oneLiner ) val existingTemplates = findTemplatesBy(templateNamePatterns.toList.toSet, in = blockContext) if (existingTemplates.isEmpty) { logger.debug( - s"""[${blockContext.requestContext.id.show}] * no Component Templates for name patterns [${templateNamePatterns.show}] found ...""" + s"""* no Component Templates for name patterns [${templateNamePatterns.show}] found ...""" ) RuleResult.fulfilled(blockContext) } else { @@ -57,13 +57,13 @@ private[indices] trait ComponentTemplateIndices (implicit blockContext: TemplateRequestBlockContext, allowedIndices: AllowedIndices): RuleResult[TemplateRequestBlockContext] = { logger.debug( - s"""[${blockContext.requestContext.id.show}] * adding Component Template [${newTemplateName.show}] with aliases + s"""* adding Component Template [${newTemplateName.show}] with aliases | [${aliases.show}] ...""".oneLiner ) findTemplateBy(name = newTemplateName, in = blockContext) match { case Some(existingTemplate) => logger.debug( - s"""[${blockContext.requestContext.id.show}] * Component Template with name [${existingTemplate.name.show}] exits ...""".oneLiner + s"""* Component Template with name [${existingTemplate.name.show}] exits ...""".oneLiner ) resultBasedOnCondition(blockContext) { canModifyExistingComponentTemplate(existingTemplate) && @@ -80,7 +80,7 @@ private[indices] trait ComponentTemplateIndices (implicit blockContext: TemplateRequestBlockContext, allowedIndices: AllowedIndices): RuleResult[TemplateRequestBlockContext] = { logger.debug( - s"""[${blockContext.requestContext.id.show}] * deleting Component Templates with name patterns [${templateNamePatterns.show}] ...""" + s"""* deleting Component Templates with name patterns [${templateNamePatterns.show}] ...""" ) val result = templateNamePatterns.foldLeft(List.empty[TemplateNamePattern].asRight[Unit]) { case (Right(acc), templateNamePattern) => @@ -111,12 +111,12 @@ private[indices] trait ComponentTemplateIndices val foundTemplates = findTemplatesBy(namePattern = templateNamePattern, in = blockContext) if (foundTemplates.isEmpty) { logger.debug( - s"""[${blockContext.requestContext.id.show}] * no Component Templates for name pattern [${templateNamePattern.show}] found ...""" + s"""* no Component Templates for name pattern [${templateNamePattern.show}] found ...""" ) Result.NotFound(templateNamePattern) } else { logger.debug( - s"""[${blockContext.requestContext.id.show}] * checking if Component Templates with names [${foundTemplates.map(_.name).show}] can be removed ...""" + s"""* checking if Component Templates with names [${foundTemplates.map(_.name).show}] can be removed ...""" ) if (foundTemplates.forall(canModifyExistingComponentTemplate)) Result.Allowed(templateNamePattern) else Result.Forbidden(templateNamePattern) @@ -128,7 +128,7 @@ private[indices] trait ComponentTemplateIndices (implicit blockContext: TemplateRequestBlockContext, allowedIndices: AllowedIndices) = { logger.debug( - s"""[${blockContext.requestContext.id.show}] * checking if Component Template [${newTemplateName.show}] can be added ...""" + s"""* checking if Component Template [${newTemplateName.show}] can be added ...""" ) lazy val allAliasesAllowed = if (newTemplateAliases.isEmpty) true @@ -136,7 +136,7 @@ private[indices] trait ComponentTemplateIndices newTemplateAliases.forall { alias => val allowed = isAliasAllowed(alias.name) if (!allowed) logger.debug( - s"""[${blockContext.requestContext.id.show}] STOP: one of Template's [${newTemplateName.show}] + s"""STOP: one of Template's [${newTemplateName.show}] | alias [${alias.show}] is forbidden.""".oneLiner ) allowed @@ -149,7 +149,7 @@ private[indices] trait ComponentTemplateIndices (implicit blockContext: TemplateRequestBlockContext, allowedIndices: AllowedIndices) = { logger.debug( - s"[${blockContext.requestContext.id.show}] * checking if Component Template [${existingTemplate.name.show}] can be modified by the user ..." + s"* checking if Component Template [${existingTemplate.name.show}] can be modified by the user ..." ) lazy val allAliasesAllowed = if (existingTemplate.aliases.isEmpty) true @@ -157,7 +157,7 @@ private[indices] trait ComponentTemplateIndices existingTemplate.aliases.forall { alias => val allowed = isAliasAllowed(alias) if (!allowed) logger.debug( - s"""[${blockContext.requestContext.id.show}] STOP: cannot allow to modify existing Component Template + s"""STOP: cannot allow to modify existing Component Template | [${existingTemplate.name.show}], because its alias [${alias.show}] is not allowed by rule | (it means that user has no access to it)""".oneLiner ) diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/indices/templates/IndexTemplateIndices.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/indices/templates/IndexTemplateIndices.scala index 1e44a64212..261446db4d 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/indices/templates/IndexTemplateIndices.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/indices/templates/IndexTemplateIndices.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.accesscontrol.blocks.rules.elasticsearch.indices.templates import cats.data.NonEmptyList -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.BlockContext.TemplateRequestBlockContext.TemplatesTransformation import tech.beshu.ror.accesscontrol.blocks.BlockContext.TemplateRequestBlockContext import tech.beshu.ror.accesscontrol.blocks.rules.Rule.RuleResult @@ -31,7 +31,7 @@ import tech.beshu.ror.utils.ScalaOps.* import tech.beshu.ror.utils.uniquelist.UniqueNonEmptyList private[indices] trait IndexTemplateIndices - extends Logging { + extends RequestIdAwareLogging { this: AllTemplateIndices => protected def gettingIndexTemplates(templateNamePatterns: NonEmptyList[TemplateNamePattern]) @@ -63,12 +63,12 @@ private[indices] trait IndexTemplateIndices (implicit blockContext: TemplateRequestBlockContext, allowedIndices: AllowedIndices): (List[TemplateNamePattern], TemplatesTransformation) = { logger.debug( - s"""[${blockContext.requestContext.id.show}] * getting Index Templates for name patterns [${templateNamePatterns.show}] ...""".oneLiner + s"""* getting Index Templates for name patterns [${templateNamePatterns.show}] ...""".oneLiner ) val existingTemplates = findTemplatesBy(templateNamePatterns.toList, in = blockContext) if (existingTemplates.isEmpty) { logger.debug( - s"""[${blockContext.requestContext.id.show}] * no Index Templates for name patterns [${templateNamePatterns.show}] found ...""" + s"""* no Index Templates for name patterns [${templateNamePatterns.show}] found ...""" ) (templateNamePatterns.toList, ignoreAnyTemplate) } else { @@ -123,13 +123,13 @@ private[indices] trait IndexTemplateIndices (implicit blockContext: TemplateRequestBlockContext, allowedIndices: AllowedIndices): Boolean = { logger.debug( - s"""[${blockContext.requestContext.id.show}] * adding Index Template [${newTemplateName.show}] with index + s"""* adding Index Template [${newTemplateName.show}] with index | patterns [${newTemplateIndicesPatterns.show}] and aliases [${aliases.show}] ...""".oneLiner ) findTemplateBy(name = newTemplateName, in = blockContext) match { case Some(existingTemplate) => logger.debug( - s"""[${blockContext.requestContext.id.show}] * Index Template with name [${existingTemplate.name.show}] + s"""* Index Template with name [${existingTemplate.name.show}] | (indices patterns [${existingTemplate.patterns.show}]) exits ...""".oneLiner ) canModifyExistingIndexTemplate(existingTemplate) && @@ -143,7 +143,7 @@ private[indices] trait IndexTemplateIndices (implicit blockContext: TemplateRequestBlockContext, allowedIndices: AllowedIndices): RuleResult[TemplateRequestBlockContext] = { logger.debug( - s"""[${blockContext.requestContext.id.show}] * deleting Index Templates with name patterns [${templateNamePatterns.show}] ...""" + s"""* deleting Index Templates with name patterns [${templateNamePatterns.show}] ...""" ) val result = templateNamePatterns.foldLeft(List.empty[TemplateNamePattern].asRight[Unit]) { case (Right(acc), templateNamePattern) => @@ -174,12 +174,12 @@ private[indices] trait IndexTemplateIndices val foundTemplates = findTemplatesBy(namePattern = templateNamePattern, in = blockContext) if (foundTemplates.isEmpty) { logger.debug( - s"""[${blockContext.requestContext.id.show}] * no Index Templates for name pattern [${templateNamePattern.show}] found ...""" + s"""* no Index Templates for name pattern [${templateNamePattern.show}] found ...""" ) Result.NotFound(templateNamePattern) } else { logger.debug( - s"""[${blockContext.requestContext.id.show}] * checking if Index Templates with names [${foundTemplates.map(_.name).show}] can be removed ...""" + s"""* checking if Index Templates with names [${foundTemplates.map(_.name).show}] can be removed ...""" ) if (foundTemplates.forall(canModifyExistingIndexTemplate)) Result.Allowed(templateNamePattern) else Result.Forbidden(templateNamePattern) @@ -192,7 +192,7 @@ private[indices] trait IndexTemplateIndices (implicit blockContext: TemplateRequestBlockContext, allowedIndices: AllowedIndices) = { logger.debug( - s"""[${blockContext.requestContext.id.show}] * checking if Index Template [${newTemplateName.show}] with indices + s"""* checking if Index Template [${newTemplateName.show}] with indices | patterns [${newTemplateIndicesPatterns.show}] and aliases [${newTemplateAliases.show}] can be added ...""".oneLiner ) lazy val allPatternAllowed = @@ -200,7 +200,7 @@ private[indices] trait IndexTemplateIndices .forall { pattern => val isPatternAllowed = allowedIndices.resolved.exists(pattern.isSubsetOf) if (!isPatternAllowed) logger.debug( - s"""[${blockContext.requestContext.id.show}] STOP: one of Template's [${newTemplateName.show}] + s"""STOP: one of Template's [${newTemplateName.show}] | index pattern [${pattern.show}] is forbidden.""".oneLiner ) isPatternAllowed @@ -212,7 +212,7 @@ private[indices] trait IndexTemplateIndices newTemplateAliases.forall { alias => val allowed = isAliasAllowed(alias.name) if (!allowed) logger.debug( - s"""[${blockContext.requestContext.id.show}] STOP: one of Template's [${newTemplateName.show}] + s"""STOP: one of Template's [${newTemplateName.show}] | alias [${alias.show}] is forbidden.""".oneLiner ) allowed @@ -227,7 +227,7 @@ private[indices] trait IndexTemplateIndices val isTemplateAllowed = existingTemplate.patterns.toList .exists { pattern => pattern.isAllowedByAny(allowedIndices.resolved) } if (!isTemplateAllowed) logger.debug( - s"""[${blockContext.requestContext.id.show}] WARN: Index Template [${existingTemplate.name.show}] is forbidden + s"""WARN: Index Template [${existingTemplate.name.show}] is forbidden | because none of its index patterns [${existingTemplate.patterns.show}] is allowed by the rule""".oneLiner ) isTemplateAllowed @@ -237,14 +237,14 @@ private[indices] trait IndexTemplateIndices (implicit blockContext: TemplateRequestBlockContext, allowedIndices: AllowedIndices) = { logger.debug( - s"[${blockContext.requestContext.id.show}] * checking if Index Template [${existingTemplate.name.show}] can be modified by the user ..." + s"* checking if Index Template [${existingTemplate.name.show}] can be modified by the user ..." ) lazy val allPatternAllowed = existingTemplate.patterns.toList .forall { pattern => val isPatternAllowed = allowedIndices.resolved.exists(pattern.isSubsetOf) if (!isPatternAllowed) logger.debug( - s"""[${blockContext.requestContext.id.show}] STOP: cannot allow to modify existing Index Template + s"""STOP: cannot allow to modify existing Index Template | [${existingTemplate.name.show}], because its index pattern [${pattern.show}] is not allowed by rule | (it means that user has no access to it)""".oneLiner ) @@ -256,7 +256,7 @@ private[indices] trait IndexTemplateIndices existingTemplate.aliases.forall { alias => val allowed = isAliasAllowed(alias) if (!allowed) logger.debug( - s"""[${blockContext.requestContext.id.show}] STOP: cannot allow to modify existing Index Template + s"""STOP: cannot allow to modify existing Index Template | [${existingTemplate.name.show}], because its alias [${alias.show}] is not allowed by rule | (it means that user has no access to it)""".oneLiner ) diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/indices/templates/LegacyTemplatesIndices.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/indices/templates/LegacyTemplatesIndices.scala index d46fd23d48..dbcf0cf28b 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/indices/templates/LegacyTemplatesIndices.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/elasticsearch/indices/templates/LegacyTemplatesIndices.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.accesscontrol.blocks.rules.elasticsearch.indices.templates import cats.data.NonEmptyList -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.BlockContext.TemplateRequestBlockContext.TemplatesTransformation import tech.beshu.ror.accesscontrol.blocks.BlockContext.TemplateRequestBlockContext import tech.beshu.ror.accesscontrol.blocks.rules.Rule.RuleResult @@ -31,7 +31,7 @@ import tech.beshu.ror.utils.ScalaOps.* import tech.beshu.ror.utils.uniquelist.UniqueNonEmptyList private[indices] trait LegacyTemplatesIndices - extends Logging { + extends RequestIdAwareLogging { this: AllTemplateIndices => protected def gettingLegacyTemplates(templateNamePatterns: NonEmptyList[TemplateNamePattern]) @@ -53,12 +53,12 @@ private[indices] trait LegacyTemplatesIndices (implicit blockContext: TemplateRequestBlockContext, allowedIndices: AllowedIndices): Either[Cause, (GettingLegacyTemplates, TemplatesTransformation)] = { logger.debug( - s"""[${blockContext.requestContext.id.show}] * getting Templates for name patterns [${templateNamePatterns.show}] ...""".oneLiner + s"""* getting Templates for name patterns [${templateNamePatterns.show}] ...""".oneLiner ) val existingTemplates = findTemplatesBy(templateNamePatterns.toList, in = blockContext) if (existingTemplates.isEmpty) { logger.debug( - s"""[${blockContext.requestContext.id.show}] * no Templates for name patterns [${templateNamePatterns.show}] found ...""" + s"""* no Templates for name patterns [${templateNamePatterns.show}] found ...""" ) Right((TemplateOperation.GettingLegacyTemplates(templateNamePatterns), identity)) } else { @@ -80,13 +80,13 @@ private[indices] trait LegacyTemplatesIndices (implicit blockContext: TemplateRequestBlockContext, allowedIndices: AllowedIndices): RuleResult[TemplateRequestBlockContext] = { logger.debug( - s"""[${blockContext.requestContext.id.show}] * adding Template [${newTemplateName.show}] with index + s"""* adding Template [${newTemplateName.show}] with index | patterns [${newTemplateIndicesPatterns.show}] and aliases [${aliases.show}] ...""".oneLiner ) findTemplateBy(name = newTemplateName, in = blockContext) match { case Some(existingTemplate) => logger.debug( - s"""[${blockContext.requestContext.id.show}] * Template with name [${existingTemplate.name.show}] + s"""* Template with name [${existingTemplate.name.show}] | (indices patterns [${existingTemplate.patterns.show}]) exits ...""".oneLiner ) resultBasedOnCondition(blockContext) { @@ -104,7 +104,7 @@ private[indices] trait LegacyTemplatesIndices (implicit blockContext: TemplateRequestBlockContext, allowedIndices: AllowedIndices): RuleResult[TemplateRequestBlockContext] = { logger.debug( - s"""[${blockContext.requestContext.id.show}] * deleting Templates with name patterns [${templateNamePatterns.show}] ...""" + s"""* deleting Templates with name patterns [${templateNamePatterns.show}] ...""" ) val result = templateNamePatterns.foldLeft(List.empty[TemplateNamePattern].asRight[Unit]) { case (Right(acc), templateNamePattern) => @@ -135,12 +135,12 @@ private[indices] trait LegacyTemplatesIndices val foundTemplates = findTemplatesBy(namePattern = templateNamePattern, in = blockContext) if (foundTemplates.isEmpty) { logger.debug( - s"""[${blockContext.requestContext.id.show}] * no Templates for name pattern [${templateNamePattern.show}] found ...""" + s"""* no Templates for name pattern [${templateNamePattern.show}] found ...""" ) Result.NotFound(templateNamePattern) } else { logger.debug( - s"""[${blockContext.requestContext.id.show}] * checking if Templates with names [${foundTemplates.map(_.name).show}] can be removed ...""" + s"""* checking if Templates with names [${foundTemplates.map(_.name).show}] can be removed ...""" ) if (foundTemplates.forall(canModifyExistingTemplate)) Result.Allowed(templateNamePattern) else Result.Forbidden(templateNamePattern) @@ -153,7 +153,7 @@ private[indices] trait LegacyTemplatesIndices (implicit blockContext: TemplateRequestBlockContext, allowedIndices: AllowedIndices) = { logger.debug( - s"""[${blockContext.requestContext.id.show}] * checking if Template [${newTemplateName.show}] with indices + s"""* checking if Template [${newTemplateName.show}] with indices | patterns [${newTemplateIndicesPatterns.show}] and aliases [${newTemplateAliases.show}] can be added ...""".oneLiner ) lazy val allPatternAllowed = @@ -161,7 +161,7 @@ private[indices] trait LegacyTemplatesIndices .forall { pattern => val isPatternAllowed = allowedIndices.resolved.exists(pattern.isSubsetOf) if (!isPatternAllowed) logger.debug( - s"""[${blockContext.requestContext.id.show}] STOP: one of Template's [${newTemplateName.show}] + s"""STOP: one of Template's [${newTemplateName.show}] | index pattern [${pattern.show}] is forbidden.""".oneLiner ) isPatternAllowed @@ -173,7 +173,7 @@ private[indices] trait LegacyTemplatesIndices newTemplateAliases.forall { alias => val allowed = isAliasAllowed(alias.name) if (!allowed) logger.debug( - s"""[${blockContext.requestContext.id.show}] STOP: one of Template's [${newTemplateName.show}] + s"""STOP: one of Template's [${newTemplateName.show}] | alias [${alias.show}] is forbidden.""".oneLiner ) allowed @@ -188,7 +188,7 @@ private[indices] trait LegacyTemplatesIndices val isTemplateAllowed = existingTemplate.patterns.toList .exists { pattern => pattern.isAllowedByAny(allowedIndices.resolved) } if (!isTemplateAllowed) logger.debug( - s"""[${blockContext.requestContext.id.show}] WARN: Template [${existingTemplate.name.show}] is forbidden + s"""WARN: Template [${existingTemplate.name.show}] is forbidden | because none of its index patterns [${existingTemplate.patterns.show}] is allowed by the rule""".oneLiner ) isTemplateAllowed @@ -198,7 +198,7 @@ private[indices] trait LegacyTemplatesIndices (implicit blockContext: TemplateRequestBlockContext, allowedIndices: AllowedIndices) = { logger.debug( - s"[${blockContext.requestContext.id.show}] * checking if Template [${existingTemplate.name.show}] with indices patterns" + + s"* checking if Template [${existingTemplate.name.show}] with indices patterns" + s" [${existingTemplate.patterns.show}] can be modified by the user ..." ) lazy val allPatternAllowed = @@ -206,7 +206,7 @@ private[indices] trait LegacyTemplatesIndices .forall { pattern => val isPatternAllowed = allowedIndices.resolved.exists(pattern.isSubsetOf) if (!isPatternAllowed) logger.debug( - s"""[${blockContext.requestContext.id.show}] STOP: cannot allow to modify existing Template + s"""STOP: cannot allow to modify existing Template | [${existingTemplate.name.show}], because its index pattern [${pattern.show}] is not allowed by rule | (it means that user has no access to it)""".oneLiner ) @@ -219,7 +219,7 @@ private[indices] trait LegacyTemplatesIndices existingTemplate.aliases.forall { alias => val allowed = isAliasAllowed(alias) if (!allowed) logger.debug( - s"""[${blockContext.requestContext.id.show}] STOP: cannot allow to modify existing Template + s"""STOP: cannot allow to modify existing Template | [${existingTemplate.name.show}], because its alias [${alias.show}] is not allowed by rule | (it means that user has no access to it)""".oneLiner ) diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/http/BaseHeaderRule.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/http/BaseHeaderRule.scala index 0644cdb71c..106d304ec0 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/http/BaseHeaderRule.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/http/BaseHeaderRule.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.accesscontrol.blocks.rules.http import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.rules.Rule.RegularRule import tech.beshu.ror.accesscontrol.domain.{AccessRequirement, Header} import tech.beshu.ror.accesscontrol.matchers.PatternsMatcher @@ -25,7 +25,7 @@ import tech.beshu.ror.accesscontrol.matchers.PatternsMatcher.Matchable import tech.beshu.ror.syntax.* private[http] abstract class BaseHeaderRule - extends RegularRule with Logging { + extends RegularRule with RequestIdAwareLogging { protected def isFulfilled(accessRequirement: AccessRequirement[Header], requestHeaders: Set[Header]): Boolean = { diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/http/HeadersAndRule.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/http/HeadersAndRule.scala index 861fa9c271..e1a83c743f 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/http/HeadersAndRule.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/http/HeadersAndRule.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.accesscontrol.blocks.rules.http import cats.Show import cats.data.NonEmptySet import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.rules.Rule import tech.beshu.ror.accesscontrol.blocks.rules.Rule.{RuleName, RuleResult} import tech.beshu.ror.accesscontrol.blocks.rules.http.HeadersAndRule.Settings @@ -32,7 +32,7 @@ import tech.beshu.ror.implicits.* * We match headers in a way that the header name is case-insensitive, and the header value is case-sensitive **/ class HeadersAndRule(val settings: Settings) - extends BaseHeaderRule with Logging { + extends BaseHeaderRule with RequestIdAwareLogging { override val name: Rule.Name = HeadersAndRule.Name.name @@ -52,7 +52,7 @@ class HeadersAndRule(val settings: Settings) private def logAccessRequirementNotFulfilled(accessRequirement: AccessRequirement[Header], requestContext: RequestContext): Unit = { implicit val headerShowImplicit: Show[Header] = headerShow - logger.debug(s"[${requestContext.id.show}] Request headers don't fulfil given header access requirement: ${accessRequirement.show}") + logger.debug(s"Request headers don't fulfil given header access requirement: ${accessRequirement.show}")(requestContext) } } diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/http/HeadersOrRule.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/http/HeadersOrRule.scala index fb8e92a1c8..92fc92dbef 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/http/HeadersOrRule.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/http/HeadersOrRule.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.accesscontrol.blocks.rules.http import cats.Show import cats.data.NonEmptySet import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.rules.Rule import tech.beshu.ror.accesscontrol.blocks.rules.Rule.{RuleName, RuleResult} import tech.beshu.ror.accesscontrol.blocks.rules.http.HeadersOrRule.Settings @@ -32,7 +32,7 @@ import tech.beshu.ror.implicits.* * We match headers in a way that the header name is case-insensitive, and the header value is case-sensitive **/ class HeadersOrRule(val settings: Settings) - extends BaseHeaderRule with Logging { + extends BaseHeaderRule with RequestIdAwareLogging { override val name: Rule.Name = HeadersOrRule.Name.name @@ -50,7 +50,7 @@ class HeadersOrRule(val settings: Settings) private def logAccessRequirementsNotFulfilled(requestContext: RequestContext): Unit = { implicit val headerShowImplicit: Show[Header] = headerShow - logger.debug(s"[${requestContext.id.show}] Request headers don't fulfil any of header access requirements: ${settings.headerAccessRequirements.show}") + logger.debug(s"Request headers don't fulfil any of header access requirements: ${settings.headerAccessRequirements.show}")(requestContext) } } diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/http/SessionMaxIdleRule.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/http/SessionMaxIdleRule.scala index 617ea2c9fe..8132e816e2 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/http/SessionMaxIdleRule.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/http/SessionMaxIdleRule.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.accesscontrol.blocks.rules.http import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.rules.Rule import tech.beshu.ror.accesscontrol.blocks.rules.Rule.RuleResult.{Fulfilled, Rejected} import tech.beshu.ror.accesscontrol.blocks.rules.Rule.{RegularRule, RuleName, RuleResult} @@ -36,7 +36,7 @@ final class SessionMaxIdleRule(val settings: Settings, implicit val caseSensitivity: CaseSensitivity) (implicit clock: Clock, uuidProvider: UuidProvider) - extends RegularRule with Logging { + extends RegularRule with RequestIdAwareLogging { override val name: Rule.Name = SessionMaxIdleRule.Name.name @@ -46,7 +46,7 @@ final class SessionMaxIdleRule(val settings: Settings, checkCookieFor(user, blockContext) case None => implicit val requestId: RequestId = blockContext.requestContext.id.toRequestId - logger.warn(s"[${requestId.show}] Cannot state the logged in user, put the authentication rule on top of the block!") + logger.warn(s"Cannot state the logged in user, put the authentication rule on top of the block!") Rejected() } } diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/kibana/BaseKibanaRule.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/kibana/BaseKibanaRule.scala index 89cc6d44e7..53f2653278 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/kibana/BaseKibanaRule.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/kibana/BaseKibanaRule.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.accesscontrol.blocks.rules.kibana import cats.Id import cats.data.ReaderT -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.rules.Rule import tech.beshu.ror.accesscontrol.blocks.rules.Rule.RegularRule import tech.beshu.ror.accesscontrol.blocks.rules.kibana.BaseKibanaRule.* @@ -39,7 +39,7 @@ trait KibanaRelatedRule { } abstract class BaseKibanaRule(val settings: Settings) - extends RegularRule with KibanaRelatedRule with Logging { + extends RegularRule with KibanaRelatedRule with RequestIdAwareLogging { import BaseKibanaRule.* @@ -58,13 +58,13 @@ abstract class BaseKibanaRule(val settings: Settings) private def isUnrestrictedAccessConfigured = ProcessingContext.create { (r, _) => val result = settings.access === KibanaAccess.Unrestricted - logger.debug(s"[${r.id.show}] Is unrestricted access configured? ${result.show}") + logger.debug(s"Is unrestricted access configured? ${result.show}")(r) result } private def isCurrentUserMetadataRequest = ProcessingContext.create { (r, _) => val result = r.restRequest.path.isCurrentUserMetadataPath - logger.debug(s"[${r.id.show}] Is is a current user metadata request? ${result.show}") + logger.debug(s"Is is a current user metadata request? ${result.show}")(r) result } @@ -80,7 +80,7 @@ abstract class BaseKibanaRule(val settings: Settings) private def isAdminAccessConfigured = ProcessingContext.create { (r, _) => val result = settings.access === KibanaAccess.Admin - logger.debug(s"[${r.id.show}] Is the admin access configured in the rule? ${result.show}") + logger.debug(s"Is the admin access configured in the rule? ${result.show}")(r) result } @@ -93,7 +93,7 @@ abstract class BaseKibanaRule(val settings: Settings) private def doesRequestContainNoIndices = ProcessingContext.create { (r, _) => val result = r.initialBlockContext.indices.isEmpty - logger.debug(s"[${r.id.show}] Does request contain no indices? ${result.show}") + logger.debug(s"Does request contain no indices? ${result.show}")(r) result } @@ -107,7 +107,7 @@ abstract class BaseKibanaRule(val settings: Settings) private def isAccessOtherThanRoStrictConfigured = ProcessingContext.create { (r, _) => val result = settings.access =!= ROStrict - logger.debug(s"[${r.id.show}] Is access other than ROStrict configured? ${result.show}") + logger.debug(s"Is access other than ROStrict configured? ${result.show}")(r) result } @@ -133,7 +133,7 @@ abstract class BaseKibanaRule(val settings: Settings) case Some(paths) => paths.matcher(path.value.value).find() case None => false } - logger.debug(s"[${requestContext.id.show}] Is non strict allowed path? ${result.show}") + logger.debug(s"Is non strict allowed path? ${result.show}")(requestContext) result } @@ -143,7 +143,7 @@ abstract class BaseKibanaRule(val settings: Settings) } else { false } - logger.debug(s"[${requestContext.id.show}] Is targeting Kibana? ${result.show}") + logger.debug(s"Is targeting Kibana? ${result.show}")(requestContext) result } @@ -165,7 +165,7 @@ abstract class BaseKibanaRule(val settings: Settings) .allHeaders .find(_.name === Header.Name.kibanaRequestPath) .exists(_.value.value.contains(s"/$pathPart/")) - logger.debug(s"[${requestContext.id.show}] Does kibana request contains '${pathPart.show}' in path? ${result.show}") + logger.debug(s"Does kibana request contains '${pathPart.show}' in path? ${result.show}")(requestContext) result } @@ -178,7 +178,7 @@ abstract class BaseKibanaRule(val settings: Settings) val result = requestContext.initialBlockContext.indices.headOption match case Some(requestedIndex) if requestedIndex.name == index => true case Some(_) | None => false - logger.debug(s"[${requestContext.id.show}] Is related to single index '${index.nonEmptyStringify}'? ${result.show}") + logger.debug(s"Is related to single index '${index.nonEmptyStringify}'? ${result.show}")(requestContext) result } @@ -188,7 +188,7 @@ abstract class BaseKibanaRule(val settings: Settings) case head :: Nil => kibanaSampleDataIndexMatcher.`match`(head.name) case _ => false } - logger.debug(s"[${requestContext.id.show}] Is related to Kibana sample data index? ${result.show}") + logger.debug(s"Is related to Kibana sample data index? ${result.show}")(requestContext) result } @@ -198,43 +198,43 @@ abstract class BaseKibanaRule(val settings: Settings) case head :: Nil => kibanaSampleDataStreamMatcher.`match`(head) case _ => false } - logger.debug(s"[${requestContext.id.show}] Is related to Kibana sample data index? ${result.show}") + logger.debug(s"Is related to Kibana sample data index? ${result.show}")(requestContext) result } private def isRoAction = ProcessingContext.create { (requestContext, _) => val result = roActionPatternsMatcher.`match`(requestContext.action) - logger.debug(s"[${requestContext.id.show}] Is RO action? ${result.show}") + logger.debug(s"Is RO action? ${result.show}")(requestContext) result } private def isClusterAction = ProcessingContext.create { (requestContext, _) => val result = clusterActionPatternsMatcher.`match`(requestContext.action) - logger.debug(s"[${requestContext.id.show}] Is Cluster action? ${result.show}") + logger.debug(s"Is Cluster action? ${result.show}")(requestContext) result } private def isRwAction = ProcessingContext.create { (requestContext, _) => val result = rwActionPatternsMatcher.`match`(requestContext.action) - logger.debug(s"[${requestContext.id.show}] Is RW action? ${result.show}") + logger.debug(s"Is RW action? ${result.show}")(requestContext) result } private def isAdminAction = ProcessingContext.create { (requestContext, _) => val result = adminActionPatternsMatcher.`match`(requestContext.action) - logger.debug(s"[${requestContext.id.show}] Is Admin action? ${result.show}") + logger.debug(s"Is Admin action? ${result.show}")(requestContext) result } private def isNonStrictAction = ProcessingContext.create { (requestContext, _) => val result = nonStrictActions.`match`(requestContext.action) - logger.debug(s"[${requestContext.id.show}] Is non strict action? ${result.show}") + logger.debug(s"Is non strict action? ${result.show}")(requestContext) result } private def isIndicesWriteAction = ProcessingContext.create { (requestContext, _) => val result = indicesWriteAction.`match`(requestContext.action) - logger.debug(s"[${requestContext.id.show}] Is indices write action? ${result.show}") + logger.debug(s"Is indices write action? ${result.show}")(requestContext) result } @@ -245,7 +245,7 @@ abstract class BaseKibanaRule(val settings: Settings) case RO | ROStrict | ApiOnly => false case RW | Admin | Unrestricted => true } - logger.debug(s"[${r.id.show}] Can Kibana be modified? ${result.show}") + logger.debug(s"Can Kibana be modified? ${result.show}")(r) result } diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/kibana/KibanaUserDataRule.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/kibana/KibanaUserDataRule.scala index 676a129833..45cf97e4d3 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/kibana/KibanaUserDataRule.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/kibana/KibanaUserDataRule.scala @@ -88,7 +88,7 @@ class KibanaUserDataRule(override val settings: Settings) case Right(resolvedKibanaIndexTemplate) => Some(resolvedKibanaIndexTemplate) case Left(error) => - logger.warn(s"[${context.requestContext.id.show}] Cannot resolve variable(s) used in Kibana template index name; error: ${error.show}") + logger.warn(s"Cannot resolve variable(s) used in Kibana template index name; error: ${error.show}")(context) None } } @@ -107,7 +107,7 @@ class KibanaUserDataRule(override val settings: Settings) case Right(resolvedKibanaMetadata) => Some(resolvedKibanaMetadata) case Left(error) => - logger.warn(s"[${context.requestContext.id.show}] Cannot resolve variable(s) used in Kibana metadata; error: ${error.show}") + logger.warn(s"Cannot resolve variable(s) used in Kibana metadata; error: ${error.show}")(context) None } } diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/tranport/BaseHostsRule.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/tranport/BaseHostsRule.scala index 74786d0851..b264a1efd5 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/tranport/BaseHostsRule.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/tranport/BaseHostsRule.scala @@ -21,7 +21,7 @@ import cats.data.{NonEmptyList, NonEmptySet, OptionT} import com.comcast.ip4s.Host import com.comcast.ip4s.Host.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.BlockContext import tech.beshu.ror.accesscontrol.blocks.rules.Rule.RegularRule import tech.beshu.ror.accesscontrol.blocks.variables.runtime.RuntimeMultiResolvableVariable @@ -33,7 +33,7 @@ import tech.beshu.ror.utils.TaskOps.* import scala.util.Success private[rules] abstract class BaseHostsRule(resolver: HostnameResolver) - extends RegularRule with Logging { + extends RegularRule with RequestIdAwareLogging { protected def checkAllowedAddresses(blockContext: BlockContext) (allowedAddresses: NonEmptySet[RuntimeMultiResolvableVariable[Address]], @@ -63,7 +63,7 @@ private[rules] abstract class BaseHostsRule(resolver: HostnameResolver) allowedHostIps <- OptionT(parallelyResolved.map(_.allowedHost)) addressIps <- OptionT(parallelyResolved.map(_.address)) isMatching = addressIps.exists(ip => allowedHostIps.exists(_.contains(ip))) - _ = logger.debug(s"[${blockContext.requestContext.id.show}] address IPs [${address.show}] resolved to [${addressIps.show}], allowed addresses [${allowedHost.show}] resolved to [${allowedHostIps.show}], isMatching=${isMatching.show}") + _ = logger.debug(s"address IPs [${address.show}] resolved to [${addressIps.show}], allowed addresses [${allowedHost.show}] resolved to [${allowedHostIps.show}], isMatching=${isMatching.show}")(blockContext) } yield isMatching result.value.map(_.getOrElse(false)) } @@ -79,7 +79,7 @@ private[rules] abstract class BaseHostsRule(resolver: HostnameResolver) resolver .resolve(address) .andThen { - case Success(None) => logger.warn(s"[${requestId.show}] Cannot resolve hostname: ${Show[Host].show(address.value)}") + case Success(None) => logger.warn(s"Cannot resolve hostname: ${Show[Host].show(address.value)}") } } } diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/tranport/HostsRule.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/tranport/HostsRule.scala index 2e05fbc16e..88e0f94215 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/tranport/HostsRule.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/rules/tranport/HostsRule.scala @@ -60,7 +60,7 @@ class HostsRule(val settings: Settings, addressToCheck = remoteAddress ).map(condition => RuleResult.resultBasedOnCondition(blockContext)(condition)) case None => - logger.warn(s"[${blockContext.requestContext.id.show}] Remote address is unavailable!") + logger.warn(s"Remote address is unavailable!")(blockContext) Task.now(Rejected()) } } diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/variables/runtime/RuntimeResolvableVariableCreator.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/variables/runtime/RuntimeResolvableVariableCreator.scala index c1839d1845..630383f42e 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/variables/runtime/RuntimeResolvableVariableCreator.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/blocks/variables/runtime/RuntimeResolvableVariableCreator.scala @@ -21,7 +21,7 @@ import cats.instances.either.* import cats.instances.list.* import cats.syntax.traverse.* import eu.timepit.refined.types.string.NonEmptyString -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.variables.Tokenizer.Token import tech.beshu.ror.accesscontrol.blocks.variables.Tokenizer.Token.Transformation import tech.beshu.ror.accesscontrol.blocks.variables.runtime.MultiExtractable.SingleExtractableWrapper @@ -38,7 +38,7 @@ import tech.beshu.ror.utils.json.JsonPath import scala.util.matching.Regex import scala.util.{Failure, Success} -class RuntimeResolvableVariableCreator(transformationCompiler: TransformationCompiler) extends Logging { +class RuntimeResolvableVariableCreator(transformationCompiler: TransformationCompiler) extends RequestIdAwareLogging { def createSingleResolvableVariableFrom[T: Convertible](text: NonEmptyString): Either[CreationError, RuntimeSingleResolvableVariable[T]] = { singleExtactablesFrom(Tokenizer.tokenize(text)) @@ -141,7 +141,7 @@ class RuntimeResolvableVariableCreator(transformationCompiler: TransformationCom case Success(compiledPath) => Right(`type`.createJwtVariableExtractable(compiledPath, maybeTransformation)) case Failure(ex) => - logger.debug("Compiling JSON path failed", ex) + noRequestIdLogger.debug("Compiling JSON path failed", ex) Left(CreationError.InvalidVariableDefinition(s"cannot compile '${jsonPathStr.show}' to JsonPath")) } } diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/domain/misc.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/domain/misc.scala index fd355d735a..8987e6943e 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/domain/misc.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/domain/misc.scala @@ -18,14 +18,20 @@ package tech.beshu.ror.accesscontrol.domain import eu.timepit.refined.auto.* import eu.timepit.refined.types.string.NonEmptyString -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.variables.runtime.RuntimeSingleResolvableVariable import tech.beshu.ror.utils.js.JsCompiler import java.util.regex import scala.util.{Failure, Success, Try} -final case class RequestId(value: String) +trait HasRequestId { + def requestId: RequestId +} + +final case class RequestId(value: String) extends HasRequestId { + override def requestId: RequestId = this +} sealed trait CaseSensitivity object CaseSensitivity { @@ -65,7 +71,7 @@ object JavaRegex { } final case class JsRegex private(value: NonEmptyString) -object JsRegex extends Logging { +object JsRegex extends RequestIdAwareLogging { private val extractRawRegex = """\/(.*)\/""".r def compile(str: NonEmptyString) @@ -77,7 +83,7 @@ object JsRegex extends Logging { case Success(_) => Right(new JsRegex(str)) case Failure(ex) => - logger.error("JS compiler error", ex) + noRequestIdLogger.error("JS compiler error", ex) Left(CompilationResult.SyntaxError) } case _ => diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/domain/security.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/domain/security.scala index 7d5af46d13..8514685bfb 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/domain/security.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/domain/security.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.accesscontrol.domain import cats.Eq import eu.timepit.refined.types.string.NonEmptyString import io.jsonwebtoken.Claims -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.ScalaOps.StringOps import tech.beshu.ror.utils.json.JsonPath @@ -39,7 +39,7 @@ final case class BasicAuth private(credentials: Credentials) { NonEmptyString.unsafeFrom(s"Basic ${Base64.getEncoder.encodeToString(s"${credentials.user.value}:${credentials.secret.value}".getBytes(UTF_8))}") ) } -object BasicAuth extends Logging { +object BasicAuth extends RequestIdAwareLogging { def fromCredentials(credentials: Credentials) = { BasicAuth(credentials) } @@ -58,7 +58,7 @@ object BasicAuth extends Logging { val basicAuth = fromBase64(rawValue.substring(authMethodName.length)) basicAuth match { case None => - logger.warn(s"Cannot decode value '${headerValue.show}' to Basic Auth") + noRequestIdLogger.warn(s"Cannot decode value '${headerValue.show}' to Basic Auth") case Some(_) => } basicAuth diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/factory/BlockValidator.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/factory/BlockValidator.scala index 9050be0eb0..07915482ec 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/factory/BlockValidator.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/factory/BlockValidator.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.accesscontrol.factory import cats.data.* import cats.data.Validated.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.Block import tech.beshu.ror.accesscontrol.blocks.Block.RuleDefinition import tech.beshu.ror.accesscontrol.blocks.rules.Rule @@ -33,7 +33,7 @@ import tech.beshu.ror.accesscontrol.domain.KibanaAccess import tech.beshu.ror.accesscontrol.factory.BlockValidator.BlockValidationError.{KibanaRuleTogetherWith, KibanaUserDataRuleTogetherWith, RuleDoesNotMeetRequirement} import tech.beshu.ror.implicits.* -object BlockValidator extends Logging { +object BlockValidator extends RequestIdAwareLogging { def validate(blockName: Block.Name, rules: NonEmptyList[RuleDefinition[Rule]]): ValidatedNel[BlockValidationError, Unit] = { diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/factory/HttpClientsFactory.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/factory/HttpClientsFactory.scala index 1ac8e2218d..b4ca667af1 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/factory/HttpClientsFactory.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/factory/HttpClientsFactory.scala @@ -23,10 +23,11 @@ import io.lemonlabs.uri.Url import io.netty.util.HashedWheelTimer import monix.eval.Task import monix.execution.atomic.AtomicBoolean -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.asynchttpclient.Dsl.asyncHttpClient import org.asynchttpclient.netty.channel.DefaultChannelPool import org.asynchttpclient.{AsyncHttpClient, DefaultAsyncHttpClientConfig} +import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.accesscontrol.factory.HttpClientsFactory.HttpClient.Method import tech.beshu.ror.accesscontrol.factory.HttpClientsFactory.{Config, HttpClient} import tech.beshu.ror.implicits.* @@ -118,9 +119,10 @@ class AsyncHttpClientsFactory extends HttpClientsFactory { } private class LoggingSimpleHttpClient[F[_] : Async](delegate: SimpleHttpClient[F]) - extends SimpleHttpClient[F] with Logging { + extends SimpleHttpClient[F] with RequestIdAwareLogging { - override def send(request: HttpClient.Request): F[HttpClient.Response] = { + override def send(request: HttpClient.Request) + (implicit requestId: RequestId): F[HttpClient.Response] = { delegate .send(request) .recoverWith { case e: Throwable => @@ -142,7 +144,8 @@ private class LoggingSimpleHttpClient[F[_] : Async](delegate: SimpleHttpClient[F class AsyncBasedSimpleHttpClient(asyncHttpClient: AsyncHttpClient) extends SimpleHttpClient[Task] { - override def send(request: HttpClient.Request): Task[HttpClient.Response] = { + override def send(request: HttpClient.Request) + (implicit requestId: RequestId): Task[HttpClient.Response] = { val asyncRequestBase = request.method match { case Method.Get => asyncHttpClient.prepareGet(request.url.toStringRaw) case Method.Post => asyncHttpClient.preparePost(request.url.toStringRaw) @@ -164,6 +167,7 @@ class AsyncBasedSimpleHttpClient(asyncHttpClient: AsyncHttpClient) extends Simpl } trait SimpleHttpClient[F[_]] { - def send(request: HttpClient.Request): F[HttpClient.Response] + def send(request: HttpClient.Request) + (implicit requestId: RequestId): F[HttpClient.Response] def close(): F[Unit] } diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/factory/RawRorConfigBasedCoreFactory.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/factory/RawRorConfigBasedCoreFactory.scala index f16dc60238..61cc48aecc 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/factory/RawRorConfigBasedCoreFactory.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/factory/RawRorConfigBasedCoreFactory.scala @@ -20,7 +20,7 @@ import cats.data.{NonEmptyList, State, Validated} import cats.kernel.Monoid import io.circe.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.* import tech.beshu.ror.accesscontrol.EnabledAccessControlList.AccessControlListStaticContext import tech.beshu.ror.accesscontrol.audit.LoggingContext @@ -69,7 +69,7 @@ trait CoreFactory { class RawRorConfigBasedCoreFactory(esVersion: EsVersion) (implicit environmentConfig: EnvironmentConfig) - extends CoreFactory with Logging { + extends CoreFactory with RequestIdAwareLogging { override def createCoreFrom(config: RawRorConfig, rorIndexNameConfiguration: RorConfigurationIndex, @@ -387,7 +387,7 @@ class RawRorConfigBasedCoreFactory(esVersion: EsVersion) } } yield { val blocks = blocksNel.map(_.block) - blocks.toList.foreach { block => logger.info(s"ADDING BLOCK:\t ${block.show}") } + blocks.toList.foreach { block => noRequestIdLogger.info(s"ADDING BLOCK:\t ${block.show}") } val localUsers: LocalUsers = { val fromUserDefs = localUsersFromUserDefs(userDefs) val fromImpersonatorDefs = localUsersFromImpersonatorDefs(impersonationDefs) diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/factory/decoders/AuditingSettingsDecoder.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/factory/decoders/AuditingSettingsDecoder.scala index db00bf2192..8fed8d4dc7 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/factory/decoders/AuditingSettingsDecoder.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/factory/decoders/AuditingSettingsDecoder.scala @@ -21,7 +21,7 @@ import eu.timepit.refined.types.string.NonEmptyString import io.circe.* import io.circe.Decoder.* import io.lemonlabs.uri.Uri -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.audit.AuditingTool import tech.beshu.ror.accesscontrol.audit.AuditingTool.AuditSettings.AuditSink import tech.beshu.ror.accesscontrol.audit.AuditingTool.AuditSettings.AuditSink.Config @@ -48,7 +48,7 @@ import tech.beshu.ror.utils.yaml.YamlKeyDecoder import scala.annotation.nowarn import scala.util.{Failure, Success, Try} -object AuditingSettingsDecoder extends Logging { +object AuditingSettingsDecoder extends RequestIdAwareLogging { def instance(esVersion: EsVersion): Decoder[Option[AuditingTool.AuditSettings]] = { for { @@ -351,7 +351,7 @@ object AuditingSettingsDecoder extends Logging { } } match { case Success(Some(customSerializer)) => - logger.info(s"Using custom serializer: ${customSerializer.getClass.getName}") + noRequestIdLogger.info(s"Using custom serializer: ${customSerializer.getClass.getName}") Right(customSerializer) case Success(None) => Left(auditSettingsError(s"Class ${fullClassName.show} is not a subclass of ${classOf[AuditLogSerializer].getName.show} or ${classOf[tech.beshu.ror.requestcontext.AuditLogSerializer[_]].getName.show}")) case Failure(ex) => Left(auditSettingsError(s"Cannot create instance of class '${fullClassName.show}', error: ${ex.getMessage.show}")) diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/factory/decoders/common.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/factory/decoders/common.scala index 57f2de6b51..5facdc39c7 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/factory/decoders/common.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/factory/decoders/common.scala @@ -22,7 +22,7 @@ import eu.timepit.refined.numeric.Positive import eu.timepit.refined.types.string.NonEmptyString import io.circe.Decoder import io.lemonlabs.uri.Uri -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.variables.runtime.ResolvableJsonRepresentationOps.* import tech.beshu.ror.accesscontrol.blocks.variables.runtime.RuntimeResolvableVariable.Convertible import tech.beshu.ror.accesscontrol.blocks.variables.runtime.RuntimeResolvableVariable.Convertible.ConvertError @@ -50,7 +50,7 @@ import java.net.URI import scala.concurrent.duration.* import scala.util.{Failure, Success, Try} -object common extends Logging { +object common extends RequestIdAwareLogging { implicit val nonEmptyStringDecoder: Decoder[NonEmptyString] = Decoder @@ -287,7 +287,7 @@ object common extends Logging { .toEither .left .map { ex => - logger.errorEx("JSON path compilation failed", ex) + noRequestIdLogger.errorEx("JSON path compilation failed", ex) DefinitionsLevelCreationError(Message(s"Cannot compile '${jsonPathStr.show}' to JSON path")) } } diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/factory/decoders/definitions/LdapServicesDecoder.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/factory/decoders/definitions/LdapServicesDecoder.scala index c190d49858..8a873a17b5 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/factory/decoders/definitions/LdapServicesDecoder.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/factory/decoders/definitions/LdapServicesDecoder.scala @@ -23,7 +23,7 @@ import eu.timepit.refined.numeric.Positive import eu.timepit.refined.types.string.NonEmptyString import io.circe.{Decoder, DecodingFailure, HCursor} import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.implicits.* import tech.beshu.ror.accesscontrol.blocks.definitions.CircuitBreakerConfig import tech.beshu.ror.accesscontrol.blocks.definitions.ldap.* @@ -50,7 +50,7 @@ import java.time.Clock import java.util.concurrent.TimeUnit import scala.language.postfixOps -object LdapServicesDecoder extends Logging { +object LdapServicesDecoder extends RequestIdAwareLogging { given nameDecoder: Decoder[LdapService.Name] = DecoderHelpers.decodeNonEmptyStringField.map(LdapService.Name.apply) @@ -267,7 +267,7 @@ object LdapServicesDecoder extends Logging { case BindingTestError(ldap) => connectionErrorFrom(s"There was a problem with test binding in case of '${ldap.show}' LDAP connector}") case UnexpectedConnectionError(ldap, cause) => - logger.error(s"Unexpected '${ldap.show}' LDAP connection error", cause) + noRequestIdLogger.error(s"Unexpected '${ldap.show}' LDAP connection error", cause) connectionErrorFrom(s"Unexpected '${ldap.show}' LDAP connection error: '${cause.getMessage.show}'}") } diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/factory/decoders/rules/auth/RorKbnRulesDecoders.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/factory/decoders/rules/auth/RorKbnRulesDecoders.scala index c79c91a551..313d66417b 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/factory/decoders/rules/auth/RorKbnRulesDecoders.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/factory/decoders/rules/auth/RorKbnRulesDecoders.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.accesscontrol.factory.decoders.rules.auth import io.circe.Decoder -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.Block.RuleDefinition import tech.beshu.ror.accesscontrol.blocks.definitions.RorKbnDef import tech.beshu.ror.accesscontrol.blocks.rules.Rule @@ -28,6 +28,7 @@ import tech.beshu.ror.accesscontrol.domain.{GroupIds, GroupsLogic} import tech.beshu.ror.accesscontrol.factory.GlobalSettings import tech.beshu.ror.accesscontrol.factory.RawRorConfigBasedCoreFactory.CoreCreationError.Reason.Message import tech.beshu.ror.accesscontrol.factory.RawRorConfigBasedCoreFactory.CoreCreationError.RulesLevelCreationError +import tech.beshu.ror.accesscontrol.factory.decoders.AuditingSettingsDecoder.noRequestIdLogger import tech.beshu.ror.accesscontrol.factory.decoders.definitions.Definitions import tech.beshu.ror.accesscontrol.factory.decoders.definitions.RorKbnDefinitionsDecoder.* import tech.beshu.ror.accesscontrol.factory.decoders.rules.RuleBaseDecoder.RuleBaseDecoderWithoutAssociatedFields @@ -41,7 +42,7 @@ import tech.beshu.ror.utils.uniquelist.UniqueNonEmptyList class RorKbnAuthenticationRuleDecoder(rorKbnDefinitions: Definitions[RorKbnDef], globalSettings: GlobalSettings) - extends RuleBaseDecoderWithoutAssociatedFields[RorKbnAuthenticationRule] with Logging { + extends RuleBaseDecoderWithoutAssociatedFields[RorKbnAuthenticationRule] with RequestIdAwareLogging { override protected def decoder: Decoder[RuleDefinition[RorKbnAuthenticationRule]] = { nameAndGroupsSimpleDecoder @@ -65,7 +66,7 @@ class RorKbnAuthenticationRuleDecoder(rorKbnDefinitions: Definitions[RorKbnDef], } class RorKbnAuthorizationRuleDecoder(rorKbnDefinitions: Definitions[RorKbnDef]) - extends RuleBaseDecoderWithoutAssociatedFields[RorKbnAuthorizationRule] with Logging { + extends RuleBaseDecoderWithoutAssociatedFields[RorKbnAuthorizationRule] with RequestIdAwareLogging { override protected def decoder: Decoder[RuleDefinition[RorKbnAuthorizationRule]] = { nameAndGroupsSimpleDecoder @@ -90,7 +91,7 @@ class RorKbnAuthorizationRuleDecoder(rorKbnDefinitions: Definitions[RorKbnDef]) class RorKbnAuthRuleDecoder(rorKbnDefinitions: Definitions[RorKbnDef], globalSettings: GlobalSettings) - extends RuleBaseDecoderWithoutAssociatedFields[RorKbnAuthRule] with Logging { + extends RuleBaseDecoderWithoutAssociatedFields[RorKbnAuthRule] with RequestIdAwareLogging { override protected def decoder: Decoder[RuleDefinition[RorKbnAuthRule]] = { nameAndGroupsSimpleDecoder @@ -104,7 +105,7 @@ class RorKbnAuthRuleDecoder(rorKbnDefinitions: Definitions[RorKbnDef], case Some(groupsLogic) => groupsLogic case None => - logger.warn( + noRequestIdLogger.warn( s"""Missing groups logic settings in ${RorKbnAuthRule.Name.name.show} rule. |For old configs, ROR treats this as `groups_any_of: ["*"]`. |This syntax is deprecated. Add groups logic (https://github.com/beshu-tech/readonlyrest-docs/blob/master/details/authorization-rules-details.md#checking-groups-logic), diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/factory/decoders/rules/kibana/KibanaUserDataRuleDecoder.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/factory/decoders/rules/kibana/KibanaUserDataRuleDecoder.scala index d1970219b2..ae3bd1ebfc 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/factory/decoders/rules/kibana/KibanaUserDataRuleDecoder.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/factory/decoders/rules/kibana/KibanaUserDataRuleDecoder.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.accesscontrol.factory.decoders.rules.kibana import eu.timepit.refined.types.string.NonEmptyString import io.circe.Decoder -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.Block import tech.beshu.ror.accesscontrol.blocks.Block.RuleDefinition import tech.beshu.ror.accesscontrol.blocks.rules.kibana.KibanaUserDataRule @@ -43,7 +43,7 @@ class KibanaUserDataRuleDecoder(configurationIndex: RorConfigurationIndex, variableCreator: RuntimeResolvableVariableCreator) (implicit jsCompiler: JsCompiler) extends RuleBaseDecoderWithoutAssociatedFields[KibanaUserDataRule] - with Logging { + with RequestIdAwareLogging { private implicit val variableCreatorImplicit: RuntimeResolvableVariableCreator = variableCreator private implicit val uniqueNonEmptyListOfKibanaAppsDecoder: Decoder[Set[KibanaApp]] = @@ -128,7 +128,7 @@ class KibanaUserDataRuleDecoder(configurationIndex: RorConfigurationIndex, case Success(regex) => Right(regex) case Failure(exception) => - logger.error(s"Cannot compile regex from string: [${str.show}]", exception) + noRequestIdLogger.error(s"Cannot compile regex from string: [${str.show}]", exception) Left(ValueLevelCreationError(Message(s"Cannot create Kibana allowed API path regex from [${str.show}]"))) } } else { diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/logging/AccessControlListLoggingDecorator.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/logging/AccessControlListLoggingDecorator.scala index 05a95a488e..165cdfdd98 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/logging/AccessControlListLoggingDecorator.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/logging/AccessControlListLoggingDecorator.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.accesscontrol.logging import cats.Show import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.AccessControlList import tech.beshu.ror.accesscontrol.AccessControlList.{RegularRequestResult, UserMetadataRequestResult, WithHistory} import tech.beshu.ror.accesscontrol.audit.{AuditingTool, LoggingContext} @@ -42,12 +42,12 @@ class AccessControlListLoggingDecorator(val underlying: AccessControlList, (implicit loggingContext: LoggingContext, auditEnvironmentContext: AuditEnvironmentContext, scheduler: Scheduler) - extends AccessControlList with Logging { + extends AccessControlList with RequestIdAwareLogging { override def description: String = underlying.description override def handleRegularRequest[B <: BlockContext : BlockContextUpdater](requestContext: RequestContext.Aux[B]): Task[WithHistory[RegularRequestResult[B], B]] = { - logger.debug(s"[${requestContext.id.show}] checking request ${requestContext.restRequest.method.show} ${requestContext.restRequest.path.show} ...") + logger.debug(s"checking request ${requestContext.restRequest.method.show} ${requestContext.restRequest.path.show} ...")(requestContext) underlying .handleRegularRequest(requestContext) .andThen { @@ -71,13 +71,13 @@ class AccessControlListLoggingDecorator(val underlying: AccessControlList, // ignore } case Failure(ex) => - logger.error(s"[${requestContext.id.show}] Request handling unexpected failure", ex) + logger.error(s"Request handling unexpected failure", ex)(requestContext) } } // todo: logging metadata should be a little bit different override def handleMetadataRequest(requestContext: RequestContext.Aux[CurrentUserMetadataRequestBlockContext]): Task[WithHistory[UserMetadataRequestResult, CurrentUserMetadataRequestBlockContext]] = { - logger.debug(s"[${requestContext.id.show}] checking user metadata request ...") + logger.debug(s"checking user metadata request ...")(requestContext) underlying .handleMetadataRequest(requestContext) .andThen { @@ -93,7 +93,7 @@ class AccessControlListLoggingDecorator(val underlying: AccessControlList, // ignore } case Failure(ex) => - logger.error(s"[${requestContext.id.show}] Request handling unexpected failure", ex) + logger.error(s"Request handling unexpected failure", ex)(requestContext) } } @@ -103,7 +103,7 @@ class AccessControlListLoggingDecorator(val underlying: AccessControlList, if (logger.delegate.isDebugEnabled()) headerShow else obfuscatedHeaderShow(loggingContext.obfuscatedHeaders) import tech.beshu.ror.accesscontrol.logging.AccessControlListLoggingDecorator.responseContextShow - logger.info(responseContextShow[B].show(responseContext)) + logger.info(responseContextShow[B].show(responseContext))(responseContext) } blockAuditSettings(responseContext) match { case Some(Block.Audit.Disabled) => @@ -115,7 +115,7 @@ class AccessControlListLoggingDecorator(val underlying: AccessControlList, .runAsync { case Right(_) => case Left(ex) => - logger.warn(s"[${responseContext.requestContext.id.show}] Auditing issue", ex) + logger.warn(s"Auditing issue", ex)(responseContext) } } } diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/logging/DeprecatedAuditLoggingDecorator.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/logging/DeprecatedAuditLoggingDecorator.scala index 18f8484b75..e7f066d88e 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/logging/DeprecatedAuditLoggingDecorator.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/logging/DeprecatedAuditLoggingDecorator.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.accesscontrol.logging -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.audit.instances.{DefaultAuditLogSerializer, QueryAuditLogSerializer} import tech.beshu.ror.commons import tech.beshu.ror.implicits.* @@ -27,14 +27,14 @@ import scala.annotation.nowarn @nowarn("cat=deprecation") final class DeprecatedAuditLoggingDecorator[T](underlying: AuditLogSerializer[T]) extends AuditLogSerializer[T] - with Logging { + with RequestIdAwareLogging { private val deprecatedSerializerCanonicalName = underlying.getClass.getCanonicalName private val defaultSerializerCanonicalName = classOf[DefaultAuditLogSerializer].getCanonicalName private val querySerializerCanonicalName = classOf[QueryAuditLogSerializer].getCanonicalName override def createLoggableEntry(context: commons.ResponseContext): T = { - logger.warn(s"you're using deprecated serializer ${deprecatedSerializerCanonicalName.show}, please use ${defaultSerializerCanonicalName.show}, or ${querySerializerCanonicalName.show} instead") + noRequestIdLogger.warn(s"you're using deprecated serializer ${deprecatedSerializerCanonicalName.show}, please use ${defaultSerializerCanonicalName.show}, or ${querySerializerCanonicalName.show} instead") underlying.createLoggableEntry(context) } } \ No newline at end of file diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/logging/ResponseContext.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/logging/ResponseContext.scala index c5e76f22c6..7b9c39eba3 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/logging/ResponseContext.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/logging/ResponseContext.scala @@ -18,9 +18,14 @@ package tech.beshu.ror.accesscontrol.logging import tech.beshu.ror.accesscontrol.blocks.metadata.UserMetadata import tech.beshu.ror.accesscontrol.blocks.{Block, BlockContext} +import tech.beshu.ror.accesscontrol.domain.{HasRequestId, RequestId} import tech.beshu.ror.accesscontrol.request.RequestContext -sealed trait ResponseContext[B <: BlockContext] +sealed trait ResponseContext[B <: BlockContext] extends HasRequestId { + def requestContext: RequestContext.Aux[B] + override def requestId: RequestId = requestContext.requestId +} + object ResponseContext { final case class AllowedBy[B <: BlockContext](requestContext: RequestContext.Aux[B], diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/request/RequestContext.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/request/RequestContext.scala index 65a9faaff6..5a301811cc 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/request/RequestContext.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/request/RequestContext.scala @@ -20,7 +20,7 @@ import cats.Show import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task import org.apache.logging.log4j.Level -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.json.JSONObject import squants.information.Bytes import tech.beshu.ror.accesscontrol.blocks.metadata.UserMetadata @@ -39,7 +39,7 @@ import tech.beshu.ror.utils.ScalaOps.* import java.time.Instant import scala.language.implicitConversions -trait RequestContext extends Logging { +trait RequestContext extends RequestIdAwareLogging with HasRequestId { type BLOCK_CONTEXT <: BlockContext @@ -89,14 +89,16 @@ trait RequestContext extends Logging { def generalAuditEvents: JSONObject = new JSONObject() + override def requestId: RequestId = id.toRequestId } -object RequestContext extends Logging { +object RequestContext extends RequestIdAwareLogging { type Aux[B <: BlockContext] = RequestContext { type BLOCK_CONTEXT = B } - final case class Id private(value: String) { + final case class Id private(value: String) extends HasRequestId { def toRequestId: RequestId = RequestId(value) + override def requestId: RequestId = toRequestId } object Id { def fromString(value: String): Id = Id(value) diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/request/RorSessionCookie.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/request/RorSessionCookie.scala index aa29f383d7..8dbbe3d2eb 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/request/RorSessionCookie.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/request/RorSessionCookie.scala @@ -21,7 +21,7 @@ import com.google.common.hash.Hashing import eu.timepit.refined.types.string.NonEmptyString import io.circe.parser.* import io.circe.{Decoder, Encoder} -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.domain.Header.Name.setCookie import tech.beshu.ror.accesscontrol.domain.{Header, LoggedUser, User} import tech.beshu.ror.accesscontrol.request.RorSessionCookie.ExtractingError.{Absent, Expired, Invalid} @@ -37,7 +37,7 @@ import scala.util.Try final case class RorSessionCookie(userId: User.Id, expiryDate: Instant) -object RorSessionCookie extends Logging { +object RorSessionCookie extends RequestIdAwareLogging { private val rorCookieName = "ReadonlyREST_Session" sealed trait ExtractingError @@ -56,7 +56,7 @@ object RorSessionCookie extends Logging { httpCookie <- extractRorHttpCookie(context).toRight(Absent) cookieAndSignature <- parseRorSessionCookieAndSignature(httpCookie).left.map(_ => Invalid: ExtractingError) (cookie, signature) = cookieAndSignature - _ <- checkCookie(cookie, signature, user) + _ <- checkCookie(context, cookie, signature, user) } yield cookie } @@ -83,7 +83,8 @@ object RorSessionCookie extends Logging { } yield decoded } - private def checkCookie(cookie: RorSessionCookie, + private def checkCookie(requestContext: RequestContext, + cookie: RorSessionCookie, signature: Signature, loggedUser: LoggedUser) (implicit clock: Clock, @@ -91,13 +92,13 @@ object RorSessionCookie extends Logging { userIdEq: Eq[User.Id]): Either[ExtractingError, Unit] = { val now = Instant.now(clock) if (cookie.userId =!= loggedUser.id) { - logger.warn(s"this cookie does not belong to the user logged in as. Found in Cookie: ${cookie.userId.show} whilst in Authentication: ${loggedUser.id.show}") + logger.warn(s"this cookie does not belong to the user logged in as. Found in Cookie: ${cookie.userId.show} whilst in Authentication: ${loggedUser.id.show}")(requestContext) Left(Invalid) } else if (!signature.check(cookie)) { - logger.warn(s"'${signature.value}' is not valid signature for ${cookie.show}") + logger.warn(s"'${signature.value}' is not valid signature for ${cookie.show}")(requestContext) Left(Invalid) } else if (now.isAfter(cookie.expiryDate)) { - logger.info(s"cookie was present but expired. Found: ${cookie.expiryDate.show}, now it's ${now.show}") + logger.info(s"cookie was present but expired. Found: ${cookie.expiryDate.show}, now it's ${now.show}")(requestContext) Left(Expired) } else { Right({}) diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/utils/Cachable.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/utils/Cachable.scala index 848ad6a911..8378b3ec19 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/utils/Cachable.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/utils/Cachable.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.accesscontrol.utils import com.github.benmanes.caffeine.cache.{Cache, Caffeine, RemovalCause} import monix.catnap.Semaphore import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.utils.DurationOps.PositiveFiniteDuration @@ -33,7 +33,7 @@ class CacheableAction[K, V](ttl: PositiveFiniteDuration, class CacheableActionWithKeyMapping[K, K1, V](ttl: PositiveFiniteDuration, action: (K, RequestId) => Task[V], - keyMap: K => K1) extends Logging { + keyMap: K => K1) extends RequestIdAwareLogging { private val keySemaphoresMap = new ConcurrentHashMap[K1, Semaphore[Task]]() diff --git a/core/src/main/scala/tech/beshu/ror/accesscontrol/utils/ClaimsOps.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/utils/ClaimsOps.scala index cebde06b1c..7d00c11396 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/utils/ClaimsOps.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/utils/ClaimsOps.scala @@ -20,7 +20,7 @@ import cats.Show import cats.data.NonEmptyList import eu.timepit.refined.types.string.NonEmptyString import io.jsonwebtoken.Claims -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.domain.* import tech.beshu.ror.accesscontrol.domain.GroupIdLike.GroupId import tech.beshu.ror.accesscontrol.utils.ClaimsOps.ClaimSearchResult.* @@ -32,7 +32,7 @@ import scala.jdk.CollectionConverters.* import scala.language.implicitConversions import scala.util.{Success, Try} -class ClaimsOps(val claims: Claims) extends Logging { +class ClaimsOps(val claims: Claims) extends RequestIdAwareLogging { def headerNameClaim(name: Header.Name): ClaimSearchResult[Header] = { Option(claims.get(name.value.value, classOf[String])) @@ -78,7 +78,8 @@ class ClaimsOps(val claims: Claims) extends Logging { } def groupsClaim(groupIdsClaimName: Jwt.ClaimName, - groupNamesClaimName: Option[Jwt.ClaimName]): ClaimSearchResult[UniqueList[Group]] = { + groupNamesClaimName: Option[Jwt.ClaimName]) + (implicit requestId: RequestId): ClaimSearchResult[UniqueList[Group]] = { (for { groupIds <- readGroupIds(groupIdsClaimName) @@ -142,7 +143,8 @@ class ClaimsOps(val claims: Claims) extends Logging { .map(Group.from) } - private def createGroupsFrom(idsWithNames: Iterable[(Any, Any)]): UniqueList[Group] = UniqueList.from { + private def createGroupsFrom(idsWithNames: Iterable[(Any, Any)]) + (implicit requestId: RequestId): UniqueList[Group] = UniqueList.from { idsWithNames .flatMap { case (id, name) => nonEmptyStringFrom(id) @@ -154,7 +156,8 @@ class ClaimsOps(val claims: Claims) extends Logging { } } - private def groupNameFrom(name: Any, groupId: GroupId) = { + private def groupNameFrom(name: Any, groupId: GroupId) + (implicit requestId: RequestId) = { nonEmptyStringFrom(name) .map(GroupName.apply) .getOrElse { diff --git a/core/src/main/scala/tech/beshu/ror/api/AuthMockApi.scala b/core/src/main/scala/tech/beshu/ror/api/AuthMockApi.scala index fd8aed1fa2..abb64da811 100644 --- a/core/src/main/scala/tech/beshu/ror/api/AuthMockApi.scala +++ b/core/src/main/scala/tech/beshu/ror/api/AuthMockApi.scala @@ -23,7 +23,7 @@ import eu.timepit.refined.types.string.NonEmptyString import io.circe.* import io.circe.syntax.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.definitions.ldap.LdapService import tech.beshu.ror.accesscontrol.blocks.definitions.{ExternalAuthenticationService as AuthenticationService, ExternalAuthorizationService as AuthorizationService} import tech.beshu.ror.accesscontrol.blocks.mocks.MocksProvider.{ExternalAuthenticationServiceMock, ExternalAuthorizationServiceMock, LdapServiceMock} @@ -37,7 +37,7 @@ import tech.beshu.ror.syntax.* import tech.beshu.ror.utils.CirceOps.CirceErrorOps class AuthMockApi(rorInstance: RorInstance) - extends Logging { + extends RequestIdAwareLogging { import AuthMockApi.* import AuthMockApi.AuthMockResponse.* diff --git a/core/src/main/scala/tech/beshu/ror/api/ConfigApi.scala b/core/src/main/scala/tech/beshu/ror/api/ConfigApi.scala index 22b9f2c9dc..049f396c32 100644 --- a/core/src/main/scala/tech/beshu/ror/api/ConfigApi.scala +++ b/core/src/main/scala/tech/beshu/ror/api/ConfigApi.scala @@ -21,7 +21,7 @@ import cats.data.EitherT import cats.implicits.* import io.circe.Decoder import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.domain.{RequestId, RorConfigurationIndex} import tech.beshu.ror.api.ConfigApi.* import tech.beshu.ror.api.ConfigApi.ConfigRequest.Type @@ -41,7 +41,7 @@ class ConfigApi(rorInstance: RorInstance, fileConfigLoader: FileConfigLoader, rorConfigurationIndex: RorConfigurationIndex) (implicit val EnvironmentConfig: EnvironmentConfig) - extends Logging { + extends RequestIdAwareLogging { import ConfigApi.Utils.* import ConfigApi.Utils.decoders.* diff --git a/core/src/main/scala/tech/beshu/ror/boot/EsInitListener.scala b/core/src/main/scala/tech/beshu/ror/boot/EsInitListener.scala index a693513262..fe75204dd7 100644 --- a/core/src/main/scala/tech/beshu/ror/boot/EsInitListener.scala +++ b/core/src/main/scala/tech/beshu/ror/boot/EsInitListener.scala @@ -17,20 +17,20 @@ package tech.beshu.ror.boot import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import scala.concurrent.Promise -class EsInitListener extends Logging { +class EsInitListener extends RequestIdAwareLogging { private val readyPromise = Promise[Unit]() - logger.info("ReadonlyREST is waiting for full Elasticsearch init") + noRequestIdLogger.info("ReadonlyREST is waiting for full Elasticsearch init") def waitUntilReady: Task[Unit] = Task.fromFuture(readyPromise.future) def onEsReady(): Unit = { - logger.info("Elasticsearch fully initiated. ReadonlyREST can continue ...") + noRequestIdLogger.info("Elasticsearch fully initiated. ReadonlyREST can continue ...") readyPromise.trySuccess(()) } } diff --git a/core/src/main/scala/tech/beshu/ror/boot/ReadonlyRest.scala b/core/src/main/scala/tech/beshu/ror/boot/ReadonlyRest.scala index 4032538787..7052634a4e 100644 --- a/core/src/main/scala/tech/beshu/ror/boot/ReadonlyRest.scala +++ b/core/src/main/scala/tech/beshu/ror/boot/ReadonlyRest.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.boot import cats.data.{EitherT, NonEmptyList} import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.audit.sink.AuditSinkServiceCreator import tech.beshu.ror.accesscontrol.audit.{AuditEnvironmentContextBasedOnEsNodeSettings, AuditingTool, LoggingContext} import tech.beshu.ror.accesscontrol.blocks.definitions.ldap.implementations.UnboundidLdapConnectionPoolProvider @@ -51,7 +51,7 @@ class ReadonlyRest(coreFactory: CoreFactory, val authServicesMocksProvider: MutableMocksProviderWithCachePerRequest, val esEnv: EsEnv) (implicit environmentConfig: EnvironmentConfig, - scheduler: Scheduler) extends Logging { + scheduler: Scheduler) extends RequestIdAwareLogging { def start(): Task[Either[StartingFailure, RorInstance]] = { (for { @@ -134,13 +134,13 @@ class ReadonlyRest(coreFactory: CoreFactory, EitherT(action.foldMap(compiler)) .leftMap { case LoadedTestRorConfig.IndexParsingError(message) => - logger.error(s"Loading ReadonlyREST test settings from index failed: ${message.show}. No test settings will be loaded.") + noRequestIdLogger.error(s"Loading ReadonlyREST test settings from index failed: ${message.show}. No test settings will be loaded.") LoadedTestRorConfig.FallbackConfig(notSetTestRorConfig) case LoadedTestRorConfig.IndexUnknownStructure => - logger.error("Loading ReadonlyREST test settings from index failed: index content malformed. No test settings will be loaded.") + noRequestIdLogger.error("Loading ReadonlyREST test settings from index failed: index content malformed. No test settings will be loaded.") LoadedTestRorConfig.FallbackConfig(notSetTestRorConfig) case LoadedTestRorConfig.IndexNotExist => - logger.info("Loading ReadonlyREST test settings from index failed: cannot find index. No test settings will be loaded.") + noRequestIdLogger.info("Loading ReadonlyREST test settings from index failed: cannot find index. No test settings will be loaded.") LoadedTestRorConfig.FallbackConfig(notSetTestRorConfig) } .merge @@ -179,7 +179,7 @@ class ReadonlyRest(coreFactory: CoreFactory, expiration = expirationConfig(testConfig.expiration) ) case Left(startingFailure) => - logger.error(s"Unable to start test engine. Cause: ${startingFailure.message.show}. Test settings engine will be marked as invalidated.") + noRequestIdLogger.error(s"Unable to start test engine. Cause: ${startingFailure.message.show}. Test settings engine will be marked as invalidated.") TestEngine.Invalidated(testConfig.rawConfig, expirationConfig(testConfig.expiration)) } } yield testEngine @@ -270,9 +270,9 @@ class ReadonlyRest(coreFactory: CoreFactory, private def inspectFlsEngine(engine: Engine): Unit = { engine.core.accessControl.staticContext.usedFlsEngineInFieldsRule.foreach { case FlsEngine.Lucene | FlsEngine.ESWithLucene => - logger.warn("Defined fls engine relies on lucene. To make it work well, all nodes should have ROR plugin installed.") + noRequestIdLogger.warn("Defined fls engine relies on lucene. To make it work well, all nodes should have ROR plugin installed.") case FlsEngine.ES => - logger.warn("Defined fls engine relies on ES only. This engine doesn't provide full FLS functionality hence some requests may be rejected.") + noRequestIdLogger.warn("Defined fls engine relies on ES only. This engine doesn't provide full FLS functionality hence some requests may be rejected.") } } diff --git a/core/src/main/scala/tech/beshu/ror/boot/RorInstance.scala b/core/src/main/scala/tech/beshu/ror/boot/RorInstance.scala index 8a0ac8e9ec..747acbb11e 100644 --- a/core/src/main/scala/tech/beshu/ror/boot/RorInstance.scala +++ b/core/src/main/scala/tech/beshu/ror/boot/RorInstance.scala @@ -23,7 +23,7 @@ import cats.syntax.either.* import monix.catnap.Semaphore import monix.eval.Task import monix.execution.{Cancelable, Scheduler} -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.mocks.{AuthServicesMocks, MocksProvider} import tech.beshu.ror.accesscontrol.domain.{RequestId, RorConfigurationIndex} import tech.beshu.ror.api.{AuthMockApi, ConfigApi, TestConfigApi} @@ -47,23 +47,23 @@ class RorInstance private(boot: ReadonlyRest, rorConfigurationIndex: RorConfigurationIndex) (implicit environmentConfig: EnvironmentConfig, scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { import RorInstance.* import RorInstance.ScheduledReloadError.{EngineReloadError, ReloadingInProgress} - logger.info("ReadonlyREST was loaded ...") + noRequestIdLogger.info("ReadonlyREST was loaded ...") private val configsReloadTask = mode match { case Mode.WithPeriodicIndexCheck => RorProperties.rorIndexSettingsReloadInterval(environmentConfig.propertiesProvider) match { case RefreshInterval.Disabled => - logger.info(s"[CLUSTERWIDE SETTINGS] Scheduling in-index settings check disabled") + noRequestIdLogger.info(s"[CLUSTERWIDE SETTINGS] Scheduling in-index settings check disabled") Cancelable.empty case RefreshInterval.Enabled(interval) => scheduleEnginesReload(interval) } case Mode.NoPeriodicIndexCheck => - logger.info(s"[CLUSTERWIDE SETTINGS] Scheduling in-index settings check disabled") + noRequestIdLogger.info(s"[CLUSTERWIDE SETTINGS] Scheduling in-index settings check disabled") Cancelable.empty } @@ -155,17 +155,17 @@ class RorInstance private(boot: ReadonlyRest, private def scheduleIndexConfigChecking(interval: PositiveFiniteDuration, reloadTask: RequestId => Task[Seq[(ConfigType, Either[ScheduledReloadError, Unit])]]): Cancelable = { - logger.debug(s"[CLUSTERWIDE SETTINGS] Scheduling next in-index settings check within ${interval.show}") + noRequestIdLogger.debug(s"[CLUSTERWIDE SETTINGS] Scheduling next in-index settings check within ${interval.show}") scheduler.scheduleOnce(interval.value) { implicit val requestId: RequestId = RequestId(environmentConfig.uuidProvider.random.toString) - logger.debug(s"[CLUSTERWIDE SETTINGS][${requestId.show}] Loading ReadonlyREST configs from index ...") + noRequestIdLogger.debug(s"[CLUSTERWIDE SETTINGS]Loading ReadonlyREST configs from index ...") reloadTask(requestId) .runAsync { case Right(reloadResults) => reloadResults.foreach(logConfigReloadResult) scheduleIndexConfigChecking(interval, reloadTask) case Left(ex) => - logger.error(s"[CLUSTERWIDE SETTINGS][${requestId.show}] Checking index config failed: error", ex) + logger.error(s"[CLUSTERWIDE SETTINGS]Checking index config failed: error", ex) scheduleIndexConfigChecking(interval, reloadTask) } } @@ -175,15 +175,15 @@ class RorInstance private(boot: ReadonlyRest, (implicit requestId: RequestId): Unit = configReloadResult match { case (_, Right(())) => case (name, Left(ReloadingInProgress)) => - logger.debug(s"[CLUSTERWIDE SETTINGS][${requestId.show}] Reloading of ${name.show} engine in progress ... skipping") + logger.debug(s"[CLUSTERWIDE SETTINGS]Reloading of ${name.show} engine in progress ... skipping") case (name, Left(EngineReloadError(IndexConfigReloadError.ReloadError(RawConfigReloadError.ConfigUpToDate(_))))) => - logger.debug(s"[CLUSTERWIDE SETTINGS][${requestId.show}] ${name.show} settings are up to date. Nothing to reload.") + logger.debug(s"[CLUSTERWIDE SETTINGS]${name.show} settings are up to date. Nothing to reload.") case (name, Left(EngineReloadError(IndexConfigReloadError.ReloadError(RawConfigReloadError.RorInstanceStopped)))) => - logger.debug(s"[CLUSTERWIDE SETTINGS][${requestId.show}] Stopping periodic ${name.show} settings check - application is being stopped") + logger.debug(s"[CLUSTERWIDE SETTINGS]Stopping periodic ${name.show} settings check - application is being stopped") case (name, Left(EngineReloadError(IndexConfigReloadError.ReloadError(RawConfigReloadError.ReloadingFailed(startingFailure))))) => - logger.debug(s"[CLUSTERWIDE SETTINGS][${requestId.show}] ReadonlyREST ${name.show} engine starting failed: ${startingFailure.message.show}") + logger.debug(s"[CLUSTERWIDE SETTINGS]ReadonlyREST ${name.show} engine starting failed: ${startingFailure.message.show}") case (name, Left(EngineReloadError(IndexConfigReloadError.LoadingConfigError(error)))) => - logger.debug(s"[CLUSTERWIDE SETTINGS][${requestId.show}] Loading ${name.show} config from index failed: ${error.show}") + logger.debug(s"[CLUSTERWIDE SETTINGS]Loading ${name.show} config from index failed: ${error.show}") } private def tryMainEngineReload(requestId: RequestId): Task[Either[ScheduledReloadError, Unit]] = { diff --git a/core/src/main/scala/tech/beshu/ror/boot/engines/BaseReloadableEngine.scala b/core/src/main/scala/tech/beshu/ror/boot/engines/BaseReloadableEngine.scala index ed8bb28961..4b12f17123 100644 --- a/core/src/main/scala/tech/beshu/ror/boot/engines/BaseReloadableEngine.scala +++ b/core/src/main/scala/tech/beshu/ror/boot/engines/BaseReloadableEngine.scala @@ -22,7 +22,7 @@ import monix.catnap.Semaphore import monix.eval.Task import monix.execution.atomic.{Atomic, AtomicAny} import monix.execution.{Cancelable, Scheduler} -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.domain.{RequestId, RorConfigurationIndex} import tech.beshu.ror.boot.ReadonlyRest import tech.beshu.ror.boot.ReadonlyRest.Engine @@ -45,14 +45,14 @@ private[engines] abstract class BaseReloadableEngine(val name: String, rorConfigurationIndex: RorConfigurationIndex) (implicit environmentConfig: EnvironmentConfig, scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { import BaseReloadableEngine.EngineUpdateType private val currentEngine: Atomic[EngineState] = AtomicAny[EngineState]( initialEngine match { case InitialEngine.Configured(engine, config, expirationConfig) => - logger.info(s"ROR ${name.show} engine (id=${config.hashString().show}) was initiated (${engine.core.accessControl.description.show}).") + noRequestIdLogger.info(s"ROR ${name.show} engine (id=${config.hashString().show}) was initiated (${engine.core.accessControl.description.show}).") stateFromInitial(EngineWithConfig(engine, config, expirationConfig))(RequestId(environmentConfig.uuidProvider.random.toString)) case InitialEngine.NotConfigured => EngineState.NotStartedYet(recentConfig = None, recentExpirationConfig = None) @@ -76,7 +76,7 @@ private[engines] abstract class BaseReloadableEngine(val name: String, state match { case EngineState.NotStartedYet(_, _) => case working@EngineState.Working(engineWithConfig, _) => - logger.info(s"[${requestId.show}] ROR ${name.show} engine (id=${engineWithConfig.config.hashString().show}) will be stopped ...") + logger.info(s"ROR ${name.show} engine (id=${engineWithConfig.config.hashString().show}) will be stopped ...") stopNow(working) case EngineState.Stopped => } @@ -97,7 +97,7 @@ private[engines] abstract class BaseReloadableEngine(val name: String, EngineState.NotStartedYet(recentConfig = None, recentExpirationConfig = None) } case oldWorkingEngine@EngineState.Working(engineWithConfig, _) => - logger.info(s"[${requestId.show}] ROR ${name.show} engine (id=${engineWithConfig.config.hashString().show}) will be invalidated ...") + logger.info(s"ROR ${name.show} engine (id=${engineWithConfig.config.hashString().show}) will be invalidated ...") stopEarly(oldWorkingEngine) if (keepPreviousConfiguration) { EngineState.NotStartedYet( @@ -153,7 +153,7 @@ private[engines] abstract class BaseReloadableEngine(val name: String, case _: EngineState.NotStartedYet => NotStartedYet(recentConfig = Some(newConfig), recentExpirationConfig = Some(newExpirationConfig)) case working: EngineState.Working => - logger.info(s"[${requestId.show}] ROR ${name.show} engine (id=${working.engineWithConfig.config.hashString().show}) will be invalidated ...") + logger.info(s"ROR ${name.show} engine (id=${working.engineWithConfig.config.hashString().show}) will be invalidated ...") stopEarly(working) NotStartedYet(recentConfig = Some(newConfig), recentExpirationConfig = Some(newExpirationConfig)) case EngineState.Stopped => @@ -283,14 +283,14 @@ private[engines] abstract class BaseReloadableEngine(val name: String, Task.delay { val oldEngineState = currentEngine.getAndTransform { case _: EngineState.NotStartedYet => - logger.info(s"[${requestId.show}] ROR ${name.show} engine (id=${newEngineWithConfig.config.hashString().show}) is going to be used ...") + logger.info(s"ROR ${name.show} engine (id=${newEngineWithConfig.config.hashString().show}) is going to be used ...") workingStateFrom(newEngineWithConfig) case oldWorkingEngine@EngineState.Working(_, _) => - logger.info(s"[${requestId.show}] ROR ${name.show} engine (id=${oldWorkingEngine.engineWithConfig.config.hashString().show}) will be replaced with engine (id=${newEngineWithConfig.config.hashString().show}) ...") + logger.info(s"ROR ${name.show} engine (id=${oldWorkingEngine.engineWithConfig.config.hashString().show}) will be replaced with engine (id=${newEngineWithConfig.config.hashString().show}) ...") stopEarly(oldWorkingEngine) workingStateFrom(newEngineWithConfig) case EngineState.Stopped => - logger.warn(s"[${requestId.show}] ROR ${name.show} engine (id=${newEngineWithConfig.config.hashString().show}) cannot be used because the ROR is already stopped!") + logger.warn(s"ROR ${name.show} engine (id=${newEngineWithConfig.config.hashString().show}) cannot be used because the ROR is already stopped!") newEngineWithConfig.engine.shutdown() EngineState.Stopped } @@ -316,7 +316,7 @@ private[engines] abstract class BaseReloadableEngine(val name: String, private def stopEngine(engineWithConfig: EngineWithConfig) (implicit requestId: RequestId): Unit = { - logger.info(s"[${requestId.show}] ROR ${name.show} engine (id=${engineWithConfig.config.hashString().show}) is being stopped after TTL were reached ...") + logger.info(s"ROR ${name.show} engine (id=${engineWithConfig.config.hashString().show}) is being stopped after TTL were reached ...") stop(engineWithConfig) currentEngine.transform { case EngineState.NotStartedYet(_, _) => @@ -368,7 +368,7 @@ private[engines] abstract class BaseReloadableEngine(val name: String, case EngineState.NotStartedYet(recentConfig, recentExpirationConfig) => EngineState.NotStartedYet(recentConfig, recentExpirationConfig) case EngineState.Working(engineWithConfig, scheduledShutdownJob) => - logger.info(s"[${requestId.show}] ROR ${name.show} engine (id=${engineWithConfig.config.hashString().show}) is being updated with new TTL ...") + logger.info(s"ROR ${name.show} engine (id=${engineWithConfig.config.hashString().show}) is being updated with new TTL ...") scheduledShutdownJob.foreach(_.cancel()) val engineWithNewExpirationConfig = engineWithConfig.copy(expirationConfig = Some(engineExpirationConfig(configExpiration))) workingStateFrom(engineWithNewExpirationConfig) @@ -391,14 +391,14 @@ private[engines] abstract class BaseReloadableEngine(val name: String, (implicit requestId: RequestId): Unit = { engineState.scheduledShutdownJob.foreach(_.cancel()) scheduler.scheduleOnce(delayOfOldEngineShutdown) { - logger.info(s"[${requestId.show}] ROR ${name.show} engine (id=${engineState.engineWithConfig.config.hashString().show}) is being stopped early ...") + logger.info(s"ROR ${name.show} engine (id=${engineState.engineWithConfig.config.hashString().show}) is being stopped early ...") stop(engineState.engineWithConfig) } } private def stopNow(engineState: EngineState.Working) (implicit requestId: RequestId): Unit = { - logger.info(s"[${requestId.show}] ROR ${name.show} engine (id=${engineState.engineWithConfig.config.hashString().show}) is being stopped now ...") + logger.info(s"ROR ${name.show} engine (id=${engineState.engineWithConfig.config.hashString().show}) is being stopped now ...") engineState.scheduledShutdownJob.foreach(_.cancel()) stop(engineState.engineWithConfig) } @@ -406,7 +406,7 @@ private[engines] abstract class BaseReloadableEngine(val name: String, private def stop(engineWithConfig: EngineWithConfig) (implicit requestId: RequestId): Unit = { engineWithConfig.engine.shutdown() - logger.info(s"[${requestId.show}] ROR ${name.show} engine (id=${engineWithConfig.config.hashString().show}) stopped!") + logger.info(s"ROR ${name.show} engine (id=${engineWithConfig.config.hashString().show}) stopped!") } private def isStillValid(validTo: Instant) = { diff --git a/core/src/main/scala/tech/beshu/ror/boot/engines/MainConfigBasedReloadableEngine.scala b/core/src/main/scala/tech/beshu/ror/boot/engines/MainConfigBasedReloadableEngine.scala index b4cdc9d2b9..e52fc69e2d 100644 --- a/core/src/main/scala/tech/beshu/ror/boot/engines/MainConfigBasedReloadableEngine.scala +++ b/core/src/main/scala/tech/beshu/ror/boot/engines/MainConfigBasedReloadableEngine.scala @@ -52,7 +52,7 @@ private[boot] class MainConfigBasedReloadableEngine(boot: ReadonlyRest, def forceReloadAndSave(config: RawRorConfig) (implicit requestId: RequestId): Task[Either[IndexConfigReloadWithUpdateError, Unit]] = { for { - _ <- Task.delay(logger.info(s"[${requestId.show}] Reloading of provided settings was forced (new engine id=${config.hashString()}) ...")) + _ <- Task.delay(logger.info(s"Reloading of provided settings was forced (new engine id=${config.hashString()}) ...")) reloadResult <- reloadInProgress.withPermit { value { for { @@ -63,18 +63,18 @@ private[boot] class MainConfigBasedReloadableEngine(boot: ReadonlyRest, } _ <- Task.delay(reloadResult match { case Right(_) => - logger.info(s"[${requestId.show}] ROR ${name.show} engine (id=${config.hashString().show}) settings reloaded!") + logger.info(s"ROR ${name.show} engine (id=${config.hashString().show}) settings reloaded!") case Left(ReloadError(ConfigUpToDate(oldConfig))) => - logger.info(s"[${requestId.show}] ROR ${name.show} engine (id=${oldConfig.hashString().show}) already loaded!") + logger.info(s"ROR ${name.show} engine (id=${oldConfig.hashString().show}) already loaded!") case Left(ReloadError(ReloadingFailed(StartingFailure(message, Some(ex))))) => - logger.error(s"[${requestId.show}] [${config.hashString()}] Cannot reload ROR settings - failure: ${message.show}", ex) + logger.error(s"[${config.hashString()}] Cannot reload ROR settings - failure: ${message.show}", ex) case Left(ReloadError(ReloadingFailed(StartingFailure(message, None)))) => - logger.error(s"[${requestId.show}] Cannot reload ROR settings - failure: ${message.show}") + logger.error(s"Cannot reload ROR settings - failure: ${message.show}") case Left(ReloadError(RorInstanceStopped)) => - logger.warn(s"[${requestId.show}] ROR is being stopped! Loading main settings skipped!") + logger.warn(s"ROR is being stopped! Loading main settings skipped!") case Left(IndexConfigSavingError(CannotSaveConfig)) => // todo: invalidate created core? - logger.warn(s"[${requestId.show}] ROR is being stopped! Loading main settings skipped!") + logger.warn(s"ROR is being stopped! Loading main settings skipped!") }) } yield reloadResult } @@ -82,21 +82,21 @@ private[boot] class MainConfigBasedReloadableEngine(boot: ReadonlyRest, def forceReloadFromIndex() (implicit requestId: RequestId): Task[Either[IndexConfigReloadError, Unit]] = { for { - _ <- Task.delay(logger.info(s"[${requestId.show}] Reloading of in-index settings was forced ...")) + _ <- Task.delay(logger.info(s"Reloading of in-index settings was forced ...")) reloadResult <- reloadEngineUsingIndexConfig() _ <- Task.delay(reloadResult match { case Right(config) => - logger.info(s"[${requestId.show}] ROR ${name.show} engine (id=${config.hashString().show}) settings reloaded!") + logger.info(s"ROR ${name.show} engine (id=${config.hashString().show}) settings reloaded!") case Left(IndexConfigReloadError.ReloadError(ConfigUpToDate(config))) => - logger.info(s"[${requestId.show}] ROR ${name.show} engine (id=${config.hashString().show}) already loaded!") + logger.info(s"ROR ${name.show} engine (id=${config.hashString().show}) already loaded!") case Left(IndexConfigReloadError.ReloadError(ReloadingFailed(StartingFailure(message, Some(ex))))) => - logger.error(s"[${requestId.show}] Cannot reload ROR settings - failure: ${message.show}", ex) + logger.error(s"Cannot reload ROR settings - failure: ${message.show}", ex) case Left(IndexConfigReloadError.ReloadError(ReloadingFailed(StartingFailure(message, None)))) => - logger.error(s"[${requestId.show}] Cannot reload ROR settings - failure: ${message.show}") + logger.error(s"Cannot reload ROR settings - failure: ${message.show}") case Left(IndexConfigReloadError.ReloadError(RorInstanceStopped)) => - logger.warn(s"[${requestId.show}] ROR is being stopped! Loading main settings skipped!") + logger.warn(s"ROR is being stopped! Loading main settings skipped!") case Left(IndexConfigReloadError.LoadingConfigError(error)) => - logger.error(s"[${requestId.show}] Cannot reload ROR settings - failure: ${error.show}") + logger.error(s"Cannot reload ROR settings - failure: ${error.show}") }) } yield reloadResult.map(_ => ()) } diff --git a/core/src/main/scala/tech/beshu/ror/boot/engines/TestConfigBasedReloadableEngine.scala b/core/src/main/scala/tech/beshu/ror/boot/engines/TestConfigBasedReloadableEngine.scala index e545bb529c..e078caa715 100644 --- a/core/src/main/scala/tech/beshu/ror/boot/engines/TestConfigBasedReloadableEngine.scala +++ b/core/src/main/scala/tech/beshu/ror/boot/engines/TestConfigBasedReloadableEngine.scala @@ -67,7 +67,7 @@ private[boot] class TestConfigBasedReloadableEngine private(boot: ReadonlyRest, ttl: PositiveFiniteDuration) (implicit requestId: RequestId): Task[Either[IndexConfigReloadWithUpdateError, TestConfig.Present]] = { for { - _ <- Task.delay(logger.info(s"[${requestId.show}] Reloading of ROR test settings was forced (TTL of test engine is ${ttl.show}) ...")) + _ <- Task.delay(logger.info(s"Reloading of ROR test settings was forced (TTL of test engine is ${ttl.show}) ...")) reloadResult <- reloadInProgress.withPermit { value { for { @@ -95,17 +95,17 @@ private[boot] class TestConfigBasedReloadableEngine private(boot: ReadonlyRest, } _ <- Task.delay(reloadResult match { case Right(_) => - logger.info(s"[${requestId.show}] ROR ${name.show} engine (id=${config.hashString().show}) reloaded!") + logger.info(s"ROR ${name.show} engine (id=${config.hashString().show}) reloaded!") case Left(ReloadError(RawConfigReloadError.ConfigUpToDate(oldConfig))) => - logger.info(s"[${requestId.show}] ROR ${name.show} engine (id=${oldConfig.hashString().show}) already loaded!") + logger.info(s"ROR ${name.show} engine (id=${oldConfig.hashString().show}) already loaded!") case Left(ReloadError(RawConfigReloadError.ReloadingFailed(StartingFailure(message, Some(ex))))) => - logger.error(s"[${requestId.show}] Cannot reload ROR test settings - failure: ${message.show}", ex) + logger.error(s"Cannot reload ROR test settings - failure: ${message.show}", ex) case Left(ReloadError(RawConfigReloadError.ReloadingFailed(StartingFailure(message, None)))) => - logger.error(s"[${requestId.show}] Cannot reload ROR test settings - failure: ${message.show}") + logger.error(s"Cannot reload ROR test settings - failure: ${message.show}") case Left(ReloadError(RawConfigReloadError.RorInstanceStopped)) => - logger.warn(s"[${requestId.show}] ROR is being stopped! Loading tests settings skipped!") + logger.warn(s"ROR is being stopped! Loading tests settings skipped!") case Left(IndexConfigSavingError(SavingIndexConfigError.CannotSaveConfig)) => - logger.error(s"[${requestId.show}] Saving ROR test settings in index failed") + logger.error(s"Saving ROR test settings in index failed") }) } yield reloadResult } diff --git a/core/src/main/scala/tech/beshu/ror/buildinfo/LogPluginBuildInfoMessage.scala b/core/src/main/scala/tech/beshu/ror/buildinfo/LogPluginBuildInfoMessage.scala index 907f2e7f66..9b5c3308fb 100644 --- a/core/src/main/scala/tech/beshu/ror/buildinfo/LogPluginBuildInfoMessage.scala +++ b/core/src/main/scala/tech/beshu/ror/buildinfo/LogPluginBuildInfoMessage.scala @@ -16,13 +16,13 @@ */ package tech.beshu.ror.buildinfo -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import scala.util.{Failure, Success} -object LogPluginBuildInfoMessage extends Logging { +object LogPluginBuildInfoMessage extends RequestIdAwareLogging { private val buildInfo = doPrivileged { BuildInfoReader.create() } def apply(): Unit = { @@ -31,8 +31,8 @@ object LogPluginBuildInfoMessage extends Logging { private def logBuildInfoMessage(): Unit = { buildInfo match { - case Success(bf) => logger.info(createLogMessage(bf)) - case Failure(_) => logger.error("Cannot find build info file. No info about ReadonlyREST version.") + case Success(bf) => noRequestIdLogger.info(createLogMessage(bf)) + case Failure(_) => noRequestIdLogger.error("Cannot find build info file. No info about ReadonlyREST version.") } } diff --git a/core/src/main/scala/tech/beshu/ror/configuration/FipsConfiguration.scala b/core/src/main/scala/tech/beshu/ror/configuration/FipsConfiguration.scala index 3a80e85e59..9cb5e74691 100644 --- a/core/src/main/scala/tech/beshu/ror/configuration/FipsConfiguration.scala +++ b/core/src/main/scala/tech/beshu/ror/configuration/FipsConfiguration.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.configuration import better.files.File import io.circe.Decoder import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.configuration.FipsConfiguration.FipsMode import tech.beshu.ror.configuration.FipsConfiguration.FipsMode.NonFips import tech.beshu.ror.configuration.loader.FileConfigLoader @@ -30,7 +30,7 @@ import java.nio.file.Path final case class FipsConfiguration(fipsMode: FipsMode) -object FipsConfiguration extends Logging { +object FipsConfiguration extends RequestIdAwareLogging { def load(esEnv: EsEnv) (implicit environmentConfig: EnvironmentConfig): Task[Either[MalformedSettings, FipsConfiguration]] = Task { @@ -40,7 +40,7 @@ object FipsConfiguration extends Logging { error => Left(error), { case FipsConfiguration(FipsMode.NonFips) => - logger.info(s"Cannot find FIPS configuration in ${esConfig.show} ...") + noRequestIdLogger.info(s"Cannot find FIPS configuration in ${esConfig.show} ...") fallbackToRorConfig(esEnv.configPath) case ssl => Right(ssl) @@ -51,7 +51,7 @@ object FipsConfiguration extends Logging { private def fallbackToRorConfig(esConfigFolderPath: Path) (implicit environmentConfig: EnvironmentConfig) = { val rorConfig = new FileConfigLoader(esConfigFolderPath).rawConfigFile - logger.info(s"... trying: ${rorConfig.show}") + noRequestIdLogger.info(s"... trying: ${rorConfig.show}") if (rorConfig.exists) { loadFipsConfigFromFile(rorConfig) } else { diff --git a/core/src/main/scala/tech/beshu/ror/configuration/RorBootConfiguration.scala b/core/src/main/scala/tech/beshu/ror/configuration/RorBootConfiguration.scala index eefe0b15e1..69ea98c92b 100644 --- a/core/src/main/scala/tech/beshu/ror/configuration/RorBootConfiguration.scala +++ b/core/src/main/scala/tech/beshu/ror/configuration/RorBootConfiguration.scala @@ -20,7 +20,7 @@ import better.files.File import cats.data.NonEmptyList import io.circe.Decoder import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.configuration.RorBootConfiguration.{RorFailedToStartResponse, RorNotStartedResponse} import tech.beshu.ror.es.EsEnv import tech.beshu.ror.implicits.* @@ -29,7 +29,7 @@ import tech.beshu.ror.utils.yaml.YamlKeyDecoder final case class RorBootConfiguration(rorNotStartedResponse: RorNotStartedResponse, rorFailedToStartResponse: RorFailedToStartResponse) -object RorBootConfiguration extends Logging { +object RorBootConfiguration extends RequestIdAwareLogging { def load(env: EsEnv) (implicit environmentConfig: EnvironmentConfig): Task[Either[MalformedSettings, RorBootConfiguration]] = Task { @@ -62,7 +62,7 @@ object RorBootConfiguration extends Logging { } } -private object Decoders extends Logging { +private object Decoders extends RequestIdAwareLogging { object consts { val rorSection = "readonlyrest" diff --git a/core/src/main/scala/tech/beshu/ror/configuration/RorIndexNameConfiguration.scala b/core/src/main/scala/tech/beshu/ror/configuration/RorIndexNameConfiguration.scala index 6e5008612a..0173715329 100644 --- a/core/src/main/scala/tech/beshu/ror/configuration/RorIndexNameConfiguration.scala +++ b/core/src/main/scala/tech/beshu/ror/configuration/RorIndexNameConfiguration.scala @@ -21,7 +21,7 @@ import cats.data.NonEmptyList import eu.timepit.refined.types.string.NonEmptyString import io.circe.Decoder import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.domain.{IndexName, RorConfigurationIndex} import tech.beshu.ror.accesscontrol.utils.CirceOps.DecoderHelpers.* import tech.beshu.ror.es.EsEnv @@ -30,7 +30,7 @@ import tech.beshu.ror.utils.yaml.YamlKeyDecoder final case class RorIndexNameConfiguration(index: RorConfigurationIndex) -object RorIndexNameConfiguration extends Logging { +object RorIndexNameConfiguration extends RequestIdAwareLogging { private val defaultIndexName = IndexName.Full(nes(".readonlyrest")) diff --git a/core/src/main/scala/tech/beshu/ror/configuration/RorProperties.scala b/core/src/main/scala/tech/beshu/ror/configuration/RorProperties.scala index 84d206b844..fcce6cf93a 100644 --- a/core/src/main/scala/tech/beshu/ror/configuration/RorProperties.scala +++ b/core/src/main/scala/tech/beshu/ror/configuration/RorProperties.scala @@ -21,7 +21,7 @@ import cats.Show import eu.timepit.refined.api.Refined import eu.timepit.refined.numeric.NonNegative import eu.timepit.refined.types.string.NonEmptyString -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import squants.information.{Information, Megabytes} import tech.beshu.ror.implicits.* import tech.beshu.ror.providers.PropertiesProvider @@ -34,7 +34,7 @@ import scala.concurrent.duration.* import scala.language.postfixOps import scala.util.{Failure, Success, Try} -object RorProperties extends Logging { +object RorProperties extends RequestIdAwareLogging { object defaults { val refreshInterval: PositiveFiniteDuration = (5 second).toRefinedPositiveUnsafe @@ -99,7 +99,7 @@ object RorProperties extends Logging { name, fromString, { - logger.info(s"No '${name.show}' property found. Using default: ${default.show}") + noRequestIdLogger.info(s"No '${name.show}' property found. Using default: ${default.show}") default } ) diff --git a/core/src/main/scala/tech/beshu/ror/configuration/SslConfiguration.scala b/core/src/main/scala/tech/beshu/ror/configuration/SslConfiguration.scala index 9ab59c953c..a943fcc5dd 100644 --- a/core/src/main/scala/tech/beshu/ror/configuration/SslConfiguration.scala +++ b/core/src/main/scala/tech/beshu/ror/configuration/SslConfiguration.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.configuration import better.files.* import io.circe.{Decoder, DecodingFailure, HCursor} import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.utils.CirceOps.DecoderHelpers import tech.beshu.ror.configuration.SslConfiguration.{ExternalSslConfiguration, InternodeSslConfiguration} import tech.beshu.ror.configuration.loader.FileConfigLoader @@ -33,7 +33,7 @@ import java.nio.file.{Path, Paths} final case class RorSsl(externalSsl: Option[ExternalSslConfiguration], interNodeSsl: Option[InternodeSslConfiguration]) -object RorSsl extends Logging { +object RorSsl extends RequestIdAwareLogging { val noSsl: RorSsl = RorSsl(None, None) @@ -46,7 +46,7 @@ object RorSsl extends Logging { error => Left(error), { case RorSsl(None, None) => - logger.info(s"Cannot find SSL configuration in ${esConfig.show} ...") + noRequestIdLogger.info(s"Cannot find SSL configuration in ${esConfig.show} ...") fallbackToRorConfig(esEnv.configPath) case ssl => Right(ssl) @@ -58,7 +58,7 @@ object RorSsl extends Logging { (implicit rorSslDecoder: Decoder[RorSsl], environmentConfig: EnvironmentConfig) = { val rorConfig = new FileConfigLoader(esConfigFolderPath).rawConfigFile - logger.info(s"... trying: ${rorConfig.show}") + noRequestIdLogger.info(s"... trying: ${rorConfig.show}") if (rorConfig.exists) { loadSslConfigFromFile(rorConfig) } else { @@ -133,7 +133,7 @@ object SslConfiguration { extends SslConfiguration } -private object SslDecoders extends Logging { +private object SslDecoders extends RequestIdAwareLogging { import tech.beshu.ror.configuration.SslConfiguration.* object consts { @@ -187,7 +187,7 @@ private object SslDecoders extends Logging { val presentKeys = c.keys.fold[Set[String]](Set.empty)(_.toSet) if (presentKeys.intersect(truststoreBasedKeys).nonEmpty && presentKeys.intersect(fileBasedKeys).nonEmpty) { val errorMessage = s"Field sets [${fileBasedKeys.show}] and [${truststoreBasedKeys.show}] could not be present in the same configuration section" - logger.error(errorMessage) + noRequestIdLogger.error(errorMessage) Left(DecodingFailure(errorMessage, List.empty)) } else if (presentKeys.intersect(truststoreBasedKeys).nonEmpty) { truststoreBasedClientCertificateConfigurationDecoder(c) @@ -198,7 +198,7 @@ private object SslDecoders extends Logging { .map(Option.apply) } else { val errorMessage = "PEM File Handling is not available in your current deployment of Elasticsearch" - logger.error(errorMessage) + noRequestIdLogger.error(errorMessage) Left(DecodingFailure(errorMessage, List.empty)) } } else { @@ -222,7 +222,7 @@ private object SslDecoders extends Logging { val presentKeys = c.keys.fold[Set[String]](Set.empty)(_.toSet) if (presentKeys.intersect(keystoreBasedKeys).nonEmpty && presentKeys.intersect(fileBasedKeys).nonEmpty) { val errorMessage = s"Field sets [${fileBasedKeys.show}] and [${keystoreBasedKeys.show}] could not be present in the same configuration section" - logger.error(errorMessage) + noRequestIdLogger.error(errorMessage) Left(DecodingFailure(errorMessage, List.empty)) } else if (presentKeys.intersect(keystoreBasedKeys).nonEmpty) { keystoreBasedServerCertificateConfigurationDecoder(c) @@ -231,12 +231,12 @@ private object SslDecoders extends Logging { fileBasedServerCertificateConfigurationDecoder(c) } else { val errorMessage = "PEM File Handling is not available in your current deployment of Elasticsearch" - logger.error(errorMessage) + noRequestIdLogger.error(errorMessage) Left(DecodingFailure(errorMessage, List.empty)) } } else { val errorMessage = "There was no SSL configuration present for server" - logger.error(errorMessage) + noRequestIdLogger.error(errorMessage) Left(DecodingFailure(errorMessage, List.empty)) } } diff --git a/core/src/main/scala/tech/beshu/ror/configuration/index/IndexConfigManager.scala b/core/src/main/scala/tech/beshu/ror/configuration/index/IndexConfigManager.scala index 7b0795a1c3..5b5aebccc8 100644 --- a/core/src/main/scala/tech/beshu/ror/configuration/index/IndexConfigManager.scala +++ b/core/src/main/scala/tech/beshu/ror/configuration/index/IndexConfigManager.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.configuration.index import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.domain.RorConfigurationIndex import tech.beshu.ror.configuration.{EnvironmentConfig, RawRorConfig} import tech.beshu.ror.configuration.index.IndexConfigError.{IndexConfigNotExist, IndexConfigUnknownStructure} @@ -29,7 +29,7 @@ import tech.beshu.ror.es.IndexJsonContentService.{CannotReachContentSource, Cann final class IndexConfigManager(indexJsonContentService: IndexJsonContentService) (implicit environmentConfig: EnvironmentConfig) extends BaseIndexConfigManager[RawRorConfig] - with Logging { + with RequestIdAwareLogging { override def load(indexName: RorConfigurationIndex): Task[Either[ConfigLoaderError[IndexConfigError], RawRorConfig]] = { indexJsonContentService diff --git a/core/src/main/scala/tech/beshu/ror/configuration/index/IndexTestConfigManager.scala b/core/src/main/scala/tech/beshu/ror/configuration/index/IndexTestConfigManager.scala index fe31acdb28..cb1589cfc1 100644 --- a/core/src/main/scala/tech/beshu/ror/configuration/index/IndexTestConfigManager.scala +++ b/core/src/main/scala/tech/beshu/ror/configuration/index/IndexTestConfigManager.scala @@ -22,7 +22,7 @@ import eu.timepit.refined.types.string.NonEmptyString import io.circe.syntax.EncoderOps import io.circe.{Codec, Decoder, Encoder} import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.blocks.definitions.ldap.LdapService import tech.beshu.ror.accesscontrol.blocks.definitions.{ExternalAuthenticationService, ExternalAuthorizationService} import tech.beshu.ror.accesscontrol.blocks.mocks.AuthServicesMocks @@ -52,7 +52,7 @@ import scala.util.Try final class IndexTestConfigManager(indexJsonContentService: IndexJsonContentService) (implicit environmentConfig: EnvironmentConfig) extends BaseIndexConfigManager[TestRorConfig] - with Logging { + with RequestIdAwareLogging { type Error = ConfigLoaderError[IndexConfigError] diff --git a/core/src/main/scala/tech/beshu/ror/configuration/loader/ConfigLoadingInterpreter.scala b/core/src/main/scala/tech/beshu/ror/configuration/loader/ConfigLoadingInterpreter.scala index a8a48bb7ca..e8efae171f 100644 --- a/core/src/main/scala/tech/beshu/ror/configuration/loader/ConfigLoadingInterpreter.scala +++ b/core/src/main/scala/tech/beshu/ror/configuration/loader/ConfigLoadingInterpreter.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.configuration.loader import cats.data.EitherT import cats.~> import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.domain.RorConfigurationIndex import tech.beshu.ror.configuration.ConfigLoading.LoadConfigAction import tech.beshu.ror.configuration.EsConfig.LoadEsConfigError @@ -33,13 +33,13 @@ import tech.beshu.ror.configuration.{ConfigLoading, EnvironmentConfig, EsConfig} import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.DurationOps.NonNegativeFiniteDuration -object ConfigLoadingInterpreter extends Logging { +object ConfigLoadingInterpreter extends RequestIdAwareLogging { def create(indexConfigManager: IndexConfigManager) (implicit environmentConfig: EnvironmentConfig): LoadConfigAction ~> Task = new (LoadConfigAction ~> Task) { override def apply[A](fa: LoadConfigAction[A]): Task[A] = fa match { case ConfigLoading.LoadConfigAction.LoadEsConfig(env) => - logger.info(s"Loading Elasticsearch settings from file: ${env.elasticsearchConfig.show}") + noRequestIdLogger.info(s"Loading Elasticsearch settings from file: ${env.elasticsearchConfig.show}") EsConfig .from(env) .map(_.left.map { @@ -56,27 +56,27 @@ object ConfigLoadingInterpreter extends Logging { ) }) case ConfigLoading.LoadConfigAction.ForceLoadRorConfigFromFile(path) => - logger.info(s"Loading ReadonlyREST settings forced loading from file from: ${path.show}") + noRequestIdLogger.info(s"Loading ReadonlyREST settings forced loading from file from: ${path.show}") EitherT(new FileConfigLoader(path).load()) .bimap(convertFileError, ForcedFileConfig(_)) .leftMap { error => - logger.error(s"Loading ReadonlyREST from file failed: ${error.toString}") + noRequestIdLogger.error(s"Loading ReadonlyREST from file failed: ${error.toString}") error }.value case ConfigLoading.LoadConfigAction.LoadRorConfigFromFile(path) => - logger.info(s"Loading ReadonlyREST settings from file from: ${path.show}, because index not exist") + noRequestIdLogger.info(s"Loading ReadonlyREST settings from file from: ${path.show}, because index not exist") EitherT(new FileConfigLoader(path).load()) .bimap(convertFileError, FileConfig(_)) .leftMap { error => - logger.error(s"Loading ReadonlyREST from file failed: ${error.toString}") + noRequestIdLogger.error(s"Loading ReadonlyREST from file failed: ${error.toString}") error } .value case ConfigLoading.LoadConfigAction.LoadRorConfigFromIndex(configIndex, inIndexLoadingDelay) => - logger.info(s"[CLUSTERWIDE SETTINGS] Loading ReadonlyREST settings from index (${configIndex.index.show}) ...") + noRequestIdLogger.info(s"[CLUSTERWIDE SETTINGS] Loading ReadonlyREST settings from index (${configIndex.index.show}) ...") loadFromIndex(indexConfigManager, configIndex, inIndexLoadingDelay) .map { rawRorConfig => - logger.debug(s"[CLUSTERWIDE SETTINGS] Loaded raw config from index: ${rawRorConfig.raw.show}") + noRequestIdLogger.debug(s"[CLUSTERWIDE SETTINGS] Loaded raw config from index: ${rawRorConfig.raw.show}") rawRorConfig } .bimap(convertIndexError, IndexConfig(configIndex, _)) @@ -90,11 +90,11 @@ object ConfigLoadingInterpreter extends Logging { private def logIndexLoadingError[A](error: LoadedRorConfig.LoadingIndexError): Unit = { error match { case IndexParsingError(message) => - logger.error(s"Loading ReadonlyREST settings from index failed: ${message.show}") + noRequestIdLogger.error(s"Loading ReadonlyREST settings from index failed: ${message.show}") case LoadedRorConfig.IndexUnknownStructure => - logger.info(s"Loading ReadonlyREST settings from index failed: index content malformed") + noRequestIdLogger.info(s"Loading ReadonlyREST settings from index failed: index content malformed") case LoadedRorConfig.IndexNotExist => - logger.info(s"Loading ReadonlyREST settings from index failed: cannot find index") + noRequestIdLogger.info(s"Loading ReadonlyREST settings from index failed: cannot find index") } } diff --git a/core/src/main/scala/tech/beshu/ror/configuration/loader/TestConfigLoadingInterpreter.scala b/core/src/main/scala/tech/beshu/ror/configuration/loader/TestConfigLoadingInterpreter.scala index 1325459dba..b3445c1a88 100644 --- a/core/src/main/scala/tech/beshu/ror/configuration/loader/TestConfigLoadingInterpreter.scala +++ b/core/src/main/scala/tech/beshu/ror/configuration/loader/TestConfigLoadingInterpreter.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.configuration.loader import cats.data.EitherT import cats.~> import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.domain.RorConfigurationIndex import tech.beshu.ror.configuration.TestConfigLoading.LoadTestConfigAction import tech.beshu.ror.configuration.index.{IndexConfigError, IndexTestConfigManager} @@ -30,19 +30,19 @@ import tech.beshu.ror.configuration.{TestConfigLoading, TestRorConfig} import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.DurationOps.NonNegativeFiniteDuration -object TestConfigLoadingInterpreter extends Logging { +object TestConfigLoadingInterpreter extends RequestIdAwareLogging { def create(indexConfigManager: IndexTestConfigManager): LoadTestConfigAction ~> Task = new (LoadTestConfigAction ~> Task) { override def apply[A](fa: LoadTestConfigAction[A]): Task[A] = fa match { case TestConfigLoading.LoadTestConfigAction.LoadRorConfigFromIndex(configIndex, loadingDelay) => - logger.info(s"[CLUSTERWIDE SETTINGS] Loading ReadonlyREST test settings from index (${configIndex.index.show}) ...") + noRequestIdLogger.info(s"[CLUSTERWIDE SETTINGS] Loading ReadonlyREST test settings from index (${configIndex.index.show}) ...") loadFromIndex(indexConfigManager, configIndex, loadingDelay) .map { testConfig => testConfig match { case TestRorConfig.Present(rawConfig, _, _) => - logger.debug(s"[CLUSTERWIDE SETTINGS] Loaded raw test config from index: ${rawConfig.raw.show}") + noRequestIdLogger.debug(s"[CLUSTERWIDE SETTINGS] Loaded raw test config from index: ${rawConfig.raw.show}") case TestRorConfig.NotSet => - logger.debug("[CLUSTERWIDE SETTINGS] There was no test settings in index. Test settings engine will be not initialized.") + noRequestIdLogger.debug("[CLUSTERWIDE SETTINGS] There was no test settings in index. Test settings engine will be not initialized.") } testConfig } @@ -57,11 +57,11 @@ object TestConfigLoadingInterpreter extends Logging { private def logIndexLoadingError(error: LoadedTestRorConfig.LoadingIndexError): Unit = { error match { case IndexParsingError(message) => - logger.error(s"Loading ReadonlyREST settings from index failed: ${message.show}") + noRequestIdLogger.error(s"Loading ReadonlyREST settings from index failed: ${message.show}") case LoadedTestRorConfig.IndexUnknownStructure => - logger.info("Loading ReadonlyREST test settings from index failed: index content malformed") + noRequestIdLogger.info("Loading ReadonlyREST test settings from index failed: index content malformed") case LoadedTestRorConfig.IndexNotExist => - logger.info("Loading ReadonlyREST test settings from index failed: cannot find index") + noRequestIdLogger.info("Loading ReadonlyREST test settings from index failed: cannot find index") } } diff --git a/core/src/main/scala/tech/beshu/ror/utils/RequestIdAwareLogging.scala b/core/src/main/scala/tech/beshu/ror/utils/RequestIdAwareLogging.scala new file mode 100644 index 0000000000..71386dd0f4 --- /dev/null +++ b/core/src/main/scala/tech/beshu/ror/utils/RequestIdAwareLogging.scala @@ -0,0 +1,89 @@ +/* + * This file is part of ReadonlyREST. + * + * ReadonlyREST is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ReadonlyREST is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ReadonlyREST. If not, see http://www.gnu.org/licenses/ + */ +package tech.beshu.ror.utils + +import cats.implicits.toShow +import org.apache.logging.log4j.scala.Logger +import org.apache.logging.log4j.spi.ExtendedLogger +import tech.beshu.ror.accesscontrol.domain.HasRequestId +import tech.beshu.ror.utils.RequestIdAwareLogging.RorLogger + +trait RequestIdAwareLogging { + + protected lazy val underlyingLogger: Logger = Logger(getClass) + + val logger: RorLogger = new RorLogger(underlyingLogger) + + val noRequestIdLogger: Logger = underlyingLogger + +} + +object RequestIdAwareLogging { + + final class RorLogger(private val log: Logger) { + + lazy val delegate: ExtendedLogger = log.delegate + + def trace(msg: => String)(implicit rid: HasRequestId): Unit = + if (log.delegate.isTraceEnabled) log.trace(buildMsg(msg, rid)) + + def trace(msg: => String, t: Throwable)(implicit rid: HasRequestId): Unit = + if (log.delegate.isTraceEnabled) log.trace(buildMsg(msg, rid), t) + + def debug(msg: => String)(implicit rid: HasRequestId): Unit = + if (log.delegate.isDebugEnabled) log.debug(buildMsg(msg, rid)) + + def debug(msg: => String, t: Throwable)(implicit rid: HasRequestId): Unit = + if (log.delegate.isDebugEnabled) log.debug(buildMsg(msg, rid), t) + + def info(msg: => String)(implicit rid: HasRequestId): Unit = + if (log.delegate.isInfoEnabled) log.info(buildMsg(msg, rid)) + + def info(msg: => String, t: Throwable)(implicit rid: HasRequestId): Unit = + if (log.delegate.isInfoEnabled) log.info(buildMsg(msg, rid), t) + + def warn(msg: => String)(implicit rid: HasRequestId): Unit = + if (log.delegate.isWarnEnabled) log.warn(buildMsg(msg, rid)) + + def warn(msg: => String, t: Throwable)(implicit rid: HasRequestId): Unit = + if (log.delegate.isWarnEnabled) log.warn(buildMsg(msg, rid), t) + + def error(msg: => String)(implicit rid: HasRequestId): Unit = + if (log.delegate.isErrorEnabled) log.error(buildMsg(msg, rid)) + + def error(msg: => String, t: Throwable)(implicit rid: HasRequestId): Unit = + if (log.delegate.isErrorEnabled) log.error(buildMsg(msg, rid), t) + + def errorEx(msg: => String, t: Throwable)(implicit rid: HasRequestId): Unit = { + if (log.delegate.isDebugEnabled) log.error(buildMsg(msg, rid), t) + else log.error(buildMsg(s"$msg; ${t.getMessage}", rid)) + } + + def warnEx(msg: => String, t: Throwable)(implicit rid: HasRequestId): Unit = { + if (log.delegate.isDebugEnabled) log.warn(buildMsg(msg, rid), t) + else log.warn(buildMsg(s"$msg; ${t.getMessage}", rid)) + } + + private def buildMsg(msg: String, requestId: HasRequestId): String = { + import tech.beshu.ror.implicits.requestIdShow + val rid = requestId.requestId.show + val sb = new java.lang.StringBuilder(rid.length + msg.length + 4) + sb.append('[').append(rid).append("] ").append(msg) + sb.toString + } + } +} diff --git a/core/src/main/scala/tech/beshu/ror/utils/SSLCertHelper.scala b/core/src/main/scala/tech/beshu/ror/utils/SSLCertHelper.scala index 9abf13d1a7..d7f246853e 100644 --- a/core/src/main/scala/tech/beshu/ror/utils/SSLCertHelper.scala +++ b/core/src/main/scala/tech/beshu/ror/utils/SSLCertHelper.scala @@ -21,7 +21,6 @@ import io.netty.buffer.ByteBufAllocator import io.netty.channel.ChannelHandlerContext import io.netty.handler.ssl.util.InsecureTrustManagerFactory import io.netty.handler.ssl.{ClientAuth, SslContext, SslContextBuilder} -import org.apache.logging.log4j.scala.Logging import org.bouncycastle.asn1.pkcs.PrivateKeyInfo import org.bouncycastle.jsse.provider.BouncyCastleJsseProvider import org.bouncycastle.openssl.PEMParser @@ -40,7 +39,7 @@ import scala.jdk.CollectionConverters.* import scala.language.implicitConversions import scala.util.Try -object SSLCertHelper extends Logging { +object SSLCertHelper extends RequestIdAwareLogging { def prepareSSLEngine(sslContext: SslContext, hostAndPort: HostAndPort, @@ -87,7 +86,7 @@ object SSLCertHelper extends Logging { } getFipsCompliantKeyManagerFactory(keystoreBasedConfiguration) .map { keyManagerFactory => - logger.info(s"Initializing ROR SSL using SSL provider: ${keyManagerFactory.getProvider.getName.show}") + noRequestIdLogger.info(s"Initializing ROR SSL using SSL provider: ${keyManagerFactory.getProvider.getName.show}") builder.keyManager(keyManagerFactory) } } else { @@ -97,7 +96,7 @@ object SSLCertHelper extends Logging { case keystoreBasedConfiguration: KeystoreBasedConfiguration => getPrivateKeyAndCertificateChainFromKeystore(keystoreBasedConfiguration) }).map { case (privateKey, certificateChain) => - logger.info(s"Initializing ROR SSL using default SSL provider ${SslContext.defaultServerProvider().name().show}") + noRequestIdLogger.info(s"Initializing ROR SSL using default SSL provider ${SslContext.defaultServerProvider().name().show}") builder.keyManager(privateKey, certificateChain.toList.asJava) } } @@ -177,7 +176,7 @@ object SSLCertHelper extends Logging { trySetProtocolsAndCiphersInsideNewEngine(sslContextBuilder: SslContextBuilder, config) .fold( ex => { - logger.error(s"ROR SSL: cannot validate SSL protocols and ciphers! ${ex.getClass.getSimpleName.show} : ${ex.getMessage.show}", ex) + noRequestIdLogger.error(s"ROR SSL: cannot validate SSL protocols and ciphers! ${ex.getClass.getSimpleName.show} : ${ex.getMessage.show}", ex) false }, _ => true @@ -205,10 +204,10 @@ object SSLCertHelper extends Logging { .use { keystoreFile => IO { val keystore = if (fipsCompliant) { - logger.info("Trying to load data in FIPS compliant BCFKS format...") + noRequestIdLogger.info("Trying to load data in FIPS compliant BCFKS format...") java.security.KeyStore.getInstance("BCFKS", "BCFIPS") } else { - logger.info("Trying to load data in JKS or PKCS#12 format...") + noRequestIdLogger.info("Trying to load data in JKS or PKCS#12 format...") java.security.KeyStore.getInstance("JKS") } keystore.load(keystoreFile, password) @@ -219,14 +218,14 @@ object SSLCertHelper extends Logging { private def loadKeystore(keystoreBasedConfiguration: KeystoreBasedConfiguration, fipsCompliant: Boolean): IO[KeyStore] = { for { - _ <- IO(logger.info("Preparing keystore...")) + _ <- IO(noRequestIdLogger.info("Preparing keystore...")) keystore <- loadKeystoreFromFile(keystoreBasedConfiguration.keystoreFile.value, keystoreBasedConfiguration.keystorePassword, fipsCompliant) } yield keystore } private def loadTruststore(truststoreBasedConfiguration: TruststoreBasedConfiguration, fipsCompliant: Boolean): IO[KeyStore] = { for { - _ <- IO(logger.info("Preparing truststore...")) + _ <- IO(noRequestIdLogger.info("Preparing truststore...")) truststore <- loadKeystoreFromFile(truststoreBasedConfiguration.truststoreFile.value, truststoreBasedConfiguration.truststorePassword, fipsCompliant) } yield truststore } @@ -235,7 +234,7 @@ object SSLCertHelper extends Logging { config.keyAlias match { case None if keystore.aliases().hasMoreElements => val firstAlias = keystore.aliases().nextElement() - logger.info(s"ROR SSL: ssl.key_alias not configured, took first alias in keystore: ${firstAlias.show}") + noRequestIdLogger.info(s"ROR SSL: ssl.key_alias not configured, took first alias in keystore: ${firstAlias.show}") firstAlias case None => throw MalformedSslSettings("Key not found in provided keystore!") @@ -252,7 +251,7 @@ object SSLCertHelper extends Logging { loadKeystore(keystoreBasedConfiguration, fipsCompliant = true) .map { keystore => if (keystoreBasedConfiguration.keyPass.isDefined) { - logger.warn("ROR configuration parameter key_pass is declared however it won't be used in this mode. In this case password for specific key MUST be the same as keystore password") + noRequestIdLogger.warn("ROR configuration parameter key_pass is declared however it won't be used in this mode. In this case password for specific key MUST be the same as keystore password") } removeAllAliasesFromKeystoreBesidesOne(keystore, prepareAlias(keystore, keystoreBasedConfiguration)) val kmf = getKeyManagerFactoryInstance(fipsCompliant = true) @@ -314,15 +313,15 @@ object SSLCertHelper extends Logging { private def trySetProtocolsAndCiphersInsideNewEngine(sslContextBuilder: SslContextBuilder, config: SslConfiguration) = Try { val sslEngine = sslContextBuilder.build().newEngine(ByteBufAllocator.DEFAULT) - logger.info(s"ROR SSL: Available ciphers: ${sslEngine.getEnabledCipherSuites.toList.show}") + noRequestIdLogger.info(s"ROR SSL: Available ciphers: ${sslEngine.getEnabledCipherSuites.toList.show}") if (config.allowedCiphers.nonEmpty) { sslEngine.setEnabledCipherSuites(config.allowedCiphers.map(_.value).toArray) - logger.info(s"ROR SSL: Restricting to ciphers: ${sslEngine.getEnabledCipherSuites.toList.show}") + noRequestIdLogger.info(s"ROR SSL: Restricting to ciphers: ${sslEngine.getEnabledCipherSuites.toList.show}") } - logger.info(s"ROR SSL: Available SSL protocols: ${sslEngine.getEnabledProtocols.toList.show}") + noRequestIdLogger.info(s"ROR SSL: Available SSL protocols: ${sslEngine.getEnabledProtocols.toList.show}") if (config.allowedProtocols.nonEmpty) { sslEngine.setEnabledProtocols(config.allowedProtocols.map(_.value).toArray) - logger.info(s"ROR SSL: Restricting to SSL protocols: ${sslEngine.getEnabledProtocols.toList.show}") + noRequestIdLogger.info(s"ROR SSL: Restricting to SSL protocols: ${sslEngine.getEnabledProtocols.toList.show}") } } @@ -334,7 +333,7 @@ object SSLCertHelper extends Logging { } getFipsCompliantKeyManagerFactory(keystoreBasedConfiguration) .map { keyManagerFactory => - logger.info(s"Initializing ROR SSL using SSL provider: ${keyManagerFactory.getProvider.getName.show}") + noRequestIdLogger.info(s"Initializing ROR SSL using SSL provider: ${keyManagerFactory.getProvider.getName.show}") SslContextBuilder.forServer(keyManagerFactory) } } else { @@ -344,7 +343,7 @@ object SSLCertHelper extends Logging { case keystoreBasedConfiguration: KeystoreBasedConfiguration => getPrivateKeyAndCertificateChainFromKeystore(keystoreBasedConfiguration) }).map { case (privateKey, certificateChain) => - logger.info(s"Initializing ROR SSL using default SSL provider ${SslContext.defaultServerProvider().name().show}") + noRequestIdLogger.info(s"Initializing ROR SSL using default SSL provider ${SslContext.defaultServerProvider().name().show}") SslContextBuilder.forServer(privateKey, certificateChain.toList.asJava) } } diff --git a/core/src/test/scala/tech/beshu/ror/mocks/MockHttpClientsFactory.scala b/core/src/test/scala/tech/beshu/ror/mocks/MockHttpClientsFactory.scala index 69e38a04a6..7ca85de774 100644 --- a/core/src/test/scala/tech/beshu/ror/mocks/MockHttpClientsFactory.scala +++ b/core/src/test/scala/tech/beshu/ror/mocks/MockHttpClientsFactory.scala @@ -17,12 +17,14 @@ package tech.beshu.ror.mocks import monix.eval.Task +import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.accesscontrol.factory.HttpClientsFactory.HttpClient import tech.beshu.ror.accesscontrol.factory.{HttpClientsFactory, SimpleHttpClient} object MockHttpClientsFactory extends HttpClientsFactory { override def create(config: HttpClientsFactory.Config): HttpClient = new SimpleHttpClient[Task] { - override def send(request: HttpClient.Request): Task[HttpClient.Response] = + override def send(request: HttpClient.Request) + (implicit requestId: RequestId): Task[HttpClient.Response] = throw new IllegalStateException("Cannot use it. It's just a mock") override def close(): Task[Unit] = Task.unit diff --git a/es67x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es67x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index 6678bb7ee0..5c135fd766 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.support.{ActionFilter, ActionFilterChain} import org.elasticsearch.action.{ActionListener, ActionRequest, ActionResponse} import org.elasticsearch.client.node.NodeClient @@ -60,7 +60,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, rorEsConfig: ReadonlyRestEsConfig) (implicit environmentConfig: EnvironmentConfig) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = environmentConfig.uniqueIdentifierGenerator @@ -201,12 +201,12 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def handleRorNotReadyYet(esContext: EsContext): Unit = { - logger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") + noRequestIdLogger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") rorNotAvailableRequestHandler.handleRorNotReadyYet(esContext) } private def handleRorFailedToStart(esContext: EsContext): Unit = { - logger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") + noRequestIdLogger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") rorNotAvailableRequestHandler.handleRorFailedToStart(esContext) } @@ -228,7 +228,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def logAndSetStartingFailureState(failure: StartingFailure): Unit = { - logger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) + noRequestIdLogger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) rorInstanceState.set(RorInstanceStartingState.NotStarted(failure)) } } diff --git a/es67x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala b/es67x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala index 7f92461f08..72c14bf252 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.xcontent.cbor.CborXContent import org.elasticsearch.common.xcontent.json.JsonXContent import org.elasticsearch.common.xcontent.smile.SmileXContent @@ -29,7 +29,7 @@ import tech.beshu.ror.accesscontrol.domain.ResponseFieldsFiltering.{AccessMode, import scala.jdk.CollectionConverters.* trait ResponseFieldsFiltering { - this: Logging => + this: RequestIdAwareLogging => private val responseFieldsRestrictions: Atomic[Option[ResponseFieldsRestrictions]] = Atomic(None: Option[ResponseFieldsRestrictions]) @@ -44,7 +44,7 @@ trait ResponseFieldsFiltering { case bytesRestResponse: BytesRestResponse => filterBytesRestResponse(bytesRestResponse, fieldsRestrictions) case otherResponse => - logger.warn("ResponseFields filtering is unavailable for this type of request") + noRequestIdLogger.warn("ResponseFields filtering is unavailable for this type of request") otherResponse } case None => diff --git a/es67x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala b/es67x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala index 0f26750588..da95de59a4 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.action.{ActionListener, ActionResponse} import org.elasticsearch.threadpool.ThreadPool @@ -37,7 +37,7 @@ sealed abstract class RorActionListener[T](val underlying: ActionListener[T]) ex final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionListener[T], correlationId: Eval[CorrelationId]) - extends RorActionListener[T](underlying) with Logging { + extends RorActionListener[T](underlying) with RequestIdAwareLogging { override def onFailure(e: Exception): Unit = { super.onFailure(adaptExceptionIfNeeded(e)) @@ -47,7 +47,7 @@ final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionLis ex match { case esException: ElasticsearchException => esException case other => - logger.error(s"[${correlationId.value.show}] Internal error.", other) + noRequestIdLogger.error(s"[${correlationId.value.show}] Internal error.", other) new ElasticsearchException(s"[${correlationId.value.show}] Internal error. See logs for details.") } } diff --git a/es67x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala b/es67x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala index 5f91c807dd..f2b0b9efb6 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.rest.{AbstractRestChannel, RestChannel as EsRestChannel, RestRequest as EsRestRequest, RestResponse as EsRestResponse} import squants.information.{Bytes, Information} import tech.beshu.ror.accesscontrol.domain.{Address, Header, UriPath} @@ -39,7 +39,7 @@ object RorRestChannel { final class RorRestChannel private(underlying: EsRestChannel, val restRequest: RorRestRequest) extends AbstractRestChannel(underlying.request(), true) with ResponseFieldsFiltering - with Logging { + with RequestIdAwareLogging { override def sendResponse(response: EsRestResponse): Unit = { ThreadRepo.removeRestChannel(this) diff --git a/es67x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala b/es67x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala index 6babc712b9..3c80750a25 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala @@ -18,16 +18,15 @@ package tech.beshu.ror.es.actions.rradmin import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.ConfigApi.ConfigResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAdminActionHandler extends Logging { +class RRAdminActionHandler extends RequestIdAwareLogging { private implicit val adminRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +51,7 @@ class RRAdminActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAdminResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAdminAction internal error", ex) + logger.error("RRAdminAction internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es67x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala b/es67x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala index c55835a1d0..ce45c6f48e 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala @@ -16,18 +16,15 @@ */ package tech.beshu.ror.es.actions.rrauthmock -import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.AuthMockApi.AuthMockResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier -import tech.beshu.ror.implicits.* +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAuthMockActionHandler extends Logging { +class RRAuthMockActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -53,7 +50,7 @@ class RRAuthMockActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAuthMockResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAuthMock internal error", ex) + logger.error("RRAuthMock internal error", ex) listener.onFailure(new Exception(ex)) } } diff --git a/es67x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala b/es67x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala index aa8bb31e67..640084c4ec 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestconfig import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.TestConfigApi.TestConfigResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestConfigActionHandler extends Logging { +class RRTestConfigActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +52,7 @@ class RRTestConfigActionHandler extends Logging { case Right(response) => listener.onResponse(new RRTestConfigResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRTestConfig internal error", ex) + logger.error(s"RRTestConfig internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es67x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala b/es67x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala index 09112e0537..12e6a79dc9 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.dlsfls import cats.data.StateT import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.DirectoryReader import org.elasticsearch.common.util.concurrent.ThreadContext import org.elasticsearch.index.IndexService @@ -29,7 +29,7 @@ import tech.beshu.ror.accesscontrol.headerValues.transientFieldsFromHeaderValue import scala.util.{Failure, Success, Try} -class RoleIndexSearcherWrapper(indexService: IndexService) extends IndexSearcherWrapper with Logging { +class RoleIndexSearcherWrapper(indexService: IndexService) extends IndexSearcherWrapper with RequestIdAwareLogging { override def wrap(reader: DirectoryReader): DirectoryReader = { val threadContext: ThreadContext = indexService.getThreadPool.getThreadContext @@ -48,7 +48,7 @@ class RoleIndexSearcherWrapper(indexService: IndexService) extends IndexSearcher } .map(r => (r, r)) case None => - logger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") + noRequestIdLogger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") Success((reader, reader)) } } @@ -60,13 +60,13 @@ class RoleIndexSearcherWrapper(indexService: IndexService) extends IndexSearcher nel <- NonEmptyString.from(value) match { case Right(nel) => Success(nel) case Left(_) => - logger.debug("FLS: empty header value") + noRequestIdLogger.debug("FLS: empty header value") failure } fields <- transientFieldsFromHeaderValue.fromRawValue(nel) match { case result@Success(_) => result case Failure(ex) => - logger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) + noRequestIdLogger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) failure } } yield fields diff --git a/es67x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala b/es67x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala index 85f92af263..a98c7a1067 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.dlsfls import java.io.ByteArrayOutputStream import java.util.{Iterator => JavaIterator} import com.google.common.collect.Iterators -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.StoredFieldVisitor.Status import org.apache.lucene.index.* import org.apache.lucene.util.Bits @@ -36,21 +36,21 @@ import scala.jdk.CollectionConverters.* import scala.util.Try private class RorDocumentFieldReader(reader: LeafReader, fieldsRestrictions: FieldsRestrictions) - extends FilterLeafReader(reader) with Logging { + extends FilterLeafReader(reader) with RequestIdAwareLogging { private val policy = new FieldsPolicy(fieldsRestrictions) private val remainingFieldsInfo = { val fInfos = in.getFieldInfos val newInfos = if (fInfos.asScala.isEmpty) { - logger.warn("original fields were empty! This is weird!") + noRequestIdLogger.warn("original fields were empty! This is weird!") fInfos } else { val remainingFields = fInfos.asScala.filter(f => policy.canKeep(f.name)).toSet new FieldInfos(remainingFields.toArray) } - logger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") - logger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") - logger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") + noRequestIdLogger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") newInfos } private val jsonPolicyBasedFilterer = new JsonPolicyBasedFilterer(policy) diff --git a/es67x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala b/es67x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala index 15f2544476..42e0b270c0 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.* import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest @@ -84,7 +84,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, threadPool: ThreadPool) (implicit generator: UniqueIdentifierGenerator, scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle(engines: Engines, esContext: EsContext): Task[Either[Error, Unit]] = { @@ -204,7 +204,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, case SearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case MultiSearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case _ => - logger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") + noRequestIdLogger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") regularRequestHandler.handle(new DummyCompositeIndicesEsRequestContext(request, esContext, aclContext, clusterService, threadPool)) } // rest diff --git a/es67x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala b/es67x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala index a388bb0f9f..57be14c040 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.common.io.stream.StreamOutput import org.elasticsearch.common.xcontent.{ToXContent, ToXContentObject, XContentBuilder} @@ -45,7 +45,7 @@ import scala.util.{Failure, Success, Try} class CurrentUserMetadataRequestHandler(engine: Engine, esContext: EsContext) - extends Logging { + extends RequestIdAwareLogging { def handle(request: RequestContext.Aux[CurrentUserMetadataRequestBlockContext] with EsRequest[CurrentUserMetadataRequestBlockContext]): Task[Unit] = { engine.core.accessControl @@ -69,7 +69,7 @@ class CurrentUserMetadataRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(ex.asInstanceOf[Exception]) } } @@ -86,13 +86,13 @@ class CurrentUserMetadataRequestHandler(engine: Engine, )) } - private def onPassThrough(requestContext: RequestContext): Unit = { - logger.warn(s"[${requestContext.id.toRequestId.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") + private def onPassThrough(implicit requestContext: RequestContext): Unit = { + logger.warn(s"Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") esContext.listener.onFailure(createRorNotEnabledResponse()) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } diff --git a/es67x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala b/es67x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala index 2fb01dcc41..c5c44fda92 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala @@ -20,7 +20,7 @@ import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.RegularRequestResult @@ -49,7 +49,7 @@ class RegularRequestHandler(engine: Engine, esContext: EsContext, threadPool: ThreadPool) (implicit scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle[B <: BlockContext : BlockContextUpdater](request: RequestContext.Aux[B] with EsRequest[B]): Task[Unit] = { engine.core.accessControl @@ -85,7 +85,7 @@ class RegularRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(new Exception(ex)) } } @@ -99,7 +99,7 @@ class RegularRequestHandler(engine: Engine, case ModificationResult.ShouldBeInterrupted => onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case ModificationResult.CannotModify => - logger.error(s"[${request.id.toRequestId.show}] Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") + noRequestIdLogger.error(s"Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case CustomResponse(response) => respond(request, response) @@ -247,7 +247,7 @@ class RegularRequestHandler(engine: Engine, esContext.listener.onResponse(response) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } \ No newline at end of file diff --git a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala index f6db2b2f6e..7ad5f7b26d 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.index.query.{AbstractQueryBuilder, QueryBuilder, QueryBuilders} import org.elasticsearch.search.aggregations.AggregatorFactories @@ -40,7 +40,7 @@ import tech.beshu.ror.implicits.* import java.util.UUID import scala.jdk.CollectionConverters.* -object SearchRequestOps extends Logging { +object SearchRequestOps extends RequestIdAwareLogging { implicit class QueryBuilderOps(val builder: Option[QueryBuilder]) extends AnyVal { @@ -52,7 +52,7 @@ object SearchRequestOps extends Logging { val modifiedQuery: AbstractQueryBuilder[_] = provideNewQueryWithAppliedFilter(builder, filterQuery) Some(modifiedQuery) case None => - logger.debug(s"[${requestId.show}] No filter applied to query.") + logger.debug(s"No filter applied to query.") builder } } @@ -92,7 +92,7 @@ object SearchRequestOps extends Logging { case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, requestId) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) disableCaching(requestId) case BasedOnBlockContextOnly.NotAllowedFieldsUsed(notAllowedFields) => modifyNotAllowedFieldsInRequest(notAllowedFields) @@ -138,8 +138,8 @@ object SearchRequestOps extends Logging { } } - private def disableCaching(requestId: RequestContext.Id) = { - logger.debug(s"[${requestId.show}] ACL uses context header for fields rule, will disable request cache for SearchRequest") + private def disableCaching(implicit requestId: RequestContext.Id) = { + logger.debug(s"ACL uses context header for fields rule, will disable request cache for SearchRequest") request.requestCache(false) } } diff --git a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala index d04bc3a95e..16827af969 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala @@ -17,7 +17,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.action.{CompositeIndicesRequest, IndicesRequest} import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -32,7 +31,7 @@ import java.time.Instant abstract class BaseEsRequestContext[B <: BlockContext](esContext: EsContext, clusterService: RorClusterService) - extends RequestContext with Logging { + extends RequestContext { override type BLOCK_CONTEXT = B diff --git a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala index ae8abbe1f5..0ee2967364 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala @@ -18,7 +18,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -26,8 +25,9 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import scala.util.Try +import tech.beshu.ror.utils.RequestIdAwareLogging -trait EsRequest[B <: BlockContext] extends Logging { +trait EsRequest[B <: BlockContext] extends RequestIdAwareLogging { implicit def threadPool: ThreadPool final def modifyUsing(blockContext: B): ModificationResult = { @@ -35,7 +35,7 @@ trait EsRequest[B <: BlockContext] extends Logging { Try(modifyRequest(blockContext)) .fold( ex => { - logger.error(s"[${blockContext.requestContext.id.show}] Cannot modify request with filtered data", ex) + logger.error(s"Cannot modify request with filtered data", ex)(blockContext) ModificationResult.CannotModify }, identity diff --git a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala index c091179cb6..d150709314 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala @@ -85,7 +85,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: case Some(indices) => update(actionRequest, indices, blockContext.filter, blockContext.fieldLevelSecurity) case None => - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -101,7 +101,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } \ No newline at end of file diff --git a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala index 71d462de57..48014e1bdc 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala @@ -73,7 +73,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, } yield update(actionRequest, filteredIndices, allAllowedIndices) result.getOrElse { - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -86,7 +86,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } diff --git a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala index 95d882c3b5..f607c0e347 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala @@ -50,7 +50,7 @@ abstract class BaseRepositoriesEsRequestContext[R <: ActionRequest](actionReques case Some(repositories) => update(actionRequest, repositories) case None => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") ShouldBeInterrupted } } diff --git a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala index b3b1d66238..7ef0f32014 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala @@ -42,7 +42,7 @@ abstract class BaseSingleIndexEsRequestContext[R <: ActionRequest](actionRequest filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } update(request, filteredIndices.head) } diff --git a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala index b5ab70fe7a..c1b2e7ea27 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala @@ -62,7 +62,7 @@ class BulkEsRequestContext(actionRequest: BulkRequest, case (_, _) => ShouldBeInterrupted } } else { - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because origin request contained different " + + logger.error(s"Cannot alter MultiGetRequest request, because origin request contained different " + s"number of requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } @@ -90,18 +90,18 @@ class BulkEsRequestContext(actionRequest: BulkRequest, updateRequestWithIndices(request, nel) Modified case None => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because empty list of indices was found") + logger.error(s"Cannot alter MultiGetRequest request, because empty list of indices was found") ShouldBeInterrupted } case Indices.NotFound => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because no allowed indices were found") + logger.error(s"Cannot alter MultiGetRequest request, because no allowed indices were found") ShouldBeInterrupted } } private def updateRequestWithIndices(request: DocWriteRequest[_], indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } request.index(indices.head.stringify) } diff --git a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala index 75a75fcef5..96a043b298 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala @@ -53,14 +53,14 @@ class BulkShardEsRequestContext(actionRequest: BulkShardRequest, case Success(_) => Modified case Failure(ex) => - logger.error(s"[${id.show}] Cannot modify BulkShardRequest", ex) + logger.error(s"Cannot modify BulkShardRequest", ex) CannotModify } } private def tryUpdate(request: BulkShardRequest, indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } val singleIndex = indices.head val uuid = clusterService.indexOrAliasUuids(singleIndex.name).toList.head diff --git a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala index 65a168092a..158ac485a5 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala @@ -45,14 +45,14 @@ class ClusterAllocationExplainEsRequestContext(actionRequest: ClusterAllocationE getRequestedIndexFrom(request) match { case Some(_) => if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateIndexIn(request, filteredIndices.head) Modified case None if filteredIndices.exists(_.name === ClusterIndexName.Local.wildcard) => Modified case None => - logger.error(s"[${id.show}] Cluster allocation explain request without index name is unavailable when block contains `indices` rule") + logger.error(s"Cluster allocation explain request without index name is unavailable when block contains `indices` rule") ShouldBeInterrupted } } diff --git a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala index 24e15f40e8..b73c123699 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala @@ -69,7 +69,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, updateAliases(actionRequest, aliases) UpdateResponse.sync(updateAliasesResponse(aliases.includedOnly, _)) case None => - logger.error(s"[${id.show}] At least one alias and one index has to be allowed. " + + logger.error(s"At least one alias and one index has to be allowed. " + s"Found allowed indices: [${blockContext.indices.show}]." + s"Found allowed aliases: [${blockContext.aliases.show}]") ShouldBeInterrupted @@ -117,7 +117,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, .indices().asSafeSet .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } @@ -125,7 +125,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, val aliases = rawRequestAliasesSet(request) .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered aliases: ${aliases.show}") + logger.debug(s"Discovered aliases: ${aliases.show}") aliases } diff --git a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala index abb85d42b7..f9e2c87e53 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala @@ -55,7 +55,7 @@ class IndicesAliasesEsRequestContext(actionRequest: IndicesAliasesRequest, if (originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala index 05b70606b9..37dd50452b 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala @@ -119,7 +119,7 @@ class MultiGetEsRequestContext(actionRequest: MultiGetRequest, case Nil => updateItemWithNonExistingIndex(item) case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } item.index(index.stringify) } diff --git a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala index 989956d79a..9e13edee8d 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala @@ -78,7 +78,7 @@ class MultiSearchEsRequestContext(actionRequest: MultiSearchRequest, } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala index 9191e33b66..5a61356f48 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala @@ -47,7 +47,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { request.getRequests.removeIf { request => removeOrAlter(request, filteredIndices.toCovariantSet) } if (request.getRequests.asScala.isEmpty) { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") ShouldBeInterrupted } else { Modified @@ -63,7 +63,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, true case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") } request.index(index.stringify) false diff --git a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala index c411df93c5..c7b99f6e85 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala @@ -52,7 +52,7 @@ class PutRollupJobEsRequestContext private(actionRequest: ActionRequest, if(originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala index 141d9db788..fff8ed58bb 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala @@ -49,7 +49,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (tryUpdate(actionRequest, filteredIndices)) Modified else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") ShouldBeInterrupted } } diff --git a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala index 489d0187bc..c42dfc3b78 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala @@ -58,10 +58,10 @@ class ReindexEsRequestContext(actionRequest: ReindexRequest, Modified } else { if (!isDestinationIndexOnFilteredIndicesList) { - logger.info(s"[${id.show}] Destination index of _reindex request is forbidden") + logger.info(s"Destination index of _reindex request is forbidden") } if (!isSearchRequestComposedOnlyOfAllowedIndices) { - logger.info(s"[${id.show}] At least one index from sources indices list of _reindex request is forbidden") + logger.info(s"At least one index from sources indices list of _reindex request is forbidden") } ShouldBeInterrupted } diff --git a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala index ef15252808..837a487bd7 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala @@ -74,7 +74,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo request } case Left(_) => - logger.debug(s"[${id.show}] Cannot parse SQL statement - we can pass it though, because ES is going to reject it") + logger.debug(s"Cannot parse SQL statement - we can pass it though, because ES is going to reject it") request } } @@ -85,7 +85,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala index 44b7d78dfd..d09015139b 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CreateRepositoryEsRequestContext(actionRequest: PutRepositoryRequest, override protected def update(request: PutRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala index eaf9334872..0cf32e1bea 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class DeleteRepositoryEsRequestContext(actionRequest: DeleteRepositoryRequest, override protected def update(request: DeleteRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala index cee0bffd4c..d1410eff3d 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class VerifyRepositoryEsRequestContext(actionRequest: VerifyRepositoryRequest, override protected def update(request: VerifyRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala index ead4fcf250..20501516d5 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala @@ -68,32 +68,32 @@ class CreateSnapshotEsRequestContext(actionRequest: CreateSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala index 281a0d73f6..27b13ffa11 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala @@ -59,32 +59,32 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala index 58122fb44f..782a54d7df 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala @@ -69,7 +69,7 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, case r => r } case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -81,14 +81,14 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.mkString(",")}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.mkString(",")}]") } Right(repository) } diff --git a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala index 88887db96c..156deb5b80 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala @@ -63,7 +63,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -75,7 +75,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") } Right(snapshot) } @@ -88,7 +88,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala index 44ee8397ec..e522e440f1 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala @@ -100,12 +100,12 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { val repositories = blockContext.repositories if (allRepositoriesRequested(repositories)) { Right(RepositoryName.All) @@ -115,7 +115,7 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala index 368597ae85..48bf8ef31d 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.{GetIndexTemplatesRequest, GetIndexTemplatesResponse} import org.elasticsearch.cluster.metadata.{AliasMetaData, IndexTemplateMetaData} import org.elasticsearch.common.collect.ImmutableOpenMap @@ -105,7 +105,7 @@ class GetTemplatesEsRequestContext(actionRequest: GetIndexTemplatesRequest, } } -private[templates] object GetTemplatesEsRequestContext extends Logging { +private[templates] object GetTemplatesEsRequestContext extends RequestIdAwareLogging { def filter(templates: Iterable[IndexTemplateMetaData], usingTemplate: Set[Template] => Set[Template]) diff --git a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala index f26cb0a547..0cc64c4f79 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala @@ -82,7 +82,7 @@ class MultiSearchTemplateEsRequestContext private(actionRequest: ActionRequest w callSearchOnceAgain(blockContext.filter, blockContext.fieldLevelSecurity) ) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala index 622fe3dc33..051a5504fa 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.queries import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.index.query.* import org.joor.Reflect.on import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.RequestFieldsUsage @@ -30,7 +30,7 @@ trait QueryFieldsUsage[QUERY <: QueryBuilder] { def fieldsIn(query: QUERY): RequestFieldsUsage } -object QueryFieldsUsage extends Logging { +object QueryFieldsUsage extends RequestIdAwareLogging { def apply[QUERY <: QueryBuilder](implicit ev: QueryFieldsUsage[QUERY]): QueryFieldsUsage[QUERY] = ev implicit class Ops[QUERY <: QueryBuilder : QueryFieldsUsage](val query: QUERY) { @@ -61,7 +61,7 @@ object QueryFieldsUsage extends Logging { Option(on(query).call("getFieldName").get[String]) match { case Some(fieldName: String) => UsingFields(NonEmptyList.one(UsedField(fieldName))) case _ => - logger.debug(s"Cannot extract fields for terms set query") + noRequestIdLogger.debug(s"Cannot extract fields for terms set query") CannotExtractFields } } @@ -87,7 +87,7 @@ object QueryFieldsUsage extends Logging { case builder: TermsSetQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder: WildcardQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder => - logger.debug(s"Cannot extract fields for query: ${builder.getName}") + noRequestIdLogger.debug(s"Cannot extract fields for query: ${builder.getName}") CannotExtractFields } diff --git a/es67x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala b/es67x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala index 0998bb9a5b..b4671e9e4d 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.handler.response import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.FieldsRestrictions import tech.beshu.ror.accesscontrol.domain.Header @@ -26,17 +26,17 @@ import tech.beshu.ror.accesscontrol.headerValues.transientFieldsToHeaderValue import tech.beshu.ror.accesscontrol.request.RequestContext import tech.beshu.ror.implicits.* -object FLSContextHeaderHandler extends Logging { +object FLSContextHeaderHandler extends RequestIdAwareLogging { def addContextHeader(threadPool: ThreadPool, - fieldsRestrictions: FieldsRestrictions, - requestId: RequestContext.Id): Unit = { + fieldsRestrictions: FieldsRestrictions) + (implicit requestId: RequestContext.Id): Unit = { val threadContext = threadPool.getThreadContext val header = createContextHeader(fieldsRestrictions) Option(threadContext.getHeader(header.name.value.value)) match { case None => implicit val show = headerShow - logger.debug(s"[${requestId.show}] Adding thread context header required by lucene. Header: '${header.show}'") + logger.debug(s"Adding thread context header required by lucene. Header: '${header.show}'") threadContext.putHeader(header.name.value.value, header.value.value) case Some(_) => } diff --git a/es67x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala b/es67x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala index a6c3824699..8c61b9664c 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.support.WriteRequest.RefreshPolicy import org.elasticsearch.client.node.NodeClient @@ -38,7 +38,7 @@ import scala.jdk.CollectionConverters.* class EsIndexJsonContentService(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexJsonContentService - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -63,14 +63,14 @@ class EsIndexJsonContentService(client: NodeClient, Option(response.getSourceAsMap) match { case Some(map) => val source = map.asScala.toMap.asStringMap - logger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") Right(source) case None => - logger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") + noRequestIdLogger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") Right(Map.empty[String, String]) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(ContentNotFound) } } @@ -78,7 +78,7 @@ class EsIndexJsonContentService(client: NodeClient, .onErrorRecover { case _: ResourceNotFoundException => Left(ContentNotFound) case ex => - logger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) Left(CannotReachContentSource) } } @@ -105,14 +105,14 @@ class EsIndexJsonContentService(client: NodeClient, case status if status / 100 == 2 => Right(()) case status => - logger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") Left(CannotWriteToIndex) } } .executeOn(RorSchedulers.blockingScheduler) .onErrorRecover { case ex => - logger.error(s"Cannot write to document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]", ex) Left(CannotWriteToIndex) } } diff --git a/es67x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala b/es67x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala index dda63798df..a2fbc4fbf0 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala @@ -21,7 +21,7 @@ import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task import monix.execution.CancelablePromise -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import org.elasticsearch.action.admin.cluster.state.{ClusterStateRequest, ClusterStateResponse} import org.elasticsearch.action.search.{MultiSearchResponse, SearchRequestBuilder, SearchResponse} @@ -62,7 +62,7 @@ class EsServerBasedRorClusterService(nodeName: String, nodeClient: NodeClient, threadPool: ThreadPool) extends RorClusterService - with Logging { + with RequestIdAwareLogging { import EsServerBasedRorClusterService.* @@ -144,7 +144,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractAccessibilityFrom) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify get request. Blocking document", ex) + logger.error(s"Could not verify get request. Blocking document", ex)(id) Inaccessible } } @@ -156,7 +156,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractResultsFromSearchResponse) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify documents returned by multi get response. Blocking all returned documents", ex) + logger.error(s"Could not verify documents returned by multi get response. Blocking all returned documents", ex)(id) blockAllDocsReturned(documents) } .map(results => zip(results, documents)) @@ -205,7 +205,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService) = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -274,7 +274,7 @@ class EsServerBasedRorClusterService(nodeName: String, } } case None => - logger.error("Cannot supply Snapshots Service. Please, report the issue!!!") + noRequestIdLogger.error("Cannot supply Snapshots Service. Please, report the issue!!!") Task.now(Set.empty[Snapshot]) } } diff --git a/es67x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala b/es67x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala index a81accd72e..378d78c607 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es.services -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.DocWriteRequest import org.elasticsearch.action.bulk.{BackoffPolicy, BulkProcessor, BulkRequest, BulkResponse} import org.elasticsearch.action.index.IndexRequest @@ -31,7 +31,7 @@ import scala.annotation.nowarn final class NodeClientBasedAuditSinkService(client: NodeClient) extends IndexBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { @nowarn("msg=deprecated") private val bulkProcessor = @@ -63,25 +63,25 @@ final class NodeClientBasedAuditSinkService(client: NodeClient) private class AuditSinkBulkProcessorListener extends BulkProcessor.Listener { override def beforeBulk(executionId: Long, request: BulkRequest): Unit = { - logger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") + noRequestIdLogger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") } override def afterBulk(executionId: Long, request: BulkRequest, response: BulkResponse): Unit = { if (response.hasFailures) { - logger.error("Some failures flushing the BulkProcessor: ") + noRequestIdLogger.error("Some failures flushing the BulkProcessor: ") response .getItems.to(LazyList) .filter(_.isFailed) .map(_.getFailureMessage) .groupBy(identity) .foreach { case (message, stream) => - logger.error(s"${stream.size}x: $message") + noRequestIdLogger.error(s"${stream.size}x: $message") } } } override def afterBulk(executionId: Long, request: BulkRequest, failure: Throwable): Unit = { - logger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) + noRequestIdLogger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) } } diff --git a/es67x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala b/es67x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala index c1f9e8e7c9..f1bba6ea58 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala @@ -22,7 +22,7 @@ import org.apache.http.auth.{AuthScope, Credentials, UsernamePasswordCredentials import org.apache.http.conn.ssl.NoopHostnameVerifier import org.apache.http.impl.client.BasicCredentialsProvider import org.apache.http.impl.nio.client.HttpAsyncClientBuilder -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.* import org.elasticsearch.client.RestClient.FailureListener import tech.beshu.ror.accesscontrol.domain.AuditCluster.ClusterMode @@ -36,7 +36,7 @@ import scala.collection.parallel.CollectionConverters.* final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient]) extends IndexBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { override def submit(indexName: IndexName.Full, documentId: String, jsonRecord: String) (implicit requestId: RequestId): Unit = { @@ -72,19 +72,19 @@ final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient] override def onSuccess(response: Response): Unit = { response.getStatusLine.getStatusCode / 100 match { case 2 => // 2xx - logger.debug(s"[${requestId.show}] Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") + logger.debug(s"Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") case _ => - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") } } override def onFailure(ex: Exception): Unit = { - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId]", ex) + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId]", ex) } } } -object RestClientAuditSinkService extends Logging { +object RestClientAuditSinkService extends RequestIdAwareLogging { def create(remoteCluster: AuditCluster.RemoteAuditCluster): RestClientAuditSinkService = { remoteCluster.mode match { @@ -115,7 +115,7 @@ object RestClientAuditSinkService extends Logging { .setFailureListener( new FailureListener { override def onFailure(node: Node): Unit = { - logger.debug( + noRequestIdLogger.debug( s"[AUDIT] Node marked dead: ${node.getHost.getSchemeName}://${node.getHost.getHostName}:${node.getHost.getPort}. The client will attempt failover.", ) } diff --git a/es67x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala b/es67x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala index def1155990..af0ff87fb4 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.{Channel, ChannelHandlerContext} import io.netty.handler.ssl.NotSslRecordException -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.network.NetworkService import org.elasticsearch.common.settings.Settings import org.elasticsearch.common.util.BigArrays @@ -38,7 +38,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, ssl: ExternalSslConfiguration, fipsCompliant: Boolean) extends Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, ssl.clientAuthenticationEnabled) @@ -46,7 +46,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, override def exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable): Unit = { if (!this.lifecycle.started) return - else if (cause.getCause.isInstanceOf[NotSslRecordException]) logger.warn(s"${cause.getMessage} connecting from: ${ctx.channel().remoteAddress()}") + else if (cause.getCause.isInstanceOf[NotSslRecordException]) noRequestIdLogger.warn(s"${cause.getMessage} connecting from: ${ctx.channel().remoteAddress()}") else super.exceptionCaught(ctx, cause) ctx.channel().flush().close() } diff --git a/es67x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala b/es67x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala index 3ac42afd15..ee7a7cdd26 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.* import io.netty.handler.ssl.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.Version import org.elasticsearch.cluster.node.DiscoveryNode import org.elasticsearch.common.io.stream.NamedWriteableRegistry @@ -44,7 +44,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, ssl: InternodeSslConfiguration, fipsCompliant: Boolean) extends Netty4Transport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = SSLCertHelper.prepareClientSSLContext(ssl, fipsCompliant, ssl.certificateVerificationEnabled) private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, clientAuthenticationEnabled = false) @@ -75,7 +75,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, override def exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable): Unit = { if (cause.isInstanceOf[NotSslRecordException] || (cause.getCause != null && cause.getCause.isInstanceOf[NotSslRecordException])) { - logger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") + noRequestIdLogger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") ctx.channel.close } else { super.exceptionCaught(ctx, cause) diff --git a/es67x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala b/es67x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala index db1b336f69..f385b4ab45 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.utils import cats.Show import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.client.node.NodeClient import org.elasticsearch.common.settings.Settings @@ -36,7 +36,7 @@ import scala.util.Try class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandler, settings: Settings) - extends RestHandler with Logging { + extends RestHandler with RequestIdAwareLogging { private val wrapped = doPrivileged { wrapSomeActions(underlying) @@ -94,11 +94,11 @@ class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandle private def logError(error: AuthorizationValueError): Unit = { { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorSanitizedShow - logger.warn(s"The incoming request was malformed. Cause: ${error.show}") + noRequestIdLogger.warn(s"The incoming request was malformed. Cause: ${error.show}") } if (logger.delegate.isDebugEnabled()) { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorWithDetailsShow - logger.debug(s"Malformed request detailed cause: ${error.show}") + noRequestIdLogger.debug(s"Malformed request detailed cause: ${error.show}") } } diff --git a/es67x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala b/es67x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala index 5ab1e35742..c1c66d1b7b 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala @@ -16,13 +16,13 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.common.settings.Settings import tech.beshu.ror.tools.core.patches.PatchingVerifier import tech.beshu.ror.tools.core.patches.PatchingVerifier.Error.{CannotVerifyIfPatched, EsNotPatched} import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged +import tech.beshu.ror.utils.RequestIdAwareLogging -object EsPatchVerifier extends Logging { +object EsPatchVerifier extends RequestIdAwareLogging { def verify(settings: Settings): Unit = doPrivileged { pathHomeFrom(settings).flatMap(PatchingVerifier.verify) match { @@ -30,7 +30,7 @@ object EsPatchVerifier extends Logging { case Left(e@EsNotPatched(_)) => throw new IllegalStateException(e.message) case Left(e@CannotVerifyIfPatched(_)) => - logger.warn(e.message) + noRequestIdLogger.warn(e.message) } } diff --git a/es70x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es70x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index 6678bb7ee0..5c135fd766 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.support.{ActionFilter, ActionFilterChain} import org.elasticsearch.action.{ActionListener, ActionRequest, ActionResponse} import org.elasticsearch.client.node.NodeClient @@ -60,7 +60,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, rorEsConfig: ReadonlyRestEsConfig) (implicit environmentConfig: EnvironmentConfig) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = environmentConfig.uniqueIdentifierGenerator @@ -201,12 +201,12 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def handleRorNotReadyYet(esContext: EsContext): Unit = { - logger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") + noRequestIdLogger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") rorNotAvailableRequestHandler.handleRorNotReadyYet(esContext) } private def handleRorFailedToStart(esContext: EsContext): Unit = { - logger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") + noRequestIdLogger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") rorNotAvailableRequestHandler.handleRorFailedToStart(esContext) } @@ -228,7 +228,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def logAndSetStartingFailureState(failure: StartingFailure): Unit = { - logger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) + noRequestIdLogger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) rorInstanceState.set(RorInstanceStartingState.NotStarted(failure)) } } diff --git a/es70x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala b/es70x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala index 7f92461f08..72c14bf252 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.xcontent.cbor.CborXContent import org.elasticsearch.common.xcontent.json.JsonXContent import org.elasticsearch.common.xcontent.smile.SmileXContent @@ -29,7 +29,7 @@ import tech.beshu.ror.accesscontrol.domain.ResponseFieldsFiltering.{AccessMode, import scala.jdk.CollectionConverters.* trait ResponseFieldsFiltering { - this: Logging => + this: RequestIdAwareLogging => private val responseFieldsRestrictions: Atomic[Option[ResponseFieldsRestrictions]] = Atomic(None: Option[ResponseFieldsRestrictions]) @@ -44,7 +44,7 @@ trait ResponseFieldsFiltering { case bytesRestResponse: BytesRestResponse => filterBytesRestResponse(bytesRestResponse, fieldsRestrictions) case otherResponse => - logger.warn("ResponseFields filtering is unavailable for this type of request") + noRequestIdLogger.warn("ResponseFields filtering is unavailable for this type of request") otherResponse } case None => diff --git a/es70x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala b/es70x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala index 0f26750588..da95de59a4 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.action.{ActionListener, ActionResponse} import org.elasticsearch.threadpool.ThreadPool @@ -37,7 +37,7 @@ sealed abstract class RorActionListener[T](val underlying: ActionListener[T]) ex final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionListener[T], correlationId: Eval[CorrelationId]) - extends RorActionListener[T](underlying) with Logging { + extends RorActionListener[T](underlying) with RequestIdAwareLogging { override def onFailure(e: Exception): Unit = { super.onFailure(adaptExceptionIfNeeded(e)) @@ -47,7 +47,7 @@ final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionLis ex match { case esException: ElasticsearchException => esException case other => - logger.error(s"[${correlationId.value.show}] Internal error.", other) + noRequestIdLogger.error(s"[${correlationId.value.show}] Internal error.", other) new ElasticsearchException(s"[${correlationId.value.show}] Internal error. See logs for details.") } } diff --git a/es70x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala b/es70x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala index 0a80ad8a51..09e707bd3e 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.http.HttpChannel import org.elasticsearch.rest.{AbstractRestChannel, RestChannel as EsRestChannel, RestRequest as EsRestRequest, RestResponse as EsRestResponse} import squants.information.{Bytes, Information} @@ -40,7 +40,7 @@ object RorRestChannel { final class RorRestChannel private(underlying: EsRestChannel, val restRequest: RorRestRequest) extends AbstractRestChannel(underlying.request(), true) with ResponseFieldsFiltering - with Logging { + with RequestIdAwareLogging { override def sendResponse(response: EsRestResponse): Unit = { ThreadRepo.removeRestChannel(this) diff --git a/es70x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala b/es70x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala index 6babc712b9..3c80750a25 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala @@ -18,16 +18,15 @@ package tech.beshu.ror.es.actions.rradmin import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.ConfigApi.ConfigResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAdminActionHandler extends Logging { +class RRAdminActionHandler extends RequestIdAwareLogging { private implicit val adminRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +51,7 @@ class RRAdminActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAdminResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAdminAction internal error", ex) + logger.error("RRAdminAction internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es70x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala b/es70x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala index c55835a1d0..ce45c6f48e 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala @@ -16,18 +16,15 @@ */ package tech.beshu.ror.es.actions.rrauthmock -import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.AuthMockApi.AuthMockResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier -import tech.beshu.ror.implicits.* +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAuthMockActionHandler extends Logging { +class RRAuthMockActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -53,7 +50,7 @@ class RRAuthMockActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAuthMockResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAuthMock internal error", ex) + logger.error("RRAuthMock internal error", ex) listener.onFailure(new Exception(ex)) } } diff --git a/es70x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala b/es70x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala index aa8bb31e67..640084c4ec 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestconfig import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.TestConfigApi.TestConfigResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestConfigActionHandler extends Logging { +class RRTestConfigActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +52,7 @@ class RRTestConfigActionHandler extends Logging { case Right(response) => listener.onResponse(new RRTestConfigResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRTestConfig internal error", ex) + logger.error(s"RRTestConfig internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es70x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala b/es70x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala index 09112e0537..12e6a79dc9 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.dlsfls import cats.data.StateT import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.DirectoryReader import org.elasticsearch.common.util.concurrent.ThreadContext import org.elasticsearch.index.IndexService @@ -29,7 +29,7 @@ import tech.beshu.ror.accesscontrol.headerValues.transientFieldsFromHeaderValue import scala.util.{Failure, Success, Try} -class RoleIndexSearcherWrapper(indexService: IndexService) extends IndexSearcherWrapper with Logging { +class RoleIndexSearcherWrapper(indexService: IndexService) extends IndexSearcherWrapper with RequestIdAwareLogging { override def wrap(reader: DirectoryReader): DirectoryReader = { val threadContext: ThreadContext = indexService.getThreadPool.getThreadContext @@ -48,7 +48,7 @@ class RoleIndexSearcherWrapper(indexService: IndexService) extends IndexSearcher } .map(r => (r, r)) case None => - logger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") + noRequestIdLogger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") Success((reader, reader)) } } @@ -60,13 +60,13 @@ class RoleIndexSearcherWrapper(indexService: IndexService) extends IndexSearcher nel <- NonEmptyString.from(value) match { case Right(nel) => Success(nel) case Left(_) => - logger.debug("FLS: empty header value") + noRequestIdLogger.debug("FLS: empty header value") failure } fields <- transientFieldsFromHeaderValue.fromRawValue(nel) match { case result@Success(_) => result case Failure(ex) => - logger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) + noRequestIdLogger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) failure } } yield fields diff --git a/es70x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala b/es70x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala index 85f92af263..a98c7a1067 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.dlsfls import java.io.ByteArrayOutputStream import java.util.{Iterator => JavaIterator} import com.google.common.collect.Iterators -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.StoredFieldVisitor.Status import org.apache.lucene.index.* import org.apache.lucene.util.Bits @@ -36,21 +36,21 @@ import scala.jdk.CollectionConverters.* import scala.util.Try private class RorDocumentFieldReader(reader: LeafReader, fieldsRestrictions: FieldsRestrictions) - extends FilterLeafReader(reader) with Logging { + extends FilterLeafReader(reader) with RequestIdAwareLogging { private val policy = new FieldsPolicy(fieldsRestrictions) private val remainingFieldsInfo = { val fInfos = in.getFieldInfos val newInfos = if (fInfos.asScala.isEmpty) { - logger.warn("original fields were empty! This is weird!") + noRequestIdLogger.warn("original fields were empty! This is weird!") fInfos } else { val remainingFields = fInfos.asScala.filter(f => policy.canKeep(f.name)).toSet new FieldInfos(remainingFields.toArray) } - logger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") - logger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") - logger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") + noRequestIdLogger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") newInfos } private val jsonPolicyBasedFilterer = new JsonPolicyBasedFilterer(policy) diff --git a/es70x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala b/es70x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala index 15f2544476..42e0b270c0 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.* import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest @@ -84,7 +84,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, threadPool: ThreadPool) (implicit generator: UniqueIdentifierGenerator, scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle(engines: Engines, esContext: EsContext): Task[Either[Error, Unit]] = { @@ -204,7 +204,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, case SearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case MultiSearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case _ => - logger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") + noRequestIdLogger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") regularRequestHandler.handle(new DummyCompositeIndicesEsRequestContext(request, esContext, aclContext, clusterService, threadPool)) } // rest diff --git a/es70x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala b/es70x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala index a388bb0f9f..57be14c040 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.common.io.stream.StreamOutput import org.elasticsearch.common.xcontent.{ToXContent, ToXContentObject, XContentBuilder} @@ -45,7 +45,7 @@ import scala.util.{Failure, Success, Try} class CurrentUserMetadataRequestHandler(engine: Engine, esContext: EsContext) - extends Logging { + extends RequestIdAwareLogging { def handle(request: RequestContext.Aux[CurrentUserMetadataRequestBlockContext] with EsRequest[CurrentUserMetadataRequestBlockContext]): Task[Unit] = { engine.core.accessControl @@ -69,7 +69,7 @@ class CurrentUserMetadataRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(ex.asInstanceOf[Exception]) } } @@ -86,13 +86,13 @@ class CurrentUserMetadataRequestHandler(engine: Engine, )) } - private def onPassThrough(requestContext: RequestContext): Unit = { - logger.warn(s"[${requestContext.id.toRequestId.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") + private def onPassThrough(implicit requestContext: RequestContext): Unit = { + logger.warn(s"Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") esContext.listener.onFailure(createRorNotEnabledResponse()) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } diff --git a/es70x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala b/es70x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala index 2fb01dcc41..c5c44fda92 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala @@ -20,7 +20,7 @@ import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.RegularRequestResult @@ -49,7 +49,7 @@ class RegularRequestHandler(engine: Engine, esContext: EsContext, threadPool: ThreadPool) (implicit scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle[B <: BlockContext : BlockContextUpdater](request: RequestContext.Aux[B] with EsRequest[B]): Task[Unit] = { engine.core.accessControl @@ -85,7 +85,7 @@ class RegularRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(new Exception(ex)) } } @@ -99,7 +99,7 @@ class RegularRequestHandler(engine: Engine, case ModificationResult.ShouldBeInterrupted => onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case ModificationResult.CannotModify => - logger.error(s"[${request.id.toRequestId.show}] Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") + noRequestIdLogger.error(s"Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case CustomResponse(response) => respond(request, response) @@ -247,7 +247,7 @@ class RegularRequestHandler(engine: Engine, esContext.listener.onResponse(response) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } \ No newline at end of file diff --git a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala index f6db2b2f6e..7ad5f7b26d 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.index.query.{AbstractQueryBuilder, QueryBuilder, QueryBuilders} import org.elasticsearch.search.aggregations.AggregatorFactories @@ -40,7 +40,7 @@ import tech.beshu.ror.implicits.* import java.util.UUID import scala.jdk.CollectionConverters.* -object SearchRequestOps extends Logging { +object SearchRequestOps extends RequestIdAwareLogging { implicit class QueryBuilderOps(val builder: Option[QueryBuilder]) extends AnyVal { @@ -52,7 +52,7 @@ object SearchRequestOps extends Logging { val modifiedQuery: AbstractQueryBuilder[_] = provideNewQueryWithAppliedFilter(builder, filterQuery) Some(modifiedQuery) case None => - logger.debug(s"[${requestId.show}] No filter applied to query.") + logger.debug(s"No filter applied to query.") builder } } @@ -92,7 +92,7 @@ object SearchRequestOps extends Logging { case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, requestId) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) disableCaching(requestId) case BasedOnBlockContextOnly.NotAllowedFieldsUsed(notAllowedFields) => modifyNotAllowedFieldsInRequest(notAllowedFields) @@ -138,8 +138,8 @@ object SearchRequestOps extends Logging { } } - private def disableCaching(requestId: RequestContext.Id) = { - logger.debug(s"[${requestId.show}] ACL uses context header for fields rule, will disable request cache for SearchRequest") + private def disableCaching(implicit requestId: RequestContext.Id) = { + logger.debug(s"ACL uses context header for fields rule, will disable request cache for SearchRequest") request.requestCache(false) } } diff --git a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala index d04bc3a95e..16827af969 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala @@ -17,7 +17,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.action.{CompositeIndicesRequest, IndicesRequest} import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -32,7 +31,7 @@ import java.time.Instant abstract class BaseEsRequestContext[B <: BlockContext](esContext: EsContext, clusterService: RorClusterService) - extends RequestContext with Logging { + extends RequestContext { override type BLOCK_CONTEXT = B diff --git a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala index ae8abbe1f5..0ee2967364 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala @@ -18,7 +18,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -26,8 +25,9 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import scala.util.Try +import tech.beshu.ror.utils.RequestIdAwareLogging -trait EsRequest[B <: BlockContext] extends Logging { +trait EsRequest[B <: BlockContext] extends RequestIdAwareLogging { implicit def threadPool: ThreadPool final def modifyUsing(blockContext: B): ModificationResult = { @@ -35,7 +35,7 @@ trait EsRequest[B <: BlockContext] extends Logging { Try(modifyRequest(blockContext)) .fold( ex => { - logger.error(s"[${blockContext.requestContext.id.show}] Cannot modify request with filtered data", ex) + logger.error(s"Cannot modify request with filtered data", ex)(blockContext) ModificationResult.CannotModify }, identity diff --git a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala index c091179cb6..d150709314 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala @@ -85,7 +85,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: case Some(indices) => update(actionRequest, indices, blockContext.filter, blockContext.fieldLevelSecurity) case None => - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -101,7 +101,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } \ No newline at end of file diff --git a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala index 71d462de57..48014e1bdc 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala @@ -73,7 +73,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, } yield update(actionRequest, filteredIndices, allAllowedIndices) result.getOrElse { - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -86,7 +86,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } diff --git a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala index 95d882c3b5..f607c0e347 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala @@ -50,7 +50,7 @@ abstract class BaseRepositoriesEsRequestContext[R <: ActionRequest](actionReques case Some(repositories) => update(actionRequest, repositories) case None => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") ShouldBeInterrupted } } diff --git a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala index b3b1d66238..7ef0f32014 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala @@ -42,7 +42,7 @@ abstract class BaseSingleIndexEsRequestContext[R <: ActionRequest](actionRequest filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } update(request, filteredIndices.head) } diff --git a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala index b5ab70fe7a..c1b2e7ea27 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala @@ -62,7 +62,7 @@ class BulkEsRequestContext(actionRequest: BulkRequest, case (_, _) => ShouldBeInterrupted } } else { - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because origin request contained different " + + logger.error(s"Cannot alter MultiGetRequest request, because origin request contained different " + s"number of requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } @@ -90,18 +90,18 @@ class BulkEsRequestContext(actionRequest: BulkRequest, updateRequestWithIndices(request, nel) Modified case None => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because empty list of indices was found") + logger.error(s"Cannot alter MultiGetRequest request, because empty list of indices was found") ShouldBeInterrupted } case Indices.NotFound => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because no allowed indices were found") + logger.error(s"Cannot alter MultiGetRequest request, because no allowed indices were found") ShouldBeInterrupted } } private def updateRequestWithIndices(request: DocWriteRequest[_], indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } request.index(indices.head.stringify) } diff --git a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala index 75a75fcef5..96a043b298 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala @@ -53,14 +53,14 @@ class BulkShardEsRequestContext(actionRequest: BulkShardRequest, case Success(_) => Modified case Failure(ex) => - logger.error(s"[${id.show}] Cannot modify BulkShardRequest", ex) + logger.error(s"Cannot modify BulkShardRequest", ex) CannotModify } } private def tryUpdate(request: BulkShardRequest, indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } val singleIndex = indices.head val uuid = clusterService.indexOrAliasUuids(singleIndex.name).toList.head diff --git a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala index 65a168092a..158ac485a5 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala @@ -45,14 +45,14 @@ class ClusterAllocationExplainEsRequestContext(actionRequest: ClusterAllocationE getRequestedIndexFrom(request) match { case Some(_) => if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateIndexIn(request, filteredIndices.head) Modified case None if filteredIndices.exists(_.name === ClusterIndexName.Local.wildcard) => Modified case None => - logger.error(s"[${id.show}] Cluster allocation explain request without index name is unavailable when block contains `indices` rule") + logger.error(s"Cluster allocation explain request without index name is unavailable when block contains `indices` rule") ShouldBeInterrupted } } diff --git a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala index 24e15f40e8..b73c123699 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala @@ -69,7 +69,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, updateAliases(actionRequest, aliases) UpdateResponse.sync(updateAliasesResponse(aliases.includedOnly, _)) case None => - logger.error(s"[${id.show}] At least one alias and one index has to be allowed. " + + logger.error(s"At least one alias and one index has to be allowed. " + s"Found allowed indices: [${blockContext.indices.show}]." + s"Found allowed aliases: [${blockContext.aliases.show}]") ShouldBeInterrupted @@ -117,7 +117,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, .indices().asSafeSet .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } @@ -125,7 +125,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, val aliases = rawRequestAliasesSet(request) .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered aliases: ${aliases.show}") + logger.debug(s"Discovered aliases: ${aliases.show}") aliases } diff --git a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala index abb85d42b7..f9e2c87e53 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala @@ -55,7 +55,7 @@ class IndicesAliasesEsRequestContext(actionRequest: IndicesAliasesRequest, if (originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala index 05b70606b9..37dd50452b 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala @@ -119,7 +119,7 @@ class MultiGetEsRequestContext(actionRequest: MultiGetRequest, case Nil => updateItemWithNonExistingIndex(item) case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } item.index(index.stringify) } diff --git a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala index 989956d79a..9e13edee8d 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala @@ -78,7 +78,7 @@ class MultiSearchEsRequestContext(actionRequest: MultiSearchRequest, } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala index 9191e33b66..5a61356f48 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala @@ -47,7 +47,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { request.getRequests.removeIf { request => removeOrAlter(request, filteredIndices.toCovariantSet) } if (request.getRequests.asScala.isEmpty) { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") ShouldBeInterrupted } else { Modified @@ -63,7 +63,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, true case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") } request.index(index.stringify) false diff --git a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala index c411df93c5..c7b99f6e85 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala @@ -52,7 +52,7 @@ class PutRollupJobEsRequestContext private(actionRequest: ActionRequest, if(originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala index 141d9db788..fff8ed58bb 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala @@ -49,7 +49,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (tryUpdate(actionRequest, filteredIndices)) Modified else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") ShouldBeInterrupted } } diff --git a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala index 489d0187bc..c42dfc3b78 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala @@ -58,10 +58,10 @@ class ReindexEsRequestContext(actionRequest: ReindexRequest, Modified } else { if (!isDestinationIndexOnFilteredIndicesList) { - logger.info(s"[${id.show}] Destination index of _reindex request is forbidden") + logger.info(s"Destination index of _reindex request is forbidden") } if (!isSearchRequestComposedOnlyOfAllowedIndices) { - logger.info(s"[${id.show}] At least one index from sources indices list of _reindex request is forbidden") + logger.info(s"At least one index from sources indices list of _reindex request is forbidden") } ShouldBeInterrupted } diff --git a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala index 2c1b0014e0..97b8ccd9c5 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala @@ -74,7 +74,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo request } case Left(_) => - logger.debug(s"[${id.show}] Cannot parse SQL statement - we can pass it though, because ES is going to reject it") + logger.debug(s"Cannot parse SQL statement - we can pass it though, because ES is going to reject it") request } } @@ -85,7 +85,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala index 44b7d78dfd..d09015139b 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CreateRepositoryEsRequestContext(actionRequest: PutRepositoryRequest, override protected def update(request: PutRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala index eaf9334872..0cf32e1bea 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class DeleteRepositoryEsRequestContext(actionRequest: DeleteRepositoryRequest, override protected def update(request: DeleteRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala index cee0bffd4c..d1410eff3d 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class VerifyRepositoryEsRequestContext(actionRequest: VerifyRepositoryRequest, override protected def update(request: VerifyRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala index ead4fcf250..20501516d5 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala @@ -68,32 +68,32 @@ class CreateSnapshotEsRequestContext(actionRequest: CreateSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala index 281a0d73f6..27b13ffa11 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala @@ -59,32 +59,32 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala index 58122fb44f..782a54d7df 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala @@ -69,7 +69,7 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, case r => r } case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -81,14 +81,14 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.mkString(",")}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.mkString(",")}]") } Right(repository) } diff --git a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala index 88887db96c..156deb5b80 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala @@ -63,7 +63,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -75,7 +75,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") } Right(snapshot) } @@ -88,7 +88,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala index 44ee8397ec..e522e440f1 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala @@ -100,12 +100,12 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { val repositories = blockContext.repositories if (allRepositoriesRequested(repositories)) { Right(RepositoryName.All) @@ -115,7 +115,7 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala index 0bdf0ce63d..243d0dff91 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.{GetIndexTemplatesRequest, GetIndexTemplatesResponse} import org.elasticsearch.cluster.metadata.{AliasMetaData, IndexTemplateMetaData} import org.elasticsearch.common.collect.ImmutableOpenMap @@ -100,7 +100,7 @@ class GetTemplatesEsRequestContext(actionRequest: GetIndexTemplatesRequest, } -private[templates] object GetTemplatesEsRequestContext extends Logging { +private[templates] object GetTemplatesEsRequestContext extends RequestIdAwareLogging { def filter(templates: Iterable[IndexTemplateMetaData], usingTemplate: Set[Template] => Set[Template]) diff --git a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala index f26cb0a547..0cc64c4f79 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala @@ -82,7 +82,7 @@ class MultiSearchTemplateEsRequestContext private(actionRequest: ActionRequest w callSearchOnceAgain(blockContext.filter, blockContext.fieldLevelSecurity) ) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala index 622fe3dc33..051a5504fa 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.queries import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.index.query.* import org.joor.Reflect.on import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.RequestFieldsUsage @@ -30,7 +30,7 @@ trait QueryFieldsUsage[QUERY <: QueryBuilder] { def fieldsIn(query: QUERY): RequestFieldsUsage } -object QueryFieldsUsage extends Logging { +object QueryFieldsUsage extends RequestIdAwareLogging { def apply[QUERY <: QueryBuilder](implicit ev: QueryFieldsUsage[QUERY]): QueryFieldsUsage[QUERY] = ev implicit class Ops[QUERY <: QueryBuilder : QueryFieldsUsage](val query: QUERY) { @@ -61,7 +61,7 @@ object QueryFieldsUsage extends Logging { Option(on(query).call("getFieldName").get[String]) match { case Some(fieldName: String) => UsingFields(NonEmptyList.one(UsedField(fieldName))) case _ => - logger.debug(s"Cannot extract fields for terms set query") + noRequestIdLogger.debug(s"Cannot extract fields for terms set query") CannotExtractFields } } @@ -87,7 +87,7 @@ object QueryFieldsUsage extends Logging { case builder: TermsSetQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder: WildcardQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder => - logger.debug(s"Cannot extract fields for query: ${builder.getName}") + noRequestIdLogger.debug(s"Cannot extract fields for query: ${builder.getName}") CannotExtractFields } diff --git a/es70x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala b/es70x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala index 0998bb9a5b..b4671e9e4d 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.handler.response import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.FieldsRestrictions import tech.beshu.ror.accesscontrol.domain.Header @@ -26,17 +26,17 @@ import tech.beshu.ror.accesscontrol.headerValues.transientFieldsToHeaderValue import tech.beshu.ror.accesscontrol.request.RequestContext import tech.beshu.ror.implicits.* -object FLSContextHeaderHandler extends Logging { +object FLSContextHeaderHandler extends RequestIdAwareLogging { def addContextHeader(threadPool: ThreadPool, - fieldsRestrictions: FieldsRestrictions, - requestId: RequestContext.Id): Unit = { + fieldsRestrictions: FieldsRestrictions) + (implicit requestId: RequestContext.Id): Unit = { val threadContext = threadPool.getThreadContext val header = createContextHeader(fieldsRestrictions) Option(threadContext.getHeader(header.name.value.value)) match { case None => implicit val show = headerShow - logger.debug(s"[${requestId.show}] Adding thread context header required by lucene. Header: '${header.show}'") + logger.debug(s"Adding thread context header required by lucene. Header: '${header.show}'") threadContext.putHeader(header.name.value.value, header.value.value) case Some(_) => } diff --git a/es70x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala b/es70x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala index 18490a232c..b65ba21df7 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.support.WriteRequest.RefreshPolicy import org.elasticsearch.client.node.NodeClient @@ -38,7 +38,7 @@ import scala.jdk.CollectionConverters.* class EsIndexJsonContentService(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexJsonContentService - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -63,14 +63,14 @@ class EsIndexJsonContentService(client: NodeClient, Option(response.getSourceAsMap) match { case Some(map) => val source = map.asScala.toMap.asStringMap - logger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") Right(source) case None => - logger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") + noRequestIdLogger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") Right(Map.empty[String, String]) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(ContentNotFound) } } @@ -78,7 +78,7 @@ class EsIndexJsonContentService(client: NodeClient, .onErrorRecover { case _: ResourceNotFoundException => Left(ContentNotFound) case ex => - logger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) Left(CannotReachContentSource) } } @@ -104,14 +104,14 @@ class EsIndexJsonContentService(client: NodeClient, case status if status / 100 == 2 => Right(()) case status => - logger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") Left(CannotWriteToIndex) } } .executeOn(RorSchedulers.blockingScheduler) .onErrorRecover { case ex => - logger.error(s"Cannot write to document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]", ex) Left(CannotWriteToIndex) } } diff --git a/es70x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala b/es70x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala index 08ef262c0b..fbb72b4b13 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala @@ -21,7 +21,7 @@ import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task import monix.execution.CancelablePromise -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import org.elasticsearch.action.admin.cluster.state.{ClusterStateRequest, ClusterStateResponse} import org.elasticsearch.action.search.{MultiSearchResponse, SearchRequestBuilder, SearchResponse} @@ -62,7 +62,7 @@ class EsServerBasedRorClusterService(nodeName: String, nodeClient: NodeClient, threadPool: ThreadPool) extends RorClusterService - with Logging { + with RequestIdAwareLogging { import EsServerBasedRorClusterService.* @@ -144,7 +144,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractAccessibilityFrom) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify get request. Blocking document", ex) + logger.error(s"Could not verify get request. Blocking document", ex)(id) Inaccessible } } @@ -156,7 +156,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractResultsFromSearchResponse) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify documents returned by multi get response. Blocking all returned documents", ex) + logger.error(s"Could not verify documents returned by multi get response. Blocking all returned documents", ex)(id) blockAllDocsReturned(documents) } .map(results => zip(results, documents)) @@ -202,7 +202,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService) = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -271,7 +271,7 @@ class EsServerBasedRorClusterService(nodeName: String, } } case None => - logger.error("Cannot supply Snapshots Service. Please, report the issue!!!") + noRequestIdLogger.error("Cannot supply Snapshots Service. Please, report the issue!!!") Task.now(Set.empty[Snapshot]) } } diff --git a/es70x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala b/es70x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala index a85df473af..85e03005d3 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es.services -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.DocWriteRequest import org.elasticsearch.action.bulk.{BackoffPolicy, BulkProcessor, BulkRequest, BulkResponse} import org.elasticsearch.action.index.IndexRequest @@ -29,7 +29,7 @@ import tech.beshu.ror.es.IndexBasedAuditSinkService final class NodeClientBasedAuditSinkService(client: NodeClient) extends IndexBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { private val bulkProcessor = BulkProcessor @@ -61,25 +61,25 @@ final class NodeClientBasedAuditSinkService(client: NodeClient) private class AuditSinkBulkProcessorListener extends BulkProcessor.Listener { override def beforeBulk(executionId: Long, request: BulkRequest): Unit = { - logger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") + noRequestIdLogger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") } override def afterBulk(executionId: Long, request: BulkRequest, response: BulkResponse): Unit = { if (response.hasFailures) { - logger.error("Some failures flushing the BulkProcessor: ") + noRequestIdLogger.error("Some failures flushing the BulkProcessor: ") response .getItems.to(LazyList) .filter(_.isFailed) .map(_.getFailureMessage) .groupBy(identity) .foreach { case (message, stream) => - logger.error(s"${stream.size}x: $message") + noRequestIdLogger.error(s"${stream.size}x: $message") } } } override def afterBulk(executionId: Long, request: BulkRequest, failure: Throwable): Unit = { - logger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) + noRequestIdLogger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) } } diff --git a/es70x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala b/es70x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala index 6c627ede96..c6a4e6124d 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala @@ -22,7 +22,7 @@ import org.apache.http.auth.{AuthScope, Credentials, UsernamePasswordCredentials import org.apache.http.conn.ssl.NoopHostnameVerifier import org.apache.http.impl.client.BasicCredentialsProvider import org.apache.http.impl.nio.client.HttpAsyncClientBuilder -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.* import org.elasticsearch.client.RestClient.FailureListener import tech.beshu.ror.accesscontrol.domain.AuditCluster.ClusterMode @@ -36,7 +36,7 @@ import scala.collection.parallel.CollectionConverters.* final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient]) extends IndexBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { override def submit(indexName: IndexName.Full, documentId: String, jsonRecord: String) (implicit requestId: RequestId): Unit = { @@ -70,19 +70,19 @@ final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient] override def onSuccess(response: Response): Unit = { response.getStatusLine.getStatusCode / 100 match { case 2 => // 2xx - logger.debug(s"[${requestId.show}] Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") + logger.debug(s"Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") case _ => - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") } } override def onFailure(ex: Exception): Unit = { - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId]", ex) + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId]", ex) } } } -object RestClientAuditSinkService extends Logging { +object RestClientAuditSinkService extends RequestIdAwareLogging { def create(remoteCluster: AuditCluster.RemoteAuditCluster): RestClientAuditSinkService = { remoteCluster.mode match { @@ -113,7 +113,7 @@ object RestClientAuditSinkService extends Logging { .setFailureListener( new FailureListener { override def onFailure(node: Node): Unit = { - logger.debug( + noRequestIdLogger.debug( s"[AUDIT] Node marked dead: ${node.getHost.getSchemeName}://${node.getHost.getHostName}:${node.getHost.getPort}. The client will attempt failover.", ) } diff --git a/es70x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala b/es70x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala index f3b70cb4ae..52f09127b7 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.Channel import io.netty.handler.ssl.NotSslRecordException -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.network.NetworkService import org.elasticsearch.common.settings.Settings import org.elasticsearch.common.util.BigArrays @@ -38,7 +38,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, ssl: ExternalSslConfiguration, fipsCompliant: Boolean) extends Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, ssl.clientAuthenticationEnabled) @@ -46,7 +46,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, override def onException(channel: HttpChannel, cause: Exception): Unit = { if (!this.lifecycle.started) return - else if (cause.getCause.isInstanceOf[NotSslRecordException]) logger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) + else if (cause.getCause.isInstanceOf[NotSslRecordException]) noRequestIdLogger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) else super.onException(channel, cause) channel.close() } diff --git a/es70x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala b/es70x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala index 3ac42afd15..ee7a7cdd26 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.* import io.netty.handler.ssl.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.Version import org.elasticsearch.cluster.node.DiscoveryNode import org.elasticsearch.common.io.stream.NamedWriteableRegistry @@ -44,7 +44,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, ssl: InternodeSslConfiguration, fipsCompliant: Boolean) extends Netty4Transport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = SSLCertHelper.prepareClientSSLContext(ssl, fipsCompliant, ssl.certificateVerificationEnabled) private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, clientAuthenticationEnabled = false) @@ -75,7 +75,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, override def exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable): Unit = { if (cause.isInstanceOf[NotSslRecordException] || (cause.getCause != null && cause.getCause.isInstanceOf[NotSslRecordException])) { - logger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") + noRequestIdLogger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") ctx.channel.close } else { super.exceptionCaught(ctx, cause) diff --git a/es70x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala b/es70x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala index db1b336f69..f385b4ab45 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.utils import cats.Show import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.client.node.NodeClient import org.elasticsearch.common.settings.Settings @@ -36,7 +36,7 @@ import scala.util.Try class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandler, settings: Settings) - extends RestHandler with Logging { + extends RestHandler with RequestIdAwareLogging { private val wrapped = doPrivileged { wrapSomeActions(underlying) @@ -94,11 +94,11 @@ class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandle private def logError(error: AuthorizationValueError): Unit = { { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorSanitizedShow - logger.warn(s"The incoming request was malformed. Cause: ${error.show}") + noRequestIdLogger.warn(s"The incoming request was malformed. Cause: ${error.show}") } if (logger.delegate.isDebugEnabled()) { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorWithDetailsShow - logger.debug(s"Malformed request detailed cause: ${error.show}") + noRequestIdLogger.debug(s"Malformed request detailed cause: ${error.show}") } } diff --git a/es70x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala b/es70x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala index 5ab1e35742..a9af8f710a 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala @@ -16,13 +16,13 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.settings.Settings import tech.beshu.ror.tools.core.patches.PatchingVerifier import tech.beshu.ror.tools.core.patches.PatchingVerifier.Error.{CannotVerifyIfPatched, EsNotPatched} import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -object EsPatchVerifier extends Logging { +object EsPatchVerifier extends RequestIdAwareLogging { def verify(settings: Settings): Unit = doPrivileged { pathHomeFrom(settings).flatMap(PatchingVerifier.verify) match { @@ -30,7 +30,7 @@ object EsPatchVerifier extends Logging { case Left(e@EsNotPatched(_)) => throw new IllegalStateException(e.message) case Left(e@CannotVerifyIfPatched(_)) => - logger.warn(e.message) + noRequestIdLogger.warn(e.message) } } diff --git a/es710x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es710x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index dfc3613b7e..06a2f90f96 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.support.{ActionFilter, ActionFilterChain} import org.elasticsearch.action.{ActionListener, ActionRequest, ActionResponse} import org.elasticsearch.client.node.NodeClient @@ -62,7 +62,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, rorEsConfig: ReadonlyRestEsConfig) (implicit environmentConfig: EnvironmentConfig) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = environmentConfig.uniqueIdentifierGenerator @@ -212,12 +212,12 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def handleRorNotReadyYet(esContext: EsContext): Unit = { - logger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") + noRequestIdLogger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") rorNotAvailableRequestHandler.handleRorNotReadyYet(esContext) } private def handleRorFailedToStart(esContext: EsContext): Unit = { - logger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") + noRequestIdLogger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") rorNotAvailableRequestHandler.handleRorFailedToStart(esContext) } @@ -239,7 +239,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def logAndSetStartingFailureState(failure: StartingFailure): Unit = { - logger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) + noRequestIdLogger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) rorInstanceState.set(RorInstanceStartingState.NotStarted(failure)) } } diff --git a/es710x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala b/es710x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala index 7f92461f08..72c14bf252 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.xcontent.cbor.CborXContent import org.elasticsearch.common.xcontent.json.JsonXContent import org.elasticsearch.common.xcontent.smile.SmileXContent @@ -29,7 +29,7 @@ import tech.beshu.ror.accesscontrol.domain.ResponseFieldsFiltering.{AccessMode, import scala.jdk.CollectionConverters.* trait ResponseFieldsFiltering { - this: Logging => + this: RequestIdAwareLogging => private val responseFieldsRestrictions: Atomic[Option[ResponseFieldsRestrictions]] = Atomic(None: Option[ResponseFieldsRestrictions]) @@ -44,7 +44,7 @@ trait ResponseFieldsFiltering { case bytesRestResponse: BytesRestResponse => filterBytesRestResponse(bytesRestResponse, fieldsRestrictions) case otherResponse => - logger.warn("ResponseFields filtering is unavailable for this type of request") + noRequestIdLogger.warn("ResponseFields filtering is unavailable for this type of request") otherResponse } case None => diff --git a/es710x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala b/es710x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala index 0f26750588..da95de59a4 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.action.{ActionListener, ActionResponse} import org.elasticsearch.threadpool.ThreadPool @@ -37,7 +37,7 @@ sealed abstract class RorActionListener[T](val underlying: ActionListener[T]) ex final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionListener[T], correlationId: Eval[CorrelationId]) - extends RorActionListener[T](underlying) with Logging { + extends RorActionListener[T](underlying) with RequestIdAwareLogging { override def onFailure(e: Exception): Unit = { super.onFailure(adaptExceptionIfNeeded(e)) @@ -47,7 +47,7 @@ final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionLis ex match { case esException: ElasticsearchException => esException case other => - logger.error(s"[${correlationId.value.show}] Internal error.", other) + noRequestIdLogger.error(s"[${correlationId.value.show}] Internal error.", other) new ElasticsearchException(s"[${correlationId.value.show}] Internal error. See logs for details.") } } diff --git a/es710x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala b/es710x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala index 0a80ad8a51..09e707bd3e 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.http.HttpChannel import org.elasticsearch.rest.{AbstractRestChannel, RestChannel as EsRestChannel, RestRequest as EsRestRequest, RestResponse as EsRestResponse} import squants.information.{Bytes, Information} @@ -40,7 +40,7 @@ object RorRestChannel { final class RorRestChannel private(underlying: EsRestChannel, val restRequest: RorRestRequest) extends AbstractRestChannel(underlying.request(), true) with ResponseFieldsFiltering - with Logging { + with RequestIdAwareLogging { override def sendResponse(response: EsRestResponse): Unit = { ThreadRepo.removeRestChannel(this) diff --git a/es710x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala b/es710x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala index 6babc712b9..3c80750a25 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala @@ -18,16 +18,15 @@ package tech.beshu.ror.es.actions.rradmin import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.ConfigApi.ConfigResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAdminActionHandler extends Logging { +class RRAdminActionHandler extends RequestIdAwareLogging { private implicit val adminRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +51,7 @@ class RRAdminActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAdminResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAdminAction internal error", ex) + logger.error("RRAdminAction internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es710x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala b/es710x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala index c55835a1d0..ce45c6f48e 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala @@ -16,18 +16,15 @@ */ package tech.beshu.ror.es.actions.rrauthmock -import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.AuthMockApi.AuthMockResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier -import tech.beshu.ror.implicits.* +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAuthMockActionHandler extends Logging { +class RRAuthMockActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -53,7 +50,7 @@ class RRAuthMockActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAuthMockResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAuthMock internal error", ex) + logger.error("RRAuthMock internal error", ex) listener.onFailure(new Exception(ex)) } } diff --git a/es710x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala b/es710x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala index aa8bb31e67..640084c4ec 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestconfig import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.TestConfigApi.TestConfigResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestConfigActionHandler extends Logging { +class RRTestConfigActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +52,7 @@ class RRTestConfigActionHandler extends Logging { case Right(response) => listener.onResponse(new RRTestConfigResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRTestConfig internal error", ex) + logger.error(s"RRTestConfig internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es710x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala b/es710x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala index 5e42d55f7e..4d9a78443a 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.dlsfls import cats.data.StateT import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.DirectoryReader import org.elasticsearch.common.CheckedFunction import org.elasticsearch.common.util.concurrent.ThreadContext @@ -31,7 +31,7 @@ import java.io.IOException import java.util.function.{Function => JavaFunction} import scala.util.{Failure, Success, Try} -object RoleIndexSearcherWrapper extends Logging { +object RoleIndexSearcherWrapper extends RequestIdAwareLogging { val instance: JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] = new JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] { @@ -54,7 +54,7 @@ object RoleIndexSearcherWrapper extends Logging { } .map(r => (r, r)) case None => - logger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") + noRequestIdLogger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") Success((reader, reader)) } } @@ -66,13 +66,13 @@ object RoleIndexSearcherWrapper extends Logging { nel <- NonEmptyString.from(value) match { case Right(nel) => Success(nel) case Left(_) => - logger.debug("FLS: empty header value") + noRequestIdLogger.debug("FLS: empty header value") failure } fields <- transientFieldsFromHeaderValue.fromRawValue(nel) match { case result@Success(_) => result case Failure(ex) => - logger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) + noRequestIdLogger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) failure } } yield fields diff --git a/es710x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala b/es710x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala index 6f89904e92..91f62e2a36 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.dlsfls import com.google.common.collect.Iterators -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.codecs.StoredFieldsReader import org.apache.lucene.index.* import org.apache.lucene.index.StoredFieldVisitor.Status @@ -38,21 +38,21 @@ import scala.jdk.CollectionConverters.* import scala.util.Try private class RorDocumentFieldReader(reader: LeafReader, fieldsRestrictions: FieldsRestrictions) - extends SequentialStoredFieldsLeafReader(reader) with Logging { + extends SequentialStoredFieldsLeafReader(reader) with RequestIdAwareLogging { private val policy = new FieldsPolicy(fieldsRestrictions) private val remainingFieldsInfo = { val fInfos = in.getFieldInfos val newInfos = if (fInfos.asScala.isEmpty) { - logger.warn("original fields were empty! This is weird!") + noRequestIdLogger.warn("original fields were empty! This is weird!") fInfos } else { val remainingFields = fInfos.asScala.filter(f => policy.canKeep(f.name)).toSet new FieldInfos(remainingFields.toArray) } - logger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") - logger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") - logger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") + noRequestIdLogger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") newInfos } private val jsonPolicyBasedFilterer = new JsonPolicyBasedFilterer(policy) diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala index ceca9c8623..8054fc4a44 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.* import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest import org.elasticsearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest @@ -87,7 +87,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, threadPool: ThreadPool) (implicit generator: UniqueIdentifierGenerator, scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle(engines: Engines, esContext: EsContext): Task[Either[Error, Unit]] = { @@ -227,7 +227,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, case SearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case MultiSearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case _ => - logger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") + noRequestIdLogger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") regularRequestHandler.handle(new DummyCompositeIndicesEsRequestContext(request, esContext, aclContext, clusterService, threadPool)) } // rest diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala index a388bb0f9f..57be14c040 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.common.io.stream.StreamOutput import org.elasticsearch.common.xcontent.{ToXContent, ToXContentObject, XContentBuilder} @@ -45,7 +45,7 @@ import scala.util.{Failure, Success, Try} class CurrentUserMetadataRequestHandler(engine: Engine, esContext: EsContext) - extends Logging { + extends RequestIdAwareLogging { def handle(request: RequestContext.Aux[CurrentUserMetadataRequestBlockContext] with EsRequest[CurrentUserMetadataRequestBlockContext]): Task[Unit] = { engine.core.accessControl @@ -69,7 +69,7 @@ class CurrentUserMetadataRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(ex.asInstanceOf[Exception]) } } @@ -86,13 +86,13 @@ class CurrentUserMetadataRequestHandler(engine: Engine, )) } - private def onPassThrough(requestContext: RequestContext): Unit = { - logger.warn(s"[${requestContext.id.toRequestId.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") + private def onPassThrough(implicit requestContext: RequestContext): Unit = { + logger.warn(s"Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") esContext.listener.onFailure(createRorNotEnabledResponse()) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala index 2fb01dcc41..c5c44fda92 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala @@ -20,7 +20,7 @@ import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.RegularRequestResult @@ -49,7 +49,7 @@ class RegularRequestHandler(engine: Engine, esContext: EsContext, threadPool: ThreadPool) (implicit scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle[B <: BlockContext : BlockContextUpdater](request: RequestContext.Aux[B] with EsRequest[B]): Task[Unit] = { engine.core.accessControl @@ -85,7 +85,7 @@ class RegularRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(new Exception(ex)) } } @@ -99,7 +99,7 @@ class RegularRequestHandler(engine: Engine, case ModificationResult.ShouldBeInterrupted => onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case ModificationResult.CannotModify => - logger.error(s"[${request.id.toRequestId.show}] Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") + noRequestIdLogger.error(s"Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case CustomResponse(response) => respond(request, response) @@ -247,7 +247,7 @@ class RegularRequestHandler(engine: Engine, esContext.listener.onResponse(response) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } \ No newline at end of file diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala index f4f832dedc..bfc421bdd5 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.index.query.{AbstractQueryBuilder, QueryBuilder, QueryBuilders} import org.elasticsearch.search.aggregations.AggregatorFactories @@ -40,7 +40,7 @@ import tech.beshu.ror.implicits.* import java.util.UUID import scala.jdk.CollectionConverters.* -object SearchRequestOps extends Logging { +object SearchRequestOps extends RequestIdAwareLogging { implicit class QueryBuilderOps(val builder: Option[QueryBuilder]) extends AnyVal { @@ -52,7 +52,7 @@ object SearchRequestOps extends Logging { val modifiedQuery: AbstractQueryBuilder[_] = provideNewQueryWithAppliedFilter(builder, filterQuery) Some(modifiedQuery) case None => - logger.debug(s"[${requestId.show}] No filter applied to query.") + logger.debug(s"No filter applied to query.") builder } } @@ -92,7 +92,7 @@ object SearchRequestOps extends Logging { case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, requestId) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) disableCaching(requestId) case BasedOnBlockContextOnly.NotAllowedFieldsUsed(notAllowedFields) => modifyNotAllowedFieldsInRequest(notAllowedFields) @@ -138,8 +138,8 @@ object SearchRequestOps extends Logging { } } - private def disableCaching(requestId: RequestContext.Id) = { - logger.debug(s"[${requestId.show}] ACL uses context header for fields rule, will disable request cache for SearchRequest") + private def disableCaching(implicit requestId: RequestContext.Id) = { + logger.debug(s"ACL uses context header for fields rule, will disable request cache for SearchRequest") request.requestCache(false) } } diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala index 9de832edcc..74790fb1fd 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala @@ -17,7 +17,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.action.support.IndicesOptions.WildcardStates import org.elasticsearch.action.{CompositeIndicesRequest, IndicesRequest} @@ -34,7 +33,7 @@ import scala.jdk.CollectionConverters.* abstract class BaseEsRequestContext[B <: BlockContext](esContext: EsContext, clusterService: RorClusterService) - extends RequestContext with Logging { + extends RequestContext { override type BLOCK_CONTEXT = B diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala index ae8abbe1f5..0ee2967364 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala @@ -18,7 +18,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -26,8 +25,9 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import scala.util.Try +import tech.beshu.ror.utils.RequestIdAwareLogging -trait EsRequest[B <: BlockContext] extends Logging { +trait EsRequest[B <: BlockContext] extends RequestIdAwareLogging { implicit def threadPool: ThreadPool final def modifyUsing(blockContext: B): ModificationResult = { @@ -35,7 +35,7 @@ trait EsRequest[B <: BlockContext] extends Logging { Try(modifyRequest(blockContext)) .fold( ex => { - logger.error(s"[${blockContext.requestContext.id.show}] Cannot modify request with filtered data", ex) + logger.error(s"Cannot modify request with filtered data", ex)(blockContext) ModificationResult.CannotModify }, identity diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala index c6a9dcbefd..f773b3efb1 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala @@ -51,7 +51,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest private def discoverDataStreams() = { val dataStreams = dataStreamsFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered data streams: ${dataStreams.show}") + logger.debug(s"Discovered data streams: ${dataStreams.show}") dataStreams } @@ -59,7 +59,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest val backingIndices = backingIndicesFrom(actionRequest) backingIndices match { case BackingIndices.IndicesInvolved(filteredIndices, _) => - logger.debug(s"[${id.show}] Discovered indices: ${filteredIndices.show}") + logger.debug(s"Discovered indices: ${filteredIndices.show}") case BackingIndices.IndicesNotInvolved => } backingIndices diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala index c091179cb6..d150709314 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala @@ -85,7 +85,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: case Some(indices) => update(actionRequest, indices, blockContext.filter, blockContext.fieldLevelSecurity) case None => - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -101,7 +101,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } \ No newline at end of file diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala index 71d462de57..48014e1bdc 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala @@ -73,7 +73,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, } yield update(actionRequest, filteredIndices, allAllowedIndices) result.getOrElse { - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -86,7 +86,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala index 95d882c3b5..f607c0e347 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala @@ -50,7 +50,7 @@ abstract class BaseRepositoriesEsRequestContext[R <: ActionRequest](actionReques case Some(repositories) => update(actionRequest, repositories) case None => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") ShouldBeInterrupted } } diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala index b3b1d66238..7ef0f32014 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala @@ -42,7 +42,7 @@ abstract class BaseSingleIndexEsRequestContext[R <: ActionRequest](actionRequest filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } update(request, filteredIndices.head) } diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala index b5ab70fe7a..c1b2e7ea27 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala @@ -62,7 +62,7 @@ class BulkEsRequestContext(actionRequest: BulkRequest, case (_, _) => ShouldBeInterrupted } } else { - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because origin request contained different " + + logger.error(s"Cannot alter MultiGetRequest request, because origin request contained different " + s"number of requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } @@ -90,18 +90,18 @@ class BulkEsRequestContext(actionRequest: BulkRequest, updateRequestWithIndices(request, nel) Modified case None => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because empty list of indices was found") + logger.error(s"Cannot alter MultiGetRequest request, because empty list of indices was found") ShouldBeInterrupted } case Indices.NotFound => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because no allowed indices were found") + logger.error(s"Cannot alter MultiGetRequest request, because no allowed indices were found") ShouldBeInterrupted } } private def updateRequestWithIndices(request: DocWriteRequest[_], indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } request.index(indices.head.stringify) } diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala index 75a75fcef5..96a043b298 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala @@ -53,14 +53,14 @@ class BulkShardEsRequestContext(actionRequest: BulkShardRequest, case Success(_) => Modified case Failure(ex) => - logger.error(s"[${id.show}] Cannot modify BulkShardRequest", ex) + logger.error(s"Cannot modify BulkShardRequest", ex) CannotModify } } private def tryUpdate(request: BulkShardRequest, indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } val singleIndex = indices.head val uuid = clusterService.indexOrAliasUuids(singleIndex.name).toList.head diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala index 65a168092a..158ac485a5 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala @@ -45,14 +45,14 @@ class ClusterAllocationExplainEsRequestContext(actionRequest: ClusterAllocationE getRequestedIndexFrom(request) match { case Some(_) => if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateIndexIn(request, filteredIndices.head) Modified case None if filteredIndices.exists(_.name === ClusterIndexName.Local.wildcard) => Modified case None => - logger.error(s"[${id.show}] Cluster allocation explain request without index name is unavailable when block contains `indices` rule") + logger.error(s"Cluster allocation explain request without index name is unavailable when block contains `indices` rule") ShouldBeInterrupted } } diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala index 3582caec0a..3a7e407d21 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala @@ -69,7 +69,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, updateAliases(actionRequest, aliases) UpdateResponse.sync(updateAliasesResponse(aliases.includedOnly, _)) case None => - logger.error(s"[${id.show}] At least one alias and one index has to be allowed. " + + logger.error(s"At least one alias and one index has to be allowed. " + s"Found allowed indices: [${blockContext.indices.show}]." + s"Found allowed aliases: [${blockContext.aliases.show}]") ShouldBeInterrupted @@ -117,7 +117,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, .indices().asSafeSet .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } @@ -125,7 +125,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, val aliases = rawRequestAliasesSet(request) .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered aliases: ${aliases.show}") + logger.debug(s"Discovered aliases: ${aliases.show}") aliases } diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala index abb85d42b7..f9e2c87e53 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala @@ -55,7 +55,7 @@ class IndicesAliasesEsRequestContext(actionRequest: IndicesAliasesRequest, if (originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala index 05b70606b9..37dd50452b 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala @@ -119,7 +119,7 @@ class MultiGetEsRequestContext(actionRequest: MultiGetRequest, case Nil => updateItemWithNonExistingIndex(item) case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } item.index(index.stringify) } diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala index 989956d79a..9e13edee8d 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala @@ -78,7 +78,7 @@ class MultiSearchEsRequestContext(actionRequest: MultiSearchRequest, } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala index 9191e33b66..5a61356f48 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala @@ -47,7 +47,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { request.getRequests.removeIf { request => removeOrAlter(request, filteredIndices.toCovariantSet) } if (request.getRequests.asScala.isEmpty) { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") ShouldBeInterrupted } else { Modified @@ -63,7 +63,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, true case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") } request.index(index.stringify) false diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala index c411df93c5..c7b99f6e85 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala @@ -52,7 +52,7 @@ class PutRollupJobEsRequestContext private(actionRequest: ActionRequest, if(originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala index 141d9db788..fff8ed58bb 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala @@ -49,7 +49,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (tryUpdate(actionRequest, filteredIndices)) Modified else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") ShouldBeInterrupted } } diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala index 489d0187bc..c42dfc3b78 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala @@ -58,10 +58,10 @@ class ReindexEsRequestContext(actionRequest: ReindexRequest, Modified } else { if (!isDestinationIndexOnFilteredIndicesList) { - logger.info(s"[${id.show}] Destination index of _reindex request is forbidden") + logger.info(s"Destination index of _reindex request is forbidden") } if (!isSearchRequestComposedOnlyOfAllowedIndices) { - logger.info(s"[${id.show}] At least one index from sources indices list of _reindex request is forbidden") + logger.info(s"At least one index from sources indices list of _reindex request is forbidden") } ShouldBeInterrupted } diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala index 2c1b0014e0..97b8ccd9c5 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala @@ -74,7 +74,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo request } case Left(_) => - logger.debug(s"[${id.show}] Cannot parse SQL statement - we can pass it though, because ES is going to reject it") + logger.debug(s"Cannot parse SQL statement - we can pass it though, because ES is going to reject it") request } } @@ -85,7 +85,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DataStreamsStatsEsRequestContext.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DataStreamsStatsEsRequestContext.scala index 3cbf6360ed..3e2648b17b 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DataStreamsStatsEsRequestContext.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DataStreamsStatsEsRequestContext.scala @@ -44,7 +44,7 @@ private[datastreams] class DataStreamsStatsEsRequestContext private(actionReques if (modifyActionRequest(blockContext)) { ModificationResult.Modified } else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") ModificationResult.ShouldBeInterrupted } } diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DeleteDataStreamEsRequestContext.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DeleteDataStreamEsRequestContext.scala index b4491990f0..cf135bdf6a 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DeleteDataStreamEsRequestContext.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DeleteDataStreamEsRequestContext.scala @@ -44,7 +44,7 @@ private[datastreams] class DeleteDataStreamEsRequestContext private(actionReques if (modifyActionRequest(blockContext)) { ModificationResult.Modified } else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") ModificationResult.ShouldBeInterrupted } } diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/GetDataStreamEsRequestContext.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/GetDataStreamEsRequestContext.scala index 12435d0f4f..ce0b1fbae6 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/GetDataStreamEsRequestContext.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/GetDataStreamEsRequestContext.scala @@ -64,7 +64,7 @@ private[datastreams] class GetDataStreamEsRequestContext(actionRequest: ActionRe r } } else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") ModificationResult.ShouldBeInterrupted } } diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala index 0c67384c1e..d7e743e648 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CleanupRepositoryEsRequestContext(actionRequest: CleanupRepositoryRequest, override protected def update(request: CleanupRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala index 44b7d78dfd..d09015139b 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CreateRepositoryEsRequestContext(actionRequest: PutRepositoryRequest, override protected def update(request: PutRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala index eaf9334872..0cf32e1bea 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class DeleteRepositoryEsRequestContext(actionRequest: DeleteRepositoryRequest, override protected def update(request: DeleteRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala index cee0bffd4c..d1410eff3d 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class VerifyRepositoryEsRequestContext(actionRequest: VerifyRepositoryRequest, override protected def update(request: VerifyRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala index ead4fcf250..20501516d5 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala @@ -68,32 +68,32 @@ class CreateSnapshotEsRequestContext(actionRequest: CreateSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala index a56aba660e..621d744767 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala @@ -60,7 +60,7 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -71,14 +71,14 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, .toRight(()) } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala index 58122fb44f..782a54d7df 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala @@ -69,7 +69,7 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, case r => r } case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -81,14 +81,14 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.mkString(",")}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.mkString(",")}]") } Right(repository) } diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala index 88887db96c..156deb5b80 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala @@ -63,7 +63,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -75,7 +75,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") } Right(snapshot) } @@ -88,7 +88,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala index 44ee8397ec..e522e440f1 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala @@ -100,12 +100,12 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { val repositories = blockContext.repositories if (allRepositoriesRequested(repositories)) { Right(RepositoryName.All) @@ -115,7 +115,7 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala index 67ea5e22af..f870e054ad 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.GetComposableIndexTemplateAction import org.elasticsearch.cluster.metadata import org.elasticsearch.cluster.metadata.ComposableIndexTemplate @@ -103,7 +103,7 @@ class GetComposableIndexTemplateEsRequestContext(actionRequest: GetComposableInd } -private[templates] object GetComposableIndexTemplateEsRequestContext extends Logging { +private[templates] object GetComposableIndexTemplateEsRequestContext extends RequestIdAwareLogging { def filter(templates: Map[String, ComposableIndexTemplate], usingTemplate: Set[Template] => Set[Template]) diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala index c170a8c87d..d49f293358 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.{GetIndexTemplatesRequest, GetIndexTemplatesResponse} import org.elasticsearch.cluster.metadata.{AliasMetadata, IndexTemplateMetadata} import org.elasticsearch.common.collect.ImmutableOpenMap @@ -100,7 +100,7 @@ class GetTemplatesEsRequestContext(actionRequest: GetIndexTemplatesRequest, } -private[templates] object GetTemplatesEsRequestContext extends Logging { +private[templates] object GetTemplatesEsRequestContext extends RequestIdAwareLogging { def filter(templates: Iterable[IndexTemplateMetadata], usingTemplate: Set[Template] => Set[Template]) diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala index a8951de5b1..32116d8212 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala @@ -72,7 +72,7 @@ class MultiSearchTemplateEsRequestContext private(actionRequest: ActionRequest w } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala index e6f6d8916e..434787a686 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala @@ -55,7 +55,7 @@ class SimulateIndexTemplateRequestEsRequestContext(actionRequest: SimulateIndexT filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateRequest(request, filteredIndices.head, allAllowedIndices) } diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala index fbc4cf6776..46ed6e7a95 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala @@ -109,7 +109,7 @@ class SimulateExistingTemplateRequestEsRequestContext(existingTemplateName: Temp case Some(_) => updateResponse(namePatterns.toList, blockContext.allAllowedIndices.toList) case None => - logger.info(s"[${id.show}] User has no access to template ${existingTemplateName.show}") + logger.info(s"User has no access to template ${existingTemplateName.show}") ModificationResult.ShouldBeInterrupted } case other => diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala index 22a0c6791a..e08a2fbb72 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.queries import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.index.query.* import org.joor.Reflect.on import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.RequestFieldsUsage @@ -32,7 +32,7 @@ trait QueryFieldsUsage[QUERY <: QueryBuilder] { def fieldsIn(query: QUERY): RequestFieldsUsage } -object QueryFieldsUsage extends Logging { +object QueryFieldsUsage extends RequestIdAwareLogging { def apply[QUERY <: QueryBuilder](implicit ev: QueryFieldsUsage[QUERY]): QueryFieldsUsage[QUERY] = ev implicit class Ops[QUERY <: QueryBuilder : QueryFieldsUsage](val query: QUERY) { @@ -65,7 +65,7 @@ object QueryFieldsUsage extends Logging { Option(on(query).call("getFieldName").get[String]) match { case Some(fieldName: String) => UsingFields(NonEmptyList.one(UsedField(fieldName))) case _ => - logger.debug(s"Cannot extract fields for terms set query") + noRequestIdLogger.debug(s"Cannot extract fields for terms set query") CannotExtractFields } } @@ -93,7 +93,7 @@ object QueryFieldsUsage extends Logging { case builder: TermsSetQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder: WildcardQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder => - logger.debug(s"Cannot extract fields for query: ${builder.getName}") + noRequestIdLogger.debug(s"Cannot extract fields for query: ${builder.getName}") CannotExtractFields } diff --git a/es710x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala b/es710x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala index 0998bb9a5b..b4671e9e4d 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.handler.response import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.FieldsRestrictions import tech.beshu.ror.accesscontrol.domain.Header @@ -26,17 +26,17 @@ import tech.beshu.ror.accesscontrol.headerValues.transientFieldsToHeaderValue import tech.beshu.ror.accesscontrol.request.RequestContext import tech.beshu.ror.implicits.* -object FLSContextHeaderHandler extends Logging { +object FLSContextHeaderHandler extends RequestIdAwareLogging { def addContextHeader(threadPool: ThreadPool, - fieldsRestrictions: FieldsRestrictions, - requestId: RequestContext.Id): Unit = { + fieldsRestrictions: FieldsRestrictions) + (implicit requestId: RequestContext.Id): Unit = { val threadContext = threadPool.getThreadContext val header = createContextHeader(fieldsRestrictions) Option(threadContext.getHeader(header.name.value.value)) match { case None => implicit val show = headerShow - logger.debug(s"[${requestId.show}] Adding thread context header required by lucene. Header: '${header.show}'") + logger.debug(s"Adding thread context header required by lucene. Header: '${header.show}'") threadContext.putHeader(header.name.value.value, header.value.value) case Some(_) => } diff --git a/es710x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala b/es710x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala index 26df1d5bb9..2ce5662a4b 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.admin.indices.template.get.{GetComponentTemplateAction, GetComposableIndexTemplateAction} import org.elasticsearch.action.admin.indices.template.put.{PutComponentTemplateAction, PutComposableIndexTemplateAction} @@ -45,7 +45,7 @@ import scala.jdk.CollectionConverters.* final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJsonParserFactory)(using Clock) extends DataStreamService - with Logging { + with RequestIdAwareLogging { override def checkDataStreamExists(dataStreamName: DataStreamName.Full): Task[Boolean] = execute { val enhancedActionType = client.findActionUnsafe[ActionResponse]("indices:admin/data_stream/get") @@ -218,11 +218,11 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ response <- Task.measure( task = Task.delay(nodeClient.execute(action, request).actionGet()), logTimeMeasurement = duration => Task.delay { - logger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") + noRequestIdLogger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") } ) _ <- Task.delay { - logger.debug(s"Action ${action.name()} response: ${response.toString}") + noRequestIdLogger.debug(s"Action ${action.name()} response: ${response.toString}") } } yield response } @@ -230,7 +230,7 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ def executeAck[REQUEST <: ActionRequest, RESPONSE <: AcknowledgedResponse](action: ActionType[RESPONSE], request: REQUEST): Task[RESPONSE] = { executeT(action, request) - .tapEval(response => Task.delay(logger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) + .tapEval(response => Task.delay(noRequestIdLogger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) } private def supportedActions: Map[ActionType[ActionResponse], TransportAction[ActionRequest, ActionResponse]] = { diff --git a/es710x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala b/es710x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala index 18490a232c..b65ba21df7 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.support.WriteRequest.RefreshPolicy import org.elasticsearch.client.node.NodeClient @@ -38,7 +38,7 @@ import scala.jdk.CollectionConverters.* class EsIndexJsonContentService(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexJsonContentService - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -63,14 +63,14 @@ class EsIndexJsonContentService(client: NodeClient, Option(response.getSourceAsMap) match { case Some(map) => val source = map.asScala.toMap.asStringMap - logger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") Right(source) case None => - logger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") + noRequestIdLogger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") Right(Map.empty[String, String]) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(ContentNotFound) } } @@ -78,7 +78,7 @@ class EsIndexJsonContentService(client: NodeClient, .onErrorRecover { case _: ResourceNotFoundException => Left(ContentNotFound) case ex => - logger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) Left(CannotReachContentSource) } } @@ -104,14 +104,14 @@ class EsIndexJsonContentService(client: NodeClient, case status if status / 100 == 2 => Right(()) case status => - logger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") Left(CannotWriteToIndex) } } .executeOn(RorSchedulers.blockingScheduler) .onErrorRecover { case ex => - logger.error(s"Cannot write to document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]", ex) Left(CannotWriteToIndex) } } diff --git a/es710x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala b/es710x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala index e09268f8a1..1a6a17e808 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala @@ -21,7 +21,7 @@ import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task import monix.execution.CancelablePromise -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction.ResolvedIndex @@ -63,7 +63,7 @@ class EsServerBasedRorClusterService(nodeName: String, nodeClient: NodeClient, threadPool: ThreadPool) extends RorClusterService - with Logging { + with RequestIdAwareLogging { import EsServerBasedRorClusterService.* @@ -154,7 +154,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractAccessibilityFrom) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify get request. Blocking document", ex) + logger.error(s"Could not verify get request. Blocking document", ex)(id) Inaccessible } } @@ -166,7 +166,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractResultsFromSearchResponse) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify documents returned by multi get response. Blocking all returned documents", ex) + logger.error(s"Could not verify documents returned by multi get response. Blocking all returned documents", ex)(id) blockAllDocsReturned(documents) } .map(results => zip(results, documents)) @@ -246,7 +246,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService): Task[List[FullRemoteDataStreamWithAliases]] = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -296,7 +296,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService) = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -366,7 +366,7 @@ class EsServerBasedRorClusterService(nodeName: String, } } case None => - logger.error("Cannot supply Snapshots Service. Please, report the issue!!!") + noRequestIdLogger.error("Cannot supply Snapshots Service. Please, report the issue!!!") Task.now(Set.empty[Snapshot]) } } diff --git a/es710x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala b/es710x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala index 84a97818fe..b5ce8bc2a6 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.services import cats.data.NonEmptyList -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.DocWriteRequest import org.elasticsearch.action.bulk.{BackoffPolicy, BulkProcessor, BulkRequest, BulkResponse} import org.elasticsearch.action.index.IndexRequest @@ -39,7 +39,7 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, (using Clock) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { private val bulkProcessor = BulkProcessor @@ -76,25 +76,25 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, private class AuditSinkBulkProcessorListener extends BulkProcessor.Listener { override def beforeBulk(executionId: Long, request: BulkRequest): Unit = { - logger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") + noRequestIdLogger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") } override def afterBulk(executionId: Long, request: BulkRequest, response: BulkResponse): Unit = { if (response.hasFailures) { - logger.error("Some failures flushing the BulkProcessor: ") + noRequestIdLogger.error("Some failures flushing the BulkProcessor: ") response .getItems.to(LazyList) .filter(_.isFailed) .map(_.getFailureMessage) .groupBy(identity) .foreach { case (message, stream) => - logger.error(s"${stream.size}x: $message") + noRequestIdLogger.error(s"${stream.size}x: $message") } } } override def afterBulk(executionId: Long, request: BulkRequest, failure: Throwable): Unit = { - logger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) + noRequestIdLogger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) } } diff --git a/es710x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala b/es710x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala index fb822d05de..d72adbdb65 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala @@ -22,7 +22,7 @@ import org.apache.http.auth.{AuthScope, Credentials, UsernamePasswordCredentials import org.apache.http.conn.ssl.NoopHostnameVerifier import org.apache.http.impl.client.BasicCredentialsProvider import org.apache.http.impl.nio.client.HttpAsyncClientBuilder -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.* import org.elasticsearch.client.RestClient.FailureListener import tech.beshu.ror.accesscontrol.audit.sink.AuditDataStreamCreator @@ -38,7 +38,7 @@ import scala.collection.parallel.CollectionConverters.* final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient]) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { override def submit(indexName: IndexName.Full, documentId: String, jsonRecord: String) (implicit requestId: RequestId): Unit = { @@ -77,21 +77,21 @@ final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient] override def onSuccess(response: Response): Unit = { response.getStatusLine.getStatusCode / 100 match { case 2 => // 2xx - logger.debug(s"[${requestId.show}] Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") + logger.debug(s"Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") case _ => - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") } } override def onFailure(ex: Exception): Unit = { - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId]", ex) + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId]", ex) } } override val dataStreamCreator: AuditDataStreamCreator = new AuditDataStreamCreator(clients.map(new RestClientDataStreamService(_))) } -object RestClientAuditSinkService extends Logging { +object RestClientAuditSinkService extends RequestIdAwareLogging { def create(remoteCluster: AuditCluster.RemoteAuditCluster): RestClientAuditSinkService = { remoteCluster.mode match { @@ -122,7 +122,7 @@ object RestClientAuditSinkService extends Logging { .setFailureListener( new FailureListener { override def onFailure(node: Node): Unit = { - logger.debug( + noRequestIdLogger.debug( s"[AUDIT] Node marked dead: ${node.getHost.getSchemeName}://${node.getHost.getHostName}:${node.getHost.getPort}. The client will attempt failover.", ) } diff --git a/es710x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala b/es710x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala index a9f97756f7..a10c1a2aeb 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.Channel import io.netty.handler.ssl.NotSslRecordException -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.network.NetworkService import org.elasticsearch.common.settings.{ClusterSettings, Settings} import org.elasticsearch.common.util.BigArrays @@ -41,7 +41,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, sharedGroupFactory: SharedGroupFactory, fipsCompliant: Boolean) extends Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, ssl.clientAuthenticationEnabled) @@ -49,7 +49,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, override def onException(channel: HttpChannel, cause: Exception): Unit = { if (!this.lifecycle.started) return - else if (cause.getCause.isInstanceOf[NotSslRecordException]) logger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) + else if (cause.getCause.isInstanceOf[NotSslRecordException]) noRequestIdLogger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) else super.onException(channel, cause) channel.close() } diff --git a/es710x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala b/es710x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala index cd73e6310c..d8c0dbbce8 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.* import io.netty.handler.ssl.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.Version import org.elasticsearch.cluster.node.DiscoveryNode import org.elasticsearch.common.io.stream.NamedWriteableRegistry @@ -46,7 +46,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, sharedGroupFactory: SharedGroupFactory, fipsCompliant: Boolean) extends Netty4Transport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = SSLCertHelper.prepareClientSSLContext(ssl, fipsCompliant, ssl.certificateVerificationEnabled) private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, clientAuthenticationEnabled = false) @@ -77,7 +77,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, override def exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable): Unit = { if (cause.isInstanceOf[NotSslRecordException] || (cause.getCause != null && cause.getCause.isInstanceOf[NotSslRecordException])) { - logger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") + noRequestIdLogger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") ctx.channel.close } else { super.exceptionCaught(ctx, cause) diff --git a/es710x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala b/es710x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala index 597035c7ee..8ef7a5c184 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.utils import cats.Show import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.client.node.NodeClient import org.elasticsearch.rest.* @@ -35,7 +35,7 @@ import java.util import scala.util.Try class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandler) - extends RestHandler with Logging { + extends RestHandler with RequestIdAwareLogging { private val wrapped = doPrivileged { wrapSomeActions(underlying) @@ -103,11 +103,11 @@ class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandle private def logError(error: AuthorizationValueError): Unit = { { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorSanitizedShow - logger.warn(s"The incoming request was malformed. Cause: ${error.show}") + noRequestIdLogger.warn(s"The incoming request was malformed. Cause: ${error.show}") } if (logger.delegate.isDebugEnabled()) { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorWithDetailsShow - logger.debug(s"Malformed request detailed cause: ${error.show}") + noRequestIdLogger.debug(s"Malformed request detailed cause: ${error.show}") } } diff --git a/es710x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala b/es710x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala index 5ab1e35742..a9af8f710a 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala @@ -16,13 +16,13 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.settings.Settings import tech.beshu.ror.tools.core.patches.PatchingVerifier import tech.beshu.ror.tools.core.patches.PatchingVerifier.Error.{CannotVerifyIfPatched, EsNotPatched} import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -object EsPatchVerifier extends Logging { +object EsPatchVerifier extends RequestIdAwareLogging { def verify(settings: Settings): Unit = doPrivileged { pathHomeFrom(settings).flatMap(PatchingVerifier.verify) match { @@ -30,7 +30,7 @@ object EsPatchVerifier extends Logging { case Left(e@EsNotPatched(_)) => throw new IllegalStateException(e.message) case Left(e@CannotVerifyIfPatched(_)) => - logger.warn(e.message) + noRequestIdLogger.warn(e.message) } } diff --git a/es711x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es711x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index dfc3613b7e..06a2f90f96 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.support.{ActionFilter, ActionFilterChain} import org.elasticsearch.action.{ActionListener, ActionRequest, ActionResponse} import org.elasticsearch.client.node.NodeClient @@ -62,7 +62,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, rorEsConfig: ReadonlyRestEsConfig) (implicit environmentConfig: EnvironmentConfig) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = environmentConfig.uniqueIdentifierGenerator @@ -212,12 +212,12 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def handleRorNotReadyYet(esContext: EsContext): Unit = { - logger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") + noRequestIdLogger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") rorNotAvailableRequestHandler.handleRorNotReadyYet(esContext) } private def handleRorFailedToStart(esContext: EsContext): Unit = { - logger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") + noRequestIdLogger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") rorNotAvailableRequestHandler.handleRorFailedToStart(esContext) } @@ -239,7 +239,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def logAndSetStartingFailureState(failure: StartingFailure): Unit = { - logger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) + noRequestIdLogger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) rorInstanceState.set(RorInstanceStartingState.NotStarted(failure)) } } diff --git a/es711x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala b/es711x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala index 7f92461f08..72c14bf252 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.xcontent.cbor.CborXContent import org.elasticsearch.common.xcontent.json.JsonXContent import org.elasticsearch.common.xcontent.smile.SmileXContent @@ -29,7 +29,7 @@ import tech.beshu.ror.accesscontrol.domain.ResponseFieldsFiltering.{AccessMode, import scala.jdk.CollectionConverters.* trait ResponseFieldsFiltering { - this: Logging => + this: RequestIdAwareLogging => private val responseFieldsRestrictions: Atomic[Option[ResponseFieldsRestrictions]] = Atomic(None: Option[ResponseFieldsRestrictions]) @@ -44,7 +44,7 @@ trait ResponseFieldsFiltering { case bytesRestResponse: BytesRestResponse => filterBytesRestResponse(bytesRestResponse, fieldsRestrictions) case otherResponse => - logger.warn("ResponseFields filtering is unavailable for this type of request") + noRequestIdLogger.warn("ResponseFields filtering is unavailable for this type of request") otherResponse } case None => diff --git a/es711x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala b/es711x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala index 0f26750588..da95de59a4 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.action.{ActionListener, ActionResponse} import org.elasticsearch.threadpool.ThreadPool @@ -37,7 +37,7 @@ sealed abstract class RorActionListener[T](val underlying: ActionListener[T]) ex final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionListener[T], correlationId: Eval[CorrelationId]) - extends RorActionListener[T](underlying) with Logging { + extends RorActionListener[T](underlying) with RequestIdAwareLogging { override def onFailure(e: Exception): Unit = { super.onFailure(adaptExceptionIfNeeded(e)) @@ -47,7 +47,7 @@ final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionLis ex match { case esException: ElasticsearchException => esException case other => - logger.error(s"[${correlationId.value.show}] Internal error.", other) + noRequestIdLogger.error(s"[${correlationId.value.show}] Internal error.", other) new ElasticsearchException(s"[${correlationId.value.show}] Internal error. See logs for details.") } } diff --git a/es711x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala b/es711x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala index 75048ebe7d..14e5e31c1b 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.http.HttpChannel import org.elasticsearch.rest.{AbstractRestChannel, RestChannel as EsRestChannel, RestRequest as EsRestRequest, RestResponse as EsRestResponse} import squants.information.{Bytes, Information} @@ -40,7 +40,7 @@ object RorRestChannel { final class RorRestChannel private(underlying: EsRestChannel, val restRequest: RorRestRequest) extends AbstractRestChannel(underlying.request(), true) with ResponseFieldsFiltering - with Logging { + with RequestIdAwareLogging { override def sendResponse(response: EsRestResponse): Unit = { ThreadRepo.removeRestChannel(this) diff --git a/es711x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala b/es711x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala index 6babc712b9..3c80750a25 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala @@ -18,16 +18,15 @@ package tech.beshu.ror.es.actions.rradmin import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.ConfigApi.ConfigResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAdminActionHandler extends Logging { +class RRAdminActionHandler extends RequestIdAwareLogging { private implicit val adminRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +51,7 @@ class RRAdminActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAdminResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAdminAction internal error", ex) + logger.error("RRAdminAction internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es711x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala b/es711x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala index c55835a1d0..ce45c6f48e 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala @@ -16,18 +16,15 @@ */ package tech.beshu.ror.es.actions.rrauthmock -import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.AuthMockApi.AuthMockResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier -import tech.beshu.ror.implicits.* +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAuthMockActionHandler extends Logging { +class RRAuthMockActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -53,7 +50,7 @@ class RRAuthMockActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAuthMockResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAuthMock internal error", ex) + logger.error("RRAuthMock internal error", ex) listener.onFailure(new Exception(ex)) } } diff --git a/es711x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala b/es711x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala index aa8bb31e67..640084c4ec 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestconfig import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.TestConfigApi.TestConfigResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestConfigActionHandler extends Logging { +class RRTestConfigActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +52,7 @@ class RRTestConfigActionHandler extends Logging { case Right(response) => listener.onResponse(new RRTestConfigResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRTestConfig internal error", ex) + logger.error(s"RRTestConfig internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es711x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala b/es711x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala index 5e42d55f7e..4d9a78443a 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.dlsfls import cats.data.StateT import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.DirectoryReader import org.elasticsearch.common.CheckedFunction import org.elasticsearch.common.util.concurrent.ThreadContext @@ -31,7 +31,7 @@ import java.io.IOException import java.util.function.{Function => JavaFunction} import scala.util.{Failure, Success, Try} -object RoleIndexSearcherWrapper extends Logging { +object RoleIndexSearcherWrapper extends RequestIdAwareLogging { val instance: JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] = new JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] { @@ -54,7 +54,7 @@ object RoleIndexSearcherWrapper extends Logging { } .map(r => (r, r)) case None => - logger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") + noRequestIdLogger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") Success((reader, reader)) } } @@ -66,13 +66,13 @@ object RoleIndexSearcherWrapper extends Logging { nel <- NonEmptyString.from(value) match { case Right(nel) => Success(nel) case Left(_) => - logger.debug("FLS: empty header value") + noRequestIdLogger.debug("FLS: empty header value") failure } fields <- transientFieldsFromHeaderValue.fromRawValue(nel) match { case result@Success(_) => result case Failure(ex) => - logger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) + noRequestIdLogger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) failure } } yield fields diff --git a/es711x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala b/es711x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala index 6f89904e92..91f62e2a36 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.dlsfls import com.google.common.collect.Iterators -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.codecs.StoredFieldsReader import org.apache.lucene.index.* import org.apache.lucene.index.StoredFieldVisitor.Status @@ -38,21 +38,21 @@ import scala.jdk.CollectionConverters.* import scala.util.Try private class RorDocumentFieldReader(reader: LeafReader, fieldsRestrictions: FieldsRestrictions) - extends SequentialStoredFieldsLeafReader(reader) with Logging { + extends SequentialStoredFieldsLeafReader(reader) with RequestIdAwareLogging { private val policy = new FieldsPolicy(fieldsRestrictions) private val remainingFieldsInfo = { val fInfos = in.getFieldInfos val newInfos = if (fInfos.asScala.isEmpty) { - logger.warn("original fields were empty! This is weird!") + noRequestIdLogger.warn("original fields were empty! This is weird!") fInfos } else { val remainingFields = fInfos.asScala.filter(f => policy.canKeep(f.name)).toSet new FieldInfos(remainingFields.toArray) } - logger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") - logger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") - logger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") + noRequestIdLogger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") newInfos } private val jsonPolicyBasedFilterer = new JsonPolicyBasedFilterer(policy) diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala index ceca9c8623..8054fc4a44 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.* import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest import org.elasticsearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest @@ -87,7 +87,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, threadPool: ThreadPool) (implicit generator: UniqueIdentifierGenerator, scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle(engines: Engines, esContext: EsContext): Task[Either[Error, Unit]] = { @@ -227,7 +227,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, case SearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case MultiSearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case _ => - logger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") + noRequestIdLogger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") regularRequestHandler.handle(new DummyCompositeIndicesEsRequestContext(request, esContext, aclContext, clusterService, threadPool)) } // rest diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala index a388bb0f9f..57be14c040 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.common.io.stream.StreamOutput import org.elasticsearch.common.xcontent.{ToXContent, ToXContentObject, XContentBuilder} @@ -45,7 +45,7 @@ import scala.util.{Failure, Success, Try} class CurrentUserMetadataRequestHandler(engine: Engine, esContext: EsContext) - extends Logging { + extends RequestIdAwareLogging { def handle(request: RequestContext.Aux[CurrentUserMetadataRequestBlockContext] with EsRequest[CurrentUserMetadataRequestBlockContext]): Task[Unit] = { engine.core.accessControl @@ -69,7 +69,7 @@ class CurrentUserMetadataRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(ex.asInstanceOf[Exception]) } } @@ -86,13 +86,13 @@ class CurrentUserMetadataRequestHandler(engine: Engine, )) } - private def onPassThrough(requestContext: RequestContext): Unit = { - logger.warn(s"[${requestContext.id.toRequestId.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") + private def onPassThrough(implicit requestContext: RequestContext): Unit = { + logger.warn(s"Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") esContext.listener.onFailure(createRorNotEnabledResponse()) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala index 2fb01dcc41..c5c44fda92 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala @@ -20,7 +20,7 @@ import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.RegularRequestResult @@ -49,7 +49,7 @@ class RegularRequestHandler(engine: Engine, esContext: EsContext, threadPool: ThreadPool) (implicit scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle[B <: BlockContext : BlockContextUpdater](request: RequestContext.Aux[B] with EsRequest[B]): Task[Unit] = { engine.core.accessControl @@ -85,7 +85,7 @@ class RegularRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(new Exception(ex)) } } @@ -99,7 +99,7 @@ class RegularRequestHandler(engine: Engine, case ModificationResult.ShouldBeInterrupted => onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case ModificationResult.CannotModify => - logger.error(s"[${request.id.toRequestId.show}] Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") + noRequestIdLogger.error(s"Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case CustomResponse(response) => respond(request, response) @@ -247,7 +247,7 @@ class RegularRequestHandler(engine: Engine, esContext.listener.onResponse(response) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } \ No newline at end of file diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala index f4f832dedc..bfc421bdd5 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.index.query.{AbstractQueryBuilder, QueryBuilder, QueryBuilders} import org.elasticsearch.search.aggregations.AggregatorFactories @@ -40,7 +40,7 @@ import tech.beshu.ror.implicits.* import java.util.UUID import scala.jdk.CollectionConverters.* -object SearchRequestOps extends Logging { +object SearchRequestOps extends RequestIdAwareLogging { implicit class QueryBuilderOps(val builder: Option[QueryBuilder]) extends AnyVal { @@ -52,7 +52,7 @@ object SearchRequestOps extends Logging { val modifiedQuery: AbstractQueryBuilder[_] = provideNewQueryWithAppliedFilter(builder, filterQuery) Some(modifiedQuery) case None => - logger.debug(s"[${requestId.show}] No filter applied to query.") + logger.debug(s"No filter applied to query.") builder } } @@ -92,7 +92,7 @@ object SearchRequestOps extends Logging { case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, requestId) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) disableCaching(requestId) case BasedOnBlockContextOnly.NotAllowedFieldsUsed(notAllowedFields) => modifyNotAllowedFieldsInRequest(notAllowedFields) @@ -138,8 +138,8 @@ object SearchRequestOps extends Logging { } } - private def disableCaching(requestId: RequestContext.Id) = { - logger.debug(s"[${requestId.show}] ACL uses context header for fields rule, will disable request cache for SearchRequest") + private def disableCaching(implicit requestId: RequestContext.Id) = { + logger.debug(s"ACL uses context header for fields rule, will disable request cache for SearchRequest") request.requestCache(false) } } diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala index 9de832edcc..74790fb1fd 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala @@ -17,7 +17,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.action.support.IndicesOptions.WildcardStates import org.elasticsearch.action.{CompositeIndicesRequest, IndicesRequest} @@ -34,7 +33,7 @@ import scala.jdk.CollectionConverters.* abstract class BaseEsRequestContext[B <: BlockContext](esContext: EsContext, clusterService: RorClusterService) - extends RequestContext with Logging { + extends RequestContext { override type BLOCK_CONTEXT = B diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala index ae8abbe1f5..0ee2967364 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala @@ -18,7 +18,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -26,8 +25,9 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import scala.util.Try +import tech.beshu.ror.utils.RequestIdAwareLogging -trait EsRequest[B <: BlockContext] extends Logging { +trait EsRequest[B <: BlockContext] extends RequestIdAwareLogging { implicit def threadPool: ThreadPool final def modifyUsing(blockContext: B): ModificationResult = { @@ -35,7 +35,7 @@ trait EsRequest[B <: BlockContext] extends Logging { Try(modifyRequest(blockContext)) .fold( ex => { - logger.error(s"[${blockContext.requestContext.id.show}] Cannot modify request with filtered data", ex) + logger.error(s"Cannot modify request with filtered data", ex)(blockContext) ModificationResult.CannotModify }, identity diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala index c6a9dcbefd..f773b3efb1 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala @@ -51,7 +51,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest private def discoverDataStreams() = { val dataStreams = dataStreamsFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered data streams: ${dataStreams.show}") + logger.debug(s"Discovered data streams: ${dataStreams.show}") dataStreams } @@ -59,7 +59,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest val backingIndices = backingIndicesFrom(actionRequest) backingIndices match { case BackingIndices.IndicesInvolved(filteredIndices, _) => - logger.debug(s"[${id.show}] Discovered indices: ${filteredIndices.show}") + logger.debug(s"Discovered indices: ${filteredIndices.show}") case BackingIndices.IndicesNotInvolved => } backingIndices diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala index c091179cb6..d150709314 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala @@ -85,7 +85,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: case Some(indices) => update(actionRequest, indices, blockContext.filter, blockContext.fieldLevelSecurity) case None => - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -101,7 +101,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } \ No newline at end of file diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala index 71d462de57..48014e1bdc 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala @@ -73,7 +73,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, } yield update(actionRequest, filteredIndices, allAllowedIndices) result.getOrElse { - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -86,7 +86,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala index 95d882c3b5..f607c0e347 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala @@ -50,7 +50,7 @@ abstract class BaseRepositoriesEsRequestContext[R <: ActionRequest](actionReques case Some(repositories) => update(actionRequest, repositories) case None => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") ShouldBeInterrupted } } diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala index b3b1d66238..7ef0f32014 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala @@ -42,7 +42,7 @@ abstract class BaseSingleIndexEsRequestContext[R <: ActionRequest](actionRequest filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } update(request, filteredIndices.head) } diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala index b5ab70fe7a..c1b2e7ea27 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala @@ -62,7 +62,7 @@ class BulkEsRequestContext(actionRequest: BulkRequest, case (_, _) => ShouldBeInterrupted } } else { - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because origin request contained different " + + logger.error(s"Cannot alter MultiGetRequest request, because origin request contained different " + s"number of requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } @@ -90,18 +90,18 @@ class BulkEsRequestContext(actionRequest: BulkRequest, updateRequestWithIndices(request, nel) Modified case None => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because empty list of indices was found") + logger.error(s"Cannot alter MultiGetRequest request, because empty list of indices was found") ShouldBeInterrupted } case Indices.NotFound => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because no allowed indices were found") + logger.error(s"Cannot alter MultiGetRequest request, because no allowed indices were found") ShouldBeInterrupted } } private def updateRequestWithIndices(request: DocWriteRequest[_], indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } request.index(indices.head.stringify) } diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala index 75a75fcef5..96a043b298 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala @@ -53,14 +53,14 @@ class BulkShardEsRequestContext(actionRequest: BulkShardRequest, case Success(_) => Modified case Failure(ex) => - logger.error(s"[${id.show}] Cannot modify BulkShardRequest", ex) + logger.error(s"Cannot modify BulkShardRequest", ex) CannotModify } } private def tryUpdate(request: BulkShardRequest, indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } val singleIndex = indices.head val uuid = clusterService.indexOrAliasUuids(singleIndex.name).toList.head diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala index 65a168092a..158ac485a5 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala @@ -45,14 +45,14 @@ class ClusterAllocationExplainEsRequestContext(actionRequest: ClusterAllocationE getRequestedIndexFrom(request) match { case Some(_) => if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateIndexIn(request, filteredIndices.head) Modified case None if filteredIndices.exists(_.name === ClusterIndexName.Local.wildcard) => Modified case None => - logger.error(s"[${id.show}] Cluster allocation explain request without index name is unavailable when block contains `indices` rule") + logger.error(s"Cluster allocation explain request without index name is unavailable when block contains `indices` rule") ShouldBeInterrupted } } diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala index 3582caec0a..3a7e407d21 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala @@ -69,7 +69,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, updateAliases(actionRequest, aliases) UpdateResponse.sync(updateAliasesResponse(aliases.includedOnly, _)) case None => - logger.error(s"[${id.show}] At least one alias and one index has to be allowed. " + + logger.error(s"At least one alias and one index has to be allowed. " + s"Found allowed indices: [${blockContext.indices.show}]." + s"Found allowed aliases: [${blockContext.aliases.show}]") ShouldBeInterrupted @@ -117,7 +117,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, .indices().asSafeSet .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } @@ -125,7 +125,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, val aliases = rawRequestAliasesSet(request) .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered aliases: ${aliases.show}") + logger.debug(s"Discovered aliases: ${aliases.show}") aliases } diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala index abb85d42b7..f9e2c87e53 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala @@ -55,7 +55,7 @@ class IndicesAliasesEsRequestContext(actionRequest: IndicesAliasesRequest, if (originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala index 05b70606b9..37dd50452b 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala @@ -119,7 +119,7 @@ class MultiGetEsRequestContext(actionRequest: MultiGetRequest, case Nil => updateItemWithNonExistingIndex(item) case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } item.index(index.stringify) } diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala index 989956d79a..9e13edee8d 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala @@ -78,7 +78,7 @@ class MultiSearchEsRequestContext(actionRequest: MultiSearchRequest, } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala index 9191e33b66..5a61356f48 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala @@ -47,7 +47,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { request.getRequests.removeIf { request => removeOrAlter(request, filteredIndices.toCovariantSet) } if (request.getRequests.asScala.isEmpty) { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") ShouldBeInterrupted } else { Modified @@ -63,7 +63,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, true case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") } request.index(index.stringify) false diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala index c411df93c5..c7b99f6e85 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala @@ -52,7 +52,7 @@ class PutRollupJobEsRequestContext private(actionRequest: ActionRequest, if(originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala index 141d9db788..fff8ed58bb 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala @@ -49,7 +49,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (tryUpdate(actionRequest, filteredIndices)) Modified else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") ShouldBeInterrupted } } diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala index 489d0187bc..c42dfc3b78 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala @@ -58,10 +58,10 @@ class ReindexEsRequestContext(actionRequest: ReindexRequest, Modified } else { if (!isDestinationIndexOnFilteredIndicesList) { - logger.info(s"[${id.show}] Destination index of _reindex request is forbidden") + logger.info(s"Destination index of _reindex request is forbidden") } if (!isSearchRequestComposedOnlyOfAllowedIndices) { - logger.info(s"[${id.show}] At least one index from sources indices list of _reindex request is forbidden") + logger.info(s"At least one index from sources indices list of _reindex request is forbidden") } ShouldBeInterrupted } diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala index 2c1b0014e0..97b8ccd9c5 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala @@ -74,7 +74,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo request } case Left(_) => - logger.debug(s"[${id.show}] Cannot parse SQL statement - we can pass it though, because ES is going to reject it") + logger.debug(s"Cannot parse SQL statement - we can pass it though, because ES is going to reject it") request } } @@ -85,7 +85,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DataStreamsStatsEsRequestContext.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DataStreamsStatsEsRequestContext.scala index 3cbf6360ed..3e2648b17b 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DataStreamsStatsEsRequestContext.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DataStreamsStatsEsRequestContext.scala @@ -44,7 +44,7 @@ private[datastreams] class DataStreamsStatsEsRequestContext private(actionReques if (modifyActionRequest(blockContext)) { ModificationResult.Modified } else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") ModificationResult.ShouldBeInterrupted } } diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DeleteDataStreamEsRequestContext.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DeleteDataStreamEsRequestContext.scala index b4491990f0..cf135bdf6a 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DeleteDataStreamEsRequestContext.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DeleteDataStreamEsRequestContext.scala @@ -44,7 +44,7 @@ private[datastreams] class DeleteDataStreamEsRequestContext private(actionReques if (modifyActionRequest(blockContext)) { ModificationResult.Modified } else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") ModificationResult.ShouldBeInterrupted } } diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/GetDataStreamEsRequestContext.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/GetDataStreamEsRequestContext.scala index 26c210c613..c2740720de 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/GetDataStreamEsRequestContext.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/GetDataStreamEsRequestContext.scala @@ -64,7 +64,7 @@ private[datastreams] class GetDataStreamEsRequestContext(actionRequest: ActionRe r } } else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") ModificationResult.ShouldBeInterrupted } } diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala index 0c67384c1e..d7e743e648 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CleanupRepositoryEsRequestContext(actionRequest: CleanupRepositoryRequest, override protected def update(request: CleanupRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala index 44b7d78dfd..d09015139b 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CreateRepositoryEsRequestContext(actionRequest: PutRepositoryRequest, override protected def update(request: PutRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala index eaf9334872..0cf32e1bea 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class DeleteRepositoryEsRequestContext(actionRequest: DeleteRepositoryRequest, override protected def update(request: DeleteRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala index cee0bffd4c..d1410eff3d 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class VerifyRepositoryEsRequestContext(actionRequest: VerifyRepositoryRequest, override protected def update(request: VerifyRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala index ead4fcf250..20501516d5 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala @@ -68,32 +68,32 @@ class CreateSnapshotEsRequestContext(actionRequest: CreateSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala index a56aba660e..621d744767 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala @@ -60,7 +60,7 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -71,14 +71,14 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, .toRight(()) } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala index 58122fb44f..782a54d7df 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala @@ -69,7 +69,7 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, case r => r } case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -81,14 +81,14 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.mkString(",")}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.mkString(",")}]") } Right(repository) } diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala index 88887db96c..156deb5b80 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala @@ -63,7 +63,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -75,7 +75,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") } Right(snapshot) } @@ -88,7 +88,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala index 44ee8397ec..e522e440f1 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala @@ -100,12 +100,12 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { val repositories = blockContext.repositories if (allRepositoriesRequested(repositories)) { Right(RepositoryName.All) @@ -115,7 +115,7 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala index 902512a1fc..453687e837 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.GetComposableIndexTemplateAction import org.elasticsearch.cluster.metadata import org.elasticsearch.cluster.metadata.ComposableIndexTemplate @@ -103,7 +103,7 @@ class GetComposableIndexTemplateEsRequestContext(actionRequest: GetComposableInd } -private[templates] object GetComposableIndexTemplateEsRequestContext extends Logging { +private[templates] object GetComposableIndexTemplateEsRequestContext extends RequestIdAwareLogging { def filter(templates: Map[String, ComposableIndexTemplate], usingTemplate: Set[Template] => Set[Template]) diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala index c170a8c87d..d49f293358 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.{GetIndexTemplatesRequest, GetIndexTemplatesResponse} import org.elasticsearch.cluster.metadata.{AliasMetadata, IndexTemplateMetadata} import org.elasticsearch.common.collect.ImmutableOpenMap @@ -100,7 +100,7 @@ class GetTemplatesEsRequestContext(actionRequest: GetIndexTemplatesRequest, } -private[templates] object GetTemplatesEsRequestContext extends Logging { +private[templates] object GetTemplatesEsRequestContext extends RequestIdAwareLogging { def filter(templates: Iterable[IndexTemplateMetadata], usingTemplate: Set[Template] => Set[Template]) diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala index a8951de5b1..32116d8212 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala @@ -72,7 +72,7 @@ class MultiSearchTemplateEsRequestContext private(actionRequest: ActionRequest w } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala index e6f6d8916e..434787a686 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala @@ -55,7 +55,7 @@ class SimulateIndexTemplateRequestEsRequestContext(actionRequest: SimulateIndexT filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateRequest(request, filteredIndices.head, allAllowedIndices) } diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala index fbc4cf6776..46ed6e7a95 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala @@ -109,7 +109,7 @@ class SimulateExistingTemplateRequestEsRequestContext(existingTemplateName: Temp case Some(_) => updateResponse(namePatterns.toList, blockContext.allAllowedIndices.toList) case None => - logger.info(s"[${id.show}] User has no access to template ${existingTemplateName.show}") + logger.info(s"User has no access to template ${existingTemplateName.show}") ModificationResult.ShouldBeInterrupted } case other => diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala index 22a0c6791a..e08a2fbb72 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.queries import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.index.query.* import org.joor.Reflect.on import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.RequestFieldsUsage @@ -32,7 +32,7 @@ trait QueryFieldsUsage[QUERY <: QueryBuilder] { def fieldsIn(query: QUERY): RequestFieldsUsage } -object QueryFieldsUsage extends Logging { +object QueryFieldsUsage extends RequestIdAwareLogging { def apply[QUERY <: QueryBuilder](implicit ev: QueryFieldsUsage[QUERY]): QueryFieldsUsage[QUERY] = ev implicit class Ops[QUERY <: QueryBuilder : QueryFieldsUsage](val query: QUERY) { @@ -65,7 +65,7 @@ object QueryFieldsUsage extends Logging { Option(on(query).call("getFieldName").get[String]) match { case Some(fieldName: String) => UsingFields(NonEmptyList.one(UsedField(fieldName))) case _ => - logger.debug(s"Cannot extract fields for terms set query") + noRequestIdLogger.debug(s"Cannot extract fields for terms set query") CannotExtractFields } } @@ -93,7 +93,7 @@ object QueryFieldsUsage extends Logging { case builder: TermsSetQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder: WildcardQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder => - logger.debug(s"Cannot extract fields for query: ${builder.getName}") + noRequestIdLogger.debug(s"Cannot extract fields for query: ${builder.getName}") CannotExtractFields } diff --git a/es711x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala b/es711x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala index 0998bb9a5b..b4671e9e4d 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.handler.response import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.FieldsRestrictions import tech.beshu.ror.accesscontrol.domain.Header @@ -26,17 +26,17 @@ import tech.beshu.ror.accesscontrol.headerValues.transientFieldsToHeaderValue import tech.beshu.ror.accesscontrol.request.RequestContext import tech.beshu.ror.implicits.* -object FLSContextHeaderHandler extends Logging { +object FLSContextHeaderHandler extends RequestIdAwareLogging { def addContextHeader(threadPool: ThreadPool, - fieldsRestrictions: FieldsRestrictions, - requestId: RequestContext.Id): Unit = { + fieldsRestrictions: FieldsRestrictions) + (implicit requestId: RequestContext.Id): Unit = { val threadContext = threadPool.getThreadContext val header = createContextHeader(fieldsRestrictions) Option(threadContext.getHeader(header.name.value.value)) match { case None => implicit val show = headerShow - logger.debug(s"[${requestId.show}] Adding thread context header required by lucene. Header: '${header.show}'") + logger.debug(s"Adding thread context header required by lucene. Header: '${header.show}'") threadContext.putHeader(header.name.value.value, header.value.value) case Some(_) => } diff --git a/es711x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala b/es711x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala index 26df1d5bb9..2ce5662a4b 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.admin.indices.template.get.{GetComponentTemplateAction, GetComposableIndexTemplateAction} import org.elasticsearch.action.admin.indices.template.put.{PutComponentTemplateAction, PutComposableIndexTemplateAction} @@ -45,7 +45,7 @@ import scala.jdk.CollectionConverters.* final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJsonParserFactory)(using Clock) extends DataStreamService - with Logging { + with RequestIdAwareLogging { override def checkDataStreamExists(dataStreamName: DataStreamName.Full): Task[Boolean] = execute { val enhancedActionType = client.findActionUnsafe[ActionResponse]("indices:admin/data_stream/get") @@ -218,11 +218,11 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ response <- Task.measure( task = Task.delay(nodeClient.execute(action, request).actionGet()), logTimeMeasurement = duration => Task.delay { - logger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") + noRequestIdLogger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") } ) _ <- Task.delay { - logger.debug(s"Action ${action.name()} response: ${response.toString}") + noRequestIdLogger.debug(s"Action ${action.name()} response: ${response.toString}") } } yield response } @@ -230,7 +230,7 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ def executeAck[REQUEST <: ActionRequest, RESPONSE <: AcknowledgedResponse](action: ActionType[RESPONSE], request: REQUEST): Task[RESPONSE] = { executeT(action, request) - .tapEval(response => Task.delay(logger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) + .tapEval(response => Task.delay(noRequestIdLogger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) } private def supportedActions: Map[ActionType[ActionResponse], TransportAction[ActionRequest, ActionResponse]] = { diff --git a/es711x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala b/es711x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala index 18490a232c..b65ba21df7 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.support.WriteRequest.RefreshPolicy import org.elasticsearch.client.node.NodeClient @@ -38,7 +38,7 @@ import scala.jdk.CollectionConverters.* class EsIndexJsonContentService(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexJsonContentService - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -63,14 +63,14 @@ class EsIndexJsonContentService(client: NodeClient, Option(response.getSourceAsMap) match { case Some(map) => val source = map.asScala.toMap.asStringMap - logger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") Right(source) case None => - logger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") + noRequestIdLogger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") Right(Map.empty[String, String]) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(ContentNotFound) } } @@ -78,7 +78,7 @@ class EsIndexJsonContentService(client: NodeClient, .onErrorRecover { case _: ResourceNotFoundException => Left(ContentNotFound) case ex => - logger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) Left(CannotReachContentSource) } } @@ -104,14 +104,14 @@ class EsIndexJsonContentService(client: NodeClient, case status if status / 100 == 2 => Right(()) case status => - logger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") Left(CannotWriteToIndex) } } .executeOn(RorSchedulers.blockingScheduler) .onErrorRecover { case ex => - logger.error(s"Cannot write to document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]", ex) Left(CannotWriteToIndex) } } diff --git a/es711x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala b/es711x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala index 304396cb5f..28c1ff97b4 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala @@ -21,7 +21,7 @@ import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task import monix.execution.CancelablePromise -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction.ResolvedIndex @@ -64,7 +64,7 @@ class EsServerBasedRorClusterService(nodeName: String, nodeClient: NodeClient, threadPool: ThreadPool) extends RorClusterService - with Logging { + with RequestIdAwareLogging { import EsServerBasedRorClusterService.* @@ -155,7 +155,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractAccessibilityFrom) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify get request. Blocking document", ex) + logger.error(s"Could not verify get request. Blocking document", ex)(id) Inaccessible } } @@ -167,7 +167,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractResultsFromSearchResponse) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify documents returned by multi get response. Blocking all returned documents", ex) + logger.error(s"Could not verify documents returned by multi get response. Blocking all returned documents", ex)(id) blockAllDocsReturned(documents) } .map(results => zip(results, documents)) @@ -247,7 +247,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService): Task[List[FullRemoteDataStreamWithAliases]] = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -297,7 +297,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService) = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -366,7 +366,7 @@ class EsServerBasedRorClusterService(nodeName: String, } } case None => - logger.error("Cannot supply Snapshots Service. Please, report the issue!!!") + noRequestIdLogger.error("Cannot supply Snapshots Service. Please, report the issue!!!") Task.now(Set.empty[Snapshot]) } } diff --git a/es711x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala b/es711x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala index 84a97818fe..b5ce8bc2a6 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.services import cats.data.NonEmptyList -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.DocWriteRequest import org.elasticsearch.action.bulk.{BackoffPolicy, BulkProcessor, BulkRequest, BulkResponse} import org.elasticsearch.action.index.IndexRequest @@ -39,7 +39,7 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, (using Clock) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { private val bulkProcessor = BulkProcessor @@ -76,25 +76,25 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, private class AuditSinkBulkProcessorListener extends BulkProcessor.Listener { override def beforeBulk(executionId: Long, request: BulkRequest): Unit = { - logger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") + noRequestIdLogger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") } override def afterBulk(executionId: Long, request: BulkRequest, response: BulkResponse): Unit = { if (response.hasFailures) { - logger.error("Some failures flushing the BulkProcessor: ") + noRequestIdLogger.error("Some failures flushing the BulkProcessor: ") response .getItems.to(LazyList) .filter(_.isFailed) .map(_.getFailureMessage) .groupBy(identity) .foreach { case (message, stream) => - logger.error(s"${stream.size}x: $message") + noRequestIdLogger.error(s"${stream.size}x: $message") } } } override def afterBulk(executionId: Long, request: BulkRequest, failure: Throwable): Unit = { - logger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) + noRequestIdLogger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) } } diff --git a/es711x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala b/es711x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala index a8def0ec7a..b3c5593c36 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala @@ -22,7 +22,7 @@ import org.apache.http.auth.{AuthScope, Credentials, UsernamePasswordCredentials import org.apache.http.conn.ssl.NoopHostnameVerifier import org.apache.http.impl.client.BasicCredentialsProvider import org.apache.http.impl.nio.client.HttpAsyncClientBuilder -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.* import org.elasticsearch.client.RestClient.FailureListener import tech.beshu.ror.accesscontrol.audit.sink.AuditDataStreamCreator @@ -38,7 +38,7 @@ import scala.collection.parallel.CollectionConverters.* final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient]) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { override def submit(indexName: IndexName.Full, documentId: String, jsonRecord: String) (implicit requestId: RequestId): Unit = { @@ -77,21 +77,21 @@ final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient] override def onSuccess(response: Response): Unit = { response.getStatusLine.getStatusCode / 100 match { case 2 => // 2xx - logger.debug(s"[${requestId.show}] Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") + logger.debug(s"Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") case _ => - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") } } override def onFailure(ex: Exception): Unit = { - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId]", ex) + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId]", ex) } } override val dataStreamCreator: AuditDataStreamCreator = new AuditDataStreamCreator(clients.map(new RestClientDataStreamService(_))) } -object RestClientAuditSinkService extends Logging { +object RestClientAuditSinkService extends RequestIdAwareLogging { def create(remoteCluster: AuditCluster.RemoteAuditCluster): RestClientAuditSinkService = { remoteCluster.mode match { @@ -122,7 +122,7 @@ object RestClientAuditSinkService extends Logging { .setFailureListener( new FailureListener { override def onFailure(node: Node): Unit = { - logger.debug( + noRequestIdLogger.debug( s"[AUDIT] Node marked dead: ${node.getHost.getSchemeName}://${node.getHost.getHostName}:${node.getHost.getPort}. The client will attempt failover.", ) } diff --git a/es711x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala b/es711x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala index a9f97756f7..a10c1a2aeb 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.Channel import io.netty.handler.ssl.NotSslRecordException -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.network.NetworkService import org.elasticsearch.common.settings.{ClusterSettings, Settings} import org.elasticsearch.common.util.BigArrays @@ -41,7 +41,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, sharedGroupFactory: SharedGroupFactory, fipsCompliant: Boolean) extends Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, ssl.clientAuthenticationEnabled) @@ -49,7 +49,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, override def onException(channel: HttpChannel, cause: Exception): Unit = { if (!this.lifecycle.started) return - else if (cause.getCause.isInstanceOf[NotSslRecordException]) logger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) + else if (cause.getCause.isInstanceOf[NotSslRecordException]) noRequestIdLogger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) else super.onException(channel, cause) channel.close() } diff --git a/es711x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala b/es711x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala index cd73e6310c..d8c0dbbce8 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.* import io.netty.handler.ssl.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.Version import org.elasticsearch.cluster.node.DiscoveryNode import org.elasticsearch.common.io.stream.NamedWriteableRegistry @@ -46,7 +46,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, sharedGroupFactory: SharedGroupFactory, fipsCompliant: Boolean) extends Netty4Transport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = SSLCertHelper.prepareClientSSLContext(ssl, fipsCompliant, ssl.certificateVerificationEnabled) private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, clientAuthenticationEnabled = false) @@ -77,7 +77,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, override def exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable): Unit = { if (cause.isInstanceOf[NotSslRecordException] || (cause.getCause != null && cause.getCause.isInstanceOf[NotSslRecordException])) { - logger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") + noRequestIdLogger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") ctx.channel.close } else { super.exceptionCaught(ctx, cause) diff --git a/es711x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala b/es711x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala index 8a27470274..058c456f9c 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.utils import cats.Show import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.client.node.NodeClient import org.elasticsearch.rest.* @@ -35,7 +35,7 @@ import java.util import scala.util.Try class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandler) - extends RestHandler with Logging { + extends RestHandler with RequestIdAwareLogging { private val wrapped = doPrivileged { wrapSomeActions(underlying) @@ -99,11 +99,11 @@ class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandle private def logError(error: AuthorizationValueError): Unit = { { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorSanitizedShow - logger.warn(s"The incoming request was malformed. Cause: ${error.show}") + noRequestIdLogger.warn(s"The incoming request was malformed. Cause: ${error.show}") } if (logger.delegate.isDebugEnabled()) { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorWithDetailsShow - logger.debug(s"Malformed request detailed cause: ${error.show}") + noRequestIdLogger.debug(s"Malformed request detailed cause: ${error.show}") } } diff --git a/es711x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala b/es711x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala index 5ab1e35742..a9af8f710a 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala @@ -16,13 +16,13 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.settings.Settings import tech.beshu.ror.tools.core.patches.PatchingVerifier import tech.beshu.ror.tools.core.patches.PatchingVerifier.Error.{CannotVerifyIfPatched, EsNotPatched} import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -object EsPatchVerifier extends Logging { +object EsPatchVerifier extends RequestIdAwareLogging { def verify(settings: Settings): Unit = doPrivileged { pathHomeFrom(settings).flatMap(PatchingVerifier.verify) match { @@ -30,7 +30,7 @@ object EsPatchVerifier extends Logging { case Left(e@EsNotPatched(_)) => throw new IllegalStateException(e.message) case Left(e@CannotVerifyIfPatched(_)) => - logger.warn(e.message) + noRequestIdLogger.warn(e.message) } } diff --git a/es714x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es714x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index dfc3613b7e..06a2f90f96 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.support.{ActionFilter, ActionFilterChain} import org.elasticsearch.action.{ActionListener, ActionRequest, ActionResponse} import org.elasticsearch.client.node.NodeClient @@ -62,7 +62,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, rorEsConfig: ReadonlyRestEsConfig) (implicit environmentConfig: EnvironmentConfig) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = environmentConfig.uniqueIdentifierGenerator @@ -212,12 +212,12 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def handleRorNotReadyYet(esContext: EsContext): Unit = { - logger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") + noRequestIdLogger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") rorNotAvailableRequestHandler.handleRorNotReadyYet(esContext) } private def handleRorFailedToStart(esContext: EsContext): Unit = { - logger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") + noRequestIdLogger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") rorNotAvailableRequestHandler.handleRorFailedToStart(esContext) } @@ -239,7 +239,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def logAndSetStartingFailureState(failure: StartingFailure): Unit = { - logger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) + noRequestIdLogger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) rorInstanceState.set(RorInstanceStartingState.NotStarted(failure)) } } diff --git a/es714x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala b/es714x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala index 7f92461f08..72c14bf252 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.xcontent.cbor.CborXContent import org.elasticsearch.common.xcontent.json.JsonXContent import org.elasticsearch.common.xcontent.smile.SmileXContent @@ -29,7 +29,7 @@ import tech.beshu.ror.accesscontrol.domain.ResponseFieldsFiltering.{AccessMode, import scala.jdk.CollectionConverters.* trait ResponseFieldsFiltering { - this: Logging => + this: RequestIdAwareLogging => private val responseFieldsRestrictions: Atomic[Option[ResponseFieldsRestrictions]] = Atomic(None: Option[ResponseFieldsRestrictions]) @@ -44,7 +44,7 @@ trait ResponseFieldsFiltering { case bytesRestResponse: BytesRestResponse => filterBytesRestResponse(bytesRestResponse, fieldsRestrictions) case otherResponse => - logger.warn("ResponseFields filtering is unavailable for this type of request") + noRequestIdLogger.warn("ResponseFields filtering is unavailable for this type of request") otherResponse } case None => diff --git a/es714x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala b/es714x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala index 0f26750588..da95de59a4 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.action.{ActionListener, ActionResponse} import org.elasticsearch.threadpool.ThreadPool @@ -37,7 +37,7 @@ sealed abstract class RorActionListener[T](val underlying: ActionListener[T]) ex final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionListener[T], correlationId: Eval[CorrelationId]) - extends RorActionListener[T](underlying) with Logging { + extends RorActionListener[T](underlying) with RequestIdAwareLogging { override def onFailure(e: Exception): Unit = { super.onFailure(adaptExceptionIfNeeded(e)) @@ -47,7 +47,7 @@ final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionLis ex match { case esException: ElasticsearchException => esException case other => - logger.error(s"[${correlationId.value.show}] Internal error.", other) + noRequestIdLogger.error(s"[${correlationId.value.show}] Internal error.", other) new ElasticsearchException(s"[${correlationId.value.show}] Internal error. See logs for details.") } } diff --git a/es714x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala b/es714x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala index 75048ebe7d..14e5e31c1b 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.http.HttpChannel import org.elasticsearch.rest.{AbstractRestChannel, RestChannel as EsRestChannel, RestRequest as EsRestRequest, RestResponse as EsRestResponse} import squants.information.{Bytes, Information} @@ -40,7 +40,7 @@ object RorRestChannel { final class RorRestChannel private(underlying: EsRestChannel, val restRequest: RorRestRequest) extends AbstractRestChannel(underlying.request(), true) with ResponseFieldsFiltering - with Logging { + with RequestIdAwareLogging { override def sendResponse(response: EsRestResponse): Unit = { ThreadRepo.removeRestChannel(this) diff --git a/es714x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala b/es714x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala index 6babc712b9..3c80750a25 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala @@ -18,16 +18,15 @@ package tech.beshu.ror.es.actions.rradmin import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.ConfigApi.ConfigResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAdminActionHandler extends Logging { +class RRAdminActionHandler extends RequestIdAwareLogging { private implicit val adminRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +51,7 @@ class RRAdminActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAdminResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAdminAction internal error", ex) + logger.error("RRAdminAction internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es714x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala b/es714x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala index c55835a1d0..ce45c6f48e 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala @@ -16,18 +16,15 @@ */ package tech.beshu.ror.es.actions.rrauthmock -import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.AuthMockApi.AuthMockResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier -import tech.beshu.ror.implicits.* +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAuthMockActionHandler extends Logging { +class RRAuthMockActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -53,7 +50,7 @@ class RRAuthMockActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAuthMockResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAuthMock internal error", ex) + logger.error("RRAuthMock internal error", ex) listener.onFailure(new Exception(ex)) } } diff --git a/es714x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala b/es714x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala index aa8bb31e67..640084c4ec 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestconfig import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.TestConfigApi.TestConfigResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestConfigActionHandler extends Logging { +class RRTestConfigActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +52,7 @@ class RRTestConfigActionHandler extends Logging { case Right(response) => listener.onResponse(new RRTestConfigResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRTestConfig internal error", ex) + logger.error(s"RRTestConfig internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es714x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala b/es714x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala index 494e9150b4..98cc0c945d 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.dlsfls import cats.data.StateT import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.DirectoryReader import org.elasticsearch.common.util.concurrent.ThreadContext import org.elasticsearch.core.CheckedFunction @@ -31,7 +31,7 @@ import java.io.IOException import java.util.function.{Function => JavaFunction} import scala.util.{Failure, Success, Try} -object RoleIndexSearcherWrapper extends Logging { +object RoleIndexSearcherWrapper extends RequestIdAwareLogging { val instance: JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] = new JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] { @@ -54,7 +54,7 @@ object RoleIndexSearcherWrapper extends Logging { } .map(r => (r, r)) case None => - logger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") + noRequestIdLogger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") Success((reader, reader)) } } @@ -66,13 +66,13 @@ object RoleIndexSearcherWrapper extends Logging { nel <- NonEmptyString.from(value) match { case Right(nel) => Success(nel) case Left(_) => - logger.debug("FLS: empty header value") + noRequestIdLogger.debug("FLS: empty header value") failure } fields <- transientFieldsFromHeaderValue.fromRawValue(nel) match { case result@Success(_) => result case Failure(ex) => - logger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) + noRequestIdLogger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) failure } } yield fields diff --git a/es714x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala b/es714x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala index 6f89904e92..91f62e2a36 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.dlsfls import com.google.common.collect.Iterators -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.codecs.StoredFieldsReader import org.apache.lucene.index.* import org.apache.lucene.index.StoredFieldVisitor.Status @@ -38,21 +38,21 @@ import scala.jdk.CollectionConverters.* import scala.util.Try private class RorDocumentFieldReader(reader: LeafReader, fieldsRestrictions: FieldsRestrictions) - extends SequentialStoredFieldsLeafReader(reader) with Logging { + extends SequentialStoredFieldsLeafReader(reader) with RequestIdAwareLogging { private val policy = new FieldsPolicy(fieldsRestrictions) private val remainingFieldsInfo = { val fInfos = in.getFieldInfos val newInfos = if (fInfos.asScala.isEmpty) { - logger.warn("original fields were empty! This is weird!") + noRequestIdLogger.warn("original fields were empty! This is weird!") fInfos } else { val remainingFields = fInfos.asScala.filter(f => policy.canKeep(f.name)).toSet new FieldInfos(remainingFields.toArray) } - logger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") - logger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") - logger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") + noRequestIdLogger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") newInfos } private val jsonPolicyBasedFilterer = new JsonPolicyBasedFilterer(policy) diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala index ceca9c8623..8054fc4a44 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.* import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest import org.elasticsearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest @@ -87,7 +87,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, threadPool: ThreadPool) (implicit generator: UniqueIdentifierGenerator, scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle(engines: Engines, esContext: EsContext): Task[Either[Error, Unit]] = { @@ -227,7 +227,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, case SearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case MultiSearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case _ => - logger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") + noRequestIdLogger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") regularRequestHandler.handle(new DummyCompositeIndicesEsRequestContext(request, esContext, aclContext, clusterService, threadPool)) } // rest diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala index a388bb0f9f..57be14c040 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.common.io.stream.StreamOutput import org.elasticsearch.common.xcontent.{ToXContent, ToXContentObject, XContentBuilder} @@ -45,7 +45,7 @@ import scala.util.{Failure, Success, Try} class CurrentUserMetadataRequestHandler(engine: Engine, esContext: EsContext) - extends Logging { + extends RequestIdAwareLogging { def handle(request: RequestContext.Aux[CurrentUserMetadataRequestBlockContext] with EsRequest[CurrentUserMetadataRequestBlockContext]): Task[Unit] = { engine.core.accessControl @@ -69,7 +69,7 @@ class CurrentUserMetadataRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(ex.asInstanceOf[Exception]) } } @@ -86,13 +86,13 @@ class CurrentUserMetadataRequestHandler(engine: Engine, )) } - private def onPassThrough(requestContext: RequestContext): Unit = { - logger.warn(s"[${requestContext.id.toRequestId.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") + private def onPassThrough(implicit requestContext: RequestContext): Unit = { + logger.warn(s"Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") esContext.listener.onFailure(createRorNotEnabledResponse()) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala index 2fb01dcc41..c5c44fda92 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala @@ -20,7 +20,7 @@ import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.RegularRequestResult @@ -49,7 +49,7 @@ class RegularRequestHandler(engine: Engine, esContext: EsContext, threadPool: ThreadPool) (implicit scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle[B <: BlockContext : BlockContextUpdater](request: RequestContext.Aux[B] with EsRequest[B]): Task[Unit] = { engine.core.accessControl @@ -85,7 +85,7 @@ class RegularRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(new Exception(ex)) } } @@ -99,7 +99,7 @@ class RegularRequestHandler(engine: Engine, case ModificationResult.ShouldBeInterrupted => onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case ModificationResult.CannotModify => - logger.error(s"[${request.id.toRequestId.show}] Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") + noRequestIdLogger.error(s"Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case CustomResponse(response) => respond(request, response) @@ -247,7 +247,7 @@ class RegularRequestHandler(engine: Engine, esContext.listener.onResponse(response) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } \ No newline at end of file diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala index f4f832dedc..bfc421bdd5 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.index.query.{AbstractQueryBuilder, QueryBuilder, QueryBuilders} import org.elasticsearch.search.aggregations.AggregatorFactories @@ -40,7 +40,7 @@ import tech.beshu.ror.implicits.* import java.util.UUID import scala.jdk.CollectionConverters.* -object SearchRequestOps extends Logging { +object SearchRequestOps extends RequestIdAwareLogging { implicit class QueryBuilderOps(val builder: Option[QueryBuilder]) extends AnyVal { @@ -52,7 +52,7 @@ object SearchRequestOps extends Logging { val modifiedQuery: AbstractQueryBuilder[_] = provideNewQueryWithAppliedFilter(builder, filterQuery) Some(modifiedQuery) case None => - logger.debug(s"[${requestId.show}] No filter applied to query.") + logger.debug(s"No filter applied to query.") builder } } @@ -92,7 +92,7 @@ object SearchRequestOps extends Logging { case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, requestId) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) disableCaching(requestId) case BasedOnBlockContextOnly.NotAllowedFieldsUsed(notAllowedFields) => modifyNotAllowedFieldsInRequest(notAllowedFields) @@ -138,8 +138,8 @@ object SearchRequestOps extends Logging { } } - private def disableCaching(requestId: RequestContext.Id) = { - logger.debug(s"[${requestId.show}] ACL uses context header for fields rule, will disable request cache for SearchRequest") + private def disableCaching(implicit requestId: RequestContext.Id) = { + logger.debug(s"ACL uses context header for fields rule, will disable request cache for SearchRequest") request.requestCache(false) } } diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala index 9de832edcc..74790fb1fd 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala @@ -17,7 +17,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.action.support.IndicesOptions.WildcardStates import org.elasticsearch.action.{CompositeIndicesRequest, IndicesRequest} @@ -34,7 +33,7 @@ import scala.jdk.CollectionConverters.* abstract class BaseEsRequestContext[B <: BlockContext](esContext: EsContext, clusterService: RorClusterService) - extends RequestContext with Logging { + extends RequestContext { override type BLOCK_CONTEXT = B diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala index ae8abbe1f5..0ee2967364 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala @@ -18,7 +18,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -26,8 +25,9 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import scala.util.Try +import tech.beshu.ror.utils.RequestIdAwareLogging -trait EsRequest[B <: BlockContext] extends Logging { +trait EsRequest[B <: BlockContext] extends RequestIdAwareLogging { implicit def threadPool: ThreadPool final def modifyUsing(blockContext: B): ModificationResult = { @@ -35,7 +35,7 @@ trait EsRequest[B <: BlockContext] extends Logging { Try(modifyRequest(blockContext)) .fold( ex => { - logger.error(s"[${blockContext.requestContext.id.show}] Cannot modify request with filtered data", ex) + logger.error(s"Cannot modify request with filtered data", ex)(blockContext) ModificationResult.CannotModify }, identity diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala index c6a9dcbefd..f773b3efb1 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala @@ -51,7 +51,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest private def discoverDataStreams() = { val dataStreams = dataStreamsFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered data streams: ${dataStreams.show}") + logger.debug(s"Discovered data streams: ${dataStreams.show}") dataStreams } @@ -59,7 +59,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest val backingIndices = backingIndicesFrom(actionRequest) backingIndices match { case BackingIndices.IndicesInvolved(filteredIndices, _) => - logger.debug(s"[${id.show}] Discovered indices: ${filteredIndices.show}") + logger.debug(s"Discovered indices: ${filteredIndices.show}") case BackingIndices.IndicesNotInvolved => } backingIndices diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala index c091179cb6..d150709314 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala @@ -85,7 +85,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: case Some(indices) => update(actionRequest, indices, blockContext.filter, blockContext.fieldLevelSecurity) case None => - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -101,7 +101,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } \ No newline at end of file diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala index 71d462de57..48014e1bdc 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala @@ -73,7 +73,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, } yield update(actionRequest, filteredIndices, allAllowedIndices) result.getOrElse { - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -86,7 +86,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala index 95d882c3b5..f607c0e347 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala @@ -50,7 +50,7 @@ abstract class BaseRepositoriesEsRequestContext[R <: ActionRequest](actionReques case Some(repositories) => update(actionRequest, repositories) case None => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") ShouldBeInterrupted } } diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala index b3b1d66238..7ef0f32014 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala @@ -42,7 +42,7 @@ abstract class BaseSingleIndexEsRequestContext[R <: ActionRequest](actionRequest filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } update(request, filteredIndices.head) } diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala index b5ab70fe7a..c1b2e7ea27 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala @@ -62,7 +62,7 @@ class BulkEsRequestContext(actionRequest: BulkRequest, case (_, _) => ShouldBeInterrupted } } else { - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because origin request contained different " + + logger.error(s"Cannot alter MultiGetRequest request, because origin request contained different " + s"number of requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } @@ -90,18 +90,18 @@ class BulkEsRequestContext(actionRequest: BulkRequest, updateRequestWithIndices(request, nel) Modified case None => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because empty list of indices was found") + logger.error(s"Cannot alter MultiGetRequest request, because empty list of indices was found") ShouldBeInterrupted } case Indices.NotFound => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because no allowed indices were found") + logger.error(s"Cannot alter MultiGetRequest request, because no allowed indices were found") ShouldBeInterrupted } } private def updateRequestWithIndices(request: DocWriteRequest[_], indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } request.index(indices.head.stringify) } diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala index 75a75fcef5..96a043b298 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala @@ -53,14 +53,14 @@ class BulkShardEsRequestContext(actionRequest: BulkShardRequest, case Success(_) => Modified case Failure(ex) => - logger.error(s"[${id.show}] Cannot modify BulkShardRequest", ex) + logger.error(s"Cannot modify BulkShardRequest", ex) CannotModify } } private def tryUpdate(request: BulkShardRequest, indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } val singleIndex = indices.head val uuid = clusterService.indexOrAliasUuids(singleIndex.name).toList.head diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala index 65a168092a..158ac485a5 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala @@ -45,14 +45,14 @@ class ClusterAllocationExplainEsRequestContext(actionRequest: ClusterAllocationE getRequestedIndexFrom(request) match { case Some(_) => if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateIndexIn(request, filteredIndices.head) Modified case None if filteredIndices.exists(_.name === ClusterIndexName.Local.wildcard) => Modified case None => - logger.error(s"[${id.show}] Cluster allocation explain request without index name is unavailable when block contains `indices` rule") + logger.error(s"Cluster allocation explain request without index name is unavailable when block contains `indices` rule") ShouldBeInterrupted } } diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala index 8f97fb7619..3410f4fc6d 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala @@ -68,7 +68,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, updateAliases(actionRequest, aliases) UpdateResponse.sync(updateAliasesResponse(aliases.includedOnly, _)) case None => - logger.error(s"[${id.show}] At least one alias and one index has to be allowed. " + + logger.error(s"At least one alias and one index has to be allowed. " + s"Found allowed indices: [${blockContext.indices.show}]." + s"Found allowed aliases: [${blockContext.aliases.show}]") ShouldBeInterrupted @@ -116,7 +116,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, .indices().asSafeSet .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } @@ -124,7 +124,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, val aliases = rawRequestAliasesSet(request) .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered aliases: ${aliases.show}") + logger.debug(s"Discovered aliases: ${aliases.show}") aliases } diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala index abb85d42b7..f9e2c87e53 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala @@ -55,7 +55,7 @@ class IndicesAliasesEsRequestContext(actionRequest: IndicesAliasesRequest, if (originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala index 05b70606b9..37dd50452b 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala @@ -119,7 +119,7 @@ class MultiGetEsRequestContext(actionRequest: MultiGetRequest, case Nil => updateItemWithNonExistingIndex(item) case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } item.index(index.stringify) } diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala index 989956d79a..9e13edee8d 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala @@ -78,7 +78,7 @@ class MultiSearchEsRequestContext(actionRequest: MultiSearchRequest, } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala index 9191e33b66..5a61356f48 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala @@ -47,7 +47,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { request.getRequests.removeIf { request => removeOrAlter(request, filteredIndices.toCovariantSet) } if (request.getRequests.asScala.isEmpty) { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") ShouldBeInterrupted } else { Modified @@ -63,7 +63,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, true case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") } request.index(index.stringify) false diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala index c411df93c5..c7b99f6e85 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala @@ -52,7 +52,7 @@ class PutRollupJobEsRequestContext private(actionRequest: ActionRequest, if(originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala index 141d9db788..fff8ed58bb 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala @@ -49,7 +49,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (tryUpdate(actionRequest, filteredIndices)) Modified else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") ShouldBeInterrupted } } diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala index 489d0187bc..c42dfc3b78 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala @@ -58,10 +58,10 @@ class ReindexEsRequestContext(actionRequest: ReindexRequest, Modified } else { if (!isDestinationIndexOnFilteredIndicesList) { - logger.info(s"[${id.show}] Destination index of _reindex request is forbidden") + logger.info(s"Destination index of _reindex request is forbidden") } if (!isSearchRequestComposedOnlyOfAllowedIndices) { - logger.info(s"[${id.show}] At least one index from sources indices list of _reindex request is forbidden") + logger.info(s"At least one index from sources indices list of _reindex request is forbidden") } ShouldBeInterrupted } diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala index 2c1b0014e0..97b8ccd9c5 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala @@ -74,7 +74,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo request } case Left(_) => - logger.debug(s"[${id.show}] Cannot parse SQL statement - we can pass it though, because ES is going to reject it") + logger.debug(s"Cannot parse SQL statement - we can pass it though, because ES is going to reject it") request } } @@ -85,7 +85,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DataStreamsStatsEsRequestContext.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DataStreamsStatsEsRequestContext.scala index 3cbf6360ed..3e2648b17b 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DataStreamsStatsEsRequestContext.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DataStreamsStatsEsRequestContext.scala @@ -44,7 +44,7 @@ private[datastreams] class DataStreamsStatsEsRequestContext private(actionReques if (modifyActionRequest(blockContext)) { ModificationResult.Modified } else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") ModificationResult.ShouldBeInterrupted } } diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DeleteDataStreamEsRequestContext.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DeleteDataStreamEsRequestContext.scala index b4491990f0..cf135bdf6a 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DeleteDataStreamEsRequestContext.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DeleteDataStreamEsRequestContext.scala @@ -44,7 +44,7 @@ private[datastreams] class DeleteDataStreamEsRequestContext private(actionReques if (modifyActionRequest(blockContext)) { ModificationResult.Modified } else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") ModificationResult.ShouldBeInterrupted } } diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/GetDataStreamEsRequestContext.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/GetDataStreamEsRequestContext.scala index 26c210c613..c2740720de 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/GetDataStreamEsRequestContext.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/GetDataStreamEsRequestContext.scala @@ -64,7 +64,7 @@ private[datastreams] class GetDataStreamEsRequestContext(actionRequest: ActionRe r } } else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") ModificationResult.ShouldBeInterrupted } } diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala index 0c67384c1e..d7e743e648 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CleanupRepositoryEsRequestContext(actionRequest: CleanupRepositoryRequest, override protected def update(request: CleanupRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala index 44b7d78dfd..d09015139b 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CreateRepositoryEsRequestContext(actionRequest: PutRepositoryRequest, override protected def update(request: PutRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala index eaf9334872..0cf32e1bea 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class DeleteRepositoryEsRequestContext(actionRequest: DeleteRepositoryRequest, override protected def update(request: DeleteRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala index cee0bffd4c..d1410eff3d 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class VerifyRepositoryEsRequestContext(actionRequest: VerifyRepositoryRequest, override protected def update(request: VerifyRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala index ead4fcf250..20501516d5 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala @@ -68,32 +68,32 @@ class CreateSnapshotEsRequestContext(actionRequest: CreateSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala index a56aba660e..621d744767 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala @@ -60,7 +60,7 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -71,14 +71,14 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, .toRight(()) } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala index 58122fb44f..782a54d7df 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala @@ -69,7 +69,7 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, case r => r } case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -81,14 +81,14 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.mkString(",")}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.mkString(",")}]") } Right(repository) } diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala index 88887db96c..156deb5b80 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala @@ -63,7 +63,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -75,7 +75,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") } Right(snapshot) } @@ -88,7 +88,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala index 44ee8397ec..e522e440f1 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala @@ -100,12 +100,12 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { val repositories = blockContext.repositories if (allRepositoriesRequested(repositories)) { Right(RepositoryName.All) @@ -115,7 +115,7 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala index 902512a1fc..453687e837 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.GetComposableIndexTemplateAction import org.elasticsearch.cluster.metadata import org.elasticsearch.cluster.metadata.ComposableIndexTemplate @@ -103,7 +103,7 @@ class GetComposableIndexTemplateEsRequestContext(actionRequest: GetComposableInd } -private[templates] object GetComposableIndexTemplateEsRequestContext extends Logging { +private[templates] object GetComposableIndexTemplateEsRequestContext extends RequestIdAwareLogging { def filter(templates: Map[String, ComposableIndexTemplate], usingTemplate: Set[Template] => Set[Template]) diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala index c170a8c87d..d49f293358 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.{GetIndexTemplatesRequest, GetIndexTemplatesResponse} import org.elasticsearch.cluster.metadata.{AliasMetadata, IndexTemplateMetadata} import org.elasticsearch.common.collect.ImmutableOpenMap @@ -100,7 +100,7 @@ class GetTemplatesEsRequestContext(actionRequest: GetIndexTemplatesRequest, } -private[templates] object GetTemplatesEsRequestContext extends Logging { +private[templates] object GetTemplatesEsRequestContext extends RequestIdAwareLogging { def filter(templates: Iterable[IndexTemplateMetadata], usingTemplate: Set[Template] => Set[Template]) diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala index a8951de5b1..32116d8212 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala @@ -72,7 +72,7 @@ class MultiSearchTemplateEsRequestContext private(actionRequest: ActionRequest w } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala index e6f6d8916e..434787a686 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala @@ -55,7 +55,7 @@ class SimulateIndexTemplateRequestEsRequestContext(actionRequest: SimulateIndexT filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateRequest(request, filteredIndices.head, allAllowedIndices) } diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala index fbc4cf6776..46ed6e7a95 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala @@ -109,7 +109,7 @@ class SimulateExistingTemplateRequestEsRequestContext(existingTemplateName: Temp case Some(_) => updateResponse(namePatterns.toList, blockContext.allAllowedIndices.toList) case None => - logger.info(s"[${id.show}] User has no access to template ${existingTemplateName.show}") + logger.info(s"User has no access to template ${existingTemplateName.show}") ModificationResult.ShouldBeInterrupted } case other => diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala index 22a0c6791a..e08a2fbb72 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.queries import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.index.query.* import org.joor.Reflect.on import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.RequestFieldsUsage @@ -32,7 +32,7 @@ trait QueryFieldsUsage[QUERY <: QueryBuilder] { def fieldsIn(query: QUERY): RequestFieldsUsage } -object QueryFieldsUsage extends Logging { +object QueryFieldsUsage extends RequestIdAwareLogging { def apply[QUERY <: QueryBuilder](implicit ev: QueryFieldsUsage[QUERY]): QueryFieldsUsage[QUERY] = ev implicit class Ops[QUERY <: QueryBuilder : QueryFieldsUsage](val query: QUERY) { @@ -65,7 +65,7 @@ object QueryFieldsUsage extends Logging { Option(on(query).call("getFieldName").get[String]) match { case Some(fieldName: String) => UsingFields(NonEmptyList.one(UsedField(fieldName))) case _ => - logger.debug(s"Cannot extract fields for terms set query") + noRequestIdLogger.debug(s"Cannot extract fields for terms set query") CannotExtractFields } } @@ -93,7 +93,7 @@ object QueryFieldsUsage extends Logging { case builder: TermsSetQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder: WildcardQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder => - logger.debug(s"Cannot extract fields for query: ${builder.getName}") + noRequestIdLogger.debug(s"Cannot extract fields for query: ${builder.getName}") CannotExtractFields } diff --git a/es714x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala b/es714x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala index 0998bb9a5b..b4671e9e4d 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.handler.response import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.FieldsRestrictions import tech.beshu.ror.accesscontrol.domain.Header @@ -26,17 +26,17 @@ import tech.beshu.ror.accesscontrol.headerValues.transientFieldsToHeaderValue import tech.beshu.ror.accesscontrol.request.RequestContext import tech.beshu.ror.implicits.* -object FLSContextHeaderHandler extends Logging { +object FLSContextHeaderHandler extends RequestIdAwareLogging { def addContextHeader(threadPool: ThreadPool, - fieldsRestrictions: FieldsRestrictions, - requestId: RequestContext.Id): Unit = { + fieldsRestrictions: FieldsRestrictions) + (implicit requestId: RequestContext.Id): Unit = { val threadContext = threadPool.getThreadContext val header = createContextHeader(fieldsRestrictions) Option(threadContext.getHeader(header.name.value.value)) match { case None => implicit val show = headerShow - logger.debug(s"[${requestId.show}] Adding thread context header required by lucene. Header: '${header.show}'") + logger.debug(s"Adding thread context header required by lucene. Header: '${header.show}'") threadContext.putHeader(header.name.value.value, header.value.value) case Some(_) => } diff --git a/es714x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala b/es714x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala index 26df1d5bb9..2ce5662a4b 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.admin.indices.template.get.{GetComponentTemplateAction, GetComposableIndexTemplateAction} import org.elasticsearch.action.admin.indices.template.put.{PutComponentTemplateAction, PutComposableIndexTemplateAction} @@ -45,7 +45,7 @@ import scala.jdk.CollectionConverters.* final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJsonParserFactory)(using Clock) extends DataStreamService - with Logging { + with RequestIdAwareLogging { override def checkDataStreamExists(dataStreamName: DataStreamName.Full): Task[Boolean] = execute { val enhancedActionType = client.findActionUnsafe[ActionResponse]("indices:admin/data_stream/get") @@ -218,11 +218,11 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ response <- Task.measure( task = Task.delay(nodeClient.execute(action, request).actionGet()), logTimeMeasurement = duration => Task.delay { - logger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") + noRequestIdLogger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") } ) _ <- Task.delay { - logger.debug(s"Action ${action.name()} response: ${response.toString}") + noRequestIdLogger.debug(s"Action ${action.name()} response: ${response.toString}") } } yield response } @@ -230,7 +230,7 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ def executeAck[REQUEST <: ActionRequest, RESPONSE <: AcknowledgedResponse](action: ActionType[RESPONSE], request: REQUEST): Task[RESPONSE] = { executeT(action, request) - .tapEval(response => Task.delay(logger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) + .tapEval(response => Task.delay(noRequestIdLogger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) } private def supportedActions: Map[ActionType[ActionResponse], TransportAction[ActionRequest, ActionResponse]] = { diff --git a/es714x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala b/es714x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala index 18490a232c..b65ba21df7 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.support.WriteRequest.RefreshPolicy import org.elasticsearch.client.node.NodeClient @@ -38,7 +38,7 @@ import scala.jdk.CollectionConverters.* class EsIndexJsonContentService(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexJsonContentService - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -63,14 +63,14 @@ class EsIndexJsonContentService(client: NodeClient, Option(response.getSourceAsMap) match { case Some(map) => val source = map.asScala.toMap.asStringMap - logger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") Right(source) case None => - logger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") + noRequestIdLogger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") Right(Map.empty[String, String]) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(ContentNotFound) } } @@ -78,7 +78,7 @@ class EsIndexJsonContentService(client: NodeClient, .onErrorRecover { case _: ResourceNotFoundException => Left(ContentNotFound) case ex => - logger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) Left(CannotReachContentSource) } } @@ -104,14 +104,14 @@ class EsIndexJsonContentService(client: NodeClient, case status if status / 100 == 2 => Right(()) case status => - logger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") Left(CannotWriteToIndex) } } .executeOn(RorSchedulers.blockingScheduler) .onErrorRecover { case ex => - logger.error(s"Cannot write to document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]", ex) Left(CannotWriteToIndex) } } diff --git a/es714x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala b/es714x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala index 0c2ef5ac80..6f970d8a83 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala @@ -22,7 +22,7 @@ import cats.kernel.Monoid import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task import monix.execution.CancelablePromise -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction.{ResolvedAlias, ResolvedIndex} @@ -64,7 +64,7 @@ class EsServerBasedRorClusterService(nodeName: String, nodeClient: NodeClient, threadPool: ThreadPool) extends RorClusterService - with Logging { + with RequestIdAwareLogging { import EsServerBasedRorClusterService.* @@ -155,7 +155,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractAccessibilityFrom) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify get request. Blocking document", ex) + logger.error(s"Could not verify get request. Blocking document", ex)(id) Inaccessible } } @@ -167,7 +167,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractResultsFromSearchResponse) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify documents returned by multi get response. Blocking all returned documents", ex) + logger.error(s"Could not verify documents returned by multi get response. Blocking all returned documents", ex)(id) blockAllDocsReturned(documents) } .map(results => zip(results, documents)) @@ -276,7 +276,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService): Task[List[FullRemoteDataStreamWithAliases]] = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -332,7 +332,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService) = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -418,7 +418,7 @@ class EsServerBasedRorClusterService(nodeName: String, } } case None => - logger.error("Cannot supply Snapshots Service. Please, report the issue!!!") + noRequestIdLogger.error("Cannot supply Snapshots Service. Please, report the issue!!!") Task.now(Set.empty[Snapshot]) } } diff --git a/es714x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala b/es714x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala index 6cace63a59..5253e9d60e 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.services import cats.data.NonEmptyList -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.DocWriteRequest import org.elasticsearch.action.bulk.{BackoffPolicy, BulkProcessor, BulkRequest, BulkResponse} import org.elasticsearch.action.index.IndexRequest @@ -40,7 +40,7 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, (using Clock) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { private val bulkProcessor = BulkProcessor @@ -77,25 +77,25 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, private class AuditSinkBulkProcessorListener extends BulkProcessor.Listener { override def beforeBulk(executionId: Long, request: BulkRequest): Unit = { - logger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") + noRequestIdLogger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") } override def afterBulk(executionId: Long, request: BulkRequest, response: BulkResponse): Unit = { if (response.hasFailures) { - logger.error("Some failures flushing the BulkProcessor: ") + noRequestIdLogger.error("Some failures flushing the BulkProcessor: ") response .getItems.to(LazyList) .filter(_.isFailed) .map(_.getFailureMessage) .groupBy(identity) .foreach { case (message, stream) => - logger.error(s"${stream.size}x: $message") + noRequestIdLogger.error(s"${stream.size}x: $message") } } } override def afterBulk(executionId: Long, request: BulkRequest, failure: Throwable): Unit = { - logger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) + noRequestIdLogger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) } } diff --git a/es714x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala b/es714x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala index a8def0ec7a..b3c5593c36 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala @@ -22,7 +22,7 @@ import org.apache.http.auth.{AuthScope, Credentials, UsernamePasswordCredentials import org.apache.http.conn.ssl.NoopHostnameVerifier import org.apache.http.impl.client.BasicCredentialsProvider import org.apache.http.impl.nio.client.HttpAsyncClientBuilder -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.* import org.elasticsearch.client.RestClient.FailureListener import tech.beshu.ror.accesscontrol.audit.sink.AuditDataStreamCreator @@ -38,7 +38,7 @@ import scala.collection.parallel.CollectionConverters.* final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient]) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { override def submit(indexName: IndexName.Full, documentId: String, jsonRecord: String) (implicit requestId: RequestId): Unit = { @@ -77,21 +77,21 @@ final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient] override def onSuccess(response: Response): Unit = { response.getStatusLine.getStatusCode / 100 match { case 2 => // 2xx - logger.debug(s"[${requestId.show}] Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") + logger.debug(s"Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") case _ => - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") } } override def onFailure(ex: Exception): Unit = { - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId]", ex) + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId]", ex) } } override val dataStreamCreator: AuditDataStreamCreator = new AuditDataStreamCreator(clients.map(new RestClientDataStreamService(_))) } -object RestClientAuditSinkService extends Logging { +object RestClientAuditSinkService extends RequestIdAwareLogging { def create(remoteCluster: AuditCluster.RemoteAuditCluster): RestClientAuditSinkService = { remoteCluster.mode match { @@ -122,7 +122,7 @@ object RestClientAuditSinkService extends Logging { .setFailureListener( new FailureListener { override def onFailure(node: Node): Unit = { - logger.debug( + noRequestIdLogger.debug( s"[AUDIT] Node marked dead: ${node.getHost.getSchemeName}://${node.getHost.getHostName}:${node.getHost.getPort}. The client will attempt failover.", ) } diff --git a/es714x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala b/es714x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala index a9f97756f7..a10c1a2aeb 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.Channel import io.netty.handler.ssl.NotSslRecordException -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.network.NetworkService import org.elasticsearch.common.settings.{ClusterSettings, Settings} import org.elasticsearch.common.util.BigArrays @@ -41,7 +41,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, sharedGroupFactory: SharedGroupFactory, fipsCompliant: Boolean) extends Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, ssl.clientAuthenticationEnabled) @@ -49,7 +49,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, override def onException(channel: HttpChannel, cause: Exception): Unit = { if (!this.lifecycle.started) return - else if (cause.getCause.isInstanceOf[NotSslRecordException]) logger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) + else if (cause.getCause.isInstanceOf[NotSslRecordException]) noRequestIdLogger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) else super.onException(channel, cause) channel.close() } diff --git a/es714x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala b/es714x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala index cd73e6310c..d8c0dbbce8 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.* import io.netty.handler.ssl.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.Version import org.elasticsearch.cluster.node.DiscoveryNode import org.elasticsearch.common.io.stream.NamedWriteableRegistry @@ -46,7 +46,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, sharedGroupFactory: SharedGroupFactory, fipsCompliant: Boolean) extends Netty4Transport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = SSLCertHelper.prepareClientSSLContext(ssl, fipsCompliant, ssl.certificateVerificationEnabled) private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, clientAuthenticationEnabled = false) @@ -77,7 +77,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, override def exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable): Unit = { if (cause.isInstanceOf[NotSslRecordException] || (cause.getCause != null && cause.getCause.isInstanceOf[NotSslRecordException])) { - logger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") + noRequestIdLogger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") ctx.channel.close } else { super.exceptionCaught(ctx, cause) diff --git a/es714x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala b/es714x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala index 8a27470274..058c456f9c 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.utils import cats.Show import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.client.node.NodeClient import org.elasticsearch.rest.* @@ -35,7 +35,7 @@ import java.util import scala.util.Try class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandler) - extends RestHandler with Logging { + extends RestHandler with RequestIdAwareLogging { private val wrapped = doPrivileged { wrapSomeActions(underlying) @@ -99,11 +99,11 @@ class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandle private def logError(error: AuthorizationValueError): Unit = { { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorSanitizedShow - logger.warn(s"The incoming request was malformed. Cause: ${error.show}") + noRequestIdLogger.warn(s"The incoming request was malformed. Cause: ${error.show}") } if (logger.delegate.isDebugEnabled()) { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorWithDetailsShow - logger.debug(s"Malformed request detailed cause: ${error.show}") + noRequestIdLogger.debug(s"Malformed request detailed cause: ${error.show}") } } diff --git a/es714x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala b/es714x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala index 5ab1e35742..a9af8f710a 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala @@ -16,13 +16,13 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.settings.Settings import tech.beshu.ror.tools.core.patches.PatchingVerifier import tech.beshu.ror.tools.core.patches.PatchingVerifier.Error.{CannotVerifyIfPatched, EsNotPatched} import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -object EsPatchVerifier extends Logging { +object EsPatchVerifier extends RequestIdAwareLogging { def verify(settings: Settings): Unit = doPrivileged { pathHomeFrom(settings).flatMap(PatchingVerifier.verify) match { @@ -30,7 +30,7 @@ object EsPatchVerifier extends Logging { case Left(e@EsNotPatched(_)) => throw new IllegalStateException(e.message) case Left(e@CannotVerifyIfPatched(_)) => - logger.warn(e.message) + noRequestIdLogger.warn(e.message) } } diff --git a/es716x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es716x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index c1eb97ae22..ee9a908bc6 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.support.{ActionFilter, ActionFilterChain} import org.elasticsearch.action.{ActionListener, ActionRequest, ActionResponse} import org.elasticsearch.client.node.NodeClient @@ -62,7 +62,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, rorEsConfig: ReadonlyRestEsConfig) (implicit environmentConfig: EnvironmentConfig) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = environmentConfig.uniqueIdentifierGenerator @@ -212,12 +212,12 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def handleRorNotReadyYet(esContext: EsContext): Unit = { - logger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") + noRequestIdLogger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") rorNotAvailableRequestHandler.handleRorNotReadyYet(esContext) } private def handleRorFailedToStart(esContext: EsContext): Unit = { - logger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") + noRequestIdLogger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") rorNotAvailableRequestHandler.handleRorFailedToStart(esContext) } @@ -239,7 +239,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def logAndSetStartingFailureState(failure: StartingFailure): Unit = { - logger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) + noRequestIdLogger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) rorInstanceState.set(RorInstanceStartingState.NotStarted(failure)) } } diff --git a/es716x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala b/es716x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala index 6e2619e391..e72659f0a5 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.xcontent.LoggingDeprecationHandler import org.elasticsearch.rest.{BytesRestResponse, RestResponse} import org.elasticsearch.xcontent.{NamedXContentRegistry, XContentBuilder, XContentType} @@ -30,7 +30,7 @@ import tech.beshu.ror.accesscontrol.domain.ResponseFieldsFiltering.{AccessMode, import scala.jdk.CollectionConverters.* trait ResponseFieldsFiltering { - this: Logging => + this: RequestIdAwareLogging => private val responseFieldsRestrictions: Atomic[Option[ResponseFieldsRestrictions]] = Atomic(None: Option[ResponseFieldsRestrictions]) @@ -45,7 +45,7 @@ trait ResponseFieldsFiltering { case bytesRestResponse: BytesRestResponse => filterBytesRestResponse(bytesRestResponse, fieldsRestrictions) case otherResponse => - logger.warn("ResponseFields filtering is unavailable for this type of request") + noRequestIdLogger.warn("ResponseFields filtering is unavailable for this type of request") otherResponse } case None => diff --git a/es716x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala b/es716x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala index 0f26750588..da95de59a4 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.action.{ActionListener, ActionResponse} import org.elasticsearch.threadpool.ThreadPool @@ -37,7 +37,7 @@ sealed abstract class RorActionListener[T](val underlying: ActionListener[T]) ex final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionListener[T], correlationId: Eval[CorrelationId]) - extends RorActionListener[T](underlying) with Logging { + extends RorActionListener[T](underlying) with RequestIdAwareLogging { override def onFailure(e: Exception): Unit = { super.onFailure(adaptExceptionIfNeeded(e)) @@ -47,7 +47,7 @@ final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionLis ex match { case esException: ElasticsearchException => esException case other => - logger.error(s"[${correlationId.value.show}] Internal error.", other) + noRequestIdLogger.error(s"[${correlationId.value.show}] Internal error.", other) new ElasticsearchException(s"[${correlationId.value.show}] Internal error. See logs for details.") } } diff --git a/es716x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala b/es716x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala index 75048ebe7d..14e5e31c1b 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.http.HttpChannel import org.elasticsearch.rest.{AbstractRestChannel, RestChannel as EsRestChannel, RestRequest as EsRestRequest, RestResponse as EsRestResponse} import squants.information.{Bytes, Information} @@ -40,7 +40,7 @@ object RorRestChannel { final class RorRestChannel private(underlying: EsRestChannel, val restRequest: RorRestRequest) extends AbstractRestChannel(underlying.request(), true) with ResponseFieldsFiltering - with Logging { + with RequestIdAwareLogging { override def sendResponse(response: EsRestResponse): Unit = { ThreadRepo.removeRestChannel(this) diff --git a/es716x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala b/es716x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala index 6babc712b9..3c80750a25 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala @@ -18,16 +18,15 @@ package tech.beshu.ror.es.actions.rradmin import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.ConfigApi.ConfigResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAdminActionHandler extends Logging { +class RRAdminActionHandler extends RequestIdAwareLogging { private implicit val adminRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +51,7 @@ class RRAdminActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAdminResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAdminAction internal error", ex) + logger.error("RRAdminAction internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es716x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala b/es716x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala index c55835a1d0..ce45c6f48e 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala @@ -16,18 +16,15 @@ */ package tech.beshu.ror.es.actions.rrauthmock -import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.AuthMockApi.AuthMockResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier -import tech.beshu.ror.implicits.* +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAuthMockActionHandler extends Logging { +class RRAuthMockActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -53,7 +50,7 @@ class RRAuthMockActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAuthMockResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAuthMock internal error", ex) + logger.error("RRAuthMock internal error", ex) listener.onFailure(new Exception(ex)) } } diff --git a/es716x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala b/es716x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala index aa8bb31e67..640084c4ec 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestconfig import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.TestConfigApi.TestConfigResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestConfigActionHandler extends Logging { +class RRTestConfigActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +52,7 @@ class RRTestConfigActionHandler extends Logging { case Right(response) => listener.onResponse(new RRTestConfigResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRTestConfig internal error", ex) + logger.error(s"RRTestConfig internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es716x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala b/es716x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala index 494e9150b4..98cc0c945d 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.dlsfls import cats.data.StateT import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.DirectoryReader import org.elasticsearch.common.util.concurrent.ThreadContext import org.elasticsearch.core.CheckedFunction @@ -31,7 +31,7 @@ import java.io.IOException import java.util.function.{Function => JavaFunction} import scala.util.{Failure, Success, Try} -object RoleIndexSearcherWrapper extends Logging { +object RoleIndexSearcherWrapper extends RequestIdAwareLogging { val instance: JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] = new JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] { @@ -54,7 +54,7 @@ object RoleIndexSearcherWrapper extends Logging { } .map(r => (r, r)) case None => - logger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") + noRequestIdLogger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") Success((reader, reader)) } } @@ -66,13 +66,13 @@ object RoleIndexSearcherWrapper extends Logging { nel <- NonEmptyString.from(value) match { case Right(nel) => Success(nel) case Left(_) => - logger.debug("FLS: empty header value") + noRequestIdLogger.debug("FLS: empty header value") failure } fields <- transientFieldsFromHeaderValue.fromRawValue(nel) match { case result@Success(_) => result case Failure(ex) => - logger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) + noRequestIdLogger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) failure } } yield fields diff --git a/es716x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala b/es716x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala index 53ba42f33a..c8dffc4da9 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.dlsfls import com.google.common.collect.Iterators -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.codecs.StoredFieldsReader import org.apache.lucene.index.* import org.apache.lucene.index.StoredFieldVisitor.Status @@ -39,21 +39,21 @@ import scala.jdk.CollectionConverters.* import scala.util.Try private class RorDocumentFieldReader(reader: LeafReader, fieldsRestrictions: FieldsRestrictions) - extends SequentialStoredFieldsLeafReader(reader) with Logging { + extends SequentialStoredFieldsLeafReader(reader) with RequestIdAwareLogging { private val policy = new FieldsPolicy(fieldsRestrictions) private val remainingFieldsInfo = { val fInfos = in.getFieldInfos val newInfos = if (fInfos.asScala.isEmpty) { - logger.warn("original fields were empty! This is weird!") + noRequestIdLogger.warn("original fields were empty! This is weird!") fInfos } else { val remainingFields = fInfos.asScala.filter(f => policy.canKeep(f.name)).toSet new FieldInfos(remainingFields.toArray) } - logger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") - logger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") - logger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") + noRequestIdLogger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") newInfos } private val jsonPolicyBasedFilterer = new JsonPolicyBasedFilterer(policy) diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala index 79537a140c..de9eb68e1c 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.* import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest import org.elasticsearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest @@ -88,7 +88,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, threadPool: ThreadPool) (implicit generator: UniqueIdentifierGenerator, scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle(engines: Engines, esContext: EsContext): Task[Either[Error, Unit]] = { @@ -231,7 +231,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, case SearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case MultiSearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case _ => - logger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") + noRequestIdLogger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") regularRequestHandler.handle(new DummyCompositeIndicesEsRequestContext(request, esContext, aclContext, clusterService, threadPool)) } // rest diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala index cab02aff37..100edd72ac 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.common.io.stream.StreamOutput import org.elasticsearch.xcontent.{ToXContent, ToXContentObject, XContentBuilder} @@ -45,7 +45,7 @@ import scala.util.{Failure, Success, Try} class CurrentUserMetadataRequestHandler(engine: Engine, esContext: EsContext) - extends Logging { + extends RequestIdAwareLogging { def handle(request: RequestContext.Aux[CurrentUserMetadataRequestBlockContext] with EsRequest[CurrentUserMetadataRequestBlockContext]): Task[Unit] = { engine.core.accessControl @@ -69,7 +69,7 @@ class CurrentUserMetadataRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(ex.asInstanceOf[Exception]) } } @@ -86,13 +86,13 @@ class CurrentUserMetadataRequestHandler(engine: Engine, )) } - private def onPassThrough(requestContext: RequestContext): Unit = { - logger.warn(s"[${requestContext.id.toRequestId.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") + private def onPassThrough(implicit requestContext: RequestContext): Unit = { + logger.warn(s"Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") esContext.listener.onFailure(createRorNotEnabledResponse()) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala index 2fb01dcc41..c5c44fda92 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala @@ -20,7 +20,7 @@ import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.RegularRequestResult @@ -49,7 +49,7 @@ class RegularRequestHandler(engine: Engine, esContext: EsContext, threadPool: ThreadPool) (implicit scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle[B <: BlockContext : BlockContextUpdater](request: RequestContext.Aux[B] with EsRequest[B]): Task[Unit] = { engine.core.accessControl @@ -85,7 +85,7 @@ class RegularRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(new Exception(ex)) } } @@ -99,7 +99,7 @@ class RegularRequestHandler(engine: Engine, case ModificationResult.ShouldBeInterrupted => onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case ModificationResult.CannotModify => - logger.error(s"[${request.id.toRequestId.show}] Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") + noRequestIdLogger.error(s"Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case CustomResponse(response) => respond(request, response) @@ -247,7 +247,7 @@ class RegularRequestHandler(engine: Engine, esContext.listener.onResponse(response) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } \ No newline at end of file diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala index f4f832dedc..bfc421bdd5 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.index.query.{AbstractQueryBuilder, QueryBuilder, QueryBuilders} import org.elasticsearch.search.aggregations.AggregatorFactories @@ -40,7 +40,7 @@ import tech.beshu.ror.implicits.* import java.util.UUID import scala.jdk.CollectionConverters.* -object SearchRequestOps extends Logging { +object SearchRequestOps extends RequestIdAwareLogging { implicit class QueryBuilderOps(val builder: Option[QueryBuilder]) extends AnyVal { @@ -52,7 +52,7 @@ object SearchRequestOps extends Logging { val modifiedQuery: AbstractQueryBuilder[_] = provideNewQueryWithAppliedFilter(builder, filterQuery) Some(modifiedQuery) case None => - logger.debug(s"[${requestId.show}] No filter applied to query.") + logger.debug(s"No filter applied to query.") builder } } @@ -92,7 +92,7 @@ object SearchRequestOps extends Logging { case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, requestId) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) disableCaching(requestId) case BasedOnBlockContextOnly.NotAllowedFieldsUsed(notAllowedFields) => modifyNotAllowedFieldsInRequest(notAllowedFields) @@ -138,8 +138,8 @@ object SearchRequestOps extends Logging { } } - private def disableCaching(requestId: RequestContext.Id) = { - logger.debug(s"[${requestId.show}] ACL uses context header for fields rule, will disable request cache for SearchRequest") + private def disableCaching(implicit requestId: RequestContext.Id) = { + logger.debug(s"ACL uses context header for fields rule, will disable request cache for SearchRequest") request.requestCache(false) } } diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala index 9de832edcc..74790fb1fd 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala @@ -17,7 +17,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.action.support.IndicesOptions.WildcardStates import org.elasticsearch.action.{CompositeIndicesRequest, IndicesRequest} @@ -34,7 +33,7 @@ import scala.jdk.CollectionConverters.* abstract class BaseEsRequestContext[B <: BlockContext](esContext: EsContext, clusterService: RorClusterService) - extends RequestContext with Logging { + extends RequestContext { override type BLOCK_CONTEXT = B diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala index ae8abbe1f5..0ee2967364 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala @@ -18,7 +18,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -26,8 +25,9 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import scala.util.Try +import tech.beshu.ror.utils.RequestIdAwareLogging -trait EsRequest[B <: BlockContext] extends Logging { +trait EsRequest[B <: BlockContext] extends RequestIdAwareLogging { implicit def threadPool: ThreadPool final def modifyUsing(blockContext: B): ModificationResult = { @@ -35,7 +35,7 @@ trait EsRequest[B <: BlockContext] extends Logging { Try(modifyRequest(blockContext)) .fold( ex => { - logger.error(s"[${blockContext.requestContext.id.show}] Cannot modify request with filtered data", ex) + logger.error(s"Cannot modify request with filtered data", ex)(blockContext) ModificationResult.CannotModify }, identity diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala index c6a9dcbefd..f773b3efb1 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala @@ -51,7 +51,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest private def discoverDataStreams() = { val dataStreams = dataStreamsFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered data streams: ${dataStreams.show}") + logger.debug(s"Discovered data streams: ${dataStreams.show}") dataStreams } @@ -59,7 +59,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest val backingIndices = backingIndicesFrom(actionRequest) backingIndices match { case BackingIndices.IndicesInvolved(filteredIndices, _) => - logger.debug(s"[${id.show}] Discovered indices: ${filteredIndices.show}") + logger.debug(s"Discovered indices: ${filteredIndices.show}") case BackingIndices.IndicesNotInvolved => } backingIndices diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala index c091179cb6..d150709314 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala @@ -85,7 +85,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: case Some(indices) => update(actionRequest, indices, blockContext.filter, blockContext.fieldLevelSecurity) case None => - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -101,7 +101,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } \ No newline at end of file diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala index 71d462de57..48014e1bdc 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala @@ -73,7 +73,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, } yield update(actionRequest, filteredIndices, allAllowedIndices) result.getOrElse { - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -86,7 +86,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala index 95d882c3b5..f607c0e347 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala @@ -50,7 +50,7 @@ abstract class BaseRepositoriesEsRequestContext[R <: ActionRequest](actionReques case Some(repositories) => update(actionRequest, repositories) case None => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") ShouldBeInterrupted } } diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala index b3b1d66238..7ef0f32014 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala @@ -42,7 +42,7 @@ abstract class BaseSingleIndexEsRequestContext[R <: ActionRequest](actionRequest filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } update(request, filteredIndices.head) } diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala index b5ab70fe7a..c1b2e7ea27 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala @@ -62,7 +62,7 @@ class BulkEsRequestContext(actionRequest: BulkRequest, case (_, _) => ShouldBeInterrupted } } else { - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because origin request contained different " + + logger.error(s"Cannot alter MultiGetRequest request, because origin request contained different " + s"number of requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } @@ -90,18 +90,18 @@ class BulkEsRequestContext(actionRequest: BulkRequest, updateRequestWithIndices(request, nel) Modified case None => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because empty list of indices was found") + logger.error(s"Cannot alter MultiGetRequest request, because empty list of indices was found") ShouldBeInterrupted } case Indices.NotFound => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because no allowed indices were found") + logger.error(s"Cannot alter MultiGetRequest request, because no allowed indices were found") ShouldBeInterrupted } } private def updateRequestWithIndices(request: DocWriteRequest[_], indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } request.index(indices.head.stringify) } diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala index 75a75fcef5..96a043b298 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala @@ -53,14 +53,14 @@ class BulkShardEsRequestContext(actionRequest: BulkShardRequest, case Success(_) => Modified case Failure(ex) => - logger.error(s"[${id.show}] Cannot modify BulkShardRequest", ex) + logger.error(s"Cannot modify BulkShardRequest", ex) CannotModify } } private def tryUpdate(request: BulkShardRequest, indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } val singleIndex = indices.head val uuid = clusterService.indexOrAliasUuids(singleIndex.name).toList.head diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala index 65a168092a..158ac485a5 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala @@ -45,14 +45,14 @@ class ClusterAllocationExplainEsRequestContext(actionRequest: ClusterAllocationE getRequestedIndexFrom(request) match { case Some(_) => if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateIndexIn(request, filteredIndices.head) Modified case None if filteredIndices.exists(_.name === ClusterIndexName.Local.wildcard) => Modified case None => - logger.error(s"[${id.show}] Cluster allocation explain request without index name is unavailable when block contains `indices` rule") + logger.error(s"Cluster allocation explain request without index name is unavailable when block contains `indices` rule") ShouldBeInterrupted } } diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala index 8f97fb7619..3410f4fc6d 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala @@ -68,7 +68,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, updateAliases(actionRequest, aliases) UpdateResponse.sync(updateAliasesResponse(aliases.includedOnly, _)) case None => - logger.error(s"[${id.show}] At least one alias and one index has to be allowed. " + + logger.error(s"At least one alias and one index has to be allowed. " + s"Found allowed indices: [${blockContext.indices.show}]." + s"Found allowed aliases: [${blockContext.aliases.show}]") ShouldBeInterrupted @@ -116,7 +116,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, .indices().asSafeSet .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } @@ -124,7 +124,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, val aliases = rawRequestAliasesSet(request) .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered aliases: ${aliases.show}") + logger.debug(s"Discovered aliases: ${aliases.show}") aliases } diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala index abb85d42b7..f9e2c87e53 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala @@ -55,7 +55,7 @@ class IndicesAliasesEsRequestContext(actionRequest: IndicesAliasesRequest, if (originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala index 05b70606b9..37dd50452b 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala @@ -119,7 +119,7 @@ class MultiGetEsRequestContext(actionRequest: MultiGetRequest, case Nil => updateItemWithNonExistingIndex(item) case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } item.index(index.stringify) } diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala index 989956d79a..9e13edee8d 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala @@ -78,7 +78,7 @@ class MultiSearchEsRequestContext(actionRequest: MultiSearchRequest, } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala index 9191e33b66..5a61356f48 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala @@ -47,7 +47,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { request.getRequests.removeIf { request => removeOrAlter(request, filteredIndices.toCovariantSet) } if (request.getRequests.asScala.isEmpty) { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") ShouldBeInterrupted } else { Modified @@ -63,7 +63,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, true case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") } request.index(index.stringify) false diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala index c411df93c5..c7b99f6e85 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala @@ -52,7 +52,7 @@ class PutRollupJobEsRequestContext private(actionRequest: ActionRequest, if(originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala index 141d9db788..fff8ed58bb 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala @@ -49,7 +49,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (tryUpdate(actionRequest, filteredIndices)) Modified else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") ShouldBeInterrupted } } diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala index 489d0187bc..c42dfc3b78 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala @@ -58,10 +58,10 @@ class ReindexEsRequestContext(actionRequest: ReindexRequest, Modified } else { if (!isDestinationIndexOnFilteredIndicesList) { - logger.info(s"[${id.show}] Destination index of _reindex request is forbidden") + logger.info(s"Destination index of _reindex request is forbidden") } if (!isSearchRequestComposedOnlyOfAllowedIndices) { - logger.info(s"[${id.show}] At least one index from sources indices list of _reindex request is forbidden") + logger.info(s"At least one index from sources indices list of _reindex request is forbidden") } ShouldBeInterrupted } diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala index 2c1b0014e0..97b8ccd9c5 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala @@ -74,7 +74,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo request } case Left(_) => - logger.debug(s"[${id.show}] Cannot parse SQL statement - we can pass it though, because ES is going to reject it") + logger.debug(s"Cannot parse SQL statement - we can pass it though, because ES is going to reject it") request } } @@ -85,7 +85,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DataStreamsStatsEsRequestContext.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DataStreamsStatsEsRequestContext.scala index 3cbf6360ed..3e2648b17b 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DataStreamsStatsEsRequestContext.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DataStreamsStatsEsRequestContext.scala @@ -44,7 +44,7 @@ private[datastreams] class DataStreamsStatsEsRequestContext private(actionReques if (modifyActionRequest(blockContext)) { ModificationResult.Modified } else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") ModificationResult.ShouldBeInterrupted } } diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DeleteDataStreamEsRequestContext.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DeleteDataStreamEsRequestContext.scala index b4491990f0..cf135bdf6a 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DeleteDataStreamEsRequestContext.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DeleteDataStreamEsRequestContext.scala @@ -44,7 +44,7 @@ private[datastreams] class DeleteDataStreamEsRequestContext private(actionReques if (modifyActionRequest(blockContext)) { ModificationResult.Modified } else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") ModificationResult.ShouldBeInterrupted } } diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/GetDataStreamEsRequestContext.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/GetDataStreamEsRequestContext.scala index 26c210c613..c2740720de 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/GetDataStreamEsRequestContext.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/GetDataStreamEsRequestContext.scala @@ -64,7 +64,7 @@ private[datastreams] class GetDataStreamEsRequestContext(actionRequest: ActionRe r } } else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") ModificationResult.ShouldBeInterrupted } } diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala index 0c67384c1e..d7e743e648 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CleanupRepositoryEsRequestContext(actionRequest: CleanupRepositoryRequest, override protected def update(request: CleanupRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala index 44b7d78dfd..d09015139b 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CreateRepositoryEsRequestContext(actionRequest: PutRepositoryRequest, override protected def update(request: PutRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala index eaf9334872..0cf32e1bea 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class DeleteRepositoryEsRequestContext(actionRequest: DeleteRepositoryRequest, override protected def update(request: DeleteRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala index cee0bffd4c..d1410eff3d 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class VerifyRepositoryEsRequestContext(actionRequest: VerifyRepositoryRequest, override protected def update(request: VerifyRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala index ead4fcf250..20501516d5 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala @@ -68,32 +68,32 @@ class CreateSnapshotEsRequestContext(actionRequest: CreateSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala index a56aba660e..621d744767 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala @@ -60,7 +60,7 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -71,14 +71,14 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, .toRight(()) } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala index 22869bbb4f..b81f333174 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala @@ -68,7 +68,7 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, case r => r } case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala index 88887db96c..156deb5b80 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala @@ -63,7 +63,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -75,7 +75,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") } Right(snapshot) } @@ -88,7 +88,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala index 44ee8397ec..e522e440f1 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala @@ -100,12 +100,12 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { val repositories = blockContext.repositories if (allRepositoriesRequested(repositories)) { Right(RepositoryName.All) @@ -115,7 +115,7 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala index 80e36a6d77..d8e5182eed 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.GetComposableIndexTemplateAction import org.elasticsearch.cluster.metadata import org.elasticsearch.cluster.metadata.ComposableIndexTemplate @@ -108,7 +108,7 @@ class GetComposableIndexTemplateEsRequestContext(actionRequest: GetComposableInd } -private[templates] object GetComposableIndexTemplateEsRequestContext extends Logging { +private[templates] object GetComposableIndexTemplateEsRequestContext extends RequestIdAwareLogging { def filter(templates: Map[String, ComposableIndexTemplate], usingTemplate: Set[Template] => Set[Template]) diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala index 7a2d813aa6..032b165885 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.{GetIndexTemplatesRequest, GetIndexTemplatesResponse} import org.elasticsearch.cluster.metadata.{AliasMetadata, IndexTemplateMetadata} import org.elasticsearch.common.collect.ImmutableOpenMap @@ -105,7 +105,7 @@ class GetTemplatesEsRequestContext(actionRequest: GetIndexTemplatesRequest, } -private[templates] object GetTemplatesEsRequestContext extends Logging { +private[templates] object GetTemplatesEsRequestContext extends RequestIdAwareLogging { def filter(templates: Iterable[IndexTemplateMetadata], usingTemplate: Set[Template] => Set[Template]) diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala index a8951de5b1..32116d8212 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala @@ -72,7 +72,7 @@ class MultiSearchTemplateEsRequestContext private(actionRequest: ActionRequest w } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala index e6f6d8916e..434787a686 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala @@ -55,7 +55,7 @@ class SimulateIndexTemplateRequestEsRequestContext(actionRequest: SimulateIndexT filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateRequest(request, filteredIndices.head, allAllowedIndices) } diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala index fbc4cf6776..46ed6e7a95 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala @@ -109,7 +109,7 @@ class SimulateExistingTemplateRequestEsRequestContext(existingTemplateName: Temp case Some(_) => updateResponse(namePatterns.toList, blockContext.allAllowedIndices.toList) case None => - logger.info(s"[${id.show}] User has no access to template ${existingTemplateName.show}") + logger.info(s"User has no access to template ${existingTemplateName.show}") ModificationResult.ShouldBeInterrupted } case other => diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala index 22a0c6791a..e08a2fbb72 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.queries import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.index.query.* import org.joor.Reflect.on import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.RequestFieldsUsage @@ -32,7 +32,7 @@ trait QueryFieldsUsage[QUERY <: QueryBuilder] { def fieldsIn(query: QUERY): RequestFieldsUsage } -object QueryFieldsUsage extends Logging { +object QueryFieldsUsage extends RequestIdAwareLogging { def apply[QUERY <: QueryBuilder](implicit ev: QueryFieldsUsage[QUERY]): QueryFieldsUsage[QUERY] = ev implicit class Ops[QUERY <: QueryBuilder : QueryFieldsUsage](val query: QUERY) { @@ -65,7 +65,7 @@ object QueryFieldsUsage extends Logging { Option(on(query).call("getFieldName").get[String]) match { case Some(fieldName: String) => UsingFields(NonEmptyList.one(UsedField(fieldName))) case _ => - logger.debug(s"Cannot extract fields for terms set query") + noRequestIdLogger.debug(s"Cannot extract fields for terms set query") CannotExtractFields } } @@ -93,7 +93,7 @@ object QueryFieldsUsage extends Logging { case builder: TermsSetQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder: WildcardQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder => - logger.debug(s"Cannot extract fields for query: ${builder.getName}") + noRequestIdLogger.debug(s"Cannot extract fields for query: ${builder.getName}") CannotExtractFields } diff --git a/es716x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala b/es716x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala index 0998bb9a5b..b4671e9e4d 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.handler.response import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.FieldsRestrictions import tech.beshu.ror.accesscontrol.domain.Header @@ -26,17 +26,17 @@ import tech.beshu.ror.accesscontrol.headerValues.transientFieldsToHeaderValue import tech.beshu.ror.accesscontrol.request.RequestContext import tech.beshu.ror.implicits.* -object FLSContextHeaderHandler extends Logging { +object FLSContextHeaderHandler extends RequestIdAwareLogging { def addContextHeader(threadPool: ThreadPool, - fieldsRestrictions: FieldsRestrictions, - requestId: RequestContext.Id): Unit = { + fieldsRestrictions: FieldsRestrictions) + (implicit requestId: RequestContext.Id): Unit = { val threadContext = threadPool.getThreadContext val header = createContextHeader(fieldsRestrictions) Option(threadContext.getHeader(header.name.value.value)) match { case None => implicit val show = headerShow - logger.debug(s"[${requestId.show}] Adding thread context header required by lucene. Header: '${header.show}'") + logger.debug(s"Adding thread context header required by lucene. Header: '${header.show}'") threadContext.putHeader(header.name.value.value, header.value.value) case Some(_) => } diff --git a/es716x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala b/es716x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala index 26df1d5bb9..2ce5662a4b 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.admin.indices.template.get.{GetComponentTemplateAction, GetComposableIndexTemplateAction} import org.elasticsearch.action.admin.indices.template.put.{PutComponentTemplateAction, PutComposableIndexTemplateAction} @@ -45,7 +45,7 @@ import scala.jdk.CollectionConverters.* final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJsonParserFactory)(using Clock) extends DataStreamService - with Logging { + with RequestIdAwareLogging { override def checkDataStreamExists(dataStreamName: DataStreamName.Full): Task[Boolean] = execute { val enhancedActionType = client.findActionUnsafe[ActionResponse]("indices:admin/data_stream/get") @@ -218,11 +218,11 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ response <- Task.measure( task = Task.delay(nodeClient.execute(action, request).actionGet()), logTimeMeasurement = duration => Task.delay { - logger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") + noRequestIdLogger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") } ) _ <- Task.delay { - logger.debug(s"Action ${action.name()} response: ${response.toString}") + noRequestIdLogger.debug(s"Action ${action.name()} response: ${response.toString}") } } yield response } @@ -230,7 +230,7 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ def executeAck[REQUEST <: ActionRequest, RESPONSE <: AcknowledgedResponse](action: ActionType[RESPONSE], request: REQUEST): Task[RESPONSE] = { executeT(action, request) - .tapEval(response => Task.delay(logger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) + .tapEval(response => Task.delay(noRequestIdLogger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) } private def supportedActions: Map[ActionType[ActionResponse], TransportAction[ActionRequest, ActionResponse]] = { diff --git a/es716x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala b/es716x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala index 2a9a3dfd8f..fb84030bb9 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.support.WriteRequest.RefreshPolicy import org.elasticsearch.client.node.NodeClient @@ -38,7 +38,7 @@ import scala.jdk.CollectionConverters.* class EsIndexJsonContentService(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexJsonContentService - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -63,14 +63,14 @@ class EsIndexJsonContentService(client: NodeClient, Option(response.getSourceAsMap) match { case Some(map) => val source = map.asScala.toMap.asStringMap - logger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") Right(source) case None => - logger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") + noRequestIdLogger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") Right(Map.empty[String, String]) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(ContentNotFound) } } @@ -78,7 +78,7 @@ class EsIndexJsonContentService(client: NodeClient, .onErrorRecover { case _: ResourceNotFoundException => Left(ContentNotFound) case ex => - logger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) Left(CannotReachContentSource) } } @@ -104,14 +104,14 @@ class EsIndexJsonContentService(client: NodeClient, case status if status / 100 == 2 => Right(()) case status => - logger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") Left(CannotWriteToIndex) } } .executeOn(RorSchedulers.blockingScheduler) .onErrorRecover { case ex => - logger.error(s"Cannot write to document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]", ex) Left(CannotWriteToIndex) } } diff --git a/es716x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala b/es716x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala index 9d42b88e51..6c7634dbc5 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala @@ -22,7 +22,7 @@ import cats.kernel.Monoid import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task import monix.execution.CancelablePromise -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction.{ResolvedAlias, ResolvedIndex} @@ -64,7 +64,7 @@ class EsServerBasedRorClusterService(nodeName: String, nodeClient: NodeClient, threadPool: ThreadPool) extends RorClusterService - with Logging { + with RequestIdAwareLogging { import EsServerBasedRorClusterService.* @@ -155,7 +155,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractAccessibilityFrom) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify get request. Blocking document", ex) + logger.error(s"Could not verify get request. Blocking document", ex)(id) Inaccessible } } @@ -167,7 +167,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractResultsFromSearchResponse) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify documents returned by multi get response. Blocking all returned documents", ex) + logger.error(s"Could not verify documents returned by multi get response. Blocking all returned documents", ex)(id) blockAllDocsReturned(documents) } .map(results => zip(results, documents)) @@ -276,7 +276,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService): Task[List[FullRemoteDataStreamWithAliases]] = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -332,7 +332,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService) = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -418,7 +418,7 @@ class EsServerBasedRorClusterService(nodeName: String, } } case None => - logger.error("Cannot supply Snapshots Service. Please, report the issue!!!") + noRequestIdLogger.error("Cannot supply Snapshots Service. Please, report the issue!!!") Task.now(Set.empty[Snapshot]) } } diff --git a/es716x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala b/es716x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala index 101c2424c0..e68a083e10 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.services import cats.data.NonEmptyList -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.DocWriteRequest import org.elasticsearch.action.bulk.{BackoffPolicy, BulkProcessor, BulkRequest, BulkResponse} import org.elasticsearch.action.index.IndexRequest @@ -40,7 +40,7 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, (using Clock) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { private val bulkProcessor = BulkProcessor @@ -77,25 +77,25 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, private class AuditSinkBulkProcessorListener extends BulkProcessor.Listener { override def beforeBulk(executionId: Long, request: BulkRequest): Unit = { - logger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") + noRequestIdLogger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") } override def afterBulk(executionId: Long, request: BulkRequest, response: BulkResponse): Unit = { if (response.hasFailures) { - logger.error("Some failures flushing the BulkProcessor: ") + noRequestIdLogger.error("Some failures flushing the BulkProcessor: ") response .getItems.to(LazyList) .filter(_.isFailed) .map(_.getFailureMessage) .groupBy(identity) .foreach { case (message, stream) => - logger.error(s"${stream.size}x: $message") + noRequestIdLogger.error(s"${stream.size}x: $message") } } } override def afterBulk(executionId: Long, request: BulkRequest, failure: Throwable): Unit = { - logger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) + noRequestIdLogger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) } } diff --git a/es716x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala b/es716x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala index a8def0ec7a..b3c5593c36 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala @@ -22,7 +22,7 @@ import org.apache.http.auth.{AuthScope, Credentials, UsernamePasswordCredentials import org.apache.http.conn.ssl.NoopHostnameVerifier import org.apache.http.impl.client.BasicCredentialsProvider import org.apache.http.impl.nio.client.HttpAsyncClientBuilder -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.* import org.elasticsearch.client.RestClient.FailureListener import tech.beshu.ror.accesscontrol.audit.sink.AuditDataStreamCreator @@ -38,7 +38,7 @@ import scala.collection.parallel.CollectionConverters.* final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient]) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { override def submit(indexName: IndexName.Full, documentId: String, jsonRecord: String) (implicit requestId: RequestId): Unit = { @@ -77,21 +77,21 @@ final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient] override def onSuccess(response: Response): Unit = { response.getStatusLine.getStatusCode / 100 match { case 2 => // 2xx - logger.debug(s"[${requestId.show}] Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") + logger.debug(s"Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") case _ => - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") } } override def onFailure(ex: Exception): Unit = { - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId]", ex) + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId]", ex) } } override val dataStreamCreator: AuditDataStreamCreator = new AuditDataStreamCreator(clients.map(new RestClientDataStreamService(_))) } -object RestClientAuditSinkService extends Logging { +object RestClientAuditSinkService extends RequestIdAwareLogging { def create(remoteCluster: AuditCluster.RemoteAuditCluster): RestClientAuditSinkService = { remoteCluster.mode match { @@ -122,7 +122,7 @@ object RestClientAuditSinkService extends Logging { .setFailureListener( new FailureListener { override def onFailure(node: Node): Unit = { - logger.debug( + noRequestIdLogger.debug( s"[AUDIT] Node marked dead: ${node.getHost.getSchemeName}://${node.getHost.getHostName}:${node.getHost.getPort}. The client will attempt failover.", ) } diff --git a/es716x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala b/es716x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala index a0a7d92ae4..391eb7e696 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.Channel import io.netty.handler.ssl.NotSslRecordException -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.network.NetworkService import org.elasticsearch.common.settings.{ClusterSettings, Settings} import org.elasticsearch.common.util.BigArrays @@ -41,7 +41,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, sharedGroupFactory: SharedGroupFactory, fipsCompliant: Boolean) extends Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, ssl.clientAuthenticationEnabled) @@ -49,7 +49,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, override def onException(channel: HttpChannel, cause: Exception): Unit = { if (!this.lifecycle.started) return - else if (cause.getCause.isInstanceOf[NotSslRecordException]) logger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) + else if (cause.getCause.isInstanceOf[NotSslRecordException]) noRequestIdLogger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) else super.onException(channel, cause) channel.close() } diff --git a/es716x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala b/es716x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala index cd73e6310c..d8c0dbbce8 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.* import io.netty.handler.ssl.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.Version import org.elasticsearch.cluster.node.DiscoveryNode import org.elasticsearch.common.io.stream.NamedWriteableRegistry @@ -46,7 +46,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, sharedGroupFactory: SharedGroupFactory, fipsCompliant: Boolean) extends Netty4Transport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = SSLCertHelper.prepareClientSSLContext(ssl, fipsCompliant, ssl.certificateVerificationEnabled) private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, clientAuthenticationEnabled = false) @@ -77,7 +77,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, override def exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable): Unit = { if (cause.isInstanceOf[NotSslRecordException] || (cause.getCause != null && cause.getCause.isInstanceOf[NotSslRecordException])) { - logger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") + noRequestIdLogger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") ctx.channel.close } else { super.exceptionCaught(ctx, cause) diff --git a/es716x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala b/es716x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala index 8a27470274..058c456f9c 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.utils import cats.Show import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.client.node.NodeClient import org.elasticsearch.rest.* @@ -35,7 +35,7 @@ import java.util import scala.util.Try class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandler) - extends RestHandler with Logging { + extends RestHandler with RequestIdAwareLogging { private val wrapped = doPrivileged { wrapSomeActions(underlying) @@ -99,11 +99,11 @@ class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandle private def logError(error: AuthorizationValueError): Unit = { { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorSanitizedShow - logger.warn(s"The incoming request was malformed. Cause: ${error.show}") + noRequestIdLogger.warn(s"The incoming request was malformed. Cause: ${error.show}") } if (logger.delegate.isDebugEnabled()) { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorWithDetailsShow - logger.debug(s"Malformed request detailed cause: ${error.show}") + noRequestIdLogger.debug(s"Malformed request detailed cause: ${error.show}") } } diff --git a/es716x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala b/es716x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala index 5ab1e35742..a9af8f710a 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala @@ -16,13 +16,13 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.settings.Settings import tech.beshu.ror.tools.core.patches.PatchingVerifier import tech.beshu.ror.tools.core.patches.PatchingVerifier.Error.{CannotVerifyIfPatched, EsNotPatched} import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -object EsPatchVerifier extends Logging { +object EsPatchVerifier extends RequestIdAwareLogging { def verify(settings: Settings): Unit = doPrivileged { pathHomeFrom(settings).flatMap(PatchingVerifier.verify) match { @@ -30,7 +30,7 @@ object EsPatchVerifier extends Logging { case Left(e@EsNotPatched(_)) => throw new IllegalStateException(e.message) case Left(e@CannotVerifyIfPatched(_)) => - logger.warn(e.message) + noRequestIdLogger.warn(e.message) } } diff --git a/es717x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es717x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index c1eb97ae22..ee9a908bc6 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.support.{ActionFilter, ActionFilterChain} import org.elasticsearch.action.{ActionListener, ActionRequest, ActionResponse} import org.elasticsearch.client.node.NodeClient @@ -62,7 +62,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, rorEsConfig: ReadonlyRestEsConfig) (implicit environmentConfig: EnvironmentConfig) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = environmentConfig.uniqueIdentifierGenerator @@ -212,12 +212,12 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def handleRorNotReadyYet(esContext: EsContext): Unit = { - logger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") + noRequestIdLogger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") rorNotAvailableRequestHandler.handleRorNotReadyYet(esContext) } private def handleRorFailedToStart(esContext: EsContext): Unit = { - logger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") + noRequestIdLogger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") rorNotAvailableRequestHandler.handleRorFailedToStart(esContext) } @@ -239,7 +239,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def logAndSetStartingFailureState(failure: StartingFailure): Unit = { - logger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) + noRequestIdLogger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) rorInstanceState.set(RorInstanceStartingState.NotStarted(failure)) } } diff --git a/es717x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala b/es717x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala index 6e2619e391..e72659f0a5 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.xcontent.LoggingDeprecationHandler import org.elasticsearch.rest.{BytesRestResponse, RestResponse} import org.elasticsearch.xcontent.{NamedXContentRegistry, XContentBuilder, XContentType} @@ -30,7 +30,7 @@ import tech.beshu.ror.accesscontrol.domain.ResponseFieldsFiltering.{AccessMode, import scala.jdk.CollectionConverters.* trait ResponseFieldsFiltering { - this: Logging => + this: RequestIdAwareLogging => private val responseFieldsRestrictions: Atomic[Option[ResponseFieldsRestrictions]] = Atomic(None: Option[ResponseFieldsRestrictions]) @@ -45,7 +45,7 @@ trait ResponseFieldsFiltering { case bytesRestResponse: BytesRestResponse => filterBytesRestResponse(bytesRestResponse, fieldsRestrictions) case otherResponse => - logger.warn("ResponseFields filtering is unavailable for this type of request") + noRequestIdLogger.warn("ResponseFields filtering is unavailable for this type of request") otherResponse } case None => diff --git a/es717x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala b/es717x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala index 0f26750588..da95de59a4 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.action.{ActionListener, ActionResponse} import org.elasticsearch.threadpool.ThreadPool @@ -37,7 +37,7 @@ sealed abstract class RorActionListener[T](val underlying: ActionListener[T]) ex final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionListener[T], correlationId: Eval[CorrelationId]) - extends RorActionListener[T](underlying) with Logging { + extends RorActionListener[T](underlying) with RequestIdAwareLogging { override def onFailure(e: Exception): Unit = { super.onFailure(adaptExceptionIfNeeded(e)) @@ -47,7 +47,7 @@ final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionLis ex match { case esException: ElasticsearchException => esException case other => - logger.error(s"[${correlationId.value.show}] Internal error.", other) + noRequestIdLogger.error(s"[${correlationId.value.show}] Internal error.", other) new ElasticsearchException(s"[${correlationId.value.show}] Internal error. See logs for details.") } } diff --git a/es717x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala b/es717x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala index 75048ebe7d..14e5e31c1b 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.http.HttpChannel import org.elasticsearch.rest.{AbstractRestChannel, RestChannel as EsRestChannel, RestRequest as EsRestRequest, RestResponse as EsRestResponse} import squants.information.{Bytes, Information} @@ -40,7 +40,7 @@ object RorRestChannel { final class RorRestChannel private(underlying: EsRestChannel, val restRequest: RorRestRequest) extends AbstractRestChannel(underlying.request(), true) with ResponseFieldsFiltering - with Logging { + with RequestIdAwareLogging { override def sendResponse(response: EsRestResponse): Unit = { ThreadRepo.removeRestChannel(this) diff --git a/es717x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala b/es717x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala index 6babc712b9..3c80750a25 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala @@ -18,16 +18,15 @@ package tech.beshu.ror.es.actions.rradmin import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.ConfigApi.ConfigResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAdminActionHandler extends Logging { +class RRAdminActionHandler extends RequestIdAwareLogging { private implicit val adminRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +51,7 @@ class RRAdminActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAdminResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAdminAction internal error", ex) + logger.error("RRAdminAction internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es717x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala b/es717x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala index c55835a1d0..ce45c6f48e 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala @@ -16,18 +16,15 @@ */ package tech.beshu.ror.es.actions.rrauthmock -import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.AuthMockApi.AuthMockResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier -import tech.beshu.ror.implicits.* +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAuthMockActionHandler extends Logging { +class RRAuthMockActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -53,7 +50,7 @@ class RRAuthMockActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAuthMockResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAuthMock internal error", ex) + logger.error("RRAuthMock internal error", ex) listener.onFailure(new Exception(ex)) } } diff --git a/es717x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala b/es717x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala index aa8bb31e67..640084c4ec 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestconfig import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.TestConfigApi.TestConfigResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestConfigActionHandler extends Logging { +class RRTestConfigActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +52,7 @@ class RRTestConfigActionHandler extends Logging { case Right(response) => listener.onResponse(new RRTestConfigResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRTestConfig internal error", ex) + logger.error(s"RRTestConfig internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es717x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala b/es717x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala index 494e9150b4..98cc0c945d 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.dlsfls import cats.data.StateT import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.DirectoryReader import org.elasticsearch.common.util.concurrent.ThreadContext import org.elasticsearch.core.CheckedFunction @@ -31,7 +31,7 @@ import java.io.IOException import java.util.function.{Function => JavaFunction} import scala.util.{Failure, Success, Try} -object RoleIndexSearcherWrapper extends Logging { +object RoleIndexSearcherWrapper extends RequestIdAwareLogging { val instance: JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] = new JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] { @@ -54,7 +54,7 @@ object RoleIndexSearcherWrapper extends Logging { } .map(r => (r, r)) case None => - logger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") + noRequestIdLogger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") Success((reader, reader)) } } @@ -66,13 +66,13 @@ object RoleIndexSearcherWrapper extends Logging { nel <- NonEmptyString.from(value) match { case Right(nel) => Success(nel) case Left(_) => - logger.debug("FLS: empty header value") + noRequestIdLogger.debug("FLS: empty header value") failure } fields <- transientFieldsFromHeaderValue.fromRawValue(nel) match { case result@Success(_) => result case Failure(ex) => - logger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) + noRequestIdLogger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) failure } } yield fields diff --git a/es717x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala b/es717x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala index 53ba42f33a..c8dffc4da9 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.dlsfls import com.google.common.collect.Iterators -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.codecs.StoredFieldsReader import org.apache.lucene.index.* import org.apache.lucene.index.StoredFieldVisitor.Status @@ -39,21 +39,21 @@ import scala.jdk.CollectionConverters.* import scala.util.Try private class RorDocumentFieldReader(reader: LeafReader, fieldsRestrictions: FieldsRestrictions) - extends SequentialStoredFieldsLeafReader(reader) with Logging { + extends SequentialStoredFieldsLeafReader(reader) with RequestIdAwareLogging { private val policy = new FieldsPolicy(fieldsRestrictions) private val remainingFieldsInfo = { val fInfos = in.getFieldInfos val newInfos = if (fInfos.asScala.isEmpty) { - logger.warn("original fields were empty! This is weird!") + noRequestIdLogger.warn("original fields were empty! This is weird!") fInfos } else { val remainingFields = fInfos.asScala.filter(f => policy.canKeep(f.name)).toSet new FieldInfos(remainingFields.toArray) } - logger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") - logger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") - logger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") + noRequestIdLogger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") newInfos } private val jsonPolicyBasedFilterer = new JsonPolicyBasedFilterer(policy) diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala index 79537a140c..de9eb68e1c 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.* import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest import org.elasticsearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest @@ -88,7 +88,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, threadPool: ThreadPool) (implicit generator: UniqueIdentifierGenerator, scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle(engines: Engines, esContext: EsContext): Task[Either[Error, Unit]] = { @@ -231,7 +231,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, case SearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case MultiSearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case _ => - logger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") + noRequestIdLogger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") regularRequestHandler.handle(new DummyCompositeIndicesEsRequestContext(request, esContext, aclContext, clusterService, threadPool)) } // rest diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala index cab02aff37..100edd72ac 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.common.io.stream.StreamOutput import org.elasticsearch.xcontent.{ToXContent, ToXContentObject, XContentBuilder} @@ -45,7 +45,7 @@ import scala.util.{Failure, Success, Try} class CurrentUserMetadataRequestHandler(engine: Engine, esContext: EsContext) - extends Logging { + extends RequestIdAwareLogging { def handle(request: RequestContext.Aux[CurrentUserMetadataRequestBlockContext] with EsRequest[CurrentUserMetadataRequestBlockContext]): Task[Unit] = { engine.core.accessControl @@ -69,7 +69,7 @@ class CurrentUserMetadataRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(ex.asInstanceOf[Exception]) } } @@ -86,13 +86,13 @@ class CurrentUserMetadataRequestHandler(engine: Engine, )) } - private def onPassThrough(requestContext: RequestContext): Unit = { - logger.warn(s"[${requestContext.id.toRequestId.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") + private def onPassThrough(implicit requestContext: RequestContext): Unit = { + logger.warn(s"Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") esContext.listener.onFailure(createRorNotEnabledResponse()) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala index 2fb01dcc41..c5c44fda92 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala @@ -20,7 +20,7 @@ import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.RegularRequestResult @@ -49,7 +49,7 @@ class RegularRequestHandler(engine: Engine, esContext: EsContext, threadPool: ThreadPool) (implicit scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle[B <: BlockContext : BlockContextUpdater](request: RequestContext.Aux[B] with EsRequest[B]): Task[Unit] = { engine.core.accessControl @@ -85,7 +85,7 @@ class RegularRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(new Exception(ex)) } } @@ -99,7 +99,7 @@ class RegularRequestHandler(engine: Engine, case ModificationResult.ShouldBeInterrupted => onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case ModificationResult.CannotModify => - logger.error(s"[${request.id.toRequestId.show}] Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") + noRequestIdLogger.error(s"Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case CustomResponse(response) => respond(request, response) @@ -247,7 +247,7 @@ class RegularRequestHandler(engine: Engine, esContext.listener.onResponse(response) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } \ No newline at end of file diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala index f4f832dedc..bfc421bdd5 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.index.query.{AbstractQueryBuilder, QueryBuilder, QueryBuilders} import org.elasticsearch.search.aggregations.AggregatorFactories @@ -40,7 +40,7 @@ import tech.beshu.ror.implicits.* import java.util.UUID import scala.jdk.CollectionConverters.* -object SearchRequestOps extends Logging { +object SearchRequestOps extends RequestIdAwareLogging { implicit class QueryBuilderOps(val builder: Option[QueryBuilder]) extends AnyVal { @@ -52,7 +52,7 @@ object SearchRequestOps extends Logging { val modifiedQuery: AbstractQueryBuilder[_] = provideNewQueryWithAppliedFilter(builder, filterQuery) Some(modifiedQuery) case None => - logger.debug(s"[${requestId.show}] No filter applied to query.") + logger.debug(s"No filter applied to query.") builder } } @@ -92,7 +92,7 @@ object SearchRequestOps extends Logging { case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, requestId) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) disableCaching(requestId) case BasedOnBlockContextOnly.NotAllowedFieldsUsed(notAllowedFields) => modifyNotAllowedFieldsInRequest(notAllowedFields) @@ -138,8 +138,8 @@ object SearchRequestOps extends Logging { } } - private def disableCaching(requestId: RequestContext.Id) = { - logger.debug(s"[${requestId.show}] ACL uses context header for fields rule, will disable request cache for SearchRequest") + private def disableCaching(implicit requestId: RequestContext.Id) = { + logger.debug(s"ACL uses context header for fields rule, will disable request cache for SearchRequest") request.requestCache(false) } } diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala index 9de832edcc..74790fb1fd 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala @@ -17,7 +17,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.action.support.IndicesOptions.WildcardStates import org.elasticsearch.action.{CompositeIndicesRequest, IndicesRequest} @@ -34,7 +33,7 @@ import scala.jdk.CollectionConverters.* abstract class BaseEsRequestContext[B <: BlockContext](esContext: EsContext, clusterService: RorClusterService) - extends RequestContext with Logging { + extends RequestContext { override type BLOCK_CONTEXT = B diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala index ae8abbe1f5..0ee2967364 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala @@ -18,7 +18,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -26,8 +25,9 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import scala.util.Try +import tech.beshu.ror.utils.RequestIdAwareLogging -trait EsRequest[B <: BlockContext] extends Logging { +trait EsRequest[B <: BlockContext] extends RequestIdAwareLogging { implicit def threadPool: ThreadPool final def modifyUsing(blockContext: B): ModificationResult = { @@ -35,7 +35,7 @@ trait EsRequest[B <: BlockContext] extends Logging { Try(modifyRequest(blockContext)) .fold( ex => { - logger.error(s"[${blockContext.requestContext.id.show}] Cannot modify request with filtered data", ex) + logger.error(s"Cannot modify request with filtered data", ex)(blockContext) ModificationResult.CannotModify }, identity diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala index c6a9dcbefd..f773b3efb1 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala @@ -51,7 +51,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest private def discoverDataStreams() = { val dataStreams = dataStreamsFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered data streams: ${dataStreams.show}") + logger.debug(s"Discovered data streams: ${dataStreams.show}") dataStreams } @@ -59,7 +59,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest val backingIndices = backingIndicesFrom(actionRequest) backingIndices match { case BackingIndices.IndicesInvolved(filteredIndices, _) => - logger.debug(s"[${id.show}] Discovered indices: ${filteredIndices.show}") + logger.debug(s"Discovered indices: ${filteredIndices.show}") case BackingIndices.IndicesNotInvolved => } backingIndices diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala index c091179cb6..d150709314 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala @@ -85,7 +85,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: case Some(indices) => update(actionRequest, indices, blockContext.filter, blockContext.fieldLevelSecurity) case None => - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -101,7 +101,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } \ No newline at end of file diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala index 71d462de57..48014e1bdc 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala @@ -73,7 +73,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, } yield update(actionRequest, filteredIndices, allAllowedIndices) result.getOrElse { - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -86,7 +86,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala index 95d882c3b5..f607c0e347 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala @@ -50,7 +50,7 @@ abstract class BaseRepositoriesEsRequestContext[R <: ActionRequest](actionReques case Some(repositories) => update(actionRequest, repositories) case None => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") ShouldBeInterrupted } } diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala index b3b1d66238..7ef0f32014 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala @@ -42,7 +42,7 @@ abstract class BaseSingleIndexEsRequestContext[R <: ActionRequest](actionRequest filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } update(request, filteredIndices.head) } diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala index b5ab70fe7a..c1b2e7ea27 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala @@ -62,7 +62,7 @@ class BulkEsRequestContext(actionRequest: BulkRequest, case (_, _) => ShouldBeInterrupted } } else { - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because origin request contained different " + + logger.error(s"Cannot alter MultiGetRequest request, because origin request contained different " + s"number of requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } @@ -90,18 +90,18 @@ class BulkEsRequestContext(actionRequest: BulkRequest, updateRequestWithIndices(request, nel) Modified case None => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because empty list of indices was found") + logger.error(s"Cannot alter MultiGetRequest request, because empty list of indices was found") ShouldBeInterrupted } case Indices.NotFound => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because no allowed indices were found") + logger.error(s"Cannot alter MultiGetRequest request, because no allowed indices were found") ShouldBeInterrupted } } private def updateRequestWithIndices(request: DocWriteRequest[_], indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } request.index(indices.head.stringify) } diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala index 75a75fcef5..96a043b298 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala @@ -53,14 +53,14 @@ class BulkShardEsRequestContext(actionRequest: BulkShardRequest, case Success(_) => Modified case Failure(ex) => - logger.error(s"[${id.show}] Cannot modify BulkShardRequest", ex) + logger.error(s"Cannot modify BulkShardRequest", ex) CannotModify } } private def tryUpdate(request: BulkShardRequest, indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } val singleIndex = indices.head val uuid = clusterService.indexOrAliasUuids(singleIndex.name).toList.head diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala index 65a168092a..158ac485a5 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala @@ -45,14 +45,14 @@ class ClusterAllocationExplainEsRequestContext(actionRequest: ClusterAllocationE getRequestedIndexFrom(request) match { case Some(_) => if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateIndexIn(request, filteredIndices.head) Modified case None if filteredIndices.exists(_.name === ClusterIndexName.Local.wildcard) => Modified case None => - logger.error(s"[${id.show}] Cluster allocation explain request without index name is unavailable when block contains `indices` rule") + logger.error(s"Cluster allocation explain request without index name is unavailable when block contains `indices` rule") ShouldBeInterrupted } } diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala index 8f97fb7619..3410f4fc6d 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala @@ -68,7 +68,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, updateAliases(actionRequest, aliases) UpdateResponse.sync(updateAliasesResponse(aliases.includedOnly, _)) case None => - logger.error(s"[${id.show}] At least one alias and one index has to be allowed. " + + logger.error(s"At least one alias and one index has to be allowed. " + s"Found allowed indices: [${blockContext.indices.show}]." + s"Found allowed aliases: [${blockContext.aliases.show}]") ShouldBeInterrupted @@ -116,7 +116,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, .indices().asSafeSet .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } @@ -124,7 +124,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, val aliases = rawRequestAliasesSet(request) .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered aliases: ${aliases.show}") + logger.debug(s"Discovered aliases: ${aliases.show}") aliases } diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala index abb85d42b7..f9e2c87e53 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala @@ -55,7 +55,7 @@ class IndicesAliasesEsRequestContext(actionRequest: IndicesAliasesRequest, if (originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala index 05b70606b9..37dd50452b 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala @@ -119,7 +119,7 @@ class MultiGetEsRequestContext(actionRequest: MultiGetRequest, case Nil => updateItemWithNonExistingIndex(item) case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } item.index(index.stringify) } diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala index 989956d79a..9e13edee8d 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala @@ -78,7 +78,7 @@ class MultiSearchEsRequestContext(actionRequest: MultiSearchRequest, } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala index 9191e33b66..5a61356f48 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala @@ -47,7 +47,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { request.getRequests.removeIf { request => removeOrAlter(request, filteredIndices.toCovariantSet) } if (request.getRequests.asScala.isEmpty) { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") ShouldBeInterrupted } else { Modified @@ -63,7 +63,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, true case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") } request.index(index.stringify) false diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala index c411df93c5..c7b99f6e85 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala @@ -52,7 +52,7 @@ class PutRollupJobEsRequestContext private(actionRequest: ActionRequest, if(originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala index 141d9db788..fff8ed58bb 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala @@ -49,7 +49,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (tryUpdate(actionRequest, filteredIndices)) Modified else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") ShouldBeInterrupted } } diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala index 489d0187bc..c42dfc3b78 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala @@ -58,10 +58,10 @@ class ReindexEsRequestContext(actionRequest: ReindexRequest, Modified } else { if (!isDestinationIndexOnFilteredIndicesList) { - logger.info(s"[${id.show}] Destination index of _reindex request is forbidden") + logger.info(s"Destination index of _reindex request is forbidden") } if (!isSearchRequestComposedOnlyOfAllowedIndices) { - logger.info(s"[${id.show}] At least one index from sources indices list of _reindex request is forbidden") + logger.info(s"At least one index from sources indices list of _reindex request is forbidden") } ShouldBeInterrupted } diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala index 2c1b0014e0..97b8ccd9c5 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala @@ -74,7 +74,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo request } case Left(_) => - logger.debug(s"[${id.show}] Cannot parse SQL statement - we can pass it though, because ES is going to reject it") + logger.debug(s"Cannot parse SQL statement - we can pass it though, because ES is going to reject it") request } } @@ -85,7 +85,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DataStreamsStatsEsRequestContext.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DataStreamsStatsEsRequestContext.scala index 3cbf6360ed..3e2648b17b 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DataStreamsStatsEsRequestContext.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DataStreamsStatsEsRequestContext.scala @@ -44,7 +44,7 @@ private[datastreams] class DataStreamsStatsEsRequestContext private(actionReques if (modifyActionRequest(blockContext)) { ModificationResult.Modified } else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") ModificationResult.ShouldBeInterrupted } } diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DeleteDataStreamEsRequestContext.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DeleteDataStreamEsRequestContext.scala index b4491990f0..cf135bdf6a 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DeleteDataStreamEsRequestContext.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DeleteDataStreamEsRequestContext.scala @@ -44,7 +44,7 @@ private[datastreams] class DeleteDataStreamEsRequestContext private(actionReques if (modifyActionRequest(blockContext)) { ModificationResult.Modified } else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") ModificationResult.ShouldBeInterrupted } } diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/GetDataStreamEsRequestContext.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/GetDataStreamEsRequestContext.scala index 26c210c613..c2740720de 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/GetDataStreamEsRequestContext.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/GetDataStreamEsRequestContext.scala @@ -64,7 +64,7 @@ private[datastreams] class GetDataStreamEsRequestContext(actionRequest: ActionRe r } } else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") ModificationResult.ShouldBeInterrupted } } diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala index 0c67384c1e..d7e743e648 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CleanupRepositoryEsRequestContext(actionRequest: CleanupRepositoryRequest, override protected def update(request: CleanupRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala index 44b7d78dfd..d09015139b 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CreateRepositoryEsRequestContext(actionRequest: PutRepositoryRequest, override protected def update(request: PutRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala index eaf9334872..0cf32e1bea 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class DeleteRepositoryEsRequestContext(actionRequest: DeleteRepositoryRequest, override protected def update(request: DeleteRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala index cee0bffd4c..d1410eff3d 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class VerifyRepositoryEsRequestContext(actionRequest: VerifyRepositoryRequest, override protected def update(request: VerifyRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala index ead4fcf250..20501516d5 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala @@ -68,32 +68,32 @@ class CreateSnapshotEsRequestContext(actionRequest: CreateSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala index a56aba660e..621d744767 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala @@ -60,7 +60,7 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -71,14 +71,14 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, .toRight(()) } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala index 22869bbb4f..b81f333174 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala @@ -68,7 +68,7 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, case r => r } case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala index 88887db96c..156deb5b80 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala @@ -63,7 +63,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -75,7 +75,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") } Right(snapshot) } @@ -88,7 +88,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala index 44ee8397ec..e522e440f1 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala @@ -100,12 +100,12 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { val repositories = blockContext.repositories if (allRepositoriesRequested(repositories)) { Right(RepositoryName.All) @@ -115,7 +115,7 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala index 80e36a6d77..d8e5182eed 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.GetComposableIndexTemplateAction import org.elasticsearch.cluster.metadata import org.elasticsearch.cluster.metadata.ComposableIndexTemplate @@ -108,7 +108,7 @@ class GetComposableIndexTemplateEsRequestContext(actionRequest: GetComposableInd } -private[templates] object GetComposableIndexTemplateEsRequestContext extends Logging { +private[templates] object GetComposableIndexTemplateEsRequestContext extends RequestIdAwareLogging { def filter(templates: Map[String, ComposableIndexTemplate], usingTemplate: Set[Template] => Set[Template]) diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala index 7a2d813aa6..032b165885 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.{GetIndexTemplatesRequest, GetIndexTemplatesResponse} import org.elasticsearch.cluster.metadata.{AliasMetadata, IndexTemplateMetadata} import org.elasticsearch.common.collect.ImmutableOpenMap @@ -105,7 +105,7 @@ class GetTemplatesEsRequestContext(actionRequest: GetIndexTemplatesRequest, } -private[templates] object GetTemplatesEsRequestContext extends Logging { +private[templates] object GetTemplatesEsRequestContext extends RequestIdAwareLogging { def filter(templates: Iterable[IndexTemplateMetadata], usingTemplate: Set[Template] => Set[Template]) diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala index a8951de5b1..32116d8212 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala @@ -72,7 +72,7 @@ class MultiSearchTemplateEsRequestContext private(actionRequest: ActionRequest w } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala index e6f6d8916e..434787a686 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala @@ -55,7 +55,7 @@ class SimulateIndexTemplateRequestEsRequestContext(actionRequest: SimulateIndexT filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateRequest(request, filteredIndices.head, allAllowedIndices) } diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala index fbc4cf6776..46ed6e7a95 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala @@ -109,7 +109,7 @@ class SimulateExistingTemplateRequestEsRequestContext(existingTemplateName: Temp case Some(_) => updateResponse(namePatterns.toList, blockContext.allAllowedIndices.toList) case None => - logger.info(s"[${id.show}] User has no access to template ${existingTemplateName.show}") + logger.info(s"User has no access to template ${existingTemplateName.show}") ModificationResult.ShouldBeInterrupted } case other => diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala index 22a0c6791a..e08a2fbb72 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.queries import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.index.query.* import org.joor.Reflect.on import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.RequestFieldsUsage @@ -32,7 +32,7 @@ trait QueryFieldsUsage[QUERY <: QueryBuilder] { def fieldsIn(query: QUERY): RequestFieldsUsage } -object QueryFieldsUsage extends Logging { +object QueryFieldsUsage extends RequestIdAwareLogging { def apply[QUERY <: QueryBuilder](implicit ev: QueryFieldsUsage[QUERY]): QueryFieldsUsage[QUERY] = ev implicit class Ops[QUERY <: QueryBuilder : QueryFieldsUsage](val query: QUERY) { @@ -65,7 +65,7 @@ object QueryFieldsUsage extends Logging { Option(on(query).call("getFieldName").get[String]) match { case Some(fieldName: String) => UsingFields(NonEmptyList.one(UsedField(fieldName))) case _ => - logger.debug(s"Cannot extract fields for terms set query") + noRequestIdLogger.debug(s"Cannot extract fields for terms set query") CannotExtractFields } } @@ -93,7 +93,7 @@ object QueryFieldsUsage extends Logging { case builder: TermsSetQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder: WildcardQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder => - logger.debug(s"Cannot extract fields for query: ${builder.getName}") + noRequestIdLogger.debug(s"Cannot extract fields for query: ${builder.getName}") CannotExtractFields } diff --git a/es717x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala b/es717x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala index 0998bb9a5b..b4671e9e4d 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.handler.response import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.FieldsRestrictions import tech.beshu.ror.accesscontrol.domain.Header @@ -26,17 +26,17 @@ import tech.beshu.ror.accesscontrol.headerValues.transientFieldsToHeaderValue import tech.beshu.ror.accesscontrol.request.RequestContext import tech.beshu.ror.implicits.* -object FLSContextHeaderHandler extends Logging { +object FLSContextHeaderHandler extends RequestIdAwareLogging { def addContextHeader(threadPool: ThreadPool, - fieldsRestrictions: FieldsRestrictions, - requestId: RequestContext.Id): Unit = { + fieldsRestrictions: FieldsRestrictions) + (implicit requestId: RequestContext.Id): Unit = { val threadContext = threadPool.getThreadContext val header = createContextHeader(fieldsRestrictions) Option(threadContext.getHeader(header.name.value.value)) match { case None => implicit val show = headerShow - logger.debug(s"[${requestId.show}] Adding thread context header required by lucene. Header: '${header.show}'") + logger.debug(s"Adding thread context header required by lucene. Header: '${header.show}'") threadContext.putHeader(header.name.value.value, header.value.value) case Some(_) => } diff --git a/es717x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala b/es717x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala index 26df1d5bb9..2ce5662a4b 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.admin.indices.template.get.{GetComponentTemplateAction, GetComposableIndexTemplateAction} import org.elasticsearch.action.admin.indices.template.put.{PutComponentTemplateAction, PutComposableIndexTemplateAction} @@ -45,7 +45,7 @@ import scala.jdk.CollectionConverters.* final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJsonParserFactory)(using Clock) extends DataStreamService - with Logging { + with RequestIdAwareLogging { override def checkDataStreamExists(dataStreamName: DataStreamName.Full): Task[Boolean] = execute { val enhancedActionType = client.findActionUnsafe[ActionResponse]("indices:admin/data_stream/get") @@ -218,11 +218,11 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ response <- Task.measure( task = Task.delay(nodeClient.execute(action, request).actionGet()), logTimeMeasurement = duration => Task.delay { - logger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") + noRequestIdLogger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") } ) _ <- Task.delay { - logger.debug(s"Action ${action.name()} response: ${response.toString}") + noRequestIdLogger.debug(s"Action ${action.name()} response: ${response.toString}") } } yield response } @@ -230,7 +230,7 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ def executeAck[REQUEST <: ActionRequest, RESPONSE <: AcknowledgedResponse](action: ActionType[RESPONSE], request: REQUEST): Task[RESPONSE] = { executeT(action, request) - .tapEval(response => Task.delay(logger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) + .tapEval(response => Task.delay(noRequestIdLogger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) } private def supportedActions: Map[ActionType[ActionResponse], TransportAction[ActionRequest, ActionResponse]] = { diff --git a/es717x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala b/es717x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala index 2a9a3dfd8f..fb84030bb9 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.support.WriteRequest.RefreshPolicy import org.elasticsearch.client.node.NodeClient @@ -38,7 +38,7 @@ import scala.jdk.CollectionConverters.* class EsIndexJsonContentService(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexJsonContentService - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -63,14 +63,14 @@ class EsIndexJsonContentService(client: NodeClient, Option(response.getSourceAsMap) match { case Some(map) => val source = map.asScala.toMap.asStringMap - logger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") Right(source) case None => - logger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") + noRequestIdLogger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") Right(Map.empty[String, String]) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(ContentNotFound) } } @@ -78,7 +78,7 @@ class EsIndexJsonContentService(client: NodeClient, .onErrorRecover { case _: ResourceNotFoundException => Left(ContentNotFound) case ex => - logger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) Left(CannotReachContentSource) } } @@ -104,14 +104,14 @@ class EsIndexJsonContentService(client: NodeClient, case status if status / 100 == 2 => Right(()) case status => - logger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") Left(CannotWriteToIndex) } } .executeOn(RorSchedulers.blockingScheduler) .onErrorRecover { case ex => - logger.error(s"Cannot write to document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]", ex) Left(CannotWriteToIndex) } } diff --git a/es717x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala b/es717x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala index 9d42b88e51..6c7634dbc5 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala @@ -22,7 +22,7 @@ import cats.kernel.Monoid import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task import monix.execution.CancelablePromise -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction.{ResolvedAlias, ResolvedIndex} @@ -64,7 +64,7 @@ class EsServerBasedRorClusterService(nodeName: String, nodeClient: NodeClient, threadPool: ThreadPool) extends RorClusterService - with Logging { + with RequestIdAwareLogging { import EsServerBasedRorClusterService.* @@ -155,7 +155,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractAccessibilityFrom) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify get request. Blocking document", ex) + logger.error(s"Could not verify get request. Blocking document", ex)(id) Inaccessible } } @@ -167,7 +167,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractResultsFromSearchResponse) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify documents returned by multi get response. Blocking all returned documents", ex) + logger.error(s"Could not verify documents returned by multi get response. Blocking all returned documents", ex)(id) blockAllDocsReturned(documents) } .map(results => zip(results, documents)) @@ -276,7 +276,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService): Task[List[FullRemoteDataStreamWithAliases]] = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -332,7 +332,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService) = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -418,7 +418,7 @@ class EsServerBasedRorClusterService(nodeName: String, } } case None => - logger.error("Cannot supply Snapshots Service. Please, report the issue!!!") + noRequestIdLogger.error("Cannot supply Snapshots Service. Please, report the issue!!!") Task.now(Set.empty[Snapshot]) } } diff --git a/es717x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala b/es717x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala index 101c2424c0..e68a083e10 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.services import cats.data.NonEmptyList -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.DocWriteRequest import org.elasticsearch.action.bulk.{BackoffPolicy, BulkProcessor, BulkRequest, BulkResponse} import org.elasticsearch.action.index.IndexRequest @@ -40,7 +40,7 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, (using Clock) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { private val bulkProcessor = BulkProcessor @@ -77,25 +77,25 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, private class AuditSinkBulkProcessorListener extends BulkProcessor.Listener { override def beforeBulk(executionId: Long, request: BulkRequest): Unit = { - logger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") + noRequestIdLogger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") } override def afterBulk(executionId: Long, request: BulkRequest, response: BulkResponse): Unit = { if (response.hasFailures) { - logger.error("Some failures flushing the BulkProcessor: ") + noRequestIdLogger.error("Some failures flushing the BulkProcessor: ") response .getItems.to(LazyList) .filter(_.isFailed) .map(_.getFailureMessage) .groupBy(identity) .foreach { case (message, stream) => - logger.error(s"${stream.size}x: $message") + noRequestIdLogger.error(s"${stream.size}x: $message") } } } override def afterBulk(executionId: Long, request: BulkRequest, failure: Throwable): Unit = { - logger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) + noRequestIdLogger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) } } diff --git a/es717x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala b/es717x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala index a8def0ec7a..b3c5593c36 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala @@ -22,7 +22,7 @@ import org.apache.http.auth.{AuthScope, Credentials, UsernamePasswordCredentials import org.apache.http.conn.ssl.NoopHostnameVerifier import org.apache.http.impl.client.BasicCredentialsProvider import org.apache.http.impl.nio.client.HttpAsyncClientBuilder -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.* import org.elasticsearch.client.RestClient.FailureListener import tech.beshu.ror.accesscontrol.audit.sink.AuditDataStreamCreator @@ -38,7 +38,7 @@ import scala.collection.parallel.CollectionConverters.* final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient]) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { override def submit(indexName: IndexName.Full, documentId: String, jsonRecord: String) (implicit requestId: RequestId): Unit = { @@ -77,21 +77,21 @@ final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient] override def onSuccess(response: Response): Unit = { response.getStatusLine.getStatusCode / 100 match { case 2 => // 2xx - logger.debug(s"[${requestId.show}] Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") + logger.debug(s"Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") case _ => - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") } } override def onFailure(ex: Exception): Unit = { - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId]", ex) + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId]", ex) } } override val dataStreamCreator: AuditDataStreamCreator = new AuditDataStreamCreator(clients.map(new RestClientDataStreamService(_))) } -object RestClientAuditSinkService extends Logging { +object RestClientAuditSinkService extends RequestIdAwareLogging { def create(remoteCluster: AuditCluster.RemoteAuditCluster): RestClientAuditSinkService = { remoteCluster.mode match { @@ -122,7 +122,7 @@ object RestClientAuditSinkService extends Logging { .setFailureListener( new FailureListener { override def onFailure(node: Node): Unit = { - logger.debug( + noRequestIdLogger.debug( s"[AUDIT] Node marked dead: ${node.getHost.getSchemeName}://${node.getHost.getHostName}:${node.getHost.getPort}. The client will attempt failover.", ) } diff --git a/es717x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala b/es717x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala index 7344bc6c4f..37238f0bd5 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.Channel import io.netty.handler.ssl.NotSslRecordException -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.network.NetworkService import org.elasticsearch.common.settings.{ClusterSettings, Settings} import org.elasticsearch.common.util.BigArrays @@ -41,7 +41,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, sharedGroupFactory: SharedGroupFactory, fipsCompliant: Boolean) extends Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory, null) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, ssl.clientAuthenticationEnabled) @@ -49,7 +49,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, override def onException(channel: HttpChannel, cause: Exception): Unit = { if (!this.lifecycle.started) return - else if (cause.getCause.isInstanceOf[NotSslRecordException]) logger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) + else if (cause.getCause.isInstanceOf[NotSslRecordException]) noRequestIdLogger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) else super.onException(channel, cause) channel.close() } diff --git a/es717x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala b/es717x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala index cd73e6310c..d8c0dbbce8 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.* import io.netty.handler.ssl.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.Version import org.elasticsearch.cluster.node.DiscoveryNode import org.elasticsearch.common.io.stream.NamedWriteableRegistry @@ -46,7 +46,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, sharedGroupFactory: SharedGroupFactory, fipsCompliant: Boolean) extends Netty4Transport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = SSLCertHelper.prepareClientSSLContext(ssl, fipsCompliant, ssl.certificateVerificationEnabled) private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, clientAuthenticationEnabled = false) @@ -77,7 +77,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, override def exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable): Unit = { if (cause.isInstanceOf[NotSslRecordException] || (cause.getCause != null && cause.getCause.isInstanceOf[NotSslRecordException])) { - logger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") + noRequestIdLogger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") ctx.channel.close } else { super.exceptionCaught(ctx, cause) diff --git a/es717x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala b/es717x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala index 318974537d..75ce93dcfa 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.utils import cats.Show import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.client.node.NodeClient import org.elasticsearch.rest.* @@ -35,7 +35,7 @@ import java.util import scala.util.Try class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandler) - extends RestHandler with Logging { + extends RestHandler with RequestIdAwareLogging { private val wrapped = doPrivileged { wrapSomeActions(underlying) @@ -101,11 +101,11 @@ class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandle private def logError(error: AuthorizationValueError): Unit = { { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorSanitizedShow - logger.warn(s"The incoming request was malformed. Cause: ${error.show}") + noRequestIdLogger.warn(s"The incoming request was malformed. Cause: ${error.show}") } if (logger.delegate.isDebugEnabled()) { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorWithDetailsShow - logger.debug(s"Malformed request detailed cause: ${error.show}") + noRequestIdLogger.debug(s"Malformed request detailed cause: ${error.show}") } } diff --git a/es717x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala b/es717x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala index 5ab1e35742..a9af8f710a 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala @@ -16,13 +16,13 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.settings.Settings import tech.beshu.ror.tools.core.patches.PatchingVerifier import tech.beshu.ror.tools.core.patches.PatchingVerifier.Error.{CannotVerifyIfPatched, EsNotPatched} import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -object EsPatchVerifier extends Logging { +object EsPatchVerifier extends RequestIdAwareLogging { def verify(settings: Settings): Unit = doPrivileged { pathHomeFrom(settings).flatMap(PatchingVerifier.verify) match { @@ -30,7 +30,7 @@ object EsPatchVerifier extends Logging { case Left(e@EsNotPatched(_)) => throw new IllegalStateException(e.message) case Left(e@CannotVerifyIfPatched(_)) => - logger.warn(e.message) + noRequestIdLogger.warn(e.message) } } diff --git a/es72x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es72x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index 6678bb7ee0..5c135fd766 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.support.{ActionFilter, ActionFilterChain} import org.elasticsearch.action.{ActionListener, ActionRequest, ActionResponse} import org.elasticsearch.client.node.NodeClient @@ -60,7 +60,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, rorEsConfig: ReadonlyRestEsConfig) (implicit environmentConfig: EnvironmentConfig) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = environmentConfig.uniqueIdentifierGenerator @@ -201,12 +201,12 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def handleRorNotReadyYet(esContext: EsContext): Unit = { - logger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") + noRequestIdLogger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") rorNotAvailableRequestHandler.handleRorNotReadyYet(esContext) } private def handleRorFailedToStart(esContext: EsContext): Unit = { - logger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") + noRequestIdLogger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") rorNotAvailableRequestHandler.handleRorFailedToStart(esContext) } @@ -228,7 +228,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def logAndSetStartingFailureState(failure: StartingFailure): Unit = { - logger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) + noRequestIdLogger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) rorInstanceState.set(RorInstanceStartingState.NotStarted(failure)) } } diff --git a/es72x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala b/es72x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala index 7f92461f08..72c14bf252 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.xcontent.cbor.CborXContent import org.elasticsearch.common.xcontent.json.JsonXContent import org.elasticsearch.common.xcontent.smile.SmileXContent @@ -29,7 +29,7 @@ import tech.beshu.ror.accesscontrol.domain.ResponseFieldsFiltering.{AccessMode, import scala.jdk.CollectionConverters.* trait ResponseFieldsFiltering { - this: Logging => + this: RequestIdAwareLogging => private val responseFieldsRestrictions: Atomic[Option[ResponseFieldsRestrictions]] = Atomic(None: Option[ResponseFieldsRestrictions]) @@ -44,7 +44,7 @@ trait ResponseFieldsFiltering { case bytesRestResponse: BytesRestResponse => filterBytesRestResponse(bytesRestResponse, fieldsRestrictions) case otherResponse => - logger.warn("ResponseFields filtering is unavailable for this type of request") + noRequestIdLogger.warn("ResponseFields filtering is unavailable for this type of request") otherResponse } case None => diff --git a/es72x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala b/es72x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala index 0f26750588..da95de59a4 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.action.{ActionListener, ActionResponse} import org.elasticsearch.threadpool.ThreadPool @@ -37,7 +37,7 @@ sealed abstract class RorActionListener[T](val underlying: ActionListener[T]) ex final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionListener[T], correlationId: Eval[CorrelationId]) - extends RorActionListener[T](underlying) with Logging { + extends RorActionListener[T](underlying) with RequestIdAwareLogging { override def onFailure(e: Exception): Unit = { super.onFailure(adaptExceptionIfNeeded(e)) @@ -47,7 +47,7 @@ final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionLis ex match { case esException: ElasticsearchException => esException case other => - logger.error(s"[${correlationId.value.show}] Internal error.", other) + noRequestIdLogger.error(s"[${correlationId.value.show}] Internal error.", other) new ElasticsearchException(s"[${correlationId.value.show}] Internal error. See logs for details.") } } diff --git a/es72x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala b/es72x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala index 0a80ad8a51..09e707bd3e 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.http.HttpChannel import org.elasticsearch.rest.{AbstractRestChannel, RestChannel as EsRestChannel, RestRequest as EsRestRequest, RestResponse as EsRestResponse} import squants.information.{Bytes, Information} @@ -40,7 +40,7 @@ object RorRestChannel { final class RorRestChannel private(underlying: EsRestChannel, val restRequest: RorRestRequest) extends AbstractRestChannel(underlying.request(), true) with ResponseFieldsFiltering - with Logging { + with RequestIdAwareLogging { override def sendResponse(response: EsRestResponse): Unit = { ThreadRepo.removeRestChannel(this) diff --git a/es72x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala b/es72x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala index 6babc712b9..3c80750a25 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala @@ -18,16 +18,15 @@ package tech.beshu.ror.es.actions.rradmin import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.ConfigApi.ConfigResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAdminActionHandler extends Logging { +class RRAdminActionHandler extends RequestIdAwareLogging { private implicit val adminRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +51,7 @@ class RRAdminActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAdminResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAdminAction internal error", ex) + logger.error("RRAdminAction internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es72x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala b/es72x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala index c55835a1d0..ce45c6f48e 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala @@ -16,18 +16,15 @@ */ package tech.beshu.ror.es.actions.rrauthmock -import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.AuthMockApi.AuthMockResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier -import tech.beshu.ror.implicits.* +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAuthMockActionHandler extends Logging { +class RRAuthMockActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -53,7 +50,7 @@ class RRAuthMockActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAuthMockResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAuthMock internal error", ex) + logger.error("RRAuthMock internal error", ex) listener.onFailure(new Exception(ex)) } } diff --git a/es72x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala b/es72x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala index aa8bb31e67..640084c4ec 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestconfig import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.TestConfigApi.TestConfigResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestConfigActionHandler extends Logging { +class RRTestConfigActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +52,7 @@ class RRTestConfigActionHandler extends Logging { case Right(response) => listener.onResponse(new RRTestConfigResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRTestConfig internal error", ex) + logger.error(s"RRTestConfig internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es72x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala b/es72x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala index 09112e0537..12e6a79dc9 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.dlsfls import cats.data.StateT import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.DirectoryReader import org.elasticsearch.common.util.concurrent.ThreadContext import org.elasticsearch.index.IndexService @@ -29,7 +29,7 @@ import tech.beshu.ror.accesscontrol.headerValues.transientFieldsFromHeaderValue import scala.util.{Failure, Success, Try} -class RoleIndexSearcherWrapper(indexService: IndexService) extends IndexSearcherWrapper with Logging { +class RoleIndexSearcherWrapper(indexService: IndexService) extends IndexSearcherWrapper with RequestIdAwareLogging { override def wrap(reader: DirectoryReader): DirectoryReader = { val threadContext: ThreadContext = indexService.getThreadPool.getThreadContext @@ -48,7 +48,7 @@ class RoleIndexSearcherWrapper(indexService: IndexService) extends IndexSearcher } .map(r => (r, r)) case None => - logger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") + noRequestIdLogger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") Success((reader, reader)) } } @@ -60,13 +60,13 @@ class RoleIndexSearcherWrapper(indexService: IndexService) extends IndexSearcher nel <- NonEmptyString.from(value) match { case Right(nel) => Success(nel) case Left(_) => - logger.debug("FLS: empty header value") + noRequestIdLogger.debug("FLS: empty header value") failure } fields <- transientFieldsFromHeaderValue.fromRawValue(nel) match { case result@Success(_) => result case Failure(ex) => - logger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) + noRequestIdLogger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) failure } } yield fields diff --git a/es72x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala b/es72x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala index 85f92af263..a98c7a1067 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.dlsfls import java.io.ByteArrayOutputStream import java.util.{Iterator => JavaIterator} import com.google.common.collect.Iterators -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.StoredFieldVisitor.Status import org.apache.lucene.index.* import org.apache.lucene.util.Bits @@ -36,21 +36,21 @@ import scala.jdk.CollectionConverters.* import scala.util.Try private class RorDocumentFieldReader(reader: LeafReader, fieldsRestrictions: FieldsRestrictions) - extends FilterLeafReader(reader) with Logging { + extends FilterLeafReader(reader) with RequestIdAwareLogging { private val policy = new FieldsPolicy(fieldsRestrictions) private val remainingFieldsInfo = { val fInfos = in.getFieldInfos val newInfos = if (fInfos.asScala.isEmpty) { - logger.warn("original fields were empty! This is weird!") + noRequestIdLogger.warn("original fields were empty! This is weird!") fInfos } else { val remainingFields = fInfos.asScala.filter(f => policy.canKeep(f.name)).toSet new FieldInfos(remainingFields.toArray) } - logger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") - logger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") - logger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") + noRequestIdLogger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") newInfos } private val jsonPolicyBasedFilterer = new JsonPolicyBasedFilterer(policy) diff --git a/es72x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala b/es72x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala index 15f2544476..42e0b270c0 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.* import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest @@ -84,7 +84,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, threadPool: ThreadPool) (implicit generator: UniqueIdentifierGenerator, scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle(engines: Engines, esContext: EsContext): Task[Either[Error, Unit]] = { @@ -204,7 +204,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, case SearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case MultiSearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case _ => - logger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") + noRequestIdLogger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") regularRequestHandler.handle(new DummyCompositeIndicesEsRequestContext(request, esContext, aclContext, clusterService, threadPool)) } // rest diff --git a/es72x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala b/es72x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala index a388bb0f9f..57be14c040 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.common.io.stream.StreamOutput import org.elasticsearch.common.xcontent.{ToXContent, ToXContentObject, XContentBuilder} @@ -45,7 +45,7 @@ import scala.util.{Failure, Success, Try} class CurrentUserMetadataRequestHandler(engine: Engine, esContext: EsContext) - extends Logging { + extends RequestIdAwareLogging { def handle(request: RequestContext.Aux[CurrentUserMetadataRequestBlockContext] with EsRequest[CurrentUserMetadataRequestBlockContext]): Task[Unit] = { engine.core.accessControl @@ -69,7 +69,7 @@ class CurrentUserMetadataRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(ex.asInstanceOf[Exception]) } } @@ -86,13 +86,13 @@ class CurrentUserMetadataRequestHandler(engine: Engine, )) } - private def onPassThrough(requestContext: RequestContext): Unit = { - logger.warn(s"[${requestContext.id.toRequestId.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") + private def onPassThrough(implicit requestContext: RequestContext): Unit = { + logger.warn(s"Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") esContext.listener.onFailure(createRorNotEnabledResponse()) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } diff --git a/es72x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala b/es72x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala index 2fb01dcc41..c5c44fda92 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala @@ -20,7 +20,7 @@ import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.RegularRequestResult @@ -49,7 +49,7 @@ class RegularRequestHandler(engine: Engine, esContext: EsContext, threadPool: ThreadPool) (implicit scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle[B <: BlockContext : BlockContextUpdater](request: RequestContext.Aux[B] with EsRequest[B]): Task[Unit] = { engine.core.accessControl @@ -85,7 +85,7 @@ class RegularRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(new Exception(ex)) } } @@ -99,7 +99,7 @@ class RegularRequestHandler(engine: Engine, case ModificationResult.ShouldBeInterrupted => onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case ModificationResult.CannotModify => - logger.error(s"[${request.id.toRequestId.show}] Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") + noRequestIdLogger.error(s"Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case CustomResponse(response) => respond(request, response) @@ -247,7 +247,7 @@ class RegularRequestHandler(engine: Engine, esContext.listener.onResponse(response) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } \ No newline at end of file diff --git a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala index f6db2b2f6e..7ad5f7b26d 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.index.query.{AbstractQueryBuilder, QueryBuilder, QueryBuilders} import org.elasticsearch.search.aggregations.AggregatorFactories @@ -40,7 +40,7 @@ import tech.beshu.ror.implicits.* import java.util.UUID import scala.jdk.CollectionConverters.* -object SearchRequestOps extends Logging { +object SearchRequestOps extends RequestIdAwareLogging { implicit class QueryBuilderOps(val builder: Option[QueryBuilder]) extends AnyVal { @@ -52,7 +52,7 @@ object SearchRequestOps extends Logging { val modifiedQuery: AbstractQueryBuilder[_] = provideNewQueryWithAppliedFilter(builder, filterQuery) Some(modifiedQuery) case None => - logger.debug(s"[${requestId.show}] No filter applied to query.") + logger.debug(s"No filter applied to query.") builder } } @@ -92,7 +92,7 @@ object SearchRequestOps extends Logging { case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, requestId) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) disableCaching(requestId) case BasedOnBlockContextOnly.NotAllowedFieldsUsed(notAllowedFields) => modifyNotAllowedFieldsInRequest(notAllowedFields) @@ -138,8 +138,8 @@ object SearchRequestOps extends Logging { } } - private def disableCaching(requestId: RequestContext.Id) = { - logger.debug(s"[${requestId.show}] ACL uses context header for fields rule, will disable request cache for SearchRequest") + private def disableCaching(implicit requestId: RequestContext.Id) = { + logger.debug(s"ACL uses context header for fields rule, will disable request cache for SearchRequest") request.requestCache(false) } } diff --git a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala index d04bc3a95e..16827af969 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala @@ -17,7 +17,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.action.{CompositeIndicesRequest, IndicesRequest} import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -32,7 +31,7 @@ import java.time.Instant abstract class BaseEsRequestContext[B <: BlockContext](esContext: EsContext, clusterService: RorClusterService) - extends RequestContext with Logging { + extends RequestContext { override type BLOCK_CONTEXT = B diff --git a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala index ae8abbe1f5..0ee2967364 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala @@ -18,7 +18,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -26,8 +25,9 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import scala.util.Try +import tech.beshu.ror.utils.RequestIdAwareLogging -trait EsRequest[B <: BlockContext] extends Logging { +trait EsRequest[B <: BlockContext] extends RequestIdAwareLogging { implicit def threadPool: ThreadPool final def modifyUsing(blockContext: B): ModificationResult = { @@ -35,7 +35,7 @@ trait EsRequest[B <: BlockContext] extends Logging { Try(modifyRequest(blockContext)) .fold( ex => { - logger.error(s"[${blockContext.requestContext.id.show}] Cannot modify request with filtered data", ex) + logger.error(s"Cannot modify request with filtered data", ex)(blockContext) ModificationResult.CannotModify }, identity diff --git a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala index c091179cb6..d150709314 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala @@ -85,7 +85,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: case Some(indices) => update(actionRequest, indices, blockContext.filter, blockContext.fieldLevelSecurity) case None => - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -101,7 +101,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } \ No newline at end of file diff --git a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala index 71d462de57..48014e1bdc 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala @@ -73,7 +73,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, } yield update(actionRequest, filteredIndices, allAllowedIndices) result.getOrElse { - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -86,7 +86,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } diff --git a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala index 95d882c3b5..f607c0e347 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala @@ -50,7 +50,7 @@ abstract class BaseRepositoriesEsRequestContext[R <: ActionRequest](actionReques case Some(repositories) => update(actionRequest, repositories) case None => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") ShouldBeInterrupted } } diff --git a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala index b3b1d66238..7ef0f32014 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala @@ -42,7 +42,7 @@ abstract class BaseSingleIndexEsRequestContext[R <: ActionRequest](actionRequest filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } update(request, filteredIndices.head) } diff --git a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala index b5ab70fe7a..c1b2e7ea27 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala @@ -62,7 +62,7 @@ class BulkEsRequestContext(actionRequest: BulkRequest, case (_, _) => ShouldBeInterrupted } } else { - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because origin request contained different " + + logger.error(s"Cannot alter MultiGetRequest request, because origin request contained different " + s"number of requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } @@ -90,18 +90,18 @@ class BulkEsRequestContext(actionRequest: BulkRequest, updateRequestWithIndices(request, nel) Modified case None => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because empty list of indices was found") + logger.error(s"Cannot alter MultiGetRequest request, because empty list of indices was found") ShouldBeInterrupted } case Indices.NotFound => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because no allowed indices were found") + logger.error(s"Cannot alter MultiGetRequest request, because no allowed indices were found") ShouldBeInterrupted } } private def updateRequestWithIndices(request: DocWriteRequest[_], indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } request.index(indices.head.stringify) } diff --git a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala index 75a75fcef5..96a043b298 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala @@ -53,14 +53,14 @@ class BulkShardEsRequestContext(actionRequest: BulkShardRequest, case Success(_) => Modified case Failure(ex) => - logger.error(s"[${id.show}] Cannot modify BulkShardRequest", ex) + logger.error(s"Cannot modify BulkShardRequest", ex) CannotModify } } private def tryUpdate(request: BulkShardRequest, indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } val singleIndex = indices.head val uuid = clusterService.indexOrAliasUuids(singleIndex.name).toList.head diff --git a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala index 65a168092a..158ac485a5 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala @@ -45,14 +45,14 @@ class ClusterAllocationExplainEsRequestContext(actionRequest: ClusterAllocationE getRequestedIndexFrom(request) match { case Some(_) => if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateIndexIn(request, filteredIndices.head) Modified case None if filteredIndices.exists(_.name === ClusterIndexName.Local.wildcard) => Modified case None => - logger.error(s"[${id.show}] Cluster allocation explain request without index name is unavailable when block contains `indices` rule") + logger.error(s"Cluster allocation explain request without index name is unavailable when block contains `indices` rule") ShouldBeInterrupted } } diff --git a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala index 24e15f40e8..b73c123699 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala @@ -69,7 +69,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, updateAliases(actionRequest, aliases) UpdateResponse.sync(updateAliasesResponse(aliases.includedOnly, _)) case None => - logger.error(s"[${id.show}] At least one alias and one index has to be allowed. " + + logger.error(s"At least one alias and one index has to be allowed. " + s"Found allowed indices: [${blockContext.indices.show}]." + s"Found allowed aliases: [${blockContext.aliases.show}]") ShouldBeInterrupted @@ -117,7 +117,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, .indices().asSafeSet .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } @@ -125,7 +125,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, val aliases = rawRequestAliasesSet(request) .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered aliases: ${aliases.show}") + logger.debug(s"Discovered aliases: ${aliases.show}") aliases } diff --git a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala index abb85d42b7..f9e2c87e53 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala @@ -55,7 +55,7 @@ class IndicesAliasesEsRequestContext(actionRequest: IndicesAliasesRequest, if (originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala index 05b70606b9..37dd50452b 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala @@ -119,7 +119,7 @@ class MultiGetEsRequestContext(actionRequest: MultiGetRequest, case Nil => updateItemWithNonExistingIndex(item) case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } item.index(index.stringify) } diff --git a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala index 989956d79a..9e13edee8d 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala @@ -78,7 +78,7 @@ class MultiSearchEsRequestContext(actionRequest: MultiSearchRequest, } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala index 9191e33b66..5a61356f48 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala @@ -47,7 +47,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { request.getRequests.removeIf { request => removeOrAlter(request, filteredIndices.toCovariantSet) } if (request.getRequests.asScala.isEmpty) { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") ShouldBeInterrupted } else { Modified @@ -63,7 +63,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, true case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") } request.index(index.stringify) false diff --git a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala index c411df93c5..c7b99f6e85 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala @@ -52,7 +52,7 @@ class PutRollupJobEsRequestContext private(actionRequest: ActionRequest, if(originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala index 141d9db788..fff8ed58bb 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala @@ -49,7 +49,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (tryUpdate(actionRequest, filteredIndices)) Modified else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") ShouldBeInterrupted } } diff --git a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala index 489d0187bc..c42dfc3b78 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala @@ -58,10 +58,10 @@ class ReindexEsRequestContext(actionRequest: ReindexRequest, Modified } else { if (!isDestinationIndexOnFilteredIndicesList) { - logger.info(s"[${id.show}] Destination index of _reindex request is forbidden") + logger.info(s"Destination index of _reindex request is forbidden") } if (!isSearchRequestComposedOnlyOfAllowedIndices) { - logger.info(s"[${id.show}] At least one index from sources indices list of _reindex request is forbidden") + logger.info(s"At least one index from sources indices list of _reindex request is forbidden") } ShouldBeInterrupted } diff --git a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala index 2c1b0014e0..97b8ccd9c5 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala @@ -74,7 +74,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo request } case Left(_) => - logger.debug(s"[${id.show}] Cannot parse SQL statement - we can pass it though, because ES is going to reject it") + logger.debug(s"Cannot parse SQL statement - we can pass it though, because ES is going to reject it") request } } @@ -85,7 +85,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala index 44b7d78dfd..d09015139b 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CreateRepositoryEsRequestContext(actionRequest: PutRepositoryRequest, override protected def update(request: PutRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala index eaf9334872..0cf32e1bea 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class DeleteRepositoryEsRequestContext(actionRequest: DeleteRepositoryRequest, override protected def update(request: DeleteRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala index cee0bffd4c..d1410eff3d 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class VerifyRepositoryEsRequestContext(actionRequest: VerifyRepositoryRequest, override protected def update(request: VerifyRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala index ead4fcf250..20501516d5 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala @@ -68,32 +68,32 @@ class CreateSnapshotEsRequestContext(actionRequest: CreateSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala index 281a0d73f6..27b13ffa11 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala @@ -59,32 +59,32 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala index 58122fb44f..782a54d7df 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala @@ -69,7 +69,7 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, case r => r } case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -81,14 +81,14 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.mkString(",")}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.mkString(",")}]") } Right(repository) } diff --git a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala index 88887db96c..156deb5b80 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala @@ -63,7 +63,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -75,7 +75,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") } Right(snapshot) } @@ -88,7 +88,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala index 44ee8397ec..e522e440f1 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala @@ -100,12 +100,12 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { val repositories = blockContext.repositories if (allRepositoriesRequested(repositories)) { Right(RepositoryName.All) @@ -115,7 +115,7 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala index 0bdf0ce63d..243d0dff91 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.{GetIndexTemplatesRequest, GetIndexTemplatesResponse} import org.elasticsearch.cluster.metadata.{AliasMetaData, IndexTemplateMetaData} import org.elasticsearch.common.collect.ImmutableOpenMap @@ -100,7 +100,7 @@ class GetTemplatesEsRequestContext(actionRequest: GetIndexTemplatesRequest, } -private[templates] object GetTemplatesEsRequestContext extends Logging { +private[templates] object GetTemplatesEsRequestContext extends RequestIdAwareLogging { def filter(templates: Iterable[IndexTemplateMetaData], usingTemplate: Set[Template] => Set[Template]) diff --git a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala index f26cb0a547..0cc64c4f79 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala @@ -82,7 +82,7 @@ class MultiSearchTemplateEsRequestContext private(actionRequest: ActionRequest w callSearchOnceAgain(blockContext.filter, blockContext.fieldLevelSecurity) ) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala index a30469ca97..23304707ed 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.queries import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.index.query.* import org.joor.Reflect.on import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.RequestFieldsUsage @@ -30,7 +30,7 @@ trait QueryFieldsUsage[QUERY <: QueryBuilder] { def fieldsIn(query: QUERY): RequestFieldsUsage } -object QueryFieldsUsage extends Logging { +object QueryFieldsUsage extends RequestIdAwareLogging { def apply[QUERY <: QueryBuilder](implicit ev: QueryFieldsUsage[QUERY]): QueryFieldsUsage[QUERY] = ev implicit class Ops[QUERY <: QueryBuilder : QueryFieldsUsage](val query: QUERY) { @@ -62,7 +62,7 @@ object QueryFieldsUsage extends Logging { Option(on(query).call("getFieldName").get[String]) match { case Some(fieldName: String) => UsingFields(NonEmptyList.one(UsedField(fieldName))) case _ => - logger.debug(s"Cannot extract fields for terms set query") + noRequestIdLogger.debug(s"Cannot extract fields for terms set query") CannotExtractFields } } @@ -89,7 +89,7 @@ object QueryFieldsUsage extends Logging { case builder: TermsSetQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder: WildcardQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder => - logger.debug(s"Cannot extract fields for query: ${builder.getName}") + noRequestIdLogger.debug(s"Cannot extract fields for query: ${builder.getName}") CannotExtractFields } diff --git a/es72x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala b/es72x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala index 0998bb9a5b..b4671e9e4d 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.handler.response import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.FieldsRestrictions import tech.beshu.ror.accesscontrol.domain.Header @@ -26,17 +26,17 @@ import tech.beshu.ror.accesscontrol.headerValues.transientFieldsToHeaderValue import tech.beshu.ror.accesscontrol.request.RequestContext import tech.beshu.ror.implicits.* -object FLSContextHeaderHandler extends Logging { +object FLSContextHeaderHandler extends RequestIdAwareLogging { def addContextHeader(threadPool: ThreadPool, - fieldsRestrictions: FieldsRestrictions, - requestId: RequestContext.Id): Unit = { + fieldsRestrictions: FieldsRestrictions) + (implicit requestId: RequestContext.Id): Unit = { val threadContext = threadPool.getThreadContext val header = createContextHeader(fieldsRestrictions) Option(threadContext.getHeader(header.name.value.value)) match { case None => implicit val show = headerShow - logger.debug(s"[${requestId.show}] Adding thread context header required by lucene. Header: '${header.show}'") + logger.debug(s"Adding thread context header required by lucene. Header: '${header.show}'") threadContext.putHeader(header.name.value.value, header.value.value) case Some(_) => } diff --git a/es72x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala b/es72x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala index 18490a232c..b65ba21df7 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.support.WriteRequest.RefreshPolicy import org.elasticsearch.client.node.NodeClient @@ -38,7 +38,7 @@ import scala.jdk.CollectionConverters.* class EsIndexJsonContentService(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexJsonContentService - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -63,14 +63,14 @@ class EsIndexJsonContentService(client: NodeClient, Option(response.getSourceAsMap) match { case Some(map) => val source = map.asScala.toMap.asStringMap - logger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") Right(source) case None => - logger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") + noRequestIdLogger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") Right(Map.empty[String, String]) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(ContentNotFound) } } @@ -78,7 +78,7 @@ class EsIndexJsonContentService(client: NodeClient, .onErrorRecover { case _: ResourceNotFoundException => Left(ContentNotFound) case ex => - logger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) Left(CannotReachContentSource) } } @@ -104,14 +104,14 @@ class EsIndexJsonContentService(client: NodeClient, case status if status / 100 == 2 => Right(()) case status => - logger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") Left(CannotWriteToIndex) } } .executeOn(RorSchedulers.blockingScheduler) .onErrorRecover { case ex => - logger.error(s"Cannot write to document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]", ex) Left(CannotWriteToIndex) } } diff --git a/es72x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala b/es72x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala index 08ef262c0b..fbb72b4b13 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala @@ -21,7 +21,7 @@ import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task import monix.execution.CancelablePromise -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import org.elasticsearch.action.admin.cluster.state.{ClusterStateRequest, ClusterStateResponse} import org.elasticsearch.action.search.{MultiSearchResponse, SearchRequestBuilder, SearchResponse} @@ -62,7 +62,7 @@ class EsServerBasedRorClusterService(nodeName: String, nodeClient: NodeClient, threadPool: ThreadPool) extends RorClusterService - with Logging { + with RequestIdAwareLogging { import EsServerBasedRorClusterService.* @@ -144,7 +144,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractAccessibilityFrom) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify get request. Blocking document", ex) + logger.error(s"Could not verify get request. Blocking document", ex)(id) Inaccessible } } @@ -156,7 +156,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractResultsFromSearchResponse) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify documents returned by multi get response. Blocking all returned documents", ex) + logger.error(s"Could not verify documents returned by multi get response. Blocking all returned documents", ex)(id) blockAllDocsReturned(documents) } .map(results => zip(results, documents)) @@ -202,7 +202,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService) = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -271,7 +271,7 @@ class EsServerBasedRorClusterService(nodeName: String, } } case None => - logger.error("Cannot supply Snapshots Service. Please, report the issue!!!") + noRequestIdLogger.error("Cannot supply Snapshots Service. Please, report the issue!!!") Task.now(Set.empty[Snapshot]) } } diff --git a/es72x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala b/es72x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala index a85df473af..85e03005d3 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es.services -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.DocWriteRequest import org.elasticsearch.action.bulk.{BackoffPolicy, BulkProcessor, BulkRequest, BulkResponse} import org.elasticsearch.action.index.IndexRequest @@ -29,7 +29,7 @@ import tech.beshu.ror.es.IndexBasedAuditSinkService final class NodeClientBasedAuditSinkService(client: NodeClient) extends IndexBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { private val bulkProcessor = BulkProcessor @@ -61,25 +61,25 @@ final class NodeClientBasedAuditSinkService(client: NodeClient) private class AuditSinkBulkProcessorListener extends BulkProcessor.Listener { override def beforeBulk(executionId: Long, request: BulkRequest): Unit = { - logger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") + noRequestIdLogger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") } override def afterBulk(executionId: Long, request: BulkRequest, response: BulkResponse): Unit = { if (response.hasFailures) { - logger.error("Some failures flushing the BulkProcessor: ") + noRequestIdLogger.error("Some failures flushing the BulkProcessor: ") response .getItems.to(LazyList) .filter(_.isFailed) .map(_.getFailureMessage) .groupBy(identity) .foreach { case (message, stream) => - logger.error(s"${stream.size}x: $message") + noRequestIdLogger.error(s"${stream.size}x: $message") } } } override def afterBulk(executionId: Long, request: BulkRequest, failure: Throwable): Unit = { - logger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) + noRequestIdLogger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) } } diff --git a/es72x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala b/es72x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala index 6c627ede96..c6a4e6124d 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala @@ -22,7 +22,7 @@ import org.apache.http.auth.{AuthScope, Credentials, UsernamePasswordCredentials import org.apache.http.conn.ssl.NoopHostnameVerifier import org.apache.http.impl.client.BasicCredentialsProvider import org.apache.http.impl.nio.client.HttpAsyncClientBuilder -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.* import org.elasticsearch.client.RestClient.FailureListener import tech.beshu.ror.accesscontrol.domain.AuditCluster.ClusterMode @@ -36,7 +36,7 @@ import scala.collection.parallel.CollectionConverters.* final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient]) extends IndexBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { override def submit(indexName: IndexName.Full, documentId: String, jsonRecord: String) (implicit requestId: RequestId): Unit = { @@ -70,19 +70,19 @@ final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient] override def onSuccess(response: Response): Unit = { response.getStatusLine.getStatusCode / 100 match { case 2 => // 2xx - logger.debug(s"[${requestId.show}] Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") + logger.debug(s"Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") case _ => - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") } } override def onFailure(ex: Exception): Unit = { - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId]", ex) + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId]", ex) } } } -object RestClientAuditSinkService extends Logging { +object RestClientAuditSinkService extends RequestIdAwareLogging { def create(remoteCluster: AuditCluster.RemoteAuditCluster): RestClientAuditSinkService = { remoteCluster.mode match { @@ -113,7 +113,7 @@ object RestClientAuditSinkService extends Logging { .setFailureListener( new FailureListener { override def onFailure(node: Node): Unit = { - logger.debug( + noRequestIdLogger.debug( s"[AUDIT] Node marked dead: ${node.getHost.getSchemeName}://${node.getHost.getHostName}:${node.getHost.getPort}. The client will attempt failover.", ) } diff --git a/es72x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala b/es72x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala index f3b70cb4ae..52f09127b7 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.Channel import io.netty.handler.ssl.NotSslRecordException -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.network.NetworkService import org.elasticsearch.common.settings.Settings import org.elasticsearch.common.util.BigArrays @@ -38,7 +38,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, ssl: ExternalSslConfiguration, fipsCompliant: Boolean) extends Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, ssl.clientAuthenticationEnabled) @@ -46,7 +46,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, override def onException(channel: HttpChannel, cause: Exception): Unit = { if (!this.lifecycle.started) return - else if (cause.getCause.isInstanceOf[NotSslRecordException]) logger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) + else if (cause.getCause.isInstanceOf[NotSslRecordException]) noRequestIdLogger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) else super.onException(channel, cause) channel.close() } diff --git a/es72x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala b/es72x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala index 3ac42afd15..ee7a7cdd26 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.* import io.netty.handler.ssl.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.Version import org.elasticsearch.cluster.node.DiscoveryNode import org.elasticsearch.common.io.stream.NamedWriteableRegistry @@ -44,7 +44,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, ssl: InternodeSslConfiguration, fipsCompliant: Boolean) extends Netty4Transport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = SSLCertHelper.prepareClientSSLContext(ssl, fipsCompliant, ssl.certificateVerificationEnabled) private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, clientAuthenticationEnabled = false) @@ -75,7 +75,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, override def exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable): Unit = { if (cause.isInstanceOf[NotSslRecordException] || (cause.getCause != null && cause.getCause.isInstanceOf[NotSslRecordException])) { - logger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") + noRequestIdLogger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") ctx.channel.close } else { super.exceptionCaught(ctx, cause) diff --git a/es72x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala b/es72x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala index db1b336f69..f385b4ab45 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.utils import cats.Show import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.client.node.NodeClient import org.elasticsearch.common.settings.Settings @@ -36,7 +36,7 @@ import scala.util.Try class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandler, settings: Settings) - extends RestHandler with Logging { + extends RestHandler with RequestIdAwareLogging { private val wrapped = doPrivileged { wrapSomeActions(underlying) @@ -94,11 +94,11 @@ class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandle private def logError(error: AuthorizationValueError): Unit = { { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorSanitizedShow - logger.warn(s"The incoming request was malformed. Cause: ${error.show}") + noRequestIdLogger.warn(s"The incoming request was malformed. Cause: ${error.show}") } if (logger.delegate.isDebugEnabled()) { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorWithDetailsShow - logger.debug(s"Malformed request detailed cause: ${error.show}") + noRequestIdLogger.debug(s"Malformed request detailed cause: ${error.show}") } } diff --git a/es72x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala b/es72x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala index 5ab1e35742..a9af8f710a 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala @@ -16,13 +16,13 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.settings.Settings import tech.beshu.ror.tools.core.patches.PatchingVerifier import tech.beshu.ror.tools.core.patches.PatchingVerifier.Error.{CannotVerifyIfPatched, EsNotPatched} import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -object EsPatchVerifier extends Logging { +object EsPatchVerifier extends RequestIdAwareLogging { def verify(settings: Settings): Unit = doPrivileged { pathHomeFrom(settings).flatMap(PatchingVerifier.verify) match { @@ -30,7 +30,7 @@ object EsPatchVerifier extends Logging { case Left(e@EsNotPatched(_)) => throw new IllegalStateException(e.message) case Left(e@CannotVerifyIfPatched(_)) => - logger.warn(e.message) + noRequestIdLogger.warn(e.message) } } diff --git a/es73x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es73x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index 6678bb7ee0..5c135fd766 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.support.{ActionFilter, ActionFilterChain} import org.elasticsearch.action.{ActionListener, ActionRequest, ActionResponse} import org.elasticsearch.client.node.NodeClient @@ -60,7 +60,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, rorEsConfig: ReadonlyRestEsConfig) (implicit environmentConfig: EnvironmentConfig) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = environmentConfig.uniqueIdentifierGenerator @@ -201,12 +201,12 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def handleRorNotReadyYet(esContext: EsContext): Unit = { - logger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") + noRequestIdLogger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") rorNotAvailableRequestHandler.handleRorNotReadyYet(esContext) } private def handleRorFailedToStart(esContext: EsContext): Unit = { - logger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") + noRequestIdLogger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") rorNotAvailableRequestHandler.handleRorFailedToStart(esContext) } @@ -228,7 +228,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def logAndSetStartingFailureState(failure: StartingFailure): Unit = { - logger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) + noRequestIdLogger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) rorInstanceState.set(RorInstanceStartingState.NotStarted(failure)) } } diff --git a/es73x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala b/es73x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala index 7f92461f08..72c14bf252 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.xcontent.cbor.CborXContent import org.elasticsearch.common.xcontent.json.JsonXContent import org.elasticsearch.common.xcontent.smile.SmileXContent @@ -29,7 +29,7 @@ import tech.beshu.ror.accesscontrol.domain.ResponseFieldsFiltering.{AccessMode, import scala.jdk.CollectionConverters.* trait ResponseFieldsFiltering { - this: Logging => + this: RequestIdAwareLogging => private val responseFieldsRestrictions: Atomic[Option[ResponseFieldsRestrictions]] = Atomic(None: Option[ResponseFieldsRestrictions]) @@ -44,7 +44,7 @@ trait ResponseFieldsFiltering { case bytesRestResponse: BytesRestResponse => filterBytesRestResponse(bytesRestResponse, fieldsRestrictions) case otherResponse => - logger.warn("ResponseFields filtering is unavailable for this type of request") + noRequestIdLogger.warn("ResponseFields filtering is unavailable for this type of request") otherResponse } case None => diff --git a/es73x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala b/es73x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala index 0f26750588..da95de59a4 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.action.{ActionListener, ActionResponse} import org.elasticsearch.threadpool.ThreadPool @@ -37,7 +37,7 @@ sealed abstract class RorActionListener[T](val underlying: ActionListener[T]) ex final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionListener[T], correlationId: Eval[CorrelationId]) - extends RorActionListener[T](underlying) with Logging { + extends RorActionListener[T](underlying) with RequestIdAwareLogging { override def onFailure(e: Exception): Unit = { super.onFailure(adaptExceptionIfNeeded(e)) @@ -47,7 +47,7 @@ final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionLis ex match { case esException: ElasticsearchException => esException case other => - logger.error(s"[${correlationId.value.show}] Internal error.", other) + noRequestIdLogger.error(s"[${correlationId.value.show}] Internal error.", other) new ElasticsearchException(s"[${correlationId.value.show}] Internal error. See logs for details.") } } diff --git a/es73x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala b/es73x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala index 0a80ad8a51..09e707bd3e 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.http.HttpChannel import org.elasticsearch.rest.{AbstractRestChannel, RestChannel as EsRestChannel, RestRequest as EsRestRequest, RestResponse as EsRestResponse} import squants.information.{Bytes, Information} @@ -40,7 +40,7 @@ object RorRestChannel { final class RorRestChannel private(underlying: EsRestChannel, val restRequest: RorRestRequest) extends AbstractRestChannel(underlying.request(), true) with ResponseFieldsFiltering - with Logging { + with RequestIdAwareLogging { override def sendResponse(response: EsRestResponse): Unit = { ThreadRepo.removeRestChannel(this) diff --git a/es73x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala b/es73x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala index 6babc712b9..3c80750a25 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala @@ -18,16 +18,15 @@ package tech.beshu.ror.es.actions.rradmin import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.ConfigApi.ConfigResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAdminActionHandler extends Logging { +class RRAdminActionHandler extends RequestIdAwareLogging { private implicit val adminRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +51,7 @@ class RRAdminActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAdminResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAdminAction internal error", ex) + logger.error("RRAdminAction internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es73x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala b/es73x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala index c55835a1d0..ce45c6f48e 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala @@ -16,18 +16,15 @@ */ package tech.beshu.ror.es.actions.rrauthmock -import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.AuthMockApi.AuthMockResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier -import tech.beshu.ror.implicits.* +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAuthMockActionHandler extends Logging { +class RRAuthMockActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -53,7 +50,7 @@ class RRAuthMockActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAuthMockResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAuthMock internal error", ex) + logger.error("RRAuthMock internal error", ex) listener.onFailure(new Exception(ex)) } } diff --git a/es73x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala b/es73x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala index aa8bb31e67..640084c4ec 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestconfig import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.TestConfigApi.TestConfigResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestConfigActionHandler extends Logging { +class RRTestConfigActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +52,7 @@ class RRTestConfigActionHandler extends Logging { case Right(response) => listener.onResponse(new RRTestConfigResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRTestConfig internal error", ex) + logger.error(s"RRTestConfig internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es73x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala b/es73x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala index 5e42d55f7e..4d9a78443a 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.dlsfls import cats.data.StateT import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.DirectoryReader import org.elasticsearch.common.CheckedFunction import org.elasticsearch.common.util.concurrent.ThreadContext @@ -31,7 +31,7 @@ import java.io.IOException import java.util.function.{Function => JavaFunction} import scala.util.{Failure, Success, Try} -object RoleIndexSearcherWrapper extends Logging { +object RoleIndexSearcherWrapper extends RequestIdAwareLogging { val instance: JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] = new JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] { @@ -54,7 +54,7 @@ object RoleIndexSearcherWrapper extends Logging { } .map(r => (r, r)) case None => - logger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") + noRequestIdLogger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") Success((reader, reader)) } } @@ -66,13 +66,13 @@ object RoleIndexSearcherWrapper extends Logging { nel <- NonEmptyString.from(value) match { case Right(nel) => Success(nel) case Left(_) => - logger.debug("FLS: empty header value") + noRequestIdLogger.debug("FLS: empty header value") failure } fields <- transientFieldsFromHeaderValue.fromRawValue(nel) match { case result@Success(_) => result case Failure(ex) => - logger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) + noRequestIdLogger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) failure } } yield fields diff --git a/es73x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala b/es73x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala index 85f92af263..a98c7a1067 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.dlsfls import java.io.ByteArrayOutputStream import java.util.{Iterator => JavaIterator} import com.google.common.collect.Iterators -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.StoredFieldVisitor.Status import org.apache.lucene.index.* import org.apache.lucene.util.Bits @@ -36,21 +36,21 @@ import scala.jdk.CollectionConverters.* import scala.util.Try private class RorDocumentFieldReader(reader: LeafReader, fieldsRestrictions: FieldsRestrictions) - extends FilterLeafReader(reader) with Logging { + extends FilterLeafReader(reader) with RequestIdAwareLogging { private val policy = new FieldsPolicy(fieldsRestrictions) private val remainingFieldsInfo = { val fInfos = in.getFieldInfos val newInfos = if (fInfos.asScala.isEmpty) { - logger.warn("original fields were empty! This is weird!") + noRequestIdLogger.warn("original fields were empty! This is weird!") fInfos } else { val remainingFields = fInfos.asScala.filter(f => policy.canKeep(f.name)).toSet new FieldInfos(remainingFields.toArray) } - logger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") - logger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") - logger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") + noRequestIdLogger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") newInfos } private val jsonPolicyBasedFilterer = new JsonPolicyBasedFilterer(policy) diff --git a/es73x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala b/es73x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala index 15f2544476..42e0b270c0 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.* import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest @@ -84,7 +84,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, threadPool: ThreadPool) (implicit generator: UniqueIdentifierGenerator, scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle(engines: Engines, esContext: EsContext): Task[Either[Error, Unit]] = { @@ -204,7 +204,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, case SearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case MultiSearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case _ => - logger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") + noRequestIdLogger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") regularRequestHandler.handle(new DummyCompositeIndicesEsRequestContext(request, esContext, aclContext, clusterService, threadPool)) } // rest diff --git a/es73x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala b/es73x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala index a388bb0f9f..57be14c040 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.common.io.stream.StreamOutput import org.elasticsearch.common.xcontent.{ToXContent, ToXContentObject, XContentBuilder} @@ -45,7 +45,7 @@ import scala.util.{Failure, Success, Try} class CurrentUserMetadataRequestHandler(engine: Engine, esContext: EsContext) - extends Logging { + extends RequestIdAwareLogging { def handle(request: RequestContext.Aux[CurrentUserMetadataRequestBlockContext] with EsRequest[CurrentUserMetadataRequestBlockContext]): Task[Unit] = { engine.core.accessControl @@ -69,7 +69,7 @@ class CurrentUserMetadataRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(ex.asInstanceOf[Exception]) } } @@ -86,13 +86,13 @@ class CurrentUserMetadataRequestHandler(engine: Engine, )) } - private def onPassThrough(requestContext: RequestContext): Unit = { - logger.warn(s"[${requestContext.id.toRequestId.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") + private def onPassThrough(implicit requestContext: RequestContext): Unit = { + logger.warn(s"Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") esContext.listener.onFailure(createRorNotEnabledResponse()) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } diff --git a/es73x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala b/es73x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala index 2fb01dcc41..c5c44fda92 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala @@ -20,7 +20,7 @@ import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.RegularRequestResult @@ -49,7 +49,7 @@ class RegularRequestHandler(engine: Engine, esContext: EsContext, threadPool: ThreadPool) (implicit scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle[B <: BlockContext : BlockContextUpdater](request: RequestContext.Aux[B] with EsRequest[B]): Task[Unit] = { engine.core.accessControl @@ -85,7 +85,7 @@ class RegularRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(new Exception(ex)) } } @@ -99,7 +99,7 @@ class RegularRequestHandler(engine: Engine, case ModificationResult.ShouldBeInterrupted => onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case ModificationResult.CannotModify => - logger.error(s"[${request.id.toRequestId.show}] Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") + noRequestIdLogger.error(s"Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case CustomResponse(response) => respond(request, response) @@ -247,7 +247,7 @@ class RegularRequestHandler(engine: Engine, esContext.listener.onResponse(response) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } \ No newline at end of file diff --git a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala index f6db2b2f6e..7ad5f7b26d 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.index.query.{AbstractQueryBuilder, QueryBuilder, QueryBuilders} import org.elasticsearch.search.aggregations.AggregatorFactories @@ -40,7 +40,7 @@ import tech.beshu.ror.implicits.* import java.util.UUID import scala.jdk.CollectionConverters.* -object SearchRequestOps extends Logging { +object SearchRequestOps extends RequestIdAwareLogging { implicit class QueryBuilderOps(val builder: Option[QueryBuilder]) extends AnyVal { @@ -52,7 +52,7 @@ object SearchRequestOps extends Logging { val modifiedQuery: AbstractQueryBuilder[_] = provideNewQueryWithAppliedFilter(builder, filterQuery) Some(modifiedQuery) case None => - logger.debug(s"[${requestId.show}] No filter applied to query.") + logger.debug(s"No filter applied to query.") builder } } @@ -92,7 +92,7 @@ object SearchRequestOps extends Logging { case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, requestId) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) disableCaching(requestId) case BasedOnBlockContextOnly.NotAllowedFieldsUsed(notAllowedFields) => modifyNotAllowedFieldsInRequest(notAllowedFields) @@ -138,8 +138,8 @@ object SearchRequestOps extends Logging { } } - private def disableCaching(requestId: RequestContext.Id) = { - logger.debug(s"[${requestId.show}] ACL uses context header for fields rule, will disable request cache for SearchRequest") + private def disableCaching(implicit requestId: RequestContext.Id) = { + logger.debug(s"ACL uses context header for fields rule, will disable request cache for SearchRequest") request.requestCache(false) } } diff --git a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala index d04bc3a95e..16827af969 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala @@ -17,7 +17,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.action.{CompositeIndicesRequest, IndicesRequest} import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -32,7 +31,7 @@ import java.time.Instant abstract class BaseEsRequestContext[B <: BlockContext](esContext: EsContext, clusterService: RorClusterService) - extends RequestContext with Logging { + extends RequestContext { override type BLOCK_CONTEXT = B diff --git a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala index ae8abbe1f5..0ee2967364 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala @@ -18,7 +18,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -26,8 +25,9 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import scala.util.Try +import tech.beshu.ror.utils.RequestIdAwareLogging -trait EsRequest[B <: BlockContext] extends Logging { +trait EsRequest[B <: BlockContext] extends RequestIdAwareLogging { implicit def threadPool: ThreadPool final def modifyUsing(blockContext: B): ModificationResult = { @@ -35,7 +35,7 @@ trait EsRequest[B <: BlockContext] extends Logging { Try(modifyRequest(blockContext)) .fold( ex => { - logger.error(s"[${blockContext.requestContext.id.show}] Cannot modify request with filtered data", ex) + logger.error(s"Cannot modify request with filtered data", ex)(blockContext) ModificationResult.CannotModify }, identity diff --git a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala index c091179cb6..d150709314 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala @@ -85,7 +85,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: case Some(indices) => update(actionRequest, indices, blockContext.filter, blockContext.fieldLevelSecurity) case None => - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -101,7 +101,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } \ No newline at end of file diff --git a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala index 71d462de57..48014e1bdc 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala @@ -73,7 +73,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, } yield update(actionRequest, filteredIndices, allAllowedIndices) result.getOrElse { - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -86,7 +86,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } diff --git a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala index 95d882c3b5..f607c0e347 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala @@ -50,7 +50,7 @@ abstract class BaseRepositoriesEsRequestContext[R <: ActionRequest](actionReques case Some(repositories) => update(actionRequest, repositories) case None => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") ShouldBeInterrupted } } diff --git a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala index b3b1d66238..7ef0f32014 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala @@ -42,7 +42,7 @@ abstract class BaseSingleIndexEsRequestContext[R <: ActionRequest](actionRequest filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } update(request, filteredIndices.head) } diff --git a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala index b5ab70fe7a..c1b2e7ea27 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala @@ -62,7 +62,7 @@ class BulkEsRequestContext(actionRequest: BulkRequest, case (_, _) => ShouldBeInterrupted } } else { - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because origin request contained different " + + logger.error(s"Cannot alter MultiGetRequest request, because origin request contained different " + s"number of requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } @@ -90,18 +90,18 @@ class BulkEsRequestContext(actionRequest: BulkRequest, updateRequestWithIndices(request, nel) Modified case None => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because empty list of indices was found") + logger.error(s"Cannot alter MultiGetRequest request, because empty list of indices was found") ShouldBeInterrupted } case Indices.NotFound => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because no allowed indices were found") + logger.error(s"Cannot alter MultiGetRequest request, because no allowed indices were found") ShouldBeInterrupted } } private def updateRequestWithIndices(request: DocWriteRequest[_], indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } request.index(indices.head.stringify) } diff --git a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala index 75a75fcef5..96a043b298 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala @@ -53,14 +53,14 @@ class BulkShardEsRequestContext(actionRequest: BulkShardRequest, case Success(_) => Modified case Failure(ex) => - logger.error(s"[${id.show}] Cannot modify BulkShardRequest", ex) + logger.error(s"Cannot modify BulkShardRequest", ex) CannotModify } } private def tryUpdate(request: BulkShardRequest, indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } val singleIndex = indices.head val uuid = clusterService.indexOrAliasUuids(singleIndex.name).toList.head diff --git a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala index 65a168092a..158ac485a5 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala @@ -45,14 +45,14 @@ class ClusterAllocationExplainEsRequestContext(actionRequest: ClusterAllocationE getRequestedIndexFrom(request) match { case Some(_) => if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateIndexIn(request, filteredIndices.head) Modified case None if filteredIndices.exists(_.name === ClusterIndexName.Local.wildcard) => Modified case None => - logger.error(s"[${id.show}] Cluster allocation explain request without index name is unavailable when block contains `indices` rule") + logger.error(s"Cluster allocation explain request without index name is unavailable when block contains `indices` rule") ShouldBeInterrupted } } diff --git a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala index 24e15f40e8..b73c123699 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala @@ -69,7 +69,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, updateAliases(actionRequest, aliases) UpdateResponse.sync(updateAliasesResponse(aliases.includedOnly, _)) case None => - logger.error(s"[${id.show}] At least one alias and one index has to be allowed. " + + logger.error(s"At least one alias and one index has to be allowed. " + s"Found allowed indices: [${blockContext.indices.show}]." + s"Found allowed aliases: [${blockContext.aliases.show}]") ShouldBeInterrupted @@ -117,7 +117,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, .indices().asSafeSet .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } @@ -125,7 +125,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, val aliases = rawRequestAliasesSet(request) .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered aliases: ${aliases.show}") + logger.debug(s"Discovered aliases: ${aliases.show}") aliases } diff --git a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala index abb85d42b7..f9e2c87e53 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala @@ -55,7 +55,7 @@ class IndicesAliasesEsRequestContext(actionRequest: IndicesAliasesRequest, if (originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala index 05b70606b9..37dd50452b 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala @@ -119,7 +119,7 @@ class MultiGetEsRequestContext(actionRequest: MultiGetRequest, case Nil => updateItemWithNonExistingIndex(item) case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } item.index(index.stringify) } diff --git a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala index 989956d79a..9e13edee8d 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala @@ -78,7 +78,7 @@ class MultiSearchEsRequestContext(actionRequest: MultiSearchRequest, } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala index 9191e33b66..5a61356f48 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala @@ -47,7 +47,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { request.getRequests.removeIf { request => removeOrAlter(request, filteredIndices.toCovariantSet) } if (request.getRequests.asScala.isEmpty) { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") ShouldBeInterrupted } else { Modified @@ -63,7 +63,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, true case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") } request.index(index.stringify) false diff --git a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala index c411df93c5..c7b99f6e85 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala @@ -52,7 +52,7 @@ class PutRollupJobEsRequestContext private(actionRequest: ActionRequest, if(originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala index 141d9db788..fff8ed58bb 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala @@ -49,7 +49,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (tryUpdate(actionRequest, filteredIndices)) Modified else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") ShouldBeInterrupted } } diff --git a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala index 489d0187bc..c42dfc3b78 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala @@ -58,10 +58,10 @@ class ReindexEsRequestContext(actionRequest: ReindexRequest, Modified } else { if (!isDestinationIndexOnFilteredIndicesList) { - logger.info(s"[${id.show}] Destination index of _reindex request is forbidden") + logger.info(s"Destination index of _reindex request is forbidden") } if (!isSearchRequestComposedOnlyOfAllowedIndices) { - logger.info(s"[${id.show}] At least one index from sources indices list of _reindex request is forbidden") + logger.info(s"At least one index from sources indices list of _reindex request is forbidden") } ShouldBeInterrupted } diff --git a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala index 2c1b0014e0..97b8ccd9c5 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala @@ -74,7 +74,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo request } case Left(_) => - logger.debug(s"[${id.show}] Cannot parse SQL statement - we can pass it though, because ES is going to reject it") + logger.debug(s"Cannot parse SQL statement - we can pass it though, because ES is going to reject it") request } } @@ -85,7 +85,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala index 44b7d78dfd..d09015139b 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CreateRepositoryEsRequestContext(actionRequest: PutRepositoryRequest, override protected def update(request: PutRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala index eaf9334872..0cf32e1bea 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class DeleteRepositoryEsRequestContext(actionRequest: DeleteRepositoryRequest, override protected def update(request: DeleteRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala index cee0bffd4c..d1410eff3d 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class VerifyRepositoryEsRequestContext(actionRequest: VerifyRepositoryRequest, override protected def update(request: VerifyRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala index ead4fcf250..20501516d5 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala @@ -68,32 +68,32 @@ class CreateSnapshotEsRequestContext(actionRequest: CreateSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala index 281a0d73f6..27b13ffa11 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala @@ -59,32 +59,32 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala index 58122fb44f..782a54d7df 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala @@ -69,7 +69,7 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, case r => r } case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -81,14 +81,14 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.mkString(",")}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.mkString(",")}]") } Right(repository) } diff --git a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala index 88887db96c..156deb5b80 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala @@ -63,7 +63,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -75,7 +75,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") } Right(snapshot) } @@ -88,7 +88,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala index 44ee8397ec..e522e440f1 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala @@ -100,12 +100,12 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { val repositories = blockContext.repositories if (allRepositoriesRequested(repositories)) { Right(RepositoryName.All) @@ -115,7 +115,7 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala index 0bdf0ce63d..243d0dff91 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.{GetIndexTemplatesRequest, GetIndexTemplatesResponse} import org.elasticsearch.cluster.metadata.{AliasMetaData, IndexTemplateMetaData} import org.elasticsearch.common.collect.ImmutableOpenMap @@ -100,7 +100,7 @@ class GetTemplatesEsRequestContext(actionRequest: GetIndexTemplatesRequest, } -private[templates] object GetTemplatesEsRequestContext extends Logging { +private[templates] object GetTemplatesEsRequestContext extends RequestIdAwareLogging { def filter(templates: Iterable[IndexTemplateMetaData], usingTemplate: Set[Template] => Set[Template]) diff --git a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala index f26cb0a547..0cc64c4f79 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala @@ -82,7 +82,7 @@ class MultiSearchTemplateEsRequestContext private(actionRequest: ActionRequest w callSearchOnceAgain(blockContext.filter, blockContext.fieldLevelSecurity) ) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala index 22a0c6791a..e08a2fbb72 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.queries import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.index.query.* import org.joor.Reflect.on import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.RequestFieldsUsage @@ -32,7 +32,7 @@ trait QueryFieldsUsage[QUERY <: QueryBuilder] { def fieldsIn(query: QUERY): RequestFieldsUsage } -object QueryFieldsUsage extends Logging { +object QueryFieldsUsage extends RequestIdAwareLogging { def apply[QUERY <: QueryBuilder](implicit ev: QueryFieldsUsage[QUERY]): QueryFieldsUsage[QUERY] = ev implicit class Ops[QUERY <: QueryBuilder : QueryFieldsUsage](val query: QUERY) { @@ -65,7 +65,7 @@ object QueryFieldsUsage extends Logging { Option(on(query).call("getFieldName").get[String]) match { case Some(fieldName: String) => UsingFields(NonEmptyList.one(UsedField(fieldName))) case _ => - logger.debug(s"Cannot extract fields for terms set query") + noRequestIdLogger.debug(s"Cannot extract fields for terms set query") CannotExtractFields } } @@ -93,7 +93,7 @@ object QueryFieldsUsage extends Logging { case builder: TermsSetQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder: WildcardQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder => - logger.debug(s"Cannot extract fields for query: ${builder.getName}") + noRequestIdLogger.debug(s"Cannot extract fields for query: ${builder.getName}") CannotExtractFields } diff --git a/es73x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala b/es73x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala index 0998bb9a5b..b4671e9e4d 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.handler.response import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.FieldsRestrictions import tech.beshu.ror.accesscontrol.domain.Header @@ -26,17 +26,17 @@ import tech.beshu.ror.accesscontrol.headerValues.transientFieldsToHeaderValue import tech.beshu.ror.accesscontrol.request.RequestContext import tech.beshu.ror.implicits.* -object FLSContextHeaderHandler extends Logging { +object FLSContextHeaderHandler extends RequestIdAwareLogging { def addContextHeader(threadPool: ThreadPool, - fieldsRestrictions: FieldsRestrictions, - requestId: RequestContext.Id): Unit = { + fieldsRestrictions: FieldsRestrictions) + (implicit requestId: RequestContext.Id): Unit = { val threadContext = threadPool.getThreadContext val header = createContextHeader(fieldsRestrictions) Option(threadContext.getHeader(header.name.value.value)) match { case None => implicit val show = headerShow - logger.debug(s"[${requestId.show}] Adding thread context header required by lucene. Header: '${header.show}'") + logger.debug(s"Adding thread context header required by lucene. Header: '${header.show}'") threadContext.putHeader(header.name.value.value, header.value.value) case Some(_) => } diff --git a/es73x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala b/es73x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala index 18490a232c..b65ba21df7 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.support.WriteRequest.RefreshPolicy import org.elasticsearch.client.node.NodeClient @@ -38,7 +38,7 @@ import scala.jdk.CollectionConverters.* class EsIndexJsonContentService(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexJsonContentService - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -63,14 +63,14 @@ class EsIndexJsonContentService(client: NodeClient, Option(response.getSourceAsMap) match { case Some(map) => val source = map.asScala.toMap.asStringMap - logger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") Right(source) case None => - logger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") + noRequestIdLogger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") Right(Map.empty[String, String]) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(ContentNotFound) } } @@ -78,7 +78,7 @@ class EsIndexJsonContentService(client: NodeClient, .onErrorRecover { case _: ResourceNotFoundException => Left(ContentNotFound) case ex => - logger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) Left(CannotReachContentSource) } } @@ -104,14 +104,14 @@ class EsIndexJsonContentService(client: NodeClient, case status if status / 100 == 2 => Right(()) case status => - logger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") Left(CannotWriteToIndex) } } .executeOn(RorSchedulers.blockingScheduler) .onErrorRecover { case ex => - logger.error(s"Cannot write to document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]", ex) Left(CannotWriteToIndex) } } diff --git a/es73x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala b/es73x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala index 08ef262c0b..fbb72b4b13 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala @@ -21,7 +21,7 @@ import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task import monix.execution.CancelablePromise -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import org.elasticsearch.action.admin.cluster.state.{ClusterStateRequest, ClusterStateResponse} import org.elasticsearch.action.search.{MultiSearchResponse, SearchRequestBuilder, SearchResponse} @@ -62,7 +62,7 @@ class EsServerBasedRorClusterService(nodeName: String, nodeClient: NodeClient, threadPool: ThreadPool) extends RorClusterService - with Logging { + with RequestIdAwareLogging { import EsServerBasedRorClusterService.* @@ -144,7 +144,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractAccessibilityFrom) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify get request. Blocking document", ex) + logger.error(s"Could not verify get request. Blocking document", ex)(id) Inaccessible } } @@ -156,7 +156,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractResultsFromSearchResponse) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify documents returned by multi get response. Blocking all returned documents", ex) + logger.error(s"Could not verify documents returned by multi get response. Blocking all returned documents", ex)(id) blockAllDocsReturned(documents) } .map(results => zip(results, documents)) @@ -202,7 +202,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService) = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -271,7 +271,7 @@ class EsServerBasedRorClusterService(nodeName: String, } } case None => - logger.error("Cannot supply Snapshots Service. Please, report the issue!!!") + noRequestIdLogger.error("Cannot supply Snapshots Service. Please, report the issue!!!") Task.now(Set.empty[Snapshot]) } } diff --git a/es73x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala b/es73x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala index a85df473af..85e03005d3 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es.services -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.DocWriteRequest import org.elasticsearch.action.bulk.{BackoffPolicy, BulkProcessor, BulkRequest, BulkResponse} import org.elasticsearch.action.index.IndexRequest @@ -29,7 +29,7 @@ import tech.beshu.ror.es.IndexBasedAuditSinkService final class NodeClientBasedAuditSinkService(client: NodeClient) extends IndexBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { private val bulkProcessor = BulkProcessor @@ -61,25 +61,25 @@ final class NodeClientBasedAuditSinkService(client: NodeClient) private class AuditSinkBulkProcessorListener extends BulkProcessor.Listener { override def beforeBulk(executionId: Long, request: BulkRequest): Unit = { - logger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") + noRequestIdLogger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") } override def afterBulk(executionId: Long, request: BulkRequest, response: BulkResponse): Unit = { if (response.hasFailures) { - logger.error("Some failures flushing the BulkProcessor: ") + noRequestIdLogger.error("Some failures flushing the BulkProcessor: ") response .getItems.to(LazyList) .filter(_.isFailed) .map(_.getFailureMessage) .groupBy(identity) .foreach { case (message, stream) => - logger.error(s"${stream.size}x: $message") + noRequestIdLogger.error(s"${stream.size}x: $message") } } } override def afterBulk(executionId: Long, request: BulkRequest, failure: Throwable): Unit = { - logger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) + noRequestIdLogger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) } } diff --git a/es73x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala b/es73x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala index 6c627ede96..c6a4e6124d 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala @@ -22,7 +22,7 @@ import org.apache.http.auth.{AuthScope, Credentials, UsernamePasswordCredentials import org.apache.http.conn.ssl.NoopHostnameVerifier import org.apache.http.impl.client.BasicCredentialsProvider import org.apache.http.impl.nio.client.HttpAsyncClientBuilder -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.* import org.elasticsearch.client.RestClient.FailureListener import tech.beshu.ror.accesscontrol.domain.AuditCluster.ClusterMode @@ -36,7 +36,7 @@ import scala.collection.parallel.CollectionConverters.* final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient]) extends IndexBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { override def submit(indexName: IndexName.Full, documentId: String, jsonRecord: String) (implicit requestId: RequestId): Unit = { @@ -70,19 +70,19 @@ final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient] override def onSuccess(response: Response): Unit = { response.getStatusLine.getStatusCode / 100 match { case 2 => // 2xx - logger.debug(s"[${requestId.show}] Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") + logger.debug(s"Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") case _ => - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") } } override def onFailure(ex: Exception): Unit = { - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId]", ex) + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId]", ex) } } } -object RestClientAuditSinkService extends Logging { +object RestClientAuditSinkService extends RequestIdAwareLogging { def create(remoteCluster: AuditCluster.RemoteAuditCluster): RestClientAuditSinkService = { remoteCluster.mode match { @@ -113,7 +113,7 @@ object RestClientAuditSinkService extends Logging { .setFailureListener( new FailureListener { override def onFailure(node: Node): Unit = { - logger.debug( + noRequestIdLogger.debug( s"[AUDIT] Node marked dead: ${node.getHost.getSchemeName}://${node.getHost.getHostName}:${node.getHost.getPort}. The client will attempt failover.", ) } diff --git a/es73x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala b/es73x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala index f3b70cb4ae..52f09127b7 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.Channel import io.netty.handler.ssl.NotSslRecordException -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.network.NetworkService import org.elasticsearch.common.settings.Settings import org.elasticsearch.common.util.BigArrays @@ -38,7 +38,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, ssl: ExternalSslConfiguration, fipsCompliant: Boolean) extends Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, ssl.clientAuthenticationEnabled) @@ -46,7 +46,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, override def onException(channel: HttpChannel, cause: Exception): Unit = { if (!this.lifecycle.started) return - else if (cause.getCause.isInstanceOf[NotSslRecordException]) logger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) + else if (cause.getCause.isInstanceOf[NotSslRecordException]) noRequestIdLogger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) else super.onException(channel, cause) channel.close() } diff --git a/es73x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala b/es73x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala index 3ac42afd15..ee7a7cdd26 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.* import io.netty.handler.ssl.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.Version import org.elasticsearch.cluster.node.DiscoveryNode import org.elasticsearch.common.io.stream.NamedWriteableRegistry @@ -44,7 +44,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, ssl: InternodeSslConfiguration, fipsCompliant: Boolean) extends Netty4Transport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = SSLCertHelper.prepareClientSSLContext(ssl, fipsCompliant, ssl.certificateVerificationEnabled) private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, clientAuthenticationEnabled = false) @@ -75,7 +75,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, override def exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable): Unit = { if (cause.isInstanceOf[NotSslRecordException] || (cause.getCause != null && cause.getCause.isInstanceOf[NotSslRecordException])) { - logger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") + noRequestIdLogger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") ctx.channel.close } else { super.exceptionCaught(ctx, cause) diff --git a/es73x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala b/es73x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala index db1b336f69..f385b4ab45 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.utils import cats.Show import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.client.node.NodeClient import org.elasticsearch.common.settings.Settings @@ -36,7 +36,7 @@ import scala.util.Try class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandler, settings: Settings) - extends RestHandler with Logging { + extends RestHandler with RequestIdAwareLogging { private val wrapped = doPrivileged { wrapSomeActions(underlying) @@ -94,11 +94,11 @@ class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandle private def logError(error: AuthorizationValueError): Unit = { { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorSanitizedShow - logger.warn(s"The incoming request was malformed. Cause: ${error.show}") + noRequestIdLogger.warn(s"The incoming request was malformed. Cause: ${error.show}") } if (logger.delegate.isDebugEnabled()) { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorWithDetailsShow - logger.debug(s"Malformed request detailed cause: ${error.show}") + noRequestIdLogger.debug(s"Malformed request detailed cause: ${error.show}") } } diff --git a/es73x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala b/es73x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala index 5ab1e35742..a9af8f710a 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala @@ -16,13 +16,13 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.settings.Settings import tech.beshu.ror.tools.core.patches.PatchingVerifier import tech.beshu.ror.tools.core.patches.PatchingVerifier.Error.{CannotVerifyIfPatched, EsNotPatched} import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -object EsPatchVerifier extends Logging { +object EsPatchVerifier extends RequestIdAwareLogging { def verify(settings: Settings): Unit = doPrivileged { pathHomeFrom(settings).flatMap(PatchingVerifier.verify) match { @@ -30,7 +30,7 @@ object EsPatchVerifier extends Logging { case Left(e@EsNotPatched(_)) => throw new IllegalStateException(e.message) case Left(e@CannotVerifyIfPatched(_)) => - logger.warn(e.message) + noRequestIdLogger.warn(e.message) } } diff --git a/es74x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es74x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index 6678bb7ee0..5c135fd766 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.support.{ActionFilter, ActionFilterChain} import org.elasticsearch.action.{ActionListener, ActionRequest, ActionResponse} import org.elasticsearch.client.node.NodeClient @@ -60,7 +60,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, rorEsConfig: ReadonlyRestEsConfig) (implicit environmentConfig: EnvironmentConfig) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = environmentConfig.uniqueIdentifierGenerator @@ -201,12 +201,12 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def handleRorNotReadyYet(esContext: EsContext): Unit = { - logger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") + noRequestIdLogger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") rorNotAvailableRequestHandler.handleRorNotReadyYet(esContext) } private def handleRorFailedToStart(esContext: EsContext): Unit = { - logger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") + noRequestIdLogger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") rorNotAvailableRequestHandler.handleRorFailedToStart(esContext) } @@ -228,7 +228,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def logAndSetStartingFailureState(failure: StartingFailure): Unit = { - logger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) + noRequestIdLogger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) rorInstanceState.set(RorInstanceStartingState.NotStarted(failure)) } } diff --git a/es74x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala b/es74x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala index 7f92461f08..72c14bf252 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.xcontent.cbor.CborXContent import org.elasticsearch.common.xcontent.json.JsonXContent import org.elasticsearch.common.xcontent.smile.SmileXContent @@ -29,7 +29,7 @@ import tech.beshu.ror.accesscontrol.domain.ResponseFieldsFiltering.{AccessMode, import scala.jdk.CollectionConverters.* trait ResponseFieldsFiltering { - this: Logging => + this: RequestIdAwareLogging => private val responseFieldsRestrictions: Atomic[Option[ResponseFieldsRestrictions]] = Atomic(None: Option[ResponseFieldsRestrictions]) @@ -44,7 +44,7 @@ trait ResponseFieldsFiltering { case bytesRestResponse: BytesRestResponse => filterBytesRestResponse(bytesRestResponse, fieldsRestrictions) case otherResponse => - logger.warn("ResponseFields filtering is unavailable for this type of request") + noRequestIdLogger.warn("ResponseFields filtering is unavailable for this type of request") otherResponse } case None => diff --git a/es74x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala b/es74x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala index 0f26750588..da95de59a4 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.action.{ActionListener, ActionResponse} import org.elasticsearch.threadpool.ThreadPool @@ -37,7 +37,7 @@ sealed abstract class RorActionListener[T](val underlying: ActionListener[T]) ex final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionListener[T], correlationId: Eval[CorrelationId]) - extends RorActionListener[T](underlying) with Logging { + extends RorActionListener[T](underlying) with RequestIdAwareLogging { override def onFailure(e: Exception): Unit = { super.onFailure(adaptExceptionIfNeeded(e)) @@ -47,7 +47,7 @@ final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionLis ex match { case esException: ElasticsearchException => esException case other => - logger.error(s"[${correlationId.value.show}] Internal error.", other) + noRequestIdLogger.error(s"[${correlationId.value.show}] Internal error.", other) new ElasticsearchException(s"[${correlationId.value.show}] Internal error. See logs for details.") } } diff --git a/es74x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala b/es74x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala index 0a80ad8a51..09e707bd3e 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.http.HttpChannel import org.elasticsearch.rest.{AbstractRestChannel, RestChannel as EsRestChannel, RestRequest as EsRestRequest, RestResponse as EsRestResponse} import squants.information.{Bytes, Information} @@ -40,7 +40,7 @@ object RorRestChannel { final class RorRestChannel private(underlying: EsRestChannel, val restRequest: RorRestRequest) extends AbstractRestChannel(underlying.request(), true) with ResponseFieldsFiltering - with Logging { + with RequestIdAwareLogging { override def sendResponse(response: EsRestResponse): Unit = { ThreadRepo.removeRestChannel(this) diff --git a/es74x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala b/es74x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala index 6babc712b9..3c80750a25 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala @@ -18,16 +18,15 @@ package tech.beshu.ror.es.actions.rradmin import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.ConfigApi.ConfigResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAdminActionHandler extends Logging { +class RRAdminActionHandler extends RequestIdAwareLogging { private implicit val adminRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +51,7 @@ class RRAdminActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAdminResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAdminAction internal error", ex) + logger.error("RRAdminAction internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es74x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala b/es74x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala index c55835a1d0..ce45c6f48e 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala @@ -16,18 +16,15 @@ */ package tech.beshu.ror.es.actions.rrauthmock -import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.AuthMockApi.AuthMockResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier -import tech.beshu.ror.implicits.* +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAuthMockActionHandler extends Logging { +class RRAuthMockActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -53,7 +50,7 @@ class RRAuthMockActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAuthMockResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAuthMock internal error", ex) + logger.error("RRAuthMock internal error", ex) listener.onFailure(new Exception(ex)) } } diff --git a/es74x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala b/es74x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala index aa8bb31e67..640084c4ec 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestconfig import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.TestConfigApi.TestConfigResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestConfigActionHandler extends Logging { +class RRTestConfigActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +52,7 @@ class RRTestConfigActionHandler extends Logging { case Right(response) => listener.onResponse(new RRTestConfigResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRTestConfig internal error", ex) + logger.error(s"RRTestConfig internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es74x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala b/es74x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala index 5e42d55f7e..4d9a78443a 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.dlsfls import cats.data.StateT import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.DirectoryReader import org.elasticsearch.common.CheckedFunction import org.elasticsearch.common.util.concurrent.ThreadContext @@ -31,7 +31,7 @@ import java.io.IOException import java.util.function.{Function => JavaFunction} import scala.util.{Failure, Success, Try} -object RoleIndexSearcherWrapper extends Logging { +object RoleIndexSearcherWrapper extends RequestIdAwareLogging { val instance: JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] = new JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] { @@ -54,7 +54,7 @@ object RoleIndexSearcherWrapper extends Logging { } .map(r => (r, r)) case None => - logger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") + noRequestIdLogger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") Success((reader, reader)) } } @@ -66,13 +66,13 @@ object RoleIndexSearcherWrapper extends Logging { nel <- NonEmptyString.from(value) match { case Right(nel) => Success(nel) case Left(_) => - logger.debug("FLS: empty header value") + noRequestIdLogger.debug("FLS: empty header value") failure } fields <- transientFieldsFromHeaderValue.fromRawValue(nel) match { case result@Success(_) => result case Failure(ex) => - logger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) + noRequestIdLogger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) failure } } yield fields diff --git a/es74x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala b/es74x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala index 85f92af263..a98c7a1067 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.dlsfls import java.io.ByteArrayOutputStream import java.util.{Iterator => JavaIterator} import com.google.common.collect.Iterators -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.StoredFieldVisitor.Status import org.apache.lucene.index.* import org.apache.lucene.util.Bits @@ -36,21 +36,21 @@ import scala.jdk.CollectionConverters.* import scala.util.Try private class RorDocumentFieldReader(reader: LeafReader, fieldsRestrictions: FieldsRestrictions) - extends FilterLeafReader(reader) with Logging { + extends FilterLeafReader(reader) with RequestIdAwareLogging { private val policy = new FieldsPolicy(fieldsRestrictions) private val remainingFieldsInfo = { val fInfos = in.getFieldInfos val newInfos = if (fInfos.asScala.isEmpty) { - logger.warn("original fields were empty! This is weird!") + noRequestIdLogger.warn("original fields were empty! This is weird!") fInfos } else { val remainingFields = fInfos.asScala.filter(f => policy.canKeep(f.name)).toSet new FieldInfos(remainingFields.toArray) } - logger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") - logger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") - logger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") + noRequestIdLogger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") newInfos } private val jsonPolicyBasedFilterer = new JsonPolicyBasedFilterer(policy) diff --git a/es74x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala b/es74x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala index 35cf4ef898..f76b31e7c1 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.* import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest import org.elasticsearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest @@ -85,7 +85,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, threadPool: ThreadPool) (implicit generator: UniqueIdentifierGenerator, scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle(engines: Engines, esContext: EsContext): Task[Either[Error, Unit]] = { @@ -207,7 +207,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, case SearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case MultiSearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case _ => - logger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") + noRequestIdLogger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") regularRequestHandler.handle(new DummyCompositeIndicesEsRequestContext(request, esContext, aclContext, clusterService, threadPool)) } // rest diff --git a/es74x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala b/es74x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala index a388bb0f9f..57be14c040 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.common.io.stream.StreamOutput import org.elasticsearch.common.xcontent.{ToXContent, ToXContentObject, XContentBuilder} @@ -45,7 +45,7 @@ import scala.util.{Failure, Success, Try} class CurrentUserMetadataRequestHandler(engine: Engine, esContext: EsContext) - extends Logging { + extends RequestIdAwareLogging { def handle(request: RequestContext.Aux[CurrentUserMetadataRequestBlockContext] with EsRequest[CurrentUserMetadataRequestBlockContext]): Task[Unit] = { engine.core.accessControl @@ -69,7 +69,7 @@ class CurrentUserMetadataRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(ex.asInstanceOf[Exception]) } } @@ -86,13 +86,13 @@ class CurrentUserMetadataRequestHandler(engine: Engine, )) } - private def onPassThrough(requestContext: RequestContext): Unit = { - logger.warn(s"[${requestContext.id.toRequestId.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") + private def onPassThrough(implicit requestContext: RequestContext): Unit = { + logger.warn(s"Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") esContext.listener.onFailure(createRorNotEnabledResponse()) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } diff --git a/es74x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala b/es74x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala index 2fb01dcc41..c5c44fda92 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala @@ -20,7 +20,7 @@ import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.RegularRequestResult @@ -49,7 +49,7 @@ class RegularRequestHandler(engine: Engine, esContext: EsContext, threadPool: ThreadPool) (implicit scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle[B <: BlockContext : BlockContextUpdater](request: RequestContext.Aux[B] with EsRequest[B]): Task[Unit] = { engine.core.accessControl @@ -85,7 +85,7 @@ class RegularRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(new Exception(ex)) } } @@ -99,7 +99,7 @@ class RegularRequestHandler(engine: Engine, case ModificationResult.ShouldBeInterrupted => onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case ModificationResult.CannotModify => - logger.error(s"[${request.id.toRequestId.show}] Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") + noRequestIdLogger.error(s"Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case CustomResponse(response) => respond(request, response) @@ -247,7 +247,7 @@ class RegularRequestHandler(engine: Engine, esContext.listener.onResponse(response) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } \ No newline at end of file diff --git a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala index f6db2b2f6e..7ad5f7b26d 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.index.query.{AbstractQueryBuilder, QueryBuilder, QueryBuilders} import org.elasticsearch.search.aggregations.AggregatorFactories @@ -40,7 +40,7 @@ import tech.beshu.ror.implicits.* import java.util.UUID import scala.jdk.CollectionConverters.* -object SearchRequestOps extends Logging { +object SearchRequestOps extends RequestIdAwareLogging { implicit class QueryBuilderOps(val builder: Option[QueryBuilder]) extends AnyVal { @@ -52,7 +52,7 @@ object SearchRequestOps extends Logging { val modifiedQuery: AbstractQueryBuilder[_] = provideNewQueryWithAppliedFilter(builder, filterQuery) Some(modifiedQuery) case None => - logger.debug(s"[${requestId.show}] No filter applied to query.") + logger.debug(s"No filter applied to query.") builder } } @@ -92,7 +92,7 @@ object SearchRequestOps extends Logging { case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, requestId) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) disableCaching(requestId) case BasedOnBlockContextOnly.NotAllowedFieldsUsed(notAllowedFields) => modifyNotAllowedFieldsInRequest(notAllowedFields) @@ -138,8 +138,8 @@ object SearchRequestOps extends Logging { } } - private def disableCaching(requestId: RequestContext.Id) = { - logger.debug(s"[${requestId.show}] ACL uses context header for fields rule, will disable request cache for SearchRequest") + private def disableCaching(implicit requestId: RequestContext.Id) = { + logger.debug(s"ACL uses context header for fields rule, will disable request cache for SearchRequest") request.requestCache(false) } } diff --git a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala index d04bc3a95e..16827af969 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala @@ -17,7 +17,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.action.{CompositeIndicesRequest, IndicesRequest} import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -32,7 +31,7 @@ import java.time.Instant abstract class BaseEsRequestContext[B <: BlockContext](esContext: EsContext, clusterService: RorClusterService) - extends RequestContext with Logging { + extends RequestContext { override type BLOCK_CONTEXT = B diff --git a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala index ae8abbe1f5..0ee2967364 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala @@ -18,7 +18,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -26,8 +25,9 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import scala.util.Try +import tech.beshu.ror.utils.RequestIdAwareLogging -trait EsRequest[B <: BlockContext] extends Logging { +trait EsRequest[B <: BlockContext] extends RequestIdAwareLogging { implicit def threadPool: ThreadPool final def modifyUsing(blockContext: B): ModificationResult = { @@ -35,7 +35,7 @@ trait EsRequest[B <: BlockContext] extends Logging { Try(modifyRequest(blockContext)) .fold( ex => { - logger.error(s"[${blockContext.requestContext.id.show}] Cannot modify request with filtered data", ex) + logger.error(s"Cannot modify request with filtered data", ex)(blockContext) ModificationResult.CannotModify }, identity diff --git a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala index c091179cb6..d150709314 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala @@ -85,7 +85,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: case Some(indices) => update(actionRequest, indices, blockContext.filter, blockContext.fieldLevelSecurity) case None => - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -101,7 +101,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } \ No newline at end of file diff --git a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala index 71d462de57..48014e1bdc 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala @@ -73,7 +73,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, } yield update(actionRequest, filteredIndices, allAllowedIndices) result.getOrElse { - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -86,7 +86,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } diff --git a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala index 95d882c3b5..f607c0e347 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala @@ -50,7 +50,7 @@ abstract class BaseRepositoriesEsRequestContext[R <: ActionRequest](actionReques case Some(repositories) => update(actionRequest, repositories) case None => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") ShouldBeInterrupted } } diff --git a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala index b3b1d66238..7ef0f32014 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala @@ -42,7 +42,7 @@ abstract class BaseSingleIndexEsRequestContext[R <: ActionRequest](actionRequest filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } update(request, filteredIndices.head) } diff --git a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala index b5ab70fe7a..c1b2e7ea27 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala @@ -62,7 +62,7 @@ class BulkEsRequestContext(actionRequest: BulkRequest, case (_, _) => ShouldBeInterrupted } } else { - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because origin request contained different " + + logger.error(s"Cannot alter MultiGetRequest request, because origin request contained different " + s"number of requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } @@ -90,18 +90,18 @@ class BulkEsRequestContext(actionRequest: BulkRequest, updateRequestWithIndices(request, nel) Modified case None => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because empty list of indices was found") + logger.error(s"Cannot alter MultiGetRequest request, because empty list of indices was found") ShouldBeInterrupted } case Indices.NotFound => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because no allowed indices were found") + logger.error(s"Cannot alter MultiGetRequest request, because no allowed indices were found") ShouldBeInterrupted } } private def updateRequestWithIndices(request: DocWriteRequest[_], indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } request.index(indices.head.stringify) } diff --git a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala index 75a75fcef5..96a043b298 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala @@ -53,14 +53,14 @@ class BulkShardEsRequestContext(actionRequest: BulkShardRequest, case Success(_) => Modified case Failure(ex) => - logger.error(s"[${id.show}] Cannot modify BulkShardRequest", ex) + logger.error(s"Cannot modify BulkShardRequest", ex) CannotModify } } private def tryUpdate(request: BulkShardRequest, indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } val singleIndex = indices.head val uuid = clusterService.indexOrAliasUuids(singleIndex.name).toList.head diff --git a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala index 65a168092a..158ac485a5 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala @@ -45,14 +45,14 @@ class ClusterAllocationExplainEsRequestContext(actionRequest: ClusterAllocationE getRequestedIndexFrom(request) match { case Some(_) => if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateIndexIn(request, filteredIndices.head) Modified case None if filteredIndices.exists(_.name === ClusterIndexName.Local.wildcard) => Modified case None => - logger.error(s"[${id.show}] Cluster allocation explain request without index name is unavailable when block contains `indices` rule") + logger.error(s"Cluster allocation explain request without index name is unavailable when block contains `indices` rule") ShouldBeInterrupted } } diff --git a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala index 24e15f40e8..b73c123699 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala @@ -69,7 +69,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, updateAliases(actionRequest, aliases) UpdateResponse.sync(updateAliasesResponse(aliases.includedOnly, _)) case None => - logger.error(s"[${id.show}] At least one alias and one index has to be allowed. " + + logger.error(s"At least one alias and one index has to be allowed. " + s"Found allowed indices: [${blockContext.indices.show}]." + s"Found allowed aliases: [${blockContext.aliases.show}]") ShouldBeInterrupted @@ -117,7 +117,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, .indices().asSafeSet .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } @@ -125,7 +125,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, val aliases = rawRequestAliasesSet(request) .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered aliases: ${aliases.show}") + logger.debug(s"Discovered aliases: ${aliases.show}") aliases } diff --git a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala index abb85d42b7..f9e2c87e53 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala @@ -55,7 +55,7 @@ class IndicesAliasesEsRequestContext(actionRequest: IndicesAliasesRequest, if (originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala index 05b70606b9..37dd50452b 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala @@ -119,7 +119,7 @@ class MultiGetEsRequestContext(actionRequest: MultiGetRequest, case Nil => updateItemWithNonExistingIndex(item) case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } item.index(index.stringify) } diff --git a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala index 989956d79a..9e13edee8d 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala @@ -78,7 +78,7 @@ class MultiSearchEsRequestContext(actionRequest: MultiSearchRequest, } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala index 9191e33b66..5a61356f48 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala @@ -47,7 +47,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { request.getRequests.removeIf { request => removeOrAlter(request, filteredIndices.toCovariantSet) } if (request.getRequests.asScala.isEmpty) { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") ShouldBeInterrupted } else { Modified @@ -63,7 +63,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, true case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") } request.index(index.stringify) false diff --git a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala index c411df93c5..c7b99f6e85 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala @@ -52,7 +52,7 @@ class PutRollupJobEsRequestContext private(actionRequest: ActionRequest, if(originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala index 141d9db788..fff8ed58bb 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala @@ -49,7 +49,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (tryUpdate(actionRequest, filteredIndices)) Modified else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") ShouldBeInterrupted } } diff --git a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala index 489d0187bc..c42dfc3b78 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala @@ -58,10 +58,10 @@ class ReindexEsRequestContext(actionRequest: ReindexRequest, Modified } else { if (!isDestinationIndexOnFilteredIndicesList) { - logger.info(s"[${id.show}] Destination index of _reindex request is forbidden") + logger.info(s"Destination index of _reindex request is forbidden") } if (!isSearchRequestComposedOnlyOfAllowedIndices) { - logger.info(s"[${id.show}] At least one index from sources indices list of _reindex request is forbidden") + logger.info(s"At least one index from sources indices list of _reindex request is forbidden") } ShouldBeInterrupted } diff --git a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala index 2c1b0014e0..97b8ccd9c5 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala @@ -74,7 +74,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo request } case Left(_) => - logger.debug(s"[${id.show}] Cannot parse SQL statement - we can pass it though, because ES is going to reject it") + logger.debug(s"Cannot parse SQL statement - we can pass it though, because ES is going to reject it") request } } @@ -85,7 +85,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala index 0c67384c1e..d7e743e648 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CleanupRepositoryEsRequestContext(actionRequest: CleanupRepositoryRequest, override protected def update(request: CleanupRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala index 44b7d78dfd..d09015139b 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CreateRepositoryEsRequestContext(actionRequest: PutRepositoryRequest, override protected def update(request: PutRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala index eaf9334872..0cf32e1bea 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class DeleteRepositoryEsRequestContext(actionRequest: DeleteRepositoryRequest, override protected def update(request: DeleteRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala index cee0bffd4c..d1410eff3d 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class VerifyRepositoryEsRequestContext(actionRequest: VerifyRepositoryRequest, override protected def update(request: VerifyRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala index ead4fcf250..20501516d5 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala @@ -68,32 +68,32 @@ class CreateSnapshotEsRequestContext(actionRequest: CreateSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala index 281a0d73f6..27b13ffa11 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala @@ -59,32 +59,32 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala index 58122fb44f..782a54d7df 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala @@ -69,7 +69,7 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, case r => r } case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -81,14 +81,14 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.mkString(",")}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.mkString(",")}]") } Right(repository) } diff --git a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala index 88887db96c..156deb5b80 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala @@ -63,7 +63,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -75,7 +75,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") } Right(snapshot) } @@ -88,7 +88,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala index 44ee8397ec..e522e440f1 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala @@ -100,12 +100,12 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { val repositories = blockContext.repositories if (allRepositoriesRequested(repositories)) { Right(RepositoryName.All) @@ -115,7 +115,7 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala index 0bdf0ce63d..243d0dff91 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.{GetIndexTemplatesRequest, GetIndexTemplatesResponse} import org.elasticsearch.cluster.metadata.{AliasMetaData, IndexTemplateMetaData} import org.elasticsearch.common.collect.ImmutableOpenMap @@ -100,7 +100,7 @@ class GetTemplatesEsRequestContext(actionRequest: GetIndexTemplatesRequest, } -private[templates] object GetTemplatesEsRequestContext extends Logging { +private[templates] object GetTemplatesEsRequestContext extends RequestIdAwareLogging { def filter(templates: Iterable[IndexTemplateMetaData], usingTemplate: Set[Template] => Set[Template]) diff --git a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala index f26cb0a547..0cc64c4f79 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala @@ -82,7 +82,7 @@ class MultiSearchTemplateEsRequestContext private(actionRequest: ActionRequest w callSearchOnceAgain(blockContext.filter, blockContext.fieldLevelSecurity) ) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala index 22a0c6791a..e08a2fbb72 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.queries import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.index.query.* import org.joor.Reflect.on import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.RequestFieldsUsage @@ -32,7 +32,7 @@ trait QueryFieldsUsage[QUERY <: QueryBuilder] { def fieldsIn(query: QUERY): RequestFieldsUsage } -object QueryFieldsUsage extends Logging { +object QueryFieldsUsage extends RequestIdAwareLogging { def apply[QUERY <: QueryBuilder](implicit ev: QueryFieldsUsage[QUERY]): QueryFieldsUsage[QUERY] = ev implicit class Ops[QUERY <: QueryBuilder : QueryFieldsUsage](val query: QUERY) { @@ -65,7 +65,7 @@ object QueryFieldsUsage extends Logging { Option(on(query).call("getFieldName").get[String]) match { case Some(fieldName: String) => UsingFields(NonEmptyList.one(UsedField(fieldName))) case _ => - logger.debug(s"Cannot extract fields for terms set query") + noRequestIdLogger.debug(s"Cannot extract fields for terms set query") CannotExtractFields } } @@ -93,7 +93,7 @@ object QueryFieldsUsage extends Logging { case builder: TermsSetQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder: WildcardQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder => - logger.debug(s"Cannot extract fields for query: ${builder.getName}") + noRequestIdLogger.debug(s"Cannot extract fields for query: ${builder.getName}") CannotExtractFields } diff --git a/es74x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala b/es74x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala index 0998bb9a5b..b4671e9e4d 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.handler.response import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.FieldsRestrictions import tech.beshu.ror.accesscontrol.domain.Header @@ -26,17 +26,17 @@ import tech.beshu.ror.accesscontrol.headerValues.transientFieldsToHeaderValue import tech.beshu.ror.accesscontrol.request.RequestContext import tech.beshu.ror.implicits.* -object FLSContextHeaderHandler extends Logging { +object FLSContextHeaderHandler extends RequestIdAwareLogging { def addContextHeader(threadPool: ThreadPool, - fieldsRestrictions: FieldsRestrictions, - requestId: RequestContext.Id): Unit = { + fieldsRestrictions: FieldsRestrictions) + (implicit requestId: RequestContext.Id): Unit = { val threadContext = threadPool.getThreadContext val header = createContextHeader(fieldsRestrictions) Option(threadContext.getHeader(header.name.value.value)) match { case None => implicit val show = headerShow - logger.debug(s"[${requestId.show}] Adding thread context header required by lucene. Header: '${header.show}'") + logger.debug(s"Adding thread context header required by lucene. Header: '${header.show}'") threadContext.putHeader(header.name.value.value, header.value.value) case Some(_) => } diff --git a/es74x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala b/es74x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala index 18490a232c..b65ba21df7 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.support.WriteRequest.RefreshPolicy import org.elasticsearch.client.node.NodeClient @@ -38,7 +38,7 @@ import scala.jdk.CollectionConverters.* class EsIndexJsonContentService(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexJsonContentService - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -63,14 +63,14 @@ class EsIndexJsonContentService(client: NodeClient, Option(response.getSourceAsMap) match { case Some(map) => val source = map.asScala.toMap.asStringMap - logger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") Right(source) case None => - logger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") + noRequestIdLogger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") Right(Map.empty[String, String]) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(ContentNotFound) } } @@ -78,7 +78,7 @@ class EsIndexJsonContentService(client: NodeClient, .onErrorRecover { case _: ResourceNotFoundException => Left(ContentNotFound) case ex => - logger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) Left(CannotReachContentSource) } } @@ -104,14 +104,14 @@ class EsIndexJsonContentService(client: NodeClient, case status if status / 100 == 2 => Right(()) case status => - logger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") Left(CannotWriteToIndex) } } .executeOn(RorSchedulers.blockingScheduler) .onErrorRecover { case ex => - logger.error(s"Cannot write to document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]", ex) Left(CannotWriteToIndex) } } diff --git a/es74x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala b/es74x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala index a468a58e96..1c0bde486b 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala @@ -21,7 +21,7 @@ import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task import monix.execution.CancelablePromise -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import org.elasticsearch.action.admin.cluster.state.{ClusterStateRequest, ClusterStateResponse} import org.elasticsearch.action.search.{MultiSearchResponse, SearchRequestBuilder, SearchResponse} @@ -65,7 +65,7 @@ class EsServerBasedRorClusterService(nodeName: String, nodeClient: NodeClient, threadPool: ThreadPool) extends RorClusterService - with Logging { + with RequestIdAwareLogging { import EsServerBasedRorClusterService.* @@ -147,7 +147,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractAccessibilityFrom) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify get request. Blocking document", ex) + logger.error(s"Could not verify get request. Blocking document", ex)(id) Inaccessible } } @@ -159,7 +159,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractResultsFromSearchResponse) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify documents returned by multi get response. Blocking all returned documents", ex) + logger.error(s"Could not verify documents returned by multi get response. Blocking all returned documents", ex)(id) blockAllDocsReturned(documents) } .map(results => zip(results, documents)) @@ -205,7 +205,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService) = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -275,7 +275,7 @@ class EsServerBasedRorClusterService(nodeName: String, } } case None => - logger.error("Cannot supply Snapshots Service. Please, report the issue!!!") + noRequestIdLogger.error("Cannot supply Snapshots Service. Please, report the issue!!!") Task.now(Set.empty[Snapshot]) } } diff --git a/es74x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala b/es74x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala index 7f0463d496..c5b3439fd4 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es.services -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.DocWriteRequest import org.elasticsearch.action.bulk.{BackoffPolicy, BulkProcessor, BulkRequest, BulkResponse} import org.elasticsearch.action.index.IndexRequest @@ -31,7 +31,7 @@ import scala.annotation.nowarn final class NodeClientBasedAuditSinkService(client: NodeClient) extends IndexBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { @nowarn("cat=deprecation") private val bulkProcessor = @@ -64,25 +64,25 @@ final class NodeClientBasedAuditSinkService(client: NodeClient) private class AuditSinkBulkProcessorListener extends BulkProcessor.Listener { override def beforeBulk(executionId: Long, request: BulkRequest): Unit = { - logger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") + noRequestIdLogger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") } override def afterBulk(executionId: Long, request: BulkRequest, response: BulkResponse): Unit = { if (response.hasFailures) { - logger.error("Some failures flushing the BulkProcessor: ") + noRequestIdLogger.error("Some failures flushing the BulkProcessor: ") response .getItems.to(LazyList) .filter(_.isFailed) .map(_.getFailureMessage) .groupBy(identity) .foreach { case (message, stream) => - logger.error(s"${stream.size}x: $message") + noRequestIdLogger.error(s"${stream.size}x: $message") } } } override def afterBulk(executionId: Long, request: BulkRequest, failure: Throwable): Unit = { - logger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) + noRequestIdLogger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) } } diff --git a/es74x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala b/es74x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala index 6c627ede96..c6a4e6124d 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala @@ -22,7 +22,7 @@ import org.apache.http.auth.{AuthScope, Credentials, UsernamePasswordCredentials import org.apache.http.conn.ssl.NoopHostnameVerifier import org.apache.http.impl.client.BasicCredentialsProvider import org.apache.http.impl.nio.client.HttpAsyncClientBuilder -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.* import org.elasticsearch.client.RestClient.FailureListener import tech.beshu.ror.accesscontrol.domain.AuditCluster.ClusterMode @@ -36,7 +36,7 @@ import scala.collection.parallel.CollectionConverters.* final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient]) extends IndexBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { override def submit(indexName: IndexName.Full, documentId: String, jsonRecord: String) (implicit requestId: RequestId): Unit = { @@ -70,19 +70,19 @@ final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient] override def onSuccess(response: Response): Unit = { response.getStatusLine.getStatusCode / 100 match { case 2 => // 2xx - logger.debug(s"[${requestId.show}] Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") + logger.debug(s"Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") case _ => - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") } } override def onFailure(ex: Exception): Unit = { - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId]", ex) + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId]", ex) } } } -object RestClientAuditSinkService extends Logging { +object RestClientAuditSinkService extends RequestIdAwareLogging { def create(remoteCluster: AuditCluster.RemoteAuditCluster): RestClientAuditSinkService = { remoteCluster.mode match { @@ -113,7 +113,7 @@ object RestClientAuditSinkService extends Logging { .setFailureListener( new FailureListener { override def onFailure(node: Node): Unit = { - logger.debug( + noRequestIdLogger.debug( s"[AUDIT] Node marked dead: ${node.getHost.getSchemeName}://${node.getHost.getHostName}:${node.getHost.getPort}. The client will attempt failover.", ) } diff --git a/es74x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala b/es74x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala index f3b70cb4ae..52f09127b7 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.Channel import io.netty.handler.ssl.NotSslRecordException -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.network.NetworkService import org.elasticsearch.common.settings.Settings import org.elasticsearch.common.util.BigArrays @@ -38,7 +38,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, ssl: ExternalSslConfiguration, fipsCompliant: Boolean) extends Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, ssl.clientAuthenticationEnabled) @@ -46,7 +46,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, override def onException(channel: HttpChannel, cause: Exception): Unit = { if (!this.lifecycle.started) return - else if (cause.getCause.isInstanceOf[NotSslRecordException]) logger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) + else if (cause.getCause.isInstanceOf[NotSslRecordException]) noRequestIdLogger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) else super.onException(channel, cause) channel.close() } diff --git a/es74x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala b/es74x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala index 3ac42afd15..ee7a7cdd26 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.* import io.netty.handler.ssl.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.Version import org.elasticsearch.cluster.node.DiscoveryNode import org.elasticsearch.common.io.stream.NamedWriteableRegistry @@ -44,7 +44,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, ssl: InternodeSslConfiguration, fipsCompliant: Boolean) extends Netty4Transport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = SSLCertHelper.prepareClientSSLContext(ssl, fipsCompliant, ssl.certificateVerificationEnabled) private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, clientAuthenticationEnabled = false) @@ -75,7 +75,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, override def exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable): Unit = { if (cause.isInstanceOf[NotSslRecordException] || (cause.getCause != null && cause.getCause.isInstanceOf[NotSslRecordException])) { - logger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") + noRequestIdLogger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") ctx.channel.close } else { super.exceptionCaught(ctx, cause) diff --git a/es74x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala b/es74x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala index 12f5ea33b5..0577325e18 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.utils import cats.Show import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.client.node.NodeClient import org.elasticsearch.rest.* @@ -35,7 +35,7 @@ import java.lang.reflect.{InvocationHandler, Method, Proxy as JProxy} import scala.util.Try class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandler) - extends RestHandler with InvocationHandler with Logging { + extends RestHandler with InvocationHandler with RequestIdAwareLogging { private val wrapped = doPrivileged { wrapSomeActions(underlying) @@ -111,11 +111,11 @@ class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandle private def logError(error: AuthorizationValueError): Unit = { { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorSanitizedShow - logger.warn(s"The incoming request was malformed. Cause: ${error.show}") + noRequestIdLogger.warn(s"The incoming request was malformed. Cause: ${error.show}") } if (logger.delegate.isDebugEnabled()) { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorWithDetailsShow - logger.debug(s"Malformed request detailed cause: ${error.show}") + noRequestIdLogger.debug(s"Malformed request detailed cause: ${error.show}") } } diff --git a/es74x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala b/es74x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala index 5ab1e35742..a9af8f710a 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala @@ -16,13 +16,13 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.settings.Settings import tech.beshu.ror.tools.core.patches.PatchingVerifier import tech.beshu.ror.tools.core.patches.PatchingVerifier.Error.{CannotVerifyIfPatched, EsNotPatched} import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -object EsPatchVerifier extends Logging { +object EsPatchVerifier extends RequestIdAwareLogging { def verify(settings: Settings): Unit = doPrivileged { pathHomeFrom(settings).flatMap(PatchingVerifier.verify) match { @@ -30,7 +30,7 @@ object EsPatchVerifier extends Logging { case Left(e@EsNotPatched(_)) => throw new IllegalStateException(e.message) case Left(e@CannotVerifyIfPatched(_)) => - logger.warn(e.message) + noRequestIdLogger.warn(e.message) } } diff --git a/es77x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es77x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index 95276bc313..cd46229928 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.support.{ActionFilter, ActionFilterChain} import org.elasticsearch.action.{ActionListener, ActionRequest, ActionResponse} import org.elasticsearch.client.node.NodeClient @@ -60,7 +60,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, rorEsConfig: ReadonlyRestEsConfig) (implicit environmentConfig: EnvironmentConfig) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = environmentConfig.uniqueIdentifierGenerator @@ -200,12 +200,12 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def handleRorNotReadyYet(esContext: EsContext): Unit = { - logger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") + noRequestIdLogger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") rorNotAvailableRequestHandler.handleRorNotReadyYet(esContext) } private def handleRorFailedToStart(esContext: EsContext): Unit = { - logger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") + noRequestIdLogger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") rorNotAvailableRequestHandler.handleRorFailedToStart(esContext) } @@ -227,7 +227,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def logAndSetStartingFailureState(failure: StartingFailure): Unit = { - logger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) + noRequestIdLogger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) rorInstanceState.set(RorInstanceStartingState.NotStarted(failure)) } } diff --git a/es77x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala b/es77x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala index 7f92461f08..72c14bf252 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.xcontent.cbor.CborXContent import org.elasticsearch.common.xcontent.json.JsonXContent import org.elasticsearch.common.xcontent.smile.SmileXContent @@ -29,7 +29,7 @@ import tech.beshu.ror.accesscontrol.domain.ResponseFieldsFiltering.{AccessMode, import scala.jdk.CollectionConverters.* trait ResponseFieldsFiltering { - this: Logging => + this: RequestIdAwareLogging => private val responseFieldsRestrictions: Atomic[Option[ResponseFieldsRestrictions]] = Atomic(None: Option[ResponseFieldsRestrictions]) @@ -44,7 +44,7 @@ trait ResponseFieldsFiltering { case bytesRestResponse: BytesRestResponse => filterBytesRestResponse(bytesRestResponse, fieldsRestrictions) case otherResponse => - logger.warn("ResponseFields filtering is unavailable for this type of request") + noRequestIdLogger.warn("ResponseFields filtering is unavailable for this type of request") otherResponse } case None => diff --git a/es77x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala b/es77x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala index 0f26750588..da95de59a4 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.action.{ActionListener, ActionResponse} import org.elasticsearch.threadpool.ThreadPool @@ -37,7 +37,7 @@ sealed abstract class RorActionListener[T](val underlying: ActionListener[T]) ex final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionListener[T], correlationId: Eval[CorrelationId]) - extends RorActionListener[T](underlying) with Logging { + extends RorActionListener[T](underlying) with RequestIdAwareLogging { override def onFailure(e: Exception): Unit = { super.onFailure(adaptExceptionIfNeeded(e)) @@ -47,7 +47,7 @@ final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionLis ex match { case esException: ElasticsearchException => esException case other => - logger.error(s"[${correlationId.value.show}] Internal error.", other) + noRequestIdLogger.error(s"[${correlationId.value.show}] Internal error.", other) new ElasticsearchException(s"[${correlationId.value.show}] Internal error. See logs for details.") } } diff --git a/es77x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala b/es77x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala index 0a80ad8a51..09e707bd3e 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.http.HttpChannel import org.elasticsearch.rest.{AbstractRestChannel, RestChannel as EsRestChannel, RestRequest as EsRestRequest, RestResponse as EsRestResponse} import squants.information.{Bytes, Information} @@ -40,7 +40,7 @@ object RorRestChannel { final class RorRestChannel private(underlying: EsRestChannel, val restRequest: RorRestRequest) extends AbstractRestChannel(underlying.request(), true) with ResponseFieldsFiltering - with Logging { + with RequestIdAwareLogging { override def sendResponse(response: EsRestResponse): Unit = { ThreadRepo.removeRestChannel(this) diff --git a/es77x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala b/es77x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala index 6babc712b9..3c80750a25 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala @@ -18,16 +18,15 @@ package tech.beshu.ror.es.actions.rradmin import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.ConfigApi.ConfigResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAdminActionHandler extends Logging { +class RRAdminActionHandler extends RequestIdAwareLogging { private implicit val adminRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +51,7 @@ class RRAdminActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAdminResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAdminAction internal error", ex) + logger.error("RRAdminAction internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es77x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala b/es77x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala index c55835a1d0..ce45c6f48e 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala @@ -16,18 +16,15 @@ */ package tech.beshu.ror.es.actions.rrauthmock -import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.AuthMockApi.AuthMockResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier -import tech.beshu.ror.implicits.* +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAuthMockActionHandler extends Logging { +class RRAuthMockActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -53,7 +50,7 @@ class RRAuthMockActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAuthMockResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAuthMock internal error", ex) + logger.error("RRAuthMock internal error", ex) listener.onFailure(new Exception(ex)) } } diff --git a/es77x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala b/es77x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala index aa8bb31e67..640084c4ec 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestconfig import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.TestConfigApi.TestConfigResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestConfigActionHandler extends Logging { +class RRTestConfigActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +52,7 @@ class RRTestConfigActionHandler extends Logging { case Right(response) => listener.onResponse(new RRTestConfigResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRTestConfig internal error", ex) + logger.error(s"RRTestConfig internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es77x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala b/es77x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala index 5e42d55f7e..4d9a78443a 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.dlsfls import cats.data.StateT import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.DirectoryReader import org.elasticsearch.common.CheckedFunction import org.elasticsearch.common.util.concurrent.ThreadContext @@ -31,7 +31,7 @@ import java.io.IOException import java.util.function.{Function => JavaFunction} import scala.util.{Failure, Success, Try} -object RoleIndexSearcherWrapper extends Logging { +object RoleIndexSearcherWrapper extends RequestIdAwareLogging { val instance: JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] = new JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] { @@ -54,7 +54,7 @@ object RoleIndexSearcherWrapper extends Logging { } .map(r => (r, r)) case None => - logger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") + noRequestIdLogger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") Success((reader, reader)) } } @@ -66,13 +66,13 @@ object RoleIndexSearcherWrapper extends Logging { nel <- NonEmptyString.from(value) match { case Right(nel) => Success(nel) case Left(_) => - logger.debug("FLS: empty header value") + noRequestIdLogger.debug("FLS: empty header value") failure } fields <- transientFieldsFromHeaderValue.fromRawValue(nel) match { case result@Success(_) => result case Failure(ex) => - logger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) + noRequestIdLogger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) failure } } yield fields diff --git a/es77x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala b/es77x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala index b4debafe78..bcac775b5a 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.dlsfls import com.google.common.collect.Iterators -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.* import org.apache.lucene.index.StoredFieldVisitor.Status import org.apache.lucene.util.Bits @@ -36,21 +36,21 @@ import scala.jdk.CollectionConverters.* import scala.util.Try private class RorDocumentFieldReader(reader: LeafReader, fieldsRestrictions: FieldsRestrictions) - extends FilterLeafReader(reader) with Logging { + extends FilterLeafReader(reader) with RequestIdAwareLogging { private val policy = new FieldsPolicy(fieldsRestrictions) private val remainingFieldsInfo = { val fInfos = in.getFieldInfos val newInfos = if (fInfos.asScala.isEmpty) { - logger.warn("original fields were empty! This is weird!") + noRequestIdLogger.warn("original fields were empty! This is weird!") fInfos } else { val remainingFields = fInfos.asScala.filter(f => policy.canKeep(f.name)).toSet new FieldInfos(remainingFields.toArray) } - logger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") - logger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") - logger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") + noRequestIdLogger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") newInfos } private val jsonPolicyBasedFilterer = new JsonPolicyBasedFilterer(policy) diff --git a/es77x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala b/es77x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala index d489b8f924..ca6e1253fe 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.* import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest import org.elasticsearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest @@ -83,7 +83,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, threadPool: ThreadPool) (implicit generator: UniqueIdentifierGenerator, scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle(engines: Engines, esContext: EsContext): Task[Either[Error, Unit]] = { @@ -205,7 +205,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, case SearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case MultiSearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case _ => - logger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") + noRequestIdLogger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") regularRequestHandler.handle(new DummyCompositeIndicesEsRequestContext(request, esContext, aclContext, clusterService, threadPool)) } // rest diff --git a/es77x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala b/es77x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala index a388bb0f9f..57be14c040 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.common.io.stream.StreamOutput import org.elasticsearch.common.xcontent.{ToXContent, ToXContentObject, XContentBuilder} @@ -45,7 +45,7 @@ import scala.util.{Failure, Success, Try} class CurrentUserMetadataRequestHandler(engine: Engine, esContext: EsContext) - extends Logging { + extends RequestIdAwareLogging { def handle(request: RequestContext.Aux[CurrentUserMetadataRequestBlockContext] with EsRequest[CurrentUserMetadataRequestBlockContext]): Task[Unit] = { engine.core.accessControl @@ -69,7 +69,7 @@ class CurrentUserMetadataRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(ex.asInstanceOf[Exception]) } } @@ -86,13 +86,13 @@ class CurrentUserMetadataRequestHandler(engine: Engine, )) } - private def onPassThrough(requestContext: RequestContext): Unit = { - logger.warn(s"[${requestContext.id.toRequestId.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") + private def onPassThrough(implicit requestContext: RequestContext): Unit = { + logger.warn(s"Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") esContext.listener.onFailure(createRorNotEnabledResponse()) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } diff --git a/es77x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala b/es77x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala index 2fb01dcc41..c5c44fda92 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala @@ -20,7 +20,7 @@ import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.RegularRequestResult @@ -49,7 +49,7 @@ class RegularRequestHandler(engine: Engine, esContext: EsContext, threadPool: ThreadPool) (implicit scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle[B <: BlockContext : BlockContextUpdater](request: RequestContext.Aux[B] with EsRequest[B]): Task[Unit] = { engine.core.accessControl @@ -85,7 +85,7 @@ class RegularRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(new Exception(ex)) } } @@ -99,7 +99,7 @@ class RegularRequestHandler(engine: Engine, case ModificationResult.ShouldBeInterrupted => onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case ModificationResult.CannotModify => - logger.error(s"[${request.id.toRequestId.show}] Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") + noRequestIdLogger.error(s"Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case CustomResponse(response) => respond(request, response) @@ -247,7 +247,7 @@ class RegularRequestHandler(engine: Engine, esContext.listener.onResponse(response) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } \ No newline at end of file diff --git a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala index f6db2b2f6e..7ad5f7b26d 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.index.query.{AbstractQueryBuilder, QueryBuilder, QueryBuilders} import org.elasticsearch.search.aggregations.AggregatorFactories @@ -40,7 +40,7 @@ import tech.beshu.ror.implicits.* import java.util.UUID import scala.jdk.CollectionConverters.* -object SearchRequestOps extends Logging { +object SearchRequestOps extends RequestIdAwareLogging { implicit class QueryBuilderOps(val builder: Option[QueryBuilder]) extends AnyVal { @@ -52,7 +52,7 @@ object SearchRequestOps extends Logging { val modifiedQuery: AbstractQueryBuilder[_] = provideNewQueryWithAppliedFilter(builder, filterQuery) Some(modifiedQuery) case None => - logger.debug(s"[${requestId.show}] No filter applied to query.") + logger.debug(s"No filter applied to query.") builder } } @@ -92,7 +92,7 @@ object SearchRequestOps extends Logging { case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, requestId) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) disableCaching(requestId) case BasedOnBlockContextOnly.NotAllowedFieldsUsed(notAllowedFields) => modifyNotAllowedFieldsInRequest(notAllowedFields) @@ -138,8 +138,8 @@ object SearchRequestOps extends Logging { } } - private def disableCaching(requestId: RequestContext.Id) = { - logger.debug(s"[${requestId.show}] ACL uses context header for fields rule, will disable request cache for SearchRequest") + private def disableCaching(implicit requestId: RequestContext.Id) = { + logger.debug(s"ACL uses context header for fields rule, will disable request cache for SearchRequest") request.requestCache(false) } } diff --git a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala index 9de832edcc..74790fb1fd 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala @@ -17,7 +17,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.action.support.IndicesOptions.WildcardStates import org.elasticsearch.action.{CompositeIndicesRequest, IndicesRequest} @@ -34,7 +33,7 @@ import scala.jdk.CollectionConverters.* abstract class BaseEsRequestContext[B <: BlockContext](esContext: EsContext, clusterService: RorClusterService) - extends RequestContext with Logging { + extends RequestContext { override type BLOCK_CONTEXT = B diff --git a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala index ae8abbe1f5..0ee2967364 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala @@ -18,7 +18,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -26,8 +25,9 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import scala.util.Try +import tech.beshu.ror.utils.RequestIdAwareLogging -trait EsRequest[B <: BlockContext] extends Logging { +trait EsRequest[B <: BlockContext] extends RequestIdAwareLogging { implicit def threadPool: ThreadPool final def modifyUsing(blockContext: B): ModificationResult = { @@ -35,7 +35,7 @@ trait EsRequest[B <: BlockContext] extends Logging { Try(modifyRequest(blockContext)) .fold( ex => { - logger.error(s"[${blockContext.requestContext.id.show}] Cannot modify request with filtered data", ex) + logger.error(s"Cannot modify request with filtered data", ex)(blockContext) ModificationResult.CannotModify }, identity diff --git a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala index c091179cb6..d150709314 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala @@ -85,7 +85,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: case Some(indices) => update(actionRequest, indices, blockContext.filter, blockContext.fieldLevelSecurity) case None => - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -101,7 +101,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } \ No newline at end of file diff --git a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala index 71d462de57..48014e1bdc 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala @@ -73,7 +73,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, } yield update(actionRequest, filteredIndices, allAllowedIndices) result.getOrElse { - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -86,7 +86,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } diff --git a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala index 95d882c3b5..f607c0e347 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala @@ -50,7 +50,7 @@ abstract class BaseRepositoriesEsRequestContext[R <: ActionRequest](actionReques case Some(repositories) => update(actionRequest, repositories) case None => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") ShouldBeInterrupted } } diff --git a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala index b3b1d66238..7ef0f32014 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala @@ -42,7 +42,7 @@ abstract class BaseSingleIndexEsRequestContext[R <: ActionRequest](actionRequest filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } update(request, filteredIndices.head) } diff --git a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala index b5ab70fe7a..c1b2e7ea27 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala @@ -62,7 +62,7 @@ class BulkEsRequestContext(actionRequest: BulkRequest, case (_, _) => ShouldBeInterrupted } } else { - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because origin request contained different " + + logger.error(s"Cannot alter MultiGetRequest request, because origin request contained different " + s"number of requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } @@ -90,18 +90,18 @@ class BulkEsRequestContext(actionRequest: BulkRequest, updateRequestWithIndices(request, nel) Modified case None => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because empty list of indices was found") + logger.error(s"Cannot alter MultiGetRequest request, because empty list of indices was found") ShouldBeInterrupted } case Indices.NotFound => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because no allowed indices were found") + logger.error(s"Cannot alter MultiGetRequest request, because no allowed indices were found") ShouldBeInterrupted } } private def updateRequestWithIndices(request: DocWriteRequest[_], indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } request.index(indices.head.stringify) } diff --git a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala index 75a75fcef5..96a043b298 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala @@ -53,14 +53,14 @@ class BulkShardEsRequestContext(actionRequest: BulkShardRequest, case Success(_) => Modified case Failure(ex) => - logger.error(s"[${id.show}] Cannot modify BulkShardRequest", ex) + logger.error(s"Cannot modify BulkShardRequest", ex) CannotModify } } private def tryUpdate(request: BulkShardRequest, indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } val singleIndex = indices.head val uuid = clusterService.indexOrAliasUuids(singleIndex.name).toList.head diff --git a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala index 65a168092a..158ac485a5 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala @@ -45,14 +45,14 @@ class ClusterAllocationExplainEsRequestContext(actionRequest: ClusterAllocationE getRequestedIndexFrom(request) match { case Some(_) => if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateIndexIn(request, filteredIndices.head) Modified case None if filteredIndices.exists(_.name === ClusterIndexName.Local.wildcard) => Modified case None => - logger.error(s"[${id.show}] Cluster allocation explain request without index name is unavailable when block contains `indices` rule") + logger.error(s"Cluster allocation explain request without index name is unavailable when block contains `indices` rule") ShouldBeInterrupted } } diff --git a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala index 24e15f40e8..b73c123699 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala @@ -69,7 +69,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, updateAliases(actionRequest, aliases) UpdateResponse.sync(updateAliasesResponse(aliases.includedOnly, _)) case None => - logger.error(s"[${id.show}] At least one alias and one index has to be allowed. " + + logger.error(s"At least one alias and one index has to be allowed. " + s"Found allowed indices: [${blockContext.indices.show}]." + s"Found allowed aliases: [${blockContext.aliases.show}]") ShouldBeInterrupted @@ -117,7 +117,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, .indices().asSafeSet .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } @@ -125,7 +125,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, val aliases = rawRequestAliasesSet(request) .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered aliases: ${aliases.show}") + logger.debug(s"Discovered aliases: ${aliases.show}") aliases } diff --git a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala index abb85d42b7..f9e2c87e53 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala @@ -55,7 +55,7 @@ class IndicesAliasesEsRequestContext(actionRequest: IndicesAliasesRequest, if (originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala index 05b70606b9..37dd50452b 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala @@ -119,7 +119,7 @@ class MultiGetEsRequestContext(actionRequest: MultiGetRequest, case Nil => updateItemWithNonExistingIndex(item) case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } item.index(index.stringify) } diff --git a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala index 989956d79a..9e13edee8d 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala @@ -78,7 +78,7 @@ class MultiSearchEsRequestContext(actionRequest: MultiSearchRequest, } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala index 9191e33b66..5a61356f48 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala @@ -47,7 +47,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { request.getRequests.removeIf { request => removeOrAlter(request, filteredIndices.toCovariantSet) } if (request.getRequests.asScala.isEmpty) { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") ShouldBeInterrupted } else { Modified @@ -63,7 +63,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, true case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") } request.index(index.stringify) false diff --git a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala index c411df93c5..c7b99f6e85 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala @@ -52,7 +52,7 @@ class PutRollupJobEsRequestContext private(actionRequest: ActionRequest, if(originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala index 141d9db788..fff8ed58bb 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala @@ -49,7 +49,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (tryUpdate(actionRequest, filteredIndices)) Modified else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") ShouldBeInterrupted } } diff --git a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala index 489d0187bc..c42dfc3b78 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala @@ -58,10 +58,10 @@ class ReindexEsRequestContext(actionRequest: ReindexRequest, Modified } else { if (!isDestinationIndexOnFilteredIndicesList) { - logger.info(s"[${id.show}] Destination index of _reindex request is forbidden") + logger.info(s"Destination index of _reindex request is forbidden") } if (!isSearchRequestComposedOnlyOfAllowedIndices) { - logger.info(s"[${id.show}] At least one index from sources indices list of _reindex request is forbidden") + logger.info(s"At least one index from sources indices list of _reindex request is forbidden") } ShouldBeInterrupted } diff --git a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala index 2c1b0014e0..97b8ccd9c5 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala @@ -74,7 +74,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo request } case Left(_) => - logger.debug(s"[${id.show}] Cannot parse SQL statement - we can pass it though, because ES is going to reject it") + logger.debug(s"Cannot parse SQL statement - we can pass it though, because ES is going to reject it") request } } @@ -85,7 +85,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala index 0c67384c1e..d7e743e648 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CleanupRepositoryEsRequestContext(actionRequest: CleanupRepositoryRequest, override protected def update(request: CleanupRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala index 44b7d78dfd..d09015139b 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CreateRepositoryEsRequestContext(actionRequest: PutRepositoryRequest, override protected def update(request: PutRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala index eaf9334872..0cf32e1bea 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class DeleteRepositoryEsRequestContext(actionRequest: DeleteRepositoryRequest, override protected def update(request: DeleteRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala index cee0bffd4c..d1410eff3d 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class VerifyRepositoryEsRequestContext(actionRequest: VerifyRepositoryRequest, override protected def update(request: VerifyRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala index ead4fcf250..20501516d5 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala @@ -68,32 +68,32 @@ class CreateSnapshotEsRequestContext(actionRequest: CreateSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala index 281a0d73f6..27b13ffa11 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala @@ -59,32 +59,32 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala index 58122fb44f..782a54d7df 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala @@ -69,7 +69,7 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, case r => r } case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -81,14 +81,14 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.mkString(",")}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.mkString(",")}]") } Right(repository) } diff --git a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala index 88887db96c..156deb5b80 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala @@ -63,7 +63,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -75,7 +75,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") } Right(snapshot) } @@ -88,7 +88,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala index 44ee8397ec..e522e440f1 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala @@ -100,12 +100,12 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { val repositories = blockContext.repositories if (allRepositoriesRequested(repositories)) { Right(RepositoryName.All) @@ -115,7 +115,7 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala index 0bdf0ce63d..243d0dff91 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.{GetIndexTemplatesRequest, GetIndexTemplatesResponse} import org.elasticsearch.cluster.metadata.{AliasMetaData, IndexTemplateMetaData} import org.elasticsearch.common.collect.ImmutableOpenMap @@ -100,7 +100,7 @@ class GetTemplatesEsRequestContext(actionRequest: GetIndexTemplatesRequest, } -private[templates] object GetTemplatesEsRequestContext extends Logging { +private[templates] object GetTemplatesEsRequestContext extends RequestIdAwareLogging { def filter(templates: Iterable[IndexTemplateMetaData], usingTemplate: Set[Template] => Set[Template]) diff --git a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala index a8951de5b1..32116d8212 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala @@ -72,7 +72,7 @@ class MultiSearchTemplateEsRequestContext private(actionRequest: ActionRequest w } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala index 22a0c6791a..e08a2fbb72 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.queries import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.index.query.* import org.joor.Reflect.on import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.RequestFieldsUsage @@ -32,7 +32,7 @@ trait QueryFieldsUsage[QUERY <: QueryBuilder] { def fieldsIn(query: QUERY): RequestFieldsUsage } -object QueryFieldsUsage extends Logging { +object QueryFieldsUsage extends RequestIdAwareLogging { def apply[QUERY <: QueryBuilder](implicit ev: QueryFieldsUsage[QUERY]): QueryFieldsUsage[QUERY] = ev implicit class Ops[QUERY <: QueryBuilder : QueryFieldsUsage](val query: QUERY) { @@ -65,7 +65,7 @@ object QueryFieldsUsage extends Logging { Option(on(query).call("getFieldName").get[String]) match { case Some(fieldName: String) => UsingFields(NonEmptyList.one(UsedField(fieldName))) case _ => - logger.debug(s"Cannot extract fields for terms set query") + noRequestIdLogger.debug(s"Cannot extract fields for terms set query") CannotExtractFields } } @@ -93,7 +93,7 @@ object QueryFieldsUsage extends Logging { case builder: TermsSetQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder: WildcardQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder => - logger.debug(s"Cannot extract fields for query: ${builder.getName}") + noRequestIdLogger.debug(s"Cannot extract fields for query: ${builder.getName}") CannotExtractFields } diff --git a/es77x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala b/es77x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala index 0998bb9a5b..b4671e9e4d 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.handler.response import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.FieldsRestrictions import tech.beshu.ror.accesscontrol.domain.Header @@ -26,17 +26,17 @@ import tech.beshu.ror.accesscontrol.headerValues.transientFieldsToHeaderValue import tech.beshu.ror.accesscontrol.request.RequestContext import tech.beshu.ror.implicits.* -object FLSContextHeaderHandler extends Logging { +object FLSContextHeaderHandler extends RequestIdAwareLogging { def addContextHeader(threadPool: ThreadPool, - fieldsRestrictions: FieldsRestrictions, - requestId: RequestContext.Id): Unit = { + fieldsRestrictions: FieldsRestrictions) + (implicit requestId: RequestContext.Id): Unit = { val threadContext = threadPool.getThreadContext val header = createContextHeader(fieldsRestrictions) Option(threadContext.getHeader(header.name.value.value)) match { case None => implicit val show = headerShow - logger.debug(s"[${requestId.show}] Adding thread context header required by lucene. Header: '${header.show}'") + logger.debug(s"Adding thread context header required by lucene. Header: '${header.show}'") threadContext.putHeader(header.name.value.value, header.value.value) case Some(_) => } diff --git a/es77x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala b/es77x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala index 18490a232c..b65ba21df7 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.support.WriteRequest.RefreshPolicy import org.elasticsearch.client.node.NodeClient @@ -38,7 +38,7 @@ import scala.jdk.CollectionConverters.* class EsIndexJsonContentService(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexJsonContentService - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -63,14 +63,14 @@ class EsIndexJsonContentService(client: NodeClient, Option(response.getSourceAsMap) match { case Some(map) => val source = map.asScala.toMap.asStringMap - logger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") Right(source) case None => - logger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") + noRequestIdLogger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") Right(Map.empty[String, String]) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(ContentNotFound) } } @@ -78,7 +78,7 @@ class EsIndexJsonContentService(client: NodeClient, .onErrorRecover { case _: ResourceNotFoundException => Left(ContentNotFound) case ex => - logger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) Left(CannotReachContentSource) } } @@ -104,14 +104,14 @@ class EsIndexJsonContentService(client: NodeClient, case status if status / 100 == 2 => Right(()) case status => - logger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") Left(CannotWriteToIndex) } } .executeOn(RorSchedulers.blockingScheduler) .onErrorRecover { case ex => - logger.error(s"Cannot write to document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]", ex) Left(CannotWriteToIndex) } } diff --git a/es77x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala b/es77x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala index c9b9ef0f76..7a191e250c 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala @@ -21,7 +21,7 @@ import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task import monix.execution.CancelablePromise -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import org.elasticsearch.action.admin.cluster.state.{ClusterStateRequest, ClusterStateResponse} import org.elasticsearch.action.search.{MultiSearchResponse, SearchRequestBuilder, SearchResponse} @@ -63,7 +63,7 @@ class EsServerBasedRorClusterService(nodeName: String, nodeClient: NodeClient, threadPool: ThreadPool) extends RorClusterService - with Logging { + with RequestIdAwareLogging { import EsServerBasedRorClusterService.* @@ -154,7 +154,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractAccessibilityFrom) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify get request. Blocking document", ex) + logger.error(s"Could not verify get request. Blocking document", ex)(id) Inaccessible } } @@ -166,7 +166,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractResultsFromSearchResponse) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify documents returned by multi get response. Blocking all returned documents", ex) + logger.error(s"Could not verify documents returned by multi get response. Blocking all returned documents", ex)(id) blockAllDocsReturned(documents) } .map(results => zip(results, documents)) @@ -245,7 +245,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService): Task[List[FullRemoteDataStreamWithAliases]] = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -279,7 +279,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService) = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -362,7 +362,7 @@ class EsServerBasedRorClusterService(nodeName: String, } } case None => - logger.error("Cannot supply Snapshots Service. Please, report the issue!!!") + noRequestIdLogger.error("Cannot supply Snapshots Service. Please, report the issue!!!") Task.now(Set.empty[Snapshot]) } } diff --git a/es77x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala b/es77x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala index 028c5bd58e..d0036caaa7 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es.services -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.DocWriteRequest import org.elasticsearch.action.bulk.{BackoffPolicy, BulkProcessor, BulkRequest, BulkResponse} import org.elasticsearch.action.index.IndexRequest @@ -30,7 +30,7 @@ import tech.beshu.ror.es.IndexBasedAuditSinkService final class NodeClientBasedAuditSinkService(client: NodeClient, threadPool: ThreadPool) extends IndexBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { private val bulkProcessor = BulkProcessor @@ -62,25 +62,25 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, threadPool: Thre private class AuditSinkBulkProcessorListener extends BulkProcessor.Listener { override def beforeBulk(executionId: Long, request: BulkRequest): Unit = { - logger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") + noRequestIdLogger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") } override def afterBulk(executionId: Long, request: BulkRequest, response: BulkResponse): Unit = { if (response.hasFailures) { - logger.error("Some failures flushing the BulkProcessor: ") + noRequestIdLogger.error("Some failures flushing the BulkProcessor: ") response .getItems.to(LazyList) .filter(_.isFailed) .map(_.getFailureMessage) .groupBy(identity) .foreach { case (message, stream) => - logger.error(s"${stream.size}x: $message") + noRequestIdLogger.error(s"${stream.size}x: $message") } } } override def afterBulk(executionId: Long, request: BulkRequest, failure: Throwable): Unit = { - logger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) + noRequestIdLogger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) } } diff --git a/es77x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala b/es77x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala index 6c627ede96..c6a4e6124d 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala @@ -22,7 +22,7 @@ import org.apache.http.auth.{AuthScope, Credentials, UsernamePasswordCredentials import org.apache.http.conn.ssl.NoopHostnameVerifier import org.apache.http.impl.client.BasicCredentialsProvider import org.apache.http.impl.nio.client.HttpAsyncClientBuilder -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.* import org.elasticsearch.client.RestClient.FailureListener import tech.beshu.ror.accesscontrol.domain.AuditCluster.ClusterMode @@ -36,7 +36,7 @@ import scala.collection.parallel.CollectionConverters.* final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient]) extends IndexBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { override def submit(indexName: IndexName.Full, documentId: String, jsonRecord: String) (implicit requestId: RequestId): Unit = { @@ -70,19 +70,19 @@ final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient] override def onSuccess(response: Response): Unit = { response.getStatusLine.getStatusCode / 100 match { case 2 => // 2xx - logger.debug(s"[${requestId.show}] Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") + logger.debug(s"Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") case _ => - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") } } override def onFailure(ex: Exception): Unit = { - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId]", ex) + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId]", ex) } } } -object RestClientAuditSinkService extends Logging { +object RestClientAuditSinkService extends RequestIdAwareLogging { def create(remoteCluster: AuditCluster.RemoteAuditCluster): RestClientAuditSinkService = { remoteCluster.mode match { @@ -113,7 +113,7 @@ object RestClientAuditSinkService extends Logging { .setFailureListener( new FailureListener { override def onFailure(node: Node): Unit = { - logger.debug( + noRequestIdLogger.debug( s"[AUDIT] Node marked dead: ${node.getHost.getSchemeName}://${node.getHost.getHostName}:${node.getHost.getPort}. The client will attempt failover.", ) } diff --git a/es77x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala b/es77x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala index 1304142499..4c9a4bc5e8 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.Channel import io.netty.handler.ssl.NotSslRecordException -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.network.NetworkService import org.elasticsearch.common.settings.{ClusterSettings, Settings} import org.elasticsearch.common.util.BigArrays @@ -39,7 +39,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, clusterSettings: ClusterSettings, fipsCompliant: Boolean) extends Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher, clusterSettings) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, ssl.clientAuthenticationEnabled) @@ -47,7 +47,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, override def onException(channel: HttpChannel, cause: Exception): Unit = { if (!this.lifecycle.started) return - else if (cause.getCause.isInstanceOf[NotSslRecordException]) logger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) + else if (cause.getCause.isInstanceOf[NotSslRecordException]) noRequestIdLogger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) else super.onException(channel, cause) channel.close() } diff --git a/es77x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala b/es77x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala index 3ac42afd15..ee7a7cdd26 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.* import io.netty.handler.ssl.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.Version import org.elasticsearch.cluster.node.DiscoveryNode import org.elasticsearch.common.io.stream.NamedWriteableRegistry @@ -44,7 +44,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, ssl: InternodeSslConfiguration, fipsCompliant: Boolean) extends Netty4Transport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = SSLCertHelper.prepareClientSSLContext(ssl, fipsCompliant, ssl.certificateVerificationEnabled) private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, clientAuthenticationEnabled = false) @@ -75,7 +75,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, override def exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable): Unit = { if (cause.isInstanceOf[NotSslRecordException] || (cause.getCause != null && cause.getCause.isInstanceOf[NotSslRecordException])) { - logger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") + noRequestIdLogger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") ctx.channel.close } else { super.exceptionCaught(ctx, cause) diff --git a/es77x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala b/es77x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala index abab175acf..e17a194f47 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.utils import cats.Show import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.client.node.NodeClient import org.elasticsearch.rest.* @@ -35,7 +35,7 @@ import java.util import scala.util.Try class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandler) - extends RestHandler with Logging { + extends RestHandler with RequestIdAwareLogging { private val wrapped = doPrivileged { wrapSomeActions(underlying) @@ -101,11 +101,11 @@ class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandle private def logError(error: AuthorizationValueError): Unit = { { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorSanitizedShow - logger.warn(s"The incoming request was malformed. Cause: ${error.show}") + noRequestIdLogger.warn(s"The incoming request was malformed. Cause: ${error.show}") } if (logger.delegate.isDebugEnabled()) { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorWithDetailsShow - logger.debug(s"Malformed request detailed cause: ${error.show}") + noRequestIdLogger.debug(s"Malformed request detailed cause: ${error.show}") } } diff --git a/es77x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala b/es77x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala index 5ab1e35742..a9af8f710a 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala @@ -16,13 +16,13 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.settings.Settings import tech.beshu.ror.tools.core.patches.PatchingVerifier import tech.beshu.ror.tools.core.patches.PatchingVerifier.Error.{CannotVerifyIfPatched, EsNotPatched} import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -object EsPatchVerifier extends Logging { +object EsPatchVerifier extends RequestIdAwareLogging { def verify(settings: Settings): Unit = doPrivileged { pathHomeFrom(settings).flatMap(PatchingVerifier.verify) match { @@ -30,7 +30,7 @@ object EsPatchVerifier extends Logging { case Left(e@EsNotPatched(_)) => throw new IllegalStateException(e.message) case Left(e@CannotVerifyIfPatched(_)) => - logger.warn(e.message) + noRequestIdLogger.warn(e.message) } } diff --git a/es78x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es78x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index 741142f834..1381c453a8 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.support.{ActionFilter, ActionFilterChain} import org.elasticsearch.action.{ActionListener, ActionRequest, ActionResponse} import org.elasticsearch.client.node.NodeClient @@ -60,7 +60,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, rorEsConfig: ReadonlyRestEsConfig) (implicit environmentConfig: EnvironmentConfig) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = environmentConfig.uniqueIdentifierGenerator @@ -200,12 +200,12 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def handleRorNotReadyYet(esContext: EsContext): Unit = { - logger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") + noRequestIdLogger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") rorNotAvailableRequestHandler.handleRorNotReadyYet(esContext) } private def handleRorFailedToStart(esContext: EsContext): Unit = { - logger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") + noRequestIdLogger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") rorNotAvailableRequestHandler.handleRorFailedToStart(esContext) } @@ -227,7 +227,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def logAndSetStartingFailureState(failure: StartingFailure): Unit = { - logger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) + noRequestIdLogger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) rorInstanceState.set(RorInstanceStartingState.NotStarted(failure)) } } diff --git a/es78x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala b/es78x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala index 7f92461f08..72c14bf252 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.xcontent.cbor.CborXContent import org.elasticsearch.common.xcontent.json.JsonXContent import org.elasticsearch.common.xcontent.smile.SmileXContent @@ -29,7 +29,7 @@ import tech.beshu.ror.accesscontrol.domain.ResponseFieldsFiltering.{AccessMode, import scala.jdk.CollectionConverters.* trait ResponseFieldsFiltering { - this: Logging => + this: RequestIdAwareLogging => private val responseFieldsRestrictions: Atomic[Option[ResponseFieldsRestrictions]] = Atomic(None: Option[ResponseFieldsRestrictions]) @@ -44,7 +44,7 @@ trait ResponseFieldsFiltering { case bytesRestResponse: BytesRestResponse => filterBytesRestResponse(bytesRestResponse, fieldsRestrictions) case otherResponse => - logger.warn("ResponseFields filtering is unavailable for this type of request") + noRequestIdLogger.warn("ResponseFields filtering is unavailable for this type of request") otherResponse } case None => diff --git a/es78x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala b/es78x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala index 0f26750588..da95de59a4 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.action.{ActionListener, ActionResponse} import org.elasticsearch.threadpool.ThreadPool @@ -37,7 +37,7 @@ sealed abstract class RorActionListener[T](val underlying: ActionListener[T]) ex final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionListener[T], correlationId: Eval[CorrelationId]) - extends RorActionListener[T](underlying) with Logging { + extends RorActionListener[T](underlying) with RequestIdAwareLogging { override def onFailure(e: Exception): Unit = { super.onFailure(adaptExceptionIfNeeded(e)) @@ -47,7 +47,7 @@ final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionLis ex match { case esException: ElasticsearchException => esException case other => - logger.error(s"[${correlationId.value.show}] Internal error.", other) + noRequestIdLogger.error(s"[${correlationId.value.show}] Internal error.", other) new ElasticsearchException(s"[${correlationId.value.show}] Internal error. See logs for details.") } } diff --git a/es78x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala b/es78x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala index 0a80ad8a51..09e707bd3e 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.http.HttpChannel import org.elasticsearch.rest.{AbstractRestChannel, RestChannel as EsRestChannel, RestRequest as EsRestRequest, RestResponse as EsRestResponse} import squants.information.{Bytes, Information} @@ -40,7 +40,7 @@ object RorRestChannel { final class RorRestChannel private(underlying: EsRestChannel, val restRequest: RorRestRequest) extends AbstractRestChannel(underlying.request(), true) with ResponseFieldsFiltering - with Logging { + with RequestIdAwareLogging { override def sendResponse(response: EsRestResponse): Unit = { ThreadRepo.removeRestChannel(this) diff --git a/es78x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala b/es78x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala index 6babc712b9..3c80750a25 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala @@ -18,16 +18,15 @@ package tech.beshu.ror.es.actions.rradmin import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.ConfigApi.ConfigResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAdminActionHandler extends Logging { +class RRAdminActionHandler extends RequestIdAwareLogging { private implicit val adminRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +51,7 @@ class RRAdminActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAdminResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAdminAction internal error", ex) + logger.error("RRAdminAction internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es78x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala b/es78x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala index c55835a1d0..ce45c6f48e 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala @@ -16,18 +16,15 @@ */ package tech.beshu.ror.es.actions.rrauthmock -import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.AuthMockApi.AuthMockResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier -import tech.beshu.ror.implicits.* +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAuthMockActionHandler extends Logging { +class RRAuthMockActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -53,7 +50,7 @@ class RRAuthMockActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAuthMockResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAuthMock internal error", ex) + logger.error("RRAuthMock internal error", ex) listener.onFailure(new Exception(ex)) } } diff --git a/es78x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala b/es78x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala index aa8bb31e67..640084c4ec 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestconfig import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.TestConfigApi.TestConfigResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestConfigActionHandler extends Logging { +class RRTestConfigActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +52,7 @@ class RRTestConfigActionHandler extends Logging { case Right(response) => listener.onResponse(new RRTestConfigResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRTestConfig internal error", ex) + logger.error(s"RRTestConfig internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es78x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala b/es78x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala index 5e42d55f7e..4d9a78443a 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.dlsfls import cats.data.StateT import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.DirectoryReader import org.elasticsearch.common.CheckedFunction import org.elasticsearch.common.util.concurrent.ThreadContext @@ -31,7 +31,7 @@ import java.io.IOException import java.util.function.{Function => JavaFunction} import scala.util.{Failure, Success, Try} -object RoleIndexSearcherWrapper extends Logging { +object RoleIndexSearcherWrapper extends RequestIdAwareLogging { val instance: JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] = new JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] { @@ -54,7 +54,7 @@ object RoleIndexSearcherWrapper extends Logging { } .map(r => (r, r)) case None => - logger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") + noRequestIdLogger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") Success((reader, reader)) } } @@ -66,13 +66,13 @@ object RoleIndexSearcherWrapper extends Logging { nel <- NonEmptyString.from(value) match { case Right(nel) => Success(nel) case Left(_) => - logger.debug("FLS: empty header value") + noRequestIdLogger.debug("FLS: empty header value") failure } fields <- transientFieldsFromHeaderValue.fromRawValue(nel) match { case result@Success(_) => result case Failure(ex) => - logger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) + noRequestIdLogger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) failure } } yield fields diff --git a/es78x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala b/es78x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala index b4debafe78..bcac775b5a 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.dlsfls import com.google.common.collect.Iterators -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.* import org.apache.lucene.index.StoredFieldVisitor.Status import org.apache.lucene.util.Bits @@ -36,21 +36,21 @@ import scala.jdk.CollectionConverters.* import scala.util.Try private class RorDocumentFieldReader(reader: LeafReader, fieldsRestrictions: FieldsRestrictions) - extends FilterLeafReader(reader) with Logging { + extends FilterLeafReader(reader) with RequestIdAwareLogging { private val policy = new FieldsPolicy(fieldsRestrictions) private val remainingFieldsInfo = { val fInfos = in.getFieldInfos val newInfos = if (fInfos.asScala.isEmpty) { - logger.warn("original fields were empty! This is weird!") + noRequestIdLogger.warn("original fields were empty! This is weird!") fInfos } else { val remainingFields = fInfos.asScala.filter(f => policy.canKeep(f.name)).toSet new FieldInfos(remainingFields.toArray) } - logger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") - logger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") - logger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") + noRequestIdLogger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") newInfos } private val jsonPolicyBasedFilterer = new JsonPolicyBasedFilterer(policy) diff --git a/es78x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala b/es78x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala index 18704ba802..334aeb7eaf 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.* import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest import org.elasticsearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest @@ -84,7 +84,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, threadPool: ThreadPool) (implicit generator: UniqueIdentifierGenerator, scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle(engines: Engines, esContext: EsContext): Task[Either[Error, Unit]] = { @@ -220,7 +220,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, case SearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case MultiSearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case _ => - logger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") + noRequestIdLogger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") regularRequestHandler.handle(new DummyCompositeIndicesEsRequestContext(request, esContext, aclContext, clusterService, threadPool)) } // rest diff --git a/es78x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala b/es78x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala index a388bb0f9f..57be14c040 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.common.io.stream.StreamOutput import org.elasticsearch.common.xcontent.{ToXContent, ToXContentObject, XContentBuilder} @@ -45,7 +45,7 @@ import scala.util.{Failure, Success, Try} class CurrentUserMetadataRequestHandler(engine: Engine, esContext: EsContext) - extends Logging { + extends RequestIdAwareLogging { def handle(request: RequestContext.Aux[CurrentUserMetadataRequestBlockContext] with EsRequest[CurrentUserMetadataRequestBlockContext]): Task[Unit] = { engine.core.accessControl @@ -69,7 +69,7 @@ class CurrentUserMetadataRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(ex.asInstanceOf[Exception]) } } @@ -86,13 +86,13 @@ class CurrentUserMetadataRequestHandler(engine: Engine, )) } - private def onPassThrough(requestContext: RequestContext): Unit = { - logger.warn(s"[${requestContext.id.toRequestId.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") + private def onPassThrough(implicit requestContext: RequestContext): Unit = { + logger.warn(s"Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") esContext.listener.onFailure(createRorNotEnabledResponse()) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } diff --git a/es78x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala b/es78x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala index 2fb01dcc41..c5c44fda92 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala @@ -20,7 +20,7 @@ import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.RegularRequestResult @@ -49,7 +49,7 @@ class RegularRequestHandler(engine: Engine, esContext: EsContext, threadPool: ThreadPool) (implicit scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle[B <: BlockContext : BlockContextUpdater](request: RequestContext.Aux[B] with EsRequest[B]): Task[Unit] = { engine.core.accessControl @@ -85,7 +85,7 @@ class RegularRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(new Exception(ex)) } } @@ -99,7 +99,7 @@ class RegularRequestHandler(engine: Engine, case ModificationResult.ShouldBeInterrupted => onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case ModificationResult.CannotModify => - logger.error(s"[${request.id.toRequestId.show}] Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") + noRequestIdLogger.error(s"Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case CustomResponse(response) => respond(request, response) @@ -247,7 +247,7 @@ class RegularRequestHandler(engine: Engine, esContext.listener.onResponse(response) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } \ No newline at end of file diff --git a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala index f4f832dedc..bfc421bdd5 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.index.query.{AbstractQueryBuilder, QueryBuilder, QueryBuilders} import org.elasticsearch.search.aggregations.AggregatorFactories @@ -40,7 +40,7 @@ import tech.beshu.ror.implicits.* import java.util.UUID import scala.jdk.CollectionConverters.* -object SearchRequestOps extends Logging { +object SearchRequestOps extends RequestIdAwareLogging { implicit class QueryBuilderOps(val builder: Option[QueryBuilder]) extends AnyVal { @@ -52,7 +52,7 @@ object SearchRequestOps extends Logging { val modifiedQuery: AbstractQueryBuilder[_] = provideNewQueryWithAppliedFilter(builder, filterQuery) Some(modifiedQuery) case None => - logger.debug(s"[${requestId.show}] No filter applied to query.") + logger.debug(s"No filter applied to query.") builder } } @@ -92,7 +92,7 @@ object SearchRequestOps extends Logging { case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, requestId) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) disableCaching(requestId) case BasedOnBlockContextOnly.NotAllowedFieldsUsed(notAllowedFields) => modifyNotAllowedFieldsInRequest(notAllowedFields) @@ -138,8 +138,8 @@ object SearchRequestOps extends Logging { } } - private def disableCaching(requestId: RequestContext.Id) = { - logger.debug(s"[${requestId.show}] ACL uses context header for fields rule, will disable request cache for SearchRequest") + private def disableCaching(implicit requestId: RequestContext.Id) = { + logger.debug(s"ACL uses context header for fields rule, will disable request cache for SearchRequest") request.requestCache(false) } } diff --git a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala index 9de832edcc..74790fb1fd 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala @@ -17,7 +17,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.action.support.IndicesOptions.WildcardStates import org.elasticsearch.action.{CompositeIndicesRequest, IndicesRequest} @@ -34,7 +33,7 @@ import scala.jdk.CollectionConverters.* abstract class BaseEsRequestContext[B <: BlockContext](esContext: EsContext, clusterService: RorClusterService) - extends RequestContext with Logging { + extends RequestContext { override type BLOCK_CONTEXT = B diff --git a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala index ae8abbe1f5..0ee2967364 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala @@ -18,7 +18,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -26,8 +25,9 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import scala.util.Try +import tech.beshu.ror.utils.RequestIdAwareLogging -trait EsRequest[B <: BlockContext] extends Logging { +trait EsRequest[B <: BlockContext] extends RequestIdAwareLogging { implicit def threadPool: ThreadPool final def modifyUsing(blockContext: B): ModificationResult = { @@ -35,7 +35,7 @@ trait EsRequest[B <: BlockContext] extends Logging { Try(modifyRequest(blockContext)) .fold( ex => { - logger.error(s"[${blockContext.requestContext.id.show}] Cannot modify request with filtered data", ex) + logger.error(s"Cannot modify request with filtered data", ex)(blockContext) ModificationResult.CannotModify }, identity diff --git a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala index c091179cb6..d150709314 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala @@ -85,7 +85,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: case Some(indices) => update(actionRequest, indices, blockContext.filter, blockContext.fieldLevelSecurity) case None => - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -101,7 +101,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } \ No newline at end of file diff --git a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala index 71d462de57..48014e1bdc 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala @@ -73,7 +73,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, } yield update(actionRequest, filteredIndices, allAllowedIndices) result.getOrElse { - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -86,7 +86,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } diff --git a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala index 95d882c3b5..f607c0e347 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala @@ -50,7 +50,7 @@ abstract class BaseRepositoriesEsRequestContext[R <: ActionRequest](actionReques case Some(repositories) => update(actionRequest, repositories) case None => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") ShouldBeInterrupted } } diff --git a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala index b3b1d66238..7ef0f32014 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala @@ -42,7 +42,7 @@ abstract class BaseSingleIndexEsRequestContext[R <: ActionRequest](actionRequest filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } update(request, filteredIndices.head) } diff --git a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala index b5ab70fe7a..c1b2e7ea27 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala @@ -62,7 +62,7 @@ class BulkEsRequestContext(actionRequest: BulkRequest, case (_, _) => ShouldBeInterrupted } } else { - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because origin request contained different " + + logger.error(s"Cannot alter MultiGetRequest request, because origin request contained different " + s"number of requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } @@ -90,18 +90,18 @@ class BulkEsRequestContext(actionRequest: BulkRequest, updateRequestWithIndices(request, nel) Modified case None => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because empty list of indices was found") + logger.error(s"Cannot alter MultiGetRequest request, because empty list of indices was found") ShouldBeInterrupted } case Indices.NotFound => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because no allowed indices were found") + logger.error(s"Cannot alter MultiGetRequest request, because no allowed indices were found") ShouldBeInterrupted } } private def updateRequestWithIndices(request: DocWriteRequest[_], indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } request.index(indices.head.stringify) } diff --git a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala index 75a75fcef5..96a043b298 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala @@ -53,14 +53,14 @@ class BulkShardEsRequestContext(actionRequest: BulkShardRequest, case Success(_) => Modified case Failure(ex) => - logger.error(s"[${id.show}] Cannot modify BulkShardRequest", ex) + logger.error(s"Cannot modify BulkShardRequest", ex) CannotModify } } private def tryUpdate(request: BulkShardRequest, indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } val singleIndex = indices.head val uuid = clusterService.indexOrAliasUuids(singleIndex.name).toList.head diff --git a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala index 65a168092a..158ac485a5 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala @@ -45,14 +45,14 @@ class ClusterAllocationExplainEsRequestContext(actionRequest: ClusterAllocationE getRequestedIndexFrom(request) match { case Some(_) => if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateIndexIn(request, filteredIndices.head) Modified case None if filteredIndices.exists(_.name === ClusterIndexName.Local.wildcard) => Modified case None => - logger.error(s"[${id.show}] Cluster allocation explain request without index name is unavailable when block contains `indices` rule") + logger.error(s"Cluster allocation explain request without index name is unavailable when block contains `indices` rule") ShouldBeInterrupted } } diff --git a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala index 3582caec0a..3a7e407d21 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala @@ -69,7 +69,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, updateAliases(actionRequest, aliases) UpdateResponse.sync(updateAliasesResponse(aliases.includedOnly, _)) case None => - logger.error(s"[${id.show}] At least one alias and one index has to be allowed. " + + logger.error(s"At least one alias and one index has to be allowed. " + s"Found allowed indices: [${blockContext.indices.show}]." + s"Found allowed aliases: [${blockContext.aliases.show}]") ShouldBeInterrupted @@ -117,7 +117,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, .indices().asSafeSet .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } @@ -125,7 +125,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, val aliases = rawRequestAliasesSet(request) .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered aliases: ${aliases.show}") + logger.debug(s"Discovered aliases: ${aliases.show}") aliases } diff --git a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala index abb85d42b7..f9e2c87e53 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala @@ -55,7 +55,7 @@ class IndicesAliasesEsRequestContext(actionRequest: IndicesAliasesRequest, if (originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala index 05b70606b9..37dd50452b 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala @@ -119,7 +119,7 @@ class MultiGetEsRequestContext(actionRequest: MultiGetRequest, case Nil => updateItemWithNonExistingIndex(item) case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } item.index(index.stringify) } diff --git a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala index 989956d79a..9e13edee8d 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala @@ -78,7 +78,7 @@ class MultiSearchEsRequestContext(actionRequest: MultiSearchRequest, } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala index 9191e33b66..5a61356f48 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala @@ -47,7 +47,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { request.getRequests.removeIf { request => removeOrAlter(request, filteredIndices.toCovariantSet) } if (request.getRequests.asScala.isEmpty) { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") ShouldBeInterrupted } else { Modified @@ -63,7 +63,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, true case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") } request.index(index.stringify) false diff --git a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala index c411df93c5..c7b99f6e85 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala @@ -52,7 +52,7 @@ class PutRollupJobEsRequestContext private(actionRequest: ActionRequest, if(originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala index 141d9db788..fff8ed58bb 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala @@ -49,7 +49,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (tryUpdate(actionRequest, filteredIndices)) Modified else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") ShouldBeInterrupted } } diff --git a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala index 489d0187bc..c42dfc3b78 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala @@ -58,10 +58,10 @@ class ReindexEsRequestContext(actionRequest: ReindexRequest, Modified } else { if (!isDestinationIndexOnFilteredIndicesList) { - logger.info(s"[${id.show}] Destination index of _reindex request is forbidden") + logger.info(s"Destination index of _reindex request is forbidden") } if (!isSearchRequestComposedOnlyOfAllowedIndices) { - logger.info(s"[${id.show}] At least one index from sources indices list of _reindex request is forbidden") + logger.info(s"At least one index from sources indices list of _reindex request is forbidden") } ShouldBeInterrupted } diff --git a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala index 2c1b0014e0..97b8ccd9c5 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala @@ -74,7 +74,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo request } case Left(_) => - logger.debug(s"[${id.show}] Cannot parse SQL statement - we can pass it though, because ES is going to reject it") + logger.debug(s"Cannot parse SQL statement - we can pass it though, because ES is going to reject it") request } } @@ -85,7 +85,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala index 0c67384c1e..d7e743e648 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CleanupRepositoryEsRequestContext(actionRequest: CleanupRepositoryRequest, override protected def update(request: CleanupRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala index 44b7d78dfd..d09015139b 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CreateRepositoryEsRequestContext(actionRequest: PutRepositoryRequest, override protected def update(request: PutRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala index eaf9334872..0cf32e1bea 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class DeleteRepositoryEsRequestContext(actionRequest: DeleteRepositoryRequest, override protected def update(request: DeleteRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala index cee0bffd4c..d1410eff3d 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class VerifyRepositoryEsRequestContext(actionRequest: VerifyRepositoryRequest, override protected def update(request: VerifyRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala index ead4fcf250..20501516d5 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala @@ -68,32 +68,32 @@ class CreateSnapshotEsRequestContext(actionRequest: CreateSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala index a56aba660e..621d744767 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala @@ -60,7 +60,7 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -71,14 +71,14 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, .toRight(()) } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala index 58122fb44f..782a54d7df 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala @@ -69,7 +69,7 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, case r => r } case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -81,14 +81,14 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.mkString(",")}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.mkString(",")}]") } Right(repository) } diff --git a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala index 88887db96c..156deb5b80 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala @@ -63,7 +63,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -75,7 +75,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") } Right(snapshot) } @@ -88,7 +88,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala index 44ee8397ec..e522e440f1 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala @@ -100,12 +100,12 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { val repositories = blockContext.repositories if (allRepositoriesRequested(repositories)) { Right(RepositoryName.All) @@ -115,7 +115,7 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala index 22b2dbf41a..5ea81fc45d 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.GetComposableIndexTemplateAction import org.elasticsearch.cluster.metadata import org.elasticsearch.cluster.metadata.ComposableIndexTemplate @@ -103,7 +103,7 @@ class GetComposableIndexTemplateEsRequestContext(actionRequest: GetComposableInd } -private[templates] object GetComposableIndexTemplateEsRequestContext extends Logging { +private[templates] object GetComposableIndexTemplateEsRequestContext extends RequestIdAwareLogging { def filter(templates: Map[String, ComposableIndexTemplate], usingTemplate: Set[Template] => Set[Template]) diff --git a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala index c170a8c87d..d49f293358 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.{GetIndexTemplatesRequest, GetIndexTemplatesResponse} import org.elasticsearch.cluster.metadata.{AliasMetadata, IndexTemplateMetadata} import org.elasticsearch.common.collect.ImmutableOpenMap @@ -100,7 +100,7 @@ class GetTemplatesEsRequestContext(actionRequest: GetIndexTemplatesRequest, } -private[templates] object GetTemplatesEsRequestContext extends Logging { +private[templates] object GetTemplatesEsRequestContext extends RequestIdAwareLogging { def filter(templates: Iterable[IndexTemplateMetadata], usingTemplate: Set[Template] => Set[Template]) diff --git a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala index a8951de5b1..32116d8212 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala @@ -72,7 +72,7 @@ class MultiSearchTemplateEsRequestContext private(actionRequest: ActionRequest w } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala index e6f6d8916e..434787a686 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala @@ -55,7 +55,7 @@ class SimulateIndexTemplateRequestEsRequestContext(actionRequest: SimulateIndexT filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateRequest(request, filteredIndices.head, allAllowedIndices) } diff --git a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala index 22a0c6791a..e08a2fbb72 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.queries import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.index.query.* import org.joor.Reflect.on import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.RequestFieldsUsage @@ -32,7 +32,7 @@ trait QueryFieldsUsage[QUERY <: QueryBuilder] { def fieldsIn(query: QUERY): RequestFieldsUsage } -object QueryFieldsUsage extends Logging { +object QueryFieldsUsage extends RequestIdAwareLogging { def apply[QUERY <: QueryBuilder](implicit ev: QueryFieldsUsage[QUERY]): QueryFieldsUsage[QUERY] = ev implicit class Ops[QUERY <: QueryBuilder : QueryFieldsUsage](val query: QUERY) { @@ -65,7 +65,7 @@ object QueryFieldsUsage extends Logging { Option(on(query).call("getFieldName").get[String]) match { case Some(fieldName: String) => UsingFields(NonEmptyList.one(UsedField(fieldName))) case _ => - logger.debug(s"Cannot extract fields for terms set query") + noRequestIdLogger.debug(s"Cannot extract fields for terms set query") CannotExtractFields } } @@ -93,7 +93,7 @@ object QueryFieldsUsage extends Logging { case builder: TermsSetQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder: WildcardQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder => - logger.debug(s"Cannot extract fields for query: ${builder.getName}") + noRequestIdLogger.debug(s"Cannot extract fields for query: ${builder.getName}") CannotExtractFields } diff --git a/es78x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala b/es78x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala index 0998bb9a5b..b4671e9e4d 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.handler.response import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.FieldsRestrictions import tech.beshu.ror.accesscontrol.domain.Header @@ -26,17 +26,17 @@ import tech.beshu.ror.accesscontrol.headerValues.transientFieldsToHeaderValue import tech.beshu.ror.accesscontrol.request.RequestContext import tech.beshu.ror.implicits.* -object FLSContextHeaderHandler extends Logging { +object FLSContextHeaderHandler extends RequestIdAwareLogging { def addContextHeader(threadPool: ThreadPool, - fieldsRestrictions: FieldsRestrictions, - requestId: RequestContext.Id): Unit = { + fieldsRestrictions: FieldsRestrictions) + (implicit requestId: RequestContext.Id): Unit = { val threadContext = threadPool.getThreadContext val header = createContextHeader(fieldsRestrictions) Option(threadContext.getHeader(header.name.value.value)) match { case None => implicit val show = headerShow - logger.debug(s"[${requestId.show}] Adding thread context header required by lucene. Header: '${header.show}'") + logger.debug(s"Adding thread context header required by lucene. Header: '${header.show}'") threadContext.putHeader(header.name.value.value, header.value.value) case Some(_) => } diff --git a/es78x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala b/es78x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala index 18490a232c..b65ba21df7 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.support.WriteRequest.RefreshPolicy import org.elasticsearch.client.node.NodeClient @@ -38,7 +38,7 @@ import scala.jdk.CollectionConverters.* class EsIndexJsonContentService(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexJsonContentService - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -63,14 +63,14 @@ class EsIndexJsonContentService(client: NodeClient, Option(response.getSourceAsMap) match { case Some(map) => val source = map.asScala.toMap.asStringMap - logger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") Right(source) case None => - logger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") + noRequestIdLogger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") Right(Map.empty[String, String]) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(ContentNotFound) } } @@ -78,7 +78,7 @@ class EsIndexJsonContentService(client: NodeClient, .onErrorRecover { case _: ResourceNotFoundException => Left(ContentNotFound) case ex => - logger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) Left(CannotReachContentSource) } } @@ -104,14 +104,14 @@ class EsIndexJsonContentService(client: NodeClient, case status if status / 100 == 2 => Right(()) case status => - logger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") Left(CannotWriteToIndex) } } .executeOn(RorSchedulers.blockingScheduler) .onErrorRecover { case ex => - logger.error(s"Cannot write to document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]", ex) Left(CannotWriteToIndex) } } diff --git a/es78x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala b/es78x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala index 23fda54750..b7d9c0c22e 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala @@ -21,7 +21,7 @@ import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task import monix.execution.CancelablePromise -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import org.elasticsearch.action.admin.cluster.state.{ClusterStateRequest, ClusterStateResponse} import org.elasticsearch.action.search.{MultiSearchResponse, SearchRequestBuilder, SearchResponse} @@ -62,7 +62,7 @@ class EsServerBasedRorClusterService(nodeName: String, nodeClient: NodeClient, threadPool: ThreadPool) extends RorClusterService - with Logging { + with RequestIdAwareLogging { import EsServerBasedRorClusterService.* @@ -153,7 +153,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractAccessibilityFrom) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify get request. Blocking document", ex) + logger.error(s"Could not verify get request. Blocking document", ex)(id) Inaccessible } } @@ -165,7 +165,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractResultsFromSearchResponse) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify documents returned by multi get response. Blocking all returned documents", ex) + logger.error(s"Could not verify documents returned by multi get response. Blocking all returned documents", ex)(id) blockAllDocsReturned(documents) } .map(results => zip(results, documents)) @@ -245,7 +245,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService): Task[List[FullRemoteDataStreamWithAliases]] = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -279,7 +279,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService) = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -361,7 +361,7 @@ class EsServerBasedRorClusterService(nodeName: String, } } case None => - logger.error("Cannot supply Snapshots Service. Please, report the issue!!!") + noRequestIdLogger.error("Cannot supply Snapshots Service. Please, report the issue!!!") Task.now(Set.empty[Snapshot]) } } diff --git a/es78x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala b/es78x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala index 028c5bd58e..d0036caaa7 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es.services -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.DocWriteRequest import org.elasticsearch.action.bulk.{BackoffPolicy, BulkProcessor, BulkRequest, BulkResponse} import org.elasticsearch.action.index.IndexRequest @@ -30,7 +30,7 @@ import tech.beshu.ror.es.IndexBasedAuditSinkService final class NodeClientBasedAuditSinkService(client: NodeClient, threadPool: ThreadPool) extends IndexBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { private val bulkProcessor = BulkProcessor @@ -62,25 +62,25 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, threadPool: Thre private class AuditSinkBulkProcessorListener extends BulkProcessor.Listener { override def beforeBulk(executionId: Long, request: BulkRequest): Unit = { - logger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") + noRequestIdLogger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") } override def afterBulk(executionId: Long, request: BulkRequest, response: BulkResponse): Unit = { if (response.hasFailures) { - logger.error("Some failures flushing the BulkProcessor: ") + noRequestIdLogger.error("Some failures flushing the BulkProcessor: ") response .getItems.to(LazyList) .filter(_.isFailed) .map(_.getFailureMessage) .groupBy(identity) .foreach { case (message, stream) => - logger.error(s"${stream.size}x: $message") + noRequestIdLogger.error(s"${stream.size}x: $message") } } } override def afterBulk(executionId: Long, request: BulkRequest, failure: Throwable): Unit = { - logger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) + noRequestIdLogger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) } } diff --git a/es78x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala b/es78x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala index 6c627ede96..c6a4e6124d 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala @@ -22,7 +22,7 @@ import org.apache.http.auth.{AuthScope, Credentials, UsernamePasswordCredentials import org.apache.http.conn.ssl.NoopHostnameVerifier import org.apache.http.impl.client.BasicCredentialsProvider import org.apache.http.impl.nio.client.HttpAsyncClientBuilder -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.* import org.elasticsearch.client.RestClient.FailureListener import tech.beshu.ror.accesscontrol.domain.AuditCluster.ClusterMode @@ -36,7 +36,7 @@ import scala.collection.parallel.CollectionConverters.* final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient]) extends IndexBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { override def submit(indexName: IndexName.Full, documentId: String, jsonRecord: String) (implicit requestId: RequestId): Unit = { @@ -70,19 +70,19 @@ final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient] override def onSuccess(response: Response): Unit = { response.getStatusLine.getStatusCode / 100 match { case 2 => // 2xx - logger.debug(s"[${requestId.show}] Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") + logger.debug(s"Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") case _ => - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") } } override def onFailure(ex: Exception): Unit = { - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId]", ex) + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId]", ex) } } } -object RestClientAuditSinkService extends Logging { +object RestClientAuditSinkService extends RequestIdAwareLogging { def create(remoteCluster: AuditCluster.RemoteAuditCluster): RestClientAuditSinkService = { remoteCluster.mode match { @@ -113,7 +113,7 @@ object RestClientAuditSinkService extends Logging { .setFailureListener( new FailureListener { override def onFailure(node: Node): Unit = { - logger.debug( + noRequestIdLogger.debug( s"[AUDIT] Node marked dead: ${node.getHost.getSchemeName}://${node.getHost.getHostName}:${node.getHost.getPort}. The client will attempt failover.", ) } diff --git a/es78x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala b/es78x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala index 1304142499..4c9a4bc5e8 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.Channel import io.netty.handler.ssl.NotSslRecordException -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.network.NetworkService import org.elasticsearch.common.settings.{ClusterSettings, Settings} import org.elasticsearch.common.util.BigArrays @@ -39,7 +39,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, clusterSettings: ClusterSettings, fipsCompliant: Boolean) extends Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher, clusterSettings) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, ssl.clientAuthenticationEnabled) @@ -47,7 +47,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, override def onException(channel: HttpChannel, cause: Exception): Unit = { if (!this.lifecycle.started) return - else if (cause.getCause.isInstanceOf[NotSslRecordException]) logger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) + else if (cause.getCause.isInstanceOf[NotSslRecordException]) noRequestIdLogger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) else super.onException(channel, cause) channel.close() } diff --git a/es78x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala b/es78x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala index 3ac42afd15..ee7a7cdd26 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.* import io.netty.handler.ssl.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.Version import org.elasticsearch.cluster.node.DiscoveryNode import org.elasticsearch.common.io.stream.NamedWriteableRegistry @@ -44,7 +44,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, ssl: InternodeSslConfiguration, fipsCompliant: Boolean) extends Netty4Transport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = SSLCertHelper.prepareClientSSLContext(ssl, fipsCompliant, ssl.certificateVerificationEnabled) private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, clientAuthenticationEnabled = false) @@ -75,7 +75,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, override def exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable): Unit = { if (cause.isInstanceOf[NotSslRecordException] || (cause.getCause != null && cause.getCause.isInstanceOf[NotSslRecordException])) { - logger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") + noRequestIdLogger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") ctx.channel.close } else { super.exceptionCaught(ctx, cause) diff --git a/es78x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala b/es78x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala index abab175acf..e17a194f47 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.utils import cats.Show import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.client.node.NodeClient import org.elasticsearch.rest.* @@ -35,7 +35,7 @@ import java.util import scala.util.Try class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandler) - extends RestHandler with Logging { + extends RestHandler with RequestIdAwareLogging { private val wrapped = doPrivileged { wrapSomeActions(underlying) @@ -101,11 +101,11 @@ class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandle private def logError(error: AuthorizationValueError): Unit = { { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorSanitizedShow - logger.warn(s"The incoming request was malformed. Cause: ${error.show}") + noRequestIdLogger.warn(s"The incoming request was malformed. Cause: ${error.show}") } if (logger.delegate.isDebugEnabled()) { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorWithDetailsShow - logger.debug(s"Malformed request detailed cause: ${error.show}") + noRequestIdLogger.debug(s"Malformed request detailed cause: ${error.show}") } } diff --git a/es78x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala b/es78x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala index 5ab1e35742..a9af8f710a 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala @@ -16,13 +16,13 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.settings.Settings import tech.beshu.ror.tools.core.patches.PatchingVerifier import tech.beshu.ror.tools.core.patches.PatchingVerifier.Error.{CannotVerifyIfPatched, EsNotPatched} import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -object EsPatchVerifier extends Logging { +object EsPatchVerifier extends RequestIdAwareLogging { def verify(settings: Settings): Unit = doPrivileged { pathHomeFrom(settings).flatMap(PatchingVerifier.verify) match { @@ -30,7 +30,7 @@ object EsPatchVerifier extends Logging { case Left(e@EsNotPatched(_)) => throw new IllegalStateException(e.message) case Left(e@CannotVerifyIfPatched(_)) => - logger.warn(e.message) + noRequestIdLogger.warn(e.message) } } diff --git a/es79x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es79x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index dfc3613b7e..06a2f90f96 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.support.{ActionFilter, ActionFilterChain} import org.elasticsearch.action.{ActionListener, ActionRequest, ActionResponse} import org.elasticsearch.client.node.NodeClient @@ -62,7 +62,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, rorEsConfig: ReadonlyRestEsConfig) (implicit environmentConfig: EnvironmentConfig) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = environmentConfig.uniqueIdentifierGenerator @@ -212,12 +212,12 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def handleRorNotReadyYet(esContext: EsContext): Unit = { - logger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") + noRequestIdLogger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") rorNotAvailableRequestHandler.handleRorNotReadyYet(esContext) } private def handleRorFailedToStart(esContext: EsContext): Unit = { - logger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") + noRequestIdLogger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") rorNotAvailableRequestHandler.handleRorFailedToStart(esContext) } @@ -239,7 +239,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def logAndSetStartingFailureState(failure: StartingFailure): Unit = { - logger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) + noRequestIdLogger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) rorInstanceState.set(RorInstanceStartingState.NotStarted(failure)) } } diff --git a/es79x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala b/es79x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala index 7f92461f08..72c14bf252 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.xcontent.cbor.CborXContent import org.elasticsearch.common.xcontent.json.JsonXContent import org.elasticsearch.common.xcontent.smile.SmileXContent @@ -29,7 +29,7 @@ import tech.beshu.ror.accesscontrol.domain.ResponseFieldsFiltering.{AccessMode, import scala.jdk.CollectionConverters.* trait ResponseFieldsFiltering { - this: Logging => + this: RequestIdAwareLogging => private val responseFieldsRestrictions: Atomic[Option[ResponseFieldsRestrictions]] = Atomic(None: Option[ResponseFieldsRestrictions]) @@ -44,7 +44,7 @@ trait ResponseFieldsFiltering { case bytesRestResponse: BytesRestResponse => filterBytesRestResponse(bytesRestResponse, fieldsRestrictions) case otherResponse => - logger.warn("ResponseFields filtering is unavailable for this type of request") + noRequestIdLogger.warn("ResponseFields filtering is unavailable for this type of request") otherResponse } case None => diff --git a/es79x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala b/es79x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala index 0f26750588..da95de59a4 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.action.{ActionListener, ActionResponse} import org.elasticsearch.threadpool.ThreadPool @@ -37,7 +37,7 @@ sealed abstract class RorActionListener[T](val underlying: ActionListener[T]) ex final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionListener[T], correlationId: Eval[CorrelationId]) - extends RorActionListener[T](underlying) with Logging { + extends RorActionListener[T](underlying) with RequestIdAwareLogging { override def onFailure(e: Exception): Unit = { super.onFailure(adaptExceptionIfNeeded(e)) @@ -47,7 +47,7 @@ final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionLis ex match { case esException: ElasticsearchException => esException case other => - logger.error(s"[${correlationId.value.show}] Internal error.", other) + noRequestIdLogger.error(s"[${correlationId.value.show}] Internal error.", other) new ElasticsearchException(s"[${correlationId.value.show}] Internal error. See logs for details.") } } diff --git a/es79x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala b/es79x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala index 0a80ad8a51..09e707bd3e 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.http.HttpChannel import org.elasticsearch.rest.{AbstractRestChannel, RestChannel as EsRestChannel, RestRequest as EsRestRequest, RestResponse as EsRestResponse} import squants.information.{Bytes, Information} @@ -40,7 +40,7 @@ object RorRestChannel { final class RorRestChannel private(underlying: EsRestChannel, val restRequest: RorRestRequest) extends AbstractRestChannel(underlying.request(), true) with ResponseFieldsFiltering - with Logging { + with RequestIdAwareLogging { override def sendResponse(response: EsRestResponse): Unit = { ThreadRepo.removeRestChannel(this) diff --git a/es79x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala b/es79x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala index 6babc712b9..3c80750a25 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala @@ -18,16 +18,15 @@ package tech.beshu.ror.es.actions.rradmin import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.ConfigApi.ConfigResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAdminActionHandler extends Logging { +class RRAdminActionHandler extends RequestIdAwareLogging { private implicit val adminRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +51,7 @@ class RRAdminActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAdminResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAdminAction internal error", ex) + logger.error("RRAdminAction internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es79x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala b/es79x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala index c55835a1d0..ce45c6f48e 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala @@ -16,18 +16,15 @@ */ package tech.beshu.ror.es.actions.rrauthmock -import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.AuthMockApi.AuthMockResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier -import tech.beshu.ror.implicits.* +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAuthMockActionHandler extends Logging { +class RRAuthMockActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -53,7 +50,7 @@ class RRAuthMockActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAuthMockResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAuthMock internal error", ex) + logger.error("RRAuthMock internal error", ex) listener.onFailure(new Exception(ex)) } } diff --git a/es79x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala b/es79x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala index aa8bb31e67..640084c4ec 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestconfig import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.TestConfigApi.TestConfigResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestConfigActionHandler extends Logging { +class RRTestConfigActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +52,7 @@ class RRTestConfigActionHandler extends Logging { case Right(response) => listener.onResponse(new RRTestConfigResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRTestConfig internal error", ex) + logger.error(s"RRTestConfig internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es79x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala b/es79x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala index 5e42d55f7e..4d9a78443a 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.dlsfls import cats.data.StateT import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.DirectoryReader import org.elasticsearch.common.CheckedFunction import org.elasticsearch.common.util.concurrent.ThreadContext @@ -31,7 +31,7 @@ import java.io.IOException import java.util.function.{Function => JavaFunction} import scala.util.{Failure, Success, Try} -object RoleIndexSearcherWrapper extends Logging { +object RoleIndexSearcherWrapper extends RequestIdAwareLogging { val instance: JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] = new JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] { @@ -54,7 +54,7 @@ object RoleIndexSearcherWrapper extends Logging { } .map(r => (r, r)) case None => - logger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") + noRequestIdLogger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") Success((reader, reader)) } } @@ -66,13 +66,13 @@ object RoleIndexSearcherWrapper extends Logging { nel <- NonEmptyString.from(value) match { case Right(nel) => Success(nel) case Left(_) => - logger.debug("FLS: empty header value") + noRequestIdLogger.debug("FLS: empty header value") failure } fields <- transientFieldsFromHeaderValue.fromRawValue(nel) match { case result@Success(_) => result case Failure(ex) => - logger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) + noRequestIdLogger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) failure } } yield fields diff --git a/es79x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala b/es79x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala index b4debafe78..bcac775b5a 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.dlsfls import com.google.common.collect.Iterators -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.* import org.apache.lucene.index.StoredFieldVisitor.Status import org.apache.lucene.util.Bits @@ -36,21 +36,21 @@ import scala.jdk.CollectionConverters.* import scala.util.Try private class RorDocumentFieldReader(reader: LeafReader, fieldsRestrictions: FieldsRestrictions) - extends FilterLeafReader(reader) with Logging { + extends FilterLeafReader(reader) with RequestIdAwareLogging { private val policy = new FieldsPolicy(fieldsRestrictions) private val remainingFieldsInfo = { val fInfos = in.getFieldInfos val newInfos = if (fInfos.asScala.isEmpty) { - logger.warn("original fields were empty! This is weird!") + noRequestIdLogger.warn("original fields were empty! This is weird!") fInfos } else { val remainingFields = fInfos.asScala.filter(f => policy.canKeep(f.name)).toSet new FieldInfos(remainingFields.toArray) } - logger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") - logger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") - logger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") + noRequestIdLogger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") newInfos } private val jsonPolicyBasedFilterer = new JsonPolicyBasedFilterer(policy) diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala index ceca9c8623..8054fc4a44 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.* import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest import org.elasticsearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest @@ -87,7 +87,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, threadPool: ThreadPool) (implicit generator: UniqueIdentifierGenerator, scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle(engines: Engines, esContext: EsContext): Task[Either[Error, Unit]] = { @@ -227,7 +227,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, case SearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case MultiSearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case _ => - logger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") + noRequestIdLogger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") regularRequestHandler.handle(new DummyCompositeIndicesEsRequestContext(request, esContext, aclContext, clusterService, threadPool)) } // rest diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala index a388bb0f9f..57be14c040 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.common.io.stream.StreamOutput import org.elasticsearch.common.xcontent.{ToXContent, ToXContentObject, XContentBuilder} @@ -45,7 +45,7 @@ import scala.util.{Failure, Success, Try} class CurrentUserMetadataRequestHandler(engine: Engine, esContext: EsContext) - extends Logging { + extends RequestIdAwareLogging { def handle(request: RequestContext.Aux[CurrentUserMetadataRequestBlockContext] with EsRequest[CurrentUserMetadataRequestBlockContext]): Task[Unit] = { engine.core.accessControl @@ -69,7 +69,7 @@ class CurrentUserMetadataRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(ex.asInstanceOf[Exception]) } } @@ -86,13 +86,13 @@ class CurrentUserMetadataRequestHandler(engine: Engine, )) } - private def onPassThrough(requestContext: RequestContext): Unit = { - logger.warn(s"[${requestContext.id.toRequestId.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") + private def onPassThrough(implicit requestContext: RequestContext): Unit = { + logger.warn(s"Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") esContext.listener.onFailure(createRorNotEnabledResponse()) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala index 2fb01dcc41..c5c44fda92 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala @@ -20,7 +20,7 @@ import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.RegularRequestResult @@ -49,7 +49,7 @@ class RegularRequestHandler(engine: Engine, esContext: EsContext, threadPool: ThreadPool) (implicit scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle[B <: BlockContext : BlockContextUpdater](request: RequestContext.Aux[B] with EsRequest[B]): Task[Unit] = { engine.core.accessControl @@ -85,7 +85,7 @@ class RegularRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(new Exception(ex)) } } @@ -99,7 +99,7 @@ class RegularRequestHandler(engine: Engine, case ModificationResult.ShouldBeInterrupted => onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case ModificationResult.CannotModify => - logger.error(s"[${request.id.toRequestId.show}] Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") + noRequestIdLogger.error(s"Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case CustomResponse(response) => respond(request, response) @@ -247,7 +247,7 @@ class RegularRequestHandler(engine: Engine, esContext.listener.onResponse(response) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } \ No newline at end of file diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala index f4f832dedc..bfc421bdd5 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.index.query.{AbstractQueryBuilder, QueryBuilder, QueryBuilders} import org.elasticsearch.search.aggregations.AggregatorFactories @@ -40,7 +40,7 @@ import tech.beshu.ror.implicits.* import java.util.UUID import scala.jdk.CollectionConverters.* -object SearchRequestOps extends Logging { +object SearchRequestOps extends RequestIdAwareLogging { implicit class QueryBuilderOps(val builder: Option[QueryBuilder]) extends AnyVal { @@ -52,7 +52,7 @@ object SearchRequestOps extends Logging { val modifiedQuery: AbstractQueryBuilder[_] = provideNewQueryWithAppliedFilter(builder, filterQuery) Some(modifiedQuery) case None => - logger.debug(s"[${requestId.show}] No filter applied to query.") + logger.debug(s"No filter applied to query.") builder } } @@ -92,7 +92,7 @@ object SearchRequestOps extends Logging { case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, requestId) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) disableCaching(requestId) case BasedOnBlockContextOnly.NotAllowedFieldsUsed(notAllowedFields) => modifyNotAllowedFieldsInRequest(notAllowedFields) @@ -138,8 +138,8 @@ object SearchRequestOps extends Logging { } } - private def disableCaching(requestId: RequestContext.Id) = { - logger.debug(s"[${requestId.show}] ACL uses context header for fields rule, will disable request cache for SearchRequest") + private def disableCaching(implicit requestId: RequestContext.Id) = { + logger.debug(s"ACL uses context header for fields rule, will disable request cache for SearchRequest") request.requestCache(false) } } diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala index 9de832edcc..74790fb1fd 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala @@ -17,7 +17,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.action.support.IndicesOptions.WildcardStates import org.elasticsearch.action.{CompositeIndicesRequest, IndicesRequest} @@ -34,7 +33,7 @@ import scala.jdk.CollectionConverters.* abstract class BaseEsRequestContext[B <: BlockContext](esContext: EsContext, clusterService: RorClusterService) - extends RequestContext with Logging { + extends RequestContext { override type BLOCK_CONTEXT = B diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala index ae8abbe1f5..0ee2967364 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala @@ -18,7 +18,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -26,8 +25,9 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import scala.util.Try +import tech.beshu.ror.utils.RequestIdAwareLogging -trait EsRequest[B <: BlockContext] extends Logging { +trait EsRequest[B <: BlockContext] extends RequestIdAwareLogging { implicit def threadPool: ThreadPool final def modifyUsing(blockContext: B): ModificationResult = { @@ -35,7 +35,7 @@ trait EsRequest[B <: BlockContext] extends Logging { Try(modifyRequest(blockContext)) .fold( ex => { - logger.error(s"[${blockContext.requestContext.id.show}] Cannot modify request with filtered data", ex) + logger.error(s"Cannot modify request with filtered data", ex)(blockContext) ModificationResult.CannotModify }, identity diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala index c6a9dcbefd..f773b3efb1 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala @@ -51,7 +51,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest private def discoverDataStreams() = { val dataStreams = dataStreamsFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered data streams: ${dataStreams.show}") + logger.debug(s"Discovered data streams: ${dataStreams.show}") dataStreams } @@ -59,7 +59,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest val backingIndices = backingIndicesFrom(actionRequest) backingIndices match { case BackingIndices.IndicesInvolved(filteredIndices, _) => - logger.debug(s"[${id.show}] Discovered indices: ${filteredIndices.show}") + logger.debug(s"Discovered indices: ${filteredIndices.show}") case BackingIndices.IndicesNotInvolved => } backingIndices diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala index c091179cb6..d150709314 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala @@ -85,7 +85,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: case Some(indices) => update(actionRequest, indices, blockContext.filter, blockContext.fieldLevelSecurity) case None => - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -101,7 +101,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } \ No newline at end of file diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala index 71d462de57..48014e1bdc 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala @@ -73,7 +73,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, } yield update(actionRequest, filteredIndices, allAllowedIndices) result.getOrElse { - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -86,7 +86,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala index 95d882c3b5..f607c0e347 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala @@ -50,7 +50,7 @@ abstract class BaseRepositoriesEsRequestContext[R <: ActionRequest](actionReques case Some(repositories) => update(actionRequest, repositories) case None => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") ShouldBeInterrupted } } diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala index b3b1d66238..7ef0f32014 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala @@ -42,7 +42,7 @@ abstract class BaseSingleIndexEsRequestContext[R <: ActionRequest](actionRequest filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } update(request, filteredIndices.head) } diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala index b5ab70fe7a..c1b2e7ea27 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala @@ -62,7 +62,7 @@ class BulkEsRequestContext(actionRequest: BulkRequest, case (_, _) => ShouldBeInterrupted } } else { - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because origin request contained different " + + logger.error(s"Cannot alter MultiGetRequest request, because origin request contained different " + s"number of requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } @@ -90,18 +90,18 @@ class BulkEsRequestContext(actionRequest: BulkRequest, updateRequestWithIndices(request, nel) Modified case None => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because empty list of indices was found") + logger.error(s"Cannot alter MultiGetRequest request, because empty list of indices was found") ShouldBeInterrupted } case Indices.NotFound => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because no allowed indices were found") + logger.error(s"Cannot alter MultiGetRequest request, because no allowed indices were found") ShouldBeInterrupted } } private def updateRequestWithIndices(request: DocWriteRequest[_], indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } request.index(indices.head.stringify) } diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala index 75a75fcef5..96a043b298 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala @@ -53,14 +53,14 @@ class BulkShardEsRequestContext(actionRequest: BulkShardRequest, case Success(_) => Modified case Failure(ex) => - logger.error(s"[${id.show}] Cannot modify BulkShardRequest", ex) + logger.error(s"Cannot modify BulkShardRequest", ex) CannotModify } } private def tryUpdate(request: BulkShardRequest, indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } val singleIndex = indices.head val uuid = clusterService.indexOrAliasUuids(singleIndex.name).toList.head diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala index 65a168092a..158ac485a5 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala @@ -45,14 +45,14 @@ class ClusterAllocationExplainEsRequestContext(actionRequest: ClusterAllocationE getRequestedIndexFrom(request) match { case Some(_) => if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateIndexIn(request, filteredIndices.head) Modified case None if filteredIndices.exists(_.name === ClusterIndexName.Local.wildcard) => Modified case None => - logger.error(s"[${id.show}] Cluster allocation explain request without index name is unavailable when block contains `indices` rule") + logger.error(s"Cluster allocation explain request without index name is unavailable when block contains `indices` rule") ShouldBeInterrupted } } diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala index 3582caec0a..3a7e407d21 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala @@ -69,7 +69,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, updateAliases(actionRequest, aliases) UpdateResponse.sync(updateAliasesResponse(aliases.includedOnly, _)) case None => - logger.error(s"[${id.show}] At least one alias and one index has to be allowed. " + + logger.error(s"At least one alias and one index has to be allowed. " + s"Found allowed indices: [${blockContext.indices.show}]." + s"Found allowed aliases: [${blockContext.aliases.show}]") ShouldBeInterrupted @@ -117,7 +117,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, .indices().asSafeSet .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } @@ -125,7 +125,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, val aliases = rawRequestAliasesSet(request) .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered aliases: ${aliases.show}") + logger.debug(s"Discovered aliases: ${aliases.show}") aliases } diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala index abb85d42b7..f9e2c87e53 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala @@ -55,7 +55,7 @@ class IndicesAliasesEsRequestContext(actionRequest: IndicesAliasesRequest, if (originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala index 05b70606b9..37dd50452b 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala @@ -119,7 +119,7 @@ class MultiGetEsRequestContext(actionRequest: MultiGetRequest, case Nil => updateItemWithNonExistingIndex(item) case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } item.index(index.stringify) } diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala index 989956d79a..9e13edee8d 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala @@ -78,7 +78,7 @@ class MultiSearchEsRequestContext(actionRequest: MultiSearchRequest, } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala index 9191e33b66..5a61356f48 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala @@ -47,7 +47,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { request.getRequests.removeIf { request => removeOrAlter(request, filteredIndices.toCovariantSet) } if (request.getRequests.asScala.isEmpty) { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") ShouldBeInterrupted } else { Modified @@ -63,7 +63,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, true case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") } request.index(index.stringify) false diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala index c411df93c5..c7b99f6e85 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala @@ -52,7 +52,7 @@ class PutRollupJobEsRequestContext private(actionRequest: ActionRequest, if(originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala index 141d9db788..fff8ed58bb 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala @@ -49,7 +49,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (tryUpdate(actionRequest, filteredIndices)) Modified else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") ShouldBeInterrupted } } diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala index 489d0187bc..c42dfc3b78 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala @@ -58,10 +58,10 @@ class ReindexEsRequestContext(actionRequest: ReindexRequest, Modified } else { if (!isDestinationIndexOnFilteredIndicesList) { - logger.info(s"[${id.show}] Destination index of _reindex request is forbidden") + logger.info(s"Destination index of _reindex request is forbidden") } if (!isSearchRequestComposedOnlyOfAllowedIndices) { - logger.info(s"[${id.show}] At least one index from sources indices list of _reindex request is forbidden") + logger.info(s"At least one index from sources indices list of _reindex request is forbidden") } ShouldBeInterrupted } diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala index 2c1b0014e0..97b8ccd9c5 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala @@ -74,7 +74,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo request } case Left(_) => - logger.debug(s"[${id.show}] Cannot parse SQL statement - we can pass it though, because ES is going to reject it") + logger.debug(s"Cannot parse SQL statement - we can pass it though, because ES is going to reject it") request } } @@ -85,7 +85,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DataStreamsStatsEsRequestContext.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DataStreamsStatsEsRequestContext.scala index 3cbf6360ed..3e2648b17b 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DataStreamsStatsEsRequestContext.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DataStreamsStatsEsRequestContext.scala @@ -44,7 +44,7 @@ private[datastreams] class DataStreamsStatsEsRequestContext private(actionReques if (modifyActionRequest(blockContext)) { ModificationResult.Modified } else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") ModificationResult.ShouldBeInterrupted } } diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DeleteDataStreamEsRequestContext.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DeleteDataStreamEsRequestContext.scala index b4491990f0..cf135bdf6a 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DeleteDataStreamEsRequestContext.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DeleteDataStreamEsRequestContext.scala @@ -44,7 +44,7 @@ private[datastreams] class DeleteDataStreamEsRequestContext private(actionReques if (modifyActionRequest(blockContext)) { ModificationResult.Modified } else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") ModificationResult.ShouldBeInterrupted } } diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/GetDataStreamEsRequestContext.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/GetDataStreamEsRequestContext.scala index 12435d0f4f..ce0b1fbae6 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/GetDataStreamEsRequestContext.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/GetDataStreamEsRequestContext.scala @@ -64,7 +64,7 @@ private[datastreams] class GetDataStreamEsRequestContext(actionRequest: ActionRe r } } else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") ModificationResult.ShouldBeInterrupted } } diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala index 0c67384c1e..d7e743e648 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CleanupRepositoryEsRequestContext(actionRequest: CleanupRepositoryRequest, override protected def update(request: CleanupRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala index 44b7d78dfd..d09015139b 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CreateRepositoryEsRequestContext(actionRequest: PutRepositoryRequest, override protected def update(request: PutRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala index eaf9334872..0cf32e1bea 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class DeleteRepositoryEsRequestContext(actionRequest: DeleteRepositoryRequest, override protected def update(request: DeleteRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala index cee0bffd4c..d1410eff3d 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class VerifyRepositoryEsRequestContext(actionRequest: VerifyRepositoryRequest, override protected def update(request: VerifyRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala index ead4fcf250..20501516d5 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala @@ -68,32 +68,32 @@ class CreateSnapshotEsRequestContext(actionRequest: CreateSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala index a56aba660e..621d744767 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala @@ -60,7 +60,7 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -71,14 +71,14 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, .toRight(()) } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala index 58122fb44f..782a54d7df 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala @@ -69,7 +69,7 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, case r => r } case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -81,14 +81,14 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.mkString(",")}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.mkString(",")}]") } Right(repository) } diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala index 88887db96c..156deb5b80 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala @@ -63,7 +63,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -75,7 +75,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") } Right(snapshot) } @@ -88,7 +88,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala index 44ee8397ec..e522e440f1 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala @@ -100,12 +100,12 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { val repositories = blockContext.repositories if (allRepositoriesRequested(repositories)) { Right(RepositoryName.All) @@ -115,7 +115,7 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala index 67ea5e22af..f870e054ad 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.GetComposableIndexTemplateAction import org.elasticsearch.cluster.metadata import org.elasticsearch.cluster.metadata.ComposableIndexTemplate @@ -103,7 +103,7 @@ class GetComposableIndexTemplateEsRequestContext(actionRequest: GetComposableInd } -private[templates] object GetComposableIndexTemplateEsRequestContext extends Logging { +private[templates] object GetComposableIndexTemplateEsRequestContext extends RequestIdAwareLogging { def filter(templates: Map[String, ComposableIndexTemplate], usingTemplate: Set[Template] => Set[Template]) diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala index c170a8c87d..d49f293358 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.{GetIndexTemplatesRequest, GetIndexTemplatesResponse} import org.elasticsearch.cluster.metadata.{AliasMetadata, IndexTemplateMetadata} import org.elasticsearch.common.collect.ImmutableOpenMap @@ -100,7 +100,7 @@ class GetTemplatesEsRequestContext(actionRequest: GetIndexTemplatesRequest, } -private[templates] object GetTemplatesEsRequestContext extends Logging { +private[templates] object GetTemplatesEsRequestContext extends RequestIdAwareLogging { def filter(templates: Iterable[IndexTemplateMetadata], usingTemplate: Set[Template] => Set[Template]) diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala index a8951de5b1..32116d8212 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala @@ -72,7 +72,7 @@ class MultiSearchTemplateEsRequestContext private(actionRequest: ActionRequest w } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala index e6f6d8916e..434787a686 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala @@ -55,7 +55,7 @@ class SimulateIndexTemplateRequestEsRequestContext(actionRequest: SimulateIndexT filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateRequest(request, filteredIndices.head, allAllowedIndices) } diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala index fbc4cf6776..46ed6e7a95 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala @@ -109,7 +109,7 @@ class SimulateExistingTemplateRequestEsRequestContext(existingTemplateName: Temp case Some(_) => updateResponse(namePatterns.toList, blockContext.allAllowedIndices.toList) case None => - logger.info(s"[${id.show}] User has no access to template ${existingTemplateName.show}") + logger.info(s"User has no access to template ${existingTemplateName.show}") ModificationResult.ShouldBeInterrupted } case other => diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala index 22a0c6791a..e08a2fbb72 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.queries import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.index.query.* import org.joor.Reflect.on import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.RequestFieldsUsage @@ -32,7 +32,7 @@ trait QueryFieldsUsage[QUERY <: QueryBuilder] { def fieldsIn(query: QUERY): RequestFieldsUsage } -object QueryFieldsUsage extends Logging { +object QueryFieldsUsage extends RequestIdAwareLogging { def apply[QUERY <: QueryBuilder](implicit ev: QueryFieldsUsage[QUERY]): QueryFieldsUsage[QUERY] = ev implicit class Ops[QUERY <: QueryBuilder : QueryFieldsUsage](val query: QUERY) { @@ -65,7 +65,7 @@ object QueryFieldsUsage extends Logging { Option(on(query).call("getFieldName").get[String]) match { case Some(fieldName: String) => UsingFields(NonEmptyList.one(UsedField(fieldName))) case _ => - logger.debug(s"Cannot extract fields for terms set query") + noRequestIdLogger.debug(s"Cannot extract fields for terms set query") CannotExtractFields } } @@ -93,7 +93,7 @@ object QueryFieldsUsage extends Logging { case builder: TermsSetQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder: WildcardQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder => - logger.debug(s"Cannot extract fields for query: ${builder.getName}") + noRequestIdLogger.debug(s"Cannot extract fields for query: ${builder.getName}") CannotExtractFields } diff --git a/es79x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala b/es79x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala index 0998bb9a5b..b4671e9e4d 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.handler.response import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.FieldsRestrictions import tech.beshu.ror.accesscontrol.domain.Header @@ -26,17 +26,17 @@ import tech.beshu.ror.accesscontrol.headerValues.transientFieldsToHeaderValue import tech.beshu.ror.accesscontrol.request.RequestContext import tech.beshu.ror.implicits.* -object FLSContextHeaderHandler extends Logging { +object FLSContextHeaderHandler extends RequestIdAwareLogging { def addContextHeader(threadPool: ThreadPool, - fieldsRestrictions: FieldsRestrictions, - requestId: RequestContext.Id): Unit = { + fieldsRestrictions: FieldsRestrictions) + (implicit requestId: RequestContext.Id): Unit = { val threadContext = threadPool.getThreadContext val header = createContextHeader(fieldsRestrictions) Option(threadContext.getHeader(header.name.value.value)) match { case None => implicit val show = headerShow - logger.debug(s"[${requestId.show}] Adding thread context header required by lucene. Header: '${header.show}'") + logger.debug(s"Adding thread context header required by lucene. Header: '${header.show}'") threadContext.putHeader(header.name.value.value, header.value.value) case Some(_) => } diff --git a/es79x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala b/es79x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala index 448e7420d8..ea57140be0 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.admin.indices.template.get.{GetComponentTemplateAction, GetComposableIndexTemplateAction} import org.elasticsearch.action.admin.indices.template.put.{PutComponentTemplateAction, PutComposableIndexTemplateAction} @@ -45,7 +45,7 @@ import scala.jdk.CollectionConverters.* final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJsonParserFactory)(using Clock) extends DataStreamService - with Logging { + with RequestIdAwareLogging { override def checkDataStreamExists(dataStreamName: DataStreamName.Full): Task[Boolean] = execute { val enhancedActionType = client.findActionUnsafe[ActionResponse]("indices:admin/data_stream/get") @@ -218,11 +218,11 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ response <- Task.measure( task = Task.delay(nodeClient.execute(action, request).actionGet()), logTimeMeasurement = duration => Task.delay { - logger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") + noRequestIdLogger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") } ) _ <- Task.delay { - logger.debug(s"Action ${action.name()} response: ${response.toString}") + noRequestIdLogger.debug(s"Action ${action.name()} response: ${response.toString}") } } yield response } @@ -230,7 +230,7 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ def executeAck[REQUEST <: ActionRequest, RESPONSE <: AcknowledgedResponse](action: ActionType[RESPONSE], request: REQUEST): Task[RESPONSE] = { executeT(action, request) - .tapEval(response => Task.delay(logger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) + .tapEval(response => Task.delay(noRequestIdLogger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) } private def supportedActions: Map[ActionType[ActionResponse], TransportAction[ActionRequest, ActionResponse]] = { diff --git a/es79x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala b/es79x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala index 18490a232c..b65ba21df7 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.support.WriteRequest.RefreshPolicy import org.elasticsearch.client.node.NodeClient @@ -38,7 +38,7 @@ import scala.jdk.CollectionConverters.* class EsIndexJsonContentService(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexJsonContentService - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -63,14 +63,14 @@ class EsIndexJsonContentService(client: NodeClient, Option(response.getSourceAsMap) match { case Some(map) => val source = map.asScala.toMap.asStringMap - logger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") Right(source) case None => - logger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") + noRequestIdLogger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") Right(Map.empty[String, String]) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(ContentNotFound) } } @@ -78,7 +78,7 @@ class EsIndexJsonContentService(client: NodeClient, .onErrorRecover { case _: ResourceNotFoundException => Left(ContentNotFound) case ex => - logger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) Left(CannotReachContentSource) } } @@ -104,14 +104,14 @@ class EsIndexJsonContentService(client: NodeClient, case status if status / 100 == 2 => Right(()) case status => - logger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") Left(CannotWriteToIndex) } } .executeOn(RorSchedulers.blockingScheduler) .onErrorRecover { case ex => - logger.error(s"Cannot write to document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]", ex) Left(CannotWriteToIndex) } } diff --git a/es79x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala b/es79x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala index e09268f8a1..1a6a17e808 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala @@ -21,7 +21,7 @@ import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task import monix.execution.CancelablePromise -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction.ResolvedIndex @@ -63,7 +63,7 @@ class EsServerBasedRorClusterService(nodeName: String, nodeClient: NodeClient, threadPool: ThreadPool) extends RorClusterService - with Logging { + with RequestIdAwareLogging { import EsServerBasedRorClusterService.* @@ -154,7 +154,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractAccessibilityFrom) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify get request. Blocking document", ex) + logger.error(s"Could not verify get request. Blocking document", ex)(id) Inaccessible } } @@ -166,7 +166,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractResultsFromSearchResponse) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify documents returned by multi get response. Blocking all returned documents", ex) + logger.error(s"Could not verify documents returned by multi get response. Blocking all returned documents", ex)(id) blockAllDocsReturned(documents) } .map(results => zip(results, documents)) @@ -246,7 +246,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService): Task[List[FullRemoteDataStreamWithAliases]] = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -296,7 +296,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService) = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -366,7 +366,7 @@ class EsServerBasedRorClusterService(nodeName: String, } } case None => - logger.error("Cannot supply Snapshots Service. Please, report the issue!!!") + noRequestIdLogger.error("Cannot supply Snapshots Service. Please, report the issue!!!") Task.now(Set.empty[Snapshot]) } } diff --git a/es79x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala b/es79x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala index 84a97818fe..b5ce8bc2a6 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.services import cats.data.NonEmptyList -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.DocWriteRequest import org.elasticsearch.action.bulk.{BackoffPolicy, BulkProcessor, BulkRequest, BulkResponse} import org.elasticsearch.action.index.IndexRequest @@ -39,7 +39,7 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, (using Clock) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { private val bulkProcessor = BulkProcessor @@ -76,25 +76,25 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, private class AuditSinkBulkProcessorListener extends BulkProcessor.Listener { override def beforeBulk(executionId: Long, request: BulkRequest): Unit = { - logger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") + noRequestIdLogger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") } override def afterBulk(executionId: Long, request: BulkRequest, response: BulkResponse): Unit = { if (response.hasFailures) { - logger.error("Some failures flushing the BulkProcessor: ") + noRequestIdLogger.error("Some failures flushing the BulkProcessor: ") response .getItems.to(LazyList) .filter(_.isFailed) .map(_.getFailureMessage) .groupBy(identity) .foreach { case (message, stream) => - logger.error(s"${stream.size}x: $message") + noRequestIdLogger.error(s"${stream.size}x: $message") } } } override def afterBulk(executionId: Long, request: BulkRequest, failure: Throwable): Unit = { - logger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) + noRequestIdLogger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) } } diff --git a/es79x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala b/es79x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala index a8def0ec7a..b3c5593c36 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala @@ -22,7 +22,7 @@ import org.apache.http.auth.{AuthScope, Credentials, UsernamePasswordCredentials import org.apache.http.conn.ssl.NoopHostnameVerifier import org.apache.http.impl.client.BasicCredentialsProvider import org.apache.http.impl.nio.client.HttpAsyncClientBuilder -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.* import org.elasticsearch.client.RestClient.FailureListener import tech.beshu.ror.accesscontrol.audit.sink.AuditDataStreamCreator @@ -38,7 +38,7 @@ import scala.collection.parallel.CollectionConverters.* final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient]) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { override def submit(indexName: IndexName.Full, documentId: String, jsonRecord: String) (implicit requestId: RequestId): Unit = { @@ -77,21 +77,21 @@ final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient] override def onSuccess(response: Response): Unit = { response.getStatusLine.getStatusCode / 100 match { case 2 => // 2xx - logger.debug(s"[${requestId.show}] Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") + logger.debug(s"Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") case _ => - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") } } override def onFailure(ex: Exception): Unit = { - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId]", ex) + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId]", ex) } } override val dataStreamCreator: AuditDataStreamCreator = new AuditDataStreamCreator(clients.map(new RestClientDataStreamService(_))) } -object RestClientAuditSinkService extends Logging { +object RestClientAuditSinkService extends RequestIdAwareLogging { def create(remoteCluster: AuditCluster.RemoteAuditCluster): RestClientAuditSinkService = { remoteCluster.mode match { @@ -122,7 +122,7 @@ object RestClientAuditSinkService extends Logging { .setFailureListener( new FailureListener { override def onFailure(node: Node): Unit = { - logger.debug( + noRequestIdLogger.debug( s"[AUDIT] Node marked dead: ${node.getHost.getSchemeName}://${node.getHost.getHostName}:${node.getHost.getPort}. The client will attempt failover.", ) } diff --git a/es79x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala b/es79x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala index a9f97756f7..a10c1a2aeb 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.Channel import io.netty.handler.ssl.NotSslRecordException -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.network.NetworkService import org.elasticsearch.common.settings.{ClusterSettings, Settings} import org.elasticsearch.common.util.BigArrays @@ -41,7 +41,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, sharedGroupFactory: SharedGroupFactory, fipsCompliant: Boolean) extends Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, ssl.clientAuthenticationEnabled) @@ -49,7 +49,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, override def onException(channel: HttpChannel, cause: Exception): Unit = { if (!this.lifecycle.started) return - else if (cause.getCause.isInstanceOf[NotSslRecordException]) logger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) + else if (cause.getCause.isInstanceOf[NotSslRecordException]) noRequestIdLogger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) else super.onException(channel, cause) channel.close() } diff --git a/es79x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala b/es79x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala index cd73e6310c..d8c0dbbce8 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.* import io.netty.handler.ssl.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.Version import org.elasticsearch.cluster.node.DiscoveryNode import org.elasticsearch.common.io.stream.NamedWriteableRegistry @@ -46,7 +46,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, sharedGroupFactory: SharedGroupFactory, fipsCompliant: Boolean) extends Netty4Transport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = SSLCertHelper.prepareClientSSLContext(ssl, fipsCompliant, ssl.certificateVerificationEnabled) private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, clientAuthenticationEnabled = false) @@ -77,7 +77,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, override def exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable): Unit = { if (cause.isInstanceOf[NotSslRecordException] || (cause.getCause != null && cause.getCause.isInstanceOf[NotSslRecordException])) { - logger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") + noRequestIdLogger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") ctx.channel.close } else { super.exceptionCaught(ctx, cause) diff --git a/es79x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala b/es79x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala index abab175acf..e17a194f47 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.utils import cats.Show import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.client.node.NodeClient import org.elasticsearch.rest.* @@ -35,7 +35,7 @@ import java.util import scala.util.Try class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandler) - extends RestHandler with Logging { + extends RestHandler with RequestIdAwareLogging { private val wrapped = doPrivileged { wrapSomeActions(underlying) @@ -101,11 +101,11 @@ class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandle private def logError(error: AuthorizationValueError): Unit = { { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorSanitizedShow - logger.warn(s"The incoming request was malformed. Cause: ${error.show}") + noRequestIdLogger.warn(s"The incoming request was malformed. Cause: ${error.show}") } if (logger.delegate.isDebugEnabled()) { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorWithDetailsShow - logger.debug(s"Malformed request detailed cause: ${error.show}") + noRequestIdLogger.debug(s"Malformed request detailed cause: ${error.show}") } } diff --git a/es79x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala b/es79x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala index 5ab1e35742..a9af8f710a 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala @@ -16,13 +16,13 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.settings.Settings import tech.beshu.ror.tools.core.patches.PatchingVerifier import tech.beshu.ror.tools.core.patches.PatchingVerifier.Error.{CannotVerifyIfPatched, EsNotPatched} import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -object EsPatchVerifier extends Logging { +object EsPatchVerifier extends RequestIdAwareLogging { def verify(settings: Settings): Unit = doPrivileged { pathHomeFrom(settings).flatMap(PatchingVerifier.verify) match { @@ -30,7 +30,7 @@ object EsPatchVerifier extends Logging { case Left(e@EsNotPatched(_)) => throw new IllegalStateException(e.message) case Left(e@CannotVerifyIfPatched(_)) => - logger.warn(e.message) + noRequestIdLogger.warn(e.message) } } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es80x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index c1eb97ae22..ee9a908bc6 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.support.{ActionFilter, ActionFilterChain} import org.elasticsearch.action.{ActionListener, ActionRequest, ActionResponse} import org.elasticsearch.client.node.NodeClient @@ -62,7 +62,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, rorEsConfig: ReadonlyRestEsConfig) (implicit environmentConfig: EnvironmentConfig) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = environmentConfig.uniqueIdentifierGenerator @@ -212,12 +212,12 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def handleRorNotReadyYet(esContext: EsContext): Unit = { - logger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") + noRequestIdLogger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") rorNotAvailableRequestHandler.handleRorNotReadyYet(esContext) } private def handleRorFailedToStart(esContext: EsContext): Unit = { - logger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") + noRequestIdLogger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") rorNotAvailableRequestHandler.handleRorFailedToStart(esContext) } @@ -239,7 +239,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def logAndSetStartingFailureState(failure: StartingFailure): Unit = { - logger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) + noRequestIdLogger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) rorInstanceState.set(RorInstanceStartingState.NotStarted(failure)) } } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala b/es80x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala index d7b798577d..eba9e6a1f8 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.xcontent.LoggingDeprecationHandler import org.elasticsearch.rest.{BytesRestResponse, RestResponse} import org.elasticsearch.xcontent.{NamedXContentRegistry, XContentBuilder, XContentType} @@ -30,7 +30,7 @@ import tech.beshu.ror.accesscontrol.domain.ResponseFieldsFiltering.{AccessMode, import scala.jdk.CollectionConverters.* trait ResponseFieldsFiltering { - this: Logging => + this: RequestIdAwareLogging => private val responseFieldsRestrictions: Atomic[Option[ResponseFieldsRestrictions]] = Atomic(None: Option[ResponseFieldsRestrictions]) @@ -45,7 +45,7 @@ trait ResponseFieldsFiltering { case bytesRestResponse: BytesRestResponse => filterBytesRestResponse(bytesRestResponse, fieldsRestrictions) case otherResponse => - logger.warn("ResponseFields filtering is unavailable for this type of request") + noRequestIdLogger.warn("ResponseFields filtering is unavailable for this type of request") otherResponse } case None => diff --git a/es80x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala b/es80x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala index 0f26750588..da95de59a4 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.action.{ActionListener, ActionResponse} import org.elasticsearch.threadpool.ThreadPool @@ -37,7 +37,7 @@ sealed abstract class RorActionListener[T](val underlying: ActionListener[T]) ex final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionListener[T], correlationId: Eval[CorrelationId]) - extends RorActionListener[T](underlying) with Logging { + extends RorActionListener[T](underlying) with RequestIdAwareLogging { override def onFailure(e: Exception): Unit = { super.onFailure(adaptExceptionIfNeeded(e)) @@ -47,7 +47,7 @@ final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionLis ex match { case esException: ElasticsearchException => esException case other => - logger.error(s"[${correlationId.value.show}] Internal error.", other) + noRequestIdLogger.error(s"[${correlationId.value.show}] Internal error.", other) new ElasticsearchException(s"[${correlationId.value.show}] Internal error. See logs for details.") } } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala b/es80x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala index 75048ebe7d..14e5e31c1b 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.http.HttpChannel import org.elasticsearch.rest.{AbstractRestChannel, RestChannel as EsRestChannel, RestRequest as EsRestRequest, RestResponse as EsRestResponse} import squants.information.{Bytes, Information} @@ -40,7 +40,7 @@ object RorRestChannel { final class RorRestChannel private(underlying: EsRestChannel, val restRequest: RorRestRequest) extends AbstractRestChannel(underlying.request(), true) with ResponseFieldsFiltering - with Logging { + with RequestIdAwareLogging { override def sendResponse(response: EsRestResponse): Unit = { ThreadRepo.removeRestChannel(this) diff --git a/es80x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala b/es80x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala index 6babc712b9..3c80750a25 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala @@ -18,16 +18,15 @@ package tech.beshu.ror.es.actions.rradmin import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.ConfigApi.ConfigResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAdminActionHandler extends Logging { +class RRAdminActionHandler extends RequestIdAwareLogging { private implicit val adminRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +51,7 @@ class RRAdminActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAdminResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAdminAction internal error", ex) + logger.error("RRAdminAction internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala b/es80x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala index c55835a1d0..ce45c6f48e 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala @@ -16,18 +16,15 @@ */ package tech.beshu.ror.es.actions.rrauthmock -import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.AuthMockApi.AuthMockResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier -import tech.beshu.ror.implicits.* +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAuthMockActionHandler extends Logging { +class RRAuthMockActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -53,7 +50,7 @@ class RRAuthMockActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAuthMockResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAuthMock internal error", ex) + logger.error("RRAuthMock internal error", ex) listener.onFailure(new Exception(ex)) } } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala b/es80x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala index aa8bb31e67..640084c4ec 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestconfig import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.TestConfigApi.TestConfigResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestConfigActionHandler extends Logging { +class RRTestConfigActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +52,7 @@ class RRTestConfigActionHandler extends Logging { case Right(response) => listener.onResponse(new RRTestConfigResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRTestConfig internal error", ex) + logger.error(s"RRTestConfig internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala b/es80x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala index 494e9150b4..98cc0c945d 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.dlsfls import cats.data.StateT import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.DirectoryReader import org.elasticsearch.common.util.concurrent.ThreadContext import org.elasticsearch.core.CheckedFunction @@ -31,7 +31,7 @@ import java.io.IOException import java.util.function.{Function => JavaFunction} import scala.util.{Failure, Success, Try} -object RoleIndexSearcherWrapper extends Logging { +object RoleIndexSearcherWrapper extends RequestIdAwareLogging { val instance: JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] = new JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] { @@ -54,7 +54,7 @@ object RoleIndexSearcherWrapper extends Logging { } .map(r => (r, r)) case None => - logger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") + noRequestIdLogger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") Success((reader, reader)) } } @@ -66,13 +66,13 @@ object RoleIndexSearcherWrapper extends Logging { nel <- NonEmptyString.from(value) match { case Right(nel) => Success(nel) case Left(_) => - logger.debug("FLS: empty header value") + noRequestIdLogger.debug("FLS: empty header value") failure } fields <- transientFieldsFromHeaderValue.fromRawValue(nel) match { case result@Success(_) => result case Failure(ex) => - logger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) + noRequestIdLogger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) failure } } yield fields diff --git a/es80x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala b/es80x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala index ac897184bb..0f785d38fd 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.dlsfls import com.google.common.collect.Iterators -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.codecs.StoredFieldsReader import org.apache.lucene.index.* import org.apache.lucene.index.StoredFieldVisitor.Status @@ -39,21 +39,21 @@ import scala.jdk.CollectionConverters.* import scala.util.Try private class RorDocumentFieldReader(reader: LeafReader, fieldsRestrictions: FieldsRestrictions) - extends SequentialStoredFieldsLeafReader(reader) with Logging { + extends SequentialStoredFieldsLeafReader(reader) with RequestIdAwareLogging { private val policy = new FieldsPolicy(fieldsRestrictions) private val remainingFieldsInfo = { val fInfos = in.getFieldInfos val newInfos = if (fInfos.asScala.isEmpty) { - logger.warn("original fields were empty! This is weird!") + noRequestIdLogger.warn("original fields were empty! This is weird!") fInfos } else { val remainingFields = fInfos.asScala.filter(f => policy.canKeep(f.name)).toSet new FieldInfos(remainingFields.toArray) } - logger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") - logger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") - logger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") + noRequestIdLogger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") newInfos } private val jsonPolicyBasedFilterer = new JsonPolicyBasedFilterer(policy) diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala index 79537a140c..de9eb68e1c 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.* import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest import org.elasticsearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest @@ -88,7 +88,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, threadPool: ThreadPool) (implicit generator: UniqueIdentifierGenerator, scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle(engines: Engines, esContext: EsContext): Task[Either[Error, Unit]] = { @@ -231,7 +231,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, case SearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case MultiSearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case _ => - logger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") + noRequestIdLogger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") regularRequestHandler.handle(new DummyCompositeIndicesEsRequestContext(request, esContext, aclContext, clusterService, threadPool)) } // rest diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala index cab02aff37..100edd72ac 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.common.io.stream.StreamOutput import org.elasticsearch.xcontent.{ToXContent, ToXContentObject, XContentBuilder} @@ -45,7 +45,7 @@ import scala.util.{Failure, Success, Try} class CurrentUserMetadataRequestHandler(engine: Engine, esContext: EsContext) - extends Logging { + extends RequestIdAwareLogging { def handle(request: RequestContext.Aux[CurrentUserMetadataRequestBlockContext] with EsRequest[CurrentUserMetadataRequestBlockContext]): Task[Unit] = { engine.core.accessControl @@ -69,7 +69,7 @@ class CurrentUserMetadataRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(ex.asInstanceOf[Exception]) } } @@ -86,13 +86,13 @@ class CurrentUserMetadataRequestHandler(engine: Engine, )) } - private def onPassThrough(requestContext: RequestContext): Unit = { - logger.warn(s"[${requestContext.id.toRequestId.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") + private def onPassThrough(implicit requestContext: RequestContext): Unit = { + logger.warn(s"Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") esContext.listener.onFailure(createRorNotEnabledResponse()) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala index 2fb01dcc41..c5c44fda92 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala @@ -20,7 +20,7 @@ import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.RegularRequestResult @@ -49,7 +49,7 @@ class RegularRequestHandler(engine: Engine, esContext: EsContext, threadPool: ThreadPool) (implicit scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle[B <: BlockContext : BlockContextUpdater](request: RequestContext.Aux[B] with EsRequest[B]): Task[Unit] = { engine.core.accessControl @@ -85,7 +85,7 @@ class RegularRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(new Exception(ex)) } } @@ -99,7 +99,7 @@ class RegularRequestHandler(engine: Engine, case ModificationResult.ShouldBeInterrupted => onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case ModificationResult.CannotModify => - logger.error(s"[${request.id.toRequestId.show}] Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") + noRequestIdLogger.error(s"Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case CustomResponse(response) => respond(request, response) @@ -247,7 +247,7 @@ class RegularRequestHandler(engine: Engine, esContext.listener.onResponse(response) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } \ No newline at end of file diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala index f4f832dedc..bfc421bdd5 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.index.query.{AbstractQueryBuilder, QueryBuilder, QueryBuilders} import org.elasticsearch.search.aggregations.AggregatorFactories @@ -40,7 +40,7 @@ import tech.beshu.ror.implicits.* import java.util.UUID import scala.jdk.CollectionConverters.* -object SearchRequestOps extends Logging { +object SearchRequestOps extends RequestIdAwareLogging { implicit class QueryBuilderOps(val builder: Option[QueryBuilder]) extends AnyVal { @@ -52,7 +52,7 @@ object SearchRequestOps extends Logging { val modifiedQuery: AbstractQueryBuilder[_] = provideNewQueryWithAppliedFilter(builder, filterQuery) Some(modifiedQuery) case None => - logger.debug(s"[${requestId.show}] No filter applied to query.") + logger.debug(s"No filter applied to query.") builder } } @@ -92,7 +92,7 @@ object SearchRequestOps extends Logging { case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, requestId) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) disableCaching(requestId) case BasedOnBlockContextOnly.NotAllowedFieldsUsed(notAllowedFields) => modifyNotAllowedFieldsInRequest(notAllowedFields) @@ -138,8 +138,8 @@ object SearchRequestOps extends Logging { } } - private def disableCaching(requestId: RequestContext.Id) = { - logger.debug(s"[${requestId.show}] ACL uses context header for fields rule, will disable request cache for SearchRequest") + private def disableCaching(implicit requestId: RequestContext.Id) = { + logger.debug(s"ACL uses context header for fields rule, will disable request cache for SearchRequest") request.requestCache(false) } } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala index 270367a54f..e2884598df 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala @@ -17,7 +17,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.action.support.IndicesOptions.WildcardStates import org.elasticsearch.action.{CompositeIndicesRequest, IndicesRequest} @@ -34,7 +33,7 @@ import scala.jdk.CollectionConverters.* abstract class BaseEsRequestContext[B <: BlockContext](esContext: EsContext, clusterService: RorClusterService) - extends RequestContext with Logging { + extends RequestContext { override type BLOCK_CONTEXT = B diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala index ae8abbe1f5..0ee2967364 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala @@ -18,7 +18,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -26,8 +25,9 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import scala.util.Try +import tech.beshu.ror.utils.RequestIdAwareLogging -trait EsRequest[B <: BlockContext] extends Logging { +trait EsRequest[B <: BlockContext] extends RequestIdAwareLogging { implicit def threadPool: ThreadPool final def modifyUsing(blockContext: B): ModificationResult = { @@ -35,7 +35,7 @@ trait EsRequest[B <: BlockContext] extends Logging { Try(modifyRequest(blockContext)) .fold( ex => { - logger.error(s"[${blockContext.requestContext.id.show}] Cannot modify request with filtered data", ex) + logger.error(s"Cannot modify request with filtered data", ex)(blockContext) ModificationResult.CannotModify }, identity diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala index c6a9dcbefd..f773b3efb1 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala @@ -51,7 +51,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest private def discoverDataStreams() = { val dataStreams = dataStreamsFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered data streams: ${dataStreams.show}") + logger.debug(s"Discovered data streams: ${dataStreams.show}") dataStreams } @@ -59,7 +59,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest val backingIndices = backingIndicesFrom(actionRequest) backingIndices match { case BackingIndices.IndicesInvolved(filteredIndices, _) => - logger.debug(s"[${id.show}] Discovered indices: ${filteredIndices.show}") + logger.debug(s"Discovered indices: ${filteredIndices.show}") case BackingIndices.IndicesNotInvolved => } backingIndices diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala index c091179cb6..d150709314 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala @@ -85,7 +85,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: case Some(indices) => update(actionRequest, indices, blockContext.filter, blockContext.fieldLevelSecurity) case None => - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -101,7 +101,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } \ No newline at end of file diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala index 71d462de57..48014e1bdc 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala @@ -73,7 +73,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, } yield update(actionRequest, filteredIndices, allAllowedIndices) result.getOrElse { - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -86,7 +86,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala index 95d882c3b5..f607c0e347 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala @@ -50,7 +50,7 @@ abstract class BaseRepositoriesEsRequestContext[R <: ActionRequest](actionReques case Some(repositories) => update(actionRequest, repositories) case None => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") ShouldBeInterrupted } } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala index b3b1d66238..7ef0f32014 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala @@ -42,7 +42,7 @@ abstract class BaseSingleIndexEsRequestContext[R <: ActionRequest](actionRequest filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } update(request, filteredIndices.head) } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala index b5ab70fe7a..c1b2e7ea27 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala @@ -62,7 +62,7 @@ class BulkEsRequestContext(actionRequest: BulkRequest, case (_, _) => ShouldBeInterrupted } } else { - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because origin request contained different " + + logger.error(s"Cannot alter MultiGetRequest request, because origin request contained different " + s"number of requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } @@ -90,18 +90,18 @@ class BulkEsRequestContext(actionRequest: BulkRequest, updateRequestWithIndices(request, nel) Modified case None => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because empty list of indices was found") + logger.error(s"Cannot alter MultiGetRequest request, because empty list of indices was found") ShouldBeInterrupted } case Indices.NotFound => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because no allowed indices were found") + logger.error(s"Cannot alter MultiGetRequest request, because no allowed indices were found") ShouldBeInterrupted } } private def updateRequestWithIndices(request: DocWriteRequest[_], indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } request.index(indices.head.stringify) } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala index 75a75fcef5..96a043b298 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala @@ -53,14 +53,14 @@ class BulkShardEsRequestContext(actionRequest: BulkShardRequest, case Success(_) => Modified case Failure(ex) => - logger.error(s"[${id.show}] Cannot modify BulkShardRequest", ex) + logger.error(s"Cannot modify BulkShardRequest", ex) CannotModify } } private def tryUpdate(request: BulkShardRequest, indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } val singleIndex = indices.head val uuid = clusterService.indexOrAliasUuids(singleIndex.name).toList.head diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala index 65a168092a..158ac485a5 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala @@ -45,14 +45,14 @@ class ClusterAllocationExplainEsRequestContext(actionRequest: ClusterAllocationE getRequestedIndexFrom(request) match { case Some(_) => if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateIndexIn(request, filteredIndices.head) Modified case None if filteredIndices.exists(_.name === ClusterIndexName.Local.wildcard) => Modified case None => - logger.error(s"[${id.show}] Cluster allocation explain request without index name is unavailable when block contains `indices` rule") + logger.error(s"Cluster allocation explain request without index name is unavailable when block contains `indices` rule") ShouldBeInterrupted } } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala index 8f97fb7619..3410f4fc6d 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala @@ -68,7 +68,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, updateAliases(actionRequest, aliases) UpdateResponse.sync(updateAliasesResponse(aliases.includedOnly, _)) case None => - logger.error(s"[${id.show}] At least one alias and one index has to be allowed. " + + logger.error(s"At least one alias and one index has to be allowed. " + s"Found allowed indices: [${blockContext.indices.show}]." + s"Found allowed aliases: [${blockContext.aliases.show}]") ShouldBeInterrupted @@ -116,7 +116,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, .indices().asSafeSet .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } @@ -124,7 +124,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, val aliases = rawRequestAliasesSet(request) .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered aliases: ${aliases.show}") + logger.debug(s"Discovered aliases: ${aliases.show}") aliases } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala index abb85d42b7..f9e2c87e53 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala @@ -55,7 +55,7 @@ class IndicesAliasesEsRequestContext(actionRequest: IndicesAliasesRequest, if (originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala index 05b70606b9..37dd50452b 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala @@ -119,7 +119,7 @@ class MultiGetEsRequestContext(actionRequest: MultiGetRequest, case Nil => updateItemWithNonExistingIndex(item) case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } item.index(index.stringify) } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala index 989956d79a..9e13edee8d 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala @@ -78,7 +78,7 @@ class MultiSearchEsRequestContext(actionRequest: MultiSearchRequest, } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala index 9191e33b66..5a61356f48 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala @@ -47,7 +47,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { request.getRequests.removeIf { request => removeOrAlter(request, filteredIndices.toCovariantSet) } if (request.getRequests.asScala.isEmpty) { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") ShouldBeInterrupted } else { Modified @@ -63,7 +63,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, true case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") } request.index(index.stringify) false diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala index c411df93c5..c7b99f6e85 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala @@ -52,7 +52,7 @@ class PutRollupJobEsRequestContext private(actionRequest: ActionRequest, if(originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala index 141d9db788..fff8ed58bb 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala @@ -49,7 +49,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (tryUpdate(actionRequest, filteredIndices)) Modified else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") ShouldBeInterrupted } } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala index 489d0187bc..c42dfc3b78 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala @@ -58,10 +58,10 @@ class ReindexEsRequestContext(actionRequest: ReindexRequest, Modified } else { if (!isDestinationIndexOnFilteredIndicesList) { - logger.info(s"[${id.show}] Destination index of _reindex request is forbidden") + logger.info(s"Destination index of _reindex request is forbidden") } if (!isSearchRequestComposedOnlyOfAllowedIndices) { - logger.info(s"[${id.show}] At least one index from sources indices list of _reindex request is forbidden") + logger.info(s"At least one index from sources indices list of _reindex request is forbidden") } ShouldBeInterrupted } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala index 2c1b0014e0..97b8ccd9c5 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala @@ -74,7 +74,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo request } case Left(_) => - logger.debug(s"[${id.show}] Cannot parse SQL statement - we can pass it though, because ES is going to reject it") + logger.debug(s"Cannot parse SQL statement - we can pass it though, because ES is going to reject it") request } } @@ -85,7 +85,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DataStreamsStatsEsRequestContext.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DataStreamsStatsEsRequestContext.scala index 3cbf6360ed..3e2648b17b 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DataStreamsStatsEsRequestContext.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DataStreamsStatsEsRequestContext.scala @@ -44,7 +44,7 @@ private[datastreams] class DataStreamsStatsEsRequestContext private(actionReques if (modifyActionRequest(blockContext)) { ModificationResult.Modified } else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") ModificationResult.ShouldBeInterrupted } } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DeleteDataStreamEsRequestContext.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DeleteDataStreamEsRequestContext.scala index b4491990f0..cf135bdf6a 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DeleteDataStreamEsRequestContext.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/DeleteDataStreamEsRequestContext.scala @@ -44,7 +44,7 @@ private[datastreams] class DeleteDataStreamEsRequestContext private(actionReques if (modifyActionRequest(blockContext)) { ModificationResult.Modified } else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") ModificationResult.ShouldBeInterrupted } } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/GetDataStreamEsRequestContext.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/GetDataStreamEsRequestContext.scala index 26c210c613..c2740720de 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/GetDataStreamEsRequestContext.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/datastreams/GetDataStreamEsRequestContext.scala @@ -64,7 +64,7 @@ private[datastreams] class GetDataStreamEsRequestContext(actionRequest: ActionRe r } } else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.getCanonicalName.show} request. We're using reflection to modify the request data streams and it fails. Please, report the issue.") ModificationResult.ShouldBeInterrupted } } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala index 0c67384c1e..d7e743e648 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CleanupRepositoryEsRequestContext(actionRequest: CleanupRepositoryRequest, override protected def update(request: CleanupRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala index 44b7d78dfd..d09015139b 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CreateRepositoryEsRequestContext(actionRequest: PutRepositoryRequest, override protected def update(request: PutRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala index eaf9334872..0cf32e1bea 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class DeleteRepositoryEsRequestContext(actionRequest: DeleteRepositoryRequest, override protected def update(request: DeleteRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala index cee0bffd4c..d1410eff3d 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class VerifyRepositoryEsRequestContext(actionRequest: VerifyRepositoryRequest, override protected def update(request: VerifyRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala index ead4fcf250..20501516d5 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala @@ -68,32 +68,32 @@ class CreateSnapshotEsRequestContext(actionRequest: CreateSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala index a56aba660e..621d744767 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala @@ -60,7 +60,7 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -71,14 +71,14 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, .toRight(()) } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala index 22869bbb4f..b81f333174 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala @@ -68,7 +68,7 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, case r => r } case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala index 88887db96c..156deb5b80 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala @@ -63,7 +63,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -75,7 +75,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") } Right(snapshot) } @@ -88,7 +88,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala index 44ee8397ec..e522e440f1 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala @@ -100,12 +100,12 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { val repositories = blockContext.repositories if (allRepositoriesRequested(repositories)) { Right(RepositoryName.All) @@ -115,7 +115,7 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala index 80e36a6d77..d8e5182eed 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.GetComposableIndexTemplateAction import org.elasticsearch.cluster.metadata import org.elasticsearch.cluster.metadata.ComposableIndexTemplate @@ -108,7 +108,7 @@ class GetComposableIndexTemplateEsRequestContext(actionRequest: GetComposableInd } -private[templates] object GetComposableIndexTemplateEsRequestContext extends Logging { +private[templates] object GetComposableIndexTemplateEsRequestContext extends RequestIdAwareLogging { def filter(templates: Map[String, ComposableIndexTemplate], usingTemplate: Set[Template] => Set[Template]) diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala index 3964bdd1cc..de573c648b 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.{GetIndexTemplatesRequest, GetIndexTemplatesResponse} import org.elasticsearch.cluster.metadata.{AliasMetadata, IndexTemplateMetadata} import org.elasticsearch.common.collect.ImmutableOpenMap @@ -105,7 +105,7 @@ class GetTemplatesEsRequestContext(actionRequest: GetIndexTemplatesRequest, } -private[templates] object GetTemplatesEsRequestContext extends Logging { +private[templates] object GetTemplatesEsRequestContext extends RequestIdAwareLogging { def filter(templates: Iterable[IndexTemplateMetadata], usingTemplate: Set[Template] => Set[Template]) diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala index a8951de5b1..32116d8212 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala @@ -72,7 +72,7 @@ class MultiSearchTemplateEsRequestContext private(actionRequest: ActionRequest w } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala index e6f6d8916e..434787a686 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala @@ -55,7 +55,7 @@ class SimulateIndexTemplateRequestEsRequestContext(actionRequest: SimulateIndexT filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateRequest(request, filteredIndices.head, allAllowedIndices) } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala index fbc4cf6776..46ed6e7a95 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala @@ -109,7 +109,7 @@ class SimulateExistingTemplateRequestEsRequestContext(existingTemplateName: Temp case Some(_) => updateResponse(namePatterns.toList, blockContext.allAllowedIndices.toList) case None => - logger.info(s"[${id.show}] User has no access to template ${existingTemplateName.show}") + logger.info(s"User has no access to template ${existingTemplateName.show}") ModificationResult.ShouldBeInterrupted } case other => diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala index 0ecd7a72b3..fe4d60bd42 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.queries import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.index.query.* import org.joor.Reflect.on import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.RequestFieldsUsage @@ -30,7 +30,7 @@ trait QueryFieldsUsage[QUERY <: QueryBuilder] { def fieldsIn(query: QUERY): RequestFieldsUsage } -object QueryFieldsUsage extends Logging { +object QueryFieldsUsage extends RequestIdAwareLogging { def apply[QUERY <: QueryBuilder](implicit ev: QueryFieldsUsage[QUERY]): QueryFieldsUsage[QUERY] = ev implicit class Ops[QUERY <: QueryBuilder : QueryFieldsUsage](val query: QUERY) { @@ -62,7 +62,7 @@ object QueryFieldsUsage extends Logging { Option(on(query).call("getFieldName").get[String]) match { case Some(fieldName: String) => UsingFields(NonEmptyList.one(UsedField(fieldName))) case _ => - logger.debug(s"Cannot extract fields for terms set query") + noRequestIdLogger.debug(s"Cannot extract fields for terms set query") CannotExtractFields } } @@ -89,7 +89,7 @@ object QueryFieldsUsage extends Logging { case builder: TermsSetQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder: WildcardQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder => - logger.debug(s"Cannot extract fields for query: ${builder.getName}") + noRequestIdLogger.debug(s"Cannot extract fields for query: ${builder.getName}") CannotExtractFields } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala b/es80x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala index 0998bb9a5b..b4671e9e4d 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.handler.response import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.FieldsRestrictions import tech.beshu.ror.accesscontrol.domain.Header @@ -26,17 +26,17 @@ import tech.beshu.ror.accesscontrol.headerValues.transientFieldsToHeaderValue import tech.beshu.ror.accesscontrol.request.RequestContext import tech.beshu.ror.implicits.* -object FLSContextHeaderHandler extends Logging { +object FLSContextHeaderHandler extends RequestIdAwareLogging { def addContextHeader(threadPool: ThreadPool, - fieldsRestrictions: FieldsRestrictions, - requestId: RequestContext.Id): Unit = { + fieldsRestrictions: FieldsRestrictions) + (implicit requestId: RequestContext.Id): Unit = { val threadContext = threadPool.getThreadContext val header = createContextHeader(fieldsRestrictions) Option(threadContext.getHeader(header.name.value.value)) match { case None => implicit val show = headerShow - logger.debug(s"[${requestId.show}] Adding thread context header required by lucene. Header: '${header.show}'") + logger.debug(s"Adding thread context header required by lucene. Header: '${header.show}'") threadContext.putHeader(header.name.value.value, header.value.value) case Some(_) => } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala b/es80x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala index 26df1d5bb9..2ce5662a4b 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.admin.indices.template.get.{GetComponentTemplateAction, GetComposableIndexTemplateAction} import org.elasticsearch.action.admin.indices.template.put.{PutComponentTemplateAction, PutComposableIndexTemplateAction} @@ -45,7 +45,7 @@ import scala.jdk.CollectionConverters.* final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJsonParserFactory)(using Clock) extends DataStreamService - with Logging { + with RequestIdAwareLogging { override def checkDataStreamExists(dataStreamName: DataStreamName.Full): Task[Boolean] = execute { val enhancedActionType = client.findActionUnsafe[ActionResponse]("indices:admin/data_stream/get") @@ -218,11 +218,11 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ response <- Task.measure( task = Task.delay(nodeClient.execute(action, request).actionGet()), logTimeMeasurement = duration => Task.delay { - logger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") + noRequestIdLogger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") } ) _ <- Task.delay { - logger.debug(s"Action ${action.name()} response: ${response.toString}") + noRequestIdLogger.debug(s"Action ${action.name()} response: ${response.toString}") } } yield response } @@ -230,7 +230,7 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ def executeAck[REQUEST <: ActionRequest, RESPONSE <: AcknowledgedResponse](action: ActionType[RESPONSE], request: REQUEST): Task[RESPONSE] = { executeT(action, request) - .tapEval(response => Task.delay(logger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) + .tapEval(response => Task.delay(noRequestIdLogger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) } private def supportedActions: Map[ActionType[ActionResponse], TransportAction[ActionRequest, ActionResponse]] = { diff --git a/es80x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala b/es80x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala index 2a9a3dfd8f..fb84030bb9 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.support.WriteRequest.RefreshPolicy import org.elasticsearch.client.node.NodeClient @@ -38,7 +38,7 @@ import scala.jdk.CollectionConverters.* class EsIndexJsonContentService(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexJsonContentService - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -63,14 +63,14 @@ class EsIndexJsonContentService(client: NodeClient, Option(response.getSourceAsMap) match { case Some(map) => val source = map.asScala.toMap.asStringMap - logger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") Right(source) case None => - logger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") + noRequestIdLogger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") Right(Map.empty[String, String]) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(ContentNotFound) } } @@ -78,7 +78,7 @@ class EsIndexJsonContentService(client: NodeClient, .onErrorRecover { case _: ResourceNotFoundException => Left(ContentNotFound) case ex => - logger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) Left(CannotReachContentSource) } } @@ -104,14 +104,14 @@ class EsIndexJsonContentService(client: NodeClient, case status if status / 100 == 2 => Right(()) case status => - logger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") Left(CannotWriteToIndex) } } .executeOn(RorSchedulers.blockingScheduler) .onErrorRecover { case ex => - logger.error(s"Cannot write to document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]", ex) Left(CannotWriteToIndex) } } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala b/es80x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala index 9d42b88e51..6c7634dbc5 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala @@ -22,7 +22,7 @@ import cats.kernel.Monoid import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task import monix.execution.CancelablePromise -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction.{ResolvedAlias, ResolvedIndex} @@ -64,7 +64,7 @@ class EsServerBasedRorClusterService(nodeName: String, nodeClient: NodeClient, threadPool: ThreadPool) extends RorClusterService - with Logging { + with RequestIdAwareLogging { import EsServerBasedRorClusterService.* @@ -155,7 +155,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractAccessibilityFrom) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify get request. Blocking document", ex) + logger.error(s"Could not verify get request. Blocking document", ex)(id) Inaccessible } } @@ -167,7 +167,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractResultsFromSearchResponse) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify documents returned by multi get response. Blocking all returned documents", ex) + logger.error(s"Could not verify documents returned by multi get response. Blocking all returned documents", ex)(id) blockAllDocsReturned(documents) } .map(results => zip(results, documents)) @@ -276,7 +276,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService): Task[List[FullRemoteDataStreamWithAliases]] = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -332,7 +332,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService) = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -418,7 +418,7 @@ class EsServerBasedRorClusterService(nodeName: String, } } case None => - logger.error("Cannot supply Snapshots Service. Please, report the issue!!!") + noRequestIdLogger.error("Cannot supply Snapshots Service. Please, report the issue!!!") Task.now(Set.empty[Snapshot]) } } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala b/es80x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala index 101c2424c0..e68a083e10 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.services import cats.data.NonEmptyList -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.DocWriteRequest import org.elasticsearch.action.bulk.{BackoffPolicy, BulkProcessor, BulkRequest, BulkResponse} import org.elasticsearch.action.index.IndexRequest @@ -40,7 +40,7 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, (using Clock) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { private val bulkProcessor = BulkProcessor @@ -77,25 +77,25 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, private class AuditSinkBulkProcessorListener extends BulkProcessor.Listener { override def beforeBulk(executionId: Long, request: BulkRequest): Unit = { - logger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") + noRequestIdLogger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") } override def afterBulk(executionId: Long, request: BulkRequest, response: BulkResponse): Unit = { if (response.hasFailures) { - logger.error("Some failures flushing the BulkProcessor: ") + noRequestIdLogger.error("Some failures flushing the BulkProcessor: ") response .getItems.to(LazyList) .filter(_.isFailed) .map(_.getFailureMessage) .groupBy(identity) .foreach { case (message, stream) => - logger.error(s"${stream.size}x: $message") + noRequestIdLogger.error(s"${stream.size}x: $message") } } } override def afterBulk(executionId: Long, request: BulkRequest, failure: Throwable): Unit = { - logger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) + noRequestIdLogger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) } } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala b/es80x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala index a8def0ec7a..b3c5593c36 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala @@ -22,7 +22,7 @@ import org.apache.http.auth.{AuthScope, Credentials, UsernamePasswordCredentials import org.apache.http.conn.ssl.NoopHostnameVerifier import org.apache.http.impl.client.BasicCredentialsProvider import org.apache.http.impl.nio.client.HttpAsyncClientBuilder -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.* import org.elasticsearch.client.RestClient.FailureListener import tech.beshu.ror.accesscontrol.audit.sink.AuditDataStreamCreator @@ -38,7 +38,7 @@ import scala.collection.parallel.CollectionConverters.* final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient]) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { override def submit(indexName: IndexName.Full, documentId: String, jsonRecord: String) (implicit requestId: RequestId): Unit = { @@ -77,21 +77,21 @@ final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient] override def onSuccess(response: Response): Unit = { response.getStatusLine.getStatusCode / 100 match { case 2 => // 2xx - logger.debug(s"[${requestId.show}] Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") + logger.debug(s"Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") case _ => - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") } } override def onFailure(ex: Exception): Unit = { - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId]", ex) + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId]", ex) } } override val dataStreamCreator: AuditDataStreamCreator = new AuditDataStreamCreator(clients.map(new RestClientDataStreamService(_))) } -object RestClientAuditSinkService extends Logging { +object RestClientAuditSinkService extends RequestIdAwareLogging { def create(remoteCluster: AuditCluster.RemoteAuditCluster): RestClientAuditSinkService = { remoteCluster.mode match { @@ -122,7 +122,7 @@ object RestClientAuditSinkService extends Logging { .setFailureListener( new FailureListener { override def onFailure(node: Node): Unit = { - logger.debug( + noRequestIdLogger.debug( s"[AUDIT] Node marked dead: ${node.getHost.getSchemeName}://${node.getHost.getHostName}:${node.getHost.getPort}. The client will attempt failover.", ) } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala b/es80x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala index 946cfa4c28..24f15af465 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.Channel import io.netty.handler.ssl.NotSslRecordException -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.network.NetworkService import org.elasticsearch.common.settings.{ClusterSettings, Settings} import org.elasticsearch.common.util.BigArrays @@ -41,7 +41,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, sharedGroupFactory: SharedGroupFactory, fipsCompliant: Boolean) extends Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, ssl.clientAuthenticationEnabled) @@ -49,7 +49,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, override def onException(channel: HttpChannel, cause: Exception): Unit = { if (!this.lifecycle.started) return - else if (cause.getCause.isInstanceOf[NotSslRecordException]) logger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) + else if (cause.getCause.isInstanceOf[NotSslRecordException]) noRequestIdLogger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) else super.onException(channel, cause) channel.close() } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala b/es80x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala index f9f71f30b1..e241596351 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.* import io.netty.handler.ssl.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.Version import org.elasticsearch.cluster.node.DiscoveryNode import org.elasticsearch.common.io.stream.NamedWriteableRegistry @@ -45,7 +45,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, sharedGroupFactory: SharedGroupFactory, fipsCompliant: Boolean) extends Netty4Transport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = SSLCertHelper.prepareClientSSLContext(ssl, fipsCompliant, ssl.certificateVerificationEnabled) private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, clientAuthenticationEnabled = false) @@ -76,7 +76,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, override def exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable): Unit = { if (cause.isInstanceOf[NotSslRecordException] || (cause.getCause != null && cause.getCause.isInstanceOf[NotSslRecordException])) { - logger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") + noRequestIdLogger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") ctx.channel.close } else { super.exceptionCaught(ctx, cause) diff --git a/es80x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala b/es80x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala index a2eb0db8a3..6c41f11b5e 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.utils import cats.Show import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.client.node.NodeClient import org.elasticsearch.rest.* @@ -38,7 +38,7 @@ import java.util import scala.util.Try class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandler) - extends RestHandler with Logging { + extends RestHandler with RequestIdAwareLogging { private val wrapped = doPrivileged { wrapSomeActions(underlying) @@ -105,11 +105,11 @@ class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandle private def logError(error: AuthorizationValueError): Unit = { { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorSanitizedShow - logger.warn(s"The incoming request was malformed. Cause: ${error.show}") + noRequestIdLogger.warn(s"The incoming request was malformed. Cause: ${error.show}") } if (logger.delegate.isDebugEnabled()) { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorWithDetailsShow - logger.debug(s"Malformed request detailed cause: ${error.show}") + noRequestIdLogger.debug(s"Malformed request detailed cause: ${error.show}") } } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala b/es80x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala index 5ab1e35742..a9af8f710a 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala @@ -16,13 +16,13 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.settings.Settings import tech.beshu.ror.tools.core.patches.PatchingVerifier import tech.beshu.ror.tools.core.patches.PatchingVerifier.Error.{CannotVerifyIfPatched, EsNotPatched} import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -object EsPatchVerifier extends Logging { +object EsPatchVerifier extends RequestIdAwareLogging { def verify(settings: Settings): Unit = doPrivileged { pathHomeFrom(settings).flatMap(PatchingVerifier.verify) match { @@ -30,7 +30,7 @@ object EsPatchVerifier extends Logging { case Left(e@EsNotPatched(_)) => throw new IllegalStateException(e.message) case Left(e@CannotVerifyIfPatched(_)) => - logger.warn(e.message) + noRequestIdLogger.warn(e.message) } } diff --git a/es80x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala b/es80x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala index 639aeb5029..893d807108 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.repositories.{RepositoriesService, VerifyNodeRepositoryAction} import org.elasticsearch.transport.{RemoteClusterService, TransportService} import org.joor.Reflect.on @@ -26,7 +26,7 @@ import java.util.function.Supplier import scala.util.{Failure, Success, Try} class RemoteClusterServiceSupplier(repositoriesServiceSupplier: Supplier[RepositoriesService]) - extends Supplier[Option[RemoteClusterService]] with Logging { + extends Supplier[Option[RemoteClusterService]] with RequestIdAwareLogging { override def get(): Option[RemoteClusterService] = { for { @@ -35,7 +35,7 @@ class RemoteClusterServiceSupplier(repositoriesServiceSupplier: Supplier[Reposit case Success(transportService) => Option(transportService.getRemoteClusterService) case Failure(ex) => - logger.error("Cannot extract RemoteClusterService from RepositoriesService", ex) + noRequestIdLogger.error("Cannot extract RemoteClusterService from RepositoriesService", ex) None } } yield remoteClusterService diff --git a/es810x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es810x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index 07d70bbf05..978eebec5d 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.support.{ActionFilter, ActionFilterChain} import org.elasticsearch.action.{ActionListener, ActionRequest, ActionResponse} import org.elasticsearch.client.internal.node.NodeClient @@ -62,7 +62,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, rorEsConfig: ReadonlyRestEsConfig) (implicit environmentConfig: EnvironmentConfig) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = environmentConfig.uniqueIdentifierGenerator @@ -211,12 +211,12 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def handleRorNotReadyYet(esContext: EsContext): Unit = { - logger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") + noRequestIdLogger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") rorNotAvailableRequestHandler.handleRorNotReadyYet(esContext) } private def handleRorFailedToStart(esContext: EsContext): Unit = { - logger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") + noRequestIdLogger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") rorNotAvailableRequestHandler.handleRorFailedToStart(esContext) } @@ -238,7 +238,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def logAndSetStartingFailureState(failure: StartingFailure): Unit = { - logger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) + noRequestIdLogger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) rorInstanceState.set(RorInstanceStartingState.NotStarted(failure)) } } diff --git a/es810x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala b/es810x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala index 1fb22fc79d..53452eb8e6 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.xcontent.LoggingDeprecationHandler import org.elasticsearch.rest.RestResponse import org.elasticsearch.transport.BytesRefRecycler @@ -32,7 +32,7 @@ import tech.beshu.ror.accesscontrol.domain.ResponseFieldsFiltering.{AccessMode, import scala.jdk.CollectionConverters.* trait ResponseFieldsFiltering { - this: Logging => + this: RequestIdAwareLogging => private val responseFieldsRestrictions: Atomic[Option[ResponseFieldsRestrictions]] = Atomic(None: Option[ResponseFieldsRestrictions]) diff --git a/es810x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala b/es810x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala index 0f26750588..da95de59a4 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.action.{ActionListener, ActionResponse} import org.elasticsearch.threadpool.ThreadPool @@ -37,7 +37,7 @@ sealed abstract class RorActionListener[T](val underlying: ActionListener[T]) ex final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionListener[T], correlationId: Eval[CorrelationId]) - extends RorActionListener[T](underlying) with Logging { + extends RorActionListener[T](underlying) with RequestIdAwareLogging { override def onFailure(e: Exception): Unit = { super.onFailure(adaptExceptionIfNeeded(e)) @@ -47,7 +47,7 @@ final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionLis ex match { case esException: ElasticsearchException => esException case other => - logger.error(s"[${correlationId.value.show}] Internal error.", other) + noRequestIdLogger.error(s"[${correlationId.value.show}] Internal error.", other) new ElasticsearchException(s"[${correlationId.value.show}] Internal error. See logs for details.") } } diff --git a/es810x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala b/es810x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala index 75048ebe7d..14e5e31c1b 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.http.HttpChannel import org.elasticsearch.rest.{AbstractRestChannel, RestChannel as EsRestChannel, RestRequest as EsRestRequest, RestResponse as EsRestResponse} import squants.information.{Bytes, Information} @@ -40,7 +40,7 @@ object RorRestChannel { final class RorRestChannel private(underlying: EsRestChannel, val restRequest: RorRestRequest) extends AbstractRestChannel(underlying.request(), true) with ResponseFieldsFiltering - with Logging { + with RequestIdAwareLogging { override def sendResponse(response: EsRestResponse): Unit = { ThreadRepo.removeRestChannel(this) diff --git a/es810x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala b/es810x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala index 6babc712b9..3c80750a25 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala @@ -18,16 +18,15 @@ package tech.beshu.ror.es.actions.rradmin import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.ConfigApi.ConfigResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAdminActionHandler extends Logging { +class RRAdminActionHandler extends RequestIdAwareLogging { private implicit val adminRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +51,7 @@ class RRAdminActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAdminResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAdminAction internal error", ex) + logger.error("RRAdminAction internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es810x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala b/es810x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala index c55835a1d0..ce45c6f48e 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala @@ -16,18 +16,15 @@ */ package tech.beshu.ror.es.actions.rrauthmock -import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.AuthMockApi.AuthMockResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier -import tech.beshu.ror.implicits.* +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAuthMockActionHandler extends Logging { +class RRAuthMockActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -53,7 +50,7 @@ class RRAuthMockActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAuthMockResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAuthMock internal error", ex) + logger.error("RRAuthMock internal error", ex) listener.onFailure(new Exception(ex)) } } diff --git a/es810x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala b/es810x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala index aa8bb31e67..640084c4ec 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestconfig import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.TestConfigApi.TestConfigResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestConfigActionHandler extends Logging { +class RRTestConfigActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +52,7 @@ class RRTestConfigActionHandler extends Logging { case Right(response) => listener.onResponse(new RRTestConfigResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRTestConfig internal error", ex) + logger.error(s"RRTestConfig internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es810x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala b/es810x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala index 494e9150b4..98cc0c945d 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.dlsfls import cats.data.StateT import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.DirectoryReader import org.elasticsearch.common.util.concurrent.ThreadContext import org.elasticsearch.core.CheckedFunction @@ -31,7 +31,7 @@ import java.io.IOException import java.util.function.{Function => JavaFunction} import scala.util.{Failure, Success, Try} -object RoleIndexSearcherWrapper extends Logging { +object RoleIndexSearcherWrapper extends RequestIdAwareLogging { val instance: JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] = new JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] { @@ -54,7 +54,7 @@ object RoleIndexSearcherWrapper extends Logging { } .map(r => (r, r)) case None => - logger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") + noRequestIdLogger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") Success((reader, reader)) } } @@ -66,13 +66,13 @@ object RoleIndexSearcherWrapper extends Logging { nel <- NonEmptyString.from(value) match { case Right(nel) => Success(nel) case Left(_) => - logger.debug("FLS: empty header value") + noRequestIdLogger.debug("FLS: empty header value") failure } fields <- transientFieldsFromHeaderValue.fromRawValue(nel) match { case result@Success(_) => result case Failure(ex) => - logger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) + noRequestIdLogger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) failure } } yield fields diff --git a/es810x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala b/es810x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala index ce77d77f4e..aeccbfcead 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.dlsfls import com.google.common.collect.Iterators -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.codecs.StoredFieldsReader import org.apache.lucene.index.* import org.apache.lucene.index.StoredFieldVisitor.Status @@ -39,21 +39,21 @@ import scala.jdk.CollectionConverters.* import scala.util.Try private class RorDocumentFieldReader(reader: LeafReader, fieldsRestrictions: FieldsRestrictions) - extends SequentialStoredFieldsLeafReader(reader) with Logging { + extends SequentialStoredFieldsLeafReader(reader) with RequestIdAwareLogging { private val policy = new FieldsPolicy(fieldsRestrictions) private val remainingFieldsInfo = { val fInfos = in.getFieldInfos val newInfos = if (fInfos.asScala.isEmpty) { - logger.warn("original fields were empty! This is weird!") + noRequestIdLogger.warn("original fields were empty! This is weird!") fInfos } else { val remainingFields = fInfos.asScala.filter(f => policy.canKeep(f.name)).toSet new FieldInfos(remainingFields.toArray) } - logger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") - logger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") - logger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") + noRequestIdLogger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") newInfos } private val jsonPolicyBasedFilterer = new JsonPolicyBasedFilterer(policy) diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala index 15add4a6dd..a4d939d26a 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.* import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest import org.elasticsearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest @@ -87,7 +87,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, threadPool: ThreadPool) (implicit generator: UniqueIdentifierGenerator, scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle(engines: Engines, esContext: EsContext): Task[Either[Error, Unit]] = { @@ -242,7 +242,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, case SearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case MultiSearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case _ => - logger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") + noRequestIdLogger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") regularRequestHandler.handle(new DummyCompositeIndicesEsRequestContext(request, esContext, aclContext, clusterService, threadPool)) } // rest diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala index cab02aff37..100edd72ac 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.common.io.stream.StreamOutput import org.elasticsearch.xcontent.{ToXContent, ToXContentObject, XContentBuilder} @@ -45,7 +45,7 @@ import scala.util.{Failure, Success, Try} class CurrentUserMetadataRequestHandler(engine: Engine, esContext: EsContext) - extends Logging { + extends RequestIdAwareLogging { def handle(request: RequestContext.Aux[CurrentUserMetadataRequestBlockContext] with EsRequest[CurrentUserMetadataRequestBlockContext]): Task[Unit] = { engine.core.accessControl @@ -69,7 +69,7 @@ class CurrentUserMetadataRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(ex.asInstanceOf[Exception]) } } @@ -86,13 +86,13 @@ class CurrentUserMetadataRequestHandler(engine: Engine, )) } - private def onPassThrough(requestContext: RequestContext): Unit = { - logger.warn(s"[${requestContext.id.toRequestId.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") + private def onPassThrough(implicit requestContext: RequestContext): Unit = { + logger.warn(s"Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") esContext.listener.onFailure(createRorNotEnabledResponse()) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala index 2fb01dcc41..c5c44fda92 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala @@ -20,7 +20,7 @@ import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.RegularRequestResult @@ -49,7 +49,7 @@ class RegularRequestHandler(engine: Engine, esContext: EsContext, threadPool: ThreadPool) (implicit scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle[B <: BlockContext : BlockContextUpdater](request: RequestContext.Aux[B] with EsRequest[B]): Task[Unit] = { engine.core.accessControl @@ -85,7 +85,7 @@ class RegularRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(new Exception(ex)) } } @@ -99,7 +99,7 @@ class RegularRequestHandler(engine: Engine, case ModificationResult.ShouldBeInterrupted => onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case ModificationResult.CannotModify => - logger.error(s"[${request.id.toRequestId.show}] Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") + noRequestIdLogger.error(s"Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case CustomResponse(response) => respond(request, response) @@ -247,7 +247,7 @@ class RegularRequestHandler(engine: Engine, esContext.listener.onResponse(response) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } \ No newline at end of file diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala index f4f832dedc..bfc421bdd5 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.index.query.{AbstractQueryBuilder, QueryBuilder, QueryBuilders} import org.elasticsearch.search.aggregations.AggregatorFactories @@ -40,7 +40,7 @@ import tech.beshu.ror.implicits.* import java.util.UUID import scala.jdk.CollectionConverters.* -object SearchRequestOps extends Logging { +object SearchRequestOps extends RequestIdAwareLogging { implicit class QueryBuilderOps(val builder: Option[QueryBuilder]) extends AnyVal { @@ -52,7 +52,7 @@ object SearchRequestOps extends Logging { val modifiedQuery: AbstractQueryBuilder[_] = provideNewQueryWithAppliedFilter(builder, filterQuery) Some(modifiedQuery) case None => - logger.debug(s"[${requestId.show}] No filter applied to query.") + logger.debug(s"No filter applied to query.") builder } } @@ -92,7 +92,7 @@ object SearchRequestOps extends Logging { case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, requestId) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) disableCaching(requestId) case BasedOnBlockContextOnly.NotAllowedFieldsUsed(notAllowedFields) => modifyNotAllowedFieldsInRequest(notAllowedFields) @@ -138,8 +138,8 @@ object SearchRequestOps extends Logging { } } - private def disableCaching(requestId: RequestContext.Id) = { - logger.debug(s"[${requestId.show}] ACL uses context header for fields rule, will disable request cache for SearchRequest") + private def disableCaching(implicit requestId: RequestContext.Id) = { + logger.debug(s"ACL uses context header for fields rule, will disable request cache for SearchRequest") request.requestCache(false) } } diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala index 270367a54f..e2884598df 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala @@ -17,7 +17,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.action.support.IndicesOptions.WildcardStates import org.elasticsearch.action.{CompositeIndicesRequest, IndicesRequest} @@ -34,7 +33,7 @@ import scala.jdk.CollectionConverters.* abstract class BaseEsRequestContext[B <: BlockContext](esContext: EsContext, clusterService: RorClusterService) - extends RequestContext with Logging { + extends RequestContext { override type BLOCK_CONTEXT = B diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala index ae8abbe1f5..0ee2967364 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala @@ -18,7 +18,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -26,8 +25,9 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import scala.util.Try +import tech.beshu.ror.utils.RequestIdAwareLogging -trait EsRequest[B <: BlockContext] extends Logging { +trait EsRequest[B <: BlockContext] extends RequestIdAwareLogging { implicit def threadPool: ThreadPool final def modifyUsing(blockContext: B): ModificationResult = { @@ -35,7 +35,7 @@ trait EsRequest[B <: BlockContext] extends Logging { Try(modifyRequest(blockContext)) .fold( ex => { - logger.error(s"[${blockContext.requestContext.id.show}] Cannot modify request with filtered data", ex) + logger.error(s"Cannot modify request with filtered data", ex)(blockContext) ModificationResult.CannotModify }, identity diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala index c6a9dcbefd..f773b3efb1 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala @@ -51,7 +51,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest private def discoverDataStreams() = { val dataStreams = dataStreamsFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered data streams: ${dataStreams.show}") + logger.debug(s"Discovered data streams: ${dataStreams.show}") dataStreams } @@ -59,7 +59,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest val backingIndices = backingIndicesFrom(actionRequest) backingIndices match { case BackingIndices.IndicesInvolved(filteredIndices, _) => - logger.debug(s"[${id.show}] Discovered indices: ${filteredIndices.show}") + logger.debug(s"Discovered indices: ${filteredIndices.show}") case BackingIndices.IndicesNotInvolved => } backingIndices diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala index c091179cb6..d150709314 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala @@ -85,7 +85,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: case Some(indices) => update(actionRequest, indices, blockContext.filter, blockContext.fieldLevelSecurity) case None => - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -101,7 +101,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } \ No newline at end of file diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala index 71d462de57..48014e1bdc 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala @@ -73,7 +73,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, } yield update(actionRequest, filteredIndices, allAllowedIndices) result.getOrElse { - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -86,7 +86,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala index 95d882c3b5..f607c0e347 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala @@ -50,7 +50,7 @@ abstract class BaseRepositoriesEsRequestContext[R <: ActionRequest](actionReques case Some(repositories) => update(actionRequest, repositories) case None => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") ShouldBeInterrupted } } diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala index b3b1d66238..7ef0f32014 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala @@ -42,7 +42,7 @@ abstract class BaseSingleIndexEsRequestContext[R <: ActionRequest](actionRequest filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } update(request, filteredIndices.head) } diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala index b5ab70fe7a..c1b2e7ea27 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala @@ -62,7 +62,7 @@ class BulkEsRequestContext(actionRequest: BulkRequest, case (_, _) => ShouldBeInterrupted } } else { - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because origin request contained different " + + logger.error(s"Cannot alter MultiGetRequest request, because origin request contained different " + s"number of requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } @@ -90,18 +90,18 @@ class BulkEsRequestContext(actionRequest: BulkRequest, updateRequestWithIndices(request, nel) Modified case None => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because empty list of indices was found") + logger.error(s"Cannot alter MultiGetRequest request, because empty list of indices was found") ShouldBeInterrupted } case Indices.NotFound => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because no allowed indices were found") + logger.error(s"Cannot alter MultiGetRequest request, because no allowed indices were found") ShouldBeInterrupted } } private def updateRequestWithIndices(request: DocWriteRequest[_], indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } request.index(indices.head.stringify) } diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala index 75a75fcef5..96a043b298 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala @@ -53,14 +53,14 @@ class BulkShardEsRequestContext(actionRequest: BulkShardRequest, case Success(_) => Modified case Failure(ex) => - logger.error(s"[${id.show}] Cannot modify BulkShardRequest", ex) + logger.error(s"Cannot modify BulkShardRequest", ex) CannotModify } } private def tryUpdate(request: BulkShardRequest, indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } val singleIndex = indices.head val uuid = clusterService.indexOrAliasUuids(singleIndex.name).toList.head diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala index 65a168092a..158ac485a5 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala @@ -45,14 +45,14 @@ class ClusterAllocationExplainEsRequestContext(actionRequest: ClusterAllocationE getRequestedIndexFrom(request) match { case Some(_) => if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateIndexIn(request, filteredIndices.head) Modified case None if filteredIndices.exists(_.name === ClusterIndexName.Local.wildcard) => Modified case None => - logger.error(s"[${id.show}] Cluster allocation explain request without index name is unavailable when block contains `indices` rule") + logger.error(s"Cluster allocation explain request without index name is unavailable when block contains `indices` rule") ShouldBeInterrupted } } diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala index 5778b8968d..02dec730ed 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala @@ -66,7 +66,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, updateAliases(actionRequest, aliases) UpdateResponse.sync(updateAliasesResponse(aliases.includedOnly, _)) case None => - logger.error(s"[${id.show}] At least one alias and one index has to be allowed. " + + logger.error(s"At least one alias and one index has to be allowed. " + s"Found allowed indices: [${blockContext.indices.show}]." + s"Found allowed aliases: [${blockContext.aliases.show}]") ShouldBeInterrupted @@ -114,7 +114,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, .indices().asSafeSet .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } @@ -122,7 +122,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, val aliases = rawRequestAliasesSet(request) .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered aliases: ${aliases.show}") + logger.debug(s"Discovered aliases: ${aliases.show}") aliases } diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala index abb85d42b7..f9e2c87e53 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala @@ -55,7 +55,7 @@ class IndicesAliasesEsRequestContext(actionRequest: IndicesAliasesRequest, if (originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala index 05b70606b9..37dd50452b 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala @@ -119,7 +119,7 @@ class MultiGetEsRequestContext(actionRequest: MultiGetRequest, case Nil => updateItemWithNonExistingIndex(item) case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } item.index(index.stringify) } diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala index 989956d79a..9e13edee8d 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala @@ -78,7 +78,7 @@ class MultiSearchEsRequestContext(actionRequest: MultiSearchRequest, } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala index 9191e33b66..5a61356f48 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala @@ -47,7 +47,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { request.getRequests.removeIf { request => removeOrAlter(request, filteredIndices.toCovariantSet) } if (request.getRequests.asScala.isEmpty) { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") ShouldBeInterrupted } else { Modified @@ -63,7 +63,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, true case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") } request.index(index.stringify) false diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala index c411df93c5..c7b99f6e85 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala @@ -52,7 +52,7 @@ class PutRollupJobEsRequestContext private(actionRequest: ActionRequest, if(originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala index 141d9db788..fff8ed58bb 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala @@ -49,7 +49,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (tryUpdate(actionRequest, filteredIndices)) Modified else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") ShouldBeInterrupted } } diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala index 489d0187bc..c42dfc3b78 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala @@ -58,10 +58,10 @@ class ReindexEsRequestContext(actionRequest: ReindexRequest, Modified } else { if (!isDestinationIndexOnFilteredIndicesList) { - logger.info(s"[${id.show}] Destination index of _reindex request is forbidden") + logger.info(s"Destination index of _reindex request is forbidden") } if (!isSearchRequestComposedOnlyOfAllowedIndices) { - logger.info(s"[${id.show}] At least one index from sources indices list of _reindex request is forbidden") + logger.info(s"At least one index from sources indices list of _reindex request is forbidden") } ShouldBeInterrupted } diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala index 2c1b0014e0..97b8ccd9c5 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala @@ -74,7 +74,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo request } case Left(_) => - logger.debug(s"[${id.show}] Cannot parse SQL statement - we can pass it though, because ES is going to reject it") + logger.debug(s"Cannot parse SQL statement - we can pass it though, because ES is going to reject it") request } } @@ -85,7 +85,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala index 0c67384c1e..d7e743e648 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CleanupRepositoryEsRequestContext(actionRequest: CleanupRepositoryRequest, override protected def update(request: CleanupRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala index 44b7d78dfd..d09015139b 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CreateRepositoryEsRequestContext(actionRequest: PutRepositoryRequest, override protected def update(request: PutRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala index eaf9334872..0cf32e1bea 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class DeleteRepositoryEsRequestContext(actionRequest: DeleteRepositoryRequest, override protected def update(request: DeleteRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala index cee0bffd4c..d1410eff3d 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class VerifyRepositoryEsRequestContext(actionRequest: VerifyRepositoryRequest, override protected def update(request: VerifyRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala index ead4fcf250..20501516d5 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala @@ -68,32 +68,32 @@ class CreateSnapshotEsRequestContext(actionRequest: CreateSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala index a56aba660e..621d744767 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala @@ -60,7 +60,7 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -71,14 +71,14 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, .toRight(()) } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala index 22869bbb4f..b81f333174 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala @@ -68,7 +68,7 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, case r => r } case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala index 88887db96c..156deb5b80 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala @@ -63,7 +63,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -75,7 +75,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") } Right(snapshot) } @@ -88,7 +88,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala index 44ee8397ec..e522e440f1 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala @@ -100,12 +100,12 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { val repositories = blockContext.repositories if (allRepositoriesRequested(repositories)) { Right(RepositoryName.All) @@ -115,7 +115,7 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala index 80e36a6d77..d8e5182eed 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.GetComposableIndexTemplateAction import org.elasticsearch.cluster.metadata import org.elasticsearch.cluster.metadata.ComposableIndexTemplate @@ -108,7 +108,7 @@ class GetComposableIndexTemplateEsRequestContext(actionRequest: GetComposableInd } -private[templates] object GetComposableIndexTemplateEsRequestContext extends Logging { +private[templates] object GetComposableIndexTemplateEsRequestContext extends RequestIdAwareLogging { def filter(templates: Map[String, ComposableIndexTemplate], usingTemplate: Set[Template] => Set[Template]) diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala index bd74c3a18f..1c6eecf409 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.{GetIndexTemplatesRequest, GetIndexTemplatesResponse} import org.elasticsearch.cluster.metadata.{AliasMetadata, IndexTemplateMetadata} import org.elasticsearch.common.collect.ImmutableOpenMap @@ -104,7 +104,7 @@ class GetTemplatesEsRequestContext(actionRequest: GetIndexTemplatesRequest, } -private[templates] object GetTemplatesEsRequestContext extends Logging { +private[templates] object GetTemplatesEsRequestContext extends RequestIdAwareLogging { def filter(templates: Iterable[IndexTemplateMetadata], usingTemplate: Set[Template] => Set[Template]) diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala index a8951de5b1..32116d8212 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala @@ -72,7 +72,7 @@ class MultiSearchTemplateEsRequestContext private(actionRequest: ActionRequest w } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala index e6f6d8916e..434787a686 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala @@ -55,7 +55,7 @@ class SimulateIndexTemplateRequestEsRequestContext(actionRequest: SimulateIndexT filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateRequest(request, filteredIndices.head, allAllowedIndices) } diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala index fbc4cf6776..46ed6e7a95 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala @@ -109,7 +109,7 @@ class SimulateExistingTemplateRequestEsRequestContext(existingTemplateName: Temp case Some(_) => updateResponse(namePatterns.toList, blockContext.allAllowedIndices.toList) case None => - logger.info(s"[${id.show}] User has no access to template ${existingTemplateName.show}") + logger.info(s"User has no access to template ${existingTemplateName.show}") ModificationResult.ShouldBeInterrupted } case other => diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala index 0ecd7a72b3..fe4d60bd42 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.queries import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.index.query.* import org.joor.Reflect.on import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.RequestFieldsUsage @@ -30,7 +30,7 @@ trait QueryFieldsUsage[QUERY <: QueryBuilder] { def fieldsIn(query: QUERY): RequestFieldsUsage } -object QueryFieldsUsage extends Logging { +object QueryFieldsUsage extends RequestIdAwareLogging { def apply[QUERY <: QueryBuilder](implicit ev: QueryFieldsUsage[QUERY]): QueryFieldsUsage[QUERY] = ev implicit class Ops[QUERY <: QueryBuilder : QueryFieldsUsage](val query: QUERY) { @@ -62,7 +62,7 @@ object QueryFieldsUsage extends Logging { Option(on(query).call("getFieldName").get[String]) match { case Some(fieldName: String) => UsingFields(NonEmptyList.one(UsedField(fieldName))) case _ => - logger.debug(s"Cannot extract fields for terms set query") + noRequestIdLogger.debug(s"Cannot extract fields for terms set query") CannotExtractFields } } @@ -89,7 +89,7 @@ object QueryFieldsUsage extends Logging { case builder: TermsSetQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder: WildcardQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder => - logger.debug(s"Cannot extract fields for query: ${builder.getName}") + noRequestIdLogger.debug(s"Cannot extract fields for query: ${builder.getName}") CannotExtractFields } diff --git a/es810x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala b/es810x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala index 0998bb9a5b..b4671e9e4d 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.handler.response import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.FieldsRestrictions import tech.beshu.ror.accesscontrol.domain.Header @@ -26,17 +26,17 @@ import tech.beshu.ror.accesscontrol.headerValues.transientFieldsToHeaderValue import tech.beshu.ror.accesscontrol.request.RequestContext import tech.beshu.ror.implicits.* -object FLSContextHeaderHandler extends Logging { +object FLSContextHeaderHandler extends RequestIdAwareLogging { def addContextHeader(threadPool: ThreadPool, - fieldsRestrictions: FieldsRestrictions, - requestId: RequestContext.Id): Unit = { + fieldsRestrictions: FieldsRestrictions) + (implicit requestId: RequestContext.Id): Unit = { val threadContext = threadPool.getThreadContext val header = createContextHeader(fieldsRestrictions) Option(threadContext.getHeader(header.name.value.value)) match { case None => implicit val show = headerShow - logger.debug(s"[${requestId.show}] Adding thread context header required by lucene. Header: '${header.show}'") + logger.debug(s"Adding thread context header required by lucene. Header: '${header.show}'") threadContext.putHeader(header.name.value.value, header.value.value) case Some(_) => } diff --git a/es810x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala b/es810x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala index 629696a91d..7aa2029a2a 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.admin.indices.template.get.{GetComponentTemplateAction, GetComposableIndexTemplateAction} import org.elasticsearch.action.admin.indices.template.put.{PutComponentTemplateAction, PutComposableIndexTemplateAction} @@ -46,7 +46,7 @@ import scala.jdk.CollectionConverters.* final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJsonParserFactory)(using Clock) extends DataStreamService - with Logging { + with RequestIdAwareLogging { override def checkDataStreamExists(dataStreamName: DataStreamName.Full): Task[Boolean] = execute { val request = new GetDataStreamAction.Request(List(dataStreamName.value.value).toArray) @@ -203,11 +203,11 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ response <- Task.measure( task = Task.delay(nodeClient.execute(action, request).actionGet()), logTimeMeasurement = duration => Task.delay { - logger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") + noRequestIdLogger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") } ) _ <- Task.delay { - logger.debug(s"Action ${action.name()} response: ${response.toString}") + noRequestIdLogger.debug(s"Action ${action.name()} response: ${response.toString}") } } yield response } @@ -215,7 +215,7 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ def executeAck[REQUEST <: ActionRequest, RESPONSE <: AcknowledgedResponse](action: ActionType[RESPONSE], request: REQUEST): Task[RESPONSE] = { executeT(action, request) - .tapEval(response => Task.delay(logger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) + .tapEval(response => Task.delay(noRequestIdLogger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) } private def supportedActions: Map[ActionType[ActionResponse], TransportAction[ActionRequest, ActionResponse]] = { diff --git a/es810x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala b/es810x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala index 2e75d37d0f..16259474bf 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.support.WriteRequest.RefreshPolicy import org.elasticsearch.client.internal.node.NodeClient @@ -38,7 +38,7 @@ import scala.jdk.CollectionConverters.* class EsIndexJsonContentService(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexJsonContentService - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -63,14 +63,14 @@ class EsIndexJsonContentService(client: NodeClient, Option(response.getSourceAsMap) match { case Some(map) => val source = map.asScala.toMap.asStringMap - logger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") Right(source) case None => - logger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") + noRequestIdLogger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") Right(Map.empty[String, String]) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(ContentNotFound) } } @@ -78,7 +78,7 @@ class EsIndexJsonContentService(client: NodeClient, .onErrorRecover { case _: ResourceNotFoundException => Left(ContentNotFound) case ex => - logger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) Left(CannotReachContentSource) } } @@ -104,14 +104,14 @@ class EsIndexJsonContentService(client: NodeClient, case status if status / 100 == 2 => Right(()) case status => - logger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") Left(CannotWriteToIndex) } } .executeOn(RorSchedulers.blockingScheduler) .onErrorRecover { case ex => - logger.error(s"Cannot write to document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]", ex) Left(CannotWriteToIndex) } } diff --git a/es810x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala b/es810x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala index 1429c7405a..c27d4ec9d5 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala @@ -22,7 +22,7 @@ import cats.kernel.Monoid import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task import monix.execution.{CancelablePromise, Scheduler} -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction.{ResolvedAlias, ResolvedIndex} @@ -64,7 +64,7 @@ class EsServerBasedRorClusterService(nodeName: String, threadPool: ThreadPool) (implicit val scheduler: Scheduler) extends RorClusterService - with Logging { + with RequestIdAwareLogging { import EsServerBasedRorClusterService.* @@ -155,7 +155,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractAccessibilityFrom) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify get request. Blocking document", ex) + logger.error(s"Could not verify get request. Blocking document", ex)(id) Inaccessible } } @@ -167,7 +167,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractResultsFromSearchResponse) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify documents returned by multi get response. Blocking all returned documents", ex) + logger.error(s"Could not verify documents returned by multi get response. Blocking all returned documents", ex)(id) blockAllDocsReturned(documents) } .map(results => zip(results, documents)) @@ -276,7 +276,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService): Task[List[FullRemoteDataStreamWithAliases]] = { getRemoteClusterClient(remoteClusterService, remoteClusterName) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -332,7 +332,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService) = { getRemoteClusterClient(remoteClusterService, remoteClusterName) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -423,7 +423,7 @@ class EsServerBasedRorClusterService(nodeName: String, } } case None => - logger.error("Cannot supply Snapshots Service. Please, report the issue!!!") + noRequestIdLogger.error("Cannot supply Snapshots Service. Please, report the issue!!!") Task.now(Set.empty[Snapshot]) } } diff --git a/es810x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala b/es810x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala index a657d15ca9..31d96f15a2 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.services import cats.data.NonEmptyList -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.bulk.{BackoffPolicy, BulkProcessor, BulkRequest, BulkResponse} import org.elasticsearch.action.index.IndexRequest import org.elasticsearch.action.{ActionListener, DocWriteRequest} @@ -39,7 +39,7 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, (using Clock) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { private val bulkProcessor = BulkProcessor @@ -80,25 +80,25 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, private class AuditSinkBulkProcessorListener extends BulkProcessor.Listener { override def beforeBulk(executionId: Long, request: BulkRequest): Unit = { - logger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") + noRequestIdLogger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") } override def afterBulk(executionId: Long, request: BulkRequest, response: BulkResponse): Unit = { if (response.hasFailures) { - logger.error("Some failures flushing the BulkProcessor: ") + noRequestIdLogger.error("Some failures flushing the BulkProcessor: ") response .getItems.to(LazyList) .filter(_.isFailed) .map(_.getFailureMessage) .groupBy(identity) .foreach { case (message, stream) => - logger.error(s"${stream.size}x: $message") + noRequestIdLogger.error(s"${stream.size}x: $message") } } } override def afterBulk(executionId: Long, request: BulkRequest, failure: Throwable): Unit = { - logger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) + noRequestIdLogger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) } } diff --git a/es810x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala b/es810x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala index a8def0ec7a..b3c5593c36 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala @@ -22,7 +22,7 @@ import org.apache.http.auth.{AuthScope, Credentials, UsernamePasswordCredentials import org.apache.http.conn.ssl.NoopHostnameVerifier import org.apache.http.impl.client.BasicCredentialsProvider import org.apache.http.impl.nio.client.HttpAsyncClientBuilder -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.* import org.elasticsearch.client.RestClient.FailureListener import tech.beshu.ror.accesscontrol.audit.sink.AuditDataStreamCreator @@ -38,7 +38,7 @@ import scala.collection.parallel.CollectionConverters.* final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient]) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { override def submit(indexName: IndexName.Full, documentId: String, jsonRecord: String) (implicit requestId: RequestId): Unit = { @@ -77,21 +77,21 @@ final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient] override def onSuccess(response: Response): Unit = { response.getStatusLine.getStatusCode / 100 match { case 2 => // 2xx - logger.debug(s"[${requestId.show}] Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") + logger.debug(s"Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") case _ => - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") } } override def onFailure(ex: Exception): Unit = { - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId]", ex) + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId]", ex) } } override val dataStreamCreator: AuditDataStreamCreator = new AuditDataStreamCreator(clients.map(new RestClientDataStreamService(_))) } -object RestClientAuditSinkService extends Logging { +object RestClientAuditSinkService extends RequestIdAwareLogging { def create(remoteCluster: AuditCluster.RemoteAuditCluster): RestClientAuditSinkService = { remoteCluster.mode match { @@ -122,7 +122,7 @@ object RestClientAuditSinkService extends Logging { .setFailureListener( new FailureListener { override def onFailure(node: Node): Unit = { - logger.debug( + noRequestIdLogger.debug( s"[AUDIT] Node marked dead: ${node.getHost.getSchemeName}://${node.getHost.getHostName}:${node.getHost.getPort}. The client will attempt failover.", ) } diff --git a/es810x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala b/es810x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala index 56afacb5bb..46e39aa197 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.Channel import io.netty.handler.ssl.NotSslRecordException -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.network.NetworkService import org.elasticsearch.common.settings.{ClusterSettings, Settings} import org.elasticsearch.http.netty4.Netty4HttpServerTransport @@ -41,7 +41,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, tracer: Tracer, fipsCompliant: Boolean) extends Netty4HttpServerTransport(settings, networkService, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory, tracer, TLSConfig.noTLS(), null, null) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, ssl.clientAuthenticationEnabled) @@ -49,7 +49,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, override def onException(channel: HttpChannel, cause: Exception): Unit = { if (!this.lifecycle.started) return - else if (cause.getCause.isInstanceOf[NotSslRecordException]) logger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) + else if (cause.getCause.isInstanceOf[NotSslRecordException]) noRequestIdLogger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) else super.onException(channel, cause) channel.close() } diff --git a/es810x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala b/es810x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala index 2fa1d7871c..2d2b0360d4 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.* import io.netty.handler.ssl.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.TransportVersion import org.elasticsearch.cluster.node.DiscoveryNode import org.elasticsearch.common.io.stream.NamedWriteableRegistry @@ -46,7 +46,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, sharedGroupFactory: SharedGroupFactory, fipsCompliant: Boolean) extends Netty4Transport(settings, TransportVersion.current(), threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = SSLCertHelper.prepareClientSSLContext(ssl, fipsCompliant, ssl.certificateVerificationEnabled) private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, clientAuthenticationEnabled = false) @@ -78,7 +78,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, override def exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable): Unit = { if (cause.isInstanceOf[NotSslRecordException] || (cause.getCause != null && cause.getCause.isInstanceOf[NotSslRecordException])) { - logger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") + noRequestIdLogger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") ctx.channel.close } else { super.exceptionCaught(ctx, cause) diff --git a/es810x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala b/es810x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala index 1a8804e4b7..84979960e0 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.utils import cats.Show import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.client.internal.node.NodeClient import org.elasticsearch.rest.* @@ -37,7 +37,7 @@ import java.util import scala.util.Try class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandler) - extends RestHandler with Logging { + extends RestHandler with RequestIdAwareLogging { private val wrapped = doPrivileged { wrapSomeActions(underlying) @@ -103,11 +103,11 @@ class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandle private def logError(error: AuthorizationValueError): Unit = { { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorSanitizedShow - logger.warn(s"The incoming request was malformed. Cause: ${error.show}") + noRequestIdLogger.warn(s"The incoming request was malformed. Cause: ${error.show}") } if (logger.delegate.isDebugEnabled()) { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorWithDetailsShow - logger.debug(s"Malformed request detailed cause: ${error.show}") + noRequestIdLogger.debug(s"Malformed request detailed cause: ${error.show}") } } diff --git a/es810x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala b/es810x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala index 5ab1e35742..a9af8f710a 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala @@ -16,13 +16,13 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.settings.Settings import tech.beshu.ror.tools.core.patches.PatchingVerifier import tech.beshu.ror.tools.core.patches.PatchingVerifier.Error.{CannotVerifyIfPatched, EsNotPatched} import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -object EsPatchVerifier extends Logging { +object EsPatchVerifier extends RequestIdAwareLogging { def verify(settings: Settings): Unit = doPrivileged { pathHomeFrom(settings).flatMap(PatchingVerifier.verify) match { @@ -30,7 +30,7 @@ object EsPatchVerifier extends Logging { case Left(e@EsNotPatched(_)) => throw new IllegalStateException(e.message) case Left(e@CannotVerifyIfPatched(_)) => - logger.warn(e.message) + noRequestIdLogger.warn(e.message) } } diff --git a/es810x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala b/es810x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala index 639aeb5029..893d807108 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.repositories.{RepositoriesService, VerifyNodeRepositoryAction} import org.elasticsearch.transport.{RemoteClusterService, TransportService} import org.joor.Reflect.on @@ -26,7 +26,7 @@ import java.util.function.Supplier import scala.util.{Failure, Success, Try} class RemoteClusterServiceSupplier(repositoriesServiceSupplier: Supplier[RepositoriesService]) - extends Supplier[Option[RemoteClusterService]] with Logging { + extends Supplier[Option[RemoteClusterService]] with RequestIdAwareLogging { override def get(): Option[RemoteClusterService] = { for { @@ -35,7 +35,7 @@ class RemoteClusterServiceSupplier(repositoriesServiceSupplier: Supplier[Reposit case Success(transportService) => Option(transportService.getRemoteClusterService) case Failure(ex) => - logger.error("Cannot extract RemoteClusterService from RepositoriesService", ex) + noRequestIdLogger.error("Cannot extract RemoteClusterService from RepositoriesService", ex) None } } yield remoteClusterService diff --git a/es811x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es811x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index 07d70bbf05..978eebec5d 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.support.{ActionFilter, ActionFilterChain} import org.elasticsearch.action.{ActionListener, ActionRequest, ActionResponse} import org.elasticsearch.client.internal.node.NodeClient @@ -62,7 +62,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, rorEsConfig: ReadonlyRestEsConfig) (implicit environmentConfig: EnvironmentConfig) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = environmentConfig.uniqueIdentifierGenerator @@ -211,12 +211,12 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def handleRorNotReadyYet(esContext: EsContext): Unit = { - logger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") + noRequestIdLogger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") rorNotAvailableRequestHandler.handleRorNotReadyYet(esContext) } private def handleRorFailedToStart(esContext: EsContext): Unit = { - logger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") + noRequestIdLogger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") rorNotAvailableRequestHandler.handleRorFailedToStart(esContext) } @@ -238,7 +238,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def logAndSetStartingFailureState(failure: StartingFailure): Unit = { - logger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) + noRequestIdLogger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) rorInstanceState.set(RorInstanceStartingState.NotStarted(failure)) } } diff --git a/es811x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala b/es811x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala index 1fb22fc79d..53452eb8e6 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.xcontent.LoggingDeprecationHandler import org.elasticsearch.rest.RestResponse import org.elasticsearch.transport.BytesRefRecycler @@ -32,7 +32,7 @@ import tech.beshu.ror.accesscontrol.domain.ResponseFieldsFiltering.{AccessMode, import scala.jdk.CollectionConverters.* trait ResponseFieldsFiltering { - this: Logging => + this: RequestIdAwareLogging => private val responseFieldsRestrictions: Atomic[Option[ResponseFieldsRestrictions]] = Atomic(None: Option[ResponseFieldsRestrictions]) diff --git a/es811x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala b/es811x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala index 0f26750588..da95de59a4 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.action.{ActionListener, ActionResponse} import org.elasticsearch.threadpool.ThreadPool @@ -37,7 +37,7 @@ sealed abstract class RorActionListener[T](val underlying: ActionListener[T]) ex final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionListener[T], correlationId: Eval[CorrelationId]) - extends RorActionListener[T](underlying) with Logging { + extends RorActionListener[T](underlying) with RequestIdAwareLogging { override def onFailure(e: Exception): Unit = { super.onFailure(adaptExceptionIfNeeded(e)) @@ -47,7 +47,7 @@ final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionLis ex match { case esException: ElasticsearchException => esException case other => - logger.error(s"[${correlationId.value.show}] Internal error.", other) + noRequestIdLogger.error(s"[${correlationId.value.show}] Internal error.", other) new ElasticsearchException(s"[${correlationId.value.show}] Internal error. See logs for details.") } } diff --git a/es811x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala b/es811x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala index 75048ebe7d..14e5e31c1b 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.http.HttpChannel import org.elasticsearch.rest.{AbstractRestChannel, RestChannel as EsRestChannel, RestRequest as EsRestRequest, RestResponse as EsRestResponse} import squants.information.{Bytes, Information} @@ -40,7 +40,7 @@ object RorRestChannel { final class RorRestChannel private(underlying: EsRestChannel, val restRequest: RorRestRequest) extends AbstractRestChannel(underlying.request(), true) with ResponseFieldsFiltering - with Logging { + with RequestIdAwareLogging { override def sendResponse(response: EsRestResponse): Unit = { ThreadRepo.removeRestChannel(this) diff --git a/es811x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala b/es811x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala index 6babc712b9..3c80750a25 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala @@ -18,16 +18,15 @@ package tech.beshu.ror.es.actions.rradmin import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.ConfigApi.ConfigResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAdminActionHandler extends Logging { +class RRAdminActionHandler extends RequestIdAwareLogging { private implicit val adminRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +51,7 @@ class RRAdminActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAdminResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAdminAction internal error", ex) + logger.error("RRAdminAction internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es811x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala b/es811x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala index c55835a1d0..ce45c6f48e 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala @@ -16,18 +16,15 @@ */ package tech.beshu.ror.es.actions.rrauthmock -import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.AuthMockApi.AuthMockResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier -import tech.beshu.ror.implicits.* +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAuthMockActionHandler extends Logging { +class RRAuthMockActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -53,7 +50,7 @@ class RRAuthMockActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAuthMockResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAuthMock internal error", ex) + logger.error("RRAuthMock internal error", ex) listener.onFailure(new Exception(ex)) } } diff --git a/es811x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala b/es811x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala index aa8bb31e67..640084c4ec 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestconfig import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.TestConfigApi.TestConfigResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestConfigActionHandler extends Logging { +class RRTestConfigActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +52,7 @@ class RRTestConfigActionHandler extends Logging { case Right(response) => listener.onResponse(new RRTestConfigResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRTestConfig internal error", ex) + logger.error(s"RRTestConfig internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es811x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala b/es811x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala index 494e9150b4..98cc0c945d 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.dlsfls import cats.data.StateT import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.DirectoryReader import org.elasticsearch.common.util.concurrent.ThreadContext import org.elasticsearch.core.CheckedFunction @@ -31,7 +31,7 @@ import java.io.IOException import java.util.function.{Function => JavaFunction} import scala.util.{Failure, Success, Try} -object RoleIndexSearcherWrapper extends Logging { +object RoleIndexSearcherWrapper extends RequestIdAwareLogging { val instance: JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] = new JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] { @@ -54,7 +54,7 @@ object RoleIndexSearcherWrapper extends Logging { } .map(r => (r, r)) case None => - logger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") + noRequestIdLogger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") Success((reader, reader)) } } @@ -66,13 +66,13 @@ object RoleIndexSearcherWrapper extends Logging { nel <- NonEmptyString.from(value) match { case Right(nel) => Success(nel) case Left(_) => - logger.debug("FLS: empty header value") + noRequestIdLogger.debug("FLS: empty header value") failure } fields <- transientFieldsFromHeaderValue.fromRawValue(nel) match { case result@Success(_) => result case Failure(ex) => - logger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) + noRequestIdLogger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) failure } } yield fields diff --git a/es811x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala b/es811x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala index ce77d77f4e..aeccbfcead 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.dlsfls import com.google.common.collect.Iterators -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.codecs.StoredFieldsReader import org.apache.lucene.index.* import org.apache.lucene.index.StoredFieldVisitor.Status @@ -39,21 +39,21 @@ import scala.jdk.CollectionConverters.* import scala.util.Try private class RorDocumentFieldReader(reader: LeafReader, fieldsRestrictions: FieldsRestrictions) - extends SequentialStoredFieldsLeafReader(reader) with Logging { + extends SequentialStoredFieldsLeafReader(reader) with RequestIdAwareLogging { private val policy = new FieldsPolicy(fieldsRestrictions) private val remainingFieldsInfo = { val fInfos = in.getFieldInfos val newInfos = if (fInfos.asScala.isEmpty) { - logger.warn("original fields were empty! This is weird!") + noRequestIdLogger.warn("original fields were empty! This is weird!") fInfos } else { val remainingFields = fInfos.asScala.filter(f => policy.canKeep(f.name)).toSet new FieldInfos(remainingFields.toArray) } - logger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") - logger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") - logger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") + noRequestIdLogger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") newInfos } private val jsonPolicyBasedFilterer = new JsonPolicyBasedFilterer(policy) diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala index e0475ee3bc..d0532cd3db 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.* import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest import org.elasticsearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest @@ -87,7 +87,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, threadPool: ThreadPool) (implicit generator: UniqueIdentifierGenerator, scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle(engines: Engines, esContext: EsContext): Task[Either[Error, Unit]] = { @@ -243,7 +243,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, case SearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case MultiSearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case _ => - logger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") + noRequestIdLogger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") regularRequestHandler.handle(new DummyCompositeIndicesEsRequestContext(request, esContext, aclContext, clusterService, threadPool)) } // rest diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala index cab02aff37..100edd72ac 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.common.io.stream.StreamOutput import org.elasticsearch.xcontent.{ToXContent, ToXContentObject, XContentBuilder} @@ -45,7 +45,7 @@ import scala.util.{Failure, Success, Try} class CurrentUserMetadataRequestHandler(engine: Engine, esContext: EsContext) - extends Logging { + extends RequestIdAwareLogging { def handle(request: RequestContext.Aux[CurrentUserMetadataRequestBlockContext] with EsRequest[CurrentUserMetadataRequestBlockContext]): Task[Unit] = { engine.core.accessControl @@ -69,7 +69,7 @@ class CurrentUserMetadataRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(ex.asInstanceOf[Exception]) } } @@ -86,13 +86,13 @@ class CurrentUserMetadataRequestHandler(engine: Engine, )) } - private def onPassThrough(requestContext: RequestContext): Unit = { - logger.warn(s"[${requestContext.id.toRequestId.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") + private def onPassThrough(implicit requestContext: RequestContext): Unit = { + logger.warn(s"Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") esContext.listener.onFailure(createRorNotEnabledResponse()) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala index 2fb01dcc41..c5c44fda92 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala @@ -20,7 +20,7 @@ import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.RegularRequestResult @@ -49,7 +49,7 @@ class RegularRequestHandler(engine: Engine, esContext: EsContext, threadPool: ThreadPool) (implicit scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle[B <: BlockContext : BlockContextUpdater](request: RequestContext.Aux[B] with EsRequest[B]): Task[Unit] = { engine.core.accessControl @@ -85,7 +85,7 @@ class RegularRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(new Exception(ex)) } } @@ -99,7 +99,7 @@ class RegularRequestHandler(engine: Engine, case ModificationResult.ShouldBeInterrupted => onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case ModificationResult.CannotModify => - logger.error(s"[${request.id.toRequestId.show}] Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") + noRequestIdLogger.error(s"Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case CustomResponse(response) => respond(request, response) @@ -247,7 +247,7 @@ class RegularRequestHandler(engine: Engine, esContext.listener.onResponse(response) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } \ No newline at end of file diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala index f4f832dedc..bfc421bdd5 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.index.query.{AbstractQueryBuilder, QueryBuilder, QueryBuilders} import org.elasticsearch.search.aggregations.AggregatorFactories @@ -40,7 +40,7 @@ import tech.beshu.ror.implicits.* import java.util.UUID import scala.jdk.CollectionConverters.* -object SearchRequestOps extends Logging { +object SearchRequestOps extends RequestIdAwareLogging { implicit class QueryBuilderOps(val builder: Option[QueryBuilder]) extends AnyVal { @@ -52,7 +52,7 @@ object SearchRequestOps extends Logging { val modifiedQuery: AbstractQueryBuilder[_] = provideNewQueryWithAppliedFilter(builder, filterQuery) Some(modifiedQuery) case None => - logger.debug(s"[${requestId.show}] No filter applied to query.") + logger.debug(s"No filter applied to query.") builder } } @@ -92,7 +92,7 @@ object SearchRequestOps extends Logging { case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, requestId) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) disableCaching(requestId) case BasedOnBlockContextOnly.NotAllowedFieldsUsed(notAllowedFields) => modifyNotAllowedFieldsInRequest(notAllowedFields) @@ -138,8 +138,8 @@ object SearchRequestOps extends Logging { } } - private def disableCaching(requestId: RequestContext.Id) = { - logger.debug(s"[${requestId.show}] ACL uses context header for fields rule, will disable request cache for SearchRequest") + private def disableCaching(implicit requestId: RequestContext.Id) = { + logger.debug(s"ACL uses context header for fields rule, will disable request cache for SearchRequest") request.requestCache(false) } } diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala index 270367a54f..e2884598df 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala @@ -17,7 +17,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.action.support.IndicesOptions.WildcardStates import org.elasticsearch.action.{CompositeIndicesRequest, IndicesRequest} @@ -34,7 +33,7 @@ import scala.jdk.CollectionConverters.* abstract class BaseEsRequestContext[B <: BlockContext](esContext: EsContext, clusterService: RorClusterService) - extends RequestContext with Logging { + extends RequestContext { override type BLOCK_CONTEXT = B diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala index ae8abbe1f5..0ee2967364 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala @@ -18,7 +18,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -26,8 +25,9 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import scala.util.Try +import tech.beshu.ror.utils.RequestIdAwareLogging -trait EsRequest[B <: BlockContext] extends Logging { +trait EsRequest[B <: BlockContext] extends RequestIdAwareLogging { implicit def threadPool: ThreadPool final def modifyUsing(blockContext: B): ModificationResult = { @@ -35,7 +35,7 @@ trait EsRequest[B <: BlockContext] extends Logging { Try(modifyRequest(blockContext)) .fold( ex => { - logger.error(s"[${blockContext.requestContext.id.show}] Cannot modify request with filtered data", ex) + logger.error(s"Cannot modify request with filtered data", ex)(blockContext) ModificationResult.CannotModify }, identity diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala index c6a9dcbefd..f773b3efb1 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala @@ -51,7 +51,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest private def discoverDataStreams() = { val dataStreams = dataStreamsFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered data streams: ${dataStreams.show}") + logger.debug(s"Discovered data streams: ${dataStreams.show}") dataStreams } @@ -59,7 +59,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest val backingIndices = backingIndicesFrom(actionRequest) backingIndices match { case BackingIndices.IndicesInvolved(filteredIndices, _) => - logger.debug(s"[${id.show}] Discovered indices: ${filteredIndices.show}") + logger.debug(s"Discovered indices: ${filteredIndices.show}") case BackingIndices.IndicesNotInvolved => } backingIndices diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala index c091179cb6..d150709314 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala @@ -85,7 +85,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: case Some(indices) => update(actionRequest, indices, blockContext.filter, blockContext.fieldLevelSecurity) case None => - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -101,7 +101,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } \ No newline at end of file diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala index 71d462de57..48014e1bdc 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala @@ -73,7 +73,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, } yield update(actionRequest, filteredIndices, allAllowedIndices) result.getOrElse { - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -86,7 +86,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala index 95d882c3b5..f607c0e347 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala @@ -50,7 +50,7 @@ abstract class BaseRepositoriesEsRequestContext[R <: ActionRequest](actionReques case Some(repositories) => update(actionRequest, repositories) case None => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") ShouldBeInterrupted } } diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala index b3b1d66238..7ef0f32014 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala @@ -42,7 +42,7 @@ abstract class BaseSingleIndexEsRequestContext[R <: ActionRequest](actionRequest filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } update(request, filteredIndices.head) } diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala index b5ab70fe7a..c1b2e7ea27 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala @@ -62,7 +62,7 @@ class BulkEsRequestContext(actionRequest: BulkRequest, case (_, _) => ShouldBeInterrupted } } else { - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because origin request contained different " + + logger.error(s"Cannot alter MultiGetRequest request, because origin request contained different " + s"number of requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } @@ -90,18 +90,18 @@ class BulkEsRequestContext(actionRequest: BulkRequest, updateRequestWithIndices(request, nel) Modified case None => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because empty list of indices was found") + logger.error(s"Cannot alter MultiGetRequest request, because empty list of indices was found") ShouldBeInterrupted } case Indices.NotFound => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because no allowed indices were found") + logger.error(s"Cannot alter MultiGetRequest request, because no allowed indices were found") ShouldBeInterrupted } } private def updateRequestWithIndices(request: DocWriteRequest[_], indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } request.index(indices.head.stringify) } diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala index 75a75fcef5..96a043b298 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala @@ -53,14 +53,14 @@ class BulkShardEsRequestContext(actionRequest: BulkShardRequest, case Success(_) => Modified case Failure(ex) => - logger.error(s"[${id.show}] Cannot modify BulkShardRequest", ex) + logger.error(s"Cannot modify BulkShardRequest", ex) CannotModify } } private def tryUpdate(request: BulkShardRequest, indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } val singleIndex = indices.head val uuid = clusterService.indexOrAliasUuids(singleIndex.name).toList.head diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala index 65a168092a..158ac485a5 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala @@ -45,14 +45,14 @@ class ClusterAllocationExplainEsRequestContext(actionRequest: ClusterAllocationE getRequestedIndexFrom(request) match { case Some(_) => if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateIndexIn(request, filteredIndices.head) Modified case None if filteredIndices.exists(_.name === ClusterIndexName.Local.wildcard) => Modified case None => - logger.error(s"[${id.show}] Cluster allocation explain request without index name is unavailable when block contains `indices` rule") + logger.error(s"Cluster allocation explain request without index name is unavailable when block contains `indices` rule") ShouldBeInterrupted } } diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala index 61fdab9d83..5bf09449c5 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala @@ -79,7 +79,7 @@ class EsqlIndicesEsRequestContext private(actionRequest: ActionRequest with Comp request } case Left(ClassificationError.ParsingException(ex)) => - logger.debug(s"[${id.show}] Cannot parse ESQL statement - we can pass it though, because ES is going to reject it. Cause:", ex) + logger.debug(s"Cannot parse ESQL statement - we can pass it though, because ES is going to reject it. Cause:", ex) request } } @@ -90,7 +90,7 @@ class EsqlIndicesEsRequestContext private(actionRequest: ActionRequest with Comp case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala index 5778b8968d..02dec730ed 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala @@ -66,7 +66,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, updateAliases(actionRequest, aliases) UpdateResponse.sync(updateAliasesResponse(aliases.includedOnly, _)) case None => - logger.error(s"[${id.show}] At least one alias and one index has to be allowed. " + + logger.error(s"At least one alias and one index has to be allowed. " + s"Found allowed indices: [${blockContext.indices.show}]." + s"Found allowed aliases: [${blockContext.aliases.show}]") ShouldBeInterrupted @@ -114,7 +114,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, .indices().asSafeSet .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } @@ -122,7 +122,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, val aliases = rawRequestAliasesSet(request) .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered aliases: ${aliases.show}") + logger.debug(s"Discovered aliases: ${aliases.show}") aliases } diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala index abb85d42b7..f9e2c87e53 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala @@ -55,7 +55,7 @@ class IndicesAliasesEsRequestContext(actionRequest: IndicesAliasesRequest, if (originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala index 05b70606b9..37dd50452b 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala @@ -119,7 +119,7 @@ class MultiGetEsRequestContext(actionRequest: MultiGetRequest, case Nil => updateItemWithNonExistingIndex(item) case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } item.index(index.stringify) } diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala index 989956d79a..9e13edee8d 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala @@ -78,7 +78,7 @@ class MultiSearchEsRequestContext(actionRequest: MultiSearchRequest, } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala index 9191e33b66..5a61356f48 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala @@ -47,7 +47,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { request.getRequests.removeIf { request => removeOrAlter(request, filteredIndices.toCovariantSet) } if (request.getRequests.asScala.isEmpty) { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") ShouldBeInterrupted } else { Modified @@ -63,7 +63,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, true case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") } request.index(index.stringify) false diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala index c411df93c5..c7b99f6e85 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala @@ -52,7 +52,7 @@ class PutRollupJobEsRequestContext private(actionRequest: ActionRequest, if(originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala index 141d9db788..fff8ed58bb 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala @@ -49,7 +49,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (tryUpdate(actionRequest, filteredIndices)) Modified else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") ShouldBeInterrupted } } diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala index 489d0187bc..c42dfc3b78 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala @@ -58,10 +58,10 @@ class ReindexEsRequestContext(actionRequest: ReindexRequest, Modified } else { if (!isDestinationIndexOnFilteredIndicesList) { - logger.info(s"[${id.show}] Destination index of _reindex request is forbidden") + logger.info(s"Destination index of _reindex request is forbidden") } if (!isSearchRequestComposedOnlyOfAllowedIndices) { - logger.info(s"[${id.show}] At least one index from sources indices list of _reindex request is forbidden") + logger.info(s"At least one index from sources indices list of _reindex request is forbidden") } ShouldBeInterrupted } diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala index 2c1b0014e0..97b8ccd9c5 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala @@ -74,7 +74,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo request } case Left(_) => - logger.debug(s"[${id.show}] Cannot parse SQL statement - we can pass it though, because ES is going to reject it") + logger.debug(s"Cannot parse SQL statement - we can pass it though, because ES is going to reject it") request } } @@ -85,7 +85,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala index 0c67384c1e..d7e743e648 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CleanupRepositoryEsRequestContext(actionRequest: CleanupRepositoryRequest, override protected def update(request: CleanupRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala index 44b7d78dfd..d09015139b 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CreateRepositoryEsRequestContext(actionRequest: PutRepositoryRequest, override protected def update(request: PutRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala index eaf9334872..0cf32e1bea 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class DeleteRepositoryEsRequestContext(actionRequest: DeleteRepositoryRequest, override protected def update(request: DeleteRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala index cee0bffd4c..d1410eff3d 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class VerifyRepositoryEsRequestContext(actionRequest: VerifyRepositoryRequest, override protected def update(request: VerifyRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala index ead4fcf250..20501516d5 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala @@ -68,32 +68,32 @@ class CreateSnapshotEsRequestContext(actionRequest: CreateSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala index a56aba660e..621d744767 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala @@ -60,7 +60,7 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -71,14 +71,14 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, .toRight(()) } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala index 22869bbb4f..b81f333174 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala @@ -68,7 +68,7 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, case r => r } case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala index 88887db96c..156deb5b80 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala @@ -63,7 +63,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -75,7 +75,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") } Right(snapshot) } @@ -88,7 +88,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala index 44ee8397ec..e522e440f1 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala @@ -100,12 +100,12 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { val repositories = blockContext.repositories if (allRepositoriesRequested(repositories)) { Right(RepositoryName.All) @@ -115,7 +115,7 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala index 80e36a6d77..d8e5182eed 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.GetComposableIndexTemplateAction import org.elasticsearch.cluster.metadata import org.elasticsearch.cluster.metadata.ComposableIndexTemplate @@ -108,7 +108,7 @@ class GetComposableIndexTemplateEsRequestContext(actionRequest: GetComposableInd } -private[templates] object GetComposableIndexTemplateEsRequestContext extends Logging { +private[templates] object GetComposableIndexTemplateEsRequestContext extends RequestIdAwareLogging { def filter(templates: Map[String, ComposableIndexTemplate], usingTemplate: Set[Template] => Set[Template]) diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala index bd74c3a18f..1c6eecf409 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.{GetIndexTemplatesRequest, GetIndexTemplatesResponse} import org.elasticsearch.cluster.metadata.{AliasMetadata, IndexTemplateMetadata} import org.elasticsearch.common.collect.ImmutableOpenMap @@ -104,7 +104,7 @@ class GetTemplatesEsRequestContext(actionRequest: GetIndexTemplatesRequest, } -private[templates] object GetTemplatesEsRequestContext extends Logging { +private[templates] object GetTemplatesEsRequestContext extends RequestIdAwareLogging { def filter(templates: Iterable[IndexTemplateMetadata], usingTemplate: Set[Template] => Set[Template]) diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala index a8951de5b1..32116d8212 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala @@ -72,7 +72,7 @@ class MultiSearchTemplateEsRequestContext private(actionRequest: ActionRequest w } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala index e6f6d8916e..434787a686 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala @@ -55,7 +55,7 @@ class SimulateIndexTemplateRequestEsRequestContext(actionRequest: SimulateIndexT filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateRequest(request, filteredIndices.head, allAllowedIndices) } diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala index fbc4cf6776..46ed6e7a95 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala @@ -109,7 +109,7 @@ class SimulateExistingTemplateRequestEsRequestContext(existingTemplateName: Temp case Some(_) => updateResponse(namePatterns.toList, blockContext.allAllowedIndices.toList) case None => - logger.info(s"[${id.show}] User has no access to template ${existingTemplateName.show}") + logger.info(s"User has no access to template ${existingTemplateName.show}") ModificationResult.ShouldBeInterrupted } case other => diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala index 0ecd7a72b3..fe4d60bd42 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.queries import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.index.query.* import org.joor.Reflect.on import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.RequestFieldsUsage @@ -30,7 +30,7 @@ trait QueryFieldsUsage[QUERY <: QueryBuilder] { def fieldsIn(query: QUERY): RequestFieldsUsage } -object QueryFieldsUsage extends Logging { +object QueryFieldsUsage extends RequestIdAwareLogging { def apply[QUERY <: QueryBuilder](implicit ev: QueryFieldsUsage[QUERY]): QueryFieldsUsage[QUERY] = ev implicit class Ops[QUERY <: QueryBuilder : QueryFieldsUsage](val query: QUERY) { @@ -62,7 +62,7 @@ object QueryFieldsUsage extends Logging { Option(on(query).call("getFieldName").get[String]) match { case Some(fieldName: String) => UsingFields(NonEmptyList.one(UsedField(fieldName))) case _ => - logger.debug(s"Cannot extract fields for terms set query") + noRequestIdLogger.debug(s"Cannot extract fields for terms set query") CannotExtractFields } } @@ -89,7 +89,7 @@ object QueryFieldsUsage extends Logging { case builder: TermsSetQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder: WildcardQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder => - logger.debug(s"Cannot extract fields for query: ${builder.getName}") + noRequestIdLogger.debug(s"Cannot extract fields for query: ${builder.getName}") CannotExtractFields } diff --git a/es811x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala b/es811x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala index 0998bb9a5b..b4671e9e4d 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.handler.response import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.FieldsRestrictions import tech.beshu.ror.accesscontrol.domain.Header @@ -26,17 +26,17 @@ import tech.beshu.ror.accesscontrol.headerValues.transientFieldsToHeaderValue import tech.beshu.ror.accesscontrol.request.RequestContext import tech.beshu.ror.implicits.* -object FLSContextHeaderHandler extends Logging { +object FLSContextHeaderHandler extends RequestIdAwareLogging { def addContextHeader(threadPool: ThreadPool, - fieldsRestrictions: FieldsRestrictions, - requestId: RequestContext.Id): Unit = { + fieldsRestrictions: FieldsRestrictions) + (implicit requestId: RequestContext.Id): Unit = { val threadContext = threadPool.getThreadContext val header = createContextHeader(fieldsRestrictions) Option(threadContext.getHeader(header.name.value.value)) match { case None => implicit val show = headerShow - logger.debug(s"[${requestId.show}] Adding thread context header required by lucene. Header: '${header.show}'") + logger.debug(s"Adding thread context header required by lucene. Header: '${header.show}'") threadContext.putHeader(header.name.value.value, header.value.value) case Some(_) => } diff --git a/es811x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala b/es811x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala index 629696a91d..7aa2029a2a 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.admin.indices.template.get.{GetComponentTemplateAction, GetComposableIndexTemplateAction} import org.elasticsearch.action.admin.indices.template.put.{PutComponentTemplateAction, PutComposableIndexTemplateAction} @@ -46,7 +46,7 @@ import scala.jdk.CollectionConverters.* final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJsonParserFactory)(using Clock) extends DataStreamService - with Logging { + with RequestIdAwareLogging { override def checkDataStreamExists(dataStreamName: DataStreamName.Full): Task[Boolean] = execute { val request = new GetDataStreamAction.Request(List(dataStreamName.value.value).toArray) @@ -203,11 +203,11 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ response <- Task.measure( task = Task.delay(nodeClient.execute(action, request).actionGet()), logTimeMeasurement = duration => Task.delay { - logger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") + noRequestIdLogger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") } ) _ <- Task.delay { - logger.debug(s"Action ${action.name()} response: ${response.toString}") + noRequestIdLogger.debug(s"Action ${action.name()} response: ${response.toString}") } } yield response } @@ -215,7 +215,7 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ def executeAck[REQUEST <: ActionRequest, RESPONSE <: AcknowledgedResponse](action: ActionType[RESPONSE], request: REQUEST): Task[RESPONSE] = { executeT(action, request) - .tapEval(response => Task.delay(logger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) + .tapEval(response => Task.delay(noRequestIdLogger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) } private def supportedActions: Map[ActionType[ActionResponse], TransportAction[ActionRequest, ActionResponse]] = { diff --git a/es811x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala b/es811x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala index 2e75d37d0f..16259474bf 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.support.WriteRequest.RefreshPolicy import org.elasticsearch.client.internal.node.NodeClient @@ -38,7 +38,7 @@ import scala.jdk.CollectionConverters.* class EsIndexJsonContentService(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexJsonContentService - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -63,14 +63,14 @@ class EsIndexJsonContentService(client: NodeClient, Option(response.getSourceAsMap) match { case Some(map) => val source = map.asScala.toMap.asStringMap - logger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") Right(source) case None => - logger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") + noRequestIdLogger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") Right(Map.empty[String, String]) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(ContentNotFound) } } @@ -78,7 +78,7 @@ class EsIndexJsonContentService(client: NodeClient, .onErrorRecover { case _: ResourceNotFoundException => Left(ContentNotFound) case ex => - logger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) Left(CannotReachContentSource) } } @@ -104,14 +104,14 @@ class EsIndexJsonContentService(client: NodeClient, case status if status / 100 == 2 => Right(()) case status => - logger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") Left(CannotWriteToIndex) } } .executeOn(RorSchedulers.blockingScheduler) .onErrorRecover { case ex => - logger.error(s"Cannot write to document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]", ex) Left(CannotWriteToIndex) } } diff --git a/es811x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala b/es811x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala index 1429c7405a..c27d4ec9d5 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala @@ -22,7 +22,7 @@ import cats.kernel.Monoid import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task import monix.execution.{CancelablePromise, Scheduler} -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction.{ResolvedAlias, ResolvedIndex} @@ -64,7 +64,7 @@ class EsServerBasedRorClusterService(nodeName: String, threadPool: ThreadPool) (implicit val scheduler: Scheduler) extends RorClusterService - with Logging { + with RequestIdAwareLogging { import EsServerBasedRorClusterService.* @@ -155,7 +155,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractAccessibilityFrom) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify get request. Blocking document", ex) + logger.error(s"Could not verify get request. Blocking document", ex)(id) Inaccessible } } @@ -167,7 +167,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractResultsFromSearchResponse) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify documents returned by multi get response. Blocking all returned documents", ex) + logger.error(s"Could not verify documents returned by multi get response. Blocking all returned documents", ex)(id) blockAllDocsReturned(documents) } .map(results => zip(results, documents)) @@ -276,7 +276,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService): Task[List[FullRemoteDataStreamWithAliases]] = { getRemoteClusterClient(remoteClusterService, remoteClusterName) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -332,7 +332,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService) = { getRemoteClusterClient(remoteClusterService, remoteClusterName) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -423,7 +423,7 @@ class EsServerBasedRorClusterService(nodeName: String, } } case None => - logger.error("Cannot supply Snapshots Service. Please, report the issue!!!") + noRequestIdLogger.error("Cannot supply Snapshots Service. Please, report the issue!!!") Task.now(Set.empty[Snapshot]) } } diff --git a/es811x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala b/es811x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala index a657d15ca9..31d96f15a2 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.services import cats.data.NonEmptyList -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.bulk.{BackoffPolicy, BulkProcessor, BulkRequest, BulkResponse} import org.elasticsearch.action.index.IndexRequest import org.elasticsearch.action.{ActionListener, DocWriteRequest} @@ -39,7 +39,7 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, (using Clock) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { private val bulkProcessor = BulkProcessor @@ -80,25 +80,25 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, private class AuditSinkBulkProcessorListener extends BulkProcessor.Listener { override def beforeBulk(executionId: Long, request: BulkRequest): Unit = { - logger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") + noRequestIdLogger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") } override def afterBulk(executionId: Long, request: BulkRequest, response: BulkResponse): Unit = { if (response.hasFailures) { - logger.error("Some failures flushing the BulkProcessor: ") + noRequestIdLogger.error("Some failures flushing the BulkProcessor: ") response .getItems.to(LazyList) .filter(_.isFailed) .map(_.getFailureMessage) .groupBy(identity) .foreach { case (message, stream) => - logger.error(s"${stream.size}x: $message") + noRequestIdLogger.error(s"${stream.size}x: $message") } } } override def afterBulk(executionId: Long, request: BulkRequest, failure: Throwable): Unit = { - logger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) + noRequestIdLogger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) } } diff --git a/es811x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala b/es811x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala index a8def0ec7a..b3c5593c36 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala @@ -22,7 +22,7 @@ import org.apache.http.auth.{AuthScope, Credentials, UsernamePasswordCredentials import org.apache.http.conn.ssl.NoopHostnameVerifier import org.apache.http.impl.client.BasicCredentialsProvider import org.apache.http.impl.nio.client.HttpAsyncClientBuilder -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.* import org.elasticsearch.client.RestClient.FailureListener import tech.beshu.ror.accesscontrol.audit.sink.AuditDataStreamCreator @@ -38,7 +38,7 @@ import scala.collection.parallel.CollectionConverters.* final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient]) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { override def submit(indexName: IndexName.Full, documentId: String, jsonRecord: String) (implicit requestId: RequestId): Unit = { @@ -77,21 +77,21 @@ final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient] override def onSuccess(response: Response): Unit = { response.getStatusLine.getStatusCode / 100 match { case 2 => // 2xx - logger.debug(s"[${requestId.show}] Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") + logger.debug(s"Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") case _ => - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") } } override def onFailure(ex: Exception): Unit = { - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId]", ex) + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId]", ex) } } override val dataStreamCreator: AuditDataStreamCreator = new AuditDataStreamCreator(clients.map(new RestClientDataStreamService(_))) } -object RestClientAuditSinkService extends Logging { +object RestClientAuditSinkService extends RequestIdAwareLogging { def create(remoteCluster: AuditCluster.RemoteAuditCluster): RestClientAuditSinkService = { remoteCluster.mode match { @@ -122,7 +122,7 @@ object RestClientAuditSinkService extends Logging { .setFailureListener( new FailureListener { override def onFailure(node: Node): Unit = { - logger.debug( + noRequestIdLogger.debug( s"[AUDIT] Node marked dead: ${node.getHost.getSchemeName}://${node.getHost.getHostName}:${node.getHost.getPort}. The client will attempt failover.", ) } diff --git a/es811x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala b/es811x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala index ce17639c06..b18c4fbfee 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.Channel import io.netty.handler.ssl.NotSslRecordException -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.network.NetworkService import org.elasticsearch.common.settings.{ClusterSettings, Settings} import org.elasticsearch.http.netty4.Netty4HttpServerTransport @@ -41,7 +41,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, tracer: Tracer, fipsCompliant: Boolean) extends Netty4HttpServerTransport(settings, networkService, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory, tracer, TLSConfig.noTLS(), null, null) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, ssl.clientAuthenticationEnabled) @@ -49,7 +49,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, override def onException(channel: HttpChannel, cause: Exception): Unit = { if (!this.lifecycle.started) return - else if (cause.getCause.isInstanceOf[NotSslRecordException]) logger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) + else if (cause.getCause.isInstanceOf[NotSslRecordException]) noRequestIdLogger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) else super.onException(channel, cause) channel.close() } diff --git a/es811x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala b/es811x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala index 2fa1d7871c..2d2b0360d4 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.* import io.netty.handler.ssl.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.TransportVersion import org.elasticsearch.cluster.node.DiscoveryNode import org.elasticsearch.common.io.stream.NamedWriteableRegistry @@ -46,7 +46,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, sharedGroupFactory: SharedGroupFactory, fipsCompliant: Boolean) extends Netty4Transport(settings, TransportVersion.current(), threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = SSLCertHelper.prepareClientSSLContext(ssl, fipsCompliant, ssl.certificateVerificationEnabled) private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, clientAuthenticationEnabled = false) @@ -78,7 +78,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, override def exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable): Unit = { if (cause.isInstanceOf[NotSslRecordException] || (cause.getCause != null && cause.getCause.isInstanceOf[NotSslRecordException])) { - logger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") + noRequestIdLogger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") ctx.channel.close } else { super.exceptionCaught(ctx, cause) diff --git a/es811x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala b/es811x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala index 1a8804e4b7..84979960e0 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.utils import cats.Show import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.client.internal.node.NodeClient import org.elasticsearch.rest.* @@ -37,7 +37,7 @@ import java.util import scala.util.Try class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandler) - extends RestHandler with Logging { + extends RestHandler with RequestIdAwareLogging { private val wrapped = doPrivileged { wrapSomeActions(underlying) @@ -103,11 +103,11 @@ class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandle private def logError(error: AuthorizationValueError): Unit = { { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorSanitizedShow - logger.warn(s"The incoming request was malformed. Cause: ${error.show}") + noRequestIdLogger.warn(s"The incoming request was malformed. Cause: ${error.show}") } if (logger.delegate.isDebugEnabled()) { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorWithDetailsShow - logger.debug(s"Malformed request detailed cause: ${error.show}") + noRequestIdLogger.debug(s"Malformed request detailed cause: ${error.show}") } } diff --git a/es811x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala b/es811x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala index 5ab1e35742..a9af8f710a 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala @@ -16,13 +16,13 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.settings.Settings import tech.beshu.ror.tools.core.patches.PatchingVerifier import tech.beshu.ror.tools.core.patches.PatchingVerifier.Error.{CannotVerifyIfPatched, EsNotPatched} import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -object EsPatchVerifier extends Logging { +object EsPatchVerifier extends RequestIdAwareLogging { def verify(settings: Settings): Unit = doPrivileged { pathHomeFrom(settings).flatMap(PatchingVerifier.verify) match { @@ -30,7 +30,7 @@ object EsPatchVerifier extends Logging { case Left(e@EsNotPatched(_)) => throw new IllegalStateException(e.message) case Left(e@CannotVerifyIfPatched(_)) => - logger.warn(e.message) + noRequestIdLogger.warn(e.message) } } diff --git a/es811x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala b/es811x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala index 639aeb5029..893d807108 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.repositories.{RepositoriesService, VerifyNodeRepositoryAction} import org.elasticsearch.transport.{RemoteClusterService, TransportService} import org.joor.Reflect.on @@ -26,7 +26,7 @@ import java.util.function.Supplier import scala.util.{Failure, Success, Try} class RemoteClusterServiceSupplier(repositoriesServiceSupplier: Supplier[RepositoriesService]) - extends Supplier[Option[RemoteClusterService]] with Logging { + extends Supplier[Option[RemoteClusterService]] with RequestIdAwareLogging { override def get(): Option[RemoteClusterService] = { for { @@ -35,7 +35,7 @@ class RemoteClusterServiceSupplier(repositoriesServiceSupplier: Supplier[Reposit case Success(transportService) => Option(transportService.getRemoteClusterService) case Failure(ex) => - logger.error("Cannot extract RemoteClusterService from RepositoriesService", ex) + noRequestIdLogger.error("Cannot extract RemoteClusterService from RepositoriesService", ex) None } } yield remoteClusterService diff --git a/es812x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es812x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index 07d70bbf05..978eebec5d 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.support.{ActionFilter, ActionFilterChain} import org.elasticsearch.action.{ActionListener, ActionRequest, ActionResponse} import org.elasticsearch.client.internal.node.NodeClient @@ -62,7 +62,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, rorEsConfig: ReadonlyRestEsConfig) (implicit environmentConfig: EnvironmentConfig) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = environmentConfig.uniqueIdentifierGenerator @@ -211,12 +211,12 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def handleRorNotReadyYet(esContext: EsContext): Unit = { - logger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") + noRequestIdLogger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") rorNotAvailableRequestHandler.handleRorNotReadyYet(esContext) } private def handleRorFailedToStart(esContext: EsContext): Unit = { - logger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") + noRequestIdLogger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") rorNotAvailableRequestHandler.handleRorFailedToStart(esContext) } @@ -238,7 +238,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def logAndSetStartingFailureState(failure: StartingFailure): Unit = { - logger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) + noRequestIdLogger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) rorInstanceState.set(RorInstanceStartingState.NotStarted(failure)) } } diff --git a/es812x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala b/es812x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala index 1fb22fc79d..53452eb8e6 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.xcontent.LoggingDeprecationHandler import org.elasticsearch.rest.RestResponse import org.elasticsearch.transport.BytesRefRecycler @@ -32,7 +32,7 @@ import tech.beshu.ror.accesscontrol.domain.ResponseFieldsFiltering.{AccessMode, import scala.jdk.CollectionConverters.* trait ResponseFieldsFiltering { - this: Logging => + this: RequestIdAwareLogging => private val responseFieldsRestrictions: Atomic[Option[ResponseFieldsRestrictions]] = Atomic(None: Option[ResponseFieldsRestrictions]) diff --git a/es812x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala b/es812x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala index 0f26750588..da95de59a4 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.action.{ActionListener, ActionResponse} import org.elasticsearch.threadpool.ThreadPool @@ -37,7 +37,7 @@ sealed abstract class RorActionListener[T](val underlying: ActionListener[T]) ex final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionListener[T], correlationId: Eval[CorrelationId]) - extends RorActionListener[T](underlying) with Logging { + extends RorActionListener[T](underlying) with RequestIdAwareLogging { override def onFailure(e: Exception): Unit = { super.onFailure(adaptExceptionIfNeeded(e)) @@ -47,7 +47,7 @@ final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionLis ex match { case esException: ElasticsearchException => esException case other => - logger.error(s"[${correlationId.value.show}] Internal error.", other) + noRequestIdLogger.error(s"[${correlationId.value.show}] Internal error.", other) new ElasticsearchException(s"[${correlationId.value.show}] Internal error. See logs for details.") } } diff --git a/es812x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala b/es812x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala index 75048ebe7d..14e5e31c1b 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.http.HttpChannel import org.elasticsearch.rest.{AbstractRestChannel, RestChannel as EsRestChannel, RestRequest as EsRestRequest, RestResponse as EsRestResponse} import squants.information.{Bytes, Information} @@ -40,7 +40,7 @@ object RorRestChannel { final class RorRestChannel private(underlying: EsRestChannel, val restRequest: RorRestRequest) extends AbstractRestChannel(underlying.request(), true) with ResponseFieldsFiltering - with Logging { + with RequestIdAwareLogging { override def sendResponse(response: EsRestResponse): Unit = { ThreadRepo.removeRestChannel(this) diff --git a/es812x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala b/es812x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala index 6babc712b9..3c80750a25 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala @@ -18,16 +18,15 @@ package tech.beshu.ror.es.actions.rradmin import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.ConfigApi.ConfigResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAdminActionHandler extends Logging { +class RRAdminActionHandler extends RequestIdAwareLogging { private implicit val adminRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +51,7 @@ class RRAdminActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAdminResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAdminAction internal error", ex) + logger.error("RRAdminAction internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es812x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala b/es812x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala index c55835a1d0..ce45c6f48e 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala @@ -16,18 +16,15 @@ */ package tech.beshu.ror.es.actions.rrauthmock -import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.AuthMockApi.AuthMockResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier -import tech.beshu.ror.implicits.* +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAuthMockActionHandler extends Logging { +class RRAuthMockActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -53,7 +50,7 @@ class RRAuthMockActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAuthMockResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAuthMock internal error", ex) + logger.error("RRAuthMock internal error", ex) listener.onFailure(new Exception(ex)) } } diff --git a/es812x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala b/es812x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala index aa8bb31e67..640084c4ec 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestconfig import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.TestConfigApi.TestConfigResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestConfigActionHandler extends Logging { +class RRTestConfigActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +52,7 @@ class RRTestConfigActionHandler extends Logging { case Right(response) => listener.onResponse(new RRTestConfigResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRTestConfig internal error", ex) + logger.error(s"RRTestConfig internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es812x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala b/es812x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala index 494e9150b4..98cc0c945d 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.dlsfls import cats.data.StateT import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.DirectoryReader import org.elasticsearch.common.util.concurrent.ThreadContext import org.elasticsearch.core.CheckedFunction @@ -31,7 +31,7 @@ import java.io.IOException import java.util.function.{Function => JavaFunction} import scala.util.{Failure, Success, Try} -object RoleIndexSearcherWrapper extends Logging { +object RoleIndexSearcherWrapper extends RequestIdAwareLogging { val instance: JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] = new JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] { @@ -54,7 +54,7 @@ object RoleIndexSearcherWrapper extends Logging { } .map(r => (r, r)) case None => - logger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") + noRequestIdLogger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") Success((reader, reader)) } } @@ -66,13 +66,13 @@ object RoleIndexSearcherWrapper extends Logging { nel <- NonEmptyString.from(value) match { case Right(nel) => Success(nel) case Left(_) => - logger.debug("FLS: empty header value") + noRequestIdLogger.debug("FLS: empty header value") failure } fields <- transientFieldsFromHeaderValue.fromRawValue(nel) match { case result@Success(_) => result case Failure(ex) => - logger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) + noRequestIdLogger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) failure } } yield fields diff --git a/es812x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala b/es812x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala index ce77d77f4e..aeccbfcead 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.dlsfls import com.google.common.collect.Iterators -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.codecs.StoredFieldsReader import org.apache.lucene.index.* import org.apache.lucene.index.StoredFieldVisitor.Status @@ -39,21 +39,21 @@ import scala.jdk.CollectionConverters.* import scala.util.Try private class RorDocumentFieldReader(reader: LeafReader, fieldsRestrictions: FieldsRestrictions) - extends SequentialStoredFieldsLeafReader(reader) with Logging { + extends SequentialStoredFieldsLeafReader(reader) with RequestIdAwareLogging { private val policy = new FieldsPolicy(fieldsRestrictions) private val remainingFieldsInfo = { val fInfos = in.getFieldInfos val newInfos = if (fInfos.asScala.isEmpty) { - logger.warn("original fields were empty! This is weird!") + noRequestIdLogger.warn("original fields were empty! This is weird!") fInfos } else { val remainingFields = fInfos.asScala.filter(f => policy.canKeep(f.name)).toSet new FieldInfos(remainingFields.toArray) } - logger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") - logger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") - logger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") + noRequestIdLogger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") newInfos } private val jsonPolicyBasedFilterer = new JsonPolicyBasedFilterer(policy) diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala index e0475ee3bc..d0532cd3db 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.* import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest import org.elasticsearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest @@ -87,7 +87,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, threadPool: ThreadPool) (implicit generator: UniqueIdentifierGenerator, scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle(engines: Engines, esContext: EsContext): Task[Either[Error, Unit]] = { @@ -243,7 +243,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, case SearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case MultiSearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case _ => - logger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") + noRequestIdLogger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") regularRequestHandler.handle(new DummyCompositeIndicesEsRequestContext(request, esContext, aclContext, clusterService, threadPool)) } // rest diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala index cab02aff37..100edd72ac 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.common.io.stream.StreamOutput import org.elasticsearch.xcontent.{ToXContent, ToXContentObject, XContentBuilder} @@ -45,7 +45,7 @@ import scala.util.{Failure, Success, Try} class CurrentUserMetadataRequestHandler(engine: Engine, esContext: EsContext) - extends Logging { + extends RequestIdAwareLogging { def handle(request: RequestContext.Aux[CurrentUserMetadataRequestBlockContext] with EsRequest[CurrentUserMetadataRequestBlockContext]): Task[Unit] = { engine.core.accessControl @@ -69,7 +69,7 @@ class CurrentUserMetadataRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(ex.asInstanceOf[Exception]) } } @@ -86,13 +86,13 @@ class CurrentUserMetadataRequestHandler(engine: Engine, )) } - private def onPassThrough(requestContext: RequestContext): Unit = { - logger.warn(s"[${requestContext.id.toRequestId.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") + private def onPassThrough(implicit requestContext: RequestContext): Unit = { + logger.warn(s"Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") esContext.listener.onFailure(createRorNotEnabledResponse()) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala index 2fb01dcc41..c5c44fda92 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala @@ -20,7 +20,7 @@ import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.RegularRequestResult @@ -49,7 +49,7 @@ class RegularRequestHandler(engine: Engine, esContext: EsContext, threadPool: ThreadPool) (implicit scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle[B <: BlockContext : BlockContextUpdater](request: RequestContext.Aux[B] with EsRequest[B]): Task[Unit] = { engine.core.accessControl @@ -85,7 +85,7 @@ class RegularRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(new Exception(ex)) } } @@ -99,7 +99,7 @@ class RegularRequestHandler(engine: Engine, case ModificationResult.ShouldBeInterrupted => onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case ModificationResult.CannotModify => - logger.error(s"[${request.id.toRequestId.show}] Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") + noRequestIdLogger.error(s"Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case CustomResponse(response) => respond(request, response) @@ -247,7 +247,7 @@ class RegularRequestHandler(engine: Engine, esContext.listener.onResponse(response) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } \ No newline at end of file diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala index f4f832dedc..bfc421bdd5 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.index.query.{AbstractQueryBuilder, QueryBuilder, QueryBuilders} import org.elasticsearch.search.aggregations.AggregatorFactories @@ -40,7 +40,7 @@ import tech.beshu.ror.implicits.* import java.util.UUID import scala.jdk.CollectionConverters.* -object SearchRequestOps extends Logging { +object SearchRequestOps extends RequestIdAwareLogging { implicit class QueryBuilderOps(val builder: Option[QueryBuilder]) extends AnyVal { @@ -52,7 +52,7 @@ object SearchRequestOps extends Logging { val modifiedQuery: AbstractQueryBuilder[_] = provideNewQueryWithAppliedFilter(builder, filterQuery) Some(modifiedQuery) case None => - logger.debug(s"[${requestId.show}] No filter applied to query.") + logger.debug(s"No filter applied to query.") builder } } @@ -92,7 +92,7 @@ object SearchRequestOps extends Logging { case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, requestId) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) disableCaching(requestId) case BasedOnBlockContextOnly.NotAllowedFieldsUsed(notAllowedFields) => modifyNotAllowedFieldsInRequest(notAllowedFields) @@ -138,8 +138,8 @@ object SearchRequestOps extends Logging { } } - private def disableCaching(requestId: RequestContext.Id) = { - logger.debug(s"[${requestId.show}] ACL uses context header for fields rule, will disable request cache for SearchRequest") + private def disableCaching(implicit requestId: RequestContext.Id) = { + logger.debug(s"ACL uses context header for fields rule, will disable request cache for SearchRequest") request.requestCache(false) } } diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala index 270367a54f..e2884598df 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala @@ -17,7 +17,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.action.support.IndicesOptions.WildcardStates import org.elasticsearch.action.{CompositeIndicesRequest, IndicesRequest} @@ -34,7 +33,7 @@ import scala.jdk.CollectionConverters.* abstract class BaseEsRequestContext[B <: BlockContext](esContext: EsContext, clusterService: RorClusterService) - extends RequestContext with Logging { + extends RequestContext { override type BLOCK_CONTEXT = B diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala index ae8abbe1f5..0ee2967364 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala @@ -18,7 +18,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -26,8 +25,9 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import scala.util.Try +import tech.beshu.ror.utils.RequestIdAwareLogging -trait EsRequest[B <: BlockContext] extends Logging { +trait EsRequest[B <: BlockContext] extends RequestIdAwareLogging { implicit def threadPool: ThreadPool final def modifyUsing(blockContext: B): ModificationResult = { @@ -35,7 +35,7 @@ trait EsRequest[B <: BlockContext] extends Logging { Try(modifyRequest(blockContext)) .fold( ex => { - logger.error(s"[${blockContext.requestContext.id.show}] Cannot modify request with filtered data", ex) + logger.error(s"Cannot modify request with filtered data", ex)(blockContext) ModificationResult.CannotModify }, identity diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala index c6a9dcbefd..f773b3efb1 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala @@ -51,7 +51,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest private def discoverDataStreams() = { val dataStreams = dataStreamsFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered data streams: ${dataStreams.show}") + logger.debug(s"Discovered data streams: ${dataStreams.show}") dataStreams } @@ -59,7 +59,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest val backingIndices = backingIndicesFrom(actionRequest) backingIndices match { case BackingIndices.IndicesInvolved(filteredIndices, _) => - logger.debug(s"[${id.show}] Discovered indices: ${filteredIndices.show}") + logger.debug(s"Discovered indices: ${filteredIndices.show}") case BackingIndices.IndicesNotInvolved => } backingIndices diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala index c091179cb6..d150709314 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala @@ -85,7 +85,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: case Some(indices) => update(actionRequest, indices, blockContext.filter, blockContext.fieldLevelSecurity) case None => - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -101,7 +101,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } \ No newline at end of file diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala index 71d462de57..48014e1bdc 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala @@ -73,7 +73,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, } yield update(actionRequest, filteredIndices, allAllowedIndices) result.getOrElse { - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -86,7 +86,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala index 95d882c3b5..f607c0e347 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala @@ -50,7 +50,7 @@ abstract class BaseRepositoriesEsRequestContext[R <: ActionRequest](actionReques case Some(repositories) => update(actionRequest, repositories) case None => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") ShouldBeInterrupted } } diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala index b3b1d66238..7ef0f32014 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala @@ -42,7 +42,7 @@ abstract class BaseSingleIndexEsRequestContext[R <: ActionRequest](actionRequest filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } update(request, filteredIndices.head) } diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala index b5ab70fe7a..c1b2e7ea27 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala @@ -62,7 +62,7 @@ class BulkEsRequestContext(actionRequest: BulkRequest, case (_, _) => ShouldBeInterrupted } } else { - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because origin request contained different " + + logger.error(s"Cannot alter MultiGetRequest request, because origin request contained different " + s"number of requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } @@ -90,18 +90,18 @@ class BulkEsRequestContext(actionRequest: BulkRequest, updateRequestWithIndices(request, nel) Modified case None => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because empty list of indices was found") + logger.error(s"Cannot alter MultiGetRequest request, because empty list of indices was found") ShouldBeInterrupted } case Indices.NotFound => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because no allowed indices were found") + logger.error(s"Cannot alter MultiGetRequest request, because no allowed indices were found") ShouldBeInterrupted } } private def updateRequestWithIndices(request: DocWriteRequest[_], indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } request.index(indices.head.stringify) } diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala index 75a75fcef5..96a043b298 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala @@ -53,14 +53,14 @@ class BulkShardEsRequestContext(actionRequest: BulkShardRequest, case Success(_) => Modified case Failure(ex) => - logger.error(s"[${id.show}] Cannot modify BulkShardRequest", ex) + logger.error(s"Cannot modify BulkShardRequest", ex) CannotModify } } private def tryUpdate(request: BulkShardRequest, indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } val singleIndex = indices.head val uuid = clusterService.indexOrAliasUuids(singleIndex.name).toList.head diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala index 65a168092a..158ac485a5 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala @@ -45,14 +45,14 @@ class ClusterAllocationExplainEsRequestContext(actionRequest: ClusterAllocationE getRequestedIndexFrom(request) match { case Some(_) => if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateIndexIn(request, filteredIndices.head) Modified case None if filteredIndices.exists(_.name === ClusterIndexName.Local.wildcard) => Modified case None => - logger.error(s"[${id.show}] Cluster allocation explain request without index name is unavailable when block contains `indices` rule") + logger.error(s"Cluster allocation explain request without index name is unavailable when block contains `indices` rule") ShouldBeInterrupted } } diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala index 61fdab9d83..5bf09449c5 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala @@ -79,7 +79,7 @@ class EsqlIndicesEsRequestContext private(actionRequest: ActionRequest with Comp request } case Left(ClassificationError.ParsingException(ex)) => - logger.debug(s"[${id.show}] Cannot parse ESQL statement - we can pass it though, because ES is going to reject it. Cause:", ex) + logger.debug(s"Cannot parse ESQL statement - we can pass it though, because ES is going to reject it. Cause:", ex) request } } @@ -90,7 +90,7 @@ class EsqlIndicesEsRequestContext private(actionRequest: ActionRequest with Comp case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala index 5778b8968d..02dec730ed 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala @@ -66,7 +66,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, updateAliases(actionRequest, aliases) UpdateResponse.sync(updateAliasesResponse(aliases.includedOnly, _)) case None => - logger.error(s"[${id.show}] At least one alias and one index has to be allowed. " + + logger.error(s"At least one alias and one index has to be allowed. " + s"Found allowed indices: [${blockContext.indices.show}]." + s"Found allowed aliases: [${blockContext.aliases.show}]") ShouldBeInterrupted @@ -114,7 +114,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, .indices().asSafeSet .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } @@ -122,7 +122,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, val aliases = rawRequestAliasesSet(request) .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered aliases: ${aliases.show}") + logger.debug(s"Discovered aliases: ${aliases.show}") aliases } diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala index abb85d42b7..f9e2c87e53 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala @@ -55,7 +55,7 @@ class IndicesAliasesEsRequestContext(actionRequest: IndicesAliasesRequest, if (originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala index 05b70606b9..37dd50452b 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala @@ -119,7 +119,7 @@ class MultiGetEsRequestContext(actionRequest: MultiGetRequest, case Nil => updateItemWithNonExistingIndex(item) case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } item.index(index.stringify) } diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala index 989956d79a..9e13edee8d 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala @@ -78,7 +78,7 @@ class MultiSearchEsRequestContext(actionRequest: MultiSearchRequest, } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala index 9191e33b66..5a61356f48 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala @@ -47,7 +47,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { request.getRequests.removeIf { request => removeOrAlter(request, filteredIndices.toCovariantSet) } if (request.getRequests.asScala.isEmpty) { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") ShouldBeInterrupted } else { Modified @@ -63,7 +63,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, true case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") } request.index(index.stringify) false diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala index c411df93c5..c7b99f6e85 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala @@ -52,7 +52,7 @@ class PutRollupJobEsRequestContext private(actionRequest: ActionRequest, if(originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala index 141d9db788..fff8ed58bb 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala @@ -49,7 +49,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (tryUpdate(actionRequest, filteredIndices)) Modified else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") ShouldBeInterrupted } } diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala index 489d0187bc..c42dfc3b78 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala @@ -58,10 +58,10 @@ class ReindexEsRequestContext(actionRequest: ReindexRequest, Modified } else { if (!isDestinationIndexOnFilteredIndicesList) { - logger.info(s"[${id.show}] Destination index of _reindex request is forbidden") + logger.info(s"Destination index of _reindex request is forbidden") } if (!isSearchRequestComposedOnlyOfAllowedIndices) { - logger.info(s"[${id.show}] At least one index from sources indices list of _reindex request is forbidden") + logger.info(s"At least one index from sources indices list of _reindex request is forbidden") } ShouldBeInterrupted } diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala index 2c1b0014e0..97b8ccd9c5 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala @@ -74,7 +74,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo request } case Left(_) => - logger.debug(s"[${id.show}] Cannot parse SQL statement - we can pass it though, because ES is going to reject it") + logger.debug(s"Cannot parse SQL statement - we can pass it though, because ES is going to reject it") request } } @@ -85,7 +85,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala index 0c67384c1e..d7e743e648 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CleanupRepositoryEsRequestContext(actionRequest: CleanupRepositoryRequest, override protected def update(request: CleanupRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala index 44b7d78dfd..d09015139b 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CreateRepositoryEsRequestContext(actionRequest: PutRepositoryRequest, override protected def update(request: PutRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala index eaf9334872..0cf32e1bea 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class DeleteRepositoryEsRequestContext(actionRequest: DeleteRepositoryRequest, override protected def update(request: DeleteRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala index cee0bffd4c..d1410eff3d 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class VerifyRepositoryEsRequestContext(actionRequest: VerifyRepositoryRequest, override protected def update(request: VerifyRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala index ead4fcf250..20501516d5 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala @@ -68,32 +68,32 @@ class CreateSnapshotEsRequestContext(actionRequest: CreateSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala index a56aba660e..621d744767 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala @@ -60,7 +60,7 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -71,14 +71,14 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, .toRight(()) } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala index 22869bbb4f..b81f333174 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala @@ -68,7 +68,7 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, case r => r } case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala index 88887db96c..156deb5b80 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala @@ -63,7 +63,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -75,7 +75,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") } Right(snapshot) } @@ -88,7 +88,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala index 44ee8397ec..e522e440f1 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala @@ -100,12 +100,12 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { val repositories = blockContext.repositories if (allRepositoriesRequested(repositories)) { Right(RepositoryName.All) @@ -115,7 +115,7 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala index 3acf4433cd..ea5c3297e1 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.GetComposableIndexTemplateAction import org.elasticsearch.cluster.metadata import org.elasticsearch.cluster.metadata.ComposableIndexTemplate @@ -108,7 +108,7 @@ class GetComposableIndexTemplateEsRequestContext(actionRequest: GetComposableInd } -private[templates] object GetComposableIndexTemplateEsRequestContext extends Logging { +private[templates] object GetComposableIndexTemplateEsRequestContext extends RequestIdAwareLogging { def filter(templates: Map[String, ComposableIndexTemplate], usingTemplate: Set[Template] => Set[Template]) diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala index bd74c3a18f..1c6eecf409 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.{GetIndexTemplatesRequest, GetIndexTemplatesResponse} import org.elasticsearch.cluster.metadata.{AliasMetadata, IndexTemplateMetadata} import org.elasticsearch.common.collect.ImmutableOpenMap @@ -104,7 +104,7 @@ class GetTemplatesEsRequestContext(actionRequest: GetIndexTemplatesRequest, } -private[templates] object GetTemplatesEsRequestContext extends Logging { +private[templates] object GetTemplatesEsRequestContext extends RequestIdAwareLogging { def filter(templates: Iterable[IndexTemplateMetadata], usingTemplate: Set[Template] => Set[Template]) diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala index a8951de5b1..32116d8212 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala @@ -72,7 +72,7 @@ class MultiSearchTemplateEsRequestContext private(actionRequest: ActionRequest w } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala index e6f6d8916e..434787a686 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala @@ -55,7 +55,7 @@ class SimulateIndexTemplateRequestEsRequestContext(actionRequest: SimulateIndexT filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateRequest(request, filteredIndices.head, allAllowedIndices) } diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala index fbc4cf6776..46ed6e7a95 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala @@ -109,7 +109,7 @@ class SimulateExistingTemplateRequestEsRequestContext(existingTemplateName: Temp case Some(_) => updateResponse(namePatterns.toList, blockContext.allAllowedIndices.toList) case None => - logger.info(s"[${id.show}] User has no access to template ${existingTemplateName.show}") + logger.info(s"User has no access to template ${existingTemplateName.show}") ModificationResult.ShouldBeInterrupted } case other => diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala index 0ecd7a72b3..fe4d60bd42 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.queries import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.index.query.* import org.joor.Reflect.on import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.RequestFieldsUsage @@ -30,7 +30,7 @@ trait QueryFieldsUsage[QUERY <: QueryBuilder] { def fieldsIn(query: QUERY): RequestFieldsUsage } -object QueryFieldsUsage extends Logging { +object QueryFieldsUsage extends RequestIdAwareLogging { def apply[QUERY <: QueryBuilder](implicit ev: QueryFieldsUsage[QUERY]): QueryFieldsUsage[QUERY] = ev implicit class Ops[QUERY <: QueryBuilder : QueryFieldsUsage](val query: QUERY) { @@ -62,7 +62,7 @@ object QueryFieldsUsage extends Logging { Option(on(query).call("getFieldName").get[String]) match { case Some(fieldName: String) => UsingFields(NonEmptyList.one(UsedField(fieldName))) case _ => - logger.debug(s"Cannot extract fields for terms set query") + noRequestIdLogger.debug(s"Cannot extract fields for terms set query") CannotExtractFields } } @@ -89,7 +89,7 @@ object QueryFieldsUsage extends Logging { case builder: TermsSetQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder: WildcardQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder => - logger.debug(s"Cannot extract fields for query: ${builder.getName}") + noRequestIdLogger.debug(s"Cannot extract fields for query: ${builder.getName}") CannotExtractFields } diff --git a/es812x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala b/es812x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala index 0998bb9a5b..b4671e9e4d 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.handler.response import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.FieldsRestrictions import tech.beshu.ror.accesscontrol.domain.Header @@ -26,17 +26,17 @@ import tech.beshu.ror.accesscontrol.headerValues.transientFieldsToHeaderValue import tech.beshu.ror.accesscontrol.request.RequestContext import tech.beshu.ror.implicits.* -object FLSContextHeaderHandler extends Logging { +object FLSContextHeaderHandler extends RequestIdAwareLogging { def addContextHeader(threadPool: ThreadPool, - fieldsRestrictions: FieldsRestrictions, - requestId: RequestContext.Id): Unit = { + fieldsRestrictions: FieldsRestrictions) + (implicit requestId: RequestContext.Id): Unit = { val threadContext = threadPool.getThreadContext val header = createContextHeader(fieldsRestrictions) Option(threadContext.getHeader(header.name.value.value)) match { case None => implicit val show = headerShow - logger.debug(s"[${requestId.show}] Adding thread context header required by lucene. Header: '${header.show}'") + logger.debug(s"Adding thread context header required by lucene. Header: '${header.show}'") threadContext.putHeader(header.name.value.value, header.value.value) case Some(_) => } diff --git a/es812x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala b/es812x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala index 0216042adb..74d8c96df2 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.admin.indices.template.get.{GetComponentTemplateAction, GetComposableIndexTemplateAction} import org.elasticsearch.action.admin.indices.template.put.{PutComponentTemplateAction, PutComposableIndexTemplateAction} @@ -46,7 +46,7 @@ import scala.jdk.CollectionConverters.* final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJsonParserFactory)(using Clock) extends DataStreamService - with Logging { + with RequestIdAwareLogging { override def checkDataStreamExists(dataStreamName: DataStreamName.Full): Task[Boolean] = execute { val request = new GetDataStreamAction.Request(List(dataStreamName.value.value).toArray) @@ -201,11 +201,11 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ response <- Task.measure( task = Task.delay(nodeClient.execute(action, request).actionGet()), logTimeMeasurement = duration => Task.delay { - logger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") + noRequestIdLogger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") } ) _ <- Task.delay { - logger.debug(s"Action ${action.name()} response: ${response.toString}") + noRequestIdLogger.debug(s"Action ${action.name()} response: ${response.toString}") } } yield response } @@ -213,7 +213,7 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ def executeAck[REQUEST <: ActionRequest, RESPONSE <: AcknowledgedResponse](action: ActionType[RESPONSE], request: REQUEST): Task[RESPONSE] = { executeT(action, request) - .tapEval(response => Task.delay(logger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) + .tapEval(response => Task.delay(noRequestIdLogger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) } private def supportedActions: Map[ActionType[ActionResponse], TransportAction[ActionRequest, ActionResponse]] = { diff --git a/es812x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala b/es812x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala index 2e75d37d0f..16259474bf 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.support.WriteRequest.RefreshPolicy import org.elasticsearch.client.internal.node.NodeClient @@ -38,7 +38,7 @@ import scala.jdk.CollectionConverters.* class EsIndexJsonContentService(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexJsonContentService - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -63,14 +63,14 @@ class EsIndexJsonContentService(client: NodeClient, Option(response.getSourceAsMap) match { case Some(map) => val source = map.asScala.toMap.asStringMap - logger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") Right(source) case None => - logger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") + noRequestIdLogger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") Right(Map.empty[String, String]) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(ContentNotFound) } } @@ -78,7 +78,7 @@ class EsIndexJsonContentService(client: NodeClient, .onErrorRecover { case _: ResourceNotFoundException => Left(ContentNotFound) case ex => - logger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) Left(CannotReachContentSource) } } @@ -104,14 +104,14 @@ class EsIndexJsonContentService(client: NodeClient, case status if status / 100 == 2 => Right(()) case status => - logger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") Left(CannotWriteToIndex) } } .executeOn(RorSchedulers.blockingScheduler) .onErrorRecover { case ex => - logger.error(s"Cannot write to document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]", ex) Left(CannotWriteToIndex) } } diff --git a/es812x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala b/es812x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala index 1429c7405a..c27d4ec9d5 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala @@ -22,7 +22,7 @@ import cats.kernel.Monoid import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task import monix.execution.{CancelablePromise, Scheduler} -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction.{ResolvedAlias, ResolvedIndex} @@ -64,7 +64,7 @@ class EsServerBasedRorClusterService(nodeName: String, threadPool: ThreadPool) (implicit val scheduler: Scheduler) extends RorClusterService - with Logging { + with RequestIdAwareLogging { import EsServerBasedRorClusterService.* @@ -155,7 +155,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractAccessibilityFrom) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify get request. Blocking document", ex) + logger.error(s"Could not verify get request. Blocking document", ex)(id) Inaccessible } } @@ -167,7 +167,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractResultsFromSearchResponse) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify documents returned by multi get response. Blocking all returned documents", ex) + logger.error(s"Could not verify documents returned by multi get response. Blocking all returned documents", ex)(id) blockAllDocsReturned(documents) } .map(results => zip(results, documents)) @@ -276,7 +276,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService): Task[List[FullRemoteDataStreamWithAliases]] = { getRemoteClusterClient(remoteClusterService, remoteClusterName) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -332,7 +332,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService) = { getRemoteClusterClient(remoteClusterService, remoteClusterName) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -423,7 +423,7 @@ class EsServerBasedRorClusterService(nodeName: String, } } case None => - logger.error("Cannot supply Snapshots Service. Please, report the issue!!!") + noRequestIdLogger.error("Cannot supply Snapshots Service. Please, report the issue!!!") Task.now(Set.empty[Snapshot]) } } diff --git a/es812x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala b/es812x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala index a657d15ca9..31d96f15a2 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.services import cats.data.NonEmptyList -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.bulk.{BackoffPolicy, BulkProcessor, BulkRequest, BulkResponse} import org.elasticsearch.action.index.IndexRequest import org.elasticsearch.action.{ActionListener, DocWriteRequest} @@ -39,7 +39,7 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, (using Clock) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { private val bulkProcessor = BulkProcessor @@ -80,25 +80,25 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, private class AuditSinkBulkProcessorListener extends BulkProcessor.Listener { override def beforeBulk(executionId: Long, request: BulkRequest): Unit = { - logger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") + noRequestIdLogger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") } override def afterBulk(executionId: Long, request: BulkRequest, response: BulkResponse): Unit = { if (response.hasFailures) { - logger.error("Some failures flushing the BulkProcessor: ") + noRequestIdLogger.error("Some failures flushing the BulkProcessor: ") response .getItems.to(LazyList) .filter(_.isFailed) .map(_.getFailureMessage) .groupBy(identity) .foreach { case (message, stream) => - logger.error(s"${stream.size}x: $message") + noRequestIdLogger.error(s"${stream.size}x: $message") } } } override def afterBulk(executionId: Long, request: BulkRequest, failure: Throwable): Unit = { - logger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) + noRequestIdLogger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) } } diff --git a/es812x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala b/es812x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala index a8def0ec7a..b3c5593c36 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala @@ -22,7 +22,7 @@ import org.apache.http.auth.{AuthScope, Credentials, UsernamePasswordCredentials import org.apache.http.conn.ssl.NoopHostnameVerifier import org.apache.http.impl.client.BasicCredentialsProvider import org.apache.http.impl.nio.client.HttpAsyncClientBuilder -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.* import org.elasticsearch.client.RestClient.FailureListener import tech.beshu.ror.accesscontrol.audit.sink.AuditDataStreamCreator @@ -38,7 +38,7 @@ import scala.collection.parallel.CollectionConverters.* final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient]) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { override def submit(indexName: IndexName.Full, documentId: String, jsonRecord: String) (implicit requestId: RequestId): Unit = { @@ -77,21 +77,21 @@ final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient] override def onSuccess(response: Response): Unit = { response.getStatusLine.getStatusCode / 100 match { case 2 => // 2xx - logger.debug(s"[${requestId.show}] Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") + logger.debug(s"Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") case _ => - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") } } override def onFailure(ex: Exception): Unit = { - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId]", ex) + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId]", ex) } } override val dataStreamCreator: AuditDataStreamCreator = new AuditDataStreamCreator(clients.map(new RestClientDataStreamService(_))) } -object RestClientAuditSinkService extends Logging { +object RestClientAuditSinkService extends RequestIdAwareLogging { def create(remoteCluster: AuditCluster.RemoteAuditCluster): RestClientAuditSinkService = { remoteCluster.mode match { @@ -122,7 +122,7 @@ object RestClientAuditSinkService extends Logging { .setFailureListener( new FailureListener { override def onFailure(node: Node): Unit = { - logger.debug( + noRequestIdLogger.debug( s"[AUDIT] Node marked dead: ${node.getHost.getSchemeName}://${node.getHost.getHostName}:${node.getHost.getPort}. The client will attempt failover.", ) } diff --git a/es812x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala b/es812x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala index ce17639c06..b18c4fbfee 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.Channel import io.netty.handler.ssl.NotSslRecordException -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.network.NetworkService import org.elasticsearch.common.settings.{ClusterSettings, Settings} import org.elasticsearch.http.netty4.Netty4HttpServerTransport @@ -41,7 +41,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, tracer: Tracer, fipsCompliant: Boolean) extends Netty4HttpServerTransport(settings, networkService, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory, tracer, TLSConfig.noTLS(), null, null) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, ssl.clientAuthenticationEnabled) @@ -49,7 +49,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, override def onException(channel: HttpChannel, cause: Exception): Unit = { if (!this.lifecycle.started) return - else if (cause.getCause.isInstanceOf[NotSslRecordException]) logger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) + else if (cause.getCause.isInstanceOf[NotSslRecordException]) noRequestIdLogger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) else super.onException(channel, cause) channel.close() } diff --git a/es812x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala b/es812x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala index 2fa1d7871c..2d2b0360d4 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.* import io.netty.handler.ssl.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.TransportVersion import org.elasticsearch.cluster.node.DiscoveryNode import org.elasticsearch.common.io.stream.NamedWriteableRegistry @@ -46,7 +46,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, sharedGroupFactory: SharedGroupFactory, fipsCompliant: Boolean) extends Netty4Transport(settings, TransportVersion.current(), threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = SSLCertHelper.prepareClientSSLContext(ssl, fipsCompliant, ssl.certificateVerificationEnabled) private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, clientAuthenticationEnabled = false) @@ -78,7 +78,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, override def exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable): Unit = { if (cause.isInstanceOf[NotSslRecordException] || (cause.getCause != null && cause.getCause.isInstanceOf[NotSslRecordException])) { - logger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") + noRequestIdLogger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") ctx.channel.close } else { super.exceptionCaught(ctx, cause) diff --git a/es812x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala b/es812x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala index 1a8804e4b7..84979960e0 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.utils import cats.Show import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.client.internal.node.NodeClient import org.elasticsearch.rest.* @@ -37,7 +37,7 @@ import java.util import scala.util.Try class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandler) - extends RestHandler with Logging { + extends RestHandler with RequestIdAwareLogging { private val wrapped = doPrivileged { wrapSomeActions(underlying) @@ -103,11 +103,11 @@ class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandle private def logError(error: AuthorizationValueError): Unit = { { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorSanitizedShow - logger.warn(s"The incoming request was malformed. Cause: ${error.show}") + noRequestIdLogger.warn(s"The incoming request was malformed. Cause: ${error.show}") } if (logger.delegate.isDebugEnabled()) { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorWithDetailsShow - logger.debug(s"Malformed request detailed cause: ${error.show}") + noRequestIdLogger.debug(s"Malformed request detailed cause: ${error.show}") } } diff --git a/es812x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala b/es812x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala index 5ab1e35742..a9af8f710a 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala @@ -16,13 +16,13 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.settings.Settings import tech.beshu.ror.tools.core.patches.PatchingVerifier import tech.beshu.ror.tools.core.patches.PatchingVerifier.Error.{CannotVerifyIfPatched, EsNotPatched} import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -object EsPatchVerifier extends Logging { +object EsPatchVerifier extends RequestIdAwareLogging { def verify(settings: Settings): Unit = doPrivileged { pathHomeFrom(settings).flatMap(PatchingVerifier.verify) match { @@ -30,7 +30,7 @@ object EsPatchVerifier extends Logging { case Left(e@EsNotPatched(_)) => throw new IllegalStateException(e.message) case Left(e@CannotVerifyIfPatched(_)) => - logger.warn(e.message) + noRequestIdLogger.warn(e.message) } } diff --git a/es812x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala b/es812x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala index 639aeb5029..893d807108 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.repositories.{RepositoriesService, VerifyNodeRepositoryAction} import org.elasticsearch.transport.{RemoteClusterService, TransportService} import org.joor.Reflect.on @@ -26,7 +26,7 @@ import java.util.function.Supplier import scala.util.{Failure, Success, Try} class RemoteClusterServiceSupplier(repositoriesServiceSupplier: Supplier[RepositoriesService]) - extends Supplier[Option[RemoteClusterService]] with Logging { + extends Supplier[Option[RemoteClusterService]] with RequestIdAwareLogging { override def get(): Option[RemoteClusterService] = { for { @@ -35,7 +35,7 @@ class RemoteClusterServiceSupplier(repositoriesServiceSupplier: Supplier[Reposit case Success(transportService) => Option(transportService.getRemoteClusterService) case Failure(ex) => - logger.error("Cannot extract RemoteClusterService from RepositoriesService", ex) + noRequestIdLogger.error("Cannot extract RemoteClusterService from RepositoriesService", ex) None } } yield remoteClusterService diff --git a/es813x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es813x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index 07d70bbf05..978eebec5d 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.support.{ActionFilter, ActionFilterChain} import org.elasticsearch.action.{ActionListener, ActionRequest, ActionResponse} import org.elasticsearch.client.internal.node.NodeClient @@ -62,7 +62,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, rorEsConfig: ReadonlyRestEsConfig) (implicit environmentConfig: EnvironmentConfig) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = environmentConfig.uniqueIdentifierGenerator @@ -211,12 +211,12 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def handleRorNotReadyYet(esContext: EsContext): Unit = { - logger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") + noRequestIdLogger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") rorNotAvailableRequestHandler.handleRorNotReadyYet(esContext) } private def handleRorFailedToStart(esContext: EsContext): Unit = { - logger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") + noRequestIdLogger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") rorNotAvailableRequestHandler.handleRorFailedToStart(esContext) } @@ -238,7 +238,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def logAndSetStartingFailureState(failure: StartingFailure): Unit = { - logger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) + noRequestIdLogger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) rorInstanceState.set(RorInstanceStartingState.NotStarted(failure)) } } diff --git a/es813x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala b/es813x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala index 1fb22fc79d..53452eb8e6 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.xcontent.LoggingDeprecationHandler import org.elasticsearch.rest.RestResponse import org.elasticsearch.transport.BytesRefRecycler @@ -32,7 +32,7 @@ import tech.beshu.ror.accesscontrol.domain.ResponseFieldsFiltering.{AccessMode, import scala.jdk.CollectionConverters.* trait ResponseFieldsFiltering { - this: Logging => + this: RequestIdAwareLogging => private val responseFieldsRestrictions: Atomic[Option[ResponseFieldsRestrictions]] = Atomic(None: Option[ResponseFieldsRestrictions]) diff --git a/es813x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala b/es813x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala index 0f26750588..da95de59a4 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.action.{ActionListener, ActionResponse} import org.elasticsearch.threadpool.ThreadPool @@ -37,7 +37,7 @@ sealed abstract class RorActionListener[T](val underlying: ActionListener[T]) ex final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionListener[T], correlationId: Eval[CorrelationId]) - extends RorActionListener[T](underlying) with Logging { + extends RorActionListener[T](underlying) with RequestIdAwareLogging { override def onFailure(e: Exception): Unit = { super.onFailure(adaptExceptionIfNeeded(e)) @@ -47,7 +47,7 @@ final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionLis ex match { case esException: ElasticsearchException => esException case other => - logger.error(s"[${correlationId.value.show}] Internal error.", other) + noRequestIdLogger.error(s"[${correlationId.value.show}] Internal error.", other) new ElasticsearchException(s"[${correlationId.value.show}] Internal error. See logs for details.") } } diff --git a/es813x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala b/es813x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala index 75048ebe7d..14e5e31c1b 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.http.HttpChannel import org.elasticsearch.rest.{AbstractRestChannel, RestChannel as EsRestChannel, RestRequest as EsRestRequest, RestResponse as EsRestResponse} import squants.information.{Bytes, Information} @@ -40,7 +40,7 @@ object RorRestChannel { final class RorRestChannel private(underlying: EsRestChannel, val restRequest: RorRestRequest) extends AbstractRestChannel(underlying.request(), true) with ResponseFieldsFiltering - with Logging { + with RequestIdAwareLogging { override def sendResponse(response: EsRestResponse): Unit = { ThreadRepo.removeRestChannel(this) diff --git a/es813x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala b/es813x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala index 6babc712b9..3c80750a25 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala @@ -18,16 +18,15 @@ package tech.beshu.ror.es.actions.rradmin import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.ConfigApi.ConfigResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAdminActionHandler extends Logging { +class RRAdminActionHandler extends RequestIdAwareLogging { private implicit val adminRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +51,7 @@ class RRAdminActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAdminResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAdminAction internal error", ex) + logger.error("RRAdminAction internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es813x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala b/es813x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala index c55835a1d0..ce45c6f48e 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala @@ -16,18 +16,15 @@ */ package tech.beshu.ror.es.actions.rrauthmock -import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.AuthMockApi.AuthMockResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier -import tech.beshu.ror.implicits.* +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAuthMockActionHandler extends Logging { +class RRAuthMockActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -53,7 +50,7 @@ class RRAuthMockActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAuthMockResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAuthMock internal error", ex) + logger.error("RRAuthMock internal error", ex) listener.onFailure(new Exception(ex)) } } diff --git a/es813x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala b/es813x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala index aa8bb31e67..640084c4ec 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestconfig import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.TestConfigApi.TestConfigResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestConfigActionHandler extends Logging { +class RRTestConfigActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +52,7 @@ class RRTestConfigActionHandler extends Logging { case Right(response) => listener.onResponse(new RRTestConfigResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRTestConfig internal error", ex) + logger.error(s"RRTestConfig internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es813x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala b/es813x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala index 494e9150b4..98cc0c945d 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.dlsfls import cats.data.StateT import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.DirectoryReader import org.elasticsearch.common.util.concurrent.ThreadContext import org.elasticsearch.core.CheckedFunction @@ -31,7 +31,7 @@ import java.io.IOException import java.util.function.{Function => JavaFunction} import scala.util.{Failure, Success, Try} -object RoleIndexSearcherWrapper extends Logging { +object RoleIndexSearcherWrapper extends RequestIdAwareLogging { val instance: JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] = new JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] { @@ -54,7 +54,7 @@ object RoleIndexSearcherWrapper extends Logging { } .map(r => (r, r)) case None => - logger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") + noRequestIdLogger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") Success((reader, reader)) } } @@ -66,13 +66,13 @@ object RoleIndexSearcherWrapper extends Logging { nel <- NonEmptyString.from(value) match { case Right(nel) => Success(nel) case Left(_) => - logger.debug("FLS: empty header value") + noRequestIdLogger.debug("FLS: empty header value") failure } fields <- transientFieldsFromHeaderValue.fromRawValue(nel) match { case result@Success(_) => result case Failure(ex) => - logger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) + noRequestIdLogger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) failure } } yield fields diff --git a/es813x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala b/es813x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala index ce77d77f4e..aeccbfcead 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.dlsfls import com.google.common.collect.Iterators -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.codecs.StoredFieldsReader import org.apache.lucene.index.* import org.apache.lucene.index.StoredFieldVisitor.Status @@ -39,21 +39,21 @@ import scala.jdk.CollectionConverters.* import scala.util.Try private class RorDocumentFieldReader(reader: LeafReader, fieldsRestrictions: FieldsRestrictions) - extends SequentialStoredFieldsLeafReader(reader) with Logging { + extends SequentialStoredFieldsLeafReader(reader) with RequestIdAwareLogging { private val policy = new FieldsPolicy(fieldsRestrictions) private val remainingFieldsInfo = { val fInfos = in.getFieldInfos val newInfos = if (fInfos.asScala.isEmpty) { - logger.warn("original fields were empty! This is weird!") + noRequestIdLogger.warn("original fields were empty! This is weird!") fInfos } else { val remainingFields = fInfos.asScala.filter(f => policy.canKeep(f.name)).toSet new FieldInfos(remainingFields.toArray) } - logger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") - logger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") - logger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") + noRequestIdLogger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") newInfos } private val jsonPolicyBasedFilterer = new JsonPolicyBasedFilterer(policy) diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala index 9365230fe3..9abe861fe3 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.* import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest import org.elasticsearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest @@ -87,7 +87,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, threadPool: ThreadPool) (implicit generator: UniqueIdentifierGenerator, scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle(engines: Engines, esContext: EsContext): Task[Either[Error, Unit]] = { @@ -243,7 +243,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, case SearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case MultiSearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case _ => - logger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") + noRequestIdLogger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") regularRequestHandler.handle(new DummyCompositeIndicesEsRequestContext(request, esContext, aclContext, clusterService, threadPool)) } // rest diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala index cab02aff37..100edd72ac 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.common.io.stream.StreamOutput import org.elasticsearch.xcontent.{ToXContent, ToXContentObject, XContentBuilder} @@ -45,7 +45,7 @@ import scala.util.{Failure, Success, Try} class CurrentUserMetadataRequestHandler(engine: Engine, esContext: EsContext) - extends Logging { + extends RequestIdAwareLogging { def handle(request: RequestContext.Aux[CurrentUserMetadataRequestBlockContext] with EsRequest[CurrentUserMetadataRequestBlockContext]): Task[Unit] = { engine.core.accessControl @@ -69,7 +69,7 @@ class CurrentUserMetadataRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(ex.asInstanceOf[Exception]) } } @@ -86,13 +86,13 @@ class CurrentUserMetadataRequestHandler(engine: Engine, )) } - private def onPassThrough(requestContext: RequestContext): Unit = { - logger.warn(s"[${requestContext.id.toRequestId.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") + private def onPassThrough(implicit requestContext: RequestContext): Unit = { + logger.warn(s"Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") esContext.listener.onFailure(createRorNotEnabledResponse()) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala index 2fb01dcc41..c5c44fda92 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala @@ -20,7 +20,7 @@ import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.RegularRequestResult @@ -49,7 +49,7 @@ class RegularRequestHandler(engine: Engine, esContext: EsContext, threadPool: ThreadPool) (implicit scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle[B <: BlockContext : BlockContextUpdater](request: RequestContext.Aux[B] with EsRequest[B]): Task[Unit] = { engine.core.accessControl @@ -85,7 +85,7 @@ class RegularRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(new Exception(ex)) } } @@ -99,7 +99,7 @@ class RegularRequestHandler(engine: Engine, case ModificationResult.ShouldBeInterrupted => onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case ModificationResult.CannotModify => - logger.error(s"[${request.id.toRequestId.show}] Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") + noRequestIdLogger.error(s"Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case CustomResponse(response) => respond(request, response) @@ -247,7 +247,7 @@ class RegularRequestHandler(engine: Engine, esContext.listener.onResponse(response) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } \ No newline at end of file diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala index f4f832dedc..bfc421bdd5 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.index.query.{AbstractQueryBuilder, QueryBuilder, QueryBuilders} import org.elasticsearch.search.aggregations.AggregatorFactories @@ -40,7 +40,7 @@ import tech.beshu.ror.implicits.* import java.util.UUID import scala.jdk.CollectionConverters.* -object SearchRequestOps extends Logging { +object SearchRequestOps extends RequestIdAwareLogging { implicit class QueryBuilderOps(val builder: Option[QueryBuilder]) extends AnyVal { @@ -52,7 +52,7 @@ object SearchRequestOps extends Logging { val modifiedQuery: AbstractQueryBuilder[_] = provideNewQueryWithAppliedFilter(builder, filterQuery) Some(modifiedQuery) case None => - logger.debug(s"[${requestId.show}] No filter applied to query.") + logger.debug(s"No filter applied to query.") builder } } @@ -92,7 +92,7 @@ object SearchRequestOps extends Logging { case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, requestId) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) disableCaching(requestId) case BasedOnBlockContextOnly.NotAllowedFieldsUsed(notAllowedFields) => modifyNotAllowedFieldsInRequest(notAllowedFields) @@ -138,8 +138,8 @@ object SearchRequestOps extends Logging { } } - private def disableCaching(requestId: RequestContext.Id) = { - logger.debug(s"[${requestId.show}] ACL uses context header for fields rule, will disable request cache for SearchRequest") + private def disableCaching(implicit requestId: RequestContext.Id) = { + logger.debug(s"ACL uses context header for fields rule, will disable request cache for SearchRequest") request.requestCache(false) } } diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala index 993bdbd7a0..f0d04a6837 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala @@ -17,7 +17,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.action.{CompositeIndicesRequest, IndicesRequest} import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -32,7 +31,7 @@ import java.time.Instant abstract class BaseEsRequestContext[B <: BlockContext](esContext: EsContext, clusterService: RorClusterService) - extends RequestContext with Logging { + extends RequestContext { override type BLOCK_CONTEXT = B diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala index ae8abbe1f5..0ee2967364 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala @@ -18,7 +18,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -26,8 +25,9 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import scala.util.Try +import tech.beshu.ror.utils.RequestIdAwareLogging -trait EsRequest[B <: BlockContext] extends Logging { +trait EsRequest[B <: BlockContext] extends RequestIdAwareLogging { implicit def threadPool: ThreadPool final def modifyUsing(blockContext: B): ModificationResult = { @@ -35,7 +35,7 @@ trait EsRequest[B <: BlockContext] extends Logging { Try(modifyRequest(blockContext)) .fold( ex => { - logger.error(s"[${blockContext.requestContext.id.show}] Cannot modify request with filtered data", ex) + logger.error(s"Cannot modify request with filtered data", ex)(blockContext) ModificationResult.CannotModify }, identity diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala index c6a9dcbefd..f773b3efb1 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala @@ -51,7 +51,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest private def discoverDataStreams() = { val dataStreams = dataStreamsFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered data streams: ${dataStreams.show}") + logger.debug(s"Discovered data streams: ${dataStreams.show}") dataStreams } @@ -59,7 +59,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest val backingIndices = backingIndicesFrom(actionRequest) backingIndices match { case BackingIndices.IndicesInvolved(filteredIndices, _) => - logger.debug(s"[${id.show}] Discovered indices: ${filteredIndices.show}") + logger.debug(s"Discovered indices: ${filteredIndices.show}") case BackingIndices.IndicesNotInvolved => } backingIndices diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala index c091179cb6..d150709314 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala @@ -85,7 +85,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: case Some(indices) => update(actionRequest, indices, blockContext.filter, blockContext.fieldLevelSecurity) case None => - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -101,7 +101,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } \ No newline at end of file diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala index 71d462de57..48014e1bdc 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala @@ -73,7 +73,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, } yield update(actionRequest, filteredIndices, allAllowedIndices) result.getOrElse { - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -86,7 +86,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala index 95d882c3b5..f607c0e347 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala @@ -50,7 +50,7 @@ abstract class BaseRepositoriesEsRequestContext[R <: ActionRequest](actionReques case Some(repositories) => update(actionRequest, repositories) case None => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") ShouldBeInterrupted } } diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala index b3b1d66238..7ef0f32014 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala @@ -42,7 +42,7 @@ abstract class BaseSingleIndexEsRequestContext[R <: ActionRequest](actionRequest filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } update(request, filteredIndices.head) } diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala index b5ab70fe7a..c1b2e7ea27 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala @@ -62,7 +62,7 @@ class BulkEsRequestContext(actionRequest: BulkRequest, case (_, _) => ShouldBeInterrupted } } else { - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because origin request contained different " + + logger.error(s"Cannot alter MultiGetRequest request, because origin request contained different " + s"number of requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } @@ -90,18 +90,18 @@ class BulkEsRequestContext(actionRequest: BulkRequest, updateRequestWithIndices(request, nel) Modified case None => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because empty list of indices was found") + logger.error(s"Cannot alter MultiGetRequest request, because empty list of indices was found") ShouldBeInterrupted } case Indices.NotFound => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because no allowed indices were found") + logger.error(s"Cannot alter MultiGetRequest request, because no allowed indices were found") ShouldBeInterrupted } } private def updateRequestWithIndices(request: DocWriteRequest[_], indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } request.index(indices.head.stringify) } diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala index 75a75fcef5..96a043b298 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala @@ -53,14 +53,14 @@ class BulkShardEsRequestContext(actionRequest: BulkShardRequest, case Success(_) => Modified case Failure(ex) => - logger.error(s"[${id.show}] Cannot modify BulkShardRequest", ex) + logger.error(s"Cannot modify BulkShardRequest", ex) CannotModify } } private def tryUpdate(request: BulkShardRequest, indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } val singleIndex = indices.head val uuid = clusterService.indexOrAliasUuids(singleIndex.name).toList.head diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala index 65a168092a..158ac485a5 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala @@ -45,14 +45,14 @@ class ClusterAllocationExplainEsRequestContext(actionRequest: ClusterAllocationE getRequestedIndexFrom(request) match { case Some(_) => if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateIndexIn(request, filteredIndices.head) Modified case None if filteredIndices.exists(_.name === ClusterIndexName.Local.wildcard) => Modified case None => - logger.error(s"[${id.show}] Cluster allocation explain request without index name is unavailable when block contains `indices` rule") + logger.error(s"Cluster allocation explain request without index name is unavailable when block contains `indices` rule") ShouldBeInterrupted } } diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala index 61fdab9d83..5bf09449c5 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala @@ -79,7 +79,7 @@ class EsqlIndicesEsRequestContext private(actionRequest: ActionRequest with Comp request } case Left(ClassificationError.ParsingException(ex)) => - logger.debug(s"[${id.show}] Cannot parse ESQL statement - we can pass it though, because ES is going to reject it. Cause:", ex) + logger.debug(s"Cannot parse ESQL statement - we can pass it though, because ES is going to reject it. Cause:", ex) request } } @@ -90,7 +90,7 @@ class EsqlIndicesEsRequestContext private(actionRequest: ActionRequest with Comp case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala index 5778b8968d..02dec730ed 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala @@ -66,7 +66,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, updateAliases(actionRequest, aliases) UpdateResponse.sync(updateAliasesResponse(aliases.includedOnly, _)) case None => - logger.error(s"[${id.show}] At least one alias and one index has to be allowed. " + + logger.error(s"At least one alias and one index has to be allowed. " + s"Found allowed indices: [${blockContext.indices.show}]." + s"Found allowed aliases: [${blockContext.aliases.show}]") ShouldBeInterrupted @@ -114,7 +114,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, .indices().asSafeSet .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } @@ -122,7 +122,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, val aliases = rawRequestAliasesSet(request) .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered aliases: ${aliases.show}") + logger.debug(s"Discovered aliases: ${aliases.show}") aliases } diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala index abb85d42b7..f9e2c87e53 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala @@ -55,7 +55,7 @@ class IndicesAliasesEsRequestContext(actionRequest: IndicesAliasesRequest, if (originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala index 584c97e9f5..834bff8e8e 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala @@ -120,7 +120,7 @@ class MultiGetEsRequestContext(actionRequest: MultiGetRequest, case Nil => updateItemWithNonExistingIndex(item) case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } item.index(index.stringify) } diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala index 989956d79a..9e13edee8d 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala @@ -78,7 +78,7 @@ class MultiSearchEsRequestContext(actionRequest: MultiSearchRequest, } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala index 9191e33b66..5a61356f48 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala @@ -47,7 +47,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { request.getRequests.removeIf { request => removeOrAlter(request, filteredIndices.toCovariantSet) } if (request.getRequests.asScala.isEmpty) { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") ShouldBeInterrupted } else { Modified @@ -63,7 +63,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, true case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") } request.index(index.stringify) false diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala index c411df93c5..c7b99f6e85 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala @@ -52,7 +52,7 @@ class PutRollupJobEsRequestContext private(actionRequest: ActionRequest, if(originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala index ba5b52b4f1..f80e716349 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler.request.context.types import cats.data.NonEmptyList import cats.implicits.* import com.google.common.collect.Sets -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionRequest import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.AccessControlStaticContext @@ -51,7 +51,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (tryUpdate(actionRequest, filteredIndices)) Modified else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") ShouldBeInterrupted } } @@ -66,7 +66,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques } } -object ReflectionBasedIndicesEsRequestContext extends Logging { +object ReflectionBasedIndicesEsRequestContext extends RequestIdAwareLogging { def unapply(arg: ReflectionBasedActionRequest): Option[ReflectionBasedIndicesEsRequestContext] = { requestedIndicesFrom(arg.esContext.actionRequest) diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala index 489d0187bc..c42dfc3b78 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala @@ -58,10 +58,10 @@ class ReindexEsRequestContext(actionRequest: ReindexRequest, Modified } else { if (!isDestinationIndexOnFilteredIndicesList) { - logger.info(s"[${id.show}] Destination index of _reindex request is forbidden") + logger.info(s"Destination index of _reindex request is forbidden") } if (!isSearchRequestComposedOnlyOfAllowedIndices) { - logger.info(s"[${id.show}] At least one index from sources indices list of _reindex request is forbidden") + logger.info(s"At least one index from sources indices list of _reindex request is forbidden") } ShouldBeInterrupted } diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala index 2c1b0014e0..97b8ccd9c5 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala @@ -74,7 +74,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo request } case Left(_) => - logger.debug(s"[${id.show}] Cannot parse SQL statement - we can pass it though, because ES is going to reject it") + logger.debug(s"Cannot parse SQL statement - we can pass it though, because ES is going to reject it") request } } @@ -85,7 +85,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala index 0c67384c1e..d7e743e648 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CleanupRepositoryEsRequestContext(actionRequest: CleanupRepositoryRequest, override protected def update(request: CleanupRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala index 44b7d78dfd..d09015139b 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CreateRepositoryEsRequestContext(actionRequest: PutRepositoryRequest, override protected def update(request: PutRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala index eaf9334872..0cf32e1bea 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class DeleteRepositoryEsRequestContext(actionRequest: DeleteRepositoryRequest, override protected def update(request: DeleteRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala index cee0bffd4c..d1410eff3d 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class VerifyRepositoryEsRequestContext(actionRequest: VerifyRepositoryRequest, override protected def update(request: VerifyRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala index ead4fcf250..20501516d5 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala @@ -68,32 +68,32 @@ class CreateSnapshotEsRequestContext(actionRequest: CreateSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala index a56aba660e..621d744767 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala @@ -60,7 +60,7 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -71,14 +71,14 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, .toRight(()) } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala index 22869bbb4f..b81f333174 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala @@ -68,7 +68,7 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, case r => r } case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala index 88887db96c..156deb5b80 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala @@ -63,7 +63,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -75,7 +75,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") } Right(snapshot) } @@ -88,7 +88,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala index 44ee8397ec..e522e440f1 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala @@ -100,12 +100,12 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { val repositories = blockContext.repositories if (allRepositoriesRequested(repositories)) { Right(RepositoryName.All) @@ -115,7 +115,7 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala index 3acf4433cd..ea5c3297e1 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.GetComposableIndexTemplateAction import org.elasticsearch.cluster.metadata import org.elasticsearch.cluster.metadata.ComposableIndexTemplate @@ -108,7 +108,7 @@ class GetComposableIndexTemplateEsRequestContext(actionRequest: GetComposableInd } -private[templates] object GetComposableIndexTemplateEsRequestContext extends Logging { +private[templates] object GetComposableIndexTemplateEsRequestContext extends RequestIdAwareLogging { def filter(templates: Map[String, ComposableIndexTemplate], usingTemplate: Set[Template] => Set[Template]) diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala index bd74c3a18f..1c6eecf409 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.{GetIndexTemplatesRequest, GetIndexTemplatesResponse} import org.elasticsearch.cluster.metadata.{AliasMetadata, IndexTemplateMetadata} import org.elasticsearch.common.collect.ImmutableOpenMap @@ -104,7 +104,7 @@ class GetTemplatesEsRequestContext(actionRequest: GetIndexTemplatesRequest, } -private[templates] object GetTemplatesEsRequestContext extends Logging { +private[templates] object GetTemplatesEsRequestContext extends RequestIdAwareLogging { def filter(templates: Iterable[IndexTemplateMetadata], usingTemplate: Set[Template] => Set[Template]) diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala index a8951de5b1..32116d8212 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala @@ -72,7 +72,7 @@ class MultiSearchTemplateEsRequestContext private(actionRequest: ActionRequest w } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala index e6f6d8916e..434787a686 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala @@ -55,7 +55,7 @@ class SimulateIndexTemplateRequestEsRequestContext(actionRequest: SimulateIndexT filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateRequest(request, filteredIndices.head, allAllowedIndices) } diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala index fbc4cf6776..46ed6e7a95 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala @@ -109,7 +109,7 @@ class SimulateExistingTemplateRequestEsRequestContext(existingTemplateName: Temp case Some(_) => updateResponse(namePatterns.toList, blockContext.allAllowedIndices.toList) case None => - logger.info(s"[${id.show}] User has no access to template ${existingTemplateName.show}") + logger.info(s"User has no access to template ${existingTemplateName.show}") ModificationResult.ShouldBeInterrupted } case other => diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala index 0ecd7a72b3..fe4d60bd42 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.queries import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.index.query.* import org.joor.Reflect.on import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.RequestFieldsUsage @@ -30,7 +30,7 @@ trait QueryFieldsUsage[QUERY <: QueryBuilder] { def fieldsIn(query: QUERY): RequestFieldsUsage } -object QueryFieldsUsage extends Logging { +object QueryFieldsUsage extends RequestIdAwareLogging { def apply[QUERY <: QueryBuilder](implicit ev: QueryFieldsUsage[QUERY]): QueryFieldsUsage[QUERY] = ev implicit class Ops[QUERY <: QueryBuilder : QueryFieldsUsage](val query: QUERY) { @@ -62,7 +62,7 @@ object QueryFieldsUsage extends Logging { Option(on(query).call("getFieldName").get[String]) match { case Some(fieldName: String) => UsingFields(NonEmptyList.one(UsedField(fieldName))) case _ => - logger.debug(s"Cannot extract fields for terms set query") + noRequestIdLogger.debug(s"Cannot extract fields for terms set query") CannotExtractFields } } @@ -89,7 +89,7 @@ object QueryFieldsUsage extends Logging { case builder: TermsSetQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder: WildcardQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder => - logger.debug(s"Cannot extract fields for query: ${builder.getName}") + noRequestIdLogger.debug(s"Cannot extract fields for query: ${builder.getName}") CannotExtractFields } diff --git a/es813x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala b/es813x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala index 0998bb9a5b..b4671e9e4d 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.handler.response import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.FieldsRestrictions import tech.beshu.ror.accesscontrol.domain.Header @@ -26,17 +26,17 @@ import tech.beshu.ror.accesscontrol.headerValues.transientFieldsToHeaderValue import tech.beshu.ror.accesscontrol.request.RequestContext import tech.beshu.ror.implicits.* -object FLSContextHeaderHandler extends Logging { +object FLSContextHeaderHandler extends RequestIdAwareLogging { def addContextHeader(threadPool: ThreadPool, - fieldsRestrictions: FieldsRestrictions, - requestId: RequestContext.Id): Unit = { + fieldsRestrictions: FieldsRestrictions) + (implicit requestId: RequestContext.Id): Unit = { val threadContext = threadPool.getThreadContext val header = createContextHeader(fieldsRestrictions) Option(threadContext.getHeader(header.name.value.value)) match { case None => implicit val show = headerShow - logger.debug(s"[${requestId.show}] Adding thread context header required by lucene. Header: '${header.show}'") + logger.debug(s"Adding thread context header required by lucene. Header: '${header.show}'") threadContext.putHeader(header.name.value.value, header.value.value) case Some(_) => } diff --git a/es813x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala b/es813x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala index bc74ede825..f19ea37663 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.admin.indices.template.get.{GetComponentTemplateAction, GetComposableIndexTemplateAction} import org.elasticsearch.action.admin.indices.template.put.{PutComponentTemplateAction, TransportPutComposableIndexTemplateAction} @@ -46,7 +46,7 @@ import scala.jdk.CollectionConverters.* final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJsonParserFactory)(using Clock) extends DataStreamService - with Logging { + with RequestIdAwareLogging { override def checkDataStreamExists(dataStreamName: DataStreamName.Full): Task[Boolean] = execute { val request = new GetDataStreamAction.Request(List(dataStreamName.value.value).toArray) @@ -201,11 +201,11 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ response <- Task.measure( task = Task.delay(nodeClient.execute(action, request).actionGet()), logTimeMeasurement = duration => Task.delay { - logger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") + noRequestIdLogger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") } ) _ <- Task.delay { - logger.debug(s"Action ${action.name()} response: ${response.toString}") + noRequestIdLogger.debug(s"Action ${action.name()} response: ${response.toString}") } } yield response } @@ -213,7 +213,7 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ def executeAck[REQUEST <: ActionRequest, RESPONSE <: AcknowledgedResponse](action: ActionType[RESPONSE], request: REQUEST): Task[RESPONSE] = { executeT(action, request) - .tapEval(response => Task.delay(logger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) + .tapEval(response => Task.delay(noRequestIdLogger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) } private def supportedActions: Map[ActionType[ActionResponse], TransportAction[ActionRequest, ActionResponse]] = { diff --git a/es813x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala b/es813x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala index 2e75d37d0f..16259474bf 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.support.WriteRequest.RefreshPolicy import org.elasticsearch.client.internal.node.NodeClient @@ -38,7 +38,7 @@ import scala.jdk.CollectionConverters.* class EsIndexJsonContentService(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexJsonContentService - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -63,14 +63,14 @@ class EsIndexJsonContentService(client: NodeClient, Option(response.getSourceAsMap) match { case Some(map) => val source = map.asScala.toMap.asStringMap - logger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") Right(source) case None => - logger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") + noRequestIdLogger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") Right(Map.empty[String, String]) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(ContentNotFound) } } @@ -78,7 +78,7 @@ class EsIndexJsonContentService(client: NodeClient, .onErrorRecover { case _: ResourceNotFoundException => Left(ContentNotFound) case ex => - logger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) Left(CannotReachContentSource) } } @@ -104,14 +104,14 @@ class EsIndexJsonContentService(client: NodeClient, case status if status / 100 == 2 => Right(()) case status => - logger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") Left(CannotWriteToIndex) } } .executeOn(RorSchedulers.blockingScheduler) .onErrorRecover { case ex => - logger.error(s"Cannot write to document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]", ex) Left(CannotWriteToIndex) } } diff --git a/es813x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala b/es813x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala index daceff73d9..3ee915db0e 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala @@ -22,7 +22,7 @@ import cats.kernel.Monoid import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task import monix.execution.{CancelablePromise, Scheduler} -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction.{ResolvedAlias, ResolvedIndex} @@ -64,7 +64,7 @@ class EsServerBasedRorClusterService(nodeName: String, threadPool: ThreadPool) (implicit val scheduler: Scheduler) extends RorClusterService - with Logging { + with RequestIdAwareLogging { import EsServerBasedRorClusterService.* @@ -155,7 +155,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractAccessibilityFrom) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify get request. Blocking document", ex) + logger.error(s"Could not verify get request. Blocking document", ex)(id) Inaccessible } } @@ -167,7 +167,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractResultsFromSearchResponse) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify documents returned by multi get response. Blocking all returned documents", ex) + logger.error(s"Could not verify documents returned by multi get response. Blocking all returned documents", ex)(id) blockAllDocsReturned(documents) } .map(results => zip(results, documents)) @@ -276,7 +276,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService): Task[List[FullRemoteDataStreamWithAliases]] = { getRemoteClusterClient(remoteClusterService, remoteClusterName) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -332,7 +332,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService) = { getRemoteClusterClient(remoteClusterService, remoteClusterName) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -422,7 +422,7 @@ class EsServerBasedRorClusterService(nodeName: String, } } case None => - logger.error("Cannot supply Snapshots Service. Please, report the issue!!!") + noRequestIdLogger.error("Cannot supply Snapshots Service. Please, report the issue!!!") Task.now(Set.empty[Snapshot]) } } diff --git a/es813x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala b/es813x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala index a657d15ca9..31d96f15a2 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.services import cats.data.NonEmptyList -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.bulk.{BackoffPolicy, BulkProcessor, BulkRequest, BulkResponse} import org.elasticsearch.action.index.IndexRequest import org.elasticsearch.action.{ActionListener, DocWriteRequest} @@ -39,7 +39,7 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, (using Clock) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { private val bulkProcessor = BulkProcessor @@ -80,25 +80,25 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, private class AuditSinkBulkProcessorListener extends BulkProcessor.Listener { override def beforeBulk(executionId: Long, request: BulkRequest): Unit = { - logger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") + noRequestIdLogger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") } override def afterBulk(executionId: Long, request: BulkRequest, response: BulkResponse): Unit = { if (response.hasFailures) { - logger.error("Some failures flushing the BulkProcessor: ") + noRequestIdLogger.error("Some failures flushing the BulkProcessor: ") response .getItems.to(LazyList) .filter(_.isFailed) .map(_.getFailureMessage) .groupBy(identity) .foreach { case (message, stream) => - logger.error(s"${stream.size}x: $message") + noRequestIdLogger.error(s"${stream.size}x: $message") } } } override def afterBulk(executionId: Long, request: BulkRequest, failure: Throwable): Unit = { - logger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) + noRequestIdLogger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) } } diff --git a/es813x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala b/es813x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala index a8def0ec7a..b3c5593c36 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala @@ -22,7 +22,7 @@ import org.apache.http.auth.{AuthScope, Credentials, UsernamePasswordCredentials import org.apache.http.conn.ssl.NoopHostnameVerifier import org.apache.http.impl.client.BasicCredentialsProvider import org.apache.http.impl.nio.client.HttpAsyncClientBuilder -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.* import org.elasticsearch.client.RestClient.FailureListener import tech.beshu.ror.accesscontrol.audit.sink.AuditDataStreamCreator @@ -38,7 +38,7 @@ import scala.collection.parallel.CollectionConverters.* final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient]) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { override def submit(indexName: IndexName.Full, documentId: String, jsonRecord: String) (implicit requestId: RequestId): Unit = { @@ -77,21 +77,21 @@ final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient] override def onSuccess(response: Response): Unit = { response.getStatusLine.getStatusCode / 100 match { case 2 => // 2xx - logger.debug(s"[${requestId.show}] Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") + logger.debug(s"Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") case _ => - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") } } override def onFailure(ex: Exception): Unit = { - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId]", ex) + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId]", ex) } } override val dataStreamCreator: AuditDataStreamCreator = new AuditDataStreamCreator(clients.map(new RestClientDataStreamService(_))) } -object RestClientAuditSinkService extends Logging { +object RestClientAuditSinkService extends RequestIdAwareLogging { def create(remoteCluster: AuditCluster.RemoteAuditCluster): RestClientAuditSinkService = { remoteCluster.mode match { @@ -122,7 +122,7 @@ object RestClientAuditSinkService extends Logging { .setFailureListener( new FailureListener { override def onFailure(node: Node): Unit = { - logger.debug( + noRequestIdLogger.debug( s"[AUDIT] Node marked dead: ${node.getHost.getSchemeName}://${node.getHost.getHostName}:${node.getHost.getPort}. The client will attempt failover.", ) } diff --git a/es813x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala b/es813x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala index ce17639c06..b18c4fbfee 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.Channel import io.netty.handler.ssl.NotSslRecordException -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.network.NetworkService import org.elasticsearch.common.settings.{ClusterSettings, Settings} import org.elasticsearch.http.netty4.Netty4HttpServerTransport @@ -41,7 +41,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, tracer: Tracer, fipsCompliant: Boolean) extends Netty4HttpServerTransport(settings, networkService, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory, tracer, TLSConfig.noTLS(), null, null) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, ssl.clientAuthenticationEnabled) @@ -49,7 +49,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, override def onException(channel: HttpChannel, cause: Exception): Unit = { if (!this.lifecycle.started) return - else if (cause.getCause.isInstanceOf[NotSslRecordException]) logger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) + else if (cause.getCause.isInstanceOf[NotSslRecordException]) noRequestIdLogger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) else super.onException(channel, cause) channel.close() } diff --git a/es813x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala b/es813x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala index 2fa1d7871c..2d2b0360d4 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.* import io.netty.handler.ssl.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.TransportVersion import org.elasticsearch.cluster.node.DiscoveryNode import org.elasticsearch.common.io.stream.NamedWriteableRegistry @@ -46,7 +46,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, sharedGroupFactory: SharedGroupFactory, fipsCompliant: Boolean) extends Netty4Transport(settings, TransportVersion.current(), threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = SSLCertHelper.prepareClientSSLContext(ssl, fipsCompliant, ssl.certificateVerificationEnabled) private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, clientAuthenticationEnabled = false) @@ -78,7 +78,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, override def exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable): Unit = { if (cause.isInstanceOf[NotSslRecordException] || (cause.getCause != null && cause.getCause.isInstanceOf[NotSslRecordException])) { - logger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") + noRequestIdLogger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") ctx.channel.close } else { super.exceptionCaught(ctx, cause) diff --git a/es813x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala b/es813x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala index 1a8804e4b7..84979960e0 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.utils import cats.Show import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.client.internal.node.NodeClient import org.elasticsearch.rest.* @@ -37,7 +37,7 @@ import java.util import scala.util.Try class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandler) - extends RestHandler with Logging { + extends RestHandler with RequestIdAwareLogging { private val wrapped = doPrivileged { wrapSomeActions(underlying) @@ -103,11 +103,11 @@ class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandle private def logError(error: AuthorizationValueError): Unit = { { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorSanitizedShow - logger.warn(s"The incoming request was malformed. Cause: ${error.show}") + noRequestIdLogger.warn(s"The incoming request was malformed. Cause: ${error.show}") } if (logger.delegate.isDebugEnabled()) { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorWithDetailsShow - logger.debug(s"Malformed request detailed cause: ${error.show}") + noRequestIdLogger.debug(s"Malformed request detailed cause: ${error.show}") } } diff --git a/es813x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala b/es813x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala index 5ab1e35742..a9af8f710a 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala @@ -16,13 +16,13 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.settings.Settings import tech.beshu.ror.tools.core.patches.PatchingVerifier import tech.beshu.ror.tools.core.patches.PatchingVerifier.Error.{CannotVerifyIfPatched, EsNotPatched} import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -object EsPatchVerifier extends Logging { +object EsPatchVerifier extends RequestIdAwareLogging { def verify(settings: Settings): Unit = doPrivileged { pathHomeFrom(settings).flatMap(PatchingVerifier.verify) match { @@ -30,7 +30,7 @@ object EsPatchVerifier extends Logging { case Left(e@EsNotPatched(_)) => throw new IllegalStateException(e.message) case Left(e@CannotVerifyIfPatched(_)) => - logger.warn(e.message) + noRequestIdLogger.warn(e.message) } } diff --git a/es813x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala b/es813x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala index 639aeb5029..893d807108 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.repositories.{RepositoriesService, VerifyNodeRepositoryAction} import org.elasticsearch.transport.{RemoteClusterService, TransportService} import org.joor.Reflect.on @@ -26,7 +26,7 @@ import java.util.function.Supplier import scala.util.{Failure, Success, Try} class RemoteClusterServiceSupplier(repositoriesServiceSupplier: Supplier[RepositoriesService]) - extends Supplier[Option[RemoteClusterService]] with Logging { + extends Supplier[Option[RemoteClusterService]] with RequestIdAwareLogging { override def get(): Option[RemoteClusterService] = { for { @@ -35,7 +35,7 @@ class RemoteClusterServiceSupplier(repositoriesServiceSupplier: Supplier[Reposit case Success(transportService) => Option(transportService.getRemoteClusterService) case Failure(ex) => - logger.error("Cannot extract RemoteClusterService from RepositoriesService", ex) + noRequestIdLogger.error("Cannot extract RemoteClusterService from RepositoriesService", ex) None } } yield remoteClusterService diff --git a/es814x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es814x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index 07d70bbf05..978eebec5d 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.support.{ActionFilter, ActionFilterChain} import org.elasticsearch.action.{ActionListener, ActionRequest, ActionResponse} import org.elasticsearch.client.internal.node.NodeClient @@ -62,7 +62,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, rorEsConfig: ReadonlyRestEsConfig) (implicit environmentConfig: EnvironmentConfig) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = environmentConfig.uniqueIdentifierGenerator @@ -211,12 +211,12 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def handleRorNotReadyYet(esContext: EsContext): Unit = { - logger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") + noRequestIdLogger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") rorNotAvailableRequestHandler.handleRorNotReadyYet(esContext) } private def handleRorFailedToStart(esContext: EsContext): Unit = { - logger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") + noRequestIdLogger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") rorNotAvailableRequestHandler.handleRorFailedToStart(esContext) } @@ -238,7 +238,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def logAndSetStartingFailureState(failure: StartingFailure): Unit = { - logger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) + noRequestIdLogger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) rorInstanceState.set(RorInstanceStartingState.NotStarted(failure)) } } diff --git a/es814x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala b/es814x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala index 1fb22fc79d..53452eb8e6 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.xcontent.LoggingDeprecationHandler import org.elasticsearch.rest.RestResponse import org.elasticsearch.transport.BytesRefRecycler @@ -32,7 +32,7 @@ import tech.beshu.ror.accesscontrol.domain.ResponseFieldsFiltering.{AccessMode, import scala.jdk.CollectionConverters.* trait ResponseFieldsFiltering { - this: Logging => + this: RequestIdAwareLogging => private val responseFieldsRestrictions: Atomic[Option[ResponseFieldsRestrictions]] = Atomic(None: Option[ResponseFieldsRestrictions]) diff --git a/es814x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala b/es814x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala index 0f26750588..da95de59a4 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.action.{ActionListener, ActionResponse} import org.elasticsearch.threadpool.ThreadPool @@ -37,7 +37,7 @@ sealed abstract class RorActionListener[T](val underlying: ActionListener[T]) ex final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionListener[T], correlationId: Eval[CorrelationId]) - extends RorActionListener[T](underlying) with Logging { + extends RorActionListener[T](underlying) with RequestIdAwareLogging { override def onFailure(e: Exception): Unit = { super.onFailure(adaptExceptionIfNeeded(e)) @@ -47,7 +47,7 @@ final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionLis ex match { case esException: ElasticsearchException => esException case other => - logger.error(s"[${correlationId.value.show}] Internal error.", other) + noRequestIdLogger.error(s"[${correlationId.value.show}] Internal error.", other) new ElasticsearchException(s"[${correlationId.value.show}] Internal error. See logs for details.") } } diff --git a/es814x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala b/es814x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala index 75048ebe7d..14e5e31c1b 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.http.HttpChannel import org.elasticsearch.rest.{AbstractRestChannel, RestChannel as EsRestChannel, RestRequest as EsRestRequest, RestResponse as EsRestResponse} import squants.information.{Bytes, Information} @@ -40,7 +40,7 @@ object RorRestChannel { final class RorRestChannel private(underlying: EsRestChannel, val restRequest: RorRestRequest) extends AbstractRestChannel(underlying.request(), true) with ResponseFieldsFiltering - with Logging { + with RequestIdAwareLogging { override def sendResponse(response: EsRestResponse): Unit = { ThreadRepo.removeRestChannel(this) diff --git a/es814x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala b/es814x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala index 6babc712b9..3c80750a25 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala @@ -18,16 +18,15 @@ package tech.beshu.ror.es.actions.rradmin import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.ConfigApi.ConfigResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAdminActionHandler extends Logging { +class RRAdminActionHandler extends RequestIdAwareLogging { private implicit val adminRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +51,7 @@ class RRAdminActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAdminResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAdminAction internal error", ex) + logger.error("RRAdminAction internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es814x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala b/es814x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala index c55835a1d0..ce45c6f48e 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala @@ -16,18 +16,15 @@ */ package tech.beshu.ror.es.actions.rrauthmock -import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.AuthMockApi.AuthMockResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier -import tech.beshu.ror.implicits.* +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAuthMockActionHandler extends Logging { +class RRAuthMockActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -53,7 +50,7 @@ class RRAuthMockActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAuthMockResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAuthMock internal error", ex) + logger.error("RRAuthMock internal error", ex) listener.onFailure(new Exception(ex)) } } diff --git a/es814x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala b/es814x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala index aa8bb31e67..640084c4ec 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestconfig import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.TestConfigApi.TestConfigResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestConfigActionHandler extends Logging { +class RRTestConfigActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +52,7 @@ class RRTestConfigActionHandler extends Logging { case Right(response) => listener.onResponse(new RRTestConfigResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRTestConfig internal error", ex) + logger.error(s"RRTestConfig internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es814x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala b/es814x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala index 494e9150b4..98cc0c945d 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.dlsfls import cats.data.StateT import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.DirectoryReader import org.elasticsearch.common.util.concurrent.ThreadContext import org.elasticsearch.core.CheckedFunction @@ -31,7 +31,7 @@ import java.io.IOException import java.util.function.{Function => JavaFunction} import scala.util.{Failure, Success, Try} -object RoleIndexSearcherWrapper extends Logging { +object RoleIndexSearcherWrapper extends RequestIdAwareLogging { val instance: JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] = new JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] { @@ -54,7 +54,7 @@ object RoleIndexSearcherWrapper extends Logging { } .map(r => (r, r)) case None => - logger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") + noRequestIdLogger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") Success((reader, reader)) } } @@ -66,13 +66,13 @@ object RoleIndexSearcherWrapper extends Logging { nel <- NonEmptyString.from(value) match { case Right(nel) => Success(nel) case Left(_) => - logger.debug("FLS: empty header value") + noRequestIdLogger.debug("FLS: empty header value") failure } fields <- transientFieldsFromHeaderValue.fromRawValue(nel) match { case result@Success(_) => result case Failure(ex) => - logger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) + noRequestIdLogger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) failure } } yield fields diff --git a/es814x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala b/es814x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala index ce77d77f4e..aeccbfcead 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.dlsfls import com.google.common.collect.Iterators -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.codecs.StoredFieldsReader import org.apache.lucene.index.* import org.apache.lucene.index.StoredFieldVisitor.Status @@ -39,21 +39,21 @@ import scala.jdk.CollectionConverters.* import scala.util.Try private class RorDocumentFieldReader(reader: LeafReader, fieldsRestrictions: FieldsRestrictions) - extends SequentialStoredFieldsLeafReader(reader) with Logging { + extends SequentialStoredFieldsLeafReader(reader) with RequestIdAwareLogging { private val policy = new FieldsPolicy(fieldsRestrictions) private val remainingFieldsInfo = { val fInfos = in.getFieldInfos val newInfos = if (fInfos.asScala.isEmpty) { - logger.warn("original fields were empty! This is weird!") + noRequestIdLogger.warn("original fields were empty! This is weird!") fInfos } else { val remainingFields = fInfos.asScala.filter(f => policy.canKeep(f.name)).toSet new FieldInfos(remainingFields.toArray) } - logger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") - logger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") - logger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") + noRequestIdLogger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") newInfos } private val jsonPolicyBasedFilterer = new JsonPolicyBasedFilterer(policy) diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala index 9365230fe3..9abe861fe3 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.* import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest import org.elasticsearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest @@ -87,7 +87,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, threadPool: ThreadPool) (implicit generator: UniqueIdentifierGenerator, scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle(engines: Engines, esContext: EsContext): Task[Either[Error, Unit]] = { @@ -243,7 +243,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, case SearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case MultiSearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case _ => - logger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") + noRequestIdLogger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") regularRequestHandler.handle(new DummyCompositeIndicesEsRequestContext(request, esContext, aclContext, clusterService, threadPool)) } // rest diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala index cab02aff37..100edd72ac 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.common.io.stream.StreamOutput import org.elasticsearch.xcontent.{ToXContent, ToXContentObject, XContentBuilder} @@ -45,7 +45,7 @@ import scala.util.{Failure, Success, Try} class CurrentUserMetadataRequestHandler(engine: Engine, esContext: EsContext) - extends Logging { + extends RequestIdAwareLogging { def handle(request: RequestContext.Aux[CurrentUserMetadataRequestBlockContext] with EsRequest[CurrentUserMetadataRequestBlockContext]): Task[Unit] = { engine.core.accessControl @@ -69,7 +69,7 @@ class CurrentUserMetadataRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(ex.asInstanceOf[Exception]) } } @@ -86,13 +86,13 @@ class CurrentUserMetadataRequestHandler(engine: Engine, )) } - private def onPassThrough(requestContext: RequestContext): Unit = { - logger.warn(s"[${requestContext.id.toRequestId.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") + private def onPassThrough(implicit requestContext: RequestContext): Unit = { + logger.warn(s"Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") esContext.listener.onFailure(createRorNotEnabledResponse()) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala index 2fb01dcc41..c5c44fda92 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala @@ -20,7 +20,7 @@ import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.RegularRequestResult @@ -49,7 +49,7 @@ class RegularRequestHandler(engine: Engine, esContext: EsContext, threadPool: ThreadPool) (implicit scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle[B <: BlockContext : BlockContextUpdater](request: RequestContext.Aux[B] with EsRequest[B]): Task[Unit] = { engine.core.accessControl @@ -85,7 +85,7 @@ class RegularRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(new Exception(ex)) } } @@ -99,7 +99,7 @@ class RegularRequestHandler(engine: Engine, case ModificationResult.ShouldBeInterrupted => onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case ModificationResult.CannotModify => - logger.error(s"[${request.id.toRequestId.show}] Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") + noRequestIdLogger.error(s"Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case CustomResponse(response) => respond(request, response) @@ -247,7 +247,7 @@ class RegularRequestHandler(engine: Engine, esContext.listener.onResponse(response) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } \ No newline at end of file diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala index f4f832dedc..bfc421bdd5 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.index.query.{AbstractQueryBuilder, QueryBuilder, QueryBuilders} import org.elasticsearch.search.aggregations.AggregatorFactories @@ -40,7 +40,7 @@ import tech.beshu.ror.implicits.* import java.util.UUID import scala.jdk.CollectionConverters.* -object SearchRequestOps extends Logging { +object SearchRequestOps extends RequestIdAwareLogging { implicit class QueryBuilderOps(val builder: Option[QueryBuilder]) extends AnyVal { @@ -52,7 +52,7 @@ object SearchRequestOps extends Logging { val modifiedQuery: AbstractQueryBuilder[_] = provideNewQueryWithAppliedFilter(builder, filterQuery) Some(modifiedQuery) case None => - logger.debug(s"[${requestId.show}] No filter applied to query.") + logger.debug(s"No filter applied to query.") builder } } @@ -92,7 +92,7 @@ object SearchRequestOps extends Logging { case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, requestId) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) disableCaching(requestId) case BasedOnBlockContextOnly.NotAllowedFieldsUsed(notAllowedFields) => modifyNotAllowedFieldsInRequest(notAllowedFields) @@ -138,8 +138,8 @@ object SearchRequestOps extends Logging { } } - private def disableCaching(requestId: RequestContext.Id) = { - logger.debug(s"[${requestId.show}] ACL uses context header for fields rule, will disable request cache for SearchRequest") + private def disableCaching(implicit requestId: RequestContext.Id) = { + logger.debug(s"ACL uses context header for fields rule, will disable request cache for SearchRequest") request.requestCache(false) } } diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala index 993bdbd7a0..f0d04a6837 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala @@ -17,7 +17,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.action.{CompositeIndicesRequest, IndicesRequest} import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -32,7 +31,7 @@ import java.time.Instant abstract class BaseEsRequestContext[B <: BlockContext](esContext: EsContext, clusterService: RorClusterService) - extends RequestContext with Logging { + extends RequestContext { override type BLOCK_CONTEXT = B diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala index ae8abbe1f5..0ee2967364 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala @@ -18,7 +18,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -26,8 +25,9 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import scala.util.Try +import tech.beshu.ror.utils.RequestIdAwareLogging -trait EsRequest[B <: BlockContext] extends Logging { +trait EsRequest[B <: BlockContext] extends RequestIdAwareLogging { implicit def threadPool: ThreadPool final def modifyUsing(blockContext: B): ModificationResult = { @@ -35,7 +35,7 @@ trait EsRequest[B <: BlockContext] extends Logging { Try(modifyRequest(blockContext)) .fold( ex => { - logger.error(s"[${blockContext.requestContext.id.show}] Cannot modify request with filtered data", ex) + logger.error(s"Cannot modify request with filtered data", ex)(blockContext) ModificationResult.CannotModify }, identity diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala index c6a9dcbefd..f773b3efb1 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala @@ -51,7 +51,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest private def discoverDataStreams() = { val dataStreams = dataStreamsFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered data streams: ${dataStreams.show}") + logger.debug(s"Discovered data streams: ${dataStreams.show}") dataStreams } @@ -59,7 +59,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest val backingIndices = backingIndicesFrom(actionRequest) backingIndices match { case BackingIndices.IndicesInvolved(filteredIndices, _) => - logger.debug(s"[${id.show}] Discovered indices: ${filteredIndices.show}") + logger.debug(s"Discovered indices: ${filteredIndices.show}") case BackingIndices.IndicesNotInvolved => } backingIndices diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala index c091179cb6..d150709314 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala @@ -85,7 +85,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: case Some(indices) => update(actionRequest, indices, blockContext.filter, blockContext.fieldLevelSecurity) case None => - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -101,7 +101,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } \ No newline at end of file diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala index 71d462de57..48014e1bdc 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala @@ -73,7 +73,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, } yield update(actionRequest, filteredIndices, allAllowedIndices) result.getOrElse { - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -86,7 +86,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala index 95d882c3b5..f607c0e347 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala @@ -50,7 +50,7 @@ abstract class BaseRepositoriesEsRequestContext[R <: ActionRequest](actionReques case Some(repositories) => update(actionRequest, repositories) case None => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") ShouldBeInterrupted } } diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala index b3b1d66238..7ef0f32014 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala @@ -42,7 +42,7 @@ abstract class BaseSingleIndexEsRequestContext[R <: ActionRequest](actionRequest filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } update(request, filteredIndices.head) } diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala index b5ab70fe7a..c1b2e7ea27 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala @@ -62,7 +62,7 @@ class BulkEsRequestContext(actionRequest: BulkRequest, case (_, _) => ShouldBeInterrupted } } else { - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because origin request contained different " + + logger.error(s"Cannot alter MultiGetRequest request, because origin request contained different " + s"number of requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } @@ -90,18 +90,18 @@ class BulkEsRequestContext(actionRequest: BulkRequest, updateRequestWithIndices(request, nel) Modified case None => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because empty list of indices was found") + logger.error(s"Cannot alter MultiGetRequest request, because empty list of indices was found") ShouldBeInterrupted } case Indices.NotFound => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because no allowed indices were found") + logger.error(s"Cannot alter MultiGetRequest request, because no allowed indices were found") ShouldBeInterrupted } } private def updateRequestWithIndices(request: DocWriteRequest[_], indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } request.index(indices.head.stringify) } diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala index 75a75fcef5..96a043b298 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala @@ -53,14 +53,14 @@ class BulkShardEsRequestContext(actionRequest: BulkShardRequest, case Success(_) => Modified case Failure(ex) => - logger.error(s"[${id.show}] Cannot modify BulkShardRequest", ex) + logger.error(s"Cannot modify BulkShardRequest", ex) CannotModify } } private def tryUpdate(request: BulkShardRequest, indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } val singleIndex = indices.head val uuid = clusterService.indexOrAliasUuids(singleIndex.name).toList.head diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala index 65a168092a..158ac485a5 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala @@ -45,14 +45,14 @@ class ClusterAllocationExplainEsRequestContext(actionRequest: ClusterAllocationE getRequestedIndexFrom(request) match { case Some(_) => if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateIndexIn(request, filteredIndices.head) Modified case None if filteredIndices.exists(_.name === ClusterIndexName.Local.wildcard) => Modified case None => - logger.error(s"[${id.show}] Cluster allocation explain request without index name is unavailable when block contains `indices` rule") + logger.error(s"Cluster allocation explain request without index name is unavailable when block contains `indices` rule") ShouldBeInterrupted } } diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala index 61fdab9d83..5bf09449c5 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala @@ -79,7 +79,7 @@ class EsqlIndicesEsRequestContext private(actionRequest: ActionRequest with Comp request } case Left(ClassificationError.ParsingException(ex)) => - logger.debug(s"[${id.show}] Cannot parse ESQL statement - we can pass it though, because ES is going to reject it. Cause:", ex) + logger.debug(s"Cannot parse ESQL statement - we can pass it though, because ES is going to reject it. Cause:", ex) request } } @@ -90,7 +90,7 @@ class EsqlIndicesEsRequestContext private(actionRequest: ActionRequest with Comp case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala index 5778b8968d..02dec730ed 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala @@ -66,7 +66,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, updateAliases(actionRequest, aliases) UpdateResponse.sync(updateAliasesResponse(aliases.includedOnly, _)) case None => - logger.error(s"[${id.show}] At least one alias and one index has to be allowed. " + + logger.error(s"At least one alias and one index has to be allowed. " + s"Found allowed indices: [${blockContext.indices.show}]." + s"Found allowed aliases: [${blockContext.aliases.show}]") ShouldBeInterrupted @@ -114,7 +114,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, .indices().asSafeSet .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } @@ -122,7 +122,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, val aliases = rawRequestAliasesSet(request) .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered aliases: ${aliases.show}") + logger.debug(s"Discovered aliases: ${aliases.show}") aliases } diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala index abb85d42b7..f9e2c87e53 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala @@ -55,7 +55,7 @@ class IndicesAliasesEsRequestContext(actionRequest: IndicesAliasesRequest, if (originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala index 584c97e9f5..834bff8e8e 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala @@ -120,7 +120,7 @@ class MultiGetEsRequestContext(actionRequest: MultiGetRequest, case Nil => updateItemWithNonExistingIndex(item) case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } item.index(index.stringify) } diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala index 989956d79a..9e13edee8d 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala @@ -78,7 +78,7 @@ class MultiSearchEsRequestContext(actionRequest: MultiSearchRequest, } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala index 9191e33b66..5a61356f48 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala @@ -47,7 +47,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { request.getRequests.removeIf { request => removeOrAlter(request, filteredIndices.toCovariantSet) } if (request.getRequests.asScala.isEmpty) { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") ShouldBeInterrupted } else { Modified @@ -63,7 +63,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, true case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") } request.index(index.stringify) false diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala index c411df93c5..c7b99f6e85 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala @@ -52,7 +52,7 @@ class PutRollupJobEsRequestContext private(actionRequest: ActionRequest, if(originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala index ba5b52b4f1..f80e716349 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler.request.context.types import cats.data.NonEmptyList import cats.implicits.* import com.google.common.collect.Sets -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionRequest import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.AccessControlStaticContext @@ -51,7 +51,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (tryUpdate(actionRequest, filteredIndices)) Modified else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") ShouldBeInterrupted } } @@ -66,7 +66,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques } } -object ReflectionBasedIndicesEsRequestContext extends Logging { +object ReflectionBasedIndicesEsRequestContext extends RequestIdAwareLogging { def unapply(arg: ReflectionBasedActionRequest): Option[ReflectionBasedIndicesEsRequestContext] = { requestedIndicesFrom(arg.esContext.actionRequest) diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala index 489d0187bc..c42dfc3b78 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala @@ -58,10 +58,10 @@ class ReindexEsRequestContext(actionRequest: ReindexRequest, Modified } else { if (!isDestinationIndexOnFilteredIndicesList) { - logger.info(s"[${id.show}] Destination index of _reindex request is forbidden") + logger.info(s"Destination index of _reindex request is forbidden") } if (!isSearchRequestComposedOnlyOfAllowedIndices) { - logger.info(s"[${id.show}] At least one index from sources indices list of _reindex request is forbidden") + logger.info(s"At least one index from sources indices list of _reindex request is forbidden") } ShouldBeInterrupted } diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala index 2c1b0014e0..97b8ccd9c5 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala @@ -74,7 +74,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo request } case Left(_) => - logger.debug(s"[${id.show}] Cannot parse SQL statement - we can pass it though, because ES is going to reject it") + logger.debug(s"Cannot parse SQL statement - we can pass it though, because ES is going to reject it") request } } @@ -85,7 +85,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala index 0c67384c1e..d7e743e648 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CleanupRepositoryEsRequestContext(actionRequest: CleanupRepositoryRequest, override protected def update(request: CleanupRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala index 44b7d78dfd..d09015139b 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CreateRepositoryEsRequestContext(actionRequest: PutRepositoryRequest, override protected def update(request: PutRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala index eaf9334872..0cf32e1bea 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class DeleteRepositoryEsRequestContext(actionRequest: DeleteRepositoryRequest, override protected def update(request: DeleteRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala index cee0bffd4c..d1410eff3d 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class VerifyRepositoryEsRequestContext(actionRequest: VerifyRepositoryRequest, override protected def update(request: VerifyRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala index ead4fcf250..20501516d5 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala @@ -68,32 +68,32 @@ class CreateSnapshotEsRequestContext(actionRequest: CreateSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala index a56aba660e..621d744767 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala @@ -60,7 +60,7 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -71,14 +71,14 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, .toRight(()) } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala index 22869bbb4f..b81f333174 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala @@ -68,7 +68,7 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, case r => r } case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala index 88887db96c..156deb5b80 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala @@ -63,7 +63,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -75,7 +75,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") } Right(snapshot) } @@ -88,7 +88,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala index 44ee8397ec..e522e440f1 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala @@ -100,12 +100,12 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { val repositories = blockContext.repositories if (allRepositoriesRequested(repositories)) { Right(RepositoryName.All) @@ -115,7 +115,7 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala index 3a9be2dd6c..f306a2252d 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.rollover.RolloverConfiguration import org.elasticsearch.action.admin.indices.template.get.GetComposableIndexTemplateAction import org.elasticsearch.cluster.metadata @@ -112,7 +112,7 @@ class GetComposableIndexTemplateEsRequestContext(actionRequest: GetComposableInd } -private[templates] object GetComposableIndexTemplateEsRequestContext extends Logging { +private[templates] object GetComposableIndexTemplateEsRequestContext extends RequestIdAwareLogging { def filter(templates: Map[String, ComposableIndexTemplate], usingTemplate: Set[Template] => Set[Template]) diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala index bd74c3a18f..1c6eecf409 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.{GetIndexTemplatesRequest, GetIndexTemplatesResponse} import org.elasticsearch.cluster.metadata.{AliasMetadata, IndexTemplateMetadata} import org.elasticsearch.common.collect.ImmutableOpenMap @@ -104,7 +104,7 @@ class GetTemplatesEsRequestContext(actionRequest: GetIndexTemplatesRequest, } -private[templates] object GetTemplatesEsRequestContext extends Logging { +private[templates] object GetTemplatesEsRequestContext extends RequestIdAwareLogging { def filter(templates: Iterable[IndexTemplateMetadata], usingTemplate: Set[Template] => Set[Template]) diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala index a8951de5b1..32116d8212 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala @@ -72,7 +72,7 @@ class MultiSearchTemplateEsRequestContext private(actionRequest: ActionRequest w } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala index e6f6d8916e..434787a686 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala @@ -55,7 +55,7 @@ class SimulateIndexTemplateRequestEsRequestContext(actionRequest: SimulateIndexT filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateRequest(request, filteredIndices.head, allAllowedIndices) } diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala index fbc4cf6776..46ed6e7a95 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala @@ -109,7 +109,7 @@ class SimulateExistingTemplateRequestEsRequestContext(existingTemplateName: Temp case Some(_) => updateResponse(namePatterns.toList, blockContext.allAllowedIndices.toList) case None => - logger.info(s"[${id.show}] User has no access to template ${existingTemplateName.show}") + logger.info(s"User has no access to template ${existingTemplateName.show}") ModificationResult.ShouldBeInterrupted } case other => diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala index 0ecd7a72b3..fe4d60bd42 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.queries import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.index.query.* import org.joor.Reflect.on import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.RequestFieldsUsage @@ -30,7 +30,7 @@ trait QueryFieldsUsage[QUERY <: QueryBuilder] { def fieldsIn(query: QUERY): RequestFieldsUsage } -object QueryFieldsUsage extends Logging { +object QueryFieldsUsage extends RequestIdAwareLogging { def apply[QUERY <: QueryBuilder](implicit ev: QueryFieldsUsage[QUERY]): QueryFieldsUsage[QUERY] = ev implicit class Ops[QUERY <: QueryBuilder : QueryFieldsUsage](val query: QUERY) { @@ -62,7 +62,7 @@ object QueryFieldsUsage extends Logging { Option(on(query).call("getFieldName").get[String]) match { case Some(fieldName: String) => UsingFields(NonEmptyList.one(UsedField(fieldName))) case _ => - logger.debug(s"Cannot extract fields for terms set query") + noRequestIdLogger.debug(s"Cannot extract fields for terms set query") CannotExtractFields } } @@ -89,7 +89,7 @@ object QueryFieldsUsage extends Logging { case builder: TermsSetQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder: WildcardQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder => - logger.debug(s"Cannot extract fields for query: ${builder.getName}") + noRequestIdLogger.debug(s"Cannot extract fields for query: ${builder.getName}") CannotExtractFields } diff --git a/es814x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala b/es814x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala index 0998bb9a5b..b4671e9e4d 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.handler.response import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.FieldsRestrictions import tech.beshu.ror.accesscontrol.domain.Header @@ -26,17 +26,17 @@ import tech.beshu.ror.accesscontrol.headerValues.transientFieldsToHeaderValue import tech.beshu.ror.accesscontrol.request.RequestContext import tech.beshu.ror.implicits.* -object FLSContextHeaderHandler extends Logging { +object FLSContextHeaderHandler extends RequestIdAwareLogging { def addContextHeader(threadPool: ThreadPool, - fieldsRestrictions: FieldsRestrictions, - requestId: RequestContext.Id): Unit = { + fieldsRestrictions: FieldsRestrictions) + (implicit requestId: RequestContext.Id): Unit = { val threadContext = threadPool.getThreadContext val header = createContextHeader(fieldsRestrictions) Option(threadContext.getHeader(header.name.value.value)) match { case None => implicit val show = headerShow - logger.debug(s"[${requestId.show}] Adding thread context header required by lucene. Header: '${header.show}'") + logger.debug(s"Adding thread context header required by lucene. Header: '${header.show}'") threadContext.putHeader(header.name.value.value, header.value.value) case Some(_) => } diff --git a/es814x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala b/es814x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala index bc74ede825..f19ea37663 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.admin.indices.template.get.{GetComponentTemplateAction, GetComposableIndexTemplateAction} import org.elasticsearch.action.admin.indices.template.put.{PutComponentTemplateAction, TransportPutComposableIndexTemplateAction} @@ -46,7 +46,7 @@ import scala.jdk.CollectionConverters.* final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJsonParserFactory)(using Clock) extends DataStreamService - with Logging { + with RequestIdAwareLogging { override def checkDataStreamExists(dataStreamName: DataStreamName.Full): Task[Boolean] = execute { val request = new GetDataStreamAction.Request(List(dataStreamName.value.value).toArray) @@ -201,11 +201,11 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ response <- Task.measure( task = Task.delay(nodeClient.execute(action, request).actionGet()), logTimeMeasurement = duration => Task.delay { - logger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") + noRequestIdLogger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") } ) _ <- Task.delay { - logger.debug(s"Action ${action.name()} response: ${response.toString}") + noRequestIdLogger.debug(s"Action ${action.name()} response: ${response.toString}") } } yield response } @@ -213,7 +213,7 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ def executeAck[REQUEST <: ActionRequest, RESPONSE <: AcknowledgedResponse](action: ActionType[RESPONSE], request: REQUEST): Task[RESPONSE] = { executeT(action, request) - .tapEval(response => Task.delay(logger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) + .tapEval(response => Task.delay(noRequestIdLogger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) } private def supportedActions: Map[ActionType[ActionResponse], TransportAction[ActionRequest, ActionResponse]] = { diff --git a/es814x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala b/es814x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala index 5e693123f3..306b486823 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.support.WriteRequest.RefreshPolicy import org.elasticsearch.client.internal.node.NodeClient @@ -37,7 +37,7 @@ import scala.jdk.CollectionConverters.* class EsIndexJsonContentService(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexJsonContentService - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -62,14 +62,14 @@ class EsIndexJsonContentService(client: NodeClient, Option(response.getSourceAsMap) match { case Some(map) => val source = map.asScala.toMap.asStringMap - logger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") Right(source) case None => - logger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") + noRequestIdLogger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") Right(Map.empty[String, String]) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(ContentNotFound) } } @@ -77,7 +77,7 @@ class EsIndexJsonContentService(client: NodeClient, .onErrorRecover { case _: ResourceNotFoundException => Left(ContentNotFound) case ex => - logger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) Left(CannotReachContentSource) } } @@ -103,14 +103,14 @@ class EsIndexJsonContentService(client: NodeClient, case status if status / 100 == 2 => Right(()) case status => - logger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") Left(CannotWriteToIndex) } } .executeOn(RorSchedulers.blockingScheduler) .onErrorRecover { case ex => - logger.error(s"Cannot write to document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]", ex) Left(CannotWriteToIndex) } } diff --git a/es814x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala b/es814x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala index 2a2669e8b4..619cb6daf2 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala @@ -22,7 +22,7 @@ import cats.kernel.Monoid import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task import monix.execution.{CancelablePromise, Scheduler} -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction.{ResolvedAlias, ResolvedIndex} @@ -65,7 +65,7 @@ class EsServerBasedRorClusterService(nodeName: String, threadPool: ThreadPool) (implicit val scheduler: Scheduler) extends RorClusterService - with Logging { + with RequestIdAwareLogging { import EsServerBasedRorClusterService.* @@ -156,7 +156,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractAccessibilityFrom) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify get request. Blocking document", ex) + logger.error(s"Could not verify get request. Blocking document", ex)(id) Inaccessible } } @@ -168,7 +168,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractResultsFromSearchResponse) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify documents returned by multi get response. Blocking all returned documents", ex) + logger.error(s"Could not verify documents returned by multi get response. Blocking all returned documents", ex)(id) blockAllDocsReturned(documents) } .map(results => zip(results, documents)) @@ -277,7 +277,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService): Task[List[FullRemoteDataStreamWithAliases]] = { getRemoteClusterClient(remoteClusterService, remoteClusterName) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -333,7 +333,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService) = { getRemoteClusterClient(remoteClusterService, remoteClusterName) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -423,7 +423,7 @@ class EsServerBasedRorClusterService(nodeName: String, } } case None => - logger.error("Cannot supply Snapshots Service. Please, report the issue!!!") + noRequestIdLogger.error("Cannot supply Snapshots Service. Please, report the issue!!!") Task.now(Set.empty[Snapshot]) } } diff --git a/es814x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala b/es814x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala index a657d15ca9..31d96f15a2 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.services import cats.data.NonEmptyList -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.bulk.{BackoffPolicy, BulkProcessor, BulkRequest, BulkResponse} import org.elasticsearch.action.index.IndexRequest import org.elasticsearch.action.{ActionListener, DocWriteRequest} @@ -39,7 +39,7 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, (using Clock) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { private val bulkProcessor = BulkProcessor @@ -80,25 +80,25 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, private class AuditSinkBulkProcessorListener extends BulkProcessor.Listener { override def beforeBulk(executionId: Long, request: BulkRequest): Unit = { - logger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") + noRequestIdLogger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") } override def afterBulk(executionId: Long, request: BulkRequest, response: BulkResponse): Unit = { if (response.hasFailures) { - logger.error("Some failures flushing the BulkProcessor: ") + noRequestIdLogger.error("Some failures flushing the BulkProcessor: ") response .getItems.to(LazyList) .filter(_.isFailed) .map(_.getFailureMessage) .groupBy(identity) .foreach { case (message, stream) => - logger.error(s"${stream.size}x: $message") + noRequestIdLogger.error(s"${stream.size}x: $message") } } } override def afterBulk(executionId: Long, request: BulkRequest, failure: Throwable): Unit = { - logger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) + noRequestIdLogger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) } } diff --git a/es814x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala b/es814x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala index a8def0ec7a..b3c5593c36 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala @@ -22,7 +22,7 @@ import org.apache.http.auth.{AuthScope, Credentials, UsernamePasswordCredentials import org.apache.http.conn.ssl.NoopHostnameVerifier import org.apache.http.impl.client.BasicCredentialsProvider import org.apache.http.impl.nio.client.HttpAsyncClientBuilder -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.* import org.elasticsearch.client.RestClient.FailureListener import tech.beshu.ror.accesscontrol.audit.sink.AuditDataStreamCreator @@ -38,7 +38,7 @@ import scala.collection.parallel.CollectionConverters.* final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient]) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { override def submit(indexName: IndexName.Full, documentId: String, jsonRecord: String) (implicit requestId: RequestId): Unit = { @@ -77,21 +77,21 @@ final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient] override def onSuccess(response: Response): Unit = { response.getStatusLine.getStatusCode / 100 match { case 2 => // 2xx - logger.debug(s"[${requestId.show}] Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") + logger.debug(s"Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") case _ => - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") } } override def onFailure(ex: Exception): Unit = { - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId]", ex) + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId]", ex) } } override val dataStreamCreator: AuditDataStreamCreator = new AuditDataStreamCreator(clients.map(new RestClientDataStreamService(_))) } -object RestClientAuditSinkService extends Logging { +object RestClientAuditSinkService extends RequestIdAwareLogging { def create(remoteCluster: AuditCluster.RemoteAuditCluster): RestClientAuditSinkService = { remoteCluster.mode match { @@ -122,7 +122,7 @@ object RestClientAuditSinkService extends Logging { .setFailureListener( new FailureListener { override def onFailure(node: Node): Unit = { - logger.debug( + noRequestIdLogger.debug( s"[AUDIT] Node marked dead: ${node.getHost.getSchemeName}://${node.getHost.getHostName}:${node.getHost.getPort}. The client will attempt failover.", ) } diff --git a/es814x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala b/es814x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala index ce17639c06..b18c4fbfee 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.Channel import io.netty.handler.ssl.NotSslRecordException -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.network.NetworkService import org.elasticsearch.common.settings.{ClusterSettings, Settings} import org.elasticsearch.http.netty4.Netty4HttpServerTransport @@ -41,7 +41,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, tracer: Tracer, fipsCompliant: Boolean) extends Netty4HttpServerTransport(settings, networkService, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory, tracer, TLSConfig.noTLS(), null, null) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, ssl.clientAuthenticationEnabled) @@ -49,7 +49,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, override def onException(channel: HttpChannel, cause: Exception): Unit = { if (!this.lifecycle.started) return - else if (cause.getCause.isInstanceOf[NotSslRecordException]) logger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) + else if (cause.getCause.isInstanceOf[NotSslRecordException]) noRequestIdLogger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) else super.onException(channel, cause) channel.close() } diff --git a/es814x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala b/es814x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala index 2fa1d7871c..2d2b0360d4 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.* import io.netty.handler.ssl.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.TransportVersion import org.elasticsearch.cluster.node.DiscoveryNode import org.elasticsearch.common.io.stream.NamedWriteableRegistry @@ -46,7 +46,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, sharedGroupFactory: SharedGroupFactory, fipsCompliant: Boolean) extends Netty4Transport(settings, TransportVersion.current(), threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = SSLCertHelper.prepareClientSSLContext(ssl, fipsCompliant, ssl.certificateVerificationEnabled) private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, clientAuthenticationEnabled = false) @@ -78,7 +78,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, override def exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable): Unit = { if (cause.isInstanceOf[NotSslRecordException] || (cause.getCause != null && cause.getCause.isInstanceOf[NotSslRecordException])) { - logger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") + noRequestIdLogger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") ctx.channel.close } else { super.exceptionCaught(ctx, cause) diff --git a/es814x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala b/es814x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala index 1a8804e4b7..84979960e0 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.utils import cats.Show import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.client.internal.node.NodeClient import org.elasticsearch.rest.* @@ -37,7 +37,7 @@ import java.util import scala.util.Try class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandler) - extends RestHandler with Logging { + extends RestHandler with RequestIdAwareLogging { private val wrapped = doPrivileged { wrapSomeActions(underlying) @@ -103,11 +103,11 @@ class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandle private def logError(error: AuthorizationValueError): Unit = { { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorSanitizedShow - logger.warn(s"The incoming request was malformed. Cause: ${error.show}") + noRequestIdLogger.warn(s"The incoming request was malformed. Cause: ${error.show}") } if (logger.delegate.isDebugEnabled()) { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorWithDetailsShow - logger.debug(s"Malformed request detailed cause: ${error.show}") + noRequestIdLogger.debug(s"Malformed request detailed cause: ${error.show}") } } diff --git a/es814x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala b/es814x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala index 5ab1e35742..a9af8f710a 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala @@ -16,13 +16,13 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.settings.Settings import tech.beshu.ror.tools.core.patches.PatchingVerifier import tech.beshu.ror.tools.core.patches.PatchingVerifier.Error.{CannotVerifyIfPatched, EsNotPatched} import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -object EsPatchVerifier extends Logging { +object EsPatchVerifier extends RequestIdAwareLogging { def verify(settings: Settings): Unit = doPrivileged { pathHomeFrom(settings).flatMap(PatchingVerifier.verify) match { @@ -30,7 +30,7 @@ object EsPatchVerifier extends Logging { case Left(e@EsNotPatched(_)) => throw new IllegalStateException(e.message) case Left(e@CannotVerifyIfPatched(_)) => - logger.warn(e.message) + noRequestIdLogger.warn(e.message) } } diff --git a/es814x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala b/es814x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala index 639aeb5029..893d807108 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.repositories.{RepositoriesService, VerifyNodeRepositoryAction} import org.elasticsearch.transport.{RemoteClusterService, TransportService} import org.joor.Reflect.on @@ -26,7 +26,7 @@ import java.util.function.Supplier import scala.util.{Failure, Success, Try} class RemoteClusterServiceSupplier(repositoriesServiceSupplier: Supplier[RepositoriesService]) - extends Supplier[Option[RemoteClusterService]] with Logging { + extends Supplier[Option[RemoteClusterService]] with RequestIdAwareLogging { override def get(): Option[RemoteClusterService] = { for { @@ -35,7 +35,7 @@ class RemoteClusterServiceSupplier(repositoriesServiceSupplier: Supplier[Reposit case Success(transportService) => Option(transportService.getRemoteClusterService) case Failure(ex) => - logger.error("Cannot extract RemoteClusterService from RepositoriesService", ex) + noRequestIdLogger.error("Cannot extract RemoteClusterService from RepositoriesService", ex) None } } yield remoteClusterService diff --git a/es815x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es815x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index 07d70bbf05..978eebec5d 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.support.{ActionFilter, ActionFilterChain} import org.elasticsearch.action.{ActionListener, ActionRequest, ActionResponse} import org.elasticsearch.client.internal.node.NodeClient @@ -62,7 +62,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, rorEsConfig: ReadonlyRestEsConfig) (implicit environmentConfig: EnvironmentConfig) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = environmentConfig.uniqueIdentifierGenerator @@ -211,12 +211,12 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def handleRorNotReadyYet(esContext: EsContext): Unit = { - logger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") + noRequestIdLogger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") rorNotAvailableRequestHandler.handleRorNotReadyYet(esContext) } private def handleRorFailedToStart(esContext: EsContext): Unit = { - logger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") + noRequestIdLogger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") rorNotAvailableRequestHandler.handleRorFailedToStart(esContext) } @@ -238,7 +238,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def logAndSetStartingFailureState(failure: StartingFailure): Unit = { - logger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) + noRequestIdLogger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) rorInstanceState.set(RorInstanceStartingState.NotStarted(failure)) } } diff --git a/es815x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala b/es815x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala index 1fb22fc79d..53452eb8e6 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.xcontent.LoggingDeprecationHandler import org.elasticsearch.rest.RestResponse import org.elasticsearch.transport.BytesRefRecycler @@ -32,7 +32,7 @@ import tech.beshu.ror.accesscontrol.domain.ResponseFieldsFiltering.{AccessMode, import scala.jdk.CollectionConverters.* trait ResponseFieldsFiltering { - this: Logging => + this: RequestIdAwareLogging => private val responseFieldsRestrictions: Atomic[Option[ResponseFieldsRestrictions]] = Atomic(None: Option[ResponseFieldsRestrictions]) diff --git a/es815x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala b/es815x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala index 0f26750588..da95de59a4 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.action.{ActionListener, ActionResponse} import org.elasticsearch.threadpool.ThreadPool @@ -37,7 +37,7 @@ sealed abstract class RorActionListener[T](val underlying: ActionListener[T]) ex final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionListener[T], correlationId: Eval[CorrelationId]) - extends RorActionListener[T](underlying) with Logging { + extends RorActionListener[T](underlying) with RequestIdAwareLogging { override def onFailure(e: Exception): Unit = { super.onFailure(adaptExceptionIfNeeded(e)) @@ -47,7 +47,7 @@ final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionLis ex match { case esException: ElasticsearchException => esException case other => - logger.error(s"[${correlationId.value.show}] Internal error.", other) + noRequestIdLogger.error(s"[${correlationId.value.show}] Internal error.", other) new ElasticsearchException(s"[${correlationId.value.show}] Internal error. See logs for details.") } } diff --git a/es815x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala b/es815x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala index 75048ebe7d..14e5e31c1b 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.http.HttpChannel import org.elasticsearch.rest.{AbstractRestChannel, RestChannel as EsRestChannel, RestRequest as EsRestRequest, RestResponse as EsRestResponse} import squants.information.{Bytes, Information} @@ -40,7 +40,7 @@ object RorRestChannel { final class RorRestChannel private(underlying: EsRestChannel, val restRequest: RorRestRequest) extends AbstractRestChannel(underlying.request(), true) with ResponseFieldsFiltering - with Logging { + with RequestIdAwareLogging { override def sendResponse(response: EsRestResponse): Unit = { ThreadRepo.removeRestChannel(this) diff --git a/es815x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala b/es815x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala index 6babc712b9..3c80750a25 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala @@ -18,16 +18,15 @@ package tech.beshu.ror.es.actions.rradmin import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.ConfigApi.ConfigResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAdminActionHandler extends Logging { +class RRAdminActionHandler extends RequestIdAwareLogging { private implicit val adminRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +51,7 @@ class RRAdminActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAdminResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAdminAction internal error", ex) + logger.error("RRAdminAction internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es815x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala b/es815x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala index c55835a1d0..ce45c6f48e 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala @@ -16,18 +16,15 @@ */ package tech.beshu.ror.es.actions.rrauthmock -import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.AuthMockApi.AuthMockResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier -import tech.beshu.ror.implicits.* +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAuthMockActionHandler extends Logging { +class RRAuthMockActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -53,7 +50,7 @@ class RRAuthMockActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAuthMockResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAuthMock internal error", ex) + logger.error("RRAuthMock internal error", ex) listener.onFailure(new Exception(ex)) } } diff --git a/es815x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala b/es815x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala index aa8bb31e67..640084c4ec 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestconfig import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.TestConfigApi.TestConfigResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestConfigActionHandler extends Logging { +class RRTestConfigActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +52,7 @@ class RRTestConfigActionHandler extends Logging { case Right(response) => listener.onResponse(new RRTestConfigResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRTestConfig internal error", ex) + logger.error(s"RRTestConfig internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es815x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala b/es815x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala index 494e9150b4..98cc0c945d 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.dlsfls import cats.data.StateT import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.DirectoryReader import org.elasticsearch.common.util.concurrent.ThreadContext import org.elasticsearch.core.CheckedFunction @@ -31,7 +31,7 @@ import java.io.IOException import java.util.function.{Function => JavaFunction} import scala.util.{Failure, Success, Try} -object RoleIndexSearcherWrapper extends Logging { +object RoleIndexSearcherWrapper extends RequestIdAwareLogging { val instance: JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] = new JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] { @@ -54,7 +54,7 @@ object RoleIndexSearcherWrapper extends Logging { } .map(r => (r, r)) case None => - logger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") + noRequestIdLogger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") Success((reader, reader)) } } @@ -66,13 +66,13 @@ object RoleIndexSearcherWrapper extends Logging { nel <- NonEmptyString.from(value) match { case Right(nel) => Success(nel) case Left(_) => - logger.debug("FLS: empty header value") + noRequestIdLogger.debug("FLS: empty header value") failure } fields <- transientFieldsFromHeaderValue.fromRawValue(nel) match { case result@Success(_) => result case Failure(ex) => - logger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) + noRequestIdLogger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) failure } } yield fields diff --git a/es815x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala b/es815x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala index ce77d77f4e..aeccbfcead 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.dlsfls import com.google.common.collect.Iterators -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.codecs.StoredFieldsReader import org.apache.lucene.index.* import org.apache.lucene.index.StoredFieldVisitor.Status @@ -39,21 +39,21 @@ import scala.jdk.CollectionConverters.* import scala.util.Try private class RorDocumentFieldReader(reader: LeafReader, fieldsRestrictions: FieldsRestrictions) - extends SequentialStoredFieldsLeafReader(reader) with Logging { + extends SequentialStoredFieldsLeafReader(reader) with RequestIdAwareLogging { private val policy = new FieldsPolicy(fieldsRestrictions) private val remainingFieldsInfo = { val fInfos = in.getFieldInfos val newInfos = if (fInfos.asScala.isEmpty) { - logger.warn("original fields were empty! This is weird!") + noRequestIdLogger.warn("original fields were empty! This is weird!") fInfos } else { val remainingFields = fInfos.asScala.filter(f => policy.canKeep(f.name)).toSet new FieldInfos(remainingFields.toArray) } - logger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") - logger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") - logger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") + noRequestIdLogger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") newInfos } private val jsonPolicyBasedFilterer = new JsonPolicyBasedFilterer(policy) diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala index 9365230fe3..9abe861fe3 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.* import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest import org.elasticsearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest @@ -87,7 +87,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, threadPool: ThreadPool) (implicit generator: UniqueIdentifierGenerator, scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle(engines: Engines, esContext: EsContext): Task[Either[Error, Unit]] = { @@ -243,7 +243,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, case SearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case MultiSearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case _ => - logger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") + noRequestIdLogger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") regularRequestHandler.handle(new DummyCompositeIndicesEsRequestContext(request, esContext, aclContext, clusterService, threadPool)) } // rest diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala index cab02aff37..100edd72ac 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.common.io.stream.StreamOutput import org.elasticsearch.xcontent.{ToXContent, ToXContentObject, XContentBuilder} @@ -45,7 +45,7 @@ import scala.util.{Failure, Success, Try} class CurrentUserMetadataRequestHandler(engine: Engine, esContext: EsContext) - extends Logging { + extends RequestIdAwareLogging { def handle(request: RequestContext.Aux[CurrentUserMetadataRequestBlockContext] with EsRequest[CurrentUserMetadataRequestBlockContext]): Task[Unit] = { engine.core.accessControl @@ -69,7 +69,7 @@ class CurrentUserMetadataRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(ex.asInstanceOf[Exception]) } } @@ -86,13 +86,13 @@ class CurrentUserMetadataRequestHandler(engine: Engine, )) } - private def onPassThrough(requestContext: RequestContext): Unit = { - logger.warn(s"[${requestContext.id.toRequestId.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") + private def onPassThrough(implicit requestContext: RequestContext): Unit = { + logger.warn(s"Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") esContext.listener.onFailure(createRorNotEnabledResponse()) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala index 2fb01dcc41..c5c44fda92 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala @@ -20,7 +20,7 @@ import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.RegularRequestResult @@ -49,7 +49,7 @@ class RegularRequestHandler(engine: Engine, esContext: EsContext, threadPool: ThreadPool) (implicit scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle[B <: BlockContext : BlockContextUpdater](request: RequestContext.Aux[B] with EsRequest[B]): Task[Unit] = { engine.core.accessControl @@ -85,7 +85,7 @@ class RegularRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(new Exception(ex)) } } @@ -99,7 +99,7 @@ class RegularRequestHandler(engine: Engine, case ModificationResult.ShouldBeInterrupted => onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case ModificationResult.CannotModify => - logger.error(s"[${request.id.toRequestId.show}] Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") + noRequestIdLogger.error(s"Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case CustomResponse(response) => respond(request, response) @@ -247,7 +247,7 @@ class RegularRequestHandler(engine: Engine, esContext.listener.onResponse(response) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } \ No newline at end of file diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala index f4f832dedc..bfc421bdd5 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.index.query.{AbstractQueryBuilder, QueryBuilder, QueryBuilders} import org.elasticsearch.search.aggregations.AggregatorFactories @@ -40,7 +40,7 @@ import tech.beshu.ror.implicits.* import java.util.UUID import scala.jdk.CollectionConverters.* -object SearchRequestOps extends Logging { +object SearchRequestOps extends RequestIdAwareLogging { implicit class QueryBuilderOps(val builder: Option[QueryBuilder]) extends AnyVal { @@ -52,7 +52,7 @@ object SearchRequestOps extends Logging { val modifiedQuery: AbstractQueryBuilder[_] = provideNewQueryWithAppliedFilter(builder, filterQuery) Some(modifiedQuery) case None => - logger.debug(s"[${requestId.show}] No filter applied to query.") + logger.debug(s"No filter applied to query.") builder } } @@ -92,7 +92,7 @@ object SearchRequestOps extends Logging { case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, requestId) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) disableCaching(requestId) case BasedOnBlockContextOnly.NotAllowedFieldsUsed(notAllowedFields) => modifyNotAllowedFieldsInRequest(notAllowedFields) @@ -138,8 +138,8 @@ object SearchRequestOps extends Logging { } } - private def disableCaching(requestId: RequestContext.Id) = { - logger.debug(s"[${requestId.show}] ACL uses context header for fields rule, will disable request cache for SearchRequest") + private def disableCaching(implicit requestId: RequestContext.Id) = { + logger.debug(s"ACL uses context header for fields rule, will disable request cache for SearchRequest") request.requestCache(false) } } diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala index 993bdbd7a0..f0d04a6837 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala @@ -17,7 +17,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.action.{CompositeIndicesRequest, IndicesRequest} import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -32,7 +31,7 @@ import java.time.Instant abstract class BaseEsRequestContext[B <: BlockContext](esContext: EsContext, clusterService: RorClusterService) - extends RequestContext with Logging { + extends RequestContext { override type BLOCK_CONTEXT = B diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala index ae8abbe1f5..0ee2967364 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala @@ -18,7 +18,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -26,8 +25,9 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import scala.util.Try +import tech.beshu.ror.utils.RequestIdAwareLogging -trait EsRequest[B <: BlockContext] extends Logging { +trait EsRequest[B <: BlockContext] extends RequestIdAwareLogging { implicit def threadPool: ThreadPool final def modifyUsing(blockContext: B): ModificationResult = { @@ -35,7 +35,7 @@ trait EsRequest[B <: BlockContext] extends Logging { Try(modifyRequest(blockContext)) .fold( ex => { - logger.error(s"[${blockContext.requestContext.id.show}] Cannot modify request with filtered data", ex) + logger.error(s"Cannot modify request with filtered data", ex)(blockContext) ModificationResult.CannotModify }, identity diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala index c6a9dcbefd..f773b3efb1 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala @@ -51,7 +51,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest private def discoverDataStreams() = { val dataStreams = dataStreamsFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered data streams: ${dataStreams.show}") + logger.debug(s"Discovered data streams: ${dataStreams.show}") dataStreams } @@ -59,7 +59,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest val backingIndices = backingIndicesFrom(actionRequest) backingIndices match { case BackingIndices.IndicesInvolved(filteredIndices, _) => - logger.debug(s"[${id.show}] Discovered indices: ${filteredIndices.show}") + logger.debug(s"Discovered indices: ${filteredIndices.show}") case BackingIndices.IndicesNotInvolved => } backingIndices diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala index c091179cb6..d150709314 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala @@ -85,7 +85,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: case Some(indices) => update(actionRequest, indices, blockContext.filter, blockContext.fieldLevelSecurity) case None => - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -101,7 +101,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } \ No newline at end of file diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala index 71d462de57..48014e1bdc 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala @@ -73,7 +73,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, } yield update(actionRequest, filteredIndices, allAllowedIndices) result.getOrElse { - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -86,7 +86,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala index 95d882c3b5..f607c0e347 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala @@ -50,7 +50,7 @@ abstract class BaseRepositoriesEsRequestContext[R <: ActionRequest](actionReques case Some(repositories) => update(actionRequest, repositories) case None => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") ShouldBeInterrupted } } diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala index b3b1d66238..7ef0f32014 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala @@ -42,7 +42,7 @@ abstract class BaseSingleIndexEsRequestContext[R <: ActionRequest](actionRequest filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } update(request, filteredIndices.head) } diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala index b5ab70fe7a..c1b2e7ea27 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala @@ -62,7 +62,7 @@ class BulkEsRequestContext(actionRequest: BulkRequest, case (_, _) => ShouldBeInterrupted } } else { - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because origin request contained different " + + logger.error(s"Cannot alter MultiGetRequest request, because origin request contained different " + s"number of requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } @@ -90,18 +90,18 @@ class BulkEsRequestContext(actionRequest: BulkRequest, updateRequestWithIndices(request, nel) Modified case None => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because empty list of indices was found") + logger.error(s"Cannot alter MultiGetRequest request, because empty list of indices was found") ShouldBeInterrupted } case Indices.NotFound => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because no allowed indices were found") + logger.error(s"Cannot alter MultiGetRequest request, because no allowed indices were found") ShouldBeInterrupted } } private def updateRequestWithIndices(request: DocWriteRequest[_], indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } request.index(indices.head.stringify) } diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala index 75a75fcef5..96a043b298 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala @@ -53,14 +53,14 @@ class BulkShardEsRequestContext(actionRequest: BulkShardRequest, case Success(_) => Modified case Failure(ex) => - logger.error(s"[${id.show}] Cannot modify BulkShardRequest", ex) + logger.error(s"Cannot modify BulkShardRequest", ex) CannotModify } } private def tryUpdate(request: BulkShardRequest, indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } val singleIndex = indices.head val uuid = clusterService.indexOrAliasUuids(singleIndex.name).toList.head diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala index 65a168092a..158ac485a5 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala @@ -45,14 +45,14 @@ class ClusterAllocationExplainEsRequestContext(actionRequest: ClusterAllocationE getRequestedIndexFrom(request) match { case Some(_) => if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateIndexIn(request, filteredIndices.head) Modified case None if filteredIndices.exists(_.name === ClusterIndexName.Local.wildcard) => Modified case None => - logger.error(s"[${id.show}] Cluster allocation explain request without index name is unavailable when block contains `indices` rule") + logger.error(s"Cluster allocation explain request without index name is unavailable when block contains `indices` rule") ShouldBeInterrupted } } diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala index 61fdab9d83..5bf09449c5 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala @@ -79,7 +79,7 @@ class EsqlIndicesEsRequestContext private(actionRequest: ActionRequest with Comp request } case Left(ClassificationError.ParsingException(ex)) => - logger.debug(s"[${id.show}] Cannot parse ESQL statement - we can pass it though, because ES is going to reject it. Cause:", ex) + logger.debug(s"Cannot parse ESQL statement - we can pass it though, because ES is going to reject it. Cause:", ex) request } } @@ -90,7 +90,7 @@ class EsqlIndicesEsRequestContext private(actionRequest: ActionRequest with Comp case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala index 5778b8968d..02dec730ed 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala @@ -66,7 +66,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, updateAliases(actionRequest, aliases) UpdateResponse.sync(updateAliasesResponse(aliases.includedOnly, _)) case None => - logger.error(s"[${id.show}] At least one alias and one index has to be allowed. " + + logger.error(s"At least one alias and one index has to be allowed. " + s"Found allowed indices: [${blockContext.indices.show}]." + s"Found allowed aliases: [${blockContext.aliases.show}]") ShouldBeInterrupted @@ -114,7 +114,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, .indices().asSafeSet .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } @@ -122,7 +122,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, val aliases = rawRequestAliasesSet(request) .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered aliases: ${aliases.show}") + logger.debug(s"Discovered aliases: ${aliases.show}") aliases } diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala index abb85d42b7..f9e2c87e53 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala @@ -55,7 +55,7 @@ class IndicesAliasesEsRequestContext(actionRequest: IndicesAliasesRequest, if (originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala index 584c97e9f5..834bff8e8e 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala @@ -120,7 +120,7 @@ class MultiGetEsRequestContext(actionRequest: MultiGetRequest, case Nil => updateItemWithNonExistingIndex(item) case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } item.index(index.stringify) } diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala index 989956d79a..9e13edee8d 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala @@ -78,7 +78,7 @@ class MultiSearchEsRequestContext(actionRequest: MultiSearchRequest, } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala index 9191e33b66..5a61356f48 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala @@ -47,7 +47,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { request.getRequests.removeIf { request => removeOrAlter(request, filteredIndices.toCovariantSet) } if (request.getRequests.asScala.isEmpty) { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") ShouldBeInterrupted } else { Modified @@ -63,7 +63,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, true case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") } request.index(index.stringify) false diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala index c411df93c5..c7b99f6e85 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala @@ -52,7 +52,7 @@ class PutRollupJobEsRequestContext private(actionRequest: ActionRequest, if(originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala index ba5b52b4f1..f80e716349 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler.request.context.types import cats.data.NonEmptyList import cats.implicits.* import com.google.common.collect.Sets -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionRequest import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.AccessControlStaticContext @@ -51,7 +51,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (tryUpdate(actionRequest, filteredIndices)) Modified else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") ShouldBeInterrupted } } @@ -66,7 +66,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques } } -object ReflectionBasedIndicesEsRequestContext extends Logging { +object ReflectionBasedIndicesEsRequestContext extends RequestIdAwareLogging { def unapply(arg: ReflectionBasedActionRequest): Option[ReflectionBasedIndicesEsRequestContext] = { requestedIndicesFrom(arg.esContext.actionRequest) diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala index 489d0187bc..c42dfc3b78 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala @@ -58,10 +58,10 @@ class ReindexEsRequestContext(actionRequest: ReindexRequest, Modified } else { if (!isDestinationIndexOnFilteredIndicesList) { - logger.info(s"[${id.show}] Destination index of _reindex request is forbidden") + logger.info(s"Destination index of _reindex request is forbidden") } if (!isSearchRequestComposedOnlyOfAllowedIndices) { - logger.info(s"[${id.show}] At least one index from sources indices list of _reindex request is forbidden") + logger.info(s"At least one index from sources indices list of _reindex request is forbidden") } ShouldBeInterrupted } diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala index 2c1b0014e0..97b8ccd9c5 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala @@ -74,7 +74,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo request } case Left(_) => - logger.debug(s"[${id.show}] Cannot parse SQL statement - we can pass it though, because ES is going to reject it") + logger.debug(s"Cannot parse SQL statement - we can pass it though, because ES is going to reject it") request } } @@ -85,7 +85,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala index 0c67384c1e..d7e743e648 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CleanupRepositoryEsRequestContext(actionRequest: CleanupRepositoryRequest, override protected def update(request: CleanupRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala index 44b7d78dfd..d09015139b 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CreateRepositoryEsRequestContext(actionRequest: PutRepositoryRequest, override protected def update(request: PutRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala index eaf9334872..0cf32e1bea 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class DeleteRepositoryEsRequestContext(actionRequest: DeleteRepositoryRequest, override protected def update(request: DeleteRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala index cee0bffd4c..d1410eff3d 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class VerifyRepositoryEsRequestContext(actionRequest: VerifyRepositoryRequest, override protected def update(request: VerifyRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala index ead4fcf250..20501516d5 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala @@ -68,32 +68,32 @@ class CreateSnapshotEsRequestContext(actionRequest: CreateSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala index a56aba660e..621d744767 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala @@ -60,7 +60,7 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -71,14 +71,14 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, .toRight(()) } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala index 22869bbb4f..b81f333174 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala @@ -68,7 +68,7 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, case r => r } case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala index 88887db96c..156deb5b80 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala @@ -63,7 +63,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -75,7 +75,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") } Right(snapshot) } @@ -88,7 +88,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala index 44ee8397ec..e522e440f1 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala @@ -100,12 +100,12 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { val repositories = blockContext.repositories if (allRepositoriesRequested(repositories)) { Right(RepositoryName.All) @@ -115,7 +115,7 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala index 3a9be2dd6c..f306a2252d 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.rollover.RolloverConfiguration import org.elasticsearch.action.admin.indices.template.get.GetComposableIndexTemplateAction import org.elasticsearch.cluster.metadata @@ -112,7 +112,7 @@ class GetComposableIndexTemplateEsRequestContext(actionRequest: GetComposableInd } -private[templates] object GetComposableIndexTemplateEsRequestContext extends Logging { +private[templates] object GetComposableIndexTemplateEsRequestContext extends RequestIdAwareLogging { def filter(templates: Map[String, ComposableIndexTemplate], usingTemplate: Set[Template] => Set[Template]) diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala index bd74c3a18f..1c6eecf409 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.{GetIndexTemplatesRequest, GetIndexTemplatesResponse} import org.elasticsearch.cluster.metadata.{AliasMetadata, IndexTemplateMetadata} import org.elasticsearch.common.collect.ImmutableOpenMap @@ -104,7 +104,7 @@ class GetTemplatesEsRequestContext(actionRequest: GetIndexTemplatesRequest, } -private[templates] object GetTemplatesEsRequestContext extends Logging { +private[templates] object GetTemplatesEsRequestContext extends RequestIdAwareLogging { def filter(templates: Iterable[IndexTemplateMetadata], usingTemplate: Set[Template] => Set[Template]) diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala index a8951de5b1..32116d8212 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala @@ -72,7 +72,7 @@ class MultiSearchTemplateEsRequestContext private(actionRequest: ActionRequest w } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala index e6f6d8916e..434787a686 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala @@ -55,7 +55,7 @@ class SimulateIndexTemplateRequestEsRequestContext(actionRequest: SimulateIndexT filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateRequest(request, filteredIndices.head, allAllowedIndices) } diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala index fbc4cf6776..46ed6e7a95 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala @@ -109,7 +109,7 @@ class SimulateExistingTemplateRequestEsRequestContext(existingTemplateName: Temp case Some(_) => updateResponse(namePatterns.toList, blockContext.allAllowedIndices.toList) case None => - logger.info(s"[${id.show}] User has no access to template ${existingTemplateName.show}") + logger.info(s"User has no access to template ${existingTemplateName.show}") ModificationResult.ShouldBeInterrupted } case other => diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala index 0ecd7a72b3..fe4d60bd42 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.queries import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.index.query.* import org.joor.Reflect.on import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.RequestFieldsUsage @@ -30,7 +30,7 @@ trait QueryFieldsUsage[QUERY <: QueryBuilder] { def fieldsIn(query: QUERY): RequestFieldsUsage } -object QueryFieldsUsage extends Logging { +object QueryFieldsUsage extends RequestIdAwareLogging { def apply[QUERY <: QueryBuilder](implicit ev: QueryFieldsUsage[QUERY]): QueryFieldsUsage[QUERY] = ev implicit class Ops[QUERY <: QueryBuilder : QueryFieldsUsage](val query: QUERY) { @@ -62,7 +62,7 @@ object QueryFieldsUsage extends Logging { Option(on(query).call("getFieldName").get[String]) match { case Some(fieldName: String) => UsingFields(NonEmptyList.one(UsedField(fieldName))) case _ => - logger.debug(s"Cannot extract fields for terms set query") + noRequestIdLogger.debug(s"Cannot extract fields for terms set query") CannotExtractFields } } @@ -89,7 +89,7 @@ object QueryFieldsUsage extends Logging { case builder: TermsSetQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder: WildcardQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder => - logger.debug(s"Cannot extract fields for query: ${builder.getName}") + noRequestIdLogger.debug(s"Cannot extract fields for query: ${builder.getName}") CannotExtractFields } diff --git a/es815x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala b/es815x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala index 0998bb9a5b..b4671e9e4d 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.handler.response import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.FieldsRestrictions import tech.beshu.ror.accesscontrol.domain.Header @@ -26,17 +26,17 @@ import tech.beshu.ror.accesscontrol.headerValues.transientFieldsToHeaderValue import tech.beshu.ror.accesscontrol.request.RequestContext import tech.beshu.ror.implicits.* -object FLSContextHeaderHandler extends Logging { +object FLSContextHeaderHandler extends RequestIdAwareLogging { def addContextHeader(threadPool: ThreadPool, - fieldsRestrictions: FieldsRestrictions, - requestId: RequestContext.Id): Unit = { + fieldsRestrictions: FieldsRestrictions) + (implicit requestId: RequestContext.Id): Unit = { val threadContext = threadPool.getThreadContext val header = createContextHeader(fieldsRestrictions) Option(threadContext.getHeader(header.name.value.value)) match { case None => implicit val show = headerShow - logger.debug(s"[${requestId.show}] Adding thread context header required by lucene. Header: '${header.show}'") + logger.debug(s"Adding thread context header required by lucene. Header: '${header.show}'") threadContext.putHeader(header.name.value.value, header.value.value) case Some(_) => } diff --git a/es815x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala b/es815x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala index de84ef167d..8574b3183b 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.admin.indices.template.get.{GetComponentTemplateAction, GetComposableIndexTemplateAction} import org.elasticsearch.action.admin.indices.template.put.{PutComponentTemplateAction, TransportPutComposableIndexTemplateAction} @@ -47,7 +47,7 @@ import scala.jdk.CollectionConverters.* final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJsonParserFactory)(using Clock) extends DataStreamService - with Logging { + with RequestIdAwareLogging { private val masterNodeTimeout: TimeValue = TimeValue(30000) private val ackTimeout: TimeValue = TimeValue(30000) @@ -205,11 +205,11 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ response <- Task.measure( task = Task.delay(nodeClient.execute(action, request).actionGet()), logTimeMeasurement = duration => Task.delay { - logger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") + noRequestIdLogger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") } ) _ <- Task.delay { - logger.debug(s"Action ${action.name()} response: ${response.toString}") + noRequestIdLogger.debug(s"Action ${action.name()} response: ${response.toString}") } } yield response } @@ -217,7 +217,7 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ def executeAck[REQUEST <: ActionRequest, RESPONSE <: AcknowledgedResponse](action: ActionType[RESPONSE], request: REQUEST): Task[RESPONSE] = { executeT(action, request) - .tapEval(response => Task.delay(logger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) + .tapEval(response => Task.delay(noRequestIdLogger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) } private def supportedActions: Map[ActionType[ActionResponse], TransportAction[ActionRequest, ActionResponse]] = { diff --git a/es815x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala b/es815x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala index 5e693123f3..306b486823 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.support.WriteRequest.RefreshPolicy import org.elasticsearch.client.internal.node.NodeClient @@ -37,7 +37,7 @@ import scala.jdk.CollectionConverters.* class EsIndexJsonContentService(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexJsonContentService - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -62,14 +62,14 @@ class EsIndexJsonContentService(client: NodeClient, Option(response.getSourceAsMap) match { case Some(map) => val source = map.asScala.toMap.asStringMap - logger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") Right(source) case None => - logger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") + noRequestIdLogger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") Right(Map.empty[String, String]) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(ContentNotFound) } } @@ -77,7 +77,7 @@ class EsIndexJsonContentService(client: NodeClient, .onErrorRecover { case _: ResourceNotFoundException => Left(ContentNotFound) case ex => - logger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) Left(CannotReachContentSource) } } @@ -103,14 +103,14 @@ class EsIndexJsonContentService(client: NodeClient, case status if status / 100 == 2 => Right(()) case status => - logger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") Left(CannotWriteToIndex) } } .executeOn(RorSchedulers.blockingScheduler) .onErrorRecover { case ex => - logger.error(s"Cannot write to document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]", ex) Left(CannotWriteToIndex) } } diff --git a/es815x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala b/es815x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala index 2a2669e8b4..619cb6daf2 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala @@ -22,7 +22,7 @@ import cats.kernel.Monoid import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task import monix.execution.{CancelablePromise, Scheduler} -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction.{ResolvedAlias, ResolvedIndex} @@ -65,7 +65,7 @@ class EsServerBasedRorClusterService(nodeName: String, threadPool: ThreadPool) (implicit val scheduler: Scheduler) extends RorClusterService - with Logging { + with RequestIdAwareLogging { import EsServerBasedRorClusterService.* @@ -156,7 +156,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractAccessibilityFrom) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify get request. Blocking document", ex) + logger.error(s"Could not verify get request. Blocking document", ex)(id) Inaccessible } } @@ -168,7 +168,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractResultsFromSearchResponse) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify documents returned by multi get response. Blocking all returned documents", ex) + logger.error(s"Could not verify documents returned by multi get response. Blocking all returned documents", ex)(id) blockAllDocsReturned(documents) } .map(results => zip(results, documents)) @@ -277,7 +277,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService): Task[List[FullRemoteDataStreamWithAliases]] = { getRemoteClusterClient(remoteClusterService, remoteClusterName) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -333,7 +333,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService) = { getRemoteClusterClient(remoteClusterService, remoteClusterName) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -423,7 +423,7 @@ class EsServerBasedRorClusterService(nodeName: String, } } case None => - logger.error("Cannot supply Snapshots Service. Please, report the issue!!!") + noRequestIdLogger.error("Cannot supply Snapshots Service. Please, report the issue!!!") Task.now(Set.empty[Snapshot]) } } diff --git a/es815x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala b/es815x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala index a657d15ca9..31d96f15a2 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.services import cats.data.NonEmptyList -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.bulk.{BackoffPolicy, BulkProcessor, BulkRequest, BulkResponse} import org.elasticsearch.action.index.IndexRequest import org.elasticsearch.action.{ActionListener, DocWriteRequest} @@ -39,7 +39,7 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, (using Clock) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { private val bulkProcessor = BulkProcessor @@ -80,25 +80,25 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, private class AuditSinkBulkProcessorListener extends BulkProcessor.Listener { override def beforeBulk(executionId: Long, request: BulkRequest): Unit = { - logger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") + noRequestIdLogger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") } override def afterBulk(executionId: Long, request: BulkRequest, response: BulkResponse): Unit = { if (response.hasFailures) { - logger.error("Some failures flushing the BulkProcessor: ") + noRequestIdLogger.error("Some failures flushing the BulkProcessor: ") response .getItems.to(LazyList) .filter(_.isFailed) .map(_.getFailureMessage) .groupBy(identity) .foreach { case (message, stream) => - logger.error(s"${stream.size}x: $message") + noRequestIdLogger.error(s"${stream.size}x: $message") } } } override def afterBulk(executionId: Long, request: BulkRequest, failure: Throwable): Unit = { - logger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) + noRequestIdLogger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) } } diff --git a/es815x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala b/es815x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala index a8def0ec7a..b3c5593c36 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala @@ -22,7 +22,7 @@ import org.apache.http.auth.{AuthScope, Credentials, UsernamePasswordCredentials import org.apache.http.conn.ssl.NoopHostnameVerifier import org.apache.http.impl.client.BasicCredentialsProvider import org.apache.http.impl.nio.client.HttpAsyncClientBuilder -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.* import org.elasticsearch.client.RestClient.FailureListener import tech.beshu.ror.accesscontrol.audit.sink.AuditDataStreamCreator @@ -38,7 +38,7 @@ import scala.collection.parallel.CollectionConverters.* final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient]) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { override def submit(indexName: IndexName.Full, documentId: String, jsonRecord: String) (implicit requestId: RequestId): Unit = { @@ -77,21 +77,21 @@ final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient] override def onSuccess(response: Response): Unit = { response.getStatusLine.getStatusCode / 100 match { case 2 => // 2xx - logger.debug(s"[${requestId.show}] Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") + logger.debug(s"Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") case _ => - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") } } override def onFailure(ex: Exception): Unit = { - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId]", ex) + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId]", ex) } } override val dataStreamCreator: AuditDataStreamCreator = new AuditDataStreamCreator(clients.map(new RestClientDataStreamService(_))) } -object RestClientAuditSinkService extends Logging { +object RestClientAuditSinkService extends RequestIdAwareLogging { def create(remoteCluster: AuditCluster.RemoteAuditCluster): RestClientAuditSinkService = { remoteCluster.mode match { @@ -122,7 +122,7 @@ object RestClientAuditSinkService extends Logging { .setFailureListener( new FailureListener { override def onFailure(node: Node): Unit = { - logger.debug( + noRequestIdLogger.debug( s"[AUDIT] Node marked dead: ${node.getHost.getSchemeName}://${node.getHost.getHostName}:${node.getHost.getPort}. The client will attempt failover.", ) } diff --git a/es815x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala b/es815x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala index ce17639c06..b18c4fbfee 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.Channel import io.netty.handler.ssl.NotSslRecordException -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.network.NetworkService import org.elasticsearch.common.settings.{ClusterSettings, Settings} import org.elasticsearch.http.netty4.Netty4HttpServerTransport @@ -41,7 +41,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, tracer: Tracer, fipsCompliant: Boolean) extends Netty4HttpServerTransport(settings, networkService, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory, tracer, TLSConfig.noTLS(), null, null) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, ssl.clientAuthenticationEnabled) @@ -49,7 +49,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, override def onException(channel: HttpChannel, cause: Exception): Unit = { if (!this.lifecycle.started) return - else if (cause.getCause.isInstanceOf[NotSslRecordException]) logger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) + else if (cause.getCause.isInstanceOf[NotSslRecordException]) noRequestIdLogger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) else super.onException(channel, cause) channel.close() } diff --git a/es815x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala b/es815x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala index 2fa1d7871c..2d2b0360d4 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.* import io.netty.handler.ssl.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.TransportVersion import org.elasticsearch.cluster.node.DiscoveryNode import org.elasticsearch.common.io.stream.NamedWriteableRegistry @@ -46,7 +46,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, sharedGroupFactory: SharedGroupFactory, fipsCompliant: Boolean) extends Netty4Transport(settings, TransportVersion.current(), threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = SSLCertHelper.prepareClientSSLContext(ssl, fipsCompliant, ssl.certificateVerificationEnabled) private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, clientAuthenticationEnabled = false) @@ -78,7 +78,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, override def exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable): Unit = { if (cause.isInstanceOf[NotSslRecordException] || (cause.getCause != null && cause.getCause.isInstanceOf[NotSslRecordException])) { - logger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") + noRequestIdLogger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") ctx.channel.close } else { super.exceptionCaught(ctx, cause) diff --git a/es815x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala b/es815x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala index 1a8804e4b7..84979960e0 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.utils import cats.Show import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.client.internal.node.NodeClient import org.elasticsearch.rest.* @@ -37,7 +37,7 @@ import java.util import scala.util.Try class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandler) - extends RestHandler with Logging { + extends RestHandler with RequestIdAwareLogging { private val wrapped = doPrivileged { wrapSomeActions(underlying) @@ -103,11 +103,11 @@ class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandle private def logError(error: AuthorizationValueError): Unit = { { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorSanitizedShow - logger.warn(s"The incoming request was malformed. Cause: ${error.show}") + noRequestIdLogger.warn(s"The incoming request was malformed. Cause: ${error.show}") } if (logger.delegate.isDebugEnabled()) { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorWithDetailsShow - logger.debug(s"Malformed request detailed cause: ${error.show}") + noRequestIdLogger.debug(s"Malformed request detailed cause: ${error.show}") } } diff --git a/es815x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala b/es815x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala index 5ab1e35742..a9af8f710a 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala @@ -16,13 +16,13 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.settings.Settings import tech.beshu.ror.tools.core.patches.PatchingVerifier import tech.beshu.ror.tools.core.patches.PatchingVerifier.Error.{CannotVerifyIfPatched, EsNotPatched} import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -object EsPatchVerifier extends Logging { +object EsPatchVerifier extends RequestIdAwareLogging { def verify(settings: Settings): Unit = doPrivileged { pathHomeFrom(settings).flatMap(PatchingVerifier.verify) match { @@ -30,7 +30,7 @@ object EsPatchVerifier extends Logging { case Left(e@EsNotPatched(_)) => throw new IllegalStateException(e.message) case Left(e@CannotVerifyIfPatched(_)) => - logger.warn(e.message) + noRequestIdLogger.warn(e.message) } } diff --git a/es815x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala b/es815x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala index b73104a175..c292a44ed2 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.internal.node.NodeClient import org.elasticsearch.transport.RemoteClusterService import org.joor.Reflect.on @@ -26,14 +26,14 @@ import java.util.function.Supplier import scala.util.{Failure, Success, Try} class RemoteClusterServiceSupplier(nodeClient: NodeClient) - extends Supplier[Option[RemoteClusterService]] with Logging { + extends Supplier[Option[RemoteClusterService]] with RequestIdAwareLogging { override def get(): Option[RemoteClusterService] = { extractRemoteClusterService() match { case Success(remoteClusterService) => remoteClusterService case Failure(ex) => - logger.error("Cannot extract RemoteClusterService from NodeClient", ex) + noRequestIdLogger.error("Cannot extract RemoteClusterService from NodeClient", ex) None } } diff --git a/es816x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es816x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index 07d70bbf05..978eebec5d 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.support.{ActionFilter, ActionFilterChain} import org.elasticsearch.action.{ActionListener, ActionRequest, ActionResponse} import org.elasticsearch.client.internal.node.NodeClient @@ -62,7 +62,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, rorEsConfig: ReadonlyRestEsConfig) (implicit environmentConfig: EnvironmentConfig) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = environmentConfig.uniqueIdentifierGenerator @@ -211,12 +211,12 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def handleRorNotReadyYet(esContext: EsContext): Unit = { - logger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") + noRequestIdLogger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") rorNotAvailableRequestHandler.handleRorNotReadyYet(esContext) } private def handleRorFailedToStart(esContext: EsContext): Unit = { - logger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") + noRequestIdLogger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") rorNotAvailableRequestHandler.handleRorFailedToStart(esContext) } @@ -238,7 +238,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def logAndSetStartingFailureState(failure: StartingFailure): Unit = { - logger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) + noRequestIdLogger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) rorInstanceState.set(RorInstanceStartingState.NotStarted(failure)) } } diff --git a/es816x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala b/es816x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala index 1fb22fc79d..53452eb8e6 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.xcontent.LoggingDeprecationHandler import org.elasticsearch.rest.RestResponse import org.elasticsearch.transport.BytesRefRecycler @@ -32,7 +32,7 @@ import tech.beshu.ror.accesscontrol.domain.ResponseFieldsFiltering.{AccessMode, import scala.jdk.CollectionConverters.* trait ResponseFieldsFiltering { - this: Logging => + this: RequestIdAwareLogging => private val responseFieldsRestrictions: Atomic[Option[ResponseFieldsRestrictions]] = Atomic(None: Option[ResponseFieldsRestrictions]) diff --git a/es816x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala b/es816x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala index 0f26750588..da95de59a4 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.action.{ActionListener, ActionResponse} import org.elasticsearch.threadpool.ThreadPool @@ -37,7 +37,7 @@ sealed abstract class RorActionListener[T](val underlying: ActionListener[T]) ex final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionListener[T], correlationId: Eval[CorrelationId]) - extends RorActionListener[T](underlying) with Logging { + extends RorActionListener[T](underlying) with RequestIdAwareLogging { override def onFailure(e: Exception): Unit = { super.onFailure(adaptExceptionIfNeeded(e)) @@ -47,7 +47,7 @@ final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionLis ex match { case esException: ElasticsearchException => esException case other => - logger.error(s"[${correlationId.value.show}] Internal error.", other) + noRequestIdLogger.error(s"[${correlationId.value.show}] Internal error.", other) new ElasticsearchException(s"[${correlationId.value.show}] Internal error. See logs for details.") } } diff --git a/es816x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala b/es816x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala index 4f0bc8c6fa..c68cc24623 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.http.HttpChannel import org.elasticsearch.rest.{AbstractRestChannel, RestChannel as EsRestChannel, RestRequest as EsRestRequest, RestResponse as EsRestResponse} import squants.information.{Bytes, Information} @@ -40,7 +40,7 @@ object RorRestChannel { final class RorRestChannel private(underlying: EsRestChannel, val restRequest: RorRestRequest) extends AbstractRestChannel(underlying.request(), true) with ResponseFieldsFiltering - with Logging { + with RequestIdAwareLogging { override def sendResponse(response: EsRestResponse): Unit = { ThreadRepo.removeRestChannel(this) diff --git a/es816x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala b/es816x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala index 6babc712b9..3c80750a25 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala @@ -18,16 +18,15 @@ package tech.beshu.ror.es.actions.rradmin import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.ConfigApi.ConfigResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAdminActionHandler extends Logging { +class RRAdminActionHandler extends RequestIdAwareLogging { private implicit val adminRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +51,7 @@ class RRAdminActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAdminResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAdminAction internal error", ex) + logger.error("RRAdminAction internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es816x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala b/es816x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala index c55835a1d0..ce45c6f48e 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala @@ -16,18 +16,15 @@ */ package tech.beshu.ror.es.actions.rrauthmock -import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.AuthMockApi.AuthMockResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier -import tech.beshu.ror.implicits.* +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAuthMockActionHandler extends Logging { +class RRAuthMockActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -53,7 +50,7 @@ class RRAuthMockActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAuthMockResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAuthMock internal error", ex) + logger.error("RRAuthMock internal error", ex) listener.onFailure(new Exception(ex)) } } diff --git a/es816x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala b/es816x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala index aa8bb31e67..640084c4ec 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestconfig import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.TestConfigApi.TestConfigResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestConfigActionHandler extends Logging { +class RRTestConfigActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +52,7 @@ class RRTestConfigActionHandler extends Logging { case Right(response) => listener.onResponse(new RRTestConfigResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRTestConfig internal error", ex) + logger.error(s"RRTestConfig internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es816x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala b/es816x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala index 494e9150b4..98cc0c945d 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.dlsfls import cats.data.StateT import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.DirectoryReader import org.elasticsearch.common.util.concurrent.ThreadContext import org.elasticsearch.core.CheckedFunction @@ -31,7 +31,7 @@ import java.io.IOException import java.util.function.{Function => JavaFunction} import scala.util.{Failure, Success, Try} -object RoleIndexSearcherWrapper extends Logging { +object RoleIndexSearcherWrapper extends RequestIdAwareLogging { val instance: JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] = new JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] { @@ -54,7 +54,7 @@ object RoleIndexSearcherWrapper extends Logging { } .map(r => (r, r)) case None => - logger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") + noRequestIdLogger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") Success((reader, reader)) } } @@ -66,13 +66,13 @@ object RoleIndexSearcherWrapper extends Logging { nel <- NonEmptyString.from(value) match { case Right(nel) => Success(nel) case Left(_) => - logger.debug("FLS: empty header value") + noRequestIdLogger.debug("FLS: empty header value") failure } fields <- transientFieldsFromHeaderValue.fromRawValue(nel) match { case result@Success(_) => result case Failure(ex) => - logger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) + noRequestIdLogger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) failure } } yield fields diff --git a/es816x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala b/es816x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala index ce77d77f4e..aeccbfcead 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.dlsfls import com.google.common.collect.Iterators -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.codecs.StoredFieldsReader import org.apache.lucene.index.* import org.apache.lucene.index.StoredFieldVisitor.Status @@ -39,21 +39,21 @@ import scala.jdk.CollectionConverters.* import scala.util.Try private class RorDocumentFieldReader(reader: LeafReader, fieldsRestrictions: FieldsRestrictions) - extends SequentialStoredFieldsLeafReader(reader) with Logging { + extends SequentialStoredFieldsLeafReader(reader) with RequestIdAwareLogging { private val policy = new FieldsPolicy(fieldsRestrictions) private val remainingFieldsInfo = { val fInfos = in.getFieldInfos val newInfos = if (fInfos.asScala.isEmpty) { - logger.warn("original fields were empty! This is weird!") + noRequestIdLogger.warn("original fields were empty! This is weird!") fInfos } else { val remainingFields = fInfos.asScala.filter(f => policy.canKeep(f.name)).toSet new FieldInfos(remainingFields.toArray) } - logger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") - logger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") - logger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") + noRequestIdLogger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") newInfos } private val jsonPolicyBasedFilterer = new JsonPolicyBasedFilterer(policy) diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala index 9365230fe3..9abe861fe3 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.* import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest import org.elasticsearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest @@ -87,7 +87,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, threadPool: ThreadPool) (implicit generator: UniqueIdentifierGenerator, scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle(engines: Engines, esContext: EsContext): Task[Either[Error, Unit]] = { @@ -243,7 +243,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, case SearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case MultiSearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case _ => - logger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") + noRequestIdLogger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") regularRequestHandler.handle(new DummyCompositeIndicesEsRequestContext(request, esContext, aclContext, clusterService, threadPool)) } // rest diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala index cab02aff37..100edd72ac 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.common.io.stream.StreamOutput import org.elasticsearch.xcontent.{ToXContent, ToXContentObject, XContentBuilder} @@ -45,7 +45,7 @@ import scala.util.{Failure, Success, Try} class CurrentUserMetadataRequestHandler(engine: Engine, esContext: EsContext) - extends Logging { + extends RequestIdAwareLogging { def handle(request: RequestContext.Aux[CurrentUserMetadataRequestBlockContext] with EsRequest[CurrentUserMetadataRequestBlockContext]): Task[Unit] = { engine.core.accessControl @@ -69,7 +69,7 @@ class CurrentUserMetadataRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(ex.asInstanceOf[Exception]) } } @@ -86,13 +86,13 @@ class CurrentUserMetadataRequestHandler(engine: Engine, )) } - private def onPassThrough(requestContext: RequestContext): Unit = { - logger.warn(s"[${requestContext.id.toRequestId.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") + private def onPassThrough(implicit requestContext: RequestContext): Unit = { + logger.warn(s"Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") esContext.listener.onFailure(createRorNotEnabledResponse()) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala index 2fb01dcc41..c5c44fda92 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala @@ -20,7 +20,7 @@ import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.RegularRequestResult @@ -49,7 +49,7 @@ class RegularRequestHandler(engine: Engine, esContext: EsContext, threadPool: ThreadPool) (implicit scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle[B <: BlockContext : BlockContextUpdater](request: RequestContext.Aux[B] with EsRequest[B]): Task[Unit] = { engine.core.accessControl @@ -85,7 +85,7 @@ class RegularRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(new Exception(ex)) } } @@ -99,7 +99,7 @@ class RegularRequestHandler(engine: Engine, case ModificationResult.ShouldBeInterrupted => onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case ModificationResult.CannotModify => - logger.error(s"[${request.id.toRequestId.show}] Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") + noRequestIdLogger.error(s"Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case CustomResponse(response) => respond(request, response) @@ -247,7 +247,7 @@ class RegularRequestHandler(engine: Engine, esContext.listener.onResponse(response) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } \ No newline at end of file diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala index f4f832dedc..bfc421bdd5 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.index.query.{AbstractQueryBuilder, QueryBuilder, QueryBuilders} import org.elasticsearch.search.aggregations.AggregatorFactories @@ -40,7 +40,7 @@ import tech.beshu.ror.implicits.* import java.util.UUID import scala.jdk.CollectionConverters.* -object SearchRequestOps extends Logging { +object SearchRequestOps extends RequestIdAwareLogging { implicit class QueryBuilderOps(val builder: Option[QueryBuilder]) extends AnyVal { @@ -52,7 +52,7 @@ object SearchRequestOps extends Logging { val modifiedQuery: AbstractQueryBuilder[_] = provideNewQueryWithAppliedFilter(builder, filterQuery) Some(modifiedQuery) case None => - logger.debug(s"[${requestId.show}] No filter applied to query.") + logger.debug(s"No filter applied to query.") builder } } @@ -92,7 +92,7 @@ object SearchRequestOps extends Logging { case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, requestId) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) disableCaching(requestId) case BasedOnBlockContextOnly.NotAllowedFieldsUsed(notAllowedFields) => modifyNotAllowedFieldsInRequest(notAllowedFields) @@ -138,8 +138,8 @@ object SearchRequestOps extends Logging { } } - private def disableCaching(requestId: RequestContext.Id) = { - logger.debug(s"[${requestId.show}] ACL uses context header for fields rule, will disable request cache for SearchRequest") + private def disableCaching(implicit requestId: RequestContext.Id) = { + logger.debug(s"ACL uses context header for fields rule, will disable request cache for SearchRequest") request.requestCache(false) } } diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala index 993bdbd7a0..f0d04a6837 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala @@ -17,7 +17,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.action.{CompositeIndicesRequest, IndicesRequest} import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -32,7 +31,7 @@ import java.time.Instant abstract class BaseEsRequestContext[B <: BlockContext](esContext: EsContext, clusterService: RorClusterService) - extends RequestContext with Logging { + extends RequestContext { override type BLOCK_CONTEXT = B diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala index ae8abbe1f5..0ee2967364 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala @@ -18,7 +18,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -26,8 +25,9 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import scala.util.Try +import tech.beshu.ror.utils.RequestIdAwareLogging -trait EsRequest[B <: BlockContext] extends Logging { +trait EsRequest[B <: BlockContext] extends RequestIdAwareLogging { implicit def threadPool: ThreadPool final def modifyUsing(blockContext: B): ModificationResult = { @@ -35,7 +35,7 @@ trait EsRequest[B <: BlockContext] extends Logging { Try(modifyRequest(blockContext)) .fold( ex => { - logger.error(s"[${blockContext.requestContext.id.show}] Cannot modify request with filtered data", ex) + logger.error(s"Cannot modify request with filtered data", ex)(blockContext) ModificationResult.CannotModify }, identity diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala index c6a9dcbefd..f773b3efb1 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala @@ -51,7 +51,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest private def discoverDataStreams() = { val dataStreams = dataStreamsFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered data streams: ${dataStreams.show}") + logger.debug(s"Discovered data streams: ${dataStreams.show}") dataStreams } @@ -59,7 +59,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest val backingIndices = backingIndicesFrom(actionRequest) backingIndices match { case BackingIndices.IndicesInvolved(filteredIndices, _) => - logger.debug(s"[${id.show}] Discovered indices: ${filteredIndices.show}") + logger.debug(s"Discovered indices: ${filteredIndices.show}") case BackingIndices.IndicesNotInvolved => } backingIndices diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala index c091179cb6..d150709314 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala @@ -85,7 +85,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: case Some(indices) => update(actionRequest, indices, blockContext.filter, blockContext.fieldLevelSecurity) case None => - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -101,7 +101,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } \ No newline at end of file diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala index 71d462de57..48014e1bdc 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala @@ -73,7 +73,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, } yield update(actionRequest, filteredIndices, allAllowedIndices) result.getOrElse { - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -86,7 +86,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala index 95d882c3b5..f607c0e347 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala @@ -50,7 +50,7 @@ abstract class BaseRepositoriesEsRequestContext[R <: ActionRequest](actionReques case Some(repositories) => update(actionRequest, repositories) case None => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") ShouldBeInterrupted } } diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala index b3b1d66238..7ef0f32014 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala @@ -42,7 +42,7 @@ abstract class BaseSingleIndexEsRequestContext[R <: ActionRequest](actionRequest filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } update(request, filteredIndices.head) } diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala index b5ab70fe7a..c1b2e7ea27 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala @@ -62,7 +62,7 @@ class BulkEsRequestContext(actionRequest: BulkRequest, case (_, _) => ShouldBeInterrupted } } else { - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because origin request contained different " + + logger.error(s"Cannot alter MultiGetRequest request, because origin request contained different " + s"number of requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } @@ -90,18 +90,18 @@ class BulkEsRequestContext(actionRequest: BulkRequest, updateRequestWithIndices(request, nel) Modified case None => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because empty list of indices was found") + logger.error(s"Cannot alter MultiGetRequest request, because empty list of indices was found") ShouldBeInterrupted } case Indices.NotFound => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because no allowed indices were found") + logger.error(s"Cannot alter MultiGetRequest request, because no allowed indices were found") ShouldBeInterrupted } } private def updateRequestWithIndices(request: DocWriteRequest[_], indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } request.index(indices.head.stringify) } diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala index 75a75fcef5..96a043b298 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala @@ -53,14 +53,14 @@ class BulkShardEsRequestContext(actionRequest: BulkShardRequest, case Success(_) => Modified case Failure(ex) => - logger.error(s"[${id.show}] Cannot modify BulkShardRequest", ex) + logger.error(s"Cannot modify BulkShardRequest", ex) CannotModify } } private def tryUpdate(request: BulkShardRequest, indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } val singleIndex = indices.head val uuid = clusterService.indexOrAliasUuids(singleIndex.name).toList.head diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala index 65a168092a..158ac485a5 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala @@ -45,14 +45,14 @@ class ClusterAllocationExplainEsRequestContext(actionRequest: ClusterAllocationE getRequestedIndexFrom(request) match { case Some(_) => if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateIndexIn(request, filteredIndices.head) Modified case None if filteredIndices.exists(_.name === ClusterIndexName.Local.wildcard) => Modified case None => - logger.error(s"[${id.show}] Cluster allocation explain request without index name is unavailable when block contains `indices` rule") + logger.error(s"Cluster allocation explain request without index name is unavailable when block contains `indices` rule") ShouldBeInterrupted } } diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala index 61fdab9d83..5bf09449c5 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala @@ -79,7 +79,7 @@ class EsqlIndicesEsRequestContext private(actionRequest: ActionRequest with Comp request } case Left(ClassificationError.ParsingException(ex)) => - logger.debug(s"[${id.show}] Cannot parse ESQL statement - we can pass it though, because ES is going to reject it. Cause:", ex) + logger.debug(s"Cannot parse ESQL statement - we can pass it though, because ES is going to reject it. Cause:", ex) request } } @@ -90,7 +90,7 @@ class EsqlIndicesEsRequestContext private(actionRequest: ActionRequest with Comp case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala index 5778b8968d..02dec730ed 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala @@ -66,7 +66,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, updateAliases(actionRequest, aliases) UpdateResponse.sync(updateAliasesResponse(aliases.includedOnly, _)) case None => - logger.error(s"[${id.show}] At least one alias and one index has to be allowed. " + + logger.error(s"At least one alias and one index has to be allowed. " + s"Found allowed indices: [${blockContext.indices.show}]." + s"Found allowed aliases: [${blockContext.aliases.show}]") ShouldBeInterrupted @@ -114,7 +114,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, .indices().asSafeSet .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } @@ -122,7 +122,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, val aliases = rawRequestAliasesSet(request) .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered aliases: ${aliases.show}") + logger.debug(s"Discovered aliases: ${aliases.show}") aliases } diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala index abb85d42b7..f9e2c87e53 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala @@ -55,7 +55,7 @@ class IndicesAliasesEsRequestContext(actionRequest: IndicesAliasesRequest, if (originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala index 584c97e9f5..834bff8e8e 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala @@ -120,7 +120,7 @@ class MultiGetEsRequestContext(actionRequest: MultiGetRequest, case Nil => updateItemWithNonExistingIndex(item) case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } item.index(index.stringify) } diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala index 989956d79a..9e13edee8d 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala @@ -78,7 +78,7 @@ class MultiSearchEsRequestContext(actionRequest: MultiSearchRequest, } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala index 9191e33b66..5a61356f48 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala @@ -47,7 +47,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { request.getRequests.removeIf { request => removeOrAlter(request, filteredIndices.toCovariantSet) } if (request.getRequests.asScala.isEmpty) { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") ShouldBeInterrupted } else { Modified @@ -63,7 +63,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, true case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") } request.index(index.stringify) false diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala index c411df93c5..c7b99f6e85 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala @@ -52,7 +52,7 @@ class PutRollupJobEsRequestContext private(actionRequest: ActionRequest, if(originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala index ba5b52b4f1..f80e716349 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler.request.context.types import cats.data.NonEmptyList import cats.implicits.* import com.google.common.collect.Sets -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionRequest import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.AccessControlStaticContext @@ -51,7 +51,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (tryUpdate(actionRequest, filteredIndices)) Modified else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") ShouldBeInterrupted } } @@ -66,7 +66,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques } } -object ReflectionBasedIndicesEsRequestContext extends Logging { +object ReflectionBasedIndicesEsRequestContext extends RequestIdAwareLogging { def unapply(arg: ReflectionBasedActionRequest): Option[ReflectionBasedIndicesEsRequestContext] = { requestedIndicesFrom(arg.esContext.actionRequest) diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala index 489d0187bc..c42dfc3b78 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala @@ -58,10 +58,10 @@ class ReindexEsRequestContext(actionRequest: ReindexRequest, Modified } else { if (!isDestinationIndexOnFilteredIndicesList) { - logger.info(s"[${id.show}] Destination index of _reindex request is forbidden") + logger.info(s"Destination index of _reindex request is forbidden") } if (!isSearchRequestComposedOnlyOfAllowedIndices) { - logger.info(s"[${id.show}] At least one index from sources indices list of _reindex request is forbidden") + logger.info(s"At least one index from sources indices list of _reindex request is forbidden") } ShouldBeInterrupted } diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala index 2c1b0014e0..97b8ccd9c5 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala @@ -74,7 +74,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo request } case Left(_) => - logger.debug(s"[${id.show}] Cannot parse SQL statement - we can pass it though, because ES is going to reject it") + logger.debug(s"Cannot parse SQL statement - we can pass it though, because ES is going to reject it") request } } @@ -85,7 +85,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala index 0c67384c1e..d7e743e648 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CleanupRepositoryEsRequestContext(actionRequest: CleanupRepositoryRequest, override protected def update(request: CleanupRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala index 44b7d78dfd..d09015139b 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CreateRepositoryEsRequestContext(actionRequest: PutRepositoryRequest, override protected def update(request: PutRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala index eaf9334872..0cf32e1bea 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class DeleteRepositoryEsRequestContext(actionRequest: DeleteRepositoryRequest, override protected def update(request: DeleteRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala index cee0bffd4c..d1410eff3d 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class VerifyRepositoryEsRequestContext(actionRequest: VerifyRepositoryRequest, override protected def update(request: VerifyRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala index ead4fcf250..20501516d5 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala @@ -68,32 +68,32 @@ class CreateSnapshotEsRequestContext(actionRequest: CreateSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala index a56aba660e..621d744767 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala @@ -60,7 +60,7 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -71,14 +71,14 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, .toRight(()) } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala index 22869bbb4f..b81f333174 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala @@ -68,7 +68,7 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, case r => r } case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala index 88887db96c..156deb5b80 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala @@ -63,7 +63,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -75,7 +75,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") } Right(snapshot) } @@ -88,7 +88,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala index 44ee8397ec..e522e440f1 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala @@ -100,12 +100,12 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { val repositories = blockContext.repositories if (allRepositoriesRequested(repositories)) { Right(RepositoryName.All) @@ -115,7 +115,7 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala index 9b58e1b7b5..0a42f8dc82 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.rollover.RolloverConfiguration import org.elasticsearch.action.admin.indices.template.get.GetComposableIndexTemplateAction import org.elasticsearch.cluster.metadata @@ -111,7 +111,7 @@ class GetComposableIndexTemplateEsRequestContext(actionRequest: GetComposableInd } -private[templates] object GetComposableIndexTemplateEsRequestContext extends Logging { +private[templates] object GetComposableIndexTemplateEsRequestContext extends RequestIdAwareLogging { def filter(templates: Map[String, ComposableIndexTemplate], usingTemplate: Set[Template] => Set[Template]) diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala index bd74c3a18f..1c6eecf409 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.{GetIndexTemplatesRequest, GetIndexTemplatesResponse} import org.elasticsearch.cluster.metadata.{AliasMetadata, IndexTemplateMetadata} import org.elasticsearch.common.collect.ImmutableOpenMap @@ -104,7 +104,7 @@ class GetTemplatesEsRequestContext(actionRequest: GetIndexTemplatesRequest, } -private[templates] object GetTemplatesEsRequestContext extends Logging { +private[templates] object GetTemplatesEsRequestContext extends RequestIdAwareLogging { def filter(templates: Iterable[IndexTemplateMetadata], usingTemplate: Set[Template] => Set[Template]) diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala index a8951de5b1..32116d8212 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala @@ -72,7 +72,7 @@ class MultiSearchTemplateEsRequestContext private(actionRequest: ActionRequest w } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala index e6f6d8916e..434787a686 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala @@ -55,7 +55,7 @@ class SimulateIndexTemplateRequestEsRequestContext(actionRequest: SimulateIndexT filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateRequest(request, filteredIndices.head, allAllowedIndices) } diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala index fbc4cf6776..46ed6e7a95 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala @@ -109,7 +109,7 @@ class SimulateExistingTemplateRequestEsRequestContext(existingTemplateName: Temp case Some(_) => updateResponse(namePatterns.toList, blockContext.allAllowedIndices.toList) case None => - logger.info(s"[${id.show}] User has no access to template ${existingTemplateName.show}") + logger.info(s"User has no access to template ${existingTemplateName.show}") ModificationResult.ShouldBeInterrupted } case other => diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala index 0ecd7a72b3..fe4d60bd42 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.queries import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.index.query.* import org.joor.Reflect.on import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.RequestFieldsUsage @@ -30,7 +30,7 @@ trait QueryFieldsUsage[QUERY <: QueryBuilder] { def fieldsIn(query: QUERY): RequestFieldsUsage } -object QueryFieldsUsage extends Logging { +object QueryFieldsUsage extends RequestIdAwareLogging { def apply[QUERY <: QueryBuilder](implicit ev: QueryFieldsUsage[QUERY]): QueryFieldsUsage[QUERY] = ev implicit class Ops[QUERY <: QueryBuilder : QueryFieldsUsage](val query: QUERY) { @@ -62,7 +62,7 @@ object QueryFieldsUsage extends Logging { Option(on(query).call("getFieldName").get[String]) match { case Some(fieldName: String) => UsingFields(NonEmptyList.one(UsedField(fieldName))) case _ => - logger.debug(s"Cannot extract fields for terms set query") + noRequestIdLogger.debug(s"Cannot extract fields for terms set query") CannotExtractFields } } @@ -89,7 +89,7 @@ object QueryFieldsUsage extends Logging { case builder: TermsSetQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder: WildcardQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder => - logger.debug(s"Cannot extract fields for query: ${builder.getName}") + noRequestIdLogger.debug(s"Cannot extract fields for query: ${builder.getName}") CannotExtractFields } diff --git a/es816x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala b/es816x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala index 0998bb9a5b..b4671e9e4d 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.handler.response import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.FieldsRestrictions import tech.beshu.ror.accesscontrol.domain.Header @@ -26,17 +26,17 @@ import tech.beshu.ror.accesscontrol.headerValues.transientFieldsToHeaderValue import tech.beshu.ror.accesscontrol.request.RequestContext import tech.beshu.ror.implicits.* -object FLSContextHeaderHandler extends Logging { +object FLSContextHeaderHandler extends RequestIdAwareLogging { def addContextHeader(threadPool: ThreadPool, - fieldsRestrictions: FieldsRestrictions, - requestId: RequestContext.Id): Unit = { + fieldsRestrictions: FieldsRestrictions) + (implicit requestId: RequestContext.Id): Unit = { val threadContext = threadPool.getThreadContext val header = createContextHeader(fieldsRestrictions) Option(threadContext.getHeader(header.name.value.value)) match { case None => implicit val show = headerShow - logger.debug(s"[${requestId.show}] Adding thread context header required by lucene. Header: '${header.show}'") + logger.debug(s"Adding thread context header required by lucene. Header: '${header.show}'") threadContext.putHeader(header.name.value.value, header.value.value) case Some(_) => } diff --git a/es816x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala b/es816x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala index f4078d757d..8a7fb3e997 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.admin.indices.template.get.{GetComponentTemplateAction, GetComposableIndexTemplateAction} import org.elasticsearch.action.admin.indices.template.put.{PutComponentTemplateAction, TransportPutComposableIndexTemplateAction} @@ -47,7 +47,7 @@ import scala.jdk.CollectionConverters.* final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJsonParserFactory)(using Clock) extends DataStreamService - with Logging { + with RequestIdAwareLogging { private val masterNodeTimeout: TimeValue = TimeValue(30000) private val ackTimeout: TimeValue = TimeValue(30000) @@ -205,11 +205,11 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ response <- Task.measure( task = Task.delay(nodeClient.execute(action, request).actionGet()), logTimeMeasurement = duration => Task.delay { - logger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") + noRequestIdLogger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") } ) _ <- Task.delay { - logger.debug(s"Action ${action.name()} response: ${response.toString}") + noRequestIdLogger.debug(s"Action ${action.name()} response: ${response.toString}") } } yield response } @@ -217,7 +217,7 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ def executeAck[REQUEST <: ActionRequest, RESPONSE <: AcknowledgedResponse](action: ActionType[RESPONSE], request: REQUEST): Task[RESPONSE] = { executeT(action, request) - .tapEval(response => Task.delay(logger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) + .tapEval(response => Task.delay(noRequestIdLogger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) } private def supportedActions: Map[ActionType[ActionResponse], TransportAction[ActionRequest, ActionResponse]] = { diff --git a/es816x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala b/es816x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala index 40ae6d97e0..f24d74c52d 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.support.WriteRequest.RefreshPolicy import org.elasticsearch.client.internal.node.NodeClient @@ -37,7 +37,7 @@ import scala.jdk.CollectionConverters.* class EsIndexJsonContentService(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexJsonContentService - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -62,14 +62,14 @@ class EsIndexJsonContentService(client: NodeClient, Option(response.getSourceAsMap) match { case Some(map) => val source = map.asScala.toMap.asStringMap - logger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") Right(source) case None => - logger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") + noRequestIdLogger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") Right(Map.empty[String, String]) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(ContentNotFound) } } @@ -77,7 +77,7 @@ class EsIndexJsonContentService(client: NodeClient, .onErrorRecover { case _: ResourceNotFoundException => Left(ContentNotFound) case ex => - logger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) Left(CannotReachContentSource) } } @@ -103,14 +103,14 @@ class EsIndexJsonContentService(client: NodeClient, case status if status / 100 == 2 => Right(()) case status => - logger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") Left(CannotWriteToIndex) } } .executeOn(RorSchedulers.blockingScheduler) .onErrorRecover { case ex => - logger.error(s"Cannot write to document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]", ex) Left(CannotWriteToIndex) } } diff --git a/es816x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala b/es816x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala index 2a2669e8b4..619cb6daf2 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala @@ -22,7 +22,7 @@ import cats.kernel.Monoid import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task import monix.execution.{CancelablePromise, Scheduler} -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction.{ResolvedAlias, ResolvedIndex} @@ -65,7 +65,7 @@ class EsServerBasedRorClusterService(nodeName: String, threadPool: ThreadPool) (implicit val scheduler: Scheduler) extends RorClusterService - with Logging { + with RequestIdAwareLogging { import EsServerBasedRorClusterService.* @@ -156,7 +156,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractAccessibilityFrom) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify get request. Blocking document", ex) + logger.error(s"Could not verify get request. Blocking document", ex)(id) Inaccessible } } @@ -168,7 +168,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractResultsFromSearchResponse) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify documents returned by multi get response. Blocking all returned documents", ex) + logger.error(s"Could not verify documents returned by multi get response. Blocking all returned documents", ex)(id) blockAllDocsReturned(documents) } .map(results => zip(results, documents)) @@ -277,7 +277,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService): Task[List[FullRemoteDataStreamWithAliases]] = { getRemoteClusterClient(remoteClusterService, remoteClusterName) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -333,7 +333,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService) = { getRemoteClusterClient(remoteClusterService, remoteClusterName) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -423,7 +423,7 @@ class EsServerBasedRorClusterService(nodeName: String, } } case None => - logger.error("Cannot supply Snapshots Service. Please, report the issue!!!") + noRequestIdLogger.error("Cannot supply Snapshots Service. Please, report the issue!!!") Task.now(Set.empty[Snapshot]) } } diff --git a/es816x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala b/es816x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala index a657d15ca9..31d96f15a2 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.services import cats.data.NonEmptyList -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.bulk.{BackoffPolicy, BulkProcessor, BulkRequest, BulkResponse} import org.elasticsearch.action.index.IndexRequest import org.elasticsearch.action.{ActionListener, DocWriteRequest} @@ -39,7 +39,7 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, (using Clock) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { private val bulkProcessor = BulkProcessor @@ -80,25 +80,25 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, private class AuditSinkBulkProcessorListener extends BulkProcessor.Listener { override def beforeBulk(executionId: Long, request: BulkRequest): Unit = { - logger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") + noRequestIdLogger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") } override def afterBulk(executionId: Long, request: BulkRequest, response: BulkResponse): Unit = { if (response.hasFailures) { - logger.error("Some failures flushing the BulkProcessor: ") + noRequestIdLogger.error("Some failures flushing the BulkProcessor: ") response .getItems.to(LazyList) .filter(_.isFailed) .map(_.getFailureMessage) .groupBy(identity) .foreach { case (message, stream) => - logger.error(s"${stream.size}x: $message") + noRequestIdLogger.error(s"${stream.size}x: $message") } } } override def afterBulk(executionId: Long, request: BulkRequest, failure: Throwable): Unit = { - logger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) + noRequestIdLogger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) } } diff --git a/es816x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala b/es816x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala index a8def0ec7a..b3c5593c36 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala @@ -22,7 +22,7 @@ import org.apache.http.auth.{AuthScope, Credentials, UsernamePasswordCredentials import org.apache.http.conn.ssl.NoopHostnameVerifier import org.apache.http.impl.client.BasicCredentialsProvider import org.apache.http.impl.nio.client.HttpAsyncClientBuilder -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.* import org.elasticsearch.client.RestClient.FailureListener import tech.beshu.ror.accesscontrol.audit.sink.AuditDataStreamCreator @@ -38,7 +38,7 @@ import scala.collection.parallel.CollectionConverters.* final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient]) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { override def submit(indexName: IndexName.Full, documentId: String, jsonRecord: String) (implicit requestId: RequestId): Unit = { @@ -77,21 +77,21 @@ final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient] override def onSuccess(response: Response): Unit = { response.getStatusLine.getStatusCode / 100 match { case 2 => // 2xx - logger.debug(s"[${requestId.show}] Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") + logger.debug(s"Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") case _ => - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") } } override def onFailure(ex: Exception): Unit = { - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId]", ex) + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId]", ex) } } override val dataStreamCreator: AuditDataStreamCreator = new AuditDataStreamCreator(clients.map(new RestClientDataStreamService(_))) } -object RestClientAuditSinkService extends Logging { +object RestClientAuditSinkService extends RequestIdAwareLogging { def create(remoteCluster: AuditCluster.RemoteAuditCluster): RestClientAuditSinkService = { remoteCluster.mode match { @@ -122,7 +122,7 @@ object RestClientAuditSinkService extends Logging { .setFailureListener( new FailureListener { override def onFailure(node: Node): Unit = { - logger.debug( + noRequestIdLogger.debug( s"[AUDIT] Node marked dead: ${node.getHost.getSchemeName}://${node.getHost.getHostName}:${node.getHost.getPort}. The client will attempt failover.", ) } diff --git a/es816x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala b/es816x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala index 1f00261ee4..6344d8c3ae 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.Channel import io.netty.handler.ssl.NotSslRecordException -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.bulk.IncrementalBulkService.Enabled import org.elasticsearch.common.network.NetworkService import org.elasticsearch.common.settings.{ClusterSettings, Settings} @@ -42,7 +42,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, tracer: Tracer, fipsCompliant: Boolean) extends Netty4HttpServerTransport(settings, networkService, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory, tracer, TLSConfig.noTLS(), null, null) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, ssl.clientAuthenticationEnabled) @@ -50,7 +50,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, override def onException(channel: HttpChannel, cause: Exception): Unit = { if (!this.lifecycle.started) return - else if (cause.getCause.isInstanceOf[NotSslRecordException]) logger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) + else if (cause.getCause.isInstanceOf[NotSslRecordException]) noRequestIdLogger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) else super.onException(channel, cause) channel.close() } diff --git a/es816x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala b/es816x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala index 2fa1d7871c..2d2b0360d4 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.* import io.netty.handler.ssl.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.TransportVersion import org.elasticsearch.cluster.node.DiscoveryNode import org.elasticsearch.common.io.stream.NamedWriteableRegistry @@ -46,7 +46,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, sharedGroupFactory: SharedGroupFactory, fipsCompliant: Boolean) extends Netty4Transport(settings, TransportVersion.current(), threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = SSLCertHelper.prepareClientSSLContext(ssl, fipsCompliant, ssl.certificateVerificationEnabled) private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, clientAuthenticationEnabled = false) @@ -78,7 +78,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, override def exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable): Unit = { if (cause.isInstanceOf[NotSslRecordException] || (cause.getCause != null && cause.getCause.isInstanceOf[NotSslRecordException])) { - logger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") + noRequestIdLogger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") ctx.channel.close } else { super.exceptionCaught(ctx, cause) diff --git a/es816x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala b/es816x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala index 9664662781..0cc19e6029 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.utils import cats.Show import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.client.internal.node.NodeClient import org.elasticsearch.rest.* @@ -37,7 +37,7 @@ import java.util import scala.util.Try class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandler) - extends RestHandler with Logging { + extends RestHandler with RequestIdAwareLogging { private val wrapped = doPrivileged { wrapSomeActions(underlying) @@ -101,11 +101,11 @@ class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandle private def logError(error: AuthorizationValueError): Unit = { { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorSanitizedShow - logger.warn(s"The incoming request was malformed. Cause: ${error.show}") + noRequestIdLogger.warn(s"The incoming request was malformed. Cause: ${error.show}") } if (logger.delegate.isDebugEnabled()) { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorWithDetailsShow - logger.debug(s"Malformed request detailed cause: ${error.show}") + noRequestIdLogger.debug(s"Malformed request detailed cause: ${error.show}") } } diff --git a/es816x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala b/es816x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala index 5ab1e35742..a9af8f710a 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala @@ -16,13 +16,13 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.settings.Settings import tech.beshu.ror.tools.core.patches.PatchingVerifier import tech.beshu.ror.tools.core.patches.PatchingVerifier.Error.{CannotVerifyIfPatched, EsNotPatched} import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -object EsPatchVerifier extends Logging { +object EsPatchVerifier extends RequestIdAwareLogging { def verify(settings: Settings): Unit = doPrivileged { pathHomeFrom(settings).flatMap(PatchingVerifier.verify) match { @@ -30,7 +30,7 @@ object EsPatchVerifier extends Logging { case Left(e@EsNotPatched(_)) => throw new IllegalStateException(e.message) case Left(e@CannotVerifyIfPatched(_)) => - logger.warn(e.message) + noRequestIdLogger.warn(e.message) } } diff --git a/es816x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala b/es816x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala index b73104a175..c292a44ed2 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.internal.node.NodeClient import org.elasticsearch.transport.RemoteClusterService import org.joor.Reflect.on @@ -26,14 +26,14 @@ import java.util.function.Supplier import scala.util.{Failure, Success, Try} class RemoteClusterServiceSupplier(nodeClient: NodeClient) - extends Supplier[Option[RemoteClusterService]] with Logging { + extends Supplier[Option[RemoteClusterService]] with RequestIdAwareLogging { override def get(): Option[RemoteClusterService] = { extractRemoteClusterService() match { case Success(remoteClusterService) => remoteClusterService case Failure(ex) => - logger.error("Cannot extract RemoteClusterService from NodeClient", ex) + noRequestIdLogger.error("Cannot extract RemoteClusterService from NodeClient", ex) None } } diff --git a/es818x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es818x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index 9a55b9861f..7f9896e3f5 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.support.{ActionFilter, ActionFilterChain} import org.elasticsearch.action.{ActionListener, ActionRequest, ActionResponse} import org.elasticsearch.client.internal.node.NodeClient @@ -62,7 +62,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, rorEsConfig: ReadonlyRestEsConfig) (implicit environmentConfig: EnvironmentConfig) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = environmentConfig.uniqueIdentifierGenerator @@ -212,12 +212,12 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def handleRorNotReadyYet(esContext: EsContext): Unit = { - logger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") + noRequestIdLogger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") rorNotAvailableRequestHandler.handleRorNotReadyYet(esContext) } private def handleRorFailedToStart(esContext: EsContext): Unit = { - logger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") + noRequestIdLogger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") rorNotAvailableRequestHandler.handleRorFailedToStart(esContext) } @@ -239,7 +239,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def logAndSetStartingFailureState(failure: StartingFailure): Unit = { - logger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) + noRequestIdLogger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) rorInstanceState.set(RorInstanceStartingState.NotStarted(failure)) } } diff --git a/es818x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala b/es818x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala index 1fb22fc79d..53452eb8e6 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.xcontent.LoggingDeprecationHandler import org.elasticsearch.rest.RestResponse import org.elasticsearch.transport.BytesRefRecycler @@ -32,7 +32,7 @@ import tech.beshu.ror.accesscontrol.domain.ResponseFieldsFiltering.{AccessMode, import scala.jdk.CollectionConverters.* trait ResponseFieldsFiltering { - this: Logging => + this: RequestIdAwareLogging => private val responseFieldsRestrictions: Atomic[Option[ResponseFieldsRestrictions]] = Atomic(None: Option[ResponseFieldsRestrictions]) diff --git a/es818x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala b/es818x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala index 0f26750588..da95de59a4 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.action.{ActionListener, ActionResponse} import org.elasticsearch.threadpool.ThreadPool @@ -37,7 +37,7 @@ sealed abstract class RorActionListener[T](val underlying: ActionListener[T]) ex final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionListener[T], correlationId: Eval[CorrelationId]) - extends RorActionListener[T](underlying) with Logging { + extends RorActionListener[T](underlying) with RequestIdAwareLogging { override def onFailure(e: Exception): Unit = { super.onFailure(adaptExceptionIfNeeded(e)) @@ -47,7 +47,7 @@ final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionLis ex match { case esException: ElasticsearchException => esException case other => - logger.error(s"[${correlationId.value.show}] Internal error.", other) + noRequestIdLogger.error(s"[${correlationId.value.show}] Internal error.", other) new ElasticsearchException(s"[${correlationId.value.show}] Internal error. See logs for details.") } } diff --git a/es818x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala b/es818x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala index 4f0bc8c6fa..c68cc24623 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.http.HttpChannel import org.elasticsearch.rest.{AbstractRestChannel, RestChannel as EsRestChannel, RestRequest as EsRestRequest, RestResponse as EsRestResponse} import squants.information.{Bytes, Information} @@ -40,7 +40,7 @@ object RorRestChannel { final class RorRestChannel private(underlying: EsRestChannel, val restRequest: RorRestRequest) extends AbstractRestChannel(underlying.request(), true) with ResponseFieldsFiltering - with Logging { + with RequestIdAwareLogging { override def sendResponse(response: EsRestResponse): Unit = { ThreadRepo.removeRestChannel(this) diff --git a/es818x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala b/es818x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala index 6babc712b9..3c80750a25 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala @@ -18,16 +18,15 @@ package tech.beshu.ror.es.actions.rradmin import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.ConfigApi.ConfigResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAdminActionHandler extends Logging { +class RRAdminActionHandler extends RequestIdAwareLogging { private implicit val adminRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +51,7 @@ class RRAdminActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAdminResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAdminAction internal error", ex) + logger.error("RRAdminAction internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es818x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala b/es818x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala index c55835a1d0..ce45c6f48e 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala @@ -16,18 +16,15 @@ */ package tech.beshu.ror.es.actions.rrauthmock -import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.AuthMockApi.AuthMockResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier -import tech.beshu.ror.implicits.* +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAuthMockActionHandler extends Logging { +class RRAuthMockActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -53,7 +50,7 @@ class RRAuthMockActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAuthMockResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAuthMock internal error", ex) + logger.error("RRAuthMock internal error", ex) listener.onFailure(new Exception(ex)) } } diff --git a/es818x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala b/es818x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala index aa8bb31e67..640084c4ec 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestconfig import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.TestConfigApi.TestConfigResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestConfigActionHandler extends Logging { +class RRTestConfigActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +52,7 @@ class RRTestConfigActionHandler extends Logging { case Right(response) => listener.onResponse(new RRTestConfigResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRTestConfig internal error", ex) + logger.error(s"RRTestConfig internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es818x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala b/es818x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala index 494e9150b4..98cc0c945d 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.dlsfls import cats.data.StateT import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.DirectoryReader import org.elasticsearch.common.util.concurrent.ThreadContext import org.elasticsearch.core.CheckedFunction @@ -31,7 +31,7 @@ import java.io.IOException import java.util.function.{Function => JavaFunction} import scala.util.{Failure, Success, Try} -object RoleIndexSearcherWrapper extends Logging { +object RoleIndexSearcherWrapper extends RequestIdAwareLogging { val instance: JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] = new JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] { @@ -54,7 +54,7 @@ object RoleIndexSearcherWrapper extends Logging { } .map(r => (r, r)) case None => - logger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") + noRequestIdLogger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") Success((reader, reader)) } } @@ -66,13 +66,13 @@ object RoleIndexSearcherWrapper extends Logging { nel <- NonEmptyString.from(value) match { case Right(nel) => Success(nel) case Left(_) => - logger.debug("FLS: empty header value") + noRequestIdLogger.debug("FLS: empty header value") failure } fields <- transientFieldsFromHeaderValue.fromRawValue(nel) match { case result@Success(_) => result case Failure(ex) => - logger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) + noRequestIdLogger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) failure } } yield fields diff --git a/es818x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala b/es818x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala index ce77d77f4e..aeccbfcead 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.dlsfls import com.google.common.collect.Iterators -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.codecs.StoredFieldsReader import org.apache.lucene.index.* import org.apache.lucene.index.StoredFieldVisitor.Status @@ -39,21 +39,21 @@ import scala.jdk.CollectionConverters.* import scala.util.Try private class RorDocumentFieldReader(reader: LeafReader, fieldsRestrictions: FieldsRestrictions) - extends SequentialStoredFieldsLeafReader(reader) with Logging { + extends SequentialStoredFieldsLeafReader(reader) with RequestIdAwareLogging { private val policy = new FieldsPolicy(fieldsRestrictions) private val remainingFieldsInfo = { val fInfos = in.getFieldInfos val newInfos = if (fInfos.asScala.isEmpty) { - logger.warn("original fields were empty! This is weird!") + noRequestIdLogger.warn("original fields were empty! This is weird!") fInfos } else { val remainingFields = fInfos.asScala.filter(f => policy.canKeep(f.name)).toSet new FieldInfos(remainingFields.toArray) } - logger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") - logger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") - logger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") + noRequestIdLogger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") newInfos } private val jsonPolicyBasedFilterer = new JsonPolicyBasedFilterer(policy) diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala index 4c8499ad39..35ecfff271 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.* import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest import org.elasticsearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest @@ -87,7 +87,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, threadPool: ThreadPool) (implicit generator: UniqueIdentifierGenerator, scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle(engines: Engines, esContext: EsContext): Task[Either[Error, Unit]] = { @@ -243,7 +243,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, case SearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case MultiSearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case _ => - logger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") + noRequestIdLogger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") regularRequestHandler.handle(new DummyCompositeIndicesEsRequestContext(request, esContext, aclContext, clusterService, threadPool)) } // rest diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala index cab02aff37..100edd72ac 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.common.io.stream.StreamOutput import org.elasticsearch.xcontent.{ToXContent, ToXContentObject, XContentBuilder} @@ -45,7 +45,7 @@ import scala.util.{Failure, Success, Try} class CurrentUserMetadataRequestHandler(engine: Engine, esContext: EsContext) - extends Logging { + extends RequestIdAwareLogging { def handle(request: RequestContext.Aux[CurrentUserMetadataRequestBlockContext] with EsRequest[CurrentUserMetadataRequestBlockContext]): Task[Unit] = { engine.core.accessControl @@ -69,7 +69,7 @@ class CurrentUserMetadataRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(ex.asInstanceOf[Exception]) } } @@ -86,13 +86,13 @@ class CurrentUserMetadataRequestHandler(engine: Engine, )) } - private def onPassThrough(requestContext: RequestContext): Unit = { - logger.warn(s"[${requestContext.id.toRequestId.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") + private def onPassThrough(implicit requestContext: RequestContext): Unit = { + logger.warn(s"Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") esContext.listener.onFailure(createRorNotEnabledResponse()) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala index 2fb01dcc41..c5c44fda92 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala @@ -20,7 +20,7 @@ import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.RegularRequestResult @@ -49,7 +49,7 @@ class RegularRequestHandler(engine: Engine, esContext: EsContext, threadPool: ThreadPool) (implicit scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle[B <: BlockContext : BlockContextUpdater](request: RequestContext.Aux[B] with EsRequest[B]): Task[Unit] = { engine.core.accessControl @@ -85,7 +85,7 @@ class RegularRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(new Exception(ex)) } } @@ -99,7 +99,7 @@ class RegularRequestHandler(engine: Engine, case ModificationResult.ShouldBeInterrupted => onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case ModificationResult.CannotModify => - logger.error(s"[${request.id.toRequestId.show}] Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") + noRequestIdLogger.error(s"Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case CustomResponse(response) => respond(request, response) @@ -247,7 +247,7 @@ class RegularRequestHandler(engine: Engine, esContext.listener.onResponse(response) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } \ No newline at end of file diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala index f4f832dedc..bfc421bdd5 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.index.query.{AbstractQueryBuilder, QueryBuilder, QueryBuilders} import org.elasticsearch.search.aggregations.AggregatorFactories @@ -40,7 +40,7 @@ import tech.beshu.ror.implicits.* import java.util.UUID import scala.jdk.CollectionConverters.* -object SearchRequestOps extends Logging { +object SearchRequestOps extends RequestIdAwareLogging { implicit class QueryBuilderOps(val builder: Option[QueryBuilder]) extends AnyVal { @@ -52,7 +52,7 @@ object SearchRequestOps extends Logging { val modifiedQuery: AbstractQueryBuilder[_] = provideNewQueryWithAppliedFilter(builder, filterQuery) Some(modifiedQuery) case None => - logger.debug(s"[${requestId.show}] No filter applied to query.") + logger.debug(s"No filter applied to query.") builder } } @@ -92,7 +92,7 @@ object SearchRequestOps extends Logging { case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, requestId) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) disableCaching(requestId) case BasedOnBlockContextOnly.NotAllowedFieldsUsed(notAllowedFields) => modifyNotAllowedFieldsInRequest(notAllowedFields) @@ -138,8 +138,8 @@ object SearchRequestOps extends Logging { } } - private def disableCaching(requestId: RequestContext.Id) = { - logger.debug(s"[${requestId.show}] ACL uses context header for fields rule, will disable request cache for SearchRequest") + private def disableCaching(implicit requestId: RequestContext.Id) = { + logger.debug(s"ACL uses context header for fields rule, will disable request cache for SearchRequest") request.requestCache(false) } } diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala index 993bdbd7a0..f0d04a6837 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala @@ -17,7 +17,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.action.{CompositeIndicesRequest, IndicesRequest} import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -32,7 +31,7 @@ import java.time.Instant abstract class BaseEsRequestContext[B <: BlockContext](esContext: EsContext, clusterService: RorClusterService) - extends RequestContext with Logging { + extends RequestContext { override type BLOCK_CONTEXT = B diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala index ae8abbe1f5..0ee2967364 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala @@ -18,7 +18,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -26,8 +25,9 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import scala.util.Try +import tech.beshu.ror.utils.RequestIdAwareLogging -trait EsRequest[B <: BlockContext] extends Logging { +trait EsRequest[B <: BlockContext] extends RequestIdAwareLogging { implicit def threadPool: ThreadPool final def modifyUsing(blockContext: B): ModificationResult = { @@ -35,7 +35,7 @@ trait EsRequest[B <: BlockContext] extends Logging { Try(modifyRequest(blockContext)) .fold( ex => { - logger.error(s"[${blockContext.requestContext.id.show}] Cannot modify request with filtered data", ex) + logger.error(s"Cannot modify request with filtered data", ex)(blockContext) ModificationResult.CannotModify }, identity diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala index c6a9dcbefd..f773b3efb1 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala @@ -51,7 +51,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest private def discoverDataStreams() = { val dataStreams = dataStreamsFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered data streams: ${dataStreams.show}") + logger.debug(s"Discovered data streams: ${dataStreams.show}") dataStreams } @@ -59,7 +59,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest val backingIndices = backingIndicesFrom(actionRequest) backingIndices match { case BackingIndices.IndicesInvolved(filteredIndices, _) => - logger.debug(s"[${id.show}] Discovered indices: ${filteredIndices.show}") + logger.debug(s"Discovered indices: ${filteredIndices.show}") case BackingIndices.IndicesNotInvolved => } backingIndices diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala index c091179cb6..d150709314 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala @@ -85,7 +85,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: case Some(indices) => update(actionRequest, indices, blockContext.filter, blockContext.fieldLevelSecurity) case None => - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -101,7 +101,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } \ No newline at end of file diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala index 71d462de57..48014e1bdc 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala @@ -73,7 +73,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, } yield update(actionRequest, filteredIndices, allAllowedIndices) result.getOrElse { - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -86,7 +86,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala index 95d882c3b5..f607c0e347 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala @@ -50,7 +50,7 @@ abstract class BaseRepositoriesEsRequestContext[R <: ActionRequest](actionReques case Some(repositories) => update(actionRequest, repositories) case None => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") ShouldBeInterrupted } } diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala index b3b1d66238..7ef0f32014 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala @@ -42,7 +42,7 @@ abstract class BaseSingleIndexEsRequestContext[R <: ActionRequest](actionRequest filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } update(request, filteredIndices.head) } diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala index b5ab70fe7a..c1b2e7ea27 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala @@ -62,7 +62,7 @@ class BulkEsRequestContext(actionRequest: BulkRequest, case (_, _) => ShouldBeInterrupted } } else { - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because origin request contained different " + + logger.error(s"Cannot alter MultiGetRequest request, because origin request contained different " + s"number of requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } @@ -90,18 +90,18 @@ class BulkEsRequestContext(actionRequest: BulkRequest, updateRequestWithIndices(request, nel) Modified case None => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because empty list of indices was found") + logger.error(s"Cannot alter MultiGetRequest request, because empty list of indices was found") ShouldBeInterrupted } case Indices.NotFound => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because no allowed indices were found") + logger.error(s"Cannot alter MultiGetRequest request, because no allowed indices were found") ShouldBeInterrupted } } private def updateRequestWithIndices(request: DocWriteRequest[_], indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } request.index(indices.head.stringify) } diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala index 75a75fcef5..96a043b298 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala @@ -53,14 +53,14 @@ class BulkShardEsRequestContext(actionRequest: BulkShardRequest, case Success(_) => Modified case Failure(ex) => - logger.error(s"[${id.show}] Cannot modify BulkShardRequest", ex) + logger.error(s"Cannot modify BulkShardRequest", ex) CannotModify } } private def tryUpdate(request: BulkShardRequest, indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } val singleIndex = indices.head val uuid = clusterService.indexOrAliasUuids(singleIndex.name).toList.head diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala index 65a168092a..158ac485a5 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala @@ -45,14 +45,14 @@ class ClusterAllocationExplainEsRequestContext(actionRequest: ClusterAllocationE getRequestedIndexFrom(request) match { case Some(_) => if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateIndexIn(request, filteredIndices.head) Modified case None if filteredIndices.exists(_.name === ClusterIndexName.Local.wildcard) => Modified case None => - logger.error(s"[${id.show}] Cluster allocation explain request without index name is unavailable when block contains `indices` rule") + logger.error(s"Cluster allocation explain request without index name is unavailable when block contains `indices` rule") ShouldBeInterrupted } } diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala index 5db7c76162..dda2eab6e5 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala @@ -80,7 +80,7 @@ class EsqlIndicesEsRequestContext private(actionRequest: ActionRequest with Comp request } case Left(ClassificationError.ParsingException(ex)) => - logger.debug(s"[${id.show}] Cannot parse ESQL statement - we can pass it though, because ES is going to reject it. Cause:", ex) + logger.debug(s"Cannot parse ESQL statement - we can pass it though, because ES is going to reject it. Cause:", ex) request } } @@ -91,7 +91,7 @@ class EsqlIndicesEsRequestContext private(actionRequest: ActionRequest with Comp case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala index 5778b8968d..02dec730ed 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala @@ -66,7 +66,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, updateAliases(actionRequest, aliases) UpdateResponse.sync(updateAliasesResponse(aliases.includedOnly, _)) case None => - logger.error(s"[${id.show}] At least one alias and one index has to be allowed. " + + logger.error(s"At least one alias and one index has to be allowed. " + s"Found allowed indices: [${blockContext.indices.show}]." + s"Found allowed aliases: [${blockContext.aliases.show}]") ShouldBeInterrupted @@ -114,7 +114,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, .indices().asSafeSet .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } @@ -122,7 +122,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, val aliases = rawRequestAliasesSet(request) .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered aliases: ${aliases.show}") + logger.debug(s"Discovered aliases: ${aliases.show}") aliases } diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala index abb85d42b7..f9e2c87e53 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala @@ -55,7 +55,7 @@ class IndicesAliasesEsRequestContext(actionRequest: IndicesAliasesRequest, if (originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala index 584c97e9f5..834bff8e8e 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala @@ -120,7 +120,7 @@ class MultiGetEsRequestContext(actionRequest: MultiGetRequest, case Nil => updateItemWithNonExistingIndex(item) case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } item.index(index.stringify) } diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala index 989956d79a..9e13edee8d 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala @@ -78,7 +78,7 @@ class MultiSearchEsRequestContext(actionRequest: MultiSearchRequest, } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala index 9191e33b66..5a61356f48 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala @@ -47,7 +47,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { request.getRequests.removeIf { request => removeOrAlter(request, filteredIndices.toCovariantSet) } if (request.getRequests.asScala.isEmpty) { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") ShouldBeInterrupted } else { Modified @@ -63,7 +63,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, true case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") } request.index(index.stringify) false diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala index c411df93c5..c7b99f6e85 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala @@ -52,7 +52,7 @@ class PutRollupJobEsRequestContext private(actionRequest: ActionRequest, if(originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala index ba5b52b4f1..f80e716349 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler.request.context.types import cats.data.NonEmptyList import cats.implicits.* import com.google.common.collect.Sets -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionRequest import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.AccessControlStaticContext @@ -51,7 +51,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (tryUpdate(actionRequest, filteredIndices)) Modified else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") ShouldBeInterrupted } } @@ -66,7 +66,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques } } -object ReflectionBasedIndicesEsRequestContext extends Logging { +object ReflectionBasedIndicesEsRequestContext extends RequestIdAwareLogging { def unapply(arg: ReflectionBasedActionRequest): Option[ReflectionBasedIndicesEsRequestContext] = { requestedIndicesFrom(arg.esContext.actionRequest) diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala index 489d0187bc..c42dfc3b78 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala @@ -58,10 +58,10 @@ class ReindexEsRequestContext(actionRequest: ReindexRequest, Modified } else { if (!isDestinationIndexOnFilteredIndicesList) { - logger.info(s"[${id.show}] Destination index of _reindex request is forbidden") + logger.info(s"Destination index of _reindex request is forbidden") } if (!isSearchRequestComposedOnlyOfAllowedIndices) { - logger.info(s"[${id.show}] At least one index from sources indices list of _reindex request is forbidden") + logger.info(s"At least one index from sources indices list of _reindex request is forbidden") } ShouldBeInterrupted } diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala index 2c1b0014e0..97b8ccd9c5 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala @@ -74,7 +74,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo request } case Left(_) => - logger.debug(s"[${id.show}] Cannot parse SQL statement - we can pass it though, because ES is going to reject it") + logger.debug(s"Cannot parse SQL statement - we can pass it though, because ES is going to reject it") request } } @@ -85,7 +85,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala index 0c67384c1e..d7e743e648 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CleanupRepositoryEsRequestContext(actionRequest: CleanupRepositoryRequest, override protected def update(request: CleanupRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala index 44b7d78dfd..d09015139b 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CreateRepositoryEsRequestContext(actionRequest: PutRepositoryRequest, override protected def update(request: PutRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala index eaf9334872..0cf32e1bea 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class DeleteRepositoryEsRequestContext(actionRequest: DeleteRepositoryRequest, override protected def update(request: DeleteRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala index cee0bffd4c..d1410eff3d 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class VerifyRepositoryEsRequestContext(actionRequest: VerifyRepositoryRequest, override protected def update(request: VerifyRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala index ead4fcf250..20501516d5 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala @@ -68,32 +68,32 @@ class CreateSnapshotEsRequestContext(actionRequest: CreateSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala index a56aba660e..621d744767 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala @@ -60,7 +60,7 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -71,14 +71,14 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, .toRight(()) } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala index 22869bbb4f..b81f333174 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala @@ -68,7 +68,7 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, case r => r } case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala index 88887db96c..156deb5b80 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala @@ -63,7 +63,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -75,7 +75,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") } Right(snapshot) } @@ -88,7 +88,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala index 44ee8397ec..e522e440f1 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala @@ -100,12 +100,12 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { val repositories = blockContext.repositories if (allRepositoriesRequested(repositories)) { Right(RepositoryName.All) @@ -115,7 +115,7 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala index 9b58e1b7b5..0a42f8dc82 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.rollover.RolloverConfiguration import org.elasticsearch.action.admin.indices.template.get.GetComposableIndexTemplateAction import org.elasticsearch.cluster.metadata @@ -111,7 +111,7 @@ class GetComposableIndexTemplateEsRequestContext(actionRequest: GetComposableInd } -private[templates] object GetComposableIndexTemplateEsRequestContext extends Logging { +private[templates] object GetComposableIndexTemplateEsRequestContext extends RequestIdAwareLogging { def filter(templates: Map[String, ComposableIndexTemplate], usingTemplate: Set[Template] => Set[Template]) diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala index bd74c3a18f..1c6eecf409 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.{GetIndexTemplatesRequest, GetIndexTemplatesResponse} import org.elasticsearch.cluster.metadata.{AliasMetadata, IndexTemplateMetadata} import org.elasticsearch.common.collect.ImmutableOpenMap @@ -104,7 +104,7 @@ class GetTemplatesEsRequestContext(actionRequest: GetIndexTemplatesRequest, } -private[templates] object GetTemplatesEsRequestContext extends Logging { +private[templates] object GetTemplatesEsRequestContext extends RequestIdAwareLogging { def filter(templates: Iterable[IndexTemplateMetadata], usingTemplate: Set[Template] => Set[Template]) diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala index a8951de5b1..32116d8212 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala @@ -72,7 +72,7 @@ class MultiSearchTemplateEsRequestContext private(actionRequest: ActionRequest w } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala index e6f6d8916e..434787a686 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala @@ -55,7 +55,7 @@ class SimulateIndexTemplateRequestEsRequestContext(actionRequest: SimulateIndexT filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateRequest(request, filteredIndices.head, allAllowedIndices) } diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala index fbc4cf6776..46ed6e7a95 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala @@ -109,7 +109,7 @@ class SimulateExistingTemplateRequestEsRequestContext(existingTemplateName: Temp case Some(_) => updateResponse(namePatterns.toList, blockContext.allAllowedIndices.toList) case None => - logger.info(s"[${id.show}] User has no access to template ${existingTemplateName.show}") + logger.info(s"User has no access to template ${existingTemplateName.show}") ModificationResult.ShouldBeInterrupted } case other => diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala index 0ecd7a72b3..fe4d60bd42 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.queries import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.index.query.* import org.joor.Reflect.on import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.RequestFieldsUsage @@ -30,7 +30,7 @@ trait QueryFieldsUsage[QUERY <: QueryBuilder] { def fieldsIn(query: QUERY): RequestFieldsUsage } -object QueryFieldsUsage extends Logging { +object QueryFieldsUsage extends RequestIdAwareLogging { def apply[QUERY <: QueryBuilder](implicit ev: QueryFieldsUsage[QUERY]): QueryFieldsUsage[QUERY] = ev implicit class Ops[QUERY <: QueryBuilder : QueryFieldsUsage](val query: QUERY) { @@ -62,7 +62,7 @@ object QueryFieldsUsage extends Logging { Option(on(query).call("getFieldName").get[String]) match { case Some(fieldName: String) => UsingFields(NonEmptyList.one(UsedField(fieldName))) case _ => - logger.debug(s"Cannot extract fields for terms set query") + noRequestIdLogger.debug(s"Cannot extract fields for terms set query") CannotExtractFields } } @@ -89,7 +89,7 @@ object QueryFieldsUsage extends Logging { case builder: TermsSetQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder: WildcardQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder => - logger.debug(s"Cannot extract fields for query: ${builder.getName}") + noRequestIdLogger.debug(s"Cannot extract fields for query: ${builder.getName}") CannotExtractFields } diff --git a/es818x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala b/es818x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala index 0998bb9a5b..b4671e9e4d 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.handler.response import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.FieldsRestrictions import tech.beshu.ror.accesscontrol.domain.Header @@ -26,17 +26,17 @@ import tech.beshu.ror.accesscontrol.headerValues.transientFieldsToHeaderValue import tech.beshu.ror.accesscontrol.request.RequestContext import tech.beshu.ror.implicits.* -object FLSContextHeaderHandler extends Logging { +object FLSContextHeaderHandler extends RequestIdAwareLogging { def addContextHeader(threadPool: ThreadPool, - fieldsRestrictions: FieldsRestrictions, - requestId: RequestContext.Id): Unit = { + fieldsRestrictions: FieldsRestrictions) + (implicit requestId: RequestContext.Id): Unit = { val threadContext = threadPool.getThreadContext val header = createContextHeader(fieldsRestrictions) Option(threadContext.getHeader(header.name.value.value)) match { case None => implicit val show = headerShow - logger.debug(s"[${requestId.show}] Adding thread context header required by lucene. Header: '${header.show}'") + logger.debug(s"Adding thread context header required by lucene. Header: '${header.show}'") threadContext.putHeader(header.name.value.value, header.value.value) case Some(_) => } diff --git a/es818x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala b/es818x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala index f4078d757d..8a7fb3e997 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.admin.indices.template.get.{GetComponentTemplateAction, GetComposableIndexTemplateAction} import org.elasticsearch.action.admin.indices.template.put.{PutComponentTemplateAction, TransportPutComposableIndexTemplateAction} @@ -47,7 +47,7 @@ import scala.jdk.CollectionConverters.* final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJsonParserFactory)(using Clock) extends DataStreamService - with Logging { + with RequestIdAwareLogging { private val masterNodeTimeout: TimeValue = TimeValue(30000) private val ackTimeout: TimeValue = TimeValue(30000) @@ -205,11 +205,11 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ response <- Task.measure( task = Task.delay(nodeClient.execute(action, request).actionGet()), logTimeMeasurement = duration => Task.delay { - logger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") + noRequestIdLogger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") } ) _ <- Task.delay { - logger.debug(s"Action ${action.name()} response: ${response.toString}") + noRequestIdLogger.debug(s"Action ${action.name()} response: ${response.toString}") } } yield response } @@ -217,7 +217,7 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ def executeAck[REQUEST <: ActionRequest, RESPONSE <: AcknowledgedResponse](action: ActionType[RESPONSE], request: REQUEST): Task[RESPONSE] = { executeT(action, request) - .tapEval(response => Task.delay(logger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) + .tapEval(response => Task.delay(noRequestIdLogger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) } private def supportedActions: Map[ActionType[ActionResponse], TransportAction[ActionRequest, ActionResponse]] = { diff --git a/es818x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala b/es818x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala index 40ae6d97e0..f24d74c52d 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.support.WriteRequest.RefreshPolicy import org.elasticsearch.client.internal.node.NodeClient @@ -37,7 +37,7 @@ import scala.jdk.CollectionConverters.* class EsIndexJsonContentService(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexJsonContentService - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -62,14 +62,14 @@ class EsIndexJsonContentService(client: NodeClient, Option(response.getSourceAsMap) match { case Some(map) => val source = map.asScala.toMap.asStringMap - logger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") Right(source) case None => - logger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") + noRequestIdLogger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") Right(Map.empty[String, String]) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(ContentNotFound) } } @@ -77,7 +77,7 @@ class EsIndexJsonContentService(client: NodeClient, .onErrorRecover { case _: ResourceNotFoundException => Left(ContentNotFound) case ex => - logger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) Left(CannotReachContentSource) } } @@ -103,14 +103,14 @@ class EsIndexJsonContentService(client: NodeClient, case status if status / 100 == 2 => Right(()) case status => - logger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") Left(CannotWriteToIndex) } } .executeOn(RorSchedulers.blockingScheduler) .onErrorRecover { case ex => - logger.error(s"Cannot write to document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]", ex) Left(CannotWriteToIndex) } } diff --git a/es818x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala b/es818x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala index 2a2669e8b4..619cb6daf2 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala @@ -22,7 +22,7 @@ import cats.kernel.Monoid import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task import monix.execution.{CancelablePromise, Scheduler} -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction.{ResolvedAlias, ResolvedIndex} @@ -65,7 +65,7 @@ class EsServerBasedRorClusterService(nodeName: String, threadPool: ThreadPool) (implicit val scheduler: Scheduler) extends RorClusterService - with Logging { + with RequestIdAwareLogging { import EsServerBasedRorClusterService.* @@ -156,7 +156,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractAccessibilityFrom) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify get request. Blocking document", ex) + logger.error(s"Could not verify get request. Blocking document", ex)(id) Inaccessible } } @@ -168,7 +168,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractResultsFromSearchResponse) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify documents returned by multi get response. Blocking all returned documents", ex) + logger.error(s"Could not verify documents returned by multi get response. Blocking all returned documents", ex)(id) blockAllDocsReturned(documents) } .map(results => zip(results, documents)) @@ -277,7 +277,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService): Task[List[FullRemoteDataStreamWithAliases]] = { getRemoteClusterClient(remoteClusterService, remoteClusterName) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -333,7 +333,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService) = { getRemoteClusterClient(remoteClusterService, remoteClusterName) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -423,7 +423,7 @@ class EsServerBasedRorClusterService(nodeName: String, } } case None => - logger.error("Cannot supply Snapshots Service. Please, report the issue!!!") + noRequestIdLogger.error("Cannot supply Snapshots Service. Please, report the issue!!!") Task.now(Set.empty[Snapshot]) } } diff --git a/es818x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala b/es818x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala index a657d15ca9..31d96f15a2 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.services import cats.data.NonEmptyList -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.bulk.{BackoffPolicy, BulkProcessor, BulkRequest, BulkResponse} import org.elasticsearch.action.index.IndexRequest import org.elasticsearch.action.{ActionListener, DocWriteRequest} @@ -39,7 +39,7 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, (using Clock) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { private val bulkProcessor = BulkProcessor @@ -80,25 +80,25 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, private class AuditSinkBulkProcessorListener extends BulkProcessor.Listener { override def beforeBulk(executionId: Long, request: BulkRequest): Unit = { - logger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") + noRequestIdLogger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") } override def afterBulk(executionId: Long, request: BulkRequest, response: BulkResponse): Unit = { if (response.hasFailures) { - logger.error("Some failures flushing the BulkProcessor: ") + noRequestIdLogger.error("Some failures flushing the BulkProcessor: ") response .getItems.to(LazyList) .filter(_.isFailed) .map(_.getFailureMessage) .groupBy(identity) .foreach { case (message, stream) => - logger.error(s"${stream.size}x: $message") + noRequestIdLogger.error(s"${stream.size}x: $message") } } } override def afterBulk(executionId: Long, request: BulkRequest, failure: Throwable): Unit = { - logger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) + noRequestIdLogger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) } } diff --git a/es818x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala b/es818x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala index a8def0ec7a..b3c5593c36 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala @@ -22,7 +22,7 @@ import org.apache.http.auth.{AuthScope, Credentials, UsernamePasswordCredentials import org.apache.http.conn.ssl.NoopHostnameVerifier import org.apache.http.impl.client.BasicCredentialsProvider import org.apache.http.impl.nio.client.HttpAsyncClientBuilder -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.* import org.elasticsearch.client.RestClient.FailureListener import tech.beshu.ror.accesscontrol.audit.sink.AuditDataStreamCreator @@ -38,7 +38,7 @@ import scala.collection.parallel.CollectionConverters.* final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient]) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { override def submit(indexName: IndexName.Full, documentId: String, jsonRecord: String) (implicit requestId: RequestId): Unit = { @@ -77,21 +77,21 @@ final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient] override def onSuccess(response: Response): Unit = { response.getStatusLine.getStatusCode / 100 match { case 2 => // 2xx - logger.debug(s"[${requestId.show}] Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") + logger.debug(s"Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") case _ => - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") } } override def onFailure(ex: Exception): Unit = { - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId]", ex) + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId]", ex) } } override val dataStreamCreator: AuditDataStreamCreator = new AuditDataStreamCreator(clients.map(new RestClientDataStreamService(_))) } -object RestClientAuditSinkService extends Logging { +object RestClientAuditSinkService extends RequestIdAwareLogging { def create(remoteCluster: AuditCluster.RemoteAuditCluster): RestClientAuditSinkService = { remoteCluster.mode match { @@ -122,7 +122,7 @@ object RestClientAuditSinkService extends Logging { .setFailureListener( new FailureListener { override def onFailure(node: Node): Unit = { - logger.debug( + noRequestIdLogger.debug( s"[AUDIT] Node marked dead: ${node.getHost.getSchemeName}://${node.getHost.getHostName}:${node.getHost.getPort}. The client will attempt failover.", ) } diff --git a/es818x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala b/es818x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala index 1f00261ee4..6344d8c3ae 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.Channel import io.netty.handler.ssl.NotSslRecordException -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.bulk.IncrementalBulkService.Enabled import org.elasticsearch.common.network.NetworkService import org.elasticsearch.common.settings.{ClusterSettings, Settings} @@ -42,7 +42,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, tracer: Tracer, fipsCompliant: Boolean) extends Netty4HttpServerTransport(settings, networkService, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory, tracer, TLSConfig.noTLS(), null, null) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, ssl.clientAuthenticationEnabled) @@ -50,7 +50,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, override def onException(channel: HttpChannel, cause: Exception): Unit = { if (!this.lifecycle.started) return - else if (cause.getCause.isInstanceOf[NotSslRecordException]) logger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) + else if (cause.getCause.isInstanceOf[NotSslRecordException]) noRequestIdLogger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) else super.onException(channel, cause) channel.close() } diff --git a/es818x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala b/es818x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala index 2fa1d7871c..2d2b0360d4 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.* import io.netty.handler.ssl.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.TransportVersion import org.elasticsearch.cluster.node.DiscoveryNode import org.elasticsearch.common.io.stream.NamedWriteableRegistry @@ -46,7 +46,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, sharedGroupFactory: SharedGroupFactory, fipsCompliant: Boolean) extends Netty4Transport(settings, TransportVersion.current(), threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = SSLCertHelper.prepareClientSSLContext(ssl, fipsCompliant, ssl.certificateVerificationEnabled) private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, clientAuthenticationEnabled = false) @@ -78,7 +78,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, override def exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable): Unit = { if (cause.isInstanceOf[NotSslRecordException] || (cause.getCause != null && cause.getCause.isInstanceOf[NotSslRecordException])) { - logger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") + noRequestIdLogger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") ctx.channel.close } else { super.exceptionCaught(ctx, cause) diff --git a/es818x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala b/es818x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala index 1515ff0cac..5b6c9c104f 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.utils import cats.Show import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.client.internal.node.NodeClient import org.elasticsearch.rest.* @@ -37,7 +37,7 @@ import java.util import scala.util.Try class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandler) - extends RestHandler with Logging { + extends RestHandler with RequestIdAwareLogging { private val wrapped = doPrivileged { wrapSomeActions(underlying) @@ -99,11 +99,11 @@ class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandle private def logError(error: AuthorizationValueError): Unit = { { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorSanitizedShow - logger.warn(s"The incoming request was malformed. Cause: ${error.show}") + noRequestIdLogger.warn(s"The incoming request was malformed. Cause: ${error.show}") } if (logger.delegate.isDebugEnabled()) { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorWithDetailsShow - logger.debug(s"Malformed request detailed cause: ${error.show}") + noRequestIdLogger.debug(s"Malformed request detailed cause: ${error.show}") } } diff --git a/es818x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala b/es818x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala index 5ab1e35742..a9af8f710a 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala @@ -16,13 +16,13 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.settings.Settings import tech.beshu.ror.tools.core.patches.PatchingVerifier import tech.beshu.ror.tools.core.patches.PatchingVerifier.Error.{CannotVerifyIfPatched, EsNotPatched} import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -object EsPatchVerifier extends Logging { +object EsPatchVerifier extends RequestIdAwareLogging { def verify(settings: Settings): Unit = doPrivileged { pathHomeFrom(settings).flatMap(PatchingVerifier.verify) match { @@ -30,7 +30,7 @@ object EsPatchVerifier extends Logging { case Left(e@EsNotPatched(_)) => throw new IllegalStateException(e.message) case Left(e@CannotVerifyIfPatched(_)) => - logger.warn(e.message) + noRequestIdLogger.warn(e.message) } } diff --git a/es818x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala b/es818x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala index b73104a175..c292a44ed2 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.internal.node.NodeClient import org.elasticsearch.transport.RemoteClusterService import org.joor.Reflect.on @@ -26,14 +26,14 @@ import java.util.function.Supplier import scala.util.{Failure, Success, Try} class RemoteClusterServiceSupplier(nodeClient: NodeClient) - extends Supplier[Option[RemoteClusterService]] with Logging { + extends Supplier[Option[RemoteClusterService]] with RequestIdAwareLogging { override def get(): Option[RemoteClusterService] = { extractRemoteClusterService() match { case Success(remoteClusterService) => remoteClusterService case Failure(ex) => - logger.error("Cannot extract RemoteClusterService from NodeClient", ex) + noRequestIdLogger.error("Cannot extract RemoteClusterService from NodeClient", ex) None } } diff --git a/es81x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es81x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index 1916982621..36ea4c1800 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.support.{ActionFilter, ActionFilterChain} import org.elasticsearch.action.{ActionListener, ActionRequest, ActionResponse} import org.elasticsearch.client.internal.node.NodeClient @@ -62,7 +62,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, rorEsConfig: ReadonlyRestEsConfig) (implicit environmentConfig: EnvironmentConfig) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = environmentConfig.uniqueIdentifierGenerator @@ -212,12 +212,12 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def handleRorNotReadyYet(esContext: EsContext): Unit = { - logger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") + noRequestIdLogger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") rorNotAvailableRequestHandler.handleRorNotReadyYet(esContext) } private def handleRorFailedToStart(esContext: EsContext): Unit = { - logger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") + noRequestIdLogger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") rorNotAvailableRequestHandler.handleRorFailedToStart(esContext) } @@ -239,7 +239,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def logAndSetStartingFailureState(failure: StartingFailure): Unit = { - logger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) + noRequestIdLogger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) rorInstanceState.set(RorInstanceStartingState.NotStarted(failure)) } } diff --git a/es81x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala b/es81x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala index 9feda808c8..ca9ab4aa2d 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.xcontent.LoggingDeprecationHandler import org.elasticsearch.rest.{BytesRestResponse, RestResponse} import org.elasticsearch.xcontent.{NamedXContentRegistry, XContentBuilder, XContentParserConfiguration, XContentType} @@ -30,7 +30,7 @@ import tech.beshu.ror.accesscontrol.domain.ResponseFieldsFiltering.{AccessMode, import scala.jdk.CollectionConverters.* trait ResponseFieldsFiltering { - this: Logging => + this: RequestIdAwareLogging => private val responseFieldsRestrictions: Atomic[Option[ResponseFieldsRestrictions]] = Atomic(None: Option[ResponseFieldsRestrictions]) @@ -45,7 +45,7 @@ trait ResponseFieldsFiltering { case bytesRestResponse: BytesRestResponse => filterBytesRestResponse(bytesRestResponse, fieldsRestrictions) case otherResponse => - logger.warn("ResponseFields filtering is unavailable for this type of request") + noRequestIdLogger.warn("ResponseFields filtering is unavailable for this type of request") otherResponse } case None => diff --git a/es81x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala b/es81x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala index 0f26750588..da95de59a4 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.action.{ActionListener, ActionResponse} import org.elasticsearch.threadpool.ThreadPool @@ -37,7 +37,7 @@ sealed abstract class RorActionListener[T](val underlying: ActionListener[T]) ex final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionListener[T], correlationId: Eval[CorrelationId]) - extends RorActionListener[T](underlying) with Logging { + extends RorActionListener[T](underlying) with RequestIdAwareLogging { override def onFailure(e: Exception): Unit = { super.onFailure(adaptExceptionIfNeeded(e)) @@ -47,7 +47,7 @@ final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionLis ex match { case esException: ElasticsearchException => esException case other => - logger.error(s"[${correlationId.value.show}] Internal error.", other) + noRequestIdLogger.error(s"[${correlationId.value.show}] Internal error.", other) new ElasticsearchException(s"[${correlationId.value.show}] Internal error. See logs for details.") } } diff --git a/es81x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala b/es81x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala index 75048ebe7d..14e5e31c1b 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.http.HttpChannel import org.elasticsearch.rest.{AbstractRestChannel, RestChannel as EsRestChannel, RestRequest as EsRestRequest, RestResponse as EsRestResponse} import squants.information.{Bytes, Information} @@ -40,7 +40,7 @@ object RorRestChannel { final class RorRestChannel private(underlying: EsRestChannel, val restRequest: RorRestRequest) extends AbstractRestChannel(underlying.request(), true) with ResponseFieldsFiltering - with Logging { + with RequestIdAwareLogging { override def sendResponse(response: EsRestResponse): Unit = { ThreadRepo.removeRestChannel(this) diff --git a/es81x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala b/es81x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala index 6babc712b9..3c80750a25 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala @@ -18,16 +18,15 @@ package tech.beshu.ror.es.actions.rradmin import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.ConfigApi.ConfigResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAdminActionHandler extends Logging { +class RRAdminActionHandler extends RequestIdAwareLogging { private implicit val adminRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +51,7 @@ class RRAdminActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAdminResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAdminAction internal error", ex) + logger.error("RRAdminAction internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es81x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala b/es81x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala index c55835a1d0..ce45c6f48e 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala @@ -16,18 +16,15 @@ */ package tech.beshu.ror.es.actions.rrauthmock -import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.AuthMockApi.AuthMockResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier -import tech.beshu.ror.implicits.* +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAuthMockActionHandler extends Logging { +class RRAuthMockActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -53,7 +50,7 @@ class RRAuthMockActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAuthMockResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAuthMock internal error", ex) + logger.error("RRAuthMock internal error", ex) listener.onFailure(new Exception(ex)) } } diff --git a/es81x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala b/es81x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala index aa8bb31e67..640084c4ec 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestconfig import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.TestConfigApi.TestConfigResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestConfigActionHandler extends Logging { +class RRTestConfigActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +52,7 @@ class RRTestConfigActionHandler extends Logging { case Right(response) => listener.onResponse(new RRTestConfigResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRTestConfig internal error", ex) + logger.error(s"RRTestConfig internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es81x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala b/es81x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala index 494e9150b4..98cc0c945d 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.dlsfls import cats.data.StateT import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.DirectoryReader import org.elasticsearch.common.util.concurrent.ThreadContext import org.elasticsearch.core.CheckedFunction @@ -31,7 +31,7 @@ import java.io.IOException import java.util.function.{Function => JavaFunction} import scala.util.{Failure, Success, Try} -object RoleIndexSearcherWrapper extends Logging { +object RoleIndexSearcherWrapper extends RequestIdAwareLogging { val instance: JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] = new JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] { @@ -54,7 +54,7 @@ object RoleIndexSearcherWrapper extends Logging { } .map(r => (r, r)) case None => - logger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") + noRequestIdLogger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") Success((reader, reader)) } } @@ -66,13 +66,13 @@ object RoleIndexSearcherWrapper extends Logging { nel <- NonEmptyString.from(value) match { case Right(nel) => Success(nel) case Left(_) => - logger.debug("FLS: empty header value") + noRequestIdLogger.debug("FLS: empty header value") failure } fields <- transientFieldsFromHeaderValue.fromRawValue(nel) match { case result@Success(_) => result case Failure(ex) => - logger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) + noRequestIdLogger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) failure } } yield fields diff --git a/es81x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala b/es81x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala index ac897184bb..0f785d38fd 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.dlsfls import com.google.common.collect.Iterators -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.codecs.StoredFieldsReader import org.apache.lucene.index.* import org.apache.lucene.index.StoredFieldVisitor.Status @@ -39,21 +39,21 @@ import scala.jdk.CollectionConverters.* import scala.util.Try private class RorDocumentFieldReader(reader: LeafReader, fieldsRestrictions: FieldsRestrictions) - extends SequentialStoredFieldsLeafReader(reader) with Logging { + extends SequentialStoredFieldsLeafReader(reader) with RequestIdAwareLogging { private val policy = new FieldsPolicy(fieldsRestrictions) private val remainingFieldsInfo = { val fInfos = in.getFieldInfos val newInfos = if (fInfos.asScala.isEmpty) { - logger.warn("original fields were empty! This is weird!") + noRequestIdLogger.warn("original fields were empty! This is weird!") fInfos } else { val remainingFields = fInfos.asScala.filter(f => policy.canKeep(f.name)).toSet new FieldInfos(remainingFields.toArray) } - logger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") - logger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") - logger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") + noRequestIdLogger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") newInfos } private val jsonPolicyBasedFilterer = new JsonPolicyBasedFilterer(policy) diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala index 15add4a6dd..a4d939d26a 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.* import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest import org.elasticsearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest @@ -87,7 +87,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, threadPool: ThreadPool) (implicit generator: UniqueIdentifierGenerator, scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle(engines: Engines, esContext: EsContext): Task[Either[Error, Unit]] = { @@ -242,7 +242,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, case SearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case MultiSearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case _ => - logger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") + noRequestIdLogger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") regularRequestHandler.handle(new DummyCompositeIndicesEsRequestContext(request, esContext, aclContext, clusterService, threadPool)) } // rest diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala index cab02aff37..100edd72ac 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.common.io.stream.StreamOutput import org.elasticsearch.xcontent.{ToXContent, ToXContentObject, XContentBuilder} @@ -45,7 +45,7 @@ import scala.util.{Failure, Success, Try} class CurrentUserMetadataRequestHandler(engine: Engine, esContext: EsContext) - extends Logging { + extends RequestIdAwareLogging { def handle(request: RequestContext.Aux[CurrentUserMetadataRequestBlockContext] with EsRequest[CurrentUserMetadataRequestBlockContext]): Task[Unit] = { engine.core.accessControl @@ -69,7 +69,7 @@ class CurrentUserMetadataRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(ex.asInstanceOf[Exception]) } } @@ -86,13 +86,13 @@ class CurrentUserMetadataRequestHandler(engine: Engine, )) } - private def onPassThrough(requestContext: RequestContext): Unit = { - logger.warn(s"[${requestContext.id.toRequestId.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") + private def onPassThrough(implicit requestContext: RequestContext): Unit = { + logger.warn(s"Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") esContext.listener.onFailure(createRorNotEnabledResponse()) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala index 2fb01dcc41..c5c44fda92 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala @@ -20,7 +20,7 @@ import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.RegularRequestResult @@ -49,7 +49,7 @@ class RegularRequestHandler(engine: Engine, esContext: EsContext, threadPool: ThreadPool) (implicit scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle[B <: BlockContext : BlockContextUpdater](request: RequestContext.Aux[B] with EsRequest[B]): Task[Unit] = { engine.core.accessControl @@ -85,7 +85,7 @@ class RegularRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(new Exception(ex)) } } @@ -99,7 +99,7 @@ class RegularRequestHandler(engine: Engine, case ModificationResult.ShouldBeInterrupted => onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case ModificationResult.CannotModify => - logger.error(s"[${request.id.toRequestId.show}] Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") + noRequestIdLogger.error(s"Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case CustomResponse(response) => respond(request, response) @@ -247,7 +247,7 @@ class RegularRequestHandler(engine: Engine, esContext.listener.onResponse(response) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } \ No newline at end of file diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala index f4f832dedc..bfc421bdd5 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.index.query.{AbstractQueryBuilder, QueryBuilder, QueryBuilders} import org.elasticsearch.search.aggregations.AggregatorFactories @@ -40,7 +40,7 @@ import tech.beshu.ror.implicits.* import java.util.UUID import scala.jdk.CollectionConverters.* -object SearchRequestOps extends Logging { +object SearchRequestOps extends RequestIdAwareLogging { implicit class QueryBuilderOps(val builder: Option[QueryBuilder]) extends AnyVal { @@ -52,7 +52,7 @@ object SearchRequestOps extends Logging { val modifiedQuery: AbstractQueryBuilder[_] = provideNewQueryWithAppliedFilter(builder, filterQuery) Some(modifiedQuery) case None => - logger.debug(s"[${requestId.show}] No filter applied to query.") + logger.debug(s"No filter applied to query.") builder } } @@ -92,7 +92,7 @@ object SearchRequestOps extends Logging { case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, requestId) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) disableCaching(requestId) case BasedOnBlockContextOnly.NotAllowedFieldsUsed(notAllowedFields) => modifyNotAllowedFieldsInRequest(notAllowedFields) @@ -138,8 +138,8 @@ object SearchRequestOps extends Logging { } } - private def disableCaching(requestId: RequestContext.Id) = { - logger.debug(s"[${requestId.show}] ACL uses context header for fields rule, will disable request cache for SearchRequest") + private def disableCaching(implicit requestId: RequestContext.Id) = { + logger.debug(s"ACL uses context header for fields rule, will disable request cache for SearchRequest") request.requestCache(false) } } diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala index 270367a54f..e2884598df 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala @@ -17,7 +17,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.action.support.IndicesOptions.WildcardStates import org.elasticsearch.action.{CompositeIndicesRequest, IndicesRequest} @@ -34,7 +33,7 @@ import scala.jdk.CollectionConverters.* abstract class BaseEsRequestContext[B <: BlockContext](esContext: EsContext, clusterService: RorClusterService) - extends RequestContext with Logging { + extends RequestContext { override type BLOCK_CONTEXT = B diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala index ae8abbe1f5..0ee2967364 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala @@ -18,7 +18,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -26,8 +25,9 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import scala.util.Try +import tech.beshu.ror.utils.RequestIdAwareLogging -trait EsRequest[B <: BlockContext] extends Logging { +trait EsRequest[B <: BlockContext] extends RequestIdAwareLogging { implicit def threadPool: ThreadPool final def modifyUsing(blockContext: B): ModificationResult = { @@ -35,7 +35,7 @@ trait EsRequest[B <: BlockContext] extends Logging { Try(modifyRequest(blockContext)) .fold( ex => { - logger.error(s"[${blockContext.requestContext.id.show}] Cannot modify request with filtered data", ex) + logger.error(s"Cannot modify request with filtered data", ex)(blockContext) ModificationResult.CannotModify }, identity diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala index c6a9dcbefd..f773b3efb1 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala @@ -51,7 +51,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest private def discoverDataStreams() = { val dataStreams = dataStreamsFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered data streams: ${dataStreams.show}") + logger.debug(s"Discovered data streams: ${dataStreams.show}") dataStreams } @@ -59,7 +59,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest val backingIndices = backingIndicesFrom(actionRequest) backingIndices match { case BackingIndices.IndicesInvolved(filteredIndices, _) => - logger.debug(s"[${id.show}] Discovered indices: ${filteredIndices.show}") + logger.debug(s"Discovered indices: ${filteredIndices.show}") case BackingIndices.IndicesNotInvolved => } backingIndices diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala index c091179cb6..d150709314 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala @@ -85,7 +85,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: case Some(indices) => update(actionRequest, indices, blockContext.filter, blockContext.fieldLevelSecurity) case None => - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -101,7 +101,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } \ No newline at end of file diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala index 71d462de57..48014e1bdc 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala @@ -73,7 +73,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, } yield update(actionRequest, filteredIndices, allAllowedIndices) result.getOrElse { - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -86,7 +86,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala index 95d882c3b5..f607c0e347 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala @@ -50,7 +50,7 @@ abstract class BaseRepositoriesEsRequestContext[R <: ActionRequest](actionReques case Some(repositories) => update(actionRequest, repositories) case None => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") ShouldBeInterrupted } } diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala index b3b1d66238..7ef0f32014 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala @@ -42,7 +42,7 @@ abstract class BaseSingleIndexEsRequestContext[R <: ActionRequest](actionRequest filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } update(request, filteredIndices.head) } diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala index b5ab70fe7a..c1b2e7ea27 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala @@ -62,7 +62,7 @@ class BulkEsRequestContext(actionRequest: BulkRequest, case (_, _) => ShouldBeInterrupted } } else { - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because origin request contained different " + + logger.error(s"Cannot alter MultiGetRequest request, because origin request contained different " + s"number of requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } @@ -90,18 +90,18 @@ class BulkEsRequestContext(actionRequest: BulkRequest, updateRequestWithIndices(request, nel) Modified case None => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because empty list of indices was found") + logger.error(s"Cannot alter MultiGetRequest request, because empty list of indices was found") ShouldBeInterrupted } case Indices.NotFound => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because no allowed indices were found") + logger.error(s"Cannot alter MultiGetRequest request, because no allowed indices were found") ShouldBeInterrupted } } private def updateRequestWithIndices(request: DocWriteRequest[_], indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } request.index(indices.head.stringify) } diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala index 75a75fcef5..96a043b298 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala @@ -53,14 +53,14 @@ class BulkShardEsRequestContext(actionRequest: BulkShardRequest, case Success(_) => Modified case Failure(ex) => - logger.error(s"[${id.show}] Cannot modify BulkShardRequest", ex) + logger.error(s"Cannot modify BulkShardRequest", ex) CannotModify } } private def tryUpdate(request: BulkShardRequest, indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } val singleIndex = indices.head val uuid = clusterService.indexOrAliasUuids(singleIndex.name).toList.head diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala index 65a168092a..158ac485a5 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala @@ -45,14 +45,14 @@ class ClusterAllocationExplainEsRequestContext(actionRequest: ClusterAllocationE getRequestedIndexFrom(request) match { case Some(_) => if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateIndexIn(request, filteredIndices.head) Modified case None if filteredIndices.exists(_.name === ClusterIndexName.Local.wildcard) => Modified case None => - logger.error(s"[${id.show}] Cluster allocation explain request without index name is unavailable when block contains `indices` rule") + logger.error(s"Cluster allocation explain request without index name is unavailable when block contains `indices` rule") ShouldBeInterrupted } } diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala index 8f97fb7619..3410f4fc6d 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala @@ -68,7 +68,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, updateAliases(actionRequest, aliases) UpdateResponse.sync(updateAliasesResponse(aliases.includedOnly, _)) case None => - logger.error(s"[${id.show}] At least one alias and one index has to be allowed. " + + logger.error(s"At least one alias and one index has to be allowed. " + s"Found allowed indices: [${blockContext.indices.show}]." + s"Found allowed aliases: [${blockContext.aliases.show}]") ShouldBeInterrupted @@ -116,7 +116,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, .indices().asSafeSet .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } @@ -124,7 +124,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, val aliases = rawRequestAliasesSet(request) .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered aliases: ${aliases.show}") + logger.debug(s"Discovered aliases: ${aliases.show}") aliases } diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala index abb85d42b7..f9e2c87e53 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala @@ -55,7 +55,7 @@ class IndicesAliasesEsRequestContext(actionRequest: IndicesAliasesRequest, if (originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala index 05b70606b9..37dd50452b 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala @@ -119,7 +119,7 @@ class MultiGetEsRequestContext(actionRequest: MultiGetRequest, case Nil => updateItemWithNonExistingIndex(item) case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } item.index(index.stringify) } diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala index 989956d79a..9e13edee8d 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala @@ -78,7 +78,7 @@ class MultiSearchEsRequestContext(actionRequest: MultiSearchRequest, } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala index 9191e33b66..5a61356f48 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala @@ -47,7 +47,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { request.getRequests.removeIf { request => removeOrAlter(request, filteredIndices.toCovariantSet) } if (request.getRequests.asScala.isEmpty) { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") ShouldBeInterrupted } else { Modified @@ -63,7 +63,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, true case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") } request.index(index.stringify) false diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala index c411df93c5..c7b99f6e85 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala @@ -52,7 +52,7 @@ class PutRollupJobEsRequestContext private(actionRequest: ActionRequest, if(originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala index 141d9db788..fff8ed58bb 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala @@ -49,7 +49,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (tryUpdate(actionRequest, filteredIndices)) Modified else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") ShouldBeInterrupted } } diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala index 489d0187bc..c42dfc3b78 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala @@ -58,10 +58,10 @@ class ReindexEsRequestContext(actionRequest: ReindexRequest, Modified } else { if (!isDestinationIndexOnFilteredIndicesList) { - logger.info(s"[${id.show}] Destination index of _reindex request is forbidden") + logger.info(s"Destination index of _reindex request is forbidden") } if (!isSearchRequestComposedOnlyOfAllowedIndices) { - logger.info(s"[${id.show}] At least one index from sources indices list of _reindex request is forbidden") + logger.info(s"At least one index from sources indices list of _reindex request is forbidden") } ShouldBeInterrupted } diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala index 2c1b0014e0..97b8ccd9c5 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala @@ -74,7 +74,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo request } case Left(_) => - logger.debug(s"[${id.show}] Cannot parse SQL statement - we can pass it though, because ES is going to reject it") + logger.debug(s"Cannot parse SQL statement - we can pass it though, because ES is going to reject it") request } } @@ -85,7 +85,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala index 0c67384c1e..d7e743e648 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CleanupRepositoryEsRequestContext(actionRequest: CleanupRepositoryRequest, override protected def update(request: CleanupRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala index 44b7d78dfd..d09015139b 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CreateRepositoryEsRequestContext(actionRequest: PutRepositoryRequest, override protected def update(request: PutRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala index eaf9334872..0cf32e1bea 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class DeleteRepositoryEsRequestContext(actionRequest: DeleteRepositoryRequest, override protected def update(request: DeleteRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala index cee0bffd4c..d1410eff3d 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class VerifyRepositoryEsRequestContext(actionRequest: VerifyRepositoryRequest, override protected def update(request: VerifyRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala index ead4fcf250..20501516d5 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala @@ -68,32 +68,32 @@ class CreateSnapshotEsRequestContext(actionRequest: CreateSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala index a56aba660e..621d744767 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala @@ -60,7 +60,7 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -71,14 +71,14 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, .toRight(()) } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala index 22869bbb4f..b81f333174 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala @@ -68,7 +68,7 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, case r => r } case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala index 88887db96c..156deb5b80 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala @@ -63,7 +63,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -75,7 +75,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") } Right(snapshot) } @@ -88,7 +88,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala index 44ee8397ec..e522e440f1 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala @@ -100,12 +100,12 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { val repositories = blockContext.repositories if (allRepositoriesRequested(repositories)) { Right(RepositoryName.All) @@ -115,7 +115,7 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala index 80e36a6d77..d8e5182eed 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.GetComposableIndexTemplateAction import org.elasticsearch.cluster.metadata import org.elasticsearch.cluster.metadata.ComposableIndexTemplate @@ -108,7 +108,7 @@ class GetComposableIndexTemplateEsRequestContext(actionRequest: GetComposableInd } -private[templates] object GetComposableIndexTemplateEsRequestContext extends Logging { +private[templates] object GetComposableIndexTemplateEsRequestContext extends RequestIdAwareLogging { def filter(templates: Map[String, ComposableIndexTemplate], usingTemplate: Set[Template] => Set[Template]) diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala index 3964bdd1cc..de573c648b 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.{GetIndexTemplatesRequest, GetIndexTemplatesResponse} import org.elasticsearch.cluster.metadata.{AliasMetadata, IndexTemplateMetadata} import org.elasticsearch.common.collect.ImmutableOpenMap @@ -105,7 +105,7 @@ class GetTemplatesEsRequestContext(actionRequest: GetIndexTemplatesRequest, } -private[templates] object GetTemplatesEsRequestContext extends Logging { +private[templates] object GetTemplatesEsRequestContext extends RequestIdAwareLogging { def filter(templates: Iterable[IndexTemplateMetadata], usingTemplate: Set[Template] => Set[Template]) diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala index a8951de5b1..32116d8212 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala @@ -72,7 +72,7 @@ class MultiSearchTemplateEsRequestContext private(actionRequest: ActionRequest w } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala index e6f6d8916e..434787a686 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala @@ -55,7 +55,7 @@ class SimulateIndexTemplateRequestEsRequestContext(actionRequest: SimulateIndexT filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateRequest(request, filteredIndices.head, allAllowedIndices) } diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala index fbc4cf6776..46ed6e7a95 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala @@ -109,7 +109,7 @@ class SimulateExistingTemplateRequestEsRequestContext(existingTemplateName: Temp case Some(_) => updateResponse(namePatterns.toList, blockContext.allAllowedIndices.toList) case None => - logger.info(s"[${id.show}] User has no access to template ${existingTemplateName.show}") + logger.info(s"User has no access to template ${existingTemplateName.show}") ModificationResult.ShouldBeInterrupted } case other => diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala index 0ecd7a72b3..fe4d60bd42 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.queries import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.index.query.* import org.joor.Reflect.on import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.RequestFieldsUsage @@ -30,7 +30,7 @@ trait QueryFieldsUsage[QUERY <: QueryBuilder] { def fieldsIn(query: QUERY): RequestFieldsUsage } -object QueryFieldsUsage extends Logging { +object QueryFieldsUsage extends RequestIdAwareLogging { def apply[QUERY <: QueryBuilder](implicit ev: QueryFieldsUsage[QUERY]): QueryFieldsUsage[QUERY] = ev implicit class Ops[QUERY <: QueryBuilder : QueryFieldsUsage](val query: QUERY) { @@ -62,7 +62,7 @@ object QueryFieldsUsage extends Logging { Option(on(query).call("getFieldName").get[String]) match { case Some(fieldName: String) => UsingFields(NonEmptyList.one(UsedField(fieldName))) case _ => - logger.debug(s"Cannot extract fields for terms set query") + noRequestIdLogger.debug(s"Cannot extract fields for terms set query") CannotExtractFields } } @@ -89,7 +89,7 @@ object QueryFieldsUsage extends Logging { case builder: TermsSetQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder: WildcardQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder => - logger.debug(s"Cannot extract fields for query: ${builder.getName}") + noRequestIdLogger.debug(s"Cannot extract fields for query: ${builder.getName}") CannotExtractFields } diff --git a/es81x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala b/es81x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala index 0998bb9a5b..b4671e9e4d 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.handler.response import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.FieldsRestrictions import tech.beshu.ror.accesscontrol.domain.Header @@ -26,17 +26,17 @@ import tech.beshu.ror.accesscontrol.headerValues.transientFieldsToHeaderValue import tech.beshu.ror.accesscontrol.request.RequestContext import tech.beshu.ror.implicits.* -object FLSContextHeaderHandler extends Logging { +object FLSContextHeaderHandler extends RequestIdAwareLogging { def addContextHeader(threadPool: ThreadPool, - fieldsRestrictions: FieldsRestrictions, - requestId: RequestContext.Id): Unit = { + fieldsRestrictions: FieldsRestrictions) + (implicit requestId: RequestContext.Id): Unit = { val threadContext = threadPool.getThreadContext val header = createContextHeader(fieldsRestrictions) Option(threadContext.getHeader(header.name.value.value)) match { case None => implicit val show = headerShow - logger.debug(s"[${requestId.show}] Adding thread context header required by lucene. Header: '${header.show}'") + logger.debug(s"Adding thread context header required by lucene. Header: '${header.show}'") threadContext.putHeader(header.name.value.value, header.value.value) case Some(_) => } diff --git a/es81x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala b/es81x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala index 629696a91d..7aa2029a2a 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.admin.indices.template.get.{GetComponentTemplateAction, GetComposableIndexTemplateAction} import org.elasticsearch.action.admin.indices.template.put.{PutComponentTemplateAction, PutComposableIndexTemplateAction} @@ -46,7 +46,7 @@ import scala.jdk.CollectionConverters.* final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJsonParserFactory)(using Clock) extends DataStreamService - with Logging { + with RequestIdAwareLogging { override def checkDataStreamExists(dataStreamName: DataStreamName.Full): Task[Boolean] = execute { val request = new GetDataStreamAction.Request(List(dataStreamName.value.value).toArray) @@ -203,11 +203,11 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ response <- Task.measure( task = Task.delay(nodeClient.execute(action, request).actionGet()), logTimeMeasurement = duration => Task.delay { - logger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") + noRequestIdLogger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") } ) _ <- Task.delay { - logger.debug(s"Action ${action.name()} response: ${response.toString}") + noRequestIdLogger.debug(s"Action ${action.name()} response: ${response.toString}") } } yield response } @@ -215,7 +215,7 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ def executeAck[REQUEST <: ActionRequest, RESPONSE <: AcknowledgedResponse](action: ActionType[RESPONSE], request: REQUEST): Task[RESPONSE] = { executeT(action, request) - .tapEval(response => Task.delay(logger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) + .tapEval(response => Task.delay(noRequestIdLogger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) } private def supportedActions: Map[ActionType[ActionResponse], TransportAction[ActionRequest, ActionResponse]] = { diff --git a/es81x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala b/es81x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala index 2e75d37d0f..16259474bf 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.support.WriteRequest.RefreshPolicy import org.elasticsearch.client.internal.node.NodeClient @@ -38,7 +38,7 @@ import scala.jdk.CollectionConverters.* class EsIndexJsonContentService(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexJsonContentService - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -63,14 +63,14 @@ class EsIndexJsonContentService(client: NodeClient, Option(response.getSourceAsMap) match { case Some(map) => val source = map.asScala.toMap.asStringMap - logger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") Right(source) case None => - logger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") + noRequestIdLogger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") Right(Map.empty[String, String]) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(ContentNotFound) } } @@ -78,7 +78,7 @@ class EsIndexJsonContentService(client: NodeClient, .onErrorRecover { case _: ResourceNotFoundException => Left(ContentNotFound) case ex => - logger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) Left(CannotReachContentSource) } } @@ -104,14 +104,14 @@ class EsIndexJsonContentService(client: NodeClient, case status if status / 100 == 2 => Right(()) case status => - logger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") Left(CannotWriteToIndex) } } .executeOn(RorSchedulers.blockingScheduler) .onErrorRecover { case ex => - logger.error(s"Cannot write to document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]", ex) Left(CannotWriteToIndex) } } diff --git a/es81x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala b/es81x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala index dddd63e278..7d172098e3 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala @@ -22,7 +22,7 @@ import cats.kernel.Monoid import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task import monix.execution.CancelablePromise -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction.{ResolvedAlias, ResolvedIndex} @@ -64,7 +64,7 @@ class EsServerBasedRorClusterService(nodeName: String, nodeClient: NodeClient, threadPool: ThreadPool) extends RorClusterService - with Logging { + with RequestIdAwareLogging { import EsServerBasedRorClusterService.* @@ -155,7 +155,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractAccessibilityFrom) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify get request. Blocking document", ex) + logger.error(s"Could not verify get request. Blocking document", ex)(id) Inaccessible } } @@ -167,7 +167,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractResultsFromSearchResponse) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify documents returned by multi get response. Blocking all returned documents", ex) + logger.error(s"Could not verify documents returned by multi get response. Blocking all returned documents", ex)(id) blockAllDocsReturned(documents) } .map(results => zip(results, documents)) @@ -276,7 +276,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService): Task[List[FullRemoteDataStreamWithAliases]] = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -332,7 +332,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService) = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -418,7 +418,7 @@ class EsServerBasedRorClusterService(nodeName: String, } } case None => - logger.error("Cannot supply Snapshots Service. Please, report the issue!!!") + noRequestIdLogger.error("Cannot supply Snapshots Service. Please, report the issue!!!") Task.now(Set.empty[Snapshot]) } } diff --git a/es81x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala b/es81x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala index 8f9d4eb4f9..cbb23419d0 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.services import cats.data.NonEmptyList -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.DocWriteRequest import org.elasticsearch.action.bulk.{BackoffPolicy, BulkProcessor, BulkRequest, BulkResponse} import org.elasticsearch.action.index.IndexRequest @@ -40,7 +40,7 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, (using Clock) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { private val bulkProcessor = BulkProcessor @@ -77,25 +77,25 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, private class AuditSinkBulkProcessorListener extends BulkProcessor.Listener { override def beforeBulk(executionId: Long, request: BulkRequest): Unit = { - logger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") + noRequestIdLogger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") } override def afterBulk(executionId: Long, request: BulkRequest, response: BulkResponse): Unit = { if (response.hasFailures) { - logger.error("Some failures flushing the BulkProcessor: ") + noRequestIdLogger.error("Some failures flushing the BulkProcessor: ") response .getItems.to(LazyList) .filter(_.isFailed) .map(_.getFailureMessage) .groupBy(identity) .foreach { case (message, stream) => - logger.error(s"${stream.size}x: $message") + noRequestIdLogger.error(s"${stream.size}x: $message") } } } override def afterBulk(executionId: Long, request: BulkRequest, failure: Throwable): Unit = { - logger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) + noRequestIdLogger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) } } diff --git a/es81x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala b/es81x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala index a8def0ec7a..b3c5593c36 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala @@ -22,7 +22,7 @@ import org.apache.http.auth.{AuthScope, Credentials, UsernamePasswordCredentials import org.apache.http.conn.ssl.NoopHostnameVerifier import org.apache.http.impl.client.BasicCredentialsProvider import org.apache.http.impl.nio.client.HttpAsyncClientBuilder -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.* import org.elasticsearch.client.RestClient.FailureListener import tech.beshu.ror.accesscontrol.audit.sink.AuditDataStreamCreator @@ -38,7 +38,7 @@ import scala.collection.parallel.CollectionConverters.* final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient]) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { override def submit(indexName: IndexName.Full, documentId: String, jsonRecord: String) (implicit requestId: RequestId): Unit = { @@ -77,21 +77,21 @@ final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient] override def onSuccess(response: Response): Unit = { response.getStatusLine.getStatusCode / 100 match { case 2 => // 2xx - logger.debug(s"[${requestId.show}] Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") + logger.debug(s"Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") case _ => - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") } } override def onFailure(ex: Exception): Unit = { - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId]", ex) + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId]", ex) } } override val dataStreamCreator: AuditDataStreamCreator = new AuditDataStreamCreator(clients.map(new RestClientDataStreamService(_))) } -object RestClientAuditSinkService extends Logging { +object RestClientAuditSinkService extends RequestIdAwareLogging { def create(remoteCluster: AuditCluster.RemoteAuditCluster): RestClientAuditSinkService = { remoteCluster.mode match { @@ -122,7 +122,7 @@ object RestClientAuditSinkService extends Logging { .setFailureListener( new FailureListener { override def onFailure(node: Node): Unit = { - logger.debug( + noRequestIdLogger.debug( s"[AUDIT] Node marked dead: ${node.getHost.getSchemeName}://${node.getHost.getHostName}:${node.getHost.getPort}. The client will attempt failover.", ) } diff --git a/es81x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala b/es81x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala index 946cfa4c28..24f15af465 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.Channel import io.netty.handler.ssl.NotSslRecordException -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.network.NetworkService import org.elasticsearch.common.settings.{ClusterSettings, Settings} import org.elasticsearch.common.util.BigArrays @@ -41,7 +41,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, sharedGroupFactory: SharedGroupFactory, fipsCompliant: Boolean) extends Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, ssl.clientAuthenticationEnabled) @@ -49,7 +49,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, override def onException(channel: HttpChannel, cause: Exception): Unit = { if (!this.lifecycle.started) return - else if (cause.getCause.isInstanceOf[NotSslRecordException]) logger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) + else if (cause.getCause.isInstanceOf[NotSslRecordException]) noRequestIdLogger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) else super.onException(channel, cause) channel.close() } diff --git a/es81x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala b/es81x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala index f9f71f30b1..e241596351 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.* import io.netty.handler.ssl.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.Version import org.elasticsearch.cluster.node.DiscoveryNode import org.elasticsearch.common.io.stream.NamedWriteableRegistry @@ -45,7 +45,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, sharedGroupFactory: SharedGroupFactory, fipsCompliant: Boolean) extends Netty4Transport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = SSLCertHelper.prepareClientSSLContext(ssl, fipsCompliant, ssl.certificateVerificationEnabled) private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, clientAuthenticationEnabled = false) @@ -76,7 +76,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, override def exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable): Unit = { if (cause.isInstanceOf[NotSslRecordException] || (cause.getCause != null && cause.getCause.isInstanceOf[NotSslRecordException])) { - logger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") + noRequestIdLogger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") ctx.channel.close } else { super.exceptionCaught(ctx, cause) diff --git a/es81x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala b/es81x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala index d206cac4a9..08895e33c4 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.utils import cats.Show import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.client.internal.node.NodeClient import org.elasticsearch.rest.* @@ -37,7 +37,7 @@ import java.util import scala.util.Try class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandler) - extends RestHandler with Logging { + extends RestHandler with RequestIdAwareLogging { private val wrapped = doPrivileged { wrapSomeActions(underlying) @@ -104,11 +104,11 @@ class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandle private def logError(error: AuthorizationValueError): Unit = { { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorSanitizedShow - logger.warn(s"The incoming request was malformed. Cause: ${error.show}") + noRequestIdLogger.warn(s"The incoming request was malformed. Cause: ${error.show}") } if (logger.delegate.isDebugEnabled()) { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorWithDetailsShow - logger.debug(s"Malformed request detailed cause: ${error.show}") + noRequestIdLogger.debug(s"Malformed request detailed cause: ${error.show}") } } diff --git a/es81x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala b/es81x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala index 5ab1e35742..a9af8f710a 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala @@ -16,13 +16,13 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.settings.Settings import tech.beshu.ror.tools.core.patches.PatchingVerifier import tech.beshu.ror.tools.core.patches.PatchingVerifier.Error.{CannotVerifyIfPatched, EsNotPatched} import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -object EsPatchVerifier extends Logging { +object EsPatchVerifier extends RequestIdAwareLogging { def verify(settings: Settings): Unit = doPrivileged { pathHomeFrom(settings).flatMap(PatchingVerifier.verify) match { @@ -30,7 +30,7 @@ object EsPatchVerifier extends Logging { case Left(e@EsNotPatched(_)) => throw new IllegalStateException(e.message) case Left(e@CannotVerifyIfPatched(_)) => - logger.warn(e.message) + noRequestIdLogger.warn(e.message) } } diff --git a/es81x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala b/es81x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala index 639aeb5029..893d807108 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.repositories.{RepositoriesService, VerifyNodeRepositoryAction} import org.elasticsearch.transport.{RemoteClusterService, TransportService} import org.joor.Reflect.on @@ -26,7 +26,7 @@ import java.util.function.Supplier import scala.util.{Failure, Success, Try} class RemoteClusterServiceSupplier(repositoriesServiceSupplier: Supplier[RepositoriesService]) - extends Supplier[Option[RemoteClusterService]] with Logging { + extends Supplier[Option[RemoteClusterService]] with RequestIdAwareLogging { override def get(): Option[RemoteClusterService] = { for { @@ -35,7 +35,7 @@ class RemoteClusterServiceSupplier(repositoriesServiceSupplier: Supplier[Reposit case Success(transportService) => Option(transportService.getRemoteClusterService) case Failure(ex) => - logger.error("Cannot extract RemoteClusterService from RepositoriesService", ex) + noRequestIdLogger.error("Cannot extract RemoteClusterService from RepositoriesService", ex) None } } yield remoteClusterService diff --git a/es82x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es82x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index 1916982621..36ea4c1800 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.support.{ActionFilter, ActionFilterChain} import org.elasticsearch.action.{ActionListener, ActionRequest, ActionResponse} import org.elasticsearch.client.internal.node.NodeClient @@ -62,7 +62,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, rorEsConfig: ReadonlyRestEsConfig) (implicit environmentConfig: EnvironmentConfig) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = environmentConfig.uniqueIdentifierGenerator @@ -212,12 +212,12 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def handleRorNotReadyYet(esContext: EsContext): Unit = { - logger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") + noRequestIdLogger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") rorNotAvailableRequestHandler.handleRorNotReadyYet(esContext) } private def handleRorFailedToStart(esContext: EsContext): Unit = { - logger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") + noRequestIdLogger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") rorNotAvailableRequestHandler.handleRorFailedToStart(esContext) } @@ -239,7 +239,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def logAndSetStartingFailureState(failure: StartingFailure): Unit = { - logger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) + noRequestIdLogger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) rorInstanceState.set(RorInstanceStartingState.NotStarted(failure)) } } diff --git a/es82x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala b/es82x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala index 9feda808c8..ca9ab4aa2d 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.xcontent.LoggingDeprecationHandler import org.elasticsearch.rest.{BytesRestResponse, RestResponse} import org.elasticsearch.xcontent.{NamedXContentRegistry, XContentBuilder, XContentParserConfiguration, XContentType} @@ -30,7 +30,7 @@ import tech.beshu.ror.accesscontrol.domain.ResponseFieldsFiltering.{AccessMode, import scala.jdk.CollectionConverters.* trait ResponseFieldsFiltering { - this: Logging => + this: RequestIdAwareLogging => private val responseFieldsRestrictions: Atomic[Option[ResponseFieldsRestrictions]] = Atomic(None: Option[ResponseFieldsRestrictions]) @@ -45,7 +45,7 @@ trait ResponseFieldsFiltering { case bytesRestResponse: BytesRestResponse => filterBytesRestResponse(bytesRestResponse, fieldsRestrictions) case otherResponse => - logger.warn("ResponseFields filtering is unavailable for this type of request") + noRequestIdLogger.warn("ResponseFields filtering is unavailable for this type of request") otherResponse } case None => diff --git a/es82x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala b/es82x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala index 0f26750588..da95de59a4 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.action.{ActionListener, ActionResponse} import org.elasticsearch.threadpool.ThreadPool @@ -37,7 +37,7 @@ sealed abstract class RorActionListener[T](val underlying: ActionListener[T]) ex final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionListener[T], correlationId: Eval[CorrelationId]) - extends RorActionListener[T](underlying) with Logging { + extends RorActionListener[T](underlying) with RequestIdAwareLogging { override def onFailure(e: Exception): Unit = { super.onFailure(adaptExceptionIfNeeded(e)) @@ -47,7 +47,7 @@ final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionLis ex match { case esException: ElasticsearchException => esException case other => - logger.error(s"[${correlationId.value.show}] Internal error.", other) + noRequestIdLogger.error(s"[${correlationId.value.show}] Internal error.", other) new ElasticsearchException(s"[${correlationId.value.show}] Internal error. See logs for details.") } } diff --git a/es82x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala b/es82x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala index 75048ebe7d..14e5e31c1b 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.http.HttpChannel import org.elasticsearch.rest.{AbstractRestChannel, RestChannel as EsRestChannel, RestRequest as EsRestRequest, RestResponse as EsRestResponse} import squants.information.{Bytes, Information} @@ -40,7 +40,7 @@ object RorRestChannel { final class RorRestChannel private(underlying: EsRestChannel, val restRequest: RorRestRequest) extends AbstractRestChannel(underlying.request(), true) with ResponseFieldsFiltering - with Logging { + with RequestIdAwareLogging { override def sendResponse(response: EsRestResponse): Unit = { ThreadRepo.removeRestChannel(this) diff --git a/es82x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala b/es82x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala index 6babc712b9..3c80750a25 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala @@ -18,16 +18,15 @@ package tech.beshu.ror.es.actions.rradmin import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.ConfigApi.ConfigResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAdminActionHandler extends Logging { +class RRAdminActionHandler extends RequestIdAwareLogging { private implicit val adminRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +51,7 @@ class RRAdminActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAdminResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAdminAction internal error", ex) + logger.error("RRAdminAction internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es82x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala b/es82x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala index c55835a1d0..ce45c6f48e 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala @@ -16,18 +16,15 @@ */ package tech.beshu.ror.es.actions.rrauthmock -import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.AuthMockApi.AuthMockResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier -import tech.beshu.ror.implicits.* +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAuthMockActionHandler extends Logging { +class RRAuthMockActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -53,7 +50,7 @@ class RRAuthMockActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAuthMockResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAuthMock internal error", ex) + logger.error("RRAuthMock internal error", ex) listener.onFailure(new Exception(ex)) } } diff --git a/es82x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala b/es82x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala index aa8bb31e67..640084c4ec 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestconfig import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.TestConfigApi.TestConfigResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestConfigActionHandler extends Logging { +class RRTestConfigActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +52,7 @@ class RRTestConfigActionHandler extends Logging { case Right(response) => listener.onResponse(new RRTestConfigResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRTestConfig internal error", ex) + logger.error(s"RRTestConfig internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es82x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala b/es82x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala index 494e9150b4..98cc0c945d 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.dlsfls import cats.data.StateT import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.DirectoryReader import org.elasticsearch.common.util.concurrent.ThreadContext import org.elasticsearch.core.CheckedFunction @@ -31,7 +31,7 @@ import java.io.IOException import java.util.function.{Function => JavaFunction} import scala.util.{Failure, Success, Try} -object RoleIndexSearcherWrapper extends Logging { +object RoleIndexSearcherWrapper extends RequestIdAwareLogging { val instance: JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] = new JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] { @@ -54,7 +54,7 @@ object RoleIndexSearcherWrapper extends Logging { } .map(r => (r, r)) case None => - logger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") + noRequestIdLogger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") Success((reader, reader)) } } @@ -66,13 +66,13 @@ object RoleIndexSearcherWrapper extends Logging { nel <- NonEmptyString.from(value) match { case Right(nel) => Success(nel) case Left(_) => - logger.debug("FLS: empty header value") + noRequestIdLogger.debug("FLS: empty header value") failure } fields <- transientFieldsFromHeaderValue.fromRawValue(nel) match { case result@Success(_) => result case Failure(ex) => - logger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) + noRequestIdLogger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) failure } } yield fields diff --git a/es82x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala b/es82x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala index ac897184bb..0f785d38fd 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.dlsfls import com.google.common.collect.Iterators -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.codecs.StoredFieldsReader import org.apache.lucene.index.* import org.apache.lucene.index.StoredFieldVisitor.Status @@ -39,21 +39,21 @@ import scala.jdk.CollectionConverters.* import scala.util.Try private class RorDocumentFieldReader(reader: LeafReader, fieldsRestrictions: FieldsRestrictions) - extends SequentialStoredFieldsLeafReader(reader) with Logging { + extends SequentialStoredFieldsLeafReader(reader) with RequestIdAwareLogging { private val policy = new FieldsPolicy(fieldsRestrictions) private val remainingFieldsInfo = { val fInfos = in.getFieldInfos val newInfos = if (fInfos.asScala.isEmpty) { - logger.warn("original fields were empty! This is weird!") + noRequestIdLogger.warn("original fields were empty! This is weird!") fInfos } else { val remainingFields = fInfos.asScala.filter(f => policy.canKeep(f.name)).toSet new FieldInfos(remainingFields.toArray) } - logger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") - logger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") - logger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") + noRequestIdLogger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") newInfos } private val jsonPolicyBasedFilterer = new JsonPolicyBasedFilterer(policy) diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala index 15add4a6dd..a4d939d26a 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.* import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest import org.elasticsearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest @@ -87,7 +87,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, threadPool: ThreadPool) (implicit generator: UniqueIdentifierGenerator, scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle(engines: Engines, esContext: EsContext): Task[Either[Error, Unit]] = { @@ -242,7 +242,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, case SearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case MultiSearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case _ => - logger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") + noRequestIdLogger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") regularRequestHandler.handle(new DummyCompositeIndicesEsRequestContext(request, esContext, aclContext, clusterService, threadPool)) } // rest diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala index cab02aff37..100edd72ac 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.common.io.stream.StreamOutput import org.elasticsearch.xcontent.{ToXContent, ToXContentObject, XContentBuilder} @@ -45,7 +45,7 @@ import scala.util.{Failure, Success, Try} class CurrentUserMetadataRequestHandler(engine: Engine, esContext: EsContext) - extends Logging { + extends RequestIdAwareLogging { def handle(request: RequestContext.Aux[CurrentUserMetadataRequestBlockContext] with EsRequest[CurrentUserMetadataRequestBlockContext]): Task[Unit] = { engine.core.accessControl @@ -69,7 +69,7 @@ class CurrentUserMetadataRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(ex.asInstanceOf[Exception]) } } @@ -86,13 +86,13 @@ class CurrentUserMetadataRequestHandler(engine: Engine, )) } - private def onPassThrough(requestContext: RequestContext): Unit = { - logger.warn(s"[${requestContext.id.toRequestId.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") + private def onPassThrough(implicit requestContext: RequestContext): Unit = { + logger.warn(s"Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") esContext.listener.onFailure(createRorNotEnabledResponse()) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala index 2fb01dcc41..c5c44fda92 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala @@ -20,7 +20,7 @@ import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.RegularRequestResult @@ -49,7 +49,7 @@ class RegularRequestHandler(engine: Engine, esContext: EsContext, threadPool: ThreadPool) (implicit scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle[B <: BlockContext : BlockContextUpdater](request: RequestContext.Aux[B] with EsRequest[B]): Task[Unit] = { engine.core.accessControl @@ -85,7 +85,7 @@ class RegularRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(new Exception(ex)) } } @@ -99,7 +99,7 @@ class RegularRequestHandler(engine: Engine, case ModificationResult.ShouldBeInterrupted => onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case ModificationResult.CannotModify => - logger.error(s"[${request.id.toRequestId.show}] Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") + noRequestIdLogger.error(s"Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case CustomResponse(response) => respond(request, response) @@ -247,7 +247,7 @@ class RegularRequestHandler(engine: Engine, esContext.listener.onResponse(response) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } \ No newline at end of file diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala index f4f832dedc..bfc421bdd5 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.index.query.{AbstractQueryBuilder, QueryBuilder, QueryBuilders} import org.elasticsearch.search.aggregations.AggregatorFactories @@ -40,7 +40,7 @@ import tech.beshu.ror.implicits.* import java.util.UUID import scala.jdk.CollectionConverters.* -object SearchRequestOps extends Logging { +object SearchRequestOps extends RequestIdAwareLogging { implicit class QueryBuilderOps(val builder: Option[QueryBuilder]) extends AnyVal { @@ -52,7 +52,7 @@ object SearchRequestOps extends Logging { val modifiedQuery: AbstractQueryBuilder[_] = provideNewQueryWithAppliedFilter(builder, filterQuery) Some(modifiedQuery) case None => - logger.debug(s"[${requestId.show}] No filter applied to query.") + logger.debug(s"No filter applied to query.") builder } } @@ -92,7 +92,7 @@ object SearchRequestOps extends Logging { case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, requestId) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) disableCaching(requestId) case BasedOnBlockContextOnly.NotAllowedFieldsUsed(notAllowedFields) => modifyNotAllowedFieldsInRequest(notAllowedFields) @@ -138,8 +138,8 @@ object SearchRequestOps extends Logging { } } - private def disableCaching(requestId: RequestContext.Id) = { - logger.debug(s"[${requestId.show}] ACL uses context header for fields rule, will disable request cache for SearchRequest") + private def disableCaching(implicit requestId: RequestContext.Id) = { + logger.debug(s"ACL uses context header for fields rule, will disable request cache for SearchRequest") request.requestCache(false) } } diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala index 270367a54f..e2884598df 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala @@ -17,7 +17,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.action.support.IndicesOptions.WildcardStates import org.elasticsearch.action.{CompositeIndicesRequest, IndicesRequest} @@ -34,7 +33,7 @@ import scala.jdk.CollectionConverters.* abstract class BaseEsRequestContext[B <: BlockContext](esContext: EsContext, clusterService: RorClusterService) - extends RequestContext with Logging { + extends RequestContext { override type BLOCK_CONTEXT = B diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala index ae8abbe1f5..0ee2967364 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala @@ -18,7 +18,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -26,8 +25,9 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import scala.util.Try +import tech.beshu.ror.utils.RequestIdAwareLogging -trait EsRequest[B <: BlockContext] extends Logging { +trait EsRequest[B <: BlockContext] extends RequestIdAwareLogging { implicit def threadPool: ThreadPool final def modifyUsing(blockContext: B): ModificationResult = { @@ -35,7 +35,7 @@ trait EsRequest[B <: BlockContext] extends Logging { Try(modifyRequest(blockContext)) .fold( ex => { - logger.error(s"[${blockContext.requestContext.id.show}] Cannot modify request with filtered data", ex) + logger.error(s"Cannot modify request with filtered data", ex)(blockContext) ModificationResult.CannotModify }, identity diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala index c6a9dcbefd..f773b3efb1 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala @@ -51,7 +51,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest private def discoverDataStreams() = { val dataStreams = dataStreamsFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered data streams: ${dataStreams.show}") + logger.debug(s"Discovered data streams: ${dataStreams.show}") dataStreams } @@ -59,7 +59,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest val backingIndices = backingIndicesFrom(actionRequest) backingIndices match { case BackingIndices.IndicesInvolved(filteredIndices, _) => - logger.debug(s"[${id.show}] Discovered indices: ${filteredIndices.show}") + logger.debug(s"Discovered indices: ${filteredIndices.show}") case BackingIndices.IndicesNotInvolved => } backingIndices diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala index c091179cb6..d150709314 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala @@ -85,7 +85,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: case Some(indices) => update(actionRequest, indices, blockContext.filter, blockContext.fieldLevelSecurity) case None => - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -101,7 +101,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } \ No newline at end of file diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala index 71d462de57..48014e1bdc 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala @@ -73,7 +73,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, } yield update(actionRequest, filteredIndices, allAllowedIndices) result.getOrElse { - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -86,7 +86,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala index 95d882c3b5..f607c0e347 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala @@ -50,7 +50,7 @@ abstract class BaseRepositoriesEsRequestContext[R <: ActionRequest](actionReques case Some(repositories) => update(actionRequest, repositories) case None => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") ShouldBeInterrupted } } diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala index b3b1d66238..7ef0f32014 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala @@ -42,7 +42,7 @@ abstract class BaseSingleIndexEsRequestContext[R <: ActionRequest](actionRequest filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } update(request, filteredIndices.head) } diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala index b5ab70fe7a..c1b2e7ea27 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala @@ -62,7 +62,7 @@ class BulkEsRequestContext(actionRequest: BulkRequest, case (_, _) => ShouldBeInterrupted } } else { - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because origin request contained different " + + logger.error(s"Cannot alter MultiGetRequest request, because origin request contained different " + s"number of requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } @@ -90,18 +90,18 @@ class BulkEsRequestContext(actionRequest: BulkRequest, updateRequestWithIndices(request, nel) Modified case None => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because empty list of indices was found") + logger.error(s"Cannot alter MultiGetRequest request, because empty list of indices was found") ShouldBeInterrupted } case Indices.NotFound => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because no allowed indices were found") + logger.error(s"Cannot alter MultiGetRequest request, because no allowed indices were found") ShouldBeInterrupted } } private def updateRequestWithIndices(request: DocWriteRequest[_], indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } request.index(indices.head.stringify) } diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala index 75a75fcef5..96a043b298 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala @@ -53,14 +53,14 @@ class BulkShardEsRequestContext(actionRequest: BulkShardRequest, case Success(_) => Modified case Failure(ex) => - logger.error(s"[${id.show}] Cannot modify BulkShardRequest", ex) + logger.error(s"Cannot modify BulkShardRequest", ex) CannotModify } } private def tryUpdate(request: BulkShardRequest, indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } val singleIndex = indices.head val uuid = clusterService.indexOrAliasUuids(singleIndex.name).toList.head diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala index 65a168092a..158ac485a5 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala @@ -45,14 +45,14 @@ class ClusterAllocationExplainEsRequestContext(actionRequest: ClusterAllocationE getRequestedIndexFrom(request) match { case Some(_) => if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateIndexIn(request, filteredIndices.head) Modified case None if filteredIndices.exists(_.name === ClusterIndexName.Local.wildcard) => Modified case None => - logger.error(s"[${id.show}] Cluster allocation explain request without index name is unavailable when block contains `indices` rule") + logger.error(s"Cluster allocation explain request without index name is unavailable when block contains `indices` rule") ShouldBeInterrupted } } diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala index 4b977d4c91..9e09afc985 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala @@ -68,7 +68,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, updateAliases(actionRequest, aliases) UpdateResponse.sync(updateAliasesResponse(aliases.includedOnly, _)) case None => - logger.error(s"[${id.show}] At least one alias and one index has to be allowed. " + + logger.error(s"At least one alias and one index has to be allowed. " + s"Found allowed indices: [${blockContext.indices.show}]." + s"Found allowed aliases: [${blockContext.aliases.show}]") ShouldBeInterrupted @@ -116,7 +116,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, .indices().asSafeSet .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } @@ -124,7 +124,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, val aliases = rawRequestAliasesSet(request) .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered aliases: ${aliases.show}") + logger.debug(s"Discovered aliases: ${aliases.show}") aliases } diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala index abb85d42b7..f9e2c87e53 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala @@ -55,7 +55,7 @@ class IndicesAliasesEsRequestContext(actionRequest: IndicesAliasesRequest, if (originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala index 05b70606b9..37dd50452b 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala @@ -119,7 +119,7 @@ class MultiGetEsRequestContext(actionRequest: MultiGetRequest, case Nil => updateItemWithNonExistingIndex(item) case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } item.index(index.stringify) } diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala index 989956d79a..9e13edee8d 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala @@ -78,7 +78,7 @@ class MultiSearchEsRequestContext(actionRequest: MultiSearchRequest, } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala index 9191e33b66..5a61356f48 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala @@ -47,7 +47,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { request.getRequests.removeIf { request => removeOrAlter(request, filteredIndices.toCovariantSet) } if (request.getRequests.asScala.isEmpty) { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") ShouldBeInterrupted } else { Modified @@ -63,7 +63,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, true case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") } request.index(index.stringify) false diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala index c411df93c5..c7b99f6e85 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala @@ -52,7 +52,7 @@ class PutRollupJobEsRequestContext private(actionRequest: ActionRequest, if(originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala index 141d9db788..fff8ed58bb 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala @@ -49,7 +49,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (tryUpdate(actionRequest, filteredIndices)) Modified else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") ShouldBeInterrupted } } diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala index 489d0187bc..c42dfc3b78 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala @@ -58,10 +58,10 @@ class ReindexEsRequestContext(actionRequest: ReindexRequest, Modified } else { if (!isDestinationIndexOnFilteredIndicesList) { - logger.info(s"[${id.show}] Destination index of _reindex request is forbidden") + logger.info(s"Destination index of _reindex request is forbidden") } if (!isSearchRequestComposedOnlyOfAllowedIndices) { - logger.info(s"[${id.show}] At least one index from sources indices list of _reindex request is forbidden") + logger.info(s"At least one index from sources indices list of _reindex request is forbidden") } ShouldBeInterrupted } diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala index 2c1b0014e0..97b8ccd9c5 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala @@ -74,7 +74,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo request } case Left(_) => - logger.debug(s"[${id.show}] Cannot parse SQL statement - we can pass it though, because ES is going to reject it") + logger.debug(s"Cannot parse SQL statement - we can pass it though, because ES is going to reject it") request } } @@ -85,7 +85,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala index 0c67384c1e..d7e743e648 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CleanupRepositoryEsRequestContext(actionRequest: CleanupRepositoryRequest, override protected def update(request: CleanupRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala index 44b7d78dfd..d09015139b 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CreateRepositoryEsRequestContext(actionRequest: PutRepositoryRequest, override protected def update(request: PutRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala index eaf9334872..0cf32e1bea 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class DeleteRepositoryEsRequestContext(actionRequest: DeleteRepositoryRequest, override protected def update(request: DeleteRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala index cee0bffd4c..d1410eff3d 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class VerifyRepositoryEsRequestContext(actionRequest: VerifyRepositoryRequest, override protected def update(request: VerifyRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala index ead4fcf250..20501516d5 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala @@ -68,32 +68,32 @@ class CreateSnapshotEsRequestContext(actionRequest: CreateSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala index a56aba660e..621d744767 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala @@ -60,7 +60,7 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -71,14 +71,14 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, .toRight(()) } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala index 22869bbb4f..b81f333174 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala @@ -68,7 +68,7 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, case r => r } case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala index 88887db96c..156deb5b80 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala @@ -63,7 +63,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -75,7 +75,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") } Right(snapshot) } @@ -88,7 +88,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala index 44ee8397ec..e522e440f1 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala @@ -100,12 +100,12 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { val repositories = blockContext.repositories if (allRepositoriesRequested(repositories)) { Right(RepositoryName.All) @@ -115,7 +115,7 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala index 80e36a6d77..d8e5182eed 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.GetComposableIndexTemplateAction import org.elasticsearch.cluster.metadata import org.elasticsearch.cluster.metadata.ComposableIndexTemplate @@ -108,7 +108,7 @@ class GetComposableIndexTemplateEsRequestContext(actionRequest: GetComposableInd } -private[templates] object GetComposableIndexTemplateEsRequestContext extends Logging { +private[templates] object GetComposableIndexTemplateEsRequestContext extends RequestIdAwareLogging { def filter(templates: Map[String, ComposableIndexTemplate], usingTemplate: Set[Template] => Set[Template]) diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala index c31371351d..1cc65edbde 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.{GetIndexTemplatesRequest, GetIndexTemplatesResponse} import org.elasticsearch.cluster.metadata.{AliasMetadata, IndexTemplateMetadata} import org.elasticsearch.common.collect.ImmutableOpenMap @@ -105,7 +105,7 @@ class GetTemplatesEsRequestContext(actionRequest: GetIndexTemplatesRequest, } -private[templates] object GetTemplatesEsRequestContext extends Logging { +private[templates] object GetTemplatesEsRequestContext extends RequestIdAwareLogging { def filter(templates: Iterable[IndexTemplateMetadata], usingTemplate: Set[Template] => Set[Template]) diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala index a8951de5b1..32116d8212 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala @@ -72,7 +72,7 @@ class MultiSearchTemplateEsRequestContext private(actionRequest: ActionRequest w } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala index e6f6d8916e..434787a686 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala @@ -55,7 +55,7 @@ class SimulateIndexTemplateRequestEsRequestContext(actionRequest: SimulateIndexT filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateRequest(request, filteredIndices.head, allAllowedIndices) } diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala index fbc4cf6776..46ed6e7a95 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala @@ -109,7 +109,7 @@ class SimulateExistingTemplateRequestEsRequestContext(existingTemplateName: Temp case Some(_) => updateResponse(namePatterns.toList, blockContext.allAllowedIndices.toList) case None => - logger.info(s"[${id.show}] User has no access to template ${existingTemplateName.show}") + logger.info(s"User has no access to template ${existingTemplateName.show}") ModificationResult.ShouldBeInterrupted } case other => diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala index 0ecd7a72b3..fe4d60bd42 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.queries import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.index.query.* import org.joor.Reflect.on import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.RequestFieldsUsage @@ -30,7 +30,7 @@ trait QueryFieldsUsage[QUERY <: QueryBuilder] { def fieldsIn(query: QUERY): RequestFieldsUsage } -object QueryFieldsUsage extends Logging { +object QueryFieldsUsage extends RequestIdAwareLogging { def apply[QUERY <: QueryBuilder](implicit ev: QueryFieldsUsage[QUERY]): QueryFieldsUsage[QUERY] = ev implicit class Ops[QUERY <: QueryBuilder : QueryFieldsUsage](val query: QUERY) { @@ -62,7 +62,7 @@ object QueryFieldsUsage extends Logging { Option(on(query).call("getFieldName").get[String]) match { case Some(fieldName: String) => UsingFields(NonEmptyList.one(UsedField(fieldName))) case _ => - logger.debug(s"Cannot extract fields for terms set query") + noRequestIdLogger.debug(s"Cannot extract fields for terms set query") CannotExtractFields } } @@ -89,7 +89,7 @@ object QueryFieldsUsage extends Logging { case builder: TermsSetQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder: WildcardQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder => - logger.debug(s"Cannot extract fields for query: ${builder.getName}") + noRequestIdLogger.debug(s"Cannot extract fields for query: ${builder.getName}") CannotExtractFields } diff --git a/es82x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala b/es82x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala index 0998bb9a5b..b4671e9e4d 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.handler.response import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.FieldsRestrictions import tech.beshu.ror.accesscontrol.domain.Header @@ -26,17 +26,17 @@ import tech.beshu.ror.accesscontrol.headerValues.transientFieldsToHeaderValue import tech.beshu.ror.accesscontrol.request.RequestContext import tech.beshu.ror.implicits.* -object FLSContextHeaderHandler extends Logging { +object FLSContextHeaderHandler extends RequestIdAwareLogging { def addContextHeader(threadPool: ThreadPool, - fieldsRestrictions: FieldsRestrictions, - requestId: RequestContext.Id): Unit = { + fieldsRestrictions: FieldsRestrictions) + (implicit requestId: RequestContext.Id): Unit = { val threadContext = threadPool.getThreadContext val header = createContextHeader(fieldsRestrictions) Option(threadContext.getHeader(header.name.value.value)) match { case None => implicit val show = headerShow - logger.debug(s"[${requestId.show}] Adding thread context header required by lucene. Header: '${header.show}'") + logger.debug(s"Adding thread context header required by lucene. Header: '${header.show}'") threadContext.putHeader(header.name.value.value, header.value.value) case Some(_) => } diff --git a/es82x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala b/es82x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala index 629696a91d..7aa2029a2a 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.admin.indices.template.get.{GetComponentTemplateAction, GetComposableIndexTemplateAction} import org.elasticsearch.action.admin.indices.template.put.{PutComponentTemplateAction, PutComposableIndexTemplateAction} @@ -46,7 +46,7 @@ import scala.jdk.CollectionConverters.* final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJsonParserFactory)(using Clock) extends DataStreamService - with Logging { + with RequestIdAwareLogging { override def checkDataStreamExists(dataStreamName: DataStreamName.Full): Task[Boolean] = execute { val request = new GetDataStreamAction.Request(List(dataStreamName.value.value).toArray) @@ -203,11 +203,11 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ response <- Task.measure( task = Task.delay(nodeClient.execute(action, request).actionGet()), logTimeMeasurement = duration => Task.delay { - logger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") + noRequestIdLogger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") } ) _ <- Task.delay { - logger.debug(s"Action ${action.name()} response: ${response.toString}") + noRequestIdLogger.debug(s"Action ${action.name()} response: ${response.toString}") } } yield response } @@ -215,7 +215,7 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ def executeAck[REQUEST <: ActionRequest, RESPONSE <: AcknowledgedResponse](action: ActionType[RESPONSE], request: REQUEST): Task[RESPONSE] = { executeT(action, request) - .tapEval(response => Task.delay(logger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) + .tapEval(response => Task.delay(noRequestIdLogger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) } private def supportedActions: Map[ActionType[ActionResponse], TransportAction[ActionRequest, ActionResponse]] = { diff --git a/es82x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala b/es82x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala index 2e75d37d0f..16259474bf 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.support.WriteRequest.RefreshPolicy import org.elasticsearch.client.internal.node.NodeClient @@ -38,7 +38,7 @@ import scala.jdk.CollectionConverters.* class EsIndexJsonContentService(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexJsonContentService - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -63,14 +63,14 @@ class EsIndexJsonContentService(client: NodeClient, Option(response.getSourceAsMap) match { case Some(map) => val source = map.asScala.toMap.asStringMap - logger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") Right(source) case None => - logger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") + noRequestIdLogger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") Right(Map.empty[String, String]) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(ContentNotFound) } } @@ -78,7 +78,7 @@ class EsIndexJsonContentService(client: NodeClient, .onErrorRecover { case _: ResourceNotFoundException => Left(ContentNotFound) case ex => - logger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) Left(CannotReachContentSource) } } @@ -104,14 +104,14 @@ class EsIndexJsonContentService(client: NodeClient, case status if status / 100 == 2 => Right(()) case status => - logger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") Left(CannotWriteToIndex) } } .executeOn(RorSchedulers.blockingScheduler) .onErrorRecover { case ex => - logger.error(s"Cannot write to document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]", ex) Left(CannotWriteToIndex) } } diff --git a/es82x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala b/es82x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala index 7d15a76306..df7ab14fec 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala @@ -22,7 +22,7 @@ import cats.kernel.Monoid import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task import monix.execution.CancelablePromise -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction.{ResolvedAlias, ResolvedIndex} @@ -63,7 +63,7 @@ class EsServerBasedRorClusterService(nodeName: String, nodeClient: NodeClient, threadPool: ThreadPool) extends RorClusterService - with Logging { + with RequestIdAwareLogging { import EsServerBasedRorClusterService.* @@ -154,7 +154,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractAccessibilityFrom) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify get request. Blocking document", ex) + logger.error(s"Could not verify get request. Blocking document", ex)(id) Inaccessible } } @@ -166,7 +166,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractResultsFromSearchResponse) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify documents returned by multi get response. Blocking all returned documents", ex) + logger.error(s"Could not verify documents returned by multi get response. Blocking all returned documents", ex)(id) blockAllDocsReturned(documents) } .map(results => zip(results, documents)) @@ -275,7 +275,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService): Task[List[FullRemoteDataStreamWithAliases]] = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -331,7 +331,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService) = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -417,7 +417,7 @@ class EsServerBasedRorClusterService(nodeName: String, } } case None => - logger.error("Cannot supply Snapshots Service. Please, report the issue!!!") + noRequestIdLogger.error("Cannot supply Snapshots Service. Please, report the issue!!!") Task.now(Set.empty[Snapshot]) } } diff --git a/es82x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala b/es82x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala index 8f9d4eb4f9..cbb23419d0 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.services import cats.data.NonEmptyList -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.DocWriteRequest import org.elasticsearch.action.bulk.{BackoffPolicy, BulkProcessor, BulkRequest, BulkResponse} import org.elasticsearch.action.index.IndexRequest @@ -40,7 +40,7 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, (using Clock) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { private val bulkProcessor = BulkProcessor @@ -77,25 +77,25 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, private class AuditSinkBulkProcessorListener extends BulkProcessor.Listener { override def beforeBulk(executionId: Long, request: BulkRequest): Unit = { - logger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") + noRequestIdLogger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") } override def afterBulk(executionId: Long, request: BulkRequest, response: BulkResponse): Unit = { if (response.hasFailures) { - logger.error("Some failures flushing the BulkProcessor: ") + noRequestIdLogger.error("Some failures flushing the BulkProcessor: ") response .getItems.to(LazyList) .filter(_.isFailed) .map(_.getFailureMessage) .groupBy(identity) .foreach { case (message, stream) => - logger.error(s"${stream.size}x: $message") + noRequestIdLogger.error(s"${stream.size}x: $message") } } } override def afterBulk(executionId: Long, request: BulkRequest, failure: Throwable): Unit = { - logger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) + noRequestIdLogger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) } } diff --git a/es82x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala b/es82x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala index a8def0ec7a..b3c5593c36 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala @@ -22,7 +22,7 @@ import org.apache.http.auth.{AuthScope, Credentials, UsernamePasswordCredentials import org.apache.http.conn.ssl.NoopHostnameVerifier import org.apache.http.impl.client.BasicCredentialsProvider import org.apache.http.impl.nio.client.HttpAsyncClientBuilder -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.* import org.elasticsearch.client.RestClient.FailureListener import tech.beshu.ror.accesscontrol.audit.sink.AuditDataStreamCreator @@ -38,7 +38,7 @@ import scala.collection.parallel.CollectionConverters.* final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient]) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { override def submit(indexName: IndexName.Full, documentId: String, jsonRecord: String) (implicit requestId: RequestId): Unit = { @@ -77,21 +77,21 @@ final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient] override def onSuccess(response: Response): Unit = { response.getStatusLine.getStatusCode / 100 match { case 2 => // 2xx - logger.debug(s"[${requestId.show}] Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") + logger.debug(s"Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") case _ => - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") } } override def onFailure(ex: Exception): Unit = { - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId]", ex) + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId]", ex) } } override val dataStreamCreator: AuditDataStreamCreator = new AuditDataStreamCreator(clients.map(new RestClientDataStreamService(_))) } -object RestClientAuditSinkService extends Logging { +object RestClientAuditSinkService extends RequestIdAwareLogging { def create(remoteCluster: AuditCluster.RemoteAuditCluster): RestClientAuditSinkService = { remoteCluster.mode match { @@ -122,7 +122,7 @@ object RestClientAuditSinkService extends Logging { .setFailureListener( new FailureListener { override def onFailure(node: Node): Unit = { - logger.debug( + noRequestIdLogger.debug( s"[AUDIT] Node marked dead: ${node.getHost.getSchemeName}://${node.getHost.getHostName}:${node.getHost.getPort}. The client will attempt failover.", ) } diff --git a/es82x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala b/es82x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala index 946cfa4c28..24f15af465 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.Channel import io.netty.handler.ssl.NotSslRecordException -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.network.NetworkService import org.elasticsearch.common.settings.{ClusterSettings, Settings} import org.elasticsearch.common.util.BigArrays @@ -41,7 +41,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, sharedGroupFactory: SharedGroupFactory, fipsCompliant: Boolean) extends Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, ssl.clientAuthenticationEnabled) @@ -49,7 +49,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, override def onException(channel: HttpChannel, cause: Exception): Unit = { if (!this.lifecycle.started) return - else if (cause.getCause.isInstanceOf[NotSslRecordException]) logger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) + else if (cause.getCause.isInstanceOf[NotSslRecordException]) noRequestIdLogger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) else super.onException(channel, cause) channel.close() } diff --git a/es82x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala b/es82x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala index f9f71f30b1..e241596351 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.* import io.netty.handler.ssl.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.Version import org.elasticsearch.cluster.node.DiscoveryNode import org.elasticsearch.common.io.stream.NamedWriteableRegistry @@ -45,7 +45,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, sharedGroupFactory: SharedGroupFactory, fipsCompliant: Boolean) extends Netty4Transport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = SSLCertHelper.prepareClientSSLContext(ssl, fipsCompliant, ssl.certificateVerificationEnabled) private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, clientAuthenticationEnabled = false) @@ -76,7 +76,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, override def exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable): Unit = { if (cause.isInstanceOf[NotSslRecordException] || (cause.getCause != null && cause.getCause.isInstanceOf[NotSslRecordException])) { - logger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") + noRequestIdLogger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") ctx.channel.close } else { super.exceptionCaught(ctx, cause) diff --git a/es82x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala b/es82x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala index d206cac4a9..08895e33c4 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.utils import cats.Show import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.client.internal.node.NodeClient import org.elasticsearch.rest.* @@ -37,7 +37,7 @@ import java.util import scala.util.Try class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandler) - extends RestHandler with Logging { + extends RestHandler with RequestIdAwareLogging { private val wrapped = doPrivileged { wrapSomeActions(underlying) @@ -104,11 +104,11 @@ class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandle private def logError(error: AuthorizationValueError): Unit = { { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorSanitizedShow - logger.warn(s"The incoming request was malformed. Cause: ${error.show}") + noRequestIdLogger.warn(s"The incoming request was malformed. Cause: ${error.show}") } if (logger.delegate.isDebugEnabled()) { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorWithDetailsShow - logger.debug(s"Malformed request detailed cause: ${error.show}") + noRequestIdLogger.debug(s"Malformed request detailed cause: ${error.show}") } } diff --git a/es82x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala b/es82x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala index 5ab1e35742..a9af8f710a 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala @@ -16,13 +16,13 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.settings.Settings import tech.beshu.ror.tools.core.patches.PatchingVerifier import tech.beshu.ror.tools.core.patches.PatchingVerifier.Error.{CannotVerifyIfPatched, EsNotPatched} import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -object EsPatchVerifier extends Logging { +object EsPatchVerifier extends RequestIdAwareLogging { def verify(settings: Settings): Unit = doPrivileged { pathHomeFrom(settings).flatMap(PatchingVerifier.verify) match { @@ -30,7 +30,7 @@ object EsPatchVerifier extends Logging { case Left(e@EsNotPatched(_)) => throw new IllegalStateException(e.message) case Left(e@CannotVerifyIfPatched(_)) => - logger.warn(e.message) + noRequestIdLogger.warn(e.message) } } diff --git a/es82x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala b/es82x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala index 639aeb5029..893d807108 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.repositories.{RepositoriesService, VerifyNodeRepositoryAction} import org.elasticsearch.transport.{RemoteClusterService, TransportService} import org.joor.Reflect.on @@ -26,7 +26,7 @@ import java.util.function.Supplier import scala.util.{Failure, Success, Try} class RemoteClusterServiceSupplier(repositoriesServiceSupplier: Supplier[RepositoriesService]) - extends Supplier[Option[RemoteClusterService]] with Logging { + extends Supplier[Option[RemoteClusterService]] with RequestIdAwareLogging { override def get(): Option[RemoteClusterService] = { for { @@ -35,7 +35,7 @@ class RemoteClusterServiceSupplier(repositoriesServiceSupplier: Supplier[Reposit case Success(transportService) => Option(transportService.getRemoteClusterService) case Failure(ex) => - logger.error("Cannot extract RemoteClusterService from RepositoriesService", ex) + noRequestIdLogger.error("Cannot extract RemoteClusterService from RepositoriesService", ex) None } } yield remoteClusterService diff --git a/es83x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es83x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index 1916982621..36ea4c1800 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.support.{ActionFilter, ActionFilterChain} import org.elasticsearch.action.{ActionListener, ActionRequest, ActionResponse} import org.elasticsearch.client.internal.node.NodeClient @@ -62,7 +62,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, rorEsConfig: ReadonlyRestEsConfig) (implicit environmentConfig: EnvironmentConfig) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = environmentConfig.uniqueIdentifierGenerator @@ -212,12 +212,12 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def handleRorNotReadyYet(esContext: EsContext): Unit = { - logger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") + noRequestIdLogger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") rorNotAvailableRequestHandler.handleRorNotReadyYet(esContext) } private def handleRorFailedToStart(esContext: EsContext): Unit = { - logger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") + noRequestIdLogger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") rorNotAvailableRequestHandler.handleRorFailedToStart(esContext) } @@ -239,7 +239,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def logAndSetStartingFailureState(failure: StartingFailure): Unit = { - logger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) + noRequestIdLogger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) rorInstanceState.set(RorInstanceStartingState.NotStarted(failure)) } } diff --git a/es83x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala b/es83x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala index 9feda808c8..ca9ab4aa2d 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.xcontent.LoggingDeprecationHandler import org.elasticsearch.rest.{BytesRestResponse, RestResponse} import org.elasticsearch.xcontent.{NamedXContentRegistry, XContentBuilder, XContentParserConfiguration, XContentType} @@ -30,7 +30,7 @@ import tech.beshu.ror.accesscontrol.domain.ResponseFieldsFiltering.{AccessMode, import scala.jdk.CollectionConverters.* trait ResponseFieldsFiltering { - this: Logging => + this: RequestIdAwareLogging => private val responseFieldsRestrictions: Atomic[Option[ResponseFieldsRestrictions]] = Atomic(None: Option[ResponseFieldsRestrictions]) @@ -45,7 +45,7 @@ trait ResponseFieldsFiltering { case bytesRestResponse: BytesRestResponse => filterBytesRestResponse(bytesRestResponse, fieldsRestrictions) case otherResponse => - logger.warn("ResponseFields filtering is unavailable for this type of request") + noRequestIdLogger.warn("ResponseFields filtering is unavailable for this type of request") otherResponse } case None => diff --git a/es83x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala b/es83x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala index 0f26750588..da95de59a4 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.action.{ActionListener, ActionResponse} import org.elasticsearch.threadpool.ThreadPool @@ -37,7 +37,7 @@ sealed abstract class RorActionListener[T](val underlying: ActionListener[T]) ex final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionListener[T], correlationId: Eval[CorrelationId]) - extends RorActionListener[T](underlying) with Logging { + extends RorActionListener[T](underlying) with RequestIdAwareLogging { override def onFailure(e: Exception): Unit = { super.onFailure(adaptExceptionIfNeeded(e)) @@ -47,7 +47,7 @@ final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionLis ex match { case esException: ElasticsearchException => esException case other => - logger.error(s"[${correlationId.value.show}] Internal error.", other) + noRequestIdLogger.error(s"[${correlationId.value.show}] Internal error.", other) new ElasticsearchException(s"[${correlationId.value.show}] Internal error. See logs for details.") } } diff --git a/es83x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala b/es83x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala index 75048ebe7d..14e5e31c1b 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.http.HttpChannel import org.elasticsearch.rest.{AbstractRestChannel, RestChannel as EsRestChannel, RestRequest as EsRestRequest, RestResponse as EsRestResponse} import squants.information.{Bytes, Information} @@ -40,7 +40,7 @@ object RorRestChannel { final class RorRestChannel private(underlying: EsRestChannel, val restRequest: RorRestRequest) extends AbstractRestChannel(underlying.request(), true) with ResponseFieldsFiltering - with Logging { + with RequestIdAwareLogging { override def sendResponse(response: EsRestResponse): Unit = { ThreadRepo.removeRestChannel(this) diff --git a/es83x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala b/es83x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala index 6babc712b9..3c80750a25 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala @@ -18,16 +18,15 @@ package tech.beshu.ror.es.actions.rradmin import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.ConfigApi.ConfigResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAdminActionHandler extends Logging { +class RRAdminActionHandler extends RequestIdAwareLogging { private implicit val adminRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +51,7 @@ class RRAdminActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAdminResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAdminAction internal error", ex) + logger.error("RRAdminAction internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es83x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala b/es83x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala index c55835a1d0..ce45c6f48e 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala @@ -16,18 +16,15 @@ */ package tech.beshu.ror.es.actions.rrauthmock -import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.AuthMockApi.AuthMockResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier -import tech.beshu.ror.implicits.* +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAuthMockActionHandler extends Logging { +class RRAuthMockActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -53,7 +50,7 @@ class RRAuthMockActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAuthMockResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAuthMock internal error", ex) + logger.error("RRAuthMock internal error", ex) listener.onFailure(new Exception(ex)) } } diff --git a/es83x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala b/es83x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala index aa8bb31e67..640084c4ec 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestconfig import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.TestConfigApi.TestConfigResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestConfigActionHandler extends Logging { +class RRTestConfigActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +52,7 @@ class RRTestConfigActionHandler extends Logging { case Right(response) => listener.onResponse(new RRTestConfigResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRTestConfig internal error", ex) + logger.error(s"RRTestConfig internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es83x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala b/es83x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala index 494e9150b4..98cc0c945d 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.dlsfls import cats.data.StateT import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.DirectoryReader import org.elasticsearch.common.util.concurrent.ThreadContext import org.elasticsearch.core.CheckedFunction @@ -31,7 +31,7 @@ import java.io.IOException import java.util.function.{Function => JavaFunction} import scala.util.{Failure, Success, Try} -object RoleIndexSearcherWrapper extends Logging { +object RoleIndexSearcherWrapper extends RequestIdAwareLogging { val instance: JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] = new JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] { @@ -54,7 +54,7 @@ object RoleIndexSearcherWrapper extends Logging { } .map(r => (r, r)) case None => - logger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") + noRequestIdLogger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") Success((reader, reader)) } } @@ -66,13 +66,13 @@ object RoleIndexSearcherWrapper extends Logging { nel <- NonEmptyString.from(value) match { case Right(nel) => Success(nel) case Left(_) => - logger.debug("FLS: empty header value") + noRequestIdLogger.debug("FLS: empty header value") failure } fields <- transientFieldsFromHeaderValue.fromRawValue(nel) match { case result@Success(_) => result case Failure(ex) => - logger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) + noRequestIdLogger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) failure } } yield fields diff --git a/es83x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala b/es83x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala index ac897184bb..0f785d38fd 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.dlsfls import com.google.common.collect.Iterators -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.codecs.StoredFieldsReader import org.apache.lucene.index.* import org.apache.lucene.index.StoredFieldVisitor.Status @@ -39,21 +39,21 @@ import scala.jdk.CollectionConverters.* import scala.util.Try private class RorDocumentFieldReader(reader: LeafReader, fieldsRestrictions: FieldsRestrictions) - extends SequentialStoredFieldsLeafReader(reader) with Logging { + extends SequentialStoredFieldsLeafReader(reader) with RequestIdAwareLogging { private val policy = new FieldsPolicy(fieldsRestrictions) private val remainingFieldsInfo = { val fInfos = in.getFieldInfos val newInfos = if (fInfos.asScala.isEmpty) { - logger.warn("original fields were empty! This is weird!") + noRequestIdLogger.warn("original fields were empty! This is weird!") fInfos } else { val remainingFields = fInfos.asScala.filter(f => policy.canKeep(f.name)).toSet new FieldInfos(remainingFields.toArray) } - logger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") - logger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") - logger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") + noRequestIdLogger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") newInfos } private val jsonPolicyBasedFilterer = new JsonPolicyBasedFilterer(policy) diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala index 15add4a6dd..a4d939d26a 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.* import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest import org.elasticsearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest @@ -87,7 +87,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, threadPool: ThreadPool) (implicit generator: UniqueIdentifierGenerator, scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle(engines: Engines, esContext: EsContext): Task[Either[Error, Unit]] = { @@ -242,7 +242,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, case SearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case MultiSearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case _ => - logger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") + noRequestIdLogger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") regularRequestHandler.handle(new DummyCompositeIndicesEsRequestContext(request, esContext, aclContext, clusterService, threadPool)) } // rest diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala index cab02aff37..100edd72ac 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.common.io.stream.StreamOutput import org.elasticsearch.xcontent.{ToXContent, ToXContentObject, XContentBuilder} @@ -45,7 +45,7 @@ import scala.util.{Failure, Success, Try} class CurrentUserMetadataRequestHandler(engine: Engine, esContext: EsContext) - extends Logging { + extends RequestIdAwareLogging { def handle(request: RequestContext.Aux[CurrentUserMetadataRequestBlockContext] with EsRequest[CurrentUserMetadataRequestBlockContext]): Task[Unit] = { engine.core.accessControl @@ -69,7 +69,7 @@ class CurrentUserMetadataRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(ex.asInstanceOf[Exception]) } } @@ -86,13 +86,13 @@ class CurrentUserMetadataRequestHandler(engine: Engine, )) } - private def onPassThrough(requestContext: RequestContext): Unit = { - logger.warn(s"[${requestContext.id.toRequestId.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") + private def onPassThrough(implicit requestContext: RequestContext): Unit = { + logger.warn(s"Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") esContext.listener.onFailure(createRorNotEnabledResponse()) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala index 2fb01dcc41..c5c44fda92 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala @@ -20,7 +20,7 @@ import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.RegularRequestResult @@ -49,7 +49,7 @@ class RegularRequestHandler(engine: Engine, esContext: EsContext, threadPool: ThreadPool) (implicit scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle[B <: BlockContext : BlockContextUpdater](request: RequestContext.Aux[B] with EsRequest[B]): Task[Unit] = { engine.core.accessControl @@ -85,7 +85,7 @@ class RegularRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(new Exception(ex)) } } @@ -99,7 +99,7 @@ class RegularRequestHandler(engine: Engine, case ModificationResult.ShouldBeInterrupted => onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case ModificationResult.CannotModify => - logger.error(s"[${request.id.toRequestId.show}] Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") + noRequestIdLogger.error(s"Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case CustomResponse(response) => respond(request, response) @@ -247,7 +247,7 @@ class RegularRequestHandler(engine: Engine, esContext.listener.onResponse(response) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } \ No newline at end of file diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala index f4f832dedc..bfc421bdd5 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.index.query.{AbstractQueryBuilder, QueryBuilder, QueryBuilders} import org.elasticsearch.search.aggregations.AggregatorFactories @@ -40,7 +40,7 @@ import tech.beshu.ror.implicits.* import java.util.UUID import scala.jdk.CollectionConverters.* -object SearchRequestOps extends Logging { +object SearchRequestOps extends RequestIdAwareLogging { implicit class QueryBuilderOps(val builder: Option[QueryBuilder]) extends AnyVal { @@ -52,7 +52,7 @@ object SearchRequestOps extends Logging { val modifiedQuery: AbstractQueryBuilder[_] = provideNewQueryWithAppliedFilter(builder, filterQuery) Some(modifiedQuery) case None => - logger.debug(s"[${requestId.show}] No filter applied to query.") + logger.debug(s"No filter applied to query.") builder } } @@ -92,7 +92,7 @@ object SearchRequestOps extends Logging { case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, requestId) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) disableCaching(requestId) case BasedOnBlockContextOnly.NotAllowedFieldsUsed(notAllowedFields) => modifyNotAllowedFieldsInRequest(notAllowedFields) @@ -138,8 +138,8 @@ object SearchRequestOps extends Logging { } } - private def disableCaching(requestId: RequestContext.Id) = { - logger.debug(s"[${requestId.show}] ACL uses context header for fields rule, will disable request cache for SearchRequest") + private def disableCaching(implicit requestId: RequestContext.Id) = { + logger.debug(s"ACL uses context header for fields rule, will disable request cache for SearchRequest") request.requestCache(false) } } diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala index 270367a54f..e2884598df 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala @@ -17,7 +17,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.action.support.IndicesOptions.WildcardStates import org.elasticsearch.action.{CompositeIndicesRequest, IndicesRequest} @@ -34,7 +33,7 @@ import scala.jdk.CollectionConverters.* abstract class BaseEsRequestContext[B <: BlockContext](esContext: EsContext, clusterService: RorClusterService) - extends RequestContext with Logging { + extends RequestContext { override type BLOCK_CONTEXT = B diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala index ae8abbe1f5..0ee2967364 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala @@ -18,7 +18,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -26,8 +25,9 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import scala.util.Try +import tech.beshu.ror.utils.RequestIdAwareLogging -trait EsRequest[B <: BlockContext] extends Logging { +trait EsRequest[B <: BlockContext] extends RequestIdAwareLogging { implicit def threadPool: ThreadPool final def modifyUsing(blockContext: B): ModificationResult = { @@ -35,7 +35,7 @@ trait EsRequest[B <: BlockContext] extends Logging { Try(modifyRequest(blockContext)) .fold( ex => { - logger.error(s"[${blockContext.requestContext.id.show}] Cannot modify request with filtered data", ex) + logger.error(s"Cannot modify request with filtered data", ex)(blockContext) ModificationResult.CannotModify }, identity diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala index c6a9dcbefd..f773b3efb1 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala @@ -51,7 +51,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest private def discoverDataStreams() = { val dataStreams = dataStreamsFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered data streams: ${dataStreams.show}") + logger.debug(s"Discovered data streams: ${dataStreams.show}") dataStreams } @@ -59,7 +59,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest val backingIndices = backingIndicesFrom(actionRequest) backingIndices match { case BackingIndices.IndicesInvolved(filteredIndices, _) => - logger.debug(s"[${id.show}] Discovered indices: ${filteredIndices.show}") + logger.debug(s"Discovered indices: ${filteredIndices.show}") case BackingIndices.IndicesNotInvolved => } backingIndices diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala index c091179cb6..d150709314 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala @@ -85,7 +85,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: case Some(indices) => update(actionRequest, indices, blockContext.filter, blockContext.fieldLevelSecurity) case None => - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -101,7 +101,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } \ No newline at end of file diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala index 71d462de57..48014e1bdc 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala @@ -73,7 +73,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, } yield update(actionRequest, filteredIndices, allAllowedIndices) result.getOrElse { - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -86,7 +86,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala index 95d882c3b5..f607c0e347 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala @@ -50,7 +50,7 @@ abstract class BaseRepositoriesEsRequestContext[R <: ActionRequest](actionReques case Some(repositories) => update(actionRequest, repositories) case None => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") ShouldBeInterrupted } } diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala index b3b1d66238..7ef0f32014 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala @@ -42,7 +42,7 @@ abstract class BaseSingleIndexEsRequestContext[R <: ActionRequest](actionRequest filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } update(request, filteredIndices.head) } diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala index b5ab70fe7a..c1b2e7ea27 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala @@ -62,7 +62,7 @@ class BulkEsRequestContext(actionRequest: BulkRequest, case (_, _) => ShouldBeInterrupted } } else { - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because origin request contained different " + + logger.error(s"Cannot alter MultiGetRequest request, because origin request contained different " + s"number of requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } @@ -90,18 +90,18 @@ class BulkEsRequestContext(actionRequest: BulkRequest, updateRequestWithIndices(request, nel) Modified case None => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because empty list of indices was found") + logger.error(s"Cannot alter MultiGetRequest request, because empty list of indices was found") ShouldBeInterrupted } case Indices.NotFound => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because no allowed indices were found") + logger.error(s"Cannot alter MultiGetRequest request, because no allowed indices were found") ShouldBeInterrupted } } private def updateRequestWithIndices(request: DocWriteRequest[_], indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } request.index(indices.head.stringify) } diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala index 75a75fcef5..96a043b298 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala @@ -53,14 +53,14 @@ class BulkShardEsRequestContext(actionRequest: BulkShardRequest, case Success(_) => Modified case Failure(ex) => - logger.error(s"[${id.show}] Cannot modify BulkShardRequest", ex) + logger.error(s"Cannot modify BulkShardRequest", ex) CannotModify } } private def tryUpdate(request: BulkShardRequest, indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } val singleIndex = indices.head val uuid = clusterService.indexOrAliasUuids(singleIndex.name).toList.head diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala index 65a168092a..158ac485a5 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala @@ -45,14 +45,14 @@ class ClusterAllocationExplainEsRequestContext(actionRequest: ClusterAllocationE getRequestedIndexFrom(request) match { case Some(_) => if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateIndexIn(request, filteredIndices.head) Modified case None if filteredIndices.exists(_.name === ClusterIndexName.Local.wildcard) => Modified case None => - logger.error(s"[${id.show}] Cluster allocation explain request without index name is unavailable when block contains `indices` rule") + logger.error(s"Cluster allocation explain request without index name is unavailable when block contains `indices` rule") ShouldBeInterrupted } } diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala index 4b977d4c91..9e09afc985 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala @@ -68,7 +68,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, updateAliases(actionRequest, aliases) UpdateResponse.sync(updateAliasesResponse(aliases.includedOnly, _)) case None => - logger.error(s"[${id.show}] At least one alias and one index has to be allowed. " + + logger.error(s"At least one alias and one index has to be allowed. " + s"Found allowed indices: [${blockContext.indices.show}]." + s"Found allowed aliases: [${blockContext.aliases.show}]") ShouldBeInterrupted @@ -116,7 +116,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, .indices().asSafeSet .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } @@ -124,7 +124,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, val aliases = rawRequestAliasesSet(request) .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered aliases: ${aliases.show}") + logger.debug(s"Discovered aliases: ${aliases.show}") aliases } diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala index abb85d42b7..f9e2c87e53 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala @@ -55,7 +55,7 @@ class IndicesAliasesEsRequestContext(actionRequest: IndicesAliasesRequest, if (originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala index 05b70606b9..37dd50452b 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala @@ -119,7 +119,7 @@ class MultiGetEsRequestContext(actionRequest: MultiGetRequest, case Nil => updateItemWithNonExistingIndex(item) case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } item.index(index.stringify) } diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala index 989956d79a..9e13edee8d 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala @@ -78,7 +78,7 @@ class MultiSearchEsRequestContext(actionRequest: MultiSearchRequest, } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala index 9191e33b66..5a61356f48 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala @@ -47,7 +47,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { request.getRequests.removeIf { request => removeOrAlter(request, filteredIndices.toCovariantSet) } if (request.getRequests.asScala.isEmpty) { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") ShouldBeInterrupted } else { Modified @@ -63,7 +63,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, true case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") } request.index(index.stringify) false diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala index c411df93c5..c7b99f6e85 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala @@ -52,7 +52,7 @@ class PutRollupJobEsRequestContext private(actionRequest: ActionRequest, if(originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala index 141d9db788..fff8ed58bb 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala @@ -49,7 +49,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (tryUpdate(actionRequest, filteredIndices)) Modified else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") ShouldBeInterrupted } } diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala index 489d0187bc..c42dfc3b78 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala @@ -58,10 +58,10 @@ class ReindexEsRequestContext(actionRequest: ReindexRequest, Modified } else { if (!isDestinationIndexOnFilteredIndicesList) { - logger.info(s"[${id.show}] Destination index of _reindex request is forbidden") + logger.info(s"Destination index of _reindex request is forbidden") } if (!isSearchRequestComposedOnlyOfAllowedIndices) { - logger.info(s"[${id.show}] At least one index from sources indices list of _reindex request is forbidden") + logger.info(s"At least one index from sources indices list of _reindex request is forbidden") } ShouldBeInterrupted } diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala index 2c1b0014e0..97b8ccd9c5 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala @@ -74,7 +74,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo request } case Left(_) => - logger.debug(s"[${id.show}] Cannot parse SQL statement - we can pass it though, because ES is going to reject it") + logger.debug(s"Cannot parse SQL statement - we can pass it though, because ES is going to reject it") request } } @@ -85,7 +85,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala index 0c67384c1e..d7e743e648 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CleanupRepositoryEsRequestContext(actionRequest: CleanupRepositoryRequest, override protected def update(request: CleanupRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala index 44b7d78dfd..d09015139b 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CreateRepositoryEsRequestContext(actionRequest: PutRepositoryRequest, override protected def update(request: PutRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala index eaf9334872..0cf32e1bea 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class DeleteRepositoryEsRequestContext(actionRequest: DeleteRepositoryRequest, override protected def update(request: DeleteRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala index cee0bffd4c..d1410eff3d 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class VerifyRepositoryEsRequestContext(actionRequest: VerifyRepositoryRequest, override protected def update(request: VerifyRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala index ead4fcf250..20501516d5 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala @@ -68,32 +68,32 @@ class CreateSnapshotEsRequestContext(actionRequest: CreateSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala index a56aba660e..621d744767 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala @@ -60,7 +60,7 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -71,14 +71,14 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, .toRight(()) } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala index 22869bbb4f..b81f333174 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala @@ -68,7 +68,7 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, case r => r } case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala index 88887db96c..156deb5b80 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala @@ -63,7 +63,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -75,7 +75,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") } Right(snapshot) } @@ -88,7 +88,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala index 44ee8397ec..e522e440f1 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala @@ -100,12 +100,12 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { val repositories = blockContext.repositories if (allRepositoriesRequested(repositories)) { Right(RepositoryName.All) @@ -115,7 +115,7 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala index 80e36a6d77..d8e5182eed 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.GetComposableIndexTemplateAction import org.elasticsearch.cluster.metadata import org.elasticsearch.cluster.metadata.ComposableIndexTemplate @@ -108,7 +108,7 @@ class GetComposableIndexTemplateEsRequestContext(actionRequest: GetComposableInd } -private[templates] object GetComposableIndexTemplateEsRequestContext extends Logging { +private[templates] object GetComposableIndexTemplateEsRequestContext extends RequestIdAwareLogging { def filter(templates: Map[String, ComposableIndexTemplate], usingTemplate: Set[Template] => Set[Template]) diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala index c31371351d..1cc65edbde 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.{GetIndexTemplatesRequest, GetIndexTemplatesResponse} import org.elasticsearch.cluster.metadata.{AliasMetadata, IndexTemplateMetadata} import org.elasticsearch.common.collect.ImmutableOpenMap @@ -105,7 +105,7 @@ class GetTemplatesEsRequestContext(actionRequest: GetIndexTemplatesRequest, } -private[templates] object GetTemplatesEsRequestContext extends Logging { +private[templates] object GetTemplatesEsRequestContext extends RequestIdAwareLogging { def filter(templates: Iterable[IndexTemplateMetadata], usingTemplate: Set[Template] => Set[Template]) diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala index a8951de5b1..32116d8212 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala @@ -72,7 +72,7 @@ class MultiSearchTemplateEsRequestContext private(actionRequest: ActionRequest w } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala index e6f6d8916e..434787a686 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala @@ -55,7 +55,7 @@ class SimulateIndexTemplateRequestEsRequestContext(actionRequest: SimulateIndexT filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateRequest(request, filteredIndices.head, allAllowedIndices) } diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala index fbc4cf6776..46ed6e7a95 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala @@ -109,7 +109,7 @@ class SimulateExistingTemplateRequestEsRequestContext(existingTemplateName: Temp case Some(_) => updateResponse(namePatterns.toList, blockContext.allAllowedIndices.toList) case None => - logger.info(s"[${id.show}] User has no access to template ${existingTemplateName.show}") + logger.info(s"User has no access to template ${existingTemplateName.show}") ModificationResult.ShouldBeInterrupted } case other => diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala index 0ecd7a72b3..fe4d60bd42 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.queries import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.index.query.* import org.joor.Reflect.on import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.RequestFieldsUsage @@ -30,7 +30,7 @@ trait QueryFieldsUsage[QUERY <: QueryBuilder] { def fieldsIn(query: QUERY): RequestFieldsUsage } -object QueryFieldsUsage extends Logging { +object QueryFieldsUsage extends RequestIdAwareLogging { def apply[QUERY <: QueryBuilder](implicit ev: QueryFieldsUsage[QUERY]): QueryFieldsUsage[QUERY] = ev implicit class Ops[QUERY <: QueryBuilder : QueryFieldsUsage](val query: QUERY) { @@ -62,7 +62,7 @@ object QueryFieldsUsage extends Logging { Option(on(query).call("getFieldName").get[String]) match { case Some(fieldName: String) => UsingFields(NonEmptyList.one(UsedField(fieldName))) case _ => - logger.debug(s"Cannot extract fields for terms set query") + noRequestIdLogger.debug(s"Cannot extract fields for terms set query") CannotExtractFields } } @@ -89,7 +89,7 @@ object QueryFieldsUsage extends Logging { case builder: TermsSetQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder: WildcardQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder => - logger.debug(s"Cannot extract fields for query: ${builder.getName}") + noRequestIdLogger.debug(s"Cannot extract fields for query: ${builder.getName}") CannotExtractFields } diff --git a/es83x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala b/es83x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala index 0998bb9a5b..b4671e9e4d 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.handler.response import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.FieldsRestrictions import tech.beshu.ror.accesscontrol.domain.Header @@ -26,17 +26,17 @@ import tech.beshu.ror.accesscontrol.headerValues.transientFieldsToHeaderValue import tech.beshu.ror.accesscontrol.request.RequestContext import tech.beshu.ror.implicits.* -object FLSContextHeaderHandler extends Logging { +object FLSContextHeaderHandler extends RequestIdAwareLogging { def addContextHeader(threadPool: ThreadPool, - fieldsRestrictions: FieldsRestrictions, - requestId: RequestContext.Id): Unit = { + fieldsRestrictions: FieldsRestrictions) + (implicit requestId: RequestContext.Id): Unit = { val threadContext = threadPool.getThreadContext val header = createContextHeader(fieldsRestrictions) Option(threadContext.getHeader(header.name.value.value)) match { case None => implicit val show = headerShow - logger.debug(s"[${requestId.show}] Adding thread context header required by lucene. Header: '${header.show}'") + logger.debug(s"Adding thread context header required by lucene. Header: '${header.show}'") threadContext.putHeader(header.name.value.value, header.value.value) case Some(_) => } diff --git a/es83x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala b/es83x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala index 629696a91d..7aa2029a2a 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.admin.indices.template.get.{GetComponentTemplateAction, GetComposableIndexTemplateAction} import org.elasticsearch.action.admin.indices.template.put.{PutComponentTemplateAction, PutComposableIndexTemplateAction} @@ -46,7 +46,7 @@ import scala.jdk.CollectionConverters.* final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJsonParserFactory)(using Clock) extends DataStreamService - with Logging { + with RequestIdAwareLogging { override def checkDataStreamExists(dataStreamName: DataStreamName.Full): Task[Boolean] = execute { val request = new GetDataStreamAction.Request(List(dataStreamName.value.value).toArray) @@ -203,11 +203,11 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ response <- Task.measure( task = Task.delay(nodeClient.execute(action, request).actionGet()), logTimeMeasurement = duration => Task.delay { - logger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") + noRequestIdLogger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") } ) _ <- Task.delay { - logger.debug(s"Action ${action.name()} response: ${response.toString}") + noRequestIdLogger.debug(s"Action ${action.name()} response: ${response.toString}") } } yield response } @@ -215,7 +215,7 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ def executeAck[REQUEST <: ActionRequest, RESPONSE <: AcknowledgedResponse](action: ActionType[RESPONSE], request: REQUEST): Task[RESPONSE] = { executeT(action, request) - .tapEval(response => Task.delay(logger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) + .tapEval(response => Task.delay(noRequestIdLogger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) } private def supportedActions: Map[ActionType[ActionResponse], TransportAction[ActionRequest, ActionResponse]] = { diff --git a/es83x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala b/es83x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala index 2e75d37d0f..16259474bf 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.support.WriteRequest.RefreshPolicy import org.elasticsearch.client.internal.node.NodeClient @@ -38,7 +38,7 @@ import scala.jdk.CollectionConverters.* class EsIndexJsonContentService(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexJsonContentService - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -63,14 +63,14 @@ class EsIndexJsonContentService(client: NodeClient, Option(response.getSourceAsMap) match { case Some(map) => val source = map.asScala.toMap.asStringMap - logger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") Right(source) case None => - logger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") + noRequestIdLogger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") Right(Map.empty[String, String]) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(ContentNotFound) } } @@ -78,7 +78,7 @@ class EsIndexJsonContentService(client: NodeClient, .onErrorRecover { case _: ResourceNotFoundException => Left(ContentNotFound) case ex => - logger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) Left(CannotReachContentSource) } } @@ -104,14 +104,14 @@ class EsIndexJsonContentService(client: NodeClient, case status if status / 100 == 2 => Right(()) case status => - logger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") Left(CannotWriteToIndex) } } .executeOn(RorSchedulers.blockingScheduler) .onErrorRecover { case ex => - logger.error(s"Cannot write to document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]", ex) Left(CannotWriteToIndex) } } diff --git a/es83x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala b/es83x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala index 7d15a76306..df7ab14fec 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala @@ -22,7 +22,7 @@ import cats.kernel.Monoid import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task import monix.execution.CancelablePromise -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction.{ResolvedAlias, ResolvedIndex} @@ -63,7 +63,7 @@ class EsServerBasedRorClusterService(nodeName: String, nodeClient: NodeClient, threadPool: ThreadPool) extends RorClusterService - with Logging { + with RequestIdAwareLogging { import EsServerBasedRorClusterService.* @@ -154,7 +154,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractAccessibilityFrom) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify get request. Blocking document", ex) + logger.error(s"Could not verify get request. Blocking document", ex)(id) Inaccessible } } @@ -166,7 +166,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractResultsFromSearchResponse) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify documents returned by multi get response. Blocking all returned documents", ex) + logger.error(s"Could not verify documents returned by multi get response. Blocking all returned documents", ex)(id) blockAllDocsReturned(documents) } .map(results => zip(results, documents)) @@ -275,7 +275,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService): Task[List[FullRemoteDataStreamWithAliases]] = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -331,7 +331,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService) = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -417,7 +417,7 @@ class EsServerBasedRorClusterService(nodeName: String, } } case None => - logger.error("Cannot supply Snapshots Service. Please, report the issue!!!") + noRequestIdLogger.error("Cannot supply Snapshots Service. Please, report the issue!!!") Task.now(Set.empty[Snapshot]) } } diff --git a/es83x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala b/es83x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala index 8f9d4eb4f9..cbb23419d0 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.services import cats.data.NonEmptyList -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.DocWriteRequest import org.elasticsearch.action.bulk.{BackoffPolicy, BulkProcessor, BulkRequest, BulkResponse} import org.elasticsearch.action.index.IndexRequest @@ -40,7 +40,7 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, (using Clock) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { private val bulkProcessor = BulkProcessor @@ -77,25 +77,25 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, private class AuditSinkBulkProcessorListener extends BulkProcessor.Listener { override def beforeBulk(executionId: Long, request: BulkRequest): Unit = { - logger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") + noRequestIdLogger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") } override def afterBulk(executionId: Long, request: BulkRequest, response: BulkResponse): Unit = { if (response.hasFailures) { - logger.error("Some failures flushing the BulkProcessor: ") + noRequestIdLogger.error("Some failures flushing the BulkProcessor: ") response .getItems.to(LazyList) .filter(_.isFailed) .map(_.getFailureMessage) .groupBy(identity) .foreach { case (message, stream) => - logger.error(s"${stream.size}x: $message") + noRequestIdLogger.error(s"${stream.size}x: $message") } } } override def afterBulk(executionId: Long, request: BulkRequest, failure: Throwable): Unit = { - logger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) + noRequestIdLogger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) } } diff --git a/es83x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala b/es83x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala index a8def0ec7a..b3c5593c36 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala @@ -22,7 +22,7 @@ import org.apache.http.auth.{AuthScope, Credentials, UsernamePasswordCredentials import org.apache.http.conn.ssl.NoopHostnameVerifier import org.apache.http.impl.client.BasicCredentialsProvider import org.apache.http.impl.nio.client.HttpAsyncClientBuilder -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.* import org.elasticsearch.client.RestClient.FailureListener import tech.beshu.ror.accesscontrol.audit.sink.AuditDataStreamCreator @@ -38,7 +38,7 @@ import scala.collection.parallel.CollectionConverters.* final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient]) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { override def submit(indexName: IndexName.Full, documentId: String, jsonRecord: String) (implicit requestId: RequestId): Unit = { @@ -77,21 +77,21 @@ final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient] override def onSuccess(response: Response): Unit = { response.getStatusLine.getStatusCode / 100 match { case 2 => // 2xx - logger.debug(s"[${requestId.show}] Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") + logger.debug(s"Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") case _ => - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") } } override def onFailure(ex: Exception): Unit = { - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId]", ex) + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId]", ex) } } override val dataStreamCreator: AuditDataStreamCreator = new AuditDataStreamCreator(clients.map(new RestClientDataStreamService(_))) } -object RestClientAuditSinkService extends Logging { +object RestClientAuditSinkService extends RequestIdAwareLogging { def create(remoteCluster: AuditCluster.RemoteAuditCluster): RestClientAuditSinkService = { remoteCluster.mode match { @@ -122,7 +122,7 @@ object RestClientAuditSinkService extends Logging { .setFailureListener( new FailureListener { override def onFailure(node: Node): Unit = { - logger.debug( + noRequestIdLogger.debug( s"[AUDIT] Node marked dead: ${node.getHost.getSchemeName}://${node.getHost.getHostName}:${node.getHost.getPort}. The client will attempt failover.", ) } diff --git a/es83x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala b/es83x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala index 8ccc1290f3..60908849d5 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.Channel import io.netty.handler.ssl.NotSslRecordException -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.network.NetworkService import org.elasticsearch.common.settings.{ClusterSettings, Settings} import org.elasticsearch.http.netty4.Netty4HttpServerTransport @@ -39,7 +39,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, sharedGroupFactory: SharedGroupFactory, fipsCompliant: Boolean) extends Netty4HttpServerTransport(settings, networkService, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, ssl.clientAuthenticationEnabled) @@ -47,7 +47,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, override def onException(channel: HttpChannel, cause: Exception): Unit = { if (!this.lifecycle.started) return - else if (cause.getCause.isInstanceOf[NotSslRecordException]) logger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) + else if (cause.getCause.isInstanceOf[NotSslRecordException]) noRequestIdLogger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) else super.onException(channel, cause) channel.close() } diff --git a/es83x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala b/es83x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala index f9f71f30b1..e241596351 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.* import io.netty.handler.ssl.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.Version import org.elasticsearch.cluster.node.DiscoveryNode import org.elasticsearch.common.io.stream.NamedWriteableRegistry @@ -45,7 +45,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, sharedGroupFactory: SharedGroupFactory, fipsCompliant: Boolean) extends Netty4Transport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = SSLCertHelper.prepareClientSSLContext(ssl, fipsCompliant, ssl.certificateVerificationEnabled) private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, clientAuthenticationEnabled = false) @@ -76,7 +76,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, override def exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable): Unit = { if (cause.isInstanceOf[NotSslRecordException] || (cause.getCause != null && cause.getCause.isInstanceOf[NotSslRecordException])) { - logger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") + noRequestIdLogger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") ctx.channel.close } else { super.exceptionCaught(ctx, cause) diff --git a/es83x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala b/es83x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala index d206cac4a9..08895e33c4 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.utils import cats.Show import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.client.internal.node.NodeClient import org.elasticsearch.rest.* @@ -37,7 +37,7 @@ import java.util import scala.util.Try class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandler) - extends RestHandler with Logging { + extends RestHandler with RequestIdAwareLogging { private val wrapped = doPrivileged { wrapSomeActions(underlying) @@ -104,11 +104,11 @@ class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandle private def logError(error: AuthorizationValueError): Unit = { { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorSanitizedShow - logger.warn(s"The incoming request was malformed. Cause: ${error.show}") + noRequestIdLogger.warn(s"The incoming request was malformed. Cause: ${error.show}") } if (logger.delegate.isDebugEnabled()) { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorWithDetailsShow - logger.debug(s"Malformed request detailed cause: ${error.show}") + noRequestIdLogger.debug(s"Malformed request detailed cause: ${error.show}") } } diff --git a/es83x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala b/es83x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala index 5ab1e35742..a9af8f710a 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala @@ -16,13 +16,13 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.settings.Settings import tech.beshu.ror.tools.core.patches.PatchingVerifier import tech.beshu.ror.tools.core.patches.PatchingVerifier.Error.{CannotVerifyIfPatched, EsNotPatched} import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -object EsPatchVerifier extends Logging { +object EsPatchVerifier extends RequestIdAwareLogging { def verify(settings: Settings): Unit = doPrivileged { pathHomeFrom(settings).flatMap(PatchingVerifier.verify) match { @@ -30,7 +30,7 @@ object EsPatchVerifier extends Logging { case Left(e@EsNotPatched(_)) => throw new IllegalStateException(e.message) case Left(e@CannotVerifyIfPatched(_)) => - logger.warn(e.message) + noRequestIdLogger.warn(e.message) } } diff --git a/es83x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala b/es83x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala index 639aeb5029..893d807108 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.repositories.{RepositoriesService, VerifyNodeRepositoryAction} import org.elasticsearch.transport.{RemoteClusterService, TransportService} import org.joor.Reflect.on @@ -26,7 +26,7 @@ import java.util.function.Supplier import scala.util.{Failure, Success, Try} class RemoteClusterServiceSupplier(repositoriesServiceSupplier: Supplier[RepositoriesService]) - extends Supplier[Option[RemoteClusterService]] with Logging { + extends Supplier[Option[RemoteClusterService]] with RequestIdAwareLogging { override def get(): Option[RemoteClusterService] = { for { @@ -35,7 +35,7 @@ class RemoteClusterServiceSupplier(repositoriesServiceSupplier: Supplier[Reposit case Success(transportService) => Option(transportService.getRemoteClusterService) case Failure(ex) => - logger.error("Cannot extract RemoteClusterService from RepositoriesService", ex) + noRequestIdLogger.error("Cannot extract RemoteClusterService from RepositoriesService", ex) None } } yield remoteClusterService diff --git a/es84x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es84x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index 1916982621..36ea4c1800 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.support.{ActionFilter, ActionFilterChain} import org.elasticsearch.action.{ActionListener, ActionRequest, ActionResponse} import org.elasticsearch.client.internal.node.NodeClient @@ -62,7 +62,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, rorEsConfig: ReadonlyRestEsConfig) (implicit environmentConfig: EnvironmentConfig) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = environmentConfig.uniqueIdentifierGenerator @@ -212,12 +212,12 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def handleRorNotReadyYet(esContext: EsContext): Unit = { - logger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") + noRequestIdLogger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") rorNotAvailableRequestHandler.handleRorNotReadyYet(esContext) } private def handleRorFailedToStart(esContext: EsContext): Unit = { - logger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") + noRequestIdLogger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") rorNotAvailableRequestHandler.handleRorFailedToStart(esContext) } @@ -239,7 +239,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def logAndSetStartingFailureState(failure: StartingFailure): Unit = { - logger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) + noRequestIdLogger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) rorInstanceState.set(RorInstanceStartingState.NotStarted(failure)) } } diff --git a/es84x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala b/es84x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala index 2533367185..12493c6b08 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.xcontent.LoggingDeprecationHandler import org.elasticsearch.rest.RestResponse import org.elasticsearch.xcontent.{NamedXContentRegistry, XContentBuilder, XContentParserConfiguration, XContentType} @@ -30,7 +30,7 @@ import tech.beshu.ror.accesscontrol.domain.ResponseFieldsFiltering.{AccessMode, import scala.jdk.CollectionConverters.* trait ResponseFieldsFiltering { - this: Logging => + this: RequestIdAwareLogging => private val responseFieldsRestrictions: Atomic[Option[ResponseFieldsRestrictions]] = Atomic(None: Option[ResponseFieldsRestrictions]) diff --git a/es84x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala b/es84x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala index 0f26750588..da95de59a4 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.action.{ActionListener, ActionResponse} import org.elasticsearch.threadpool.ThreadPool @@ -37,7 +37,7 @@ sealed abstract class RorActionListener[T](val underlying: ActionListener[T]) ex final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionListener[T], correlationId: Eval[CorrelationId]) - extends RorActionListener[T](underlying) with Logging { + extends RorActionListener[T](underlying) with RequestIdAwareLogging { override def onFailure(e: Exception): Unit = { super.onFailure(adaptExceptionIfNeeded(e)) @@ -47,7 +47,7 @@ final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionLis ex match { case esException: ElasticsearchException => esException case other => - logger.error(s"[${correlationId.value.show}] Internal error.", other) + noRequestIdLogger.error(s"[${correlationId.value.show}] Internal error.", other) new ElasticsearchException(s"[${correlationId.value.show}] Internal error. See logs for details.") } } diff --git a/es84x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala b/es84x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala index 75048ebe7d..14e5e31c1b 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.http.HttpChannel import org.elasticsearch.rest.{AbstractRestChannel, RestChannel as EsRestChannel, RestRequest as EsRestRequest, RestResponse as EsRestResponse} import squants.information.{Bytes, Information} @@ -40,7 +40,7 @@ object RorRestChannel { final class RorRestChannel private(underlying: EsRestChannel, val restRequest: RorRestRequest) extends AbstractRestChannel(underlying.request(), true) with ResponseFieldsFiltering - with Logging { + with RequestIdAwareLogging { override def sendResponse(response: EsRestResponse): Unit = { ThreadRepo.removeRestChannel(this) diff --git a/es84x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala b/es84x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala index 6babc712b9..3c80750a25 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala @@ -18,16 +18,15 @@ package tech.beshu.ror.es.actions.rradmin import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.ConfigApi.ConfigResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAdminActionHandler extends Logging { +class RRAdminActionHandler extends RequestIdAwareLogging { private implicit val adminRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +51,7 @@ class RRAdminActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAdminResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAdminAction internal error", ex) + logger.error("RRAdminAction internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es84x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala b/es84x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala index c55835a1d0..ce45c6f48e 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala @@ -16,18 +16,15 @@ */ package tech.beshu.ror.es.actions.rrauthmock -import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.AuthMockApi.AuthMockResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier -import tech.beshu.ror.implicits.* +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAuthMockActionHandler extends Logging { +class RRAuthMockActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -53,7 +50,7 @@ class RRAuthMockActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAuthMockResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAuthMock internal error", ex) + logger.error("RRAuthMock internal error", ex) listener.onFailure(new Exception(ex)) } } diff --git a/es84x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala b/es84x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala index aa8bb31e67..640084c4ec 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestconfig import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.TestConfigApi.TestConfigResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestConfigActionHandler extends Logging { +class RRTestConfigActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +52,7 @@ class RRTestConfigActionHandler extends Logging { case Right(response) => listener.onResponse(new RRTestConfigResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRTestConfig internal error", ex) + logger.error(s"RRTestConfig internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es84x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala b/es84x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala index 494e9150b4..98cc0c945d 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.dlsfls import cats.data.StateT import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.DirectoryReader import org.elasticsearch.common.util.concurrent.ThreadContext import org.elasticsearch.core.CheckedFunction @@ -31,7 +31,7 @@ import java.io.IOException import java.util.function.{Function => JavaFunction} import scala.util.{Failure, Success, Try} -object RoleIndexSearcherWrapper extends Logging { +object RoleIndexSearcherWrapper extends RequestIdAwareLogging { val instance: JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] = new JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] { @@ -54,7 +54,7 @@ object RoleIndexSearcherWrapper extends Logging { } .map(r => (r, r)) case None => - logger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") + noRequestIdLogger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") Success((reader, reader)) } } @@ -66,13 +66,13 @@ object RoleIndexSearcherWrapper extends Logging { nel <- NonEmptyString.from(value) match { case Right(nel) => Success(nel) case Left(_) => - logger.debug("FLS: empty header value") + noRequestIdLogger.debug("FLS: empty header value") failure } fields <- transientFieldsFromHeaderValue.fromRawValue(nel) match { case result@Success(_) => result case Failure(ex) => - logger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) + noRequestIdLogger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) failure } } yield fields diff --git a/es84x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala b/es84x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala index ac897184bb..0f785d38fd 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.dlsfls import com.google.common.collect.Iterators -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.codecs.StoredFieldsReader import org.apache.lucene.index.* import org.apache.lucene.index.StoredFieldVisitor.Status @@ -39,21 +39,21 @@ import scala.jdk.CollectionConverters.* import scala.util.Try private class RorDocumentFieldReader(reader: LeafReader, fieldsRestrictions: FieldsRestrictions) - extends SequentialStoredFieldsLeafReader(reader) with Logging { + extends SequentialStoredFieldsLeafReader(reader) with RequestIdAwareLogging { private val policy = new FieldsPolicy(fieldsRestrictions) private val remainingFieldsInfo = { val fInfos = in.getFieldInfos val newInfos = if (fInfos.asScala.isEmpty) { - logger.warn("original fields were empty! This is weird!") + noRequestIdLogger.warn("original fields were empty! This is weird!") fInfos } else { val remainingFields = fInfos.asScala.filter(f => policy.canKeep(f.name)).toSet new FieldInfos(remainingFields.toArray) } - logger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") - logger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") - logger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") + noRequestIdLogger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") newInfos } private val jsonPolicyBasedFilterer = new JsonPolicyBasedFilterer(policy) diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala index 15add4a6dd..a4d939d26a 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.* import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest import org.elasticsearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest @@ -87,7 +87,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, threadPool: ThreadPool) (implicit generator: UniqueIdentifierGenerator, scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle(engines: Engines, esContext: EsContext): Task[Either[Error, Unit]] = { @@ -242,7 +242,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, case SearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case MultiSearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case _ => - logger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") + noRequestIdLogger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") regularRequestHandler.handle(new DummyCompositeIndicesEsRequestContext(request, esContext, aclContext, clusterService, threadPool)) } // rest diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala index cab02aff37..100edd72ac 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.common.io.stream.StreamOutput import org.elasticsearch.xcontent.{ToXContent, ToXContentObject, XContentBuilder} @@ -45,7 +45,7 @@ import scala.util.{Failure, Success, Try} class CurrentUserMetadataRequestHandler(engine: Engine, esContext: EsContext) - extends Logging { + extends RequestIdAwareLogging { def handle(request: RequestContext.Aux[CurrentUserMetadataRequestBlockContext] with EsRequest[CurrentUserMetadataRequestBlockContext]): Task[Unit] = { engine.core.accessControl @@ -69,7 +69,7 @@ class CurrentUserMetadataRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(ex.asInstanceOf[Exception]) } } @@ -86,13 +86,13 @@ class CurrentUserMetadataRequestHandler(engine: Engine, )) } - private def onPassThrough(requestContext: RequestContext): Unit = { - logger.warn(s"[${requestContext.id.toRequestId.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") + private def onPassThrough(implicit requestContext: RequestContext): Unit = { + logger.warn(s"Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") esContext.listener.onFailure(createRorNotEnabledResponse()) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala index 2fb01dcc41..c5c44fda92 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala @@ -20,7 +20,7 @@ import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.RegularRequestResult @@ -49,7 +49,7 @@ class RegularRequestHandler(engine: Engine, esContext: EsContext, threadPool: ThreadPool) (implicit scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle[B <: BlockContext : BlockContextUpdater](request: RequestContext.Aux[B] with EsRequest[B]): Task[Unit] = { engine.core.accessControl @@ -85,7 +85,7 @@ class RegularRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(new Exception(ex)) } } @@ -99,7 +99,7 @@ class RegularRequestHandler(engine: Engine, case ModificationResult.ShouldBeInterrupted => onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case ModificationResult.CannotModify => - logger.error(s"[${request.id.toRequestId.show}] Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") + noRequestIdLogger.error(s"Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case CustomResponse(response) => respond(request, response) @@ -247,7 +247,7 @@ class RegularRequestHandler(engine: Engine, esContext.listener.onResponse(response) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } \ No newline at end of file diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala index f4f832dedc..bfc421bdd5 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.index.query.{AbstractQueryBuilder, QueryBuilder, QueryBuilders} import org.elasticsearch.search.aggregations.AggregatorFactories @@ -40,7 +40,7 @@ import tech.beshu.ror.implicits.* import java.util.UUID import scala.jdk.CollectionConverters.* -object SearchRequestOps extends Logging { +object SearchRequestOps extends RequestIdAwareLogging { implicit class QueryBuilderOps(val builder: Option[QueryBuilder]) extends AnyVal { @@ -52,7 +52,7 @@ object SearchRequestOps extends Logging { val modifiedQuery: AbstractQueryBuilder[_] = provideNewQueryWithAppliedFilter(builder, filterQuery) Some(modifiedQuery) case None => - logger.debug(s"[${requestId.show}] No filter applied to query.") + logger.debug(s"No filter applied to query.") builder } } @@ -92,7 +92,7 @@ object SearchRequestOps extends Logging { case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, requestId) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) disableCaching(requestId) case BasedOnBlockContextOnly.NotAllowedFieldsUsed(notAllowedFields) => modifyNotAllowedFieldsInRequest(notAllowedFields) @@ -138,8 +138,8 @@ object SearchRequestOps extends Logging { } } - private def disableCaching(requestId: RequestContext.Id) = { - logger.debug(s"[${requestId.show}] ACL uses context header for fields rule, will disable request cache for SearchRequest") + private def disableCaching(implicit requestId: RequestContext.Id) = { + logger.debug(s"ACL uses context header for fields rule, will disable request cache for SearchRequest") request.requestCache(false) } } diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala index 270367a54f..e2884598df 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala @@ -17,7 +17,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.action.support.IndicesOptions.WildcardStates import org.elasticsearch.action.{CompositeIndicesRequest, IndicesRequest} @@ -34,7 +33,7 @@ import scala.jdk.CollectionConverters.* abstract class BaseEsRequestContext[B <: BlockContext](esContext: EsContext, clusterService: RorClusterService) - extends RequestContext with Logging { + extends RequestContext { override type BLOCK_CONTEXT = B diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala index ae8abbe1f5..0ee2967364 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala @@ -18,7 +18,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -26,8 +25,9 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import scala.util.Try +import tech.beshu.ror.utils.RequestIdAwareLogging -trait EsRequest[B <: BlockContext] extends Logging { +trait EsRequest[B <: BlockContext] extends RequestIdAwareLogging { implicit def threadPool: ThreadPool final def modifyUsing(blockContext: B): ModificationResult = { @@ -35,7 +35,7 @@ trait EsRequest[B <: BlockContext] extends Logging { Try(modifyRequest(blockContext)) .fold( ex => { - logger.error(s"[${blockContext.requestContext.id.show}] Cannot modify request with filtered data", ex) + logger.error(s"Cannot modify request with filtered data", ex)(blockContext) ModificationResult.CannotModify }, identity diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala index c6a9dcbefd..f773b3efb1 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala @@ -51,7 +51,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest private def discoverDataStreams() = { val dataStreams = dataStreamsFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered data streams: ${dataStreams.show}") + logger.debug(s"Discovered data streams: ${dataStreams.show}") dataStreams } @@ -59,7 +59,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest val backingIndices = backingIndicesFrom(actionRequest) backingIndices match { case BackingIndices.IndicesInvolved(filteredIndices, _) => - logger.debug(s"[${id.show}] Discovered indices: ${filteredIndices.show}") + logger.debug(s"Discovered indices: ${filteredIndices.show}") case BackingIndices.IndicesNotInvolved => } backingIndices diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala index c091179cb6..d150709314 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala @@ -85,7 +85,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: case Some(indices) => update(actionRequest, indices, blockContext.filter, blockContext.fieldLevelSecurity) case None => - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -101,7 +101,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } \ No newline at end of file diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala index 71d462de57..48014e1bdc 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala @@ -73,7 +73,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, } yield update(actionRequest, filteredIndices, allAllowedIndices) result.getOrElse { - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -86,7 +86,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala index 95d882c3b5..f607c0e347 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala @@ -50,7 +50,7 @@ abstract class BaseRepositoriesEsRequestContext[R <: ActionRequest](actionReques case Some(repositories) => update(actionRequest, repositories) case None => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") ShouldBeInterrupted } } diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala index b3b1d66238..7ef0f32014 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala @@ -42,7 +42,7 @@ abstract class BaseSingleIndexEsRequestContext[R <: ActionRequest](actionRequest filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } update(request, filteredIndices.head) } diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala index b5ab70fe7a..c1b2e7ea27 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala @@ -62,7 +62,7 @@ class BulkEsRequestContext(actionRequest: BulkRequest, case (_, _) => ShouldBeInterrupted } } else { - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because origin request contained different " + + logger.error(s"Cannot alter MultiGetRequest request, because origin request contained different " + s"number of requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } @@ -90,18 +90,18 @@ class BulkEsRequestContext(actionRequest: BulkRequest, updateRequestWithIndices(request, nel) Modified case None => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because empty list of indices was found") + logger.error(s"Cannot alter MultiGetRequest request, because empty list of indices was found") ShouldBeInterrupted } case Indices.NotFound => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because no allowed indices were found") + logger.error(s"Cannot alter MultiGetRequest request, because no allowed indices were found") ShouldBeInterrupted } } private def updateRequestWithIndices(request: DocWriteRequest[_], indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } request.index(indices.head.stringify) } diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala index 75a75fcef5..96a043b298 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala @@ -53,14 +53,14 @@ class BulkShardEsRequestContext(actionRequest: BulkShardRequest, case Success(_) => Modified case Failure(ex) => - logger.error(s"[${id.show}] Cannot modify BulkShardRequest", ex) + logger.error(s"Cannot modify BulkShardRequest", ex) CannotModify } } private def tryUpdate(request: BulkShardRequest, indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } val singleIndex = indices.head val uuid = clusterService.indexOrAliasUuids(singleIndex.name).toList.head diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala index 65a168092a..158ac485a5 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala @@ -45,14 +45,14 @@ class ClusterAllocationExplainEsRequestContext(actionRequest: ClusterAllocationE getRequestedIndexFrom(request) match { case Some(_) => if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateIndexIn(request, filteredIndices.head) Modified case None if filteredIndices.exists(_.name === ClusterIndexName.Local.wildcard) => Modified case None => - logger.error(s"[${id.show}] Cluster allocation explain request without index name is unavailable when block contains `indices` rule") + logger.error(s"Cluster allocation explain request without index name is unavailable when block contains `indices` rule") ShouldBeInterrupted } } diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala index 5778b8968d..02dec730ed 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala @@ -66,7 +66,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, updateAliases(actionRequest, aliases) UpdateResponse.sync(updateAliasesResponse(aliases.includedOnly, _)) case None => - logger.error(s"[${id.show}] At least one alias and one index has to be allowed. " + + logger.error(s"At least one alias and one index has to be allowed. " + s"Found allowed indices: [${blockContext.indices.show}]." + s"Found allowed aliases: [${blockContext.aliases.show}]") ShouldBeInterrupted @@ -114,7 +114,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, .indices().asSafeSet .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } @@ -122,7 +122,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, val aliases = rawRequestAliasesSet(request) .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered aliases: ${aliases.show}") + logger.debug(s"Discovered aliases: ${aliases.show}") aliases } diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala index abb85d42b7..f9e2c87e53 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala @@ -55,7 +55,7 @@ class IndicesAliasesEsRequestContext(actionRequest: IndicesAliasesRequest, if (originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala index 05b70606b9..37dd50452b 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala @@ -119,7 +119,7 @@ class MultiGetEsRequestContext(actionRequest: MultiGetRequest, case Nil => updateItemWithNonExistingIndex(item) case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } item.index(index.stringify) } diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala index 989956d79a..9e13edee8d 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala @@ -78,7 +78,7 @@ class MultiSearchEsRequestContext(actionRequest: MultiSearchRequest, } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala index 9191e33b66..5a61356f48 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala @@ -47,7 +47,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { request.getRequests.removeIf { request => removeOrAlter(request, filteredIndices.toCovariantSet) } if (request.getRequests.asScala.isEmpty) { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") ShouldBeInterrupted } else { Modified @@ -63,7 +63,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, true case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") } request.index(index.stringify) false diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala index c411df93c5..c7b99f6e85 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala @@ -52,7 +52,7 @@ class PutRollupJobEsRequestContext private(actionRequest: ActionRequest, if(originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala index 141d9db788..fff8ed58bb 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala @@ -49,7 +49,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (tryUpdate(actionRequest, filteredIndices)) Modified else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") ShouldBeInterrupted } } diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala index 489d0187bc..c42dfc3b78 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala @@ -58,10 +58,10 @@ class ReindexEsRequestContext(actionRequest: ReindexRequest, Modified } else { if (!isDestinationIndexOnFilteredIndicesList) { - logger.info(s"[${id.show}] Destination index of _reindex request is forbidden") + logger.info(s"Destination index of _reindex request is forbidden") } if (!isSearchRequestComposedOnlyOfAllowedIndices) { - logger.info(s"[${id.show}] At least one index from sources indices list of _reindex request is forbidden") + logger.info(s"At least one index from sources indices list of _reindex request is forbidden") } ShouldBeInterrupted } diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala index 2c1b0014e0..97b8ccd9c5 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala @@ -74,7 +74,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo request } case Left(_) => - logger.debug(s"[${id.show}] Cannot parse SQL statement - we can pass it though, because ES is going to reject it") + logger.debug(s"Cannot parse SQL statement - we can pass it though, because ES is going to reject it") request } } @@ -85,7 +85,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala index 0c67384c1e..d7e743e648 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CleanupRepositoryEsRequestContext(actionRequest: CleanupRepositoryRequest, override protected def update(request: CleanupRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala index 44b7d78dfd..d09015139b 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CreateRepositoryEsRequestContext(actionRequest: PutRepositoryRequest, override protected def update(request: PutRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala index eaf9334872..0cf32e1bea 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class DeleteRepositoryEsRequestContext(actionRequest: DeleteRepositoryRequest, override protected def update(request: DeleteRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala index cee0bffd4c..d1410eff3d 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class VerifyRepositoryEsRequestContext(actionRequest: VerifyRepositoryRequest, override protected def update(request: VerifyRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala index ead4fcf250..20501516d5 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala @@ -68,32 +68,32 @@ class CreateSnapshotEsRequestContext(actionRequest: CreateSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala index a56aba660e..621d744767 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala @@ -60,7 +60,7 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -71,14 +71,14 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, .toRight(()) } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala index 22869bbb4f..b81f333174 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala @@ -68,7 +68,7 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, case r => r } case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala index 88887db96c..156deb5b80 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala @@ -63,7 +63,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -75,7 +75,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") } Right(snapshot) } @@ -88,7 +88,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala index 44ee8397ec..e522e440f1 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala @@ -100,12 +100,12 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { val repositories = blockContext.repositories if (allRepositoriesRequested(repositories)) { Right(RepositoryName.All) @@ -115,7 +115,7 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala index 80e36a6d77..d8e5182eed 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.GetComposableIndexTemplateAction import org.elasticsearch.cluster.metadata import org.elasticsearch.cluster.metadata.ComposableIndexTemplate @@ -108,7 +108,7 @@ class GetComposableIndexTemplateEsRequestContext(actionRequest: GetComposableInd } -private[templates] object GetComposableIndexTemplateEsRequestContext extends Logging { +private[templates] object GetComposableIndexTemplateEsRequestContext extends RequestIdAwareLogging { def filter(templates: Map[String, ComposableIndexTemplate], usingTemplate: Set[Template] => Set[Template]) diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala index bd74c3a18f..1c6eecf409 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.{GetIndexTemplatesRequest, GetIndexTemplatesResponse} import org.elasticsearch.cluster.metadata.{AliasMetadata, IndexTemplateMetadata} import org.elasticsearch.common.collect.ImmutableOpenMap @@ -104,7 +104,7 @@ class GetTemplatesEsRequestContext(actionRequest: GetIndexTemplatesRequest, } -private[templates] object GetTemplatesEsRequestContext extends Logging { +private[templates] object GetTemplatesEsRequestContext extends RequestIdAwareLogging { def filter(templates: Iterable[IndexTemplateMetadata], usingTemplate: Set[Template] => Set[Template]) diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala index a8951de5b1..32116d8212 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala @@ -72,7 +72,7 @@ class MultiSearchTemplateEsRequestContext private(actionRequest: ActionRequest w } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala index e6f6d8916e..434787a686 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala @@ -55,7 +55,7 @@ class SimulateIndexTemplateRequestEsRequestContext(actionRequest: SimulateIndexT filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateRequest(request, filteredIndices.head, allAllowedIndices) } diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala index fbc4cf6776..46ed6e7a95 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala @@ -109,7 +109,7 @@ class SimulateExistingTemplateRequestEsRequestContext(existingTemplateName: Temp case Some(_) => updateResponse(namePatterns.toList, blockContext.allAllowedIndices.toList) case None => - logger.info(s"[${id.show}] User has no access to template ${existingTemplateName.show}") + logger.info(s"User has no access to template ${existingTemplateName.show}") ModificationResult.ShouldBeInterrupted } case other => diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala index 0ecd7a72b3..fe4d60bd42 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.queries import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.index.query.* import org.joor.Reflect.on import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.RequestFieldsUsage @@ -30,7 +30,7 @@ trait QueryFieldsUsage[QUERY <: QueryBuilder] { def fieldsIn(query: QUERY): RequestFieldsUsage } -object QueryFieldsUsage extends Logging { +object QueryFieldsUsage extends RequestIdAwareLogging { def apply[QUERY <: QueryBuilder](implicit ev: QueryFieldsUsage[QUERY]): QueryFieldsUsage[QUERY] = ev implicit class Ops[QUERY <: QueryBuilder : QueryFieldsUsage](val query: QUERY) { @@ -62,7 +62,7 @@ object QueryFieldsUsage extends Logging { Option(on(query).call("getFieldName").get[String]) match { case Some(fieldName: String) => UsingFields(NonEmptyList.one(UsedField(fieldName))) case _ => - logger.debug(s"Cannot extract fields for terms set query") + noRequestIdLogger.debug(s"Cannot extract fields for terms set query") CannotExtractFields } } @@ -89,7 +89,7 @@ object QueryFieldsUsage extends Logging { case builder: TermsSetQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder: WildcardQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder => - logger.debug(s"Cannot extract fields for query: ${builder.getName}") + noRequestIdLogger.debug(s"Cannot extract fields for query: ${builder.getName}") CannotExtractFields } diff --git a/es84x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala b/es84x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala index 0998bb9a5b..b4671e9e4d 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.handler.response import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.FieldsRestrictions import tech.beshu.ror.accesscontrol.domain.Header @@ -26,17 +26,17 @@ import tech.beshu.ror.accesscontrol.headerValues.transientFieldsToHeaderValue import tech.beshu.ror.accesscontrol.request.RequestContext import tech.beshu.ror.implicits.* -object FLSContextHeaderHandler extends Logging { +object FLSContextHeaderHandler extends RequestIdAwareLogging { def addContextHeader(threadPool: ThreadPool, - fieldsRestrictions: FieldsRestrictions, - requestId: RequestContext.Id): Unit = { + fieldsRestrictions: FieldsRestrictions) + (implicit requestId: RequestContext.Id): Unit = { val threadContext = threadPool.getThreadContext val header = createContextHeader(fieldsRestrictions) Option(threadContext.getHeader(header.name.value.value)) match { case None => implicit val show = headerShow - logger.debug(s"[${requestId.show}] Adding thread context header required by lucene. Header: '${header.show}'") + logger.debug(s"Adding thread context header required by lucene. Header: '${header.show}'") threadContext.putHeader(header.name.value.value, header.value.value) case Some(_) => } diff --git a/es84x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala b/es84x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala index 629696a91d..7aa2029a2a 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.admin.indices.template.get.{GetComponentTemplateAction, GetComposableIndexTemplateAction} import org.elasticsearch.action.admin.indices.template.put.{PutComponentTemplateAction, PutComposableIndexTemplateAction} @@ -46,7 +46,7 @@ import scala.jdk.CollectionConverters.* final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJsonParserFactory)(using Clock) extends DataStreamService - with Logging { + with RequestIdAwareLogging { override def checkDataStreamExists(dataStreamName: DataStreamName.Full): Task[Boolean] = execute { val request = new GetDataStreamAction.Request(List(dataStreamName.value.value).toArray) @@ -203,11 +203,11 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ response <- Task.measure( task = Task.delay(nodeClient.execute(action, request).actionGet()), logTimeMeasurement = duration => Task.delay { - logger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") + noRequestIdLogger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") } ) _ <- Task.delay { - logger.debug(s"Action ${action.name()} response: ${response.toString}") + noRequestIdLogger.debug(s"Action ${action.name()} response: ${response.toString}") } } yield response } @@ -215,7 +215,7 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ def executeAck[REQUEST <: ActionRequest, RESPONSE <: AcknowledgedResponse](action: ActionType[RESPONSE], request: REQUEST): Task[RESPONSE] = { executeT(action, request) - .tapEval(response => Task.delay(logger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) + .tapEval(response => Task.delay(noRequestIdLogger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) } private def supportedActions: Map[ActionType[ActionResponse], TransportAction[ActionRequest, ActionResponse]] = { diff --git a/es84x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala b/es84x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala index 2e75d37d0f..16259474bf 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.support.WriteRequest.RefreshPolicy import org.elasticsearch.client.internal.node.NodeClient @@ -38,7 +38,7 @@ import scala.jdk.CollectionConverters.* class EsIndexJsonContentService(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexJsonContentService - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -63,14 +63,14 @@ class EsIndexJsonContentService(client: NodeClient, Option(response.getSourceAsMap) match { case Some(map) => val source = map.asScala.toMap.asStringMap - logger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") Right(source) case None => - logger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") + noRequestIdLogger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") Right(Map.empty[String, String]) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(ContentNotFound) } } @@ -78,7 +78,7 @@ class EsIndexJsonContentService(client: NodeClient, .onErrorRecover { case _: ResourceNotFoundException => Left(ContentNotFound) case ex => - logger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) Left(CannotReachContentSource) } } @@ -104,14 +104,14 @@ class EsIndexJsonContentService(client: NodeClient, case status if status / 100 == 2 => Right(()) case status => - logger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") Left(CannotWriteToIndex) } } .executeOn(RorSchedulers.blockingScheduler) .onErrorRecover { case ex => - logger.error(s"Cannot write to document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]", ex) Left(CannotWriteToIndex) } } diff --git a/es84x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala b/es84x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala index 7d15a76306..df7ab14fec 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala @@ -22,7 +22,7 @@ import cats.kernel.Monoid import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task import monix.execution.CancelablePromise -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction.{ResolvedAlias, ResolvedIndex} @@ -63,7 +63,7 @@ class EsServerBasedRorClusterService(nodeName: String, nodeClient: NodeClient, threadPool: ThreadPool) extends RorClusterService - with Logging { + with RequestIdAwareLogging { import EsServerBasedRorClusterService.* @@ -154,7 +154,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractAccessibilityFrom) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify get request. Blocking document", ex) + logger.error(s"Could not verify get request. Blocking document", ex)(id) Inaccessible } } @@ -166,7 +166,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractResultsFromSearchResponse) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify documents returned by multi get response. Blocking all returned documents", ex) + logger.error(s"Could not verify documents returned by multi get response. Blocking all returned documents", ex)(id) blockAllDocsReturned(documents) } .map(results => zip(results, documents)) @@ -275,7 +275,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService): Task[List[FullRemoteDataStreamWithAliases]] = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -331,7 +331,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService) = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -417,7 +417,7 @@ class EsServerBasedRorClusterService(nodeName: String, } } case None => - logger.error("Cannot supply Snapshots Service. Please, report the issue!!!") + noRequestIdLogger.error("Cannot supply Snapshots Service. Please, report the issue!!!") Task.now(Set.empty[Snapshot]) } } diff --git a/es84x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala b/es84x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala index 8f9d4eb4f9..cbb23419d0 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.services import cats.data.NonEmptyList -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.DocWriteRequest import org.elasticsearch.action.bulk.{BackoffPolicy, BulkProcessor, BulkRequest, BulkResponse} import org.elasticsearch.action.index.IndexRequest @@ -40,7 +40,7 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, (using Clock) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { private val bulkProcessor = BulkProcessor @@ -77,25 +77,25 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, private class AuditSinkBulkProcessorListener extends BulkProcessor.Listener { override def beforeBulk(executionId: Long, request: BulkRequest): Unit = { - logger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") + noRequestIdLogger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") } override def afterBulk(executionId: Long, request: BulkRequest, response: BulkResponse): Unit = { if (response.hasFailures) { - logger.error("Some failures flushing the BulkProcessor: ") + noRequestIdLogger.error("Some failures flushing the BulkProcessor: ") response .getItems.to(LazyList) .filter(_.isFailed) .map(_.getFailureMessage) .groupBy(identity) .foreach { case (message, stream) => - logger.error(s"${stream.size}x: $message") + noRequestIdLogger.error(s"${stream.size}x: $message") } } } override def afterBulk(executionId: Long, request: BulkRequest, failure: Throwable): Unit = { - logger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) + noRequestIdLogger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) } } diff --git a/es84x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala b/es84x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala index a8def0ec7a..b3c5593c36 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala @@ -22,7 +22,7 @@ import org.apache.http.auth.{AuthScope, Credentials, UsernamePasswordCredentials import org.apache.http.conn.ssl.NoopHostnameVerifier import org.apache.http.impl.client.BasicCredentialsProvider import org.apache.http.impl.nio.client.HttpAsyncClientBuilder -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.* import org.elasticsearch.client.RestClient.FailureListener import tech.beshu.ror.accesscontrol.audit.sink.AuditDataStreamCreator @@ -38,7 +38,7 @@ import scala.collection.parallel.CollectionConverters.* final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient]) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { override def submit(indexName: IndexName.Full, documentId: String, jsonRecord: String) (implicit requestId: RequestId): Unit = { @@ -77,21 +77,21 @@ final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient] override def onSuccess(response: Response): Unit = { response.getStatusLine.getStatusCode / 100 match { case 2 => // 2xx - logger.debug(s"[${requestId.show}] Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") + logger.debug(s"Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") case _ => - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") } } override def onFailure(ex: Exception): Unit = { - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId]", ex) + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId]", ex) } } override val dataStreamCreator: AuditDataStreamCreator = new AuditDataStreamCreator(clients.map(new RestClientDataStreamService(_))) } -object RestClientAuditSinkService extends Logging { +object RestClientAuditSinkService extends RequestIdAwareLogging { def create(remoteCluster: AuditCluster.RemoteAuditCluster): RestClientAuditSinkService = { remoteCluster.mode match { @@ -122,7 +122,7 @@ object RestClientAuditSinkService extends Logging { .setFailureListener( new FailureListener { override def onFailure(node: Node): Unit = { - logger.debug( + noRequestIdLogger.debug( s"[AUDIT] Node marked dead: ${node.getHost.getSchemeName}://${node.getHost.getHostName}:${node.getHost.getPort}. The client will attempt failover.", ) } diff --git a/es84x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala b/es84x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala index 5631d98c22..729ab73cda 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.Channel import io.netty.handler.ssl.NotSslRecordException -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.network.NetworkService import org.elasticsearch.common.settings.{ClusterSettings, Settings} import org.elasticsearch.http.netty4.Netty4HttpServerTransport @@ -41,7 +41,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, tracer: Tracer, fipsCompliant: Boolean) extends Netty4HttpServerTransport(settings, networkService, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory, tracer) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, ssl.clientAuthenticationEnabled) @@ -49,7 +49,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, override def onException(channel: HttpChannel, cause: Exception): Unit = { if (!this.lifecycle.started) return - else if (cause.getCause.isInstanceOf[NotSslRecordException]) logger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) + else if (cause.getCause.isInstanceOf[NotSslRecordException]) noRequestIdLogger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) else super.onException(channel, cause) channel.close() } diff --git a/es84x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala b/es84x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala index f9f71f30b1..e241596351 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.* import io.netty.handler.ssl.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.Version import org.elasticsearch.cluster.node.DiscoveryNode import org.elasticsearch.common.io.stream.NamedWriteableRegistry @@ -45,7 +45,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, sharedGroupFactory: SharedGroupFactory, fipsCompliant: Boolean) extends Netty4Transport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = SSLCertHelper.prepareClientSSLContext(ssl, fipsCompliant, ssl.certificateVerificationEnabled) private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, clientAuthenticationEnabled = false) @@ -76,7 +76,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, override def exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable): Unit = { if (cause.isInstanceOf[NotSslRecordException] || (cause.getCause != null && cause.getCause.isInstanceOf[NotSslRecordException])) { - logger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") + noRequestIdLogger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") ctx.channel.close } else { super.exceptionCaught(ctx, cause) diff --git a/es84x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala b/es84x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala index 2e997a741f..80d11fa6f5 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.utils import cats.Show import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.client.internal.node.NodeClient import org.elasticsearch.rest.* @@ -37,7 +37,7 @@ import java.util import scala.util.Try class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandler) - extends RestHandler with Logging { + extends RestHandler with RequestIdAwareLogging { private val wrapped = doPrivileged { wrapSomeActions(underlying) @@ -104,11 +104,11 @@ class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandle private def logError(error: AuthorizationValueError): Unit = { { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorSanitizedShow - logger.warn(s"The incoming request was malformed. Cause: ${error.show}") + noRequestIdLogger.warn(s"The incoming request was malformed. Cause: ${error.show}") } if (logger.delegate.isDebugEnabled()) { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorWithDetailsShow - logger.debug(s"Malformed request detailed cause: ${error.show}") + noRequestIdLogger.debug(s"Malformed request detailed cause: ${error.show}") } } diff --git a/es84x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala b/es84x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala index 5ab1e35742..a9af8f710a 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala @@ -16,13 +16,13 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.settings.Settings import tech.beshu.ror.tools.core.patches.PatchingVerifier import tech.beshu.ror.tools.core.patches.PatchingVerifier.Error.{CannotVerifyIfPatched, EsNotPatched} import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -object EsPatchVerifier extends Logging { +object EsPatchVerifier extends RequestIdAwareLogging { def verify(settings: Settings): Unit = doPrivileged { pathHomeFrom(settings).flatMap(PatchingVerifier.verify) match { @@ -30,7 +30,7 @@ object EsPatchVerifier extends Logging { case Left(e@EsNotPatched(_)) => throw new IllegalStateException(e.message) case Left(e@CannotVerifyIfPatched(_)) => - logger.warn(e.message) + noRequestIdLogger.warn(e.message) } } diff --git a/es84x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala b/es84x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala index 639aeb5029..893d807108 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.repositories.{RepositoriesService, VerifyNodeRepositoryAction} import org.elasticsearch.transport.{RemoteClusterService, TransportService} import org.joor.Reflect.on @@ -26,7 +26,7 @@ import java.util.function.Supplier import scala.util.{Failure, Success, Try} class RemoteClusterServiceSupplier(repositoriesServiceSupplier: Supplier[RepositoriesService]) - extends Supplier[Option[RemoteClusterService]] with Logging { + extends Supplier[Option[RemoteClusterService]] with RequestIdAwareLogging { override def get(): Option[RemoteClusterService] = { for { @@ -35,7 +35,7 @@ class RemoteClusterServiceSupplier(repositoriesServiceSupplier: Supplier[Reposit case Success(transportService) => Option(transportService.getRemoteClusterService) case Failure(ex) => - logger.error("Cannot extract RemoteClusterService from RepositoriesService", ex) + noRequestIdLogger.error("Cannot extract RemoteClusterService from RepositoriesService", ex) None } } yield remoteClusterService diff --git a/es85x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es85x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index 07d70bbf05..978eebec5d 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.support.{ActionFilter, ActionFilterChain} import org.elasticsearch.action.{ActionListener, ActionRequest, ActionResponse} import org.elasticsearch.client.internal.node.NodeClient @@ -62,7 +62,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, rorEsConfig: ReadonlyRestEsConfig) (implicit environmentConfig: EnvironmentConfig) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = environmentConfig.uniqueIdentifierGenerator @@ -211,12 +211,12 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def handleRorNotReadyYet(esContext: EsContext): Unit = { - logger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") + noRequestIdLogger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") rorNotAvailableRequestHandler.handleRorNotReadyYet(esContext) } private def handleRorFailedToStart(esContext: EsContext): Unit = { - logger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") + noRequestIdLogger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") rorNotAvailableRequestHandler.handleRorFailedToStart(esContext) } @@ -238,7 +238,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def logAndSetStartingFailureState(failure: StartingFailure): Unit = { - logger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) + noRequestIdLogger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) rorInstanceState.set(RorInstanceStartingState.NotStarted(failure)) } } diff --git a/es85x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala b/es85x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala index 1fb22fc79d..53452eb8e6 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.xcontent.LoggingDeprecationHandler import org.elasticsearch.rest.RestResponse import org.elasticsearch.transport.BytesRefRecycler @@ -32,7 +32,7 @@ import tech.beshu.ror.accesscontrol.domain.ResponseFieldsFiltering.{AccessMode, import scala.jdk.CollectionConverters.* trait ResponseFieldsFiltering { - this: Logging => + this: RequestIdAwareLogging => private val responseFieldsRestrictions: Atomic[Option[ResponseFieldsRestrictions]] = Atomic(None: Option[ResponseFieldsRestrictions]) diff --git a/es85x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala b/es85x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala index 0f26750588..da95de59a4 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.action.{ActionListener, ActionResponse} import org.elasticsearch.threadpool.ThreadPool @@ -37,7 +37,7 @@ sealed abstract class RorActionListener[T](val underlying: ActionListener[T]) ex final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionListener[T], correlationId: Eval[CorrelationId]) - extends RorActionListener[T](underlying) with Logging { + extends RorActionListener[T](underlying) with RequestIdAwareLogging { override def onFailure(e: Exception): Unit = { super.onFailure(adaptExceptionIfNeeded(e)) @@ -47,7 +47,7 @@ final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionLis ex match { case esException: ElasticsearchException => esException case other => - logger.error(s"[${correlationId.value.show}] Internal error.", other) + noRequestIdLogger.error(s"[${correlationId.value.show}] Internal error.", other) new ElasticsearchException(s"[${correlationId.value.show}] Internal error. See logs for details.") } } diff --git a/es85x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala b/es85x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala index 75048ebe7d..14e5e31c1b 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.http.HttpChannel import org.elasticsearch.rest.{AbstractRestChannel, RestChannel as EsRestChannel, RestRequest as EsRestRequest, RestResponse as EsRestResponse} import squants.information.{Bytes, Information} @@ -40,7 +40,7 @@ object RorRestChannel { final class RorRestChannel private(underlying: EsRestChannel, val restRequest: RorRestRequest) extends AbstractRestChannel(underlying.request(), true) with ResponseFieldsFiltering - with Logging { + with RequestIdAwareLogging { override def sendResponse(response: EsRestResponse): Unit = { ThreadRepo.removeRestChannel(this) diff --git a/es85x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala b/es85x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala index 6babc712b9..3c80750a25 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala @@ -18,16 +18,15 @@ package tech.beshu.ror.es.actions.rradmin import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.ConfigApi.ConfigResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAdminActionHandler extends Logging { +class RRAdminActionHandler extends RequestIdAwareLogging { private implicit val adminRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +51,7 @@ class RRAdminActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAdminResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAdminAction internal error", ex) + logger.error("RRAdminAction internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es85x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala b/es85x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala index c55835a1d0..ce45c6f48e 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala @@ -16,18 +16,15 @@ */ package tech.beshu.ror.es.actions.rrauthmock -import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.AuthMockApi.AuthMockResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier -import tech.beshu.ror.implicits.* +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAuthMockActionHandler extends Logging { +class RRAuthMockActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -53,7 +50,7 @@ class RRAuthMockActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAuthMockResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAuthMock internal error", ex) + logger.error("RRAuthMock internal error", ex) listener.onFailure(new Exception(ex)) } } diff --git a/es85x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala b/es85x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala index aa8bb31e67..640084c4ec 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestconfig import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.TestConfigApi.TestConfigResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestConfigActionHandler extends Logging { +class RRTestConfigActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +52,7 @@ class RRTestConfigActionHandler extends Logging { case Right(response) => listener.onResponse(new RRTestConfigResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRTestConfig internal error", ex) + logger.error(s"RRTestConfig internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es85x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala b/es85x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala index 494e9150b4..98cc0c945d 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.dlsfls import cats.data.StateT import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.DirectoryReader import org.elasticsearch.common.util.concurrent.ThreadContext import org.elasticsearch.core.CheckedFunction @@ -31,7 +31,7 @@ import java.io.IOException import java.util.function.{Function => JavaFunction} import scala.util.{Failure, Success, Try} -object RoleIndexSearcherWrapper extends Logging { +object RoleIndexSearcherWrapper extends RequestIdAwareLogging { val instance: JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] = new JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] { @@ -54,7 +54,7 @@ object RoleIndexSearcherWrapper extends Logging { } .map(r => (r, r)) case None => - logger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") + noRequestIdLogger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") Success((reader, reader)) } } @@ -66,13 +66,13 @@ object RoleIndexSearcherWrapper extends Logging { nel <- NonEmptyString.from(value) match { case Right(nel) => Success(nel) case Left(_) => - logger.debug("FLS: empty header value") + noRequestIdLogger.debug("FLS: empty header value") failure } fields <- transientFieldsFromHeaderValue.fromRawValue(nel) match { case result@Success(_) => result case Failure(ex) => - logger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) + noRequestIdLogger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) failure } } yield fields diff --git a/es85x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala b/es85x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala index ac897184bb..0f785d38fd 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.dlsfls import com.google.common.collect.Iterators -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.codecs.StoredFieldsReader import org.apache.lucene.index.* import org.apache.lucene.index.StoredFieldVisitor.Status @@ -39,21 +39,21 @@ import scala.jdk.CollectionConverters.* import scala.util.Try private class RorDocumentFieldReader(reader: LeafReader, fieldsRestrictions: FieldsRestrictions) - extends SequentialStoredFieldsLeafReader(reader) with Logging { + extends SequentialStoredFieldsLeafReader(reader) with RequestIdAwareLogging { private val policy = new FieldsPolicy(fieldsRestrictions) private val remainingFieldsInfo = { val fInfos = in.getFieldInfos val newInfos = if (fInfos.asScala.isEmpty) { - logger.warn("original fields were empty! This is weird!") + noRequestIdLogger.warn("original fields were empty! This is weird!") fInfos } else { val remainingFields = fInfos.asScala.filter(f => policy.canKeep(f.name)).toSet new FieldInfos(remainingFields.toArray) } - logger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") - logger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") - logger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") + noRequestIdLogger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") newInfos } private val jsonPolicyBasedFilterer = new JsonPolicyBasedFilterer(policy) diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala index 15add4a6dd..a4d939d26a 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.* import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest import org.elasticsearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest @@ -87,7 +87,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, threadPool: ThreadPool) (implicit generator: UniqueIdentifierGenerator, scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle(engines: Engines, esContext: EsContext): Task[Either[Error, Unit]] = { @@ -242,7 +242,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, case SearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case MultiSearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case _ => - logger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") + noRequestIdLogger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") regularRequestHandler.handle(new DummyCompositeIndicesEsRequestContext(request, esContext, aclContext, clusterService, threadPool)) } // rest diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala index cab02aff37..100edd72ac 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.common.io.stream.StreamOutput import org.elasticsearch.xcontent.{ToXContent, ToXContentObject, XContentBuilder} @@ -45,7 +45,7 @@ import scala.util.{Failure, Success, Try} class CurrentUserMetadataRequestHandler(engine: Engine, esContext: EsContext) - extends Logging { + extends RequestIdAwareLogging { def handle(request: RequestContext.Aux[CurrentUserMetadataRequestBlockContext] with EsRequest[CurrentUserMetadataRequestBlockContext]): Task[Unit] = { engine.core.accessControl @@ -69,7 +69,7 @@ class CurrentUserMetadataRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(ex.asInstanceOf[Exception]) } } @@ -86,13 +86,13 @@ class CurrentUserMetadataRequestHandler(engine: Engine, )) } - private def onPassThrough(requestContext: RequestContext): Unit = { - logger.warn(s"[${requestContext.id.toRequestId.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") + private def onPassThrough(implicit requestContext: RequestContext): Unit = { + logger.warn(s"Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") esContext.listener.onFailure(createRorNotEnabledResponse()) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala index 2fb01dcc41..c5c44fda92 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala @@ -20,7 +20,7 @@ import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.RegularRequestResult @@ -49,7 +49,7 @@ class RegularRequestHandler(engine: Engine, esContext: EsContext, threadPool: ThreadPool) (implicit scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle[B <: BlockContext : BlockContextUpdater](request: RequestContext.Aux[B] with EsRequest[B]): Task[Unit] = { engine.core.accessControl @@ -85,7 +85,7 @@ class RegularRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(new Exception(ex)) } } @@ -99,7 +99,7 @@ class RegularRequestHandler(engine: Engine, case ModificationResult.ShouldBeInterrupted => onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case ModificationResult.CannotModify => - logger.error(s"[${request.id.toRequestId.show}] Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") + noRequestIdLogger.error(s"Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case CustomResponse(response) => respond(request, response) @@ -247,7 +247,7 @@ class RegularRequestHandler(engine: Engine, esContext.listener.onResponse(response) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } \ No newline at end of file diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala index f4f832dedc..bfc421bdd5 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.index.query.{AbstractQueryBuilder, QueryBuilder, QueryBuilders} import org.elasticsearch.search.aggregations.AggregatorFactories @@ -40,7 +40,7 @@ import tech.beshu.ror.implicits.* import java.util.UUID import scala.jdk.CollectionConverters.* -object SearchRequestOps extends Logging { +object SearchRequestOps extends RequestIdAwareLogging { implicit class QueryBuilderOps(val builder: Option[QueryBuilder]) extends AnyVal { @@ -52,7 +52,7 @@ object SearchRequestOps extends Logging { val modifiedQuery: AbstractQueryBuilder[_] = provideNewQueryWithAppliedFilter(builder, filterQuery) Some(modifiedQuery) case None => - logger.debug(s"[${requestId.show}] No filter applied to query.") + logger.debug(s"No filter applied to query.") builder } } @@ -92,7 +92,7 @@ object SearchRequestOps extends Logging { case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, requestId) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) disableCaching(requestId) case BasedOnBlockContextOnly.NotAllowedFieldsUsed(notAllowedFields) => modifyNotAllowedFieldsInRequest(notAllowedFields) @@ -138,8 +138,8 @@ object SearchRequestOps extends Logging { } } - private def disableCaching(requestId: RequestContext.Id) = { - logger.debug(s"[${requestId.show}] ACL uses context header for fields rule, will disable request cache for SearchRequest") + private def disableCaching(implicit requestId: RequestContext.Id) = { + logger.debug(s"ACL uses context header for fields rule, will disable request cache for SearchRequest") request.requestCache(false) } } diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala index 270367a54f..e2884598df 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala @@ -17,7 +17,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.action.support.IndicesOptions.WildcardStates import org.elasticsearch.action.{CompositeIndicesRequest, IndicesRequest} @@ -34,7 +33,7 @@ import scala.jdk.CollectionConverters.* abstract class BaseEsRequestContext[B <: BlockContext](esContext: EsContext, clusterService: RorClusterService) - extends RequestContext with Logging { + extends RequestContext { override type BLOCK_CONTEXT = B diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala index ae8abbe1f5..0ee2967364 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala @@ -18,7 +18,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -26,8 +25,9 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import scala.util.Try +import tech.beshu.ror.utils.RequestIdAwareLogging -trait EsRequest[B <: BlockContext] extends Logging { +trait EsRequest[B <: BlockContext] extends RequestIdAwareLogging { implicit def threadPool: ThreadPool final def modifyUsing(blockContext: B): ModificationResult = { @@ -35,7 +35,7 @@ trait EsRequest[B <: BlockContext] extends Logging { Try(modifyRequest(blockContext)) .fold( ex => { - logger.error(s"[${blockContext.requestContext.id.show}] Cannot modify request with filtered data", ex) + logger.error(s"Cannot modify request with filtered data", ex)(blockContext) ModificationResult.CannotModify }, identity diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala index c6a9dcbefd..f773b3efb1 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala @@ -51,7 +51,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest private def discoverDataStreams() = { val dataStreams = dataStreamsFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered data streams: ${dataStreams.show}") + logger.debug(s"Discovered data streams: ${dataStreams.show}") dataStreams } @@ -59,7 +59,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest val backingIndices = backingIndicesFrom(actionRequest) backingIndices match { case BackingIndices.IndicesInvolved(filteredIndices, _) => - logger.debug(s"[${id.show}] Discovered indices: ${filteredIndices.show}") + logger.debug(s"Discovered indices: ${filteredIndices.show}") case BackingIndices.IndicesNotInvolved => } backingIndices diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala index c091179cb6..d150709314 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala @@ -85,7 +85,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: case Some(indices) => update(actionRequest, indices, blockContext.filter, blockContext.fieldLevelSecurity) case None => - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -101,7 +101,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } \ No newline at end of file diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala index 71d462de57..48014e1bdc 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala @@ -73,7 +73,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, } yield update(actionRequest, filteredIndices, allAllowedIndices) result.getOrElse { - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -86,7 +86,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala index 95d882c3b5..f607c0e347 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala @@ -50,7 +50,7 @@ abstract class BaseRepositoriesEsRequestContext[R <: ActionRequest](actionReques case Some(repositories) => update(actionRequest, repositories) case None => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") ShouldBeInterrupted } } diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala index b3b1d66238..7ef0f32014 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala @@ -42,7 +42,7 @@ abstract class BaseSingleIndexEsRequestContext[R <: ActionRequest](actionRequest filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } update(request, filteredIndices.head) } diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala index b5ab70fe7a..c1b2e7ea27 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala @@ -62,7 +62,7 @@ class BulkEsRequestContext(actionRequest: BulkRequest, case (_, _) => ShouldBeInterrupted } } else { - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because origin request contained different " + + logger.error(s"Cannot alter MultiGetRequest request, because origin request contained different " + s"number of requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } @@ -90,18 +90,18 @@ class BulkEsRequestContext(actionRequest: BulkRequest, updateRequestWithIndices(request, nel) Modified case None => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because empty list of indices was found") + logger.error(s"Cannot alter MultiGetRequest request, because empty list of indices was found") ShouldBeInterrupted } case Indices.NotFound => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because no allowed indices were found") + logger.error(s"Cannot alter MultiGetRequest request, because no allowed indices were found") ShouldBeInterrupted } } private def updateRequestWithIndices(request: DocWriteRequest[_], indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } request.index(indices.head.stringify) } diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala index 75a75fcef5..96a043b298 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala @@ -53,14 +53,14 @@ class BulkShardEsRequestContext(actionRequest: BulkShardRequest, case Success(_) => Modified case Failure(ex) => - logger.error(s"[${id.show}] Cannot modify BulkShardRequest", ex) + logger.error(s"Cannot modify BulkShardRequest", ex) CannotModify } } private def tryUpdate(request: BulkShardRequest, indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } val singleIndex = indices.head val uuid = clusterService.indexOrAliasUuids(singleIndex.name).toList.head diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala index 65a168092a..158ac485a5 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala @@ -45,14 +45,14 @@ class ClusterAllocationExplainEsRequestContext(actionRequest: ClusterAllocationE getRequestedIndexFrom(request) match { case Some(_) => if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateIndexIn(request, filteredIndices.head) Modified case None if filteredIndices.exists(_.name === ClusterIndexName.Local.wildcard) => Modified case None => - logger.error(s"[${id.show}] Cluster allocation explain request without index name is unavailable when block contains `indices` rule") + logger.error(s"Cluster allocation explain request without index name is unavailable when block contains `indices` rule") ShouldBeInterrupted } } diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala index 5778b8968d..02dec730ed 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala @@ -66,7 +66,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, updateAliases(actionRequest, aliases) UpdateResponse.sync(updateAliasesResponse(aliases.includedOnly, _)) case None => - logger.error(s"[${id.show}] At least one alias and one index has to be allowed. " + + logger.error(s"At least one alias and one index has to be allowed. " + s"Found allowed indices: [${blockContext.indices.show}]." + s"Found allowed aliases: [${blockContext.aliases.show}]") ShouldBeInterrupted @@ -114,7 +114,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, .indices().asSafeSet .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } @@ -122,7 +122,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, val aliases = rawRequestAliasesSet(request) .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered aliases: ${aliases.show}") + logger.debug(s"Discovered aliases: ${aliases.show}") aliases } diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala index abb85d42b7..f9e2c87e53 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala @@ -55,7 +55,7 @@ class IndicesAliasesEsRequestContext(actionRequest: IndicesAliasesRequest, if (originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala index 05b70606b9..37dd50452b 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala @@ -119,7 +119,7 @@ class MultiGetEsRequestContext(actionRequest: MultiGetRequest, case Nil => updateItemWithNonExistingIndex(item) case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } item.index(index.stringify) } diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala index 989956d79a..9e13edee8d 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala @@ -78,7 +78,7 @@ class MultiSearchEsRequestContext(actionRequest: MultiSearchRequest, } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala index 9191e33b66..5a61356f48 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala @@ -47,7 +47,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { request.getRequests.removeIf { request => removeOrAlter(request, filteredIndices.toCovariantSet) } if (request.getRequests.asScala.isEmpty) { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") ShouldBeInterrupted } else { Modified @@ -63,7 +63,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, true case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") } request.index(index.stringify) false diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala index c411df93c5..c7b99f6e85 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala @@ -52,7 +52,7 @@ class PutRollupJobEsRequestContext private(actionRequest: ActionRequest, if(originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala index 141d9db788..fff8ed58bb 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala @@ -49,7 +49,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (tryUpdate(actionRequest, filteredIndices)) Modified else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") ShouldBeInterrupted } } diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala index 489d0187bc..c42dfc3b78 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala @@ -58,10 +58,10 @@ class ReindexEsRequestContext(actionRequest: ReindexRequest, Modified } else { if (!isDestinationIndexOnFilteredIndicesList) { - logger.info(s"[${id.show}] Destination index of _reindex request is forbidden") + logger.info(s"Destination index of _reindex request is forbidden") } if (!isSearchRequestComposedOnlyOfAllowedIndices) { - logger.info(s"[${id.show}] At least one index from sources indices list of _reindex request is forbidden") + logger.info(s"At least one index from sources indices list of _reindex request is forbidden") } ShouldBeInterrupted } diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala index 2c1b0014e0..97b8ccd9c5 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala @@ -74,7 +74,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo request } case Left(_) => - logger.debug(s"[${id.show}] Cannot parse SQL statement - we can pass it though, because ES is going to reject it") + logger.debug(s"Cannot parse SQL statement - we can pass it though, because ES is going to reject it") request } } @@ -85,7 +85,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala index 0c67384c1e..d7e743e648 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CleanupRepositoryEsRequestContext(actionRequest: CleanupRepositoryRequest, override protected def update(request: CleanupRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala index 44b7d78dfd..d09015139b 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CreateRepositoryEsRequestContext(actionRequest: PutRepositoryRequest, override protected def update(request: PutRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala index eaf9334872..0cf32e1bea 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class DeleteRepositoryEsRequestContext(actionRequest: DeleteRepositoryRequest, override protected def update(request: DeleteRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala index cee0bffd4c..d1410eff3d 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class VerifyRepositoryEsRequestContext(actionRequest: VerifyRepositoryRequest, override protected def update(request: VerifyRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala index ead4fcf250..20501516d5 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala @@ -68,32 +68,32 @@ class CreateSnapshotEsRequestContext(actionRequest: CreateSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala index a56aba660e..621d744767 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala @@ -60,7 +60,7 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -71,14 +71,14 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, .toRight(()) } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala index 22869bbb4f..b81f333174 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala @@ -68,7 +68,7 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, case r => r } case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala index 88887db96c..156deb5b80 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala @@ -63,7 +63,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -75,7 +75,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") } Right(snapshot) } @@ -88,7 +88,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala index 44ee8397ec..e522e440f1 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala @@ -100,12 +100,12 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { val repositories = blockContext.repositories if (allRepositoriesRequested(repositories)) { Right(RepositoryName.All) @@ -115,7 +115,7 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala index 80e36a6d77..d8e5182eed 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.GetComposableIndexTemplateAction import org.elasticsearch.cluster.metadata import org.elasticsearch.cluster.metadata.ComposableIndexTemplate @@ -108,7 +108,7 @@ class GetComposableIndexTemplateEsRequestContext(actionRequest: GetComposableInd } -private[templates] object GetComposableIndexTemplateEsRequestContext extends Logging { +private[templates] object GetComposableIndexTemplateEsRequestContext extends RequestIdAwareLogging { def filter(templates: Map[String, ComposableIndexTemplate], usingTemplate: Set[Template] => Set[Template]) diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala index bd74c3a18f..1c6eecf409 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.{GetIndexTemplatesRequest, GetIndexTemplatesResponse} import org.elasticsearch.cluster.metadata.{AliasMetadata, IndexTemplateMetadata} import org.elasticsearch.common.collect.ImmutableOpenMap @@ -104,7 +104,7 @@ class GetTemplatesEsRequestContext(actionRequest: GetIndexTemplatesRequest, } -private[templates] object GetTemplatesEsRequestContext extends Logging { +private[templates] object GetTemplatesEsRequestContext extends RequestIdAwareLogging { def filter(templates: Iterable[IndexTemplateMetadata], usingTemplate: Set[Template] => Set[Template]) diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala index a8951de5b1..32116d8212 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala @@ -72,7 +72,7 @@ class MultiSearchTemplateEsRequestContext private(actionRequest: ActionRequest w } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala index e6f6d8916e..434787a686 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala @@ -55,7 +55,7 @@ class SimulateIndexTemplateRequestEsRequestContext(actionRequest: SimulateIndexT filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateRequest(request, filteredIndices.head, allAllowedIndices) } diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala index fbc4cf6776..46ed6e7a95 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala @@ -109,7 +109,7 @@ class SimulateExistingTemplateRequestEsRequestContext(existingTemplateName: Temp case Some(_) => updateResponse(namePatterns.toList, blockContext.allAllowedIndices.toList) case None => - logger.info(s"[${id.show}] User has no access to template ${existingTemplateName.show}") + logger.info(s"User has no access to template ${existingTemplateName.show}") ModificationResult.ShouldBeInterrupted } case other => diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala index 0ecd7a72b3..fe4d60bd42 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.queries import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.index.query.* import org.joor.Reflect.on import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.RequestFieldsUsage @@ -30,7 +30,7 @@ trait QueryFieldsUsage[QUERY <: QueryBuilder] { def fieldsIn(query: QUERY): RequestFieldsUsage } -object QueryFieldsUsage extends Logging { +object QueryFieldsUsage extends RequestIdAwareLogging { def apply[QUERY <: QueryBuilder](implicit ev: QueryFieldsUsage[QUERY]): QueryFieldsUsage[QUERY] = ev implicit class Ops[QUERY <: QueryBuilder : QueryFieldsUsage](val query: QUERY) { @@ -62,7 +62,7 @@ object QueryFieldsUsage extends Logging { Option(on(query).call("getFieldName").get[String]) match { case Some(fieldName: String) => UsingFields(NonEmptyList.one(UsedField(fieldName))) case _ => - logger.debug(s"Cannot extract fields for terms set query") + noRequestIdLogger.debug(s"Cannot extract fields for terms set query") CannotExtractFields } } @@ -89,7 +89,7 @@ object QueryFieldsUsage extends Logging { case builder: TermsSetQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder: WildcardQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder => - logger.debug(s"Cannot extract fields for query: ${builder.getName}") + noRequestIdLogger.debug(s"Cannot extract fields for query: ${builder.getName}") CannotExtractFields } diff --git a/es85x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala b/es85x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala index 0998bb9a5b..b4671e9e4d 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.handler.response import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.FieldsRestrictions import tech.beshu.ror.accesscontrol.domain.Header @@ -26,17 +26,17 @@ import tech.beshu.ror.accesscontrol.headerValues.transientFieldsToHeaderValue import tech.beshu.ror.accesscontrol.request.RequestContext import tech.beshu.ror.implicits.* -object FLSContextHeaderHandler extends Logging { +object FLSContextHeaderHandler extends RequestIdAwareLogging { def addContextHeader(threadPool: ThreadPool, - fieldsRestrictions: FieldsRestrictions, - requestId: RequestContext.Id): Unit = { + fieldsRestrictions: FieldsRestrictions) + (implicit requestId: RequestContext.Id): Unit = { val threadContext = threadPool.getThreadContext val header = createContextHeader(fieldsRestrictions) Option(threadContext.getHeader(header.name.value.value)) match { case None => implicit val show = headerShow - logger.debug(s"[${requestId.show}] Adding thread context header required by lucene. Header: '${header.show}'") + logger.debug(s"Adding thread context header required by lucene. Header: '${header.show}'") threadContext.putHeader(header.name.value.value, header.value.value) case Some(_) => } diff --git a/es85x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala b/es85x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala index 629696a91d..7aa2029a2a 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.admin.indices.template.get.{GetComponentTemplateAction, GetComposableIndexTemplateAction} import org.elasticsearch.action.admin.indices.template.put.{PutComponentTemplateAction, PutComposableIndexTemplateAction} @@ -46,7 +46,7 @@ import scala.jdk.CollectionConverters.* final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJsonParserFactory)(using Clock) extends DataStreamService - with Logging { + with RequestIdAwareLogging { override def checkDataStreamExists(dataStreamName: DataStreamName.Full): Task[Boolean] = execute { val request = new GetDataStreamAction.Request(List(dataStreamName.value.value).toArray) @@ -203,11 +203,11 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ response <- Task.measure( task = Task.delay(nodeClient.execute(action, request).actionGet()), logTimeMeasurement = duration => Task.delay { - logger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") + noRequestIdLogger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") } ) _ <- Task.delay { - logger.debug(s"Action ${action.name()} response: ${response.toString}") + noRequestIdLogger.debug(s"Action ${action.name()} response: ${response.toString}") } } yield response } @@ -215,7 +215,7 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ def executeAck[REQUEST <: ActionRequest, RESPONSE <: AcknowledgedResponse](action: ActionType[RESPONSE], request: REQUEST): Task[RESPONSE] = { executeT(action, request) - .tapEval(response => Task.delay(logger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) + .tapEval(response => Task.delay(noRequestIdLogger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) } private def supportedActions: Map[ActionType[ActionResponse], TransportAction[ActionRequest, ActionResponse]] = { diff --git a/es85x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala b/es85x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala index 2e75d37d0f..16259474bf 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.support.WriteRequest.RefreshPolicy import org.elasticsearch.client.internal.node.NodeClient @@ -38,7 +38,7 @@ import scala.jdk.CollectionConverters.* class EsIndexJsonContentService(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexJsonContentService - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -63,14 +63,14 @@ class EsIndexJsonContentService(client: NodeClient, Option(response.getSourceAsMap) match { case Some(map) => val source = map.asScala.toMap.asStringMap - logger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") Right(source) case None => - logger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") + noRequestIdLogger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") Right(Map.empty[String, String]) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(ContentNotFound) } } @@ -78,7 +78,7 @@ class EsIndexJsonContentService(client: NodeClient, .onErrorRecover { case _: ResourceNotFoundException => Left(ContentNotFound) case ex => - logger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) Left(CannotReachContentSource) } } @@ -104,14 +104,14 @@ class EsIndexJsonContentService(client: NodeClient, case status if status / 100 == 2 => Right(()) case status => - logger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") Left(CannotWriteToIndex) } } .executeOn(RorSchedulers.blockingScheduler) .onErrorRecover { case ex => - logger.error(s"Cannot write to document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]", ex) Left(CannotWriteToIndex) } } diff --git a/es85x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala b/es85x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala index 7d15a76306..df7ab14fec 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala @@ -22,7 +22,7 @@ import cats.kernel.Monoid import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task import monix.execution.CancelablePromise -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction.{ResolvedAlias, ResolvedIndex} @@ -63,7 +63,7 @@ class EsServerBasedRorClusterService(nodeName: String, nodeClient: NodeClient, threadPool: ThreadPool) extends RorClusterService - with Logging { + with RequestIdAwareLogging { import EsServerBasedRorClusterService.* @@ -154,7 +154,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractAccessibilityFrom) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify get request. Blocking document", ex) + logger.error(s"Could not verify get request. Blocking document", ex)(id) Inaccessible } } @@ -166,7 +166,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractResultsFromSearchResponse) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify documents returned by multi get response. Blocking all returned documents", ex) + logger.error(s"Could not verify documents returned by multi get response. Blocking all returned documents", ex)(id) blockAllDocsReturned(documents) } .map(results => zip(results, documents)) @@ -275,7 +275,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService): Task[List[FullRemoteDataStreamWithAliases]] = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -331,7 +331,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService) = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -417,7 +417,7 @@ class EsServerBasedRorClusterService(nodeName: String, } } case None => - logger.error("Cannot supply Snapshots Service. Please, report the issue!!!") + noRequestIdLogger.error("Cannot supply Snapshots Service. Please, report the issue!!!") Task.now(Set.empty[Snapshot]) } } diff --git a/es85x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala b/es85x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala index a657d15ca9..31d96f15a2 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.services import cats.data.NonEmptyList -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.bulk.{BackoffPolicy, BulkProcessor, BulkRequest, BulkResponse} import org.elasticsearch.action.index.IndexRequest import org.elasticsearch.action.{ActionListener, DocWriteRequest} @@ -39,7 +39,7 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, (using Clock) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { private val bulkProcessor = BulkProcessor @@ -80,25 +80,25 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, private class AuditSinkBulkProcessorListener extends BulkProcessor.Listener { override def beforeBulk(executionId: Long, request: BulkRequest): Unit = { - logger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") + noRequestIdLogger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") } override def afterBulk(executionId: Long, request: BulkRequest, response: BulkResponse): Unit = { if (response.hasFailures) { - logger.error("Some failures flushing the BulkProcessor: ") + noRequestIdLogger.error("Some failures flushing the BulkProcessor: ") response .getItems.to(LazyList) .filter(_.isFailed) .map(_.getFailureMessage) .groupBy(identity) .foreach { case (message, stream) => - logger.error(s"${stream.size}x: $message") + noRequestIdLogger.error(s"${stream.size}x: $message") } } } override def afterBulk(executionId: Long, request: BulkRequest, failure: Throwable): Unit = { - logger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) + noRequestIdLogger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) } } diff --git a/es85x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala b/es85x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala index a8def0ec7a..b3c5593c36 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala @@ -22,7 +22,7 @@ import org.apache.http.auth.{AuthScope, Credentials, UsernamePasswordCredentials import org.apache.http.conn.ssl.NoopHostnameVerifier import org.apache.http.impl.client.BasicCredentialsProvider import org.apache.http.impl.nio.client.HttpAsyncClientBuilder -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.* import org.elasticsearch.client.RestClient.FailureListener import tech.beshu.ror.accesscontrol.audit.sink.AuditDataStreamCreator @@ -38,7 +38,7 @@ import scala.collection.parallel.CollectionConverters.* final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient]) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { override def submit(indexName: IndexName.Full, documentId: String, jsonRecord: String) (implicit requestId: RequestId): Unit = { @@ -77,21 +77,21 @@ final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient] override def onSuccess(response: Response): Unit = { response.getStatusLine.getStatusCode / 100 match { case 2 => // 2xx - logger.debug(s"[${requestId.show}] Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") + logger.debug(s"Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") case _ => - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") } } override def onFailure(ex: Exception): Unit = { - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId]", ex) + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId]", ex) } } override val dataStreamCreator: AuditDataStreamCreator = new AuditDataStreamCreator(clients.map(new RestClientDataStreamService(_))) } -object RestClientAuditSinkService extends Logging { +object RestClientAuditSinkService extends RequestIdAwareLogging { def create(remoteCluster: AuditCluster.RemoteAuditCluster): RestClientAuditSinkService = { remoteCluster.mode match { @@ -122,7 +122,7 @@ object RestClientAuditSinkService extends Logging { .setFailureListener( new FailureListener { override def onFailure(node: Node): Unit = { - logger.debug( + noRequestIdLogger.debug( s"[AUDIT] Node marked dead: ${node.getHost.getSchemeName}://${node.getHost.getHostName}:${node.getHost.getPort}. The client will attempt failover.", ) } diff --git a/es85x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala b/es85x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala index 5631d98c22..729ab73cda 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.Channel import io.netty.handler.ssl.NotSslRecordException -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.network.NetworkService import org.elasticsearch.common.settings.{ClusterSettings, Settings} import org.elasticsearch.http.netty4.Netty4HttpServerTransport @@ -41,7 +41,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, tracer: Tracer, fipsCompliant: Boolean) extends Netty4HttpServerTransport(settings, networkService, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory, tracer) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, ssl.clientAuthenticationEnabled) @@ -49,7 +49,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, override def onException(channel: HttpChannel, cause: Exception): Unit = { if (!this.lifecycle.started) return - else if (cause.getCause.isInstanceOf[NotSslRecordException]) logger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) + else if (cause.getCause.isInstanceOf[NotSslRecordException]) noRequestIdLogger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) else super.onException(channel, cause) channel.close() } diff --git a/es85x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala b/es85x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala index f9f71f30b1..e241596351 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.* import io.netty.handler.ssl.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.Version import org.elasticsearch.cluster.node.DiscoveryNode import org.elasticsearch.common.io.stream.NamedWriteableRegistry @@ -45,7 +45,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, sharedGroupFactory: SharedGroupFactory, fipsCompliant: Boolean) extends Netty4Transport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = SSLCertHelper.prepareClientSSLContext(ssl, fipsCompliant, ssl.certificateVerificationEnabled) private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, clientAuthenticationEnabled = false) @@ -76,7 +76,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, override def exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable): Unit = { if (cause.isInstanceOf[NotSslRecordException] || (cause.getCause != null && cause.getCause.isInstanceOf[NotSslRecordException])) { - logger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") + noRequestIdLogger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") ctx.channel.close } else { super.exceptionCaught(ctx, cause) diff --git a/es85x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala b/es85x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala index 2e997a741f..80d11fa6f5 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.utils import cats.Show import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.client.internal.node.NodeClient import org.elasticsearch.rest.* @@ -37,7 +37,7 @@ import java.util import scala.util.Try class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandler) - extends RestHandler with Logging { + extends RestHandler with RequestIdAwareLogging { private val wrapped = doPrivileged { wrapSomeActions(underlying) @@ -104,11 +104,11 @@ class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandle private def logError(error: AuthorizationValueError): Unit = { { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorSanitizedShow - logger.warn(s"The incoming request was malformed. Cause: ${error.show}") + noRequestIdLogger.warn(s"The incoming request was malformed. Cause: ${error.show}") } if (logger.delegate.isDebugEnabled()) { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorWithDetailsShow - logger.debug(s"Malformed request detailed cause: ${error.show}") + noRequestIdLogger.debug(s"Malformed request detailed cause: ${error.show}") } } diff --git a/es85x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala b/es85x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala index 5ab1e35742..a9af8f710a 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala @@ -16,13 +16,13 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.settings.Settings import tech.beshu.ror.tools.core.patches.PatchingVerifier import tech.beshu.ror.tools.core.patches.PatchingVerifier.Error.{CannotVerifyIfPatched, EsNotPatched} import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -object EsPatchVerifier extends Logging { +object EsPatchVerifier extends RequestIdAwareLogging { def verify(settings: Settings): Unit = doPrivileged { pathHomeFrom(settings).flatMap(PatchingVerifier.verify) match { @@ -30,7 +30,7 @@ object EsPatchVerifier extends Logging { case Left(e@EsNotPatched(_)) => throw new IllegalStateException(e.message) case Left(e@CannotVerifyIfPatched(_)) => - logger.warn(e.message) + noRequestIdLogger.warn(e.message) } } diff --git a/es85x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala b/es85x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala index 639aeb5029..893d807108 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.repositories.{RepositoriesService, VerifyNodeRepositoryAction} import org.elasticsearch.transport.{RemoteClusterService, TransportService} import org.joor.Reflect.on @@ -26,7 +26,7 @@ import java.util.function.Supplier import scala.util.{Failure, Success, Try} class RemoteClusterServiceSupplier(repositoriesServiceSupplier: Supplier[RepositoriesService]) - extends Supplier[Option[RemoteClusterService]] with Logging { + extends Supplier[Option[RemoteClusterService]] with RequestIdAwareLogging { override def get(): Option[RemoteClusterService] = { for { @@ -35,7 +35,7 @@ class RemoteClusterServiceSupplier(repositoriesServiceSupplier: Supplier[Reposit case Success(transportService) => Option(transportService.getRemoteClusterService) case Failure(ex) => - logger.error("Cannot extract RemoteClusterService from RepositoriesService", ex) + noRequestIdLogger.error("Cannot extract RemoteClusterService from RepositoriesService", ex) None } } yield remoteClusterService diff --git a/es87x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es87x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index 07d70bbf05..978eebec5d 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.support.{ActionFilter, ActionFilterChain} import org.elasticsearch.action.{ActionListener, ActionRequest, ActionResponse} import org.elasticsearch.client.internal.node.NodeClient @@ -62,7 +62,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, rorEsConfig: ReadonlyRestEsConfig) (implicit environmentConfig: EnvironmentConfig) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = environmentConfig.uniqueIdentifierGenerator @@ -211,12 +211,12 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def handleRorNotReadyYet(esContext: EsContext): Unit = { - logger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") + noRequestIdLogger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") rorNotAvailableRequestHandler.handleRorNotReadyYet(esContext) } private def handleRorFailedToStart(esContext: EsContext): Unit = { - logger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") + noRequestIdLogger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") rorNotAvailableRequestHandler.handleRorFailedToStart(esContext) } @@ -238,7 +238,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def logAndSetStartingFailureState(failure: StartingFailure): Unit = { - logger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) + noRequestIdLogger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) rorInstanceState.set(RorInstanceStartingState.NotStarted(failure)) } } diff --git a/es87x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala b/es87x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala index 1fb22fc79d..53452eb8e6 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.xcontent.LoggingDeprecationHandler import org.elasticsearch.rest.RestResponse import org.elasticsearch.transport.BytesRefRecycler @@ -32,7 +32,7 @@ import tech.beshu.ror.accesscontrol.domain.ResponseFieldsFiltering.{AccessMode, import scala.jdk.CollectionConverters.* trait ResponseFieldsFiltering { - this: Logging => + this: RequestIdAwareLogging => private val responseFieldsRestrictions: Atomic[Option[ResponseFieldsRestrictions]] = Atomic(None: Option[ResponseFieldsRestrictions]) diff --git a/es87x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala b/es87x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala index 0f26750588..da95de59a4 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.action.{ActionListener, ActionResponse} import org.elasticsearch.threadpool.ThreadPool @@ -37,7 +37,7 @@ sealed abstract class RorActionListener[T](val underlying: ActionListener[T]) ex final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionListener[T], correlationId: Eval[CorrelationId]) - extends RorActionListener[T](underlying) with Logging { + extends RorActionListener[T](underlying) with RequestIdAwareLogging { override def onFailure(e: Exception): Unit = { super.onFailure(adaptExceptionIfNeeded(e)) @@ -47,7 +47,7 @@ final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionLis ex match { case esException: ElasticsearchException => esException case other => - logger.error(s"[${correlationId.value.show}] Internal error.", other) + noRequestIdLogger.error(s"[${correlationId.value.show}] Internal error.", other) new ElasticsearchException(s"[${correlationId.value.show}] Internal error. See logs for details.") } } diff --git a/es87x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala b/es87x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala index 75048ebe7d..14e5e31c1b 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.http.HttpChannel import org.elasticsearch.rest.{AbstractRestChannel, RestChannel as EsRestChannel, RestRequest as EsRestRequest, RestResponse as EsRestResponse} import squants.information.{Bytes, Information} @@ -40,7 +40,7 @@ object RorRestChannel { final class RorRestChannel private(underlying: EsRestChannel, val restRequest: RorRestRequest) extends AbstractRestChannel(underlying.request(), true) with ResponseFieldsFiltering - with Logging { + with RequestIdAwareLogging { override def sendResponse(response: EsRestResponse): Unit = { ThreadRepo.removeRestChannel(this) diff --git a/es87x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala b/es87x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala index 6babc712b9..3c80750a25 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala @@ -18,16 +18,15 @@ package tech.beshu.ror.es.actions.rradmin import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.ConfigApi.ConfigResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAdminActionHandler extends Logging { +class RRAdminActionHandler extends RequestIdAwareLogging { private implicit val adminRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +51,7 @@ class RRAdminActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAdminResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAdminAction internal error", ex) + logger.error("RRAdminAction internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es87x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala b/es87x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala index c55835a1d0..ce45c6f48e 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala @@ -16,18 +16,15 @@ */ package tech.beshu.ror.es.actions.rrauthmock -import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.AuthMockApi.AuthMockResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier -import tech.beshu.ror.implicits.* +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAuthMockActionHandler extends Logging { +class RRAuthMockActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -53,7 +50,7 @@ class RRAuthMockActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAuthMockResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAuthMock internal error", ex) + logger.error("RRAuthMock internal error", ex) listener.onFailure(new Exception(ex)) } } diff --git a/es87x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala b/es87x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala index aa8bb31e67..640084c4ec 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestconfig import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.TestConfigApi.TestConfigResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestConfigActionHandler extends Logging { +class RRTestConfigActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +52,7 @@ class RRTestConfigActionHandler extends Logging { case Right(response) => listener.onResponse(new RRTestConfigResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRTestConfig internal error", ex) + logger.error(s"RRTestConfig internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es87x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala b/es87x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala index 494e9150b4..98cc0c945d 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.dlsfls import cats.data.StateT import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.DirectoryReader import org.elasticsearch.common.util.concurrent.ThreadContext import org.elasticsearch.core.CheckedFunction @@ -31,7 +31,7 @@ import java.io.IOException import java.util.function.{Function => JavaFunction} import scala.util.{Failure, Success, Try} -object RoleIndexSearcherWrapper extends Logging { +object RoleIndexSearcherWrapper extends RequestIdAwareLogging { val instance: JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] = new JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] { @@ -54,7 +54,7 @@ object RoleIndexSearcherWrapper extends Logging { } .map(r => (r, r)) case None => - logger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") + noRequestIdLogger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") Success((reader, reader)) } } @@ -66,13 +66,13 @@ object RoleIndexSearcherWrapper extends Logging { nel <- NonEmptyString.from(value) match { case Right(nel) => Success(nel) case Left(_) => - logger.debug("FLS: empty header value") + noRequestIdLogger.debug("FLS: empty header value") failure } fields <- transientFieldsFromHeaderValue.fromRawValue(nel) match { case result@Success(_) => result case Failure(ex) => - logger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) + noRequestIdLogger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) failure } } yield fields diff --git a/es87x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala b/es87x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala index ce77d77f4e..aeccbfcead 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.dlsfls import com.google.common.collect.Iterators -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.codecs.StoredFieldsReader import org.apache.lucene.index.* import org.apache.lucene.index.StoredFieldVisitor.Status @@ -39,21 +39,21 @@ import scala.jdk.CollectionConverters.* import scala.util.Try private class RorDocumentFieldReader(reader: LeafReader, fieldsRestrictions: FieldsRestrictions) - extends SequentialStoredFieldsLeafReader(reader) with Logging { + extends SequentialStoredFieldsLeafReader(reader) with RequestIdAwareLogging { private val policy = new FieldsPolicy(fieldsRestrictions) private val remainingFieldsInfo = { val fInfos = in.getFieldInfos val newInfos = if (fInfos.asScala.isEmpty) { - logger.warn("original fields were empty! This is weird!") + noRequestIdLogger.warn("original fields were empty! This is weird!") fInfos } else { val remainingFields = fInfos.asScala.filter(f => policy.canKeep(f.name)).toSet new FieldInfos(remainingFields.toArray) } - logger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") - logger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") - logger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") + noRequestIdLogger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") newInfos } private val jsonPolicyBasedFilterer = new JsonPolicyBasedFilterer(policy) diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala index 15add4a6dd..a4d939d26a 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.* import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest import org.elasticsearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest @@ -87,7 +87,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, threadPool: ThreadPool) (implicit generator: UniqueIdentifierGenerator, scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle(engines: Engines, esContext: EsContext): Task[Either[Error, Unit]] = { @@ -242,7 +242,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, case SearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case MultiSearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case _ => - logger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") + noRequestIdLogger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") regularRequestHandler.handle(new DummyCompositeIndicesEsRequestContext(request, esContext, aclContext, clusterService, threadPool)) } // rest diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala index cab02aff37..100edd72ac 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.common.io.stream.StreamOutput import org.elasticsearch.xcontent.{ToXContent, ToXContentObject, XContentBuilder} @@ -45,7 +45,7 @@ import scala.util.{Failure, Success, Try} class CurrentUserMetadataRequestHandler(engine: Engine, esContext: EsContext) - extends Logging { + extends RequestIdAwareLogging { def handle(request: RequestContext.Aux[CurrentUserMetadataRequestBlockContext] with EsRequest[CurrentUserMetadataRequestBlockContext]): Task[Unit] = { engine.core.accessControl @@ -69,7 +69,7 @@ class CurrentUserMetadataRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(ex.asInstanceOf[Exception]) } } @@ -86,13 +86,13 @@ class CurrentUserMetadataRequestHandler(engine: Engine, )) } - private def onPassThrough(requestContext: RequestContext): Unit = { - logger.warn(s"[${requestContext.id.toRequestId.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") + private def onPassThrough(implicit requestContext: RequestContext): Unit = { + logger.warn(s"Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") esContext.listener.onFailure(createRorNotEnabledResponse()) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala index 2fb01dcc41..c5c44fda92 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala @@ -20,7 +20,7 @@ import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.RegularRequestResult @@ -49,7 +49,7 @@ class RegularRequestHandler(engine: Engine, esContext: EsContext, threadPool: ThreadPool) (implicit scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle[B <: BlockContext : BlockContextUpdater](request: RequestContext.Aux[B] with EsRequest[B]): Task[Unit] = { engine.core.accessControl @@ -85,7 +85,7 @@ class RegularRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(new Exception(ex)) } } @@ -99,7 +99,7 @@ class RegularRequestHandler(engine: Engine, case ModificationResult.ShouldBeInterrupted => onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case ModificationResult.CannotModify => - logger.error(s"[${request.id.toRequestId.show}] Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") + noRequestIdLogger.error(s"Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case CustomResponse(response) => respond(request, response) @@ -247,7 +247,7 @@ class RegularRequestHandler(engine: Engine, esContext.listener.onResponse(response) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } \ No newline at end of file diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala index f4f832dedc..bfc421bdd5 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.index.query.{AbstractQueryBuilder, QueryBuilder, QueryBuilders} import org.elasticsearch.search.aggregations.AggregatorFactories @@ -40,7 +40,7 @@ import tech.beshu.ror.implicits.* import java.util.UUID import scala.jdk.CollectionConverters.* -object SearchRequestOps extends Logging { +object SearchRequestOps extends RequestIdAwareLogging { implicit class QueryBuilderOps(val builder: Option[QueryBuilder]) extends AnyVal { @@ -52,7 +52,7 @@ object SearchRequestOps extends Logging { val modifiedQuery: AbstractQueryBuilder[_] = provideNewQueryWithAppliedFilter(builder, filterQuery) Some(modifiedQuery) case None => - logger.debug(s"[${requestId.show}] No filter applied to query.") + logger.debug(s"No filter applied to query.") builder } } @@ -92,7 +92,7 @@ object SearchRequestOps extends Logging { case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, requestId) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) disableCaching(requestId) case BasedOnBlockContextOnly.NotAllowedFieldsUsed(notAllowedFields) => modifyNotAllowedFieldsInRequest(notAllowedFields) @@ -138,8 +138,8 @@ object SearchRequestOps extends Logging { } } - private def disableCaching(requestId: RequestContext.Id) = { - logger.debug(s"[${requestId.show}] ACL uses context header for fields rule, will disable request cache for SearchRequest") + private def disableCaching(implicit requestId: RequestContext.Id) = { + logger.debug(s"ACL uses context header for fields rule, will disable request cache for SearchRequest") request.requestCache(false) } } diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala index 270367a54f..e2884598df 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala @@ -17,7 +17,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.action.support.IndicesOptions.WildcardStates import org.elasticsearch.action.{CompositeIndicesRequest, IndicesRequest} @@ -34,7 +33,7 @@ import scala.jdk.CollectionConverters.* abstract class BaseEsRequestContext[B <: BlockContext](esContext: EsContext, clusterService: RorClusterService) - extends RequestContext with Logging { + extends RequestContext { override type BLOCK_CONTEXT = B diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala index ae8abbe1f5..0ee2967364 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala @@ -18,7 +18,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -26,8 +25,9 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import scala.util.Try +import tech.beshu.ror.utils.RequestIdAwareLogging -trait EsRequest[B <: BlockContext] extends Logging { +trait EsRequest[B <: BlockContext] extends RequestIdAwareLogging { implicit def threadPool: ThreadPool final def modifyUsing(blockContext: B): ModificationResult = { @@ -35,7 +35,7 @@ trait EsRequest[B <: BlockContext] extends Logging { Try(modifyRequest(blockContext)) .fold( ex => { - logger.error(s"[${blockContext.requestContext.id.show}] Cannot modify request with filtered data", ex) + logger.error(s"Cannot modify request with filtered data", ex)(blockContext) ModificationResult.CannotModify }, identity diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala index c6a9dcbefd..f773b3efb1 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala @@ -51,7 +51,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest private def discoverDataStreams() = { val dataStreams = dataStreamsFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered data streams: ${dataStreams.show}") + logger.debug(s"Discovered data streams: ${dataStreams.show}") dataStreams } @@ -59,7 +59,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest val backingIndices = backingIndicesFrom(actionRequest) backingIndices match { case BackingIndices.IndicesInvolved(filteredIndices, _) => - logger.debug(s"[${id.show}] Discovered indices: ${filteredIndices.show}") + logger.debug(s"Discovered indices: ${filteredIndices.show}") case BackingIndices.IndicesNotInvolved => } backingIndices diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala index c091179cb6..d150709314 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala @@ -85,7 +85,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: case Some(indices) => update(actionRequest, indices, blockContext.filter, blockContext.fieldLevelSecurity) case None => - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -101,7 +101,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } \ No newline at end of file diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala index 71d462de57..48014e1bdc 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala @@ -73,7 +73,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, } yield update(actionRequest, filteredIndices, allAllowedIndices) result.getOrElse { - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -86,7 +86,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala index 95d882c3b5..f607c0e347 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala @@ -50,7 +50,7 @@ abstract class BaseRepositoriesEsRequestContext[R <: ActionRequest](actionReques case Some(repositories) => update(actionRequest, repositories) case None => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") ShouldBeInterrupted } } diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala index b3b1d66238..7ef0f32014 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala @@ -42,7 +42,7 @@ abstract class BaseSingleIndexEsRequestContext[R <: ActionRequest](actionRequest filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } update(request, filteredIndices.head) } diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala index b5ab70fe7a..c1b2e7ea27 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala @@ -62,7 +62,7 @@ class BulkEsRequestContext(actionRequest: BulkRequest, case (_, _) => ShouldBeInterrupted } } else { - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because origin request contained different " + + logger.error(s"Cannot alter MultiGetRequest request, because origin request contained different " + s"number of requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } @@ -90,18 +90,18 @@ class BulkEsRequestContext(actionRequest: BulkRequest, updateRequestWithIndices(request, nel) Modified case None => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because empty list of indices was found") + logger.error(s"Cannot alter MultiGetRequest request, because empty list of indices was found") ShouldBeInterrupted } case Indices.NotFound => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because no allowed indices were found") + logger.error(s"Cannot alter MultiGetRequest request, because no allowed indices were found") ShouldBeInterrupted } } private def updateRequestWithIndices(request: DocWriteRequest[_], indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } request.index(indices.head.stringify) } diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala index 75a75fcef5..96a043b298 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala @@ -53,14 +53,14 @@ class BulkShardEsRequestContext(actionRequest: BulkShardRequest, case Success(_) => Modified case Failure(ex) => - logger.error(s"[${id.show}] Cannot modify BulkShardRequest", ex) + logger.error(s"Cannot modify BulkShardRequest", ex) CannotModify } } private def tryUpdate(request: BulkShardRequest, indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } val singleIndex = indices.head val uuid = clusterService.indexOrAliasUuids(singleIndex.name).toList.head diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala index 65a168092a..158ac485a5 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala @@ -45,14 +45,14 @@ class ClusterAllocationExplainEsRequestContext(actionRequest: ClusterAllocationE getRequestedIndexFrom(request) match { case Some(_) => if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateIndexIn(request, filteredIndices.head) Modified case None if filteredIndices.exists(_.name === ClusterIndexName.Local.wildcard) => Modified case None => - logger.error(s"[${id.show}] Cluster allocation explain request without index name is unavailable when block contains `indices` rule") + logger.error(s"Cluster allocation explain request without index name is unavailable when block contains `indices` rule") ShouldBeInterrupted } } diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala index 5778b8968d..02dec730ed 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala @@ -66,7 +66,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, updateAliases(actionRequest, aliases) UpdateResponse.sync(updateAliasesResponse(aliases.includedOnly, _)) case None => - logger.error(s"[${id.show}] At least one alias and one index has to be allowed. " + + logger.error(s"At least one alias and one index has to be allowed. " + s"Found allowed indices: [${blockContext.indices.show}]." + s"Found allowed aliases: [${blockContext.aliases.show}]") ShouldBeInterrupted @@ -114,7 +114,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, .indices().asSafeSet .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } @@ -122,7 +122,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, val aliases = rawRequestAliasesSet(request) .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered aliases: ${aliases.show}") + logger.debug(s"Discovered aliases: ${aliases.show}") aliases } diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala index abb85d42b7..f9e2c87e53 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala @@ -55,7 +55,7 @@ class IndicesAliasesEsRequestContext(actionRequest: IndicesAliasesRequest, if (originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala index 05b70606b9..37dd50452b 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala @@ -119,7 +119,7 @@ class MultiGetEsRequestContext(actionRequest: MultiGetRequest, case Nil => updateItemWithNonExistingIndex(item) case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } item.index(index.stringify) } diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala index 989956d79a..9e13edee8d 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala @@ -78,7 +78,7 @@ class MultiSearchEsRequestContext(actionRequest: MultiSearchRequest, } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala index 9191e33b66..5a61356f48 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala @@ -47,7 +47,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { request.getRequests.removeIf { request => removeOrAlter(request, filteredIndices.toCovariantSet) } if (request.getRequests.asScala.isEmpty) { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") ShouldBeInterrupted } else { Modified @@ -63,7 +63,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, true case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") } request.index(index.stringify) false diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala index c411df93c5..c7b99f6e85 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala @@ -52,7 +52,7 @@ class PutRollupJobEsRequestContext private(actionRequest: ActionRequest, if(originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala index 141d9db788..fff8ed58bb 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala @@ -49,7 +49,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (tryUpdate(actionRequest, filteredIndices)) Modified else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") ShouldBeInterrupted } } diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala index 489d0187bc..c42dfc3b78 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala @@ -58,10 +58,10 @@ class ReindexEsRequestContext(actionRequest: ReindexRequest, Modified } else { if (!isDestinationIndexOnFilteredIndicesList) { - logger.info(s"[${id.show}] Destination index of _reindex request is forbidden") + logger.info(s"Destination index of _reindex request is forbidden") } if (!isSearchRequestComposedOnlyOfAllowedIndices) { - logger.info(s"[${id.show}] At least one index from sources indices list of _reindex request is forbidden") + logger.info(s"At least one index from sources indices list of _reindex request is forbidden") } ShouldBeInterrupted } diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala index 2c1b0014e0..97b8ccd9c5 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala @@ -74,7 +74,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo request } case Left(_) => - logger.debug(s"[${id.show}] Cannot parse SQL statement - we can pass it though, because ES is going to reject it") + logger.debug(s"Cannot parse SQL statement - we can pass it though, because ES is going to reject it") request } } @@ -85,7 +85,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala index 0c67384c1e..d7e743e648 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CleanupRepositoryEsRequestContext(actionRequest: CleanupRepositoryRequest, override protected def update(request: CleanupRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala index 44b7d78dfd..d09015139b 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CreateRepositoryEsRequestContext(actionRequest: PutRepositoryRequest, override protected def update(request: PutRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala index eaf9334872..0cf32e1bea 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class DeleteRepositoryEsRequestContext(actionRequest: DeleteRepositoryRequest, override protected def update(request: DeleteRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala index cee0bffd4c..d1410eff3d 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class VerifyRepositoryEsRequestContext(actionRequest: VerifyRepositoryRequest, override protected def update(request: VerifyRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala index ead4fcf250..20501516d5 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala @@ -68,32 +68,32 @@ class CreateSnapshotEsRequestContext(actionRequest: CreateSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala index a56aba660e..621d744767 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala @@ -60,7 +60,7 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -71,14 +71,14 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, .toRight(()) } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala index 22869bbb4f..b81f333174 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala @@ -68,7 +68,7 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, case r => r } case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala index 88887db96c..156deb5b80 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala @@ -63,7 +63,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -75,7 +75,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") } Right(snapshot) } @@ -88,7 +88,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala index 44ee8397ec..e522e440f1 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala @@ -100,12 +100,12 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { val repositories = blockContext.repositories if (allRepositoriesRequested(repositories)) { Right(RepositoryName.All) @@ -115,7 +115,7 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala index 80e36a6d77..d8e5182eed 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.GetComposableIndexTemplateAction import org.elasticsearch.cluster.metadata import org.elasticsearch.cluster.metadata.ComposableIndexTemplate @@ -108,7 +108,7 @@ class GetComposableIndexTemplateEsRequestContext(actionRequest: GetComposableInd } -private[templates] object GetComposableIndexTemplateEsRequestContext extends Logging { +private[templates] object GetComposableIndexTemplateEsRequestContext extends RequestIdAwareLogging { def filter(templates: Map[String, ComposableIndexTemplate], usingTemplate: Set[Template] => Set[Template]) diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala index bd74c3a18f..1c6eecf409 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.{GetIndexTemplatesRequest, GetIndexTemplatesResponse} import org.elasticsearch.cluster.metadata.{AliasMetadata, IndexTemplateMetadata} import org.elasticsearch.common.collect.ImmutableOpenMap @@ -104,7 +104,7 @@ class GetTemplatesEsRequestContext(actionRequest: GetIndexTemplatesRequest, } -private[templates] object GetTemplatesEsRequestContext extends Logging { +private[templates] object GetTemplatesEsRequestContext extends RequestIdAwareLogging { def filter(templates: Iterable[IndexTemplateMetadata], usingTemplate: Set[Template] => Set[Template]) diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala index a8951de5b1..32116d8212 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala @@ -72,7 +72,7 @@ class MultiSearchTemplateEsRequestContext private(actionRequest: ActionRequest w } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala index e6f6d8916e..434787a686 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala @@ -55,7 +55,7 @@ class SimulateIndexTemplateRequestEsRequestContext(actionRequest: SimulateIndexT filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateRequest(request, filteredIndices.head, allAllowedIndices) } diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala index fbc4cf6776..46ed6e7a95 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala @@ -109,7 +109,7 @@ class SimulateExistingTemplateRequestEsRequestContext(existingTemplateName: Temp case Some(_) => updateResponse(namePatterns.toList, blockContext.allAllowedIndices.toList) case None => - logger.info(s"[${id.show}] User has no access to template ${existingTemplateName.show}") + logger.info(s"User has no access to template ${existingTemplateName.show}") ModificationResult.ShouldBeInterrupted } case other => diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala index 0ecd7a72b3..fe4d60bd42 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.queries import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.index.query.* import org.joor.Reflect.on import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.RequestFieldsUsage @@ -30,7 +30,7 @@ trait QueryFieldsUsage[QUERY <: QueryBuilder] { def fieldsIn(query: QUERY): RequestFieldsUsage } -object QueryFieldsUsage extends Logging { +object QueryFieldsUsage extends RequestIdAwareLogging { def apply[QUERY <: QueryBuilder](implicit ev: QueryFieldsUsage[QUERY]): QueryFieldsUsage[QUERY] = ev implicit class Ops[QUERY <: QueryBuilder : QueryFieldsUsage](val query: QUERY) { @@ -62,7 +62,7 @@ object QueryFieldsUsage extends Logging { Option(on(query).call("getFieldName").get[String]) match { case Some(fieldName: String) => UsingFields(NonEmptyList.one(UsedField(fieldName))) case _ => - logger.debug(s"Cannot extract fields for terms set query") + noRequestIdLogger.debug(s"Cannot extract fields for terms set query") CannotExtractFields } } @@ -89,7 +89,7 @@ object QueryFieldsUsage extends Logging { case builder: TermsSetQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder: WildcardQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder => - logger.debug(s"Cannot extract fields for query: ${builder.getName}") + noRequestIdLogger.debug(s"Cannot extract fields for query: ${builder.getName}") CannotExtractFields } diff --git a/es87x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala b/es87x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala index 0998bb9a5b..b4671e9e4d 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.handler.response import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.FieldsRestrictions import tech.beshu.ror.accesscontrol.domain.Header @@ -26,17 +26,17 @@ import tech.beshu.ror.accesscontrol.headerValues.transientFieldsToHeaderValue import tech.beshu.ror.accesscontrol.request.RequestContext import tech.beshu.ror.implicits.* -object FLSContextHeaderHandler extends Logging { +object FLSContextHeaderHandler extends RequestIdAwareLogging { def addContextHeader(threadPool: ThreadPool, - fieldsRestrictions: FieldsRestrictions, - requestId: RequestContext.Id): Unit = { + fieldsRestrictions: FieldsRestrictions) + (implicit requestId: RequestContext.Id): Unit = { val threadContext = threadPool.getThreadContext val header = createContextHeader(fieldsRestrictions) Option(threadContext.getHeader(header.name.value.value)) match { case None => implicit val show = headerShow - logger.debug(s"[${requestId.show}] Adding thread context header required by lucene. Header: '${header.show}'") + logger.debug(s"Adding thread context header required by lucene. Header: '${header.show}'") threadContext.putHeader(header.name.value.value, header.value.value) case Some(_) => } diff --git a/es87x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala b/es87x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala index 629696a91d..7aa2029a2a 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.admin.indices.template.get.{GetComponentTemplateAction, GetComposableIndexTemplateAction} import org.elasticsearch.action.admin.indices.template.put.{PutComponentTemplateAction, PutComposableIndexTemplateAction} @@ -46,7 +46,7 @@ import scala.jdk.CollectionConverters.* final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJsonParserFactory)(using Clock) extends DataStreamService - with Logging { + with RequestIdAwareLogging { override def checkDataStreamExists(dataStreamName: DataStreamName.Full): Task[Boolean] = execute { val request = new GetDataStreamAction.Request(List(dataStreamName.value.value).toArray) @@ -203,11 +203,11 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ response <- Task.measure( task = Task.delay(nodeClient.execute(action, request).actionGet()), logTimeMeasurement = duration => Task.delay { - logger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") + noRequestIdLogger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") } ) _ <- Task.delay { - logger.debug(s"Action ${action.name()} response: ${response.toString}") + noRequestIdLogger.debug(s"Action ${action.name()} response: ${response.toString}") } } yield response } @@ -215,7 +215,7 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ def executeAck[REQUEST <: ActionRequest, RESPONSE <: AcknowledgedResponse](action: ActionType[RESPONSE], request: REQUEST): Task[RESPONSE] = { executeT(action, request) - .tapEval(response => Task.delay(logger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) + .tapEval(response => Task.delay(noRequestIdLogger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) } private def supportedActions: Map[ActionType[ActionResponse], TransportAction[ActionRequest, ActionResponse]] = { diff --git a/es87x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala b/es87x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala index 2e75d37d0f..16259474bf 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.support.WriteRequest.RefreshPolicy import org.elasticsearch.client.internal.node.NodeClient @@ -38,7 +38,7 @@ import scala.jdk.CollectionConverters.* class EsIndexJsonContentService(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexJsonContentService - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -63,14 +63,14 @@ class EsIndexJsonContentService(client: NodeClient, Option(response.getSourceAsMap) match { case Some(map) => val source = map.asScala.toMap.asStringMap - logger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") Right(source) case None => - logger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") + noRequestIdLogger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") Right(Map.empty[String, String]) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(ContentNotFound) } } @@ -78,7 +78,7 @@ class EsIndexJsonContentService(client: NodeClient, .onErrorRecover { case _: ResourceNotFoundException => Left(ContentNotFound) case ex => - logger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) Left(CannotReachContentSource) } } @@ -104,14 +104,14 @@ class EsIndexJsonContentService(client: NodeClient, case status if status / 100 == 2 => Right(()) case status => - logger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") Left(CannotWriteToIndex) } } .executeOn(RorSchedulers.blockingScheduler) .onErrorRecover { case ex => - logger.error(s"Cannot write to document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]", ex) Left(CannotWriteToIndex) } } diff --git a/es87x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala b/es87x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala index 7d15a76306..df7ab14fec 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala @@ -22,7 +22,7 @@ import cats.kernel.Monoid import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task import monix.execution.CancelablePromise -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction.{ResolvedAlias, ResolvedIndex} @@ -63,7 +63,7 @@ class EsServerBasedRorClusterService(nodeName: String, nodeClient: NodeClient, threadPool: ThreadPool) extends RorClusterService - with Logging { + with RequestIdAwareLogging { import EsServerBasedRorClusterService.* @@ -154,7 +154,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractAccessibilityFrom) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify get request. Blocking document", ex) + logger.error(s"Could not verify get request. Blocking document", ex)(id) Inaccessible } } @@ -166,7 +166,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractResultsFromSearchResponse) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify documents returned by multi get response. Blocking all returned documents", ex) + logger.error(s"Could not verify documents returned by multi get response. Blocking all returned documents", ex)(id) blockAllDocsReturned(documents) } .map(results => zip(results, documents)) @@ -275,7 +275,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService): Task[List[FullRemoteDataStreamWithAliases]] = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -331,7 +331,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService) = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -417,7 +417,7 @@ class EsServerBasedRorClusterService(nodeName: String, } } case None => - logger.error("Cannot supply Snapshots Service. Please, report the issue!!!") + noRequestIdLogger.error("Cannot supply Snapshots Service. Please, report the issue!!!") Task.now(Set.empty[Snapshot]) } } diff --git a/es87x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala b/es87x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala index a657d15ca9..31d96f15a2 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.services import cats.data.NonEmptyList -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.bulk.{BackoffPolicy, BulkProcessor, BulkRequest, BulkResponse} import org.elasticsearch.action.index.IndexRequest import org.elasticsearch.action.{ActionListener, DocWriteRequest} @@ -39,7 +39,7 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, (using Clock) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { private val bulkProcessor = BulkProcessor @@ -80,25 +80,25 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, private class AuditSinkBulkProcessorListener extends BulkProcessor.Listener { override def beforeBulk(executionId: Long, request: BulkRequest): Unit = { - logger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") + noRequestIdLogger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") } override def afterBulk(executionId: Long, request: BulkRequest, response: BulkResponse): Unit = { if (response.hasFailures) { - logger.error("Some failures flushing the BulkProcessor: ") + noRequestIdLogger.error("Some failures flushing the BulkProcessor: ") response .getItems.to(LazyList) .filter(_.isFailed) .map(_.getFailureMessage) .groupBy(identity) .foreach { case (message, stream) => - logger.error(s"${stream.size}x: $message") + noRequestIdLogger.error(s"${stream.size}x: $message") } } } override def afterBulk(executionId: Long, request: BulkRequest, failure: Throwable): Unit = { - logger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) + noRequestIdLogger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) } } diff --git a/es87x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala b/es87x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala index a8def0ec7a..b3c5593c36 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala @@ -22,7 +22,7 @@ import org.apache.http.auth.{AuthScope, Credentials, UsernamePasswordCredentials import org.apache.http.conn.ssl.NoopHostnameVerifier import org.apache.http.impl.client.BasicCredentialsProvider import org.apache.http.impl.nio.client.HttpAsyncClientBuilder -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.* import org.elasticsearch.client.RestClient.FailureListener import tech.beshu.ror.accesscontrol.audit.sink.AuditDataStreamCreator @@ -38,7 +38,7 @@ import scala.collection.parallel.CollectionConverters.* final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient]) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { override def submit(indexName: IndexName.Full, documentId: String, jsonRecord: String) (implicit requestId: RequestId): Unit = { @@ -77,21 +77,21 @@ final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient] override def onSuccess(response: Response): Unit = { response.getStatusLine.getStatusCode / 100 match { case 2 => // 2xx - logger.debug(s"[${requestId.show}] Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") + logger.debug(s"Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") case _ => - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") } } override def onFailure(ex: Exception): Unit = { - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId]", ex) + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId]", ex) } } override val dataStreamCreator: AuditDataStreamCreator = new AuditDataStreamCreator(clients.map(new RestClientDataStreamService(_))) } -object RestClientAuditSinkService extends Logging { +object RestClientAuditSinkService extends RequestIdAwareLogging { def create(remoteCluster: AuditCluster.RemoteAuditCluster): RestClientAuditSinkService = { remoteCluster.mode match { @@ -122,7 +122,7 @@ object RestClientAuditSinkService extends Logging { .setFailureListener( new FailureListener { override def onFailure(node: Node): Unit = { - logger.debug( + noRequestIdLogger.debug( s"[AUDIT] Node marked dead: ${node.getHost.getSchemeName}://${node.getHost.getHostName}:${node.getHost.getPort}. The client will attempt failover.", ) } diff --git a/es87x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala b/es87x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala index d3c8c290b0..2b8a950017 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.Channel import io.netty.handler.ssl.NotSslRecordException -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.network.NetworkService import org.elasticsearch.common.settings.{ClusterSettings, Settings} import org.elasticsearch.http.netty4.Netty4HttpServerTransport @@ -41,7 +41,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, tracer: Tracer, fipsCompliant: Boolean) extends Netty4HttpServerTransport(settings, networkService, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory, tracer, TLSConfig.noTLS(), null) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, ssl.clientAuthenticationEnabled) @@ -49,7 +49,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, override def onException(channel: HttpChannel, cause: Exception): Unit = { if (!this.lifecycle.started) return - else if (cause.getCause.isInstanceOf[NotSslRecordException]) logger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) + else if (cause.getCause.isInstanceOf[NotSslRecordException]) noRequestIdLogger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) else super.onException(channel, cause) channel.close() } diff --git a/es87x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala b/es87x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala index ba64286bb4..ce09748e17 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.* import io.netty.handler.ssl.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.TransportVersion import org.elasticsearch.cluster.node.DiscoveryNode import org.elasticsearch.common.io.stream.NamedWriteableRegistry @@ -46,7 +46,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, sharedGroupFactory: SharedGroupFactory, fipsCompliant: Boolean) extends Netty4Transport(settings, TransportVersion.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = SSLCertHelper.prepareClientSSLContext(ssl, fipsCompliant, ssl.certificateVerificationEnabled) private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, clientAuthenticationEnabled = false) @@ -78,7 +78,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, override def exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable): Unit = { if (cause.isInstanceOf[NotSslRecordException] || (cause.getCause != null && cause.getCause.isInstanceOf[NotSslRecordException])) { - logger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") + noRequestIdLogger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") ctx.channel.close } else { super.exceptionCaught(ctx, cause) diff --git a/es87x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala b/es87x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala index 2e997a741f..80d11fa6f5 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.utils import cats.Show import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.client.internal.node.NodeClient import org.elasticsearch.rest.* @@ -37,7 +37,7 @@ import java.util import scala.util.Try class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandler) - extends RestHandler with Logging { + extends RestHandler with RequestIdAwareLogging { private val wrapped = doPrivileged { wrapSomeActions(underlying) @@ -104,11 +104,11 @@ class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandle private def logError(error: AuthorizationValueError): Unit = { { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorSanitizedShow - logger.warn(s"The incoming request was malformed. Cause: ${error.show}") + noRequestIdLogger.warn(s"The incoming request was malformed. Cause: ${error.show}") } if (logger.delegate.isDebugEnabled()) { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorWithDetailsShow - logger.debug(s"Malformed request detailed cause: ${error.show}") + noRequestIdLogger.debug(s"Malformed request detailed cause: ${error.show}") } } diff --git a/es87x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala b/es87x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala index 5ab1e35742..a9af8f710a 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala @@ -16,13 +16,13 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.settings.Settings import tech.beshu.ror.tools.core.patches.PatchingVerifier import tech.beshu.ror.tools.core.patches.PatchingVerifier.Error.{CannotVerifyIfPatched, EsNotPatched} import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -object EsPatchVerifier extends Logging { +object EsPatchVerifier extends RequestIdAwareLogging { def verify(settings: Settings): Unit = doPrivileged { pathHomeFrom(settings).flatMap(PatchingVerifier.verify) match { @@ -30,7 +30,7 @@ object EsPatchVerifier extends Logging { case Left(e@EsNotPatched(_)) => throw new IllegalStateException(e.message) case Left(e@CannotVerifyIfPatched(_)) => - logger.warn(e.message) + noRequestIdLogger.warn(e.message) } } diff --git a/es87x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala b/es87x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala index 639aeb5029..893d807108 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.repositories.{RepositoriesService, VerifyNodeRepositoryAction} import org.elasticsearch.transport.{RemoteClusterService, TransportService} import org.joor.Reflect.on @@ -26,7 +26,7 @@ import java.util.function.Supplier import scala.util.{Failure, Success, Try} class RemoteClusterServiceSupplier(repositoriesServiceSupplier: Supplier[RepositoriesService]) - extends Supplier[Option[RemoteClusterService]] with Logging { + extends Supplier[Option[RemoteClusterService]] with RequestIdAwareLogging { override def get(): Option[RemoteClusterService] = { for { @@ -35,7 +35,7 @@ class RemoteClusterServiceSupplier(repositoriesServiceSupplier: Supplier[Reposit case Success(transportService) => Option(transportService.getRemoteClusterService) case Failure(ex) => - logger.error("Cannot extract RemoteClusterService from RepositoriesService", ex) + noRequestIdLogger.error("Cannot extract RemoteClusterService from RepositoriesService", ex) None } } yield remoteClusterService diff --git a/es88x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es88x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index 07d70bbf05..978eebec5d 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.support.{ActionFilter, ActionFilterChain} import org.elasticsearch.action.{ActionListener, ActionRequest, ActionResponse} import org.elasticsearch.client.internal.node.NodeClient @@ -62,7 +62,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, rorEsConfig: ReadonlyRestEsConfig) (implicit environmentConfig: EnvironmentConfig) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = environmentConfig.uniqueIdentifierGenerator @@ -211,12 +211,12 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def handleRorNotReadyYet(esContext: EsContext): Unit = { - logger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") + noRequestIdLogger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") rorNotAvailableRequestHandler.handleRorNotReadyYet(esContext) } private def handleRorFailedToStart(esContext: EsContext): Unit = { - logger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") + noRequestIdLogger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") rorNotAvailableRequestHandler.handleRorFailedToStart(esContext) } @@ -238,7 +238,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def logAndSetStartingFailureState(failure: StartingFailure): Unit = { - logger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) + noRequestIdLogger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) rorInstanceState.set(RorInstanceStartingState.NotStarted(failure)) } } diff --git a/es88x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala b/es88x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala index 1fb22fc79d..53452eb8e6 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.xcontent.LoggingDeprecationHandler import org.elasticsearch.rest.RestResponse import org.elasticsearch.transport.BytesRefRecycler @@ -32,7 +32,7 @@ import tech.beshu.ror.accesscontrol.domain.ResponseFieldsFiltering.{AccessMode, import scala.jdk.CollectionConverters.* trait ResponseFieldsFiltering { - this: Logging => + this: RequestIdAwareLogging => private val responseFieldsRestrictions: Atomic[Option[ResponseFieldsRestrictions]] = Atomic(None: Option[ResponseFieldsRestrictions]) diff --git a/es88x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala b/es88x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala index 0f26750588..da95de59a4 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.action.{ActionListener, ActionResponse} import org.elasticsearch.threadpool.ThreadPool @@ -37,7 +37,7 @@ sealed abstract class RorActionListener[T](val underlying: ActionListener[T]) ex final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionListener[T], correlationId: Eval[CorrelationId]) - extends RorActionListener[T](underlying) with Logging { + extends RorActionListener[T](underlying) with RequestIdAwareLogging { override def onFailure(e: Exception): Unit = { super.onFailure(adaptExceptionIfNeeded(e)) @@ -47,7 +47,7 @@ final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionLis ex match { case esException: ElasticsearchException => esException case other => - logger.error(s"[${correlationId.value.show}] Internal error.", other) + noRequestIdLogger.error(s"[${correlationId.value.show}] Internal error.", other) new ElasticsearchException(s"[${correlationId.value.show}] Internal error. See logs for details.") } } diff --git a/es88x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala b/es88x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala index 75048ebe7d..14e5e31c1b 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.http.HttpChannel import org.elasticsearch.rest.{AbstractRestChannel, RestChannel as EsRestChannel, RestRequest as EsRestRequest, RestResponse as EsRestResponse} import squants.information.{Bytes, Information} @@ -40,7 +40,7 @@ object RorRestChannel { final class RorRestChannel private(underlying: EsRestChannel, val restRequest: RorRestRequest) extends AbstractRestChannel(underlying.request(), true) with ResponseFieldsFiltering - with Logging { + with RequestIdAwareLogging { override def sendResponse(response: EsRestResponse): Unit = { ThreadRepo.removeRestChannel(this) diff --git a/es88x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala b/es88x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala index 6babc712b9..3c80750a25 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala @@ -18,16 +18,15 @@ package tech.beshu.ror.es.actions.rradmin import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.ConfigApi.ConfigResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAdminActionHandler extends Logging { +class RRAdminActionHandler extends RequestIdAwareLogging { private implicit val adminRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +51,7 @@ class RRAdminActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAdminResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAdminAction internal error", ex) + logger.error("RRAdminAction internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es88x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala b/es88x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala index c55835a1d0..ce45c6f48e 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala @@ -16,18 +16,15 @@ */ package tech.beshu.ror.es.actions.rrauthmock -import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.AuthMockApi.AuthMockResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier -import tech.beshu.ror.implicits.* +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAuthMockActionHandler extends Logging { +class RRAuthMockActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -53,7 +50,7 @@ class RRAuthMockActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAuthMockResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAuthMock internal error", ex) + logger.error("RRAuthMock internal error", ex) listener.onFailure(new Exception(ex)) } } diff --git a/es88x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala b/es88x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala index aa8bb31e67..640084c4ec 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestconfig import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.TestConfigApi.TestConfigResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestConfigActionHandler extends Logging { +class RRTestConfigActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +52,7 @@ class RRTestConfigActionHandler extends Logging { case Right(response) => listener.onResponse(new RRTestConfigResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRTestConfig internal error", ex) + logger.error(s"RRTestConfig internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es88x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala b/es88x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala index 494e9150b4..98cc0c945d 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.dlsfls import cats.data.StateT import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.DirectoryReader import org.elasticsearch.common.util.concurrent.ThreadContext import org.elasticsearch.core.CheckedFunction @@ -31,7 +31,7 @@ import java.io.IOException import java.util.function.{Function => JavaFunction} import scala.util.{Failure, Success, Try} -object RoleIndexSearcherWrapper extends Logging { +object RoleIndexSearcherWrapper extends RequestIdAwareLogging { val instance: JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] = new JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] { @@ -54,7 +54,7 @@ object RoleIndexSearcherWrapper extends Logging { } .map(r => (r, r)) case None => - logger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") + noRequestIdLogger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") Success((reader, reader)) } } @@ -66,13 +66,13 @@ object RoleIndexSearcherWrapper extends Logging { nel <- NonEmptyString.from(value) match { case Right(nel) => Success(nel) case Left(_) => - logger.debug("FLS: empty header value") + noRequestIdLogger.debug("FLS: empty header value") failure } fields <- transientFieldsFromHeaderValue.fromRawValue(nel) match { case result@Success(_) => result case Failure(ex) => - logger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) + noRequestIdLogger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) failure } } yield fields diff --git a/es88x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala b/es88x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala index ce77d77f4e..aeccbfcead 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.dlsfls import com.google.common.collect.Iterators -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.codecs.StoredFieldsReader import org.apache.lucene.index.* import org.apache.lucene.index.StoredFieldVisitor.Status @@ -39,21 +39,21 @@ import scala.jdk.CollectionConverters.* import scala.util.Try private class RorDocumentFieldReader(reader: LeafReader, fieldsRestrictions: FieldsRestrictions) - extends SequentialStoredFieldsLeafReader(reader) with Logging { + extends SequentialStoredFieldsLeafReader(reader) with RequestIdAwareLogging { private val policy = new FieldsPolicy(fieldsRestrictions) private val remainingFieldsInfo = { val fInfos = in.getFieldInfos val newInfos = if (fInfos.asScala.isEmpty) { - logger.warn("original fields were empty! This is weird!") + noRequestIdLogger.warn("original fields were empty! This is weird!") fInfos } else { val remainingFields = fInfos.asScala.filter(f => policy.canKeep(f.name)).toSet new FieldInfos(remainingFields.toArray) } - logger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") - logger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") - logger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") + noRequestIdLogger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") newInfos } private val jsonPolicyBasedFilterer = new JsonPolicyBasedFilterer(policy) diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala index 15add4a6dd..a4d939d26a 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.* import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest import org.elasticsearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest @@ -87,7 +87,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, threadPool: ThreadPool) (implicit generator: UniqueIdentifierGenerator, scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle(engines: Engines, esContext: EsContext): Task[Either[Error, Unit]] = { @@ -242,7 +242,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, case SearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case MultiSearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case _ => - logger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") + noRequestIdLogger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") regularRequestHandler.handle(new DummyCompositeIndicesEsRequestContext(request, esContext, aclContext, clusterService, threadPool)) } // rest diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala index cab02aff37..100edd72ac 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.common.io.stream.StreamOutput import org.elasticsearch.xcontent.{ToXContent, ToXContentObject, XContentBuilder} @@ -45,7 +45,7 @@ import scala.util.{Failure, Success, Try} class CurrentUserMetadataRequestHandler(engine: Engine, esContext: EsContext) - extends Logging { + extends RequestIdAwareLogging { def handle(request: RequestContext.Aux[CurrentUserMetadataRequestBlockContext] with EsRequest[CurrentUserMetadataRequestBlockContext]): Task[Unit] = { engine.core.accessControl @@ -69,7 +69,7 @@ class CurrentUserMetadataRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(ex.asInstanceOf[Exception]) } } @@ -86,13 +86,13 @@ class CurrentUserMetadataRequestHandler(engine: Engine, )) } - private def onPassThrough(requestContext: RequestContext): Unit = { - logger.warn(s"[${requestContext.id.toRequestId.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") + private def onPassThrough(implicit requestContext: RequestContext): Unit = { + logger.warn(s"Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") esContext.listener.onFailure(createRorNotEnabledResponse()) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala index 2fb01dcc41..c5c44fda92 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala @@ -20,7 +20,7 @@ import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.RegularRequestResult @@ -49,7 +49,7 @@ class RegularRequestHandler(engine: Engine, esContext: EsContext, threadPool: ThreadPool) (implicit scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle[B <: BlockContext : BlockContextUpdater](request: RequestContext.Aux[B] with EsRequest[B]): Task[Unit] = { engine.core.accessControl @@ -85,7 +85,7 @@ class RegularRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(new Exception(ex)) } } @@ -99,7 +99,7 @@ class RegularRequestHandler(engine: Engine, case ModificationResult.ShouldBeInterrupted => onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case ModificationResult.CannotModify => - logger.error(s"[${request.id.toRequestId.show}] Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") + noRequestIdLogger.error(s"Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case CustomResponse(response) => respond(request, response) @@ -247,7 +247,7 @@ class RegularRequestHandler(engine: Engine, esContext.listener.onResponse(response) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } \ No newline at end of file diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala index f4f832dedc..bfc421bdd5 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.index.query.{AbstractQueryBuilder, QueryBuilder, QueryBuilders} import org.elasticsearch.search.aggregations.AggregatorFactories @@ -40,7 +40,7 @@ import tech.beshu.ror.implicits.* import java.util.UUID import scala.jdk.CollectionConverters.* -object SearchRequestOps extends Logging { +object SearchRequestOps extends RequestIdAwareLogging { implicit class QueryBuilderOps(val builder: Option[QueryBuilder]) extends AnyVal { @@ -52,7 +52,7 @@ object SearchRequestOps extends Logging { val modifiedQuery: AbstractQueryBuilder[_] = provideNewQueryWithAppliedFilter(builder, filterQuery) Some(modifiedQuery) case None => - logger.debug(s"[${requestId.show}] No filter applied to query.") + logger.debug(s"No filter applied to query.") builder } } @@ -92,7 +92,7 @@ object SearchRequestOps extends Logging { case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, requestId) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) disableCaching(requestId) case BasedOnBlockContextOnly.NotAllowedFieldsUsed(notAllowedFields) => modifyNotAllowedFieldsInRequest(notAllowedFields) @@ -138,8 +138,8 @@ object SearchRequestOps extends Logging { } } - private def disableCaching(requestId: RequestContext.Id) = { - logger.debug(s"[${requestId.show}] ACL uses context header for fields rule, will disable request cache for SearchRequest") + private def disableCaching(implicit requestId: RequestContext.Id) = { + logger.debug(s"ACL uses context header for fields rule, will disable request cache for SearchRequest") request.requestCache(false) } } diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala index 270367a54f..e2884598df 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala @@ -17,7 +17,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.action.support.IndicesOptions.WildcardStates import org.elasticsearch.action.{CompositeIndicesRequest, IndicesRequest} @@ -34,7 +33,7 @@ import scala.jdk.CollectionConverters.* abstract class BaseEsRequestContext[B <: BlockContext](esContext: EsContext, clusterService: RorClusterService) - extends RequestContext with Logging { + extends RequestContext { override type BLOCK_CONTEXT = B diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala index ae8abbe1f5..0a9e6343dc 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala @@ -18,16 +18,16 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.blocks.BlockContext import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged +import tech.beshu.ror.utils.RequestIdAwareLogging import scala.util.Try -trait EsRequest[B <: BlockContext] extends Logging { +trait EsRequest[B <: BlockContext] extends RequestIdAwareLogging { implicit def threadPool: ThreadPool final def modifyUsing(blockContext: B): ModificationResult = { @@ -35,7 +35,7 @@ trait EsRequest[B <: BlockContext] extends Logging { Try(modifyRequest(blockContext)) .fold( ex => { - logger.error(s"[${blockContext.requestContext.id.show}] Cannot modify request with filtered data", ex) + logger.error(s"Cannot modify request with filtered data", ex)(blockContext) ModificationResult.CannotModify }, identity diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala index c6a9dcbefd..f773b3efb1 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala @@ -51,7 +51,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest private def discoverDataStreams() = { val dataStreams = dataStreamsFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered data streams: ${dataStreams.show}") + logger.debug(s"Discovered data streams: ${dataStreams.show}") dataStreams } @@ -59,7 +59,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest val backingIndices = backingIndicesFrom(actionRequest) backingIndices match { case BackingIndices.IndicesInvolved(filteredIndices, _) => - logger.debug(s"[${id.show}] Discovered indices: ${filteredIndices.show}") + logger.debug(s"Discovered indices: ${filteredIndices.show}") case BackingIndices.IndicesNotInvolved => } backingIndices diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala index c091179cb6..d150709314 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala @@ -85,7 +85,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: case Some(indices) => update(actionRequest, indices, blockContext.filter, blockContext.fieldLevelSecurity) case None => - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -101,7 +101,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } \ No newline at end of file diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala index 71d462de57..48014e1bdc 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala @@ -73,7 +73,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, } yield update(actionRequest, filteredIndices, allAllowedIndices) result.getOrElse { - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -86,7 +86,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala index 95d882c3b5..f607c0e347 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala @@ -50,7 +50,7 @@ abstract class BaseRepositoriesEsRequestContext[R <: ActionRequest](actionReques case Some(repositories) => update(actionRequest, repositories) case None => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") ShouldBeInterrupted } } diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala index b3b1d66238..7ef0f32014 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala @@ -42,7 +42,7 @@ abstract class BaseSingleIndexEsRequestContext[R <: ActionRequest](actionRequest filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } update(request, filteredIndices.head) } diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala index b5ab70fe7a..c1b2e7ea27 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala @@ -62,7 +62,7 @@ class BulkEsRequestContext(actionRequest: BulkRequest, case (_, _) => ShouldBeInterrupted } } else { - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because origin request contained different " + + logger.error(s"Cannot alter MultiGetRequest request, because origin request contained different " + s"number of requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } @@ -90,18 +90,18 @@ class BulkEsRequestContext(actionRequest: BulkRequest, updateRequestWithIndices(request, nel) Modified case None => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because empty list of indices was found") + logger.error(s"Cannot alter MultiGetRequest request, because empty list of indices was found") ShouldBeInterrupted } case Indices.NotFound => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because no allowed indices were found") + logger.error(s"Cannot alter MultiGetRequest request, because no allowed indices were found") ShouldBeInterrupted } } private def updateRequestWithIndices(request: DocWriteRequest[_], indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } request.index(indices.head.stringify) } diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala index 75a75fcef5..96a043b298 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala @@ -53,14 +53,14 @@ class BulkShardEsRequestContext(actionRequest: BulkShardRequest, case Success(_) => Modified case Failure(ex) => - logger.error(s"[${id.show}] Cannot modify BulkShardRequest", ex) + logger.error(s"Cannot modify BulkShardRequest", ex) CannotModify } } private def tryUpdate(request: BulkShardRequest, indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } val singleIndex = indices.head val uuid = clusterService.indexOrAliasUuids(singleIndex.name).toList.head diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala index 65a168092a..158ac485a5 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala @@ -45,14 +45,14 @@ class ClusterAllocationExplainEsRequestContext(actionRequest: ClusterAllocationE getRequestedIndexFrom(request) match { case Some(_) => if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateIndexIn(request, filteredIndices.head) Modified case None if filteredIndices.exists(_.name === ClusterIndexName.Local.wildcard) => Modified case None => - logger.error(s"[${id.show}] Cluster allocation explain request without index name is unavailable when block contains `indices` rule") + logger.error(s"Cluster allocation explain request without index name is unavailable when block contains `indices` rule") ShouldBeInterrupted } } diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala index 5778b8968d..02dec730ed 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala @@ -66,7 +66,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, updateAliases(actionRequest, aliases) UpdateResponse.sync(updateAliasesResponse(aliases.includedOnly, _)) case None => - logger.error(s"[${id.show}] At least one alias and one index has to be allowed. " + + logger.error(s"At least one alias and one index has to be allowed. " + s"Found allowed indices: [${blockContext.indices.show}]." + s"Found allowed aliases: [${blockContext.aliases.show}]") ShouldBeInterrupted @@ -114,7 +114,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, .indices().asSafeSet .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } @@ -122,7 +122,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, val aliases = rawRequestAliasesSet(request) .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered aliases: ${aliases.show}") + logger.debug(s"Discovered aliases: ${aliases.show}") aliases } diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala index abb85d42b7..f9e2c87e53 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala @@ -55,7 +55,7 @@ class IndicesAliasesEsRequestContext(actionRequest: IndicesAliasesRequest, if (originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala index 05b70606b9..37dd50452b 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala @@ -119,7 +119,7 @@ class MultiGetEsRequestContext(actionRequest: MultiGetRequest, case Nil => updateItemWithNonExistingIndex(item) case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } item.index(index.stringify) } diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala index 989956d79a..9e13edee8d 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala @@ -78,7 +78,7 @@ class MultiSearchEsRequestContext(actionRequest: MultiSearchRequest, } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala index 9191e33b66..5a61356f48 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala @@ -47,7 +47,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { request.getRequests.removeIf { request => removeOrAlter(request, filteredIndices.toCovariantSet) } if (request.getRequests.asScala.isEmpty) { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") ShouldBeInterrupted } else { Modified @@ -63,7 +63,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, true case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") } request.index(index.stringify) false diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala index c411df93c5..c7b99f6e85 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala @@ -52,7 +52,7 @@ class PutRollupJobEsRequestContext private(actionRequest: ActionRequest, if(originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala index 141d9db788..fff8ed58bb 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala @@ -49,7 +49,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (tryUpdate(actionRequest, filteredIndices)) Modified else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") ShouldBeInterrupted } } diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala index 489d0187bc..c42dfc3b78 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala @@ -58,10 +58,10 @@ class ReindexEsRequestContext(actionRequest: ReindexRequest, Modified } else { if (!isDestinationIndexOnFilteredIndicesList) { - logger.info(s"[${id.show}] Destination index of _reindex request is forbidden") + logger.info(s"Destination index of _reindex request is forbidden") } if (!isSearchRequestComposedOnlyOfAllowedIndices) { - logger.info(s"[${id.show}] At least one index from sources indices list of _reindex request is forbidden") + logger.info(s"At least one index from sources indices list of _reindex request is forbidden") } ShouldBeInterrupted } diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala index 2c1b0014e0..97b8ccd9c5 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala @@ -74,7 +74,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo request } case Left(_) => - logger.debug(s"[${id.show}] Cannot parse SQL statement - we can pass it though, because ES is going to reject it") + logger.debug(s"Cannot parse SQL statement - we can pass it though, because ES is going to reject it") request } } @@ -85,7 +85,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala index 0c67384c1e..d7e743e648 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CleanupRepositoryEsRequestContext(actionRequest: CleanupRepositoryRequest, override protected def update(request: CleanupRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala index 44b7d78dfd..d09015139b 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CreateRepositoryEsRequestContext(actionRequest: PutRepositoryRequest, override protected def update(request: PutRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala index eaf9334872..0cf32e1bea 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class DeleteRepositoryEsRequestContext(actionRequest: DeleteRepositoryRequest, override protected def update(request: DeleteRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala index cee0bffd4c..d1410eff3d 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class VerifyRepositoryEsRequestContext(actionRequest: VerifyRepositoryRequest, override protected def update(request: VerifyRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala index ead4fcf250..20501516d5 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala @@ -68,32 +68,32 @@ class CreateSnapshotEsRequestContext(actionRequest: CreateSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala index a56aba660e..621d744767 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala @@ -60,7 +60,7 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -71,14 +71,14 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, .toRight(()) } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala index 22869bbb4f..b81f333174 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala @@ -68,7 +68,7 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, case r => r } case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala index 88887db96c..156deb5b80 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala @@ -63,7 +63,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -75,7 +75,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") } Right(snapshot) } @@ -88,7 +88,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala index 44ee8397ec..e522e440f1 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala @@ -100,12 +100,12 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { val repositories = blockContext.repositories if (allRepositoriesRequested(repositories)) { Right(RepositoryName.All) @@ -115,7 +115,7 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala index 80e36a6d77..d8e5182eed 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.GetComposableIndexTemplateAction import org.elasticsearch.cluster.metadata import org.elasticsearch.cluster.metadata.ComposableIndexTemplate @@ -108,7 +108,7 @@ class GetComposableIndexTemplateEsRequestContext(actionRequest: GetComposableInd } -private[templates] object GetComposableIndexTemplateEsRequestContext extends Logging { +private[templates] object GetComposableIndexTemplateEsRequestContext extends RequestIdAwareLogging { def filter(templates: Map[String, ComposableIndexTemplate], usingTemplate: Set[Template] => Set[Template]) diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala index bd74c3a18f..1c6eecf409 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.{GetIndexTemplatesRequest, GetIndexTemplatesResponse} import org.elasticsearch.cluster.metadata.{AliasMetadata, IndexTemplateMetadata} import org.elasticsearch.common.collect.ImmutableOpenMap @@ -104,7 +104,7 @@ class GetTemplatesEsRequestContext(actionRequest: GetIndexTemplatesRequest, } -private[templates] object GetTemplatesEsRequestContext extends Logging { +private[templates] object GetTemplatesEsRequestContext extends RequestIdAwareLogging { def filter(templates: Iterable[IndexTemplateMetadata], usingTemplate: Set[Template] => Set[Template]) diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala index a8951de5b1..32116d8212 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala @@ -72,7 +72,7 @@ class MultiSearchTemplateEsRequestContext private(actionRequest: ActionRequest w } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala index e6f6d8916e..434787a686 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala @@ -55,7 +55,7 @@ class SimulateIndexTemplateRequestEsRequestContext(actionRequest: SimulateIndexT filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateRequest(request, filteredIndices.head, allAllowedIndices) } diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala index fbc4cf6776..46ed6e7a95 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala @@ -109,7 +109,7 @@ class SimulateExistingTemplateRequestEsRequestContext(existingTemplateName: Temp case Some(_) => updateResponse(namePatterns.toList, blockContext.allAllowedIndices.toList) case None => - logger.info(s"[${id.show}] User has no access to template ${existingTemplateName.show}") + logger.info(s"User has no access to template ${existingTemplateName.show}") ModificationResult.ShouldBeInterrupted } case other => diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala index 0ecd7a72b3..fe4d60bd42 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.queries import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.index.query.* import org.joor.Reflect.on import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.RequestFieldsUsage @@ -30,7 +30,7 @@ trait QueryFieldsUsage[QUERY <: QueryBuilder] { def fieldsIn(query: QUERY): RequestFieldsUsage } -object QueryFieldsUsage extends Logging { +object QueryFieldsUsage extends RequestIdAwareLogging { def apply[QUERY <: QueryBuilder](implicit ev: QueryFieldsUsage[QUERY]): QueryFieldsUsage[QUERY] = ev implicit class Ops[QUERY <: QueryBuilder : QueryFieldsUsage](val query: QUERY) { @@ -62,7 +62,7 @@ object QueryFieldsUsage extends Logging { Option(on(query).call("getFieldName").get[String]) match { case Some(fieldName: String) => UsingFields(NonEmptyList.one(UsedField(fieldName))) case _ => - logger.debug(s"Cannot extract fields for terms set query") + noRequestIdLogger.debug(s"Cannot extract fields for terms set query") CannotExtractFields } } @@ -89,7 +89,7 @@ object QueryFieldsUsage extends Logging { case builder: TermsSetQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder: WildcardQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder => - logger.debug(s"Cannot extract fields for query: ${builder.getName}") + noRequestIdLogger.debug(s"Cannot extract fields for query: ${builder.getName}") CannotExtractFields } diff --git a/es88x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala b/es88x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala index 0998bb9a5b..b4671e9e4d 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.handler.response import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.FieldsRestrictions import tech.beshu.ror.accesscontrol.domain.Header @@ -26,17 +26,17 @@ import tech.beshu.ror.accesscontrol.headerValues.transientFieldsToHeaderValue import tech.beshu.ror.accesscontrol.request.RequestContext import tech.beshu.ror.implicits.* -object FLSContextHeaderHandler extends Logging { +object FLSContextHeaderHandler extends RequestIdAwareLogging { def addContextHeader(threadPool: ThreadPool, - fieldsRestrictions: FieldsRestrictions, - requestId: RequestContext.Id): Unit = { + fieldsRestrictions: FieldsRestrictions) + (implicit requestId: RequestContext.Id): Unit = { val threadContext = threadPool.getThreadContext val header = createContextHeader(fieldsRestrictions) Option(threadContext.getHeader(header.name.value.value)) match { case None => implicit val show = headerShow - logger.debug(s"[${requestId.show}] Adding thread context header required by lucene. Header: '${header.show}'") + logger.debug(s"Adding thread context header required by lucene. Header: '${header.show}'") threadContext.putHeader(header.name.value.value, header.value.value) case Some(_) => } diff --git a/es88x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala b/es88x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala index 629696a91d..7aa2029a2a 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.admin.indices.template.get.{GetComponentTemplateAction, GetComposableIndexTemplateAction} import org.elasticsearch.action.admin.indices.template.put.{PutComponentTemplateAction, PutComposableIndexTemplateAction} @@ -46,7 +46,7 @@ import scala.jdk.CollectionConverters.* final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJsonParserFactory)(using Clock) extends DataStreamService - with Logging { + with RequestIdAwareLogging { override def checkDataStreamExists(dataStreamName: DataStreamName.Full): Task[Boolean] = execute { val request = new GetDataStreamAction.Request(List(dataStreamName.value.value).toArray) @@ -203,11 +203,11 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ response <- Task.measure( task = Task.delay(nodeClient.execute(action, request).actionGet()), logTimeMeasurement = duration => Task.delay { - logger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") + noRequestIdLogger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") } ) _ <- Task.delay { - logger.debug(s"Action ${action.name()} response: ${response.toString}") + noRequestIdLogger.debug(s"Action ${action.name()} response: ${response.toString}") } } yield response } @@ -215,7 +215,7 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ def executeAck[REQUEST <: ActionRequest, RESPONSE <: AcknowledgedResponse](action: ActionType[RESPONSE], request: REQUEST): Task[RESPONSE] = { executeT(action, request) - .tapEval(response => Task.delay(logger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) + .tapEval(response => Task.delay(noRequestIdLogger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) } private def supportedActions: Map[ActionType[ActionResponse], TransportAction[ActionRequest, ActionResponse]] = { diff --git a/es88x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala b/es88x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala index 2e75d37d0f..16259474bf 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.support.WriteRequest.RefreshPolicy import org.elasticsearch.client.internal.node.NodeClient @@ -38,7 +38,7 @@ import scala.jdk.CollectionConverters.* class EsIndexJsonContentService(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexJsonContentService - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -63,14 +63,14 @@ class EsIndexJsonContentService(client: NodeClient, Option(response.getSourceAsMap) match { case Some(map) => val source = map.asScala.toMap.asStringMap - logger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") Right(source) case None => - logger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") + noRequestIdLogger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") Right(Map.empty[String, String]) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(ContentNotFound) } } @@ -78,7 +78,7 @@ class EsIndexJsonContentService(client: NodeClient, .onErrorRecover { case _: ResourceNotFoundException => Left(ContentNotFound) case ex => - logger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) Left(CannotReachContentSource) } } @@ -104,14 +104,14 @@ class EsIndexJsonContentService(client: NodeClient, case status if status / 100 == 2 => Right(()) case status => - logger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") Left(CannotWriteToIndex) } } .executeOn(RorSchedulers.blockingScheduler) .onErrorRecover { case ex => - logger.error(s"Cannot write to document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]", ex) Left(CannotWriteToIndex) } } diff --git a/es88x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala b/es88x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala index 7d15a76306..df7ab14fec 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala @@ -22,7 +22,7 @@ import cats.kernel.Monoid import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task import monix.execution.CancelablePromise -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction.{ResolvedAlias, ResolvedIndex} @@ -63,7 +63,7 @@ class EsServerBasedRorClusterService(nodeName: String, nodeClient: NodeClient, threadPool: ThreadPool) extends RorClusterService - with Logging { + with RequestIdAwareLogging { import EsServerBasedRorClusterService.* @@ -154,7 +154,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractAccessibilityFrom) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify get request. Blocking document", ex) + logger.error(s"Could not verify get request. Blocking document", ex)(id) Inaccessible } } @@ -166,7 +166,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractResultsFromSearchResponse) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify documents returned by multi get response. Blocking all returned documents", ex) + logger.error(s"Could not verify documents returned by multi get response. Blocking all returned documents", ex)(id) blockAllDocsReturned(documents) } .map(results => zip(results, documents)) @@ -275,7 +275,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService): Task[List[FullRemoteDataStreamWithAliases]] = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -331,7 +331,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService) = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -417,7 +417,7 @@ class EsServerBasedRorClusterService(nodeName: String, } } case None => - logger.error("Cannot supply Snapshots Service. Please, report the issue!!!") + noRequestIdLogger.error("Cannot supply Snapshots Service. Please, report the issue!!!") Task.now(Set.empty[Snapshot]) } } diff --git a/es88x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala b/es88x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala index a657d15ca9..31d96f15a2 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.services import cats.data.NonEmptyList -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.bulk.{BackoffPolicy, BulkProcessor, BulkRequest, BulkResponse} import org.elasticsearch.action.index.IndexRequest import org.elasticsearch.action.{ActionListener, DocWriteRequest} @@ -39,7 +39,7 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, (using Clock) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { private val bulkProcessor = BulkProcessor @@ -80,25 +80,25 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, private class AuditSinkBulkProcessorListener extends BulkProcessor.Listener { override def beforeBulk(executionId: Long, request: BulkRequest): Unit = { - logger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") + noRequestIdLogger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") } override def afterBulk(executionId: Long, request: BulkRequest, response: BulkResponse): Unit = { if (response.hasFailures) { - logger.error("Some failures flushing the BulkProcessor: ") + noRequestIdLogger.error("Some failures flushing the BulkProcessor: ") response .getItems.to(LazyList) .filter(_.isFailed) .map(_.getFailureMessage) .groupBy(identity) .foreach { case (message, stream) => - logger.error(s"${stream.size}x: $message") + noRequestIdLogger.error(s"${stream.size}x: $message") } } } override def afterBulk(executionId: Long, request: BulkRequest, failure: Throwable): Unit = { - logger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) + noRequestIdLogger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) } } diff --git a/es88x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala b/es88x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala index a8def0ec7a..b3c5593c36 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala @@ -22,7 +22,7 @@ import org.apache.http.auth.{AuthScope, Credentials, UsernamePasswordCredentials import org.apache.http.conn.ssl.NoopHostnameVerifier import org.apache.http.impl.client.BasicCredentialsProvider import org.apache.http.impl.nio.client.HttpAsyncClientBuilder -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.* import org.elasticsearch.client.RestClient.FailureListener import tech.beshu.ror.accesscontrol.audit.sink.AuditDataStreamCreator @@ -38,7 +38,7 @@ import scala.collection.parallel.CollectionConverters.* final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient]) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { override def submit(indexName: IndexName.Full, documentId: String, jsonRecord: String) (implicit requestId: RequestId): Unit = { @@ -77,21 +77,21 @@ final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient] override def onSuccess(response: Response): Unit = { response.getStatusLine.getStatusCode / 100 match { case 2 => // 2xx - logger.debug(s"[${requestId.show}] Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") + logger.debug(s"Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") case _ => - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") } } override def onFailure(ex: Exception): Unit = { - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId]", ex) + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId]", ex) } } override val dataStreamCreator: AuditDataStreamCreator = new AuditDataStreamCreator(clients.map(new RestClientDataStreamService(_))) } -object RestClientAuditSinkService extends Logging { +object RestClientAuditSinkService extends RequestIdAwareLogging { def create(remoteCluster: AuditCluster.RemoteAuditCluster): RestClientAuditSinkService = { remoteCluster.mode match { @@ -122,7 +122,7 @@ object RestClientAuditSinkService extends Logging { .setFailureListener( new FailureListener { override def onFailure(node: Node): Unit = { - logger.debug( + noRequestIdLogger.debug( s"[AUDIT] Node marked dead: ${node.getHost.getSchemeName}://${node.getHost.getHostName}:${node.getHost.getPort}. The client will attempt failover.", ) } diff --git a/es88x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala b/es88x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala index 4a3437a056..ef5fbba1f9 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.Channel import io.netty.handler.ssl.NotSslRecordException -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.network.NetworkService import org.elasticsearch.common.settings.{ClusterSettings, Settings} import org.elasticsearch.http.netty4.Netty4HttpServerTransport @@ -41,7 +41,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, tracer: Tracer, fipsCompliant: Boolean) extends Netty4HttpServerTransport(settings, networkService, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory, tracer, TLSConfig.noTLS(), null, null) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, ssl.clientAuthenticationEnabled) @@ -49,7 +49,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, override def onException(channel: HttpChannel, cause: Exception): Unit = { if (!this.lifecycle.started) return - else if (cause.getCause.isInstanceOf[NotSslRecordException]) logger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) + else if (cause.getCause.isInstanceOf[NotSslRecordException]) noRequestIdLogger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) else super.onException(channel, cause) channel.close() } diff --git a/es88x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala b/es88x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala index ba64286bb4..ce09748e17 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.* import io.netty.handler.ssl.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.TransportVersion import org.elasticsearch.cluster.node.DiscoveryNode import org.elasticsearch.common.io.stream.NamedWriteableRegistry @@ -46,7 +46,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, sharedGroupFactory: SharedGroupFactory, fipsCompliant: Boolean) extends Netty4Transport(settings, TransportVersion.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = SSLCertHelper.prepareClientSSLContext(ssl, fipsCompliant, ssl.certificateVerificationEnabled) private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, clientAuthenticationEnabled = false) @@ -78,7 +78,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, override def exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable): Unit = { if (cause.isInstanceOf[NotSslRecordException] || (cause.getCause != null && cause.getCause.isInstanceOf[NotSslRecordException])) { - logger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") + noRequestIdLogger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") ctx.channel.close } else { super.exceptionCaught(ctx, cause) diff --git a/es88x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala b/es88x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala index a8e79a70fb..3883543495 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.utils import cats.Show import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.client.internal.node.NodeClient import org.elasticsearch.rest.* @@ -37,7 +37,7 @@ import java.util import scala.util.Try class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandler) - extends RestHandler with Logging { + extends RestHandler with RequestIdAwareLogging { private val wrapped = doPrivileged { wrapSomeActions(underlying) @@ -108,11 +108,11 @@ class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandle private def logError(error: AuthorizationValueError): Unit = { { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorSanitizedShow - logger.warn(s"The incoming request was malformed. Cause: ${error.show}") + noRequestIdLogger.warn(s"The incoming request was malformed. Cause: ${error.show}") } if (logger.delegate.isDebugEnabled()) { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorWithDetailsShow - logger.debug(s"Malformed request detailed cause: ${error.show}") + noRequestIdLogger.debug(s"Malformed request detailed cause: ${error.show}") } } diff --git a/es88x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala b/es88x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala index 5ab1e35742..a9af8f710a 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala @@ -16,13 +16,13 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.settings.Settings import tech.beshu.ror.tools.core.patches.PatchingVerifier import tech.beshu.ror.tools.core.patches.PatchingVerifier.Error.{CannotVerifyIfPatched, EsNotPatched} import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -object EsPatchVerifier extends Logging { +object EsPatchVerifier extends RequestIdAwareLogging { def verify(settings: Settings): Unit = doPrivileged { pathHomeFrom(settings).flatMap(PatchingVerifier.verify) match { @@ -30,7 +30,7 @@ object EsPatchVerifier extends Logging { case Left(e@EsNotPatched(_)) => throw new IllegalStateException(e.message) case Left(e@CannotVerifyIfPatched(_)) => - logger.warn(e.message) + noRequestIdLogger.warn(e.message) } } diff --git a/es88x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala b/es88x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala index 639aeb5029..893d807108 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.repositories.{RepositoriesService, VerifyNodeRepositoryAction} import org.elasticsearch.transport.{RemoteClusterService, TransportService} import org.joor.Reflect.on @@ -26,7 +26,7 @@ import java.util.function.Supplier import scala.util.{Failure, Success, Try} class RemoteClusterServiceSupplier(repositoriesServiceSupplier: Supplier[RepositoriesService]) - extends Supplier[Option[RemoteClusterService]] with Logging { + extends Supplier[Option[RemoteClusterService]] with RequestIdAwareLogging { override def get(): Option[RemoteClusterService] = { for { @@ -35,7 +35,7 @@ class RemoteClusterServiceSupplier(repositoriesServiceSupplier: Supplier[Reposit case Success(transportService) => Option(transportService.getRemoteClusterService) case Failure(ex) => - logger.error("Cannot extract RemoteClusterService from RepositoriesService", ex) + noRequestIdLogger.error("Cannot extract RemoteClusterService from RepositoriesService", ex) None } } yield remoteClusterService diff --git a/es89x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es89x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index 07d70bbf05..978eebec5d 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.support.{ActionFilter, ActionFilterChain} import org.elasticsearch.action.{ActionListener, ActionRequest, ActionResponse} import org.elasticsearch.client.internal.node.NodeClient @@ -62,7 +62,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, rorEsConfig: ReadonlyRestEsConfig) (implicit environmentConfig: EnvironmentConfig) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = environmentConfig.uniqueIdentifierGenerator @@ -211,12 +211,12 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def handleRorNotReadyYet(esContext: EsContext): Unit = { - logger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") + noRequestIdLogger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") rorNotAvailableRequestHandler.handleRorNotReadyYet(esContext) } private def handleRorFailedToStart(esContext: EsContext): Unit = { - logger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") + noRequestIdLogger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") rorNotAvailableRequestHandler.handleRorFailedToStart(esContext) } @@ -238,7 +238,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def logAndSetStartingFailureState(failure: StartingFailure): Unit = { - logger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) + noRequestIdLogger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) rorInstanceState.set(RorInstanceStartingState.NotStarted(failure)) } } diff --git a/es89x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala b/es89x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala index 1fb22fc79d..53452eb8e6 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.xcontent.LoggingDeprecationHandler import org.elasticsearch.rest.RestResponse import org.elasticsearch.transport.BytesRefRecycler @@ -32,7 +32,7 @@ import tech.beshu.ror.accesscontrol.domain.ResponseFieldsFiltering.{AccessMode, import scala.jdk.CollectionConverters.* trait ResponseFieldsFiltering { - this: Logging => + this: RequestIdAwareLogging => private val responseFieldsRestrictions: Atomic[Option[ResponseFieldsRestrictions]] = Atomic(None: Option[ResponseFieldsRestrictions]) diff --git a/es89x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala b/es89x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala index 0f26750588..da95de59a4 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.action.{ActionListener, ActionResponse} import org.elasticsearch.threadpool.ThreadPool @@ -37,7 +37,7 @@ sealed abstract class RorActionListener[T](val underlying: ActionListener[T]) ex final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionListener[T], correlationId: Eval[CorrelationId]) - extends RorActionListener[T](underlying) with Logging { + extends RorActionListener[T](underlying) with RequestIdAwareLogging { override def onFailure(e: Exception): Unit = { super.onFailure(adaptExceptionIfNeeded(e)) @@ -47,7 +47,7 @@ final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionLis ex match { case esException: ElasticsearchException => esException case other => - logger.error(s"[${correlationId.value.show}] Internal error.", other) + noRequestIdLogger.error(s"[${correlationId.value.show}] Internal error.", other) new ElasticsearchException(s"[${correlationId.value.show}] Internal error. See logs for details.") } } diff --git a/es89x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala b/es89x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala index 75048ebe7d..14e5e31c1b 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.http.HttpChannel import org.elasticsearch.rest.{AbstractRestChannel, RestChannel as EsRestChannel, RestRequest as EsRestRequest, RestResponse as EsRestResponse} import squants.information.{Bytes, Information} @@ -40,7 +40,7 @@ object RorRestChannel { final class RorRestChannel private(underlying: EsRestChannel, val restRequest: RorRestRequest) extends AbstractRestChannel(underlying.request(), true) with ResponseFieldsFiltering - with Logging { + with RequestIdAwareLogging { override def sendResponse(response: EsRestResponse): Unit = { ThreadRepo.removeRestChannel(this) diff --git a/es89x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala b/es89x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala index 6babc712b9..3c80750a25 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala @@ -18,16 +18,15 @@ package tech.beshu.ror.es.actions.rradmin import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.ConfigApi.ConfigResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAdminActionHandler extends Logging { +class RRAdminActionHandler extends RequestIdAwareLogging { private implicit val adminRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +51,7 @@ class RRAdminActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAdminResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAdminAction internal error", ex) + logger.error("RRAdminAction internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es89x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala b/es89x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala index c55835a1d0..ce45c6f48e 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala @@ -16,18 +16,15 @@ */ package tech.beshu.ror.es.actions.rrauthmock -import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.AuthMockApi.AuthMockResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier -import tech.beshu.ror.implicits.* +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAuthMockActionHandler extends Logging { +class RRAuthMockActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -53,7 +50,7 @@ class RRAuthMockActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAuthMockResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAuthMock internal error", ex) + logger.error("RRAuthMock internal error", ex) listener.onFailure(new Exception(ex)) } } diff --git a/es89x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala b/es89x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala index aa8bb31e67..640084c4ec 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestconfig import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.TestConfigApi.TestConfigResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestConfigActionHandler extends Logging { +class RRTestConfigActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +52,7 @@ class RRTestConfigActionHandler extends Logging { case Right(response) => listener.onResponse(new RRTestConfigResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRTestConfig internal error", ex) + logger.error(s"RRTestConfig internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es89x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala b/es89x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala index 494e9150b4..98cc0c945d 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.dlsfls import cats.data.StateT import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.DirectoryReader import org.elasticsearch.common.util.concurrent.ThreadContext import org.elasticsearch.core.CheckedFunction @@ -31,7 +31,7 @@ import java.io.IOException import java.util.function.{Function => JavaFunction} import scala.util.{Failure, Success, Try} -object RoleIndexSearcherWrapper extends Logging { +object RoleIndexSearcherWrapper extends RequestIdAwareLogging { val instance: JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] = new JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] { @@ -54,7 +54,7 @@ object RoleIndexSearcherWrapper extends Logging { } .map(r => (r, r)) case None => - logger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") + noRequestIdLogger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") Success((reader, reader)) } } @@ -66,13 +66,13 @@ object RoleIndexSearcherWrapper extends Logging { nel <- NonEmptyString.from(value) match { case Right(nel) => Success(nel) case Left(_) => - logger.debug("FLS: empty header value") + noRequestIdLogger.debug("FLS: empty header value") failure } fields <- transientFieldsFromHeaderValue.fromRawValue(nel) match { case result@Success(_) => result case Failure(ex) => - logger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) + noRequestIdLogger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) failure } } yield fields diff --git a/es89x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala b/es89x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala index ce77d77f4e..aeccbfcead 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.dlsfls import com.google.common.collect.Iterators -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.codecs.StoredFieldsReader import org.apache.lucene.index.* import org.apache.lucene.index.StoredFieldVisitor.Status @@ -39,21 +39,21 @@ import scala.jdk.CollectionConverters.* import scala.util.Try private class RorDocumentFieldReader(reader: LeafReader, fieldsRestrictions: FieldsRestrictions) - extends SequentialStoredFieldsLeafReader(reader) with Logging { + extends SequentialStoredFieldsLeafReader(reader) with RequestIdAwareLogging { private val policy = new FieldsPolicy(fieldsRestrictions) private val remainingFieldsInfo = { val fInfos = in.getFieldInfos val newInfos = if (fInfos.asScala.isEmpty) { - logger.warn("original fields were empty! This is weird!") + noRequestIdLogger.warn("original fields were empty! This is weird!") fInfos } else { val remainingFields = fInfos.asScala.filter(f => policy.canKeep(f.name)).toSet new FieldInfos(remainingFields.toArray) } - logger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") - logger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") - logger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") + noRequestIdLogger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") newInfos } private val jsonPolicyBasedFilterer = new JsonPolicyBasedFilterer(policy) diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala index 15add4a6dd..a4d939d26a 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.* import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest import org.elasticsearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest @@ -87,7 +87,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, threadPool: ThreadPool) (implicit generator: UniqueIdentifierGenerator, scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle(engines: Engines, esContext: EsContext): Task[Either[Error, Unit]] = { @@ -242,7 +242,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, case SearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case MultiSearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case _ => - logger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") + noRequestIdLogger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") regularRequestHandler.handle(new DummyCompositeIndicesEsRequestContext(request, esContext, aclContext, clusterService, threadPool)) } // rest diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala index cab02aff37..100edd72ac 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.common.io.stream.StreamOutput import org.elasticsearch.xcontent.{ToXContent, ToXContentObject, XContentBuilder} @@ -45,7 +45,7 @@ import scala.util.{Failure, Success, Try} class CurrentUserMetadataRequestHandler(engine: Engine, esContext: EsContext) - extends Logging { + extends RequestIdAwareLogging { def handle(request: RequestContext.Aux[CurrentUserMetadataRequestBlockContext] with EsRequest[CurrentUserMetadataRequestBlockContext]): Task[Unit] = { engine.core.accessControl @@ -69,7 +69,7 @@ class CurrentUserMetadataRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(ex.asInstanceOf[Exception]) } } @@ -86,13 +86,13 @@ class CurrentUserMetadataRequestHandler(engine: Engine, )) } - private def onPassThrough(requestContext: RequestContext): Unit = { - logger.warn(s"[${requestContext.id.toRequestId.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") + private def onPassThrough(implicit requestContext: RequestContext): Unit = { + logger.warn(s"Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") esContext.listener.onFailure(createRorNotEnabledResponse()) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala index 2fb01dcc41..c5c44fda92 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala @@ -20,7 +20,7 @@ import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.RegularRequestResult @@ -49,7 +49,7 @@ class RegularRequestHandler(engine: Engine, esContext: EsContext, threadPool: ThreadPool) (implicit scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle[B <: BlockContext : BlockContextUpdater](request: RequestContext.Aux[B] with EsRequest[B]): Task[Unit] = { engine.core.accessControl @@ -85,7 +85,7 @@ class RegularRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(new Exception(ex)) } } @@ -99,7 +99,7 @@ class RegularRequestHandler(engine: Engine, case ModificationResult.ShouldBeInterrupted => onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case ModificationResult.CannotModify => - logger.error(s"[${request.id.toRequestId.show}] Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") + noRequestIdLogger.error(s"Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case CustomResponse(response) => respond(request, response) @@ -247,7 +247,7 @@ class RegularRequestHandler(engine: Engine, esContext.listener.onResponse(response) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } \ No newline at end of file diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala index f4f832dedc..bfc421bdd5 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.index.query.{AbstractQueryBuilder, QueryBuilder, QueryBuilders} import org.elasticsearch.search.aggregations.AggregatorFactories @@ -40,7 +40,7 @@ import tech.beshu.ror.implicits.* import java.util.UUID import scala.jdk.CollectionConverters.* -object SearchRequestOps extends Logging { +object SearchRequestOps extends RequestIdAwareLogging { implicit class QueryBuilderOps(val builder: Option[QueryBuilder]) extends AnyVal { @@ -52,7 +52,7 @@ object SearchRequestOps extends Logging { val modifiedQuery: AbstractQueryBuilder[_] = provideNewQueryWithAppliedFilter(builder, filterQuery) Some(modifiedQuery) case None => - logger.debug(s"[${requestId.show}] No filter applied to query.") + logger.debug(s"No filter applied to query.") builder } } @@ -92,7 +92,7 @@ object SearchRequestOps extends Logging { case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, requestId) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) disableCaching(requestId) case BasedOnBlockContextOnly.NotAllowedFieldsUsed(notAllowedFields) => modifyNotAllowedFieldsInRequest(notAllowedFields) @@ -138,8 +138,8 @@ object SearchRequestOps extends Logging { } } - private def disableCaching(requestId: RequestContext.Id) = { - logger.debug(s"[${requestId.show}] ACL uses context header for fields rule, will disable request cache for SearchRequest") + private def disableCaching(implicit requestId: RequestContext.Id) = { + logger.debug(s"ACL uses context header for fields rule, will disable request cache for SearchRequest") request.requestCache(false) } } diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala index 270367a54f..e2884598df 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala @@ -17,7 +17,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.action.support.IndicesOptions.WildcardStates import org.elasticsearch.action.{CompositeIndicesRequest, IndicesRequest} @@ -34,7 +33,7 @@ import scala.jdk.CollectionConverters.* abstract class BaseEsRequestContext[B <: BlockContext](esContext: EsContext, clusterService: RorClusterService) - extends RequestContext with Logging { + extends RequestContext { override type BLOCK_CONTEXT = B diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala index ae8abbe1f5..0ee2967364 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala @@ -18,7 +18,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -26,8 +25,9 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import scala.util.Try +import tech.beshu.ror.utils.RequestIdAwareLogging -trait EsRequest[B <: BlockContext] extends Logging { +trait EsRequest[B <: BlockContext] extends RequestIdAwareLogging { implicit def threadPool: ThreadPool final def modifyUsing(blockContext: B): ModificationResult = { @@ -35,7 +35,7 @@ trait EsRequest[B <: BlockContext] extends Logging { Try(modifyRequest(blockContext)) .fold( ex => { - logger.error(s"[${blockContext.requestContext.id.show}] Cannot modify request with filtered data", ex) + logger.error(s"Cannot modify request with filtered data", ex)(blockContext) ModificationResult.CannotModify }, identity diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala index c6a9dcbefd..f773b3efb1 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala @@ -51,7 +51,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest private def discoverDataStreams() = { val dataStreams = dataStreamsFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered data streams: ${dataStreams.show}") + logger.debug(s"Discovered data streams: ${dataStreams.show}") dataStreams } @@ -59,7 +59,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest val backingIndices = backingIndicesFrom(actionRequest) backingIndices match { case BackingIndices.IndicesInvolved(filteredIndices, _) => - logger.debug(s"[${id.show}] Discovered indices: ${filteredIndices.show}") + logger.debug(s"Discovered indices: ${filteredIndices.show}") case BackingIndices.IndicesNotInvolved => } backingIndices diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala index c091179cb6..d150709314 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala @@ -85,7 +85,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: case Some(indices) => update(actionRequest, indices, blockContext.filter, blockContext.fieldLevelSecurity) case None => - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -101,7 +101,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } \ No newline at end of file diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala index 71d462de57..48014e1bdc 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala @@ -73,7 +73,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, } yield update(actionRequest, filteredIndices, allAllowedIndices) result.getOrElse { - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -86,7 +86,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala index 95d882c3b5..f607c0e347 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala @@ -50,7 +50,7 @@ abstract class BaseRepositoriesEsRequestContext[R <: ActionRequest](actionReques case Some(repositories) => update(actionRequest, repositories) case None => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") ShouldBeInterrupted } } diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala index b3b1d66238..7ef0f32014 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala @@ -42,7 +42,7 @@ abstract class BaseSingleIndexEsRequestContext[R <: ActionRequest](actionRequest filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } update(request, filteredIndices.head) } diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala index b5ab70fe7a..c1b2e7ea27 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala @@ -62,7 +62,7 @@ class BulkEsRequestContext(actionRequest: BulkRequest, case (_, _) => ShouldBeInterrupted } } else { - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because origin request contained different " + + logger.error(s"Cannot alter MultiGetRequest request, because origin request contained different " + s"number of requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } @@ -90,18 +90,18 @@ class BulkEsRequestContext(actionRequest: BulkRequest, updateRequestWithIndices(request, nel) Modified case None => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because empty list of indices was found") + logger.error(s"Cannot alter MultiGetRequest request, because empty list of indices was found") ShouldBeInterrupted } case Indices.NotFound => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because no allowed indices were found") + logger.error(s"Cannot alter MultiGetRequest request, because no allowed indices were found") ShouldBeInterrupted } } private def updateRequestWithIndices(request: DocWriteRequest[_], indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } request.index(indices.head.stringify) } diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala index 75a75fcef5..96a043b298 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala @@ -53,14 +53,14 @@ class BulkShardEsRequestContext(actionRequest: BulkShardRequest, case Success(_) => Modified case Failure(ex) => - logger.error(s"[${id.show}] Cannot modify BulkShardRequest", ex) + logger.error(s"Cannot modify BulkShardRequest", ex) CannotModify } } private def tryUpdate(request: BulkShardRequest, indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } val singleIndex = indices.head val uuid = clusterService.indexOrAliasUuids(singleIndex.name).toList.head diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala index 65a168092a..158ac485a5 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala @@ -45,14 +45,14 @@ class ClusterAllocationExplainEsRequestContext(actionRequest: ClusterAllocationE getRequestedIndexFrom(request) match { case Some(_) => if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateIndexIn(request, filteredIndices.head) Modified case None if filteredIndices.exists(_.name === ClusterIndexName.Local.wildcard) => Modified case None => - logger.error(s"[${id.show}] Cluster allocation explain request without index name is unavailable when block contains `indices` rule") + logger.error(s"Cluster allocation explain request without index name is unavailable when block contains `indices` rule") ShouldBeInterrupted } } diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala index 5778b8968d..02dec730ed 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala @@ -66,7 +66,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, updateAliases(actionRequest, aliases) UpdateResponse.sync(updateAliasesResponse(aliases.includedOnly, _)) case None => - logger.error(s"[${id.show}] At least one alias and one index has to be allowed. " + + logger.error(s"At least one alias and one index has to be allowed. " + s"Found allowed indices: [${blockContext.indices.show}]." + s"Found allowed aliases: [${blockContext.aliases.show}]") ShouldBeInterrupted @@ -114,7 +114,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, .indices().asSafeSet .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } @@ -122,7 +122,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, val aliases = rawRequestAliasesSet(request) .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered aliases: ${aliases.show}") + logger.debug(s"Discovered aliases: ${aliases.show}") aliases } diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala index abb85d42b7..f9e2c87e53 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala @@ -55,7 +55,7 @@ class IndicesAliasesEsRequestContext(actionRequest: IndicesAliasesRequest, if (originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala index 05b70606b9..37dd50452b 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala @@ -119,7 +119,7 @@ class MultiGetEsRequestContext(actionRequest: MultiGetRequest, case Nil => updateItemWithNonExistingIndex(item) case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } item.index(index.stringify) } diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala index 989956d79a..9e13edee8d 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala @@ -78,7 +78,7 @@ class MultiSearchEsRequestContext(actionRequest: MultiSearchRequest, } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala index 9191e33b66..5a61356f48 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala @@ -47,7 +47,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { request.getRequests.removeIf { request => removeOrAlter(request, filteredIndices.toCovariantSet) } if (request.getRequests.asScala.isEmpty) { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") ShouldBeInterrupted } else { Modified @@ -63,7 +63,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, true case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") } request.index(index.stringify) false diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala index c411df93c5..c7b99f6e85 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala @@ -52,7 +52,7 @@ class PutRollupJobEsRequestContext private(actionRequest: ActionRequest, if(originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala index 141d9db788..fff8ed58bb 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala @@ -49,7 +49,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (tryUpdate(actionRequest, filteredIndices)) Modified else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") ShouldBeInterrupted } } diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala index 489d0187bc..c42dfc3b78 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala @@ -58,10 +58,10 @@ class ReindexEsRequestContext(actionRequest: ReindexRequest, Modified } else { if (!isDestinationIndexOnFilteredIndicesList) { - logger.info(s"[${id.show}] Destination index of _reindex request is forbidden") + logger.info(s"Destination index of _reindex request is forbidden") } if (!isSearchRequestComposedOnlyOfAllowedIndices) { - logger.info(s"[${id.show}] At least one index from sources indices list of _reindex request is forbidden") + logger.info(s"At least one index from sources indices list of _reindex request is forbidden") } ShouldBeInterrupted } diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala index 2c1b0014e0..97b8ccd9c5 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala @@ -74,7 +74,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo request } case Left(_) => - logger.debug(s"[${id.show}] Cannot parse SQL statement - we can pass it though, because ES is going to reject it") + logger.debug(s"Cannot parse SQL statement - we can pass it though, because ES is going to reject it") request } } @@ -85,7 +85,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala index 0c67384c1e..d7e743e648 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CleanupRepositoryEsRequestContext(actionRequest: CleanupRepositoryRequest, override protected def update(request: CleanupRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala index 44b7d78dfd..d09015139b 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CreateRepositoryEsRequestContext(actionRequest: PutRepositoryRequest, override protected def update(request: PutRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala index eaf9334872..0cf32e1bea 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class DeleteRepositoryEsRequestContext(actionRequest: DeleteRepositoryRequest, override protected def update(request: DeleteRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala index cee0bffd4c..d1410eff3d 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class VerifyRepositoryEsRequestContext(actionRequest: VerifyRepositoryRequest, override protected def update(request: VerifyRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala index ead4fcf250..20501516d5 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala @@ -68,32 +68,32 @@ class CreateSnapshotEsRequestContext(actionRequest: CreateSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala index a56aba660e..621d744767 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala @@ -60,7 +60,7 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -71,14 +71,14 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, .toRight(()) } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala index 22869bbb4f..b81f333174 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala @@ -68,7 +68,7 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, case r => r } case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala index 88887db96c..156deb5b80 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala @@ -63,7 +63,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -75,7 +75,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") } Right(snapshot) } @@ -88,7 +88,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala index 44ee8397ec..e522e440f1 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala @@ -100,12 +100,12 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { val repositories = blockContext.repositories if (allRepositoriesRequested(repositories)) { Right(RepositoryName.All) @@ -115,7 +115,7 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala index 80e36a6d77..d8e5182eed 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.GetComposableIndexTemplateAction import org.elasticsearch.cluster.metadata import org.elasticsearch.cluster.metadata.ComposableIndexTemplate @@ -108,7 +108,7 @@ class GetComposableIndexTemplateEsRequestContext(actionRequest: GetComposableInd } -private[templates] object GetComposableIndexTemplateEsRequestContext extends Logging { +private[templates] object GetComposableIndexTemplateEsRequestContext extends RequestIdAwareLogging { def filter(templates: Map[String, ComposableIndexTemplate], usingTemplate: Set[Template] => Set[Template]) diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala index bd74c3a18f..1c6eecf409 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.{GetIndexTemplatesRequest, GetIndexTemplatesResponse} import org.elasticsearch.cluster.metadata.{AliasMetadata, IndexTemplateMetadata} import org.elasticsearch.common.collect.ImmutableOpenMap @@ -104,7 +104,7 @@ class GetTemplatesEsRequestContext(actionRequest: GetIndexTemplatesRequest, } -private[templates] object GetTemplatesEsRequestContext extends Logging { +private[templates] object GetTemplatesEsRequestContext extends RequestIdAwareLogging { def filter(templates: Iterable[IndexTemplateMetadata], usingTemplate: Set[Template] => Set[Template]) diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala index a8951de5b1..32116d8212 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala @@ -72,7 +72,7 @@ class MultiSearchTemplateEsRequestContext private(actionRequest: ActionRequest w } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala index e6f6d8916e..434787a686 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala @@ -55,7 +55,7 @@ class SimulateIndexTemplateRequestEsRequestContext(actionRequest: SimulateIndexT filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateRequest(request, filteredIndices.head, allAllowedIndices) } diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala index fbc4cf6776..46ed6e7a95 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala @@ -109,7 +109,7 @@ class SimulateExistingTemplateRequestEsRequestContext(existingTemplateName: Temp case Some(_) => updateResponse(namePatterns.toList, blockContext.allAllowedIndices.toList) case None => - logger.info(s"[${id.show}] User has no access to template ${existingTemplateName.show}") + logger.info(s"User has no access to template ${existingTemplateName.show}") ModificationResult.ShouldBeInterrupted } case other => diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala index 0ecd7a72b3..fe4d60bd42 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.queries import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.index.query.* import org.joor.Reflect.on import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.RequestFieldsUsage @@ -30,7 +30,7 @@ trait QueryFieldsUsage[QUERY <: QueryBuilder] { def fieldsIn(query: QUERY): RequestFieldsUsage } -object QueryFieldsUsage extends Logging { +object QueryFieldsUsage extends RequestIdAwareLogging { def apply[QUERY <: QueryBuilder](implicit ev: QueryFieldsUsage[QUERY]): QueryFieldsUsage[QUERY] = ev implicit class Ops[QUERY <: QueryBuilder : QueryFieldsUsage](val query: QUERY) { @@ -62,7 +62,7 @@ object QueryFieldsUsage extends Logging { Option(on(query).call("getFieldName").get[String]) match { case Some(fieldName: String) => UsingFields(NonEmptyList.one(UsedField(fieldName))) case _ => - logger.debug(s"Cannot extract fields for terms set query") + noRequestIdLogger.debug(s"Cannot extract fields for terms set query") CannotExtractFields } } @@ -89,7 +89,7 @@ object QueryFieldsUsage extends Logging { case builder: TermsSetQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder: WildcardQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder => - logger.debug(s"Cannot extract fields for query: ${builder.getName}") + noRequestIdLogger.debug(s"Cannot extract fields for query: ${builder.getName}") CannotExtractFields } diff --git a/es89x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala b/es89x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala index 0998bb9a5b..b4671e9e4d 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.handler.response import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.FieldsRestrictions import tech.beshu.ror.accesscontrol.domain.Header @@ -26,17 +26,17 @@ import tech.beshu.ror.accesscontrol.headerValues.transientFieldsToHeaderValue import tech.beshu.ror.accesscontrol.request.RequestContext import tech.beshu.ror.implicits.* -object FLSContextHeaderHandler extends Logging { +object FLSContextHeaderHandler extends RequestIdAwareLogging { def addContextHeader(threadPool: ThreadPool, - fieldsRestrictions: FieldsRestrictions, - requestId: RequestContext.Id): Unit = { + fieldsRestrictions: FieldsRestrictions) + (implicit requestId: RequestContext.Id): Unit = { val threadContext = threadPool.getThreadContext val header = createContextHeader(fieldsRestrictions) Option(threadContext.getHeader(header.name.value.value)) match { case None => implicit val show = headerShow - logger.debug(s"[${requestId.show}] Adding thread context header required by lucene. Header: '${header.show}'") + logger.debug(s"Adding thread context header required by lucene. Header: '${header.show}'") threadContext.putHeader(header.name.value.value, header.value.value) case Some(_) => } diff --git a/es89x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala b/es89x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala index 629696a91d..7aa2029a2a 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.admin.indices.template.get.{GetComponentTemplateAction, GetComposableIndexTemplateAction} import org.elasticsearch.action.admin.indices.template.put.{PutComponentTemplateAction, PutComposableIndexTemplateAction} @@ -46,7 +46,7 @@ import scala.jdk.CollectionConverters.* final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJsonParserFactory)(using Clock) extends DataStreamService - with Logging { + with RequestIdAwareLogging { override def checkDataStreamExists(dataStreamName: DataStreamName.Full): Task[Boolean] = execute { val request = new GetDataStreamAction.Request(List(dataStreamName.value.value).toArray) @@ -203,11 +203,11 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ response <- Task.measure( task = Task.delay(nodeClient.execute(action, request).actionGet()), logTimeMeasurement = duration => Task.delay { - logger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") + noRequestIdLogger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") } ) _ <- Task.delay { - logger.debug(s"Action ${action.name()} response: ${response.toString}") + noRequestIdLogger.debug(s"Action ${action.name()} response: ${response.toString}") } } yield response } @@ -215,7 +215,7 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ def executeAck[REQUEST <: ActionRequest, RESPONSE <: AcknowledgedResponse](action: ActionType[RESPONSE], request: REQUEST): Task[RESPONSE] = { executeT(action, request) - .tapEval(response => Task.delay(logger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) + .tapEval(response => Task.delay(noRequestIdLogger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) } private def supportedActions: Map[ActionType[ActionResponse], TransportAction[ActionRequest, ActionResponse]] = { diff --git a/es89x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala b/es89x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala index 2e75d37d0f..16259474bf 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.support.WriteRequest.RefreshPolicy import org.elasticsearch.client.internal.node.NodeClient @@ -38,7 +38,7 @@ import scala.jdk.CollectionConverters.* class EsIndexJsonContentService(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexJsonContentService - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -63,14 +63,14 @@ class EsIndexJsonContentService(client: NodeClient, Option(response.getSourceAsMap) match { case Some(map) => val source = map.asScala.toMap.asStringMap - logger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") Right(source) case None => - logger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") + noRequestIdLogger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") Right(Map.empty[String, String]) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(ContentNotFound) } } @@ -78,7 +78,7 @@ class EsIndexJsonContentService(client: NodeClient, .onErrorRecover { case _: ResourceNotFoundException => Left(ContentNotFound) case ex => - logger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) Left(CannotReachContentSource) } } @@ -104,14 +104,14 @@ class EsIndexJsonContentService(client: NodeClient, case status if status / 100 == 2 => Right(()) case status => - logger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") Left(CannotWriteToIndex) } } .executeOn(RorSchedulers.blockingScheduler) .onErrorRecover { case ex => - logger.error(s"Cannot write to document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]", ex) Left(CannotWriteToIndex) } } diff --git a/es89x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala b/es89x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala index 7d15a76306..df7ab14fec 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala @@ -22,7 +22,7 @@ import cats.kernel.Monoid import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task import monix.execution.CancelablePromise -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction.{ResolvedAlias, ResolvedIndex} @@ -63,7 +63,7 @@ class EsServerBasedRorClusterService(nodeName: String, nodeClient: NodeClient, threadPool: ThreadPool) extends RorClusterService - with Logging { + with RequestIdAwareLogging { import EsServerBasedRorClusterService.* @@ -154,7 +154,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractAccessibilityFrom) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify get request. Blocking document", ex) + logger.error(s"Could not verify get request. Blocking document", ex)(id) Inaccessible } } @@ -166,7 +166,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractResultsFromSearchResponse) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify documents returned by multi get response. Blocking all returned documents", ex) + logger.error(s"Could not verify documents returned by multi get response. Blocking all returned documents", ex)(id) blockAllDocsReturned(documents) } .map(results => zip(results, documents)) @@ -275,7 +275,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService): Task[List[FullRemoteDataStreamWithAliases]] = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -331,7 +331,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService) = { Try(remoteClusterService.getRemoteClusterClient(threadPool, remoteClusterName.value.value)) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -417,7 +417,7 @@ class EsServerBasedRorClusterService(nodeName: String, } } case None => - logger.error("Cannot supply Snapshots Service. Please, report the issue!!!") + noRequestIdLogger.error("Cannot supply Snapshots Service. Please, report the issue!!!") Task.now(Set.empty[Snapshot]) } } diff --git a/es89x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala b/es89x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala index a657d15ca9..31d96f15a2 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.services import cats.data.NonEmptyList -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.bulk.{BackoffPolicy, BulkProcessor, BulkRequest, BulkResponse} import org.elasticsearch.action.index.IndexRequest import org.elasticsearch.action.{ActionListener, DocWriteRequest} @@ -39,7 +39,7 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, (using Clock) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { private val bulkProcessor = BulkProcessor @@ -80,25 +80,25 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, private class AuditSinkBulkProcessorListener extends BulkProcessor.Listener { override def beforeBulk(executionId: Long, request: BulkRequest): Unit = { - logger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") + noRequestIdLogger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") } override def afterBulk(executionId: Long, request: BulkRequest, response: BulkResponse): Unit = { if (response.hasFailures) { - logger.error("Some failures flushing the BulkProcessor: ") + noRequestIdLogger.error("Some failures flushing the BulkProcessor: ") response .getItems.to(LazyList) .filter(_.isFailed) .map(_.getFailureMessage) .groupBy(identity) .foreach { case (message, stream) => - logger.error(s"${stream.size}x: $message") + noRequestIdLogger.error(s"${stream.size}x: $message") } } } override def afterBulk(executionId: Long, request: BulkRequest, failure: Throwable): Unit = { - logger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) + noRequestIdLogger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) } } diff --git a/es89x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala b/es89x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala index a8def0ec7a..b3c5593c36 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala @@ -22,7 +22,7 @@ import org.apache.http.auth.{AuthScope, Credentials, UsernamePasswordCredentials import org.apache.http.conn.ssl.NoopHostnameVerifier import org.apache.http.impl.client.BasicCredentialsProvider import org.apache.http.impl.nio.client.HttpAsyncClientBuilder -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.* import org.elasticsearch.client.RestClient.FailureListener import tech.beshu.ror.accesscontrol.audit.sink.AuditDataStreamCreator @@ -38,7 +38,7 @@ import scala.collection.parallel.CollectionConverters.* final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient]) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { override def submit(indexName: IndexName.Full, documentId: String, jsonRecord: String) (implicit requestId: RequestId): Unit = { @@ -77,21 +77,21 @@ final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient] override def onSuccess(response: Response): Unit = { response.getStatusLine.getStatusCode / 100 match { case 2 => // 2xx - logger.debug(s"[${requestId.show}] Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") + logger.debug(s"Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") case _ => - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") } } override def onFailure(ex: Exception): Unit = { - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId]", ex) + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId]", ex) } } override val dataStreamCreator: AuditDataStreamCreator = new AuditDataStreamCreator(clients.map(new RestClientDataStreamService(_))) } -object RestClientAuditSinkService extends Logging { +object RestClientAuditSinkService extends RequestIdAwareLogging { def create(remoteCluster: AuditCluster.RemoteAuditCluster): RestClientAuditSinkService = { remoteCluster.mode match { @@ -122,7 +122,7 @@ object RestClientAuditSinkService extends Logging { .setFailureListener( new FailureListener { override def onFailure(node: Node): Unit = { - logger.debug( + noRequestIdLogger.debug( s"[AUDIT] Node marked dead: ${node.getHost.getSchemeName}://${node.getHost.getHostName}:${node.getHost.getPort}. The client will attempt failover.", ) } diff --git a/es89x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala b/es89x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala index 56afacb5bb..46e39aa197 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.Channel import io.netty.handler.ssl.NotSslRecordException -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.network.NetworkService import org.elasticsearch.common.settings.{ClusterSettings, Settings} import org.elasticsearch.http.netty4.Netty4HttpServerTransport @@ -41,7 +41,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, tracer: Tracer, fipsCompliant: Boolean) extends Netty4HttpServerTransport(settings, networkService, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory, tracer, TLSConfig.noTLS(), null, null) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, ssl.clientAuthenticationEnabled) @@ -49,7 +49,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, override def onException(channel: HttpChannel, cause: Exception): Unit = { if (!this.lifecycle.started) return - else if (cause.getCause.isInstanceOf[NotSslRecordException]) logger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) + else if (cause.getCause.isInstanceOf[NotSslRecordException]) noRequestIdLogger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) else super.onException(channel, cause) channel.close() } diff --git a/es89x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala b/es89x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala index 2fa1d7871c..2d2b0360d4 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.* import io.netty.handler.ssl.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.TransportVersion import org.elasticsearch.cluster.node.DiscoveryNode import org.elasticsearch.common.io.stream.NamedWriteableRegistry @@ -46,7 +46,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, sharedGroupFactory: SharedGroupFactory, fipsCompliant: Boolean) extends Netty4Transport(settings, TransportVersion.current(), threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = SSLCertHelper.prepareClientSSLContext(ssl, fipsCompliant, ssl.certificateVerificationEnabled) private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, clientAuthenticationEnabled = false) @@ -78,7 +78,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, override def exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable): Unit = { if (cause.isInstanceOf[NotSslRecordException] || (cause.getCause != null && cause.getCause.isInstanceOf[NotSslRecordException])) { - logger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") + noRequestIdLogger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") ctx.channel.close } else { super.exceptionCaught(ctx, cause) diff --git a/es89x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala b/es89x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala index 599b91f985..08cd714687 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.utils import cats.Show import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.client.internal.node.NodeClient import org.elasticsearch.rest.* @@ -37,7 +37,7 @@ import java.util import scala.util.Try class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandler) - extends RestHandler with Logging { + extends RestHandler with RequestIdAwareLogging { private val wrapped = doPrivileged { wrapSomeActions(underlying) @@ -109,11 +109,11 @@ class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandle private def logError(error: AuthorizationValueError): Unit = { { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorSanitizedShow - logger.warn(s"The incoming request was malformed. Cause: ${error.show}") + noRequestIdLogger.warn(s"The incoming request was malformed. Cause: ${error.show}") } if (logger.delegate.isDebugEnabled()) { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorWithDetailsShow - logger.debug(s"Malformed request detailed cause: ${error.show}") + noRequestIdLogger.debug(s"Malformed request detailed cause: ${error.show}") } } diff --git a/es89x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala b/es89x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala index 5ab1e35742..a9af8f710a 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala @@ -16,13 +16,13 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.settings.Settings import tech.beshu.ror.tools.core.patches.PatchingVerifier import tech.beshu.ror.tools.core.patches.PatchingVerifier.Error.{CannotVerifyIfPatched, EsNotPatched} import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -object EsPatchVerifier extends Logging { +object EsPatchVerifier extends RequestIdAwareLogging { def verify(settings: Settings): Unit = doPrivileged { pathHomeFrom(settings).flatMap(PatchingVerifier.verify) match { @@ -30,7 +30,7 @@ object EsPatchVerifier extends Logging { case Left(e@EsNotPatched(_)) => throw new IllegalStateException(e.message) case Left(e@CannotVerifyIfPatched(_)) => - logger.warn(e.message) + noRequestIdLogger.warn(e.message) } } diff --git a/es89x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala b/es89x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala index 639aeb5029..893d807108 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.repositories.{RepositoriesService, VerifyNodeRepositoryAction} import org.elasticsearch.transport.{RemoteClusterService, TransportService} import org.joor.Reflect.on @@ -26,7 +26,7 @@ import java.util.function.Supplier import scala.util.{Failure, Success, Try} class RemoteClusterServiceSupplier(repositoriesServiceSupplier: Supplier[RepositoriesService]) - extends Supplier[Option[RemoteClusterService]] with Logging { + extends Supplier[Option[RemoteClusterService]] with RequestIdAwareLogging { override def get(): Option[RemoteClusterService] = { for { @@ -35,7 +35,7 @@ class RemoteClusterServiceSupplier(repositoriesServiceSupplier: Supplier[Reposit case Success(transportService) => Option(transportService.getRemoteClusterService) case Failure(ex) => - logger.error("Cannot extract RemoteClusterService from RepositoriesService", ex) + noRequestIdLogger.error("Cannot extract RemoteClusterService from RepositoriesService", ex) None } } yield remoteClusterService diff --git a/es90x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es90x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index c32aac4d9a..9d665fd7b9 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.support.{ActionFilter, ActionFilterChain} import org.elasticsearch.action.{ActionListener, ActionRequest, ActionResponse} import org.elasticsearch.client.internal.node.NodeClient @@ -62,7 +62,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, rorEsConfig: ReadonlyRestEsConfig) (implicit environmentConfig: EnvironmentConfig) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = environmentConfig.uniqueIdentifierGenerator @@ -208,12 +208,12 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def handleRorNotReadyYet(esContext: EsContext): Unit = { - logger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") + noRequestIdLogger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") rorNotAvailableRequestHandler.handleRorNotReadyYet(esContext) } private def handleRorFailedToStart(esContext: EsContext): Unit = { - logger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") + noRequestIdLogger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") rorNotAvailableRequestHandler.handleRorFailedToStart(esContext) } @@ -235,7 +235,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def logAndSetStartingFailureState(failure: StartingFailure): Unit = { - logger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) + noRequestIdLogger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) rorInstanceState.set(RorInstanceStartingState.NotStarted(failure)) } } diff --git a/es90x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala b/es90x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala index 1fb22fc79d..53452eb8e6 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.xcontent.LoggingDeprecationHandler import org.elasticsearch.rest.RestResponse import org.elasticsearch.transport.BytesRefRecycler @@ -32,7 +32,7 @@ import tech.beshu.ror.accesscontrol.domain.ResponseFieldsFiltering.{AccessMode, import scala.jdk.CollectionConverters.* trait ResponseFieldsFiltering { - this: Logging => + this: RequestIdAwareLogging => private val responseFieldsRestrictions: Atomic[Option[ResponseFieldsRestrictions]] = Atomic(None: Option[ResponseFieldsRestrictions]) diff --git a/es90x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala b/es90x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala index 0f26750588..da95de59a4 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.action.{ActionListener, ActionResponse} import org.elasticsearch.threadpool.ThreadPool @@ -37,7 +37,7 @@ sealed abstract class RorActionListener[T](val underlying: ActionListener[T]) ex final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionListener[T], correlationId: Eval[CorrelationId]) - extends RorActionListener[T](underlying) with Logging { + extends RorActionListener[T](underlying) with RequestIdAwareLogging { override def onFailure(e: Exception): Unit = { super.onFailure(adaptExceptionIfNeeded(e)) @@ -47,7 +47,7 @@ final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionLis ex match { case esException: ElasticsearchException => esException case other => - logger.error(s"[${correlationId.value.show}] Internal error.", other) + noRequestIdLogger.error(s"[${correlationId.value.show}] Internal error.", other) new ElasticsearchException(s"[${correlationId.value.show}] Internal error. See logs for details.") } } diff --git a/es90x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala b/es90x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala index 4f0bc8c6fa..c68cc24623 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.http.HttpChannel import org.elasticsearch.rest.{AbstractRestChannel, RestChannel as EsRestChannel, RestRequest as EsRestRequest, RestResponse as EsRestResponse} import squants.information.{Bytes, Information} @@ -40,7 +40,7 @@ object RorRestChannel { final class RorRestChannel private(underlying: EsRestChannel, val restRequest: RorRestRequest) extends AbstractRestChannel(underlying.request(), true) with ResponseFieldsFiltering - with Logging { + with RequestIdAwareLogging { override def sendResponse(response: EsRestResponse): Unit = { ThreadRepo.removeRestChannel(this) diff --git a/es90x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala b/es90x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala index 6babc712b9..3c80750a25 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala @@ -18,16 +18,15 @@ package tech.beshu.ror.es.actions.rradmin import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.ConfigApi.ConfigResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAdminActionHandler extends Logging { +class RRAdminActionHandler extends RequestIdAwareLogging { private implicit val adminRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +51,7 @@ class RRAdminActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAdminResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAdminAction internal error", ex) + logger.error("RRAdminAction internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es90x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala b/es90x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala index c55835a1d0..ce45c6f48e 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala @@ -16,18 +16,15 @@ */ package tech.beshu.ror.es.actions.rrauthmock -import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.AuthMockApi.AuthMockResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier -import tech.beshu.ror.implicits.* +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAuthMockActionHandler extends Logging { +class RRAuthMockActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -53,7 +50,7 @@ class RRAuthMockActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAuthMockResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAuthMock internal error", ex) + logger.error("RRAuthMock internal error", ex) listener.onFailure(new Exception(ex)) } } diff --git a/es90x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala b/es90x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala index aa8bb31e67..640084c4ec 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestconfig import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.TestConfigApi.TestConfigResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestConfigActionHandler extends Logging { +class RRTestConfigActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +52,7 @@ class RRTestConfigActionHandler extends Logging { case Right(response) => listener.onResponse(new RRTestConfigResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRTestConfig internal error", ex) + logger.error(s"RRTestConfig internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es90x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala b/es90x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala index 494e9150b4..98cc0c945d 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.dlsfls import cats.data.StateT import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.DirectoryReader import org.elasticsearch.common.util.concurrent.ThreadContext import org.elasticsearch.core.CheckedFunction @@ -31,7 +31,7 @@ import java.io.IOException import java.util.function.{Function => JavaFunction} import scala.util.{Failure, Success, Try} -object RoleIndexSearcherWrapper extends Logging { +object RoleIndexSearcherWrapper extends RequestIdAwareLogging { val instance: JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] = new JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] { @@ -54,7 +54,7 @@ object RoleIndexSearcherWrapper extends Logging { } .map(r => (r, r)) case None => - logger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") + noRequestIdLogger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") Success((reader, reader)) } } @@ -66,13 +66,13 @@ object RoleIndexSearcherWrapper extends Logging { nel <- NonEmptyString.from(value) match { case Right(nel) => Success(nel) case Left(_) => - logger.debug("FLS: empty header value") + noRequestIdLogger.debug("FLS: empty header value") failure } fields <- transientFieldsFromHeaderValue.fromRawValue(nel) match { case result@Success(_) => result case Failure(ex) => - logger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) + noRequestIdLogger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) failure } } yield fields diff --git a/es90x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala b/es90x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala index 6e90eedff3..e4e18e54b7 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.dlsfls import com.google.common.collect.Iterators -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.codecs.StoredFieldsReader import org.apache.lucene.index.* import org.apache.lucene.index.StoredFieldVisitor.Status @@ -39,21 +39,21 @@ import scala.jdk.CollectionConverters.* import scala.util.Try private class RorDocumentFieldReader(reader: LeafReader, fieldsRestrictions: FieldsRestrictions) - extends SequentialStoredFieldsLeafReader(reader) with Logging { + extends SequentialStoredFieldsLeafReader(reader) with RequestIdAwareLogging { private val policy = new FieldsPolicy(fieldsRestrictions) private val remainingFieldsInfo = { val fInfos = in.getFieldInfos val newInfos = if (fInfos.asScala.isEmpty) { - logger.warn("original fields were empty! This is weird!") + noRequestIdLogger.warn("original fields were empty! This is weird!") fInfos } else { val remainingFields = fInfos.asScala.filter(f => policy.canKeep(f.name)).toSet new FieldInfos(remainingFields.toArray) } - logger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") - logger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") - logger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") + noRequestIdLogger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") newInfos } private val jsonPolicyBasedFilterer = new JsonPolicyBasedFilterer(policy) diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala index 9365230fe3..9abe861fe3 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.* import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest import org.elasticsearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest @@ -87,7 +87,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, threadPool: ThreadPool) (implicit generator: UniqueIdentifierGenerator, scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle(engines: Engines, esContext: EsContext): Task[Either[Error, Unit]] = { @@ -243,7 +243,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, case SearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case MultiSearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case _ => - logger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") + noRequestIdLogger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") regularRequestHandler.handle(new DummyCompositeIndicesEsRequestContext(request, esContext, aclContext, clusterService, threadPool)) } // rest diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala index cab02aff37..100edd72ac 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.common.io.stream.StreamOutput import org.elasticsearch.xcontent.{ToXContent, ToXContentObject, XContentBuilder} @@ -45,7 +45,7 @@ import scala.util.{Failure, Success, Try} class CurrentUserMetadataRequestHandler(engine: Engine, esContext: EsContext) - extends Logging { + extends RequestIdAwareLogging { def handle(request: RequestContext.Aux[CurrentUserMetadataRequestBlockContext] with EsRequest[CurrentUserMetadataRequestBlockContext]): Task[Unit] = { engine.core.accessControl @@ -69,7 +69,7 @@ class CurrentUserMetadataRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(ex.asInstanceOf[Exception]) } } @@ -86,13 +86,13 @@ class CurrentUserMetadataRequestHandler(engine: Engine, )) } - private def onPassThrough(requestContext: RequestContext): Unit = { - logger.warn(s"[${requestContext.id.toRequestId.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") + private def onPassThrough(implicit requestContext: RequestContext): Unit = { + logger.warn(s"Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") esContext.listener.onFailure(createRorNotEnabledResponse()) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala index 2fb01dcc41..c5c44fda92 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala @@ -20,7 +20,7 @@ import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.RegularRequestResult @@ -49,7 +49,7 @@ class RegularRequestHandler(engine: Engine, esContext: EsContext, threadPool: ThreadPool) (implicit scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle[B <: BlockContext : BlockContextUpdater](request: RequestContext.Aux[B] with EsRequest[B]): Task[Unit] = { engine.core.accessControl @@ -85,7 +85,7 @@ class RegularRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(new Exception(ex)) } } @@ -99,7 +99,7 @@ class RegularRequestHandler(engine: Engine, case ModificationResult.ShouldBeInterrupted => onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case ModificationResult.CannotModify => - logger.error(s"[${request.id.toRequestId.show}] Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") + noRequestIdLogger.error(s"Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case CustomResponse(response) => respond(request, response) @@ -247,7 +247,7 @@ class RegularRequestHandler(engine: Engine, esContext.listener.onResponse(response) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } \ No newline at end of file diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala index f4f832dedc..bfc421bdd5 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.index.query.{AbstractQueryBuilder, QueryBuilder, QueryBuilders} import org.elasticsearch.search.aggregations.AggregatorFactories @@ -40,7 +40,7 @@ import tech.beshu.ror.implicits.* import java.util.UUID import scala.jdk.CollectionConverters.* -object SearchRequestOps extends Logging { +object SearchRequestOps extends RequestIdAwareLogging { implicit class QueryBuilderOps(val builder: Option[QueryBuilder]) extends AnyVal { @@ -52,7 +52,7 @@ object SearchRequestOps extends Logging { val modifiedQuery: AbstractQueryBuilder[_] = provideNewQueryWithAppliedFilter(builder, filterQuery) Some(modifiedQuery) case None => - logger.debug(s"[${requestId.show}] No filter applied to query.") + logger.debug(s"No filter applied to query.") builder } } @@ -92,7 +92,7 @@ object SearchRequestOps extends Logging { case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, requestId) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) disableCaching(requestId) case BasedOnBlockContextOnly.NotAllowedFieldsUsed(notAllowedFields) => modifyNotAllowedFieldsInRequest(notAllowedFields) @@ -138,8 +138,8 @@ object SearchRequestOps extends Logging { } } - private def disableCaching(requestId: RequestContext.Id) = { - logger.debug(s"[${requestId.show}] ACL uses context header for fields rule, will disable request cache for SearchRequest") + private def disableCaching(implicit requestId: RequestContext.Id) = { + logger.debug(s"ACL uses context header for fields rule, will disable request cache for SearchRequest") request.requestCache(false) } } diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala index 993bdbd7a0..f0d04a6837 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala @@ -17,7 +17,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.action.{CompositeIndicesRequest, IndicesRequest} import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -32,7 +31,7 @@ import java.time.Instant abstract class BaseEsRequestContext[B <: BlockContext](esContext: EsContext, clusterService: RorClusterService) - extends RequestContext with Logging { + extends RequestContext { override type BLOCK_CONTEXT = B diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala index ae8abbe1f5..0ee2967364 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala @@ -18,7 +18,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -26,8 +25,9 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import scala.util.Try +import tech.beshu.ror.utils.RequestIdAwareLogging -trait EsRequest[B <: BlockContext] extends Logging { +trait EsRequest[B <: BlockContext] extends RequestIdAwareLogging { implicit def threadPool: ThreadPool final def modifyUsing(blockContext: B): ModificationResult = { @@ -35,7 +35,7 @@ trait EsRequest[B <: BlockContext] extends Logging { Try(modifyRequest(blockContext)) .fold( ex => { - logger.error(s"[${blockContext.requestContext.id.show}] Cannot modify request with filtered data", ex) + logger.error(s"Cannot modify request with filtered data", ex)(blockContext) ModificationResult.CannotModify }, identity diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala index c6a9dcbefd..f773b3efb1 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala @@ -51,7 +51,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest private def discoverDataStreams() = { val dataStreams = dataStreamsFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered data streams: ${dataStreams.show}") + logger.debug(s"Discovered data streams: ${dataStreams.show}") dataStreams } @@ -59,7 +59,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest val backingIndices = backingIndicesFrom(actionRequest) backingIndices match { case BackingIndices.IndicesInvolved(filteredIndices, _) => - logger.debug(s"[${id.show}] Discovered indices: ${filteredIndices.show}") + logger.debug(s"Discovered indices: ${filteredIndices.show}") case BackingIndices.IndicesNotInvolved => } backingIndices diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala index c091179cb6..d150709314 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala @@ -85,7 +85,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: case Some(indices) => update(actionRequest, indices, blockContext.filter, blockContext.fieldLevelSecurity) case None => - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -101,7 +101,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } \ No newline at end of file diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala index 71d462de57..48014e1bdc 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala @@ -73,7 +73,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, } yield update(actionRequest, filteredIndices, allAllowedIndices) result.getOrElse { - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -86,7 +86,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala index 95d882c3b5..f607c0e347 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala @@ -50,7 +50,7 @@ abstract class BaseRepositoriesEsRequestContext[R <: ActionRequest](actionReques case Some(repositories) => update(actionRequest, repositories) case None => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") ShouldBeInterrupted } } diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala index b3b1d66238..7ef0f32014 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala @@ -42,7 +42,7 @@ abstract class BaseSingleIndexEsRequestContext[R <: ActionRequest](actionRequest filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } update(request, filteredIndices.head) } diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala index b5ab70fe7a..c1b2e7ea27 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala @@ -62,7 +62,7 @@ class BulkEsRequestContext(actionRequest: BulkRequest, case (_, _) => ShouldBeInterrupted } } else { - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because origin request contained different " + + logger.error(s"Cannot alter MultiGetRequest request, because origin request contained different " + s"number of requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } @@ -90,18 +90,18 @@ class BulkEsRequestContext(actionRequest: BulkRequest, updateRequestWithIndices(request, nel) Modified case None => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because empty list of indices was found") + logger.error(s"Cannot alter MultiGetRequest request, because empty list of indices was found") ShouldBeInterrupted } case Indices.NotFound => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because no allowed indices were found") + logger.error(s"Cannot alter MultiGetRequest request, because no allowed indices were found") ShouldBeInterrupted } } private def updateRequestWithIndices(request: DocWriteRequest[_], indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } request.index(indices.head.stringify) } diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala index 75a75fcef5..96a043b298 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala @@ -53,14 +53,14 @@ class BulkShardEsRequestContext(actionRequest: BulkShardRequest, case Success(_) => Modified case Failure(ex) => - logger.error(s"[${id.show}] Cannot modify BulkShardRequest", ex) + logger.error(s"Cannot modify BulkShardRequest", ex) CannotModify } } private def tryUpdate(request: BulkShardRequest, indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } val singleIndex = indices.head val uuid = clusterService.indexOrAliasUuids(singleIndex.name).toList.head diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala index 65a168092a..158ac485a5 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala @@ -45,14 +45,14 @@ class ClusterAllocationExplainEsRequestContext(actionRequest: ClusterAllocationE getRequestedIndexFrom(request) match { case Some(_) => if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateIndexIn(request, filteredIndices.head) Modified case None if filteredIndices.exists(_.name === ClusterIndexName.Local.wildcard) => Modified case None => - logger.error(s"[${id.show}] Cluster allocation explain request without index name is unavailable when block contains `indices` rule") + logger.error(s"Cluster allocation explain request without index name is unavailable when block contains `indices` rule") ShouldBeInterrupted } } diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala index 61fdab9d83..5bf09449c5 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala @@ -79,7 +79,7 @@ class EsqlIndicesEsRequestContext private(actionRequest: ActionRequest with Comp request } case Left(ClassificationError.ParsingException(ex)) => - logger.debug(s"[${id.show}] Cannot parse ESQL statement - we can pass it though, because ES is going to reject it. Cause:", ex) + logger.debug(s"Cannot parse ESQL statement - we can pass it though, because ES is going to reject it. Cause:", ex) request } } @@ -90,7 +90,7 @@ class EsqlIndicesEsRequestContext private(actionRequest: ActionRequest with Comp case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala index 5778b8968d..02dec730ed 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala @@ -66,7 +66,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, updateAliases(actionRequest, aliases) UpdateResponse.sync(updateAliasesResponse(aliases.includedOnly, _)) case None => - logger.error(s"[${id.show}] At least one alias and one index has to be allowed. " + + logger.error(s"At least one alias and one index has to be allowed. " + s"Found allowed indices: [${blockContext.indices.show}]." + s"Found allowed aliases: [${blockContext.aliases.show}]") ShouldBeInterrupted @@ -114,7 +114,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, .indices().asSafeSet .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } @@ -122,7 +122,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, val aliases = rawRequestAliasesSet(request) .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered aliases: ${aliases.show}") + logger.debug(s"Discovered aliases: ${aliases.show}") aliases } diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala index abb85d42b7..f9e2c87e53 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala @@ -55,7 +55,7 @@ class IndicesAliasesEsRequestContext(actionRequest: IndicesAliasesRequest, if (originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala index 584c97e9f5..834bff8e8e 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala @@ -120,7 +120,7 @@ class MultiGetEsRequestContext(actionRequest: MultiGetRequest, case Nil => updateItemWithNonExistingIndex(item) case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } item.index(index.stringify) } diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala index 989956d79a..9e13edee8d 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala @@ -78,7 +78,7 @@ class MultiSearchEsRequestContext(actionRequest: MultiSearchRequest, } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala index 9191e33b66..5a61356f48 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala @@ -47,7 +47,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { request.getRequests.removeIf { request => removeOrAlter(request, filteredIndices.toCovariantSet) } if (request.getRequests.asScala.isEmpty) { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") ShouldBeInterrupted } else { Modified @@ -63,7 +63,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, true case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") } request.index(index.stringify) false diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala index c411df93c5..c7b99f6e85 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala @@ -52,7 +52,7 @@ class PutRollupJobEsRequestContext private(actionRequest: ActionRequest, if(originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala index ba5b52b4f1..f80e716349 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler.request.context.types import cats.data.NonEmptyList import cats.implicits.* import com.google.common.collect.Sets -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionRequest import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.AccessControlStaticContext @@ -51,7 +51,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (tryUpdate(actionRequest, filteredIndices)) Modified else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") ShouldBeInterrupted } } @@ -66,7 +66,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques } } -object ReflectionBasedIndicesEsRequestContext extends Logging { +object ReflectionBasedIndicesEsRequestContext extends RequestIdAwareLogging { def unapply(arg: ReflectionBasedActionRequest): Option[ReflectionBasedIndicesEsRequestContext] = { requestedIndicesFrom(arg.esContext.actionRequest) diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala index 489d0187bc..c42dfc3b78 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala @@ -58,10 +58,10 @@ class ReindexEsRequestContext(actionRequest: ReindexRequest, Modified } else { if (!isDestinationIndexOnFilteredIndicesList) { - logger.info(s"[${id.show}] Destination index of _reindex request is forbidden") + logger.info(s"Destination index of _reindex request is forbidden") } if (!isSearchRequestComposedOnlyOfAllowedIndices) { - logger.info(s"[${id.show}] At least one index from sources indices list of _reindex request is forbidden") + logger.info(s"At least one index from sources indices list of _reindex request is forbidden") } ShouldBeInterrupted } diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala index 2c1b0014e0..97b8ccd9c5 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala @@ -74,7 +74,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo request } case Left(_) => - logger.debug(s"[${id.show}] Cannot parse SQL statement - we can pass it though, because ES is going to reject it") + logger.debug(s"Cannot parse SQL statement - we can pass it though, because ES is going to reject it") request } } @@ -85,7 +85,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala index 0c67384c1e..d7e743e648 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CleanupRepositoryEsRequestContext(actionRequest: CleanupRepositoryRequest, override protected def update(request: CleanupRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala index 44b7d78dfd..d09015139b 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CreateRepositoryEsRequestContext(actionRequest: PutRepositoryRequest, override protected def update(request: PutRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala index eaf9334872..0cf32e1bea 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class DeleteRepositoryEsRequestContext(actionRequest: DeleteRepositoryRequest, override protected def update(request: DeleteRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala index cee0bffd4c..d1410eff3d 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class VerifyRepositoryEsRequestContext(actionRequest: VerifyRepositoryRequest, override protected def update(request: VerifyRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala index ead4fcf250..20501516d5 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala @@ -68,32 +68,32 @@ class CreateSnapshotEsRequestContext(actionRequest: CreateSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala index a56aba660e..621d744767 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala @@ -60,7 +60,7 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -71,14 +71,14 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, .toRight(()) } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala index 22869bbb4f..b81f333174 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala @@ -68,7 +68,7 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, case r => r } case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala index 88887db96c..156deb5b80 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala @@ -63,7 +63,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -75,7 +75,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") } Right(snapshot) } @@ -88,7 +88,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala index 44ee8397ec..e522e440f1 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala @@ -100,12 +100,12 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { val repositories = blockContext.repositories if (allRepositoriesRequested(repositories)) { Right(RepositoryName.All) @@ -115,7 +115,7 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala index 9b58e1b7b5..0a42f8dc82 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.rollover.RolloverConfiguration import org.elasticsearch.action.admin.indices.template.get.GetComposableIndexTemplateAction import org.elasticsearch.cluster.metadata @@ -111,7 +111,7 @@ class GetComposableIndexTemplateEsRequestContext(actionRequest: GetComposableInd } -private[templates] object GetComposableIndexTemplateEsRequestContext extends Logging { +private[templates] object GetComposableIndexTemplateEsRequestContext extends RequestIdAwareLogging { def filter(templates: Map[String, ComposableIndexTemplate], usingTemplate: Set[Template] => Set[Template]) diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala index bd74c3a18f..1c6eecf409 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.{GetIndexTemplatesRequest, GetIndexTemplatesResponse} import org.elasticsearch.cluster.metadata.{AliasMetadata, IndexTemplateMetadata} import org.elasticsearch.common.collect.ImmutableOpenMap @@ -104,7 +104,7 @@ class GetTemplatesEsRequestContext(actionRequest: GetIndexTemplatesRequest, } -private[templates] object GetTemplatesEsRequestContext extends Logging { +private[templates] object GetTemplatesEsRequestContext extends RequestIdAwareLogging { def filter(templates: Iterable[IndexTemplateMetadata], usingTemplate: Set[Template] => Set[Template]) diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala index a8951de5b1..32116d8212 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala @@ -72,7 +72,7 @@ class MultiSearchTemplateEsRequestContext private(actionRequest: ActionRequest w } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala index e6f6d8916e..434787a686 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala @@ -55,7 +55,7 @@ class SimulateIndexTemplateRequestEsRequestContext(actionRequest: SimulateIndexT filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateRequest(request, filteredIndices.head, allAllowedIndices) } diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala index dae9f408ea..ff1bec011a 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala @@ -110,7 +110,7 @@ class SimulateExistingTemplateRequestEsRequestContext(existingTemplateName: Temp case Some(_) => updateResponse(namePatterns.toList, blockContext.allAllowedIndices.toList) case None => - logger.info(s"[${id.show}] User has no access to template ${existingTemplateName.show}") + logger.info(s"User has no access to template ${existingTemplateName.show}") ModificationResult.ShouldBeInterrupted } case other => diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala index f4217184af..88811c3d87 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.queries import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.index.query.* import org.joor.Reflect.on import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.RequestFieldsUsage @@ -30,7 +30,7 @@ trait QueryFieldsUsage[QUERY <: QueryBuilder] { def fieldsIn(query: QUERY): RequestFieldsUsage } -object QueryFieldsUsage extends Logging { +object QueryFieldsUsage extends RequestIdAwareLogging { def apply[QUERY <: QueryBuilder](implicit ev: QueryFieldsUsage[QUERY]): QueryFieldsUsage[QUERY] = ev implicit class Ops[QUERY <: QueryBuilder : QueryFieldsUsage](val query: QUERY) { @@ -61,7 +61,7 @@ object QueryFieldsUsage extends Logging { Option(on(query).call("getFieldName").get[String]) match { case Some(fieldName: String) => UsingFields(NonEmptyList.one(UsedField(fieldName))) case _ => - logger.debug(s"Cannot extract fields for terms set query") + noRequestIdLogger.debug(s"Cannot extract fields for terms set query") CannotExtractFields } } @@ -87,7 +87,7 @@ object QueryFieldsUsage extends Logging { case builder: TermsSetQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder: WildcardQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder => - logger.debug(s"Cannot extract fields for query: ${builder.getName}") + noRequestIdLogger.debug(s"Cannot extract fields for query: ${builder.getName}") CannotExtractFields } diff --git a/es90x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala b/es90x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala index 0998bb9a5b..b4671e9e4d 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.handler.response import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.FieldsRestrictions import tech.beshu.ror.accesscontrol.domain.Header @@ -26,17 +26,17 @@ import tech.beshu.ror.accesscontrol.headerValues.transientFieldsToHeaderValue import tech.beshu.ror.accesscontrol.request.RequestContext import tech.beshu.ror.implicits.* -object FLSContextHeaderHandler extends Logging { +object FLSContextHeaderHandler extends RequestIdAwareLogging { def addContextHeader(threadPool: ThreadPool, - fieldsRestrictions: FieldsRestrictions, - requestId: RequestContext.Id): Unit = { + fieldsRestrictions: FieldsRestrictions) + (implicit requestId: RequestContext.Id): Unit = { val threadContext = threadPool.getThreadContext val header = createContextHeader(fieldsRestrictions) Option(threadContext.getHeader(header.name.value.value)) match { case None => implicit val show = headerShow - logger.debug(s"[${requestId.show}] Adding thread context header required by lucene. Header: '${header.show}'") + logger.debug(s"Adding thread context header required by lucene. Header: '${header.show}'") threadContext.putHeader(header.name.value.value, header.value.value) case Some(_) => } diff --git a/es90x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala b/es90x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala index cc01cf6181..804e0a1faa 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.admin.indices.template.get.{GetComponentTemplateAction, GetComposableIndexTemplateAction} import org.elasticsearch.action.admin.indices.template.put.{PutComponentTemplateAction, TransportPutComposableIndexTemplateAction} @@ -47,7 +47,7 @@ import scala.jdk.CollectionConverters.* final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJsonParserFactory)(using Clock) extends DataStreamService - with Logging { + with RequestIdAwareLogging { private val masterNodeTimeout: TimeValue = TimeValue(30000) private val ackTimeout: TimeValue = TimeValue(30000) @@ -205,11 +205,11 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ response <- Task.measure( task = Task.delay(nodeClient.execute(action, request).actionGet()), logTimeMeasurement = duration => Task.delay { - logger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") + noRequestIdLogger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") } ) _ <- Task.delay { - logger.debug(s"Action ${action.name()} response: ${response.toString}") + noRequestIdLogger.debug(s"Action ${action.name()} response: ${response.toString}") } } yield response } @@ -217,7 +217,7 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ def executeAck[REQUEST <: ActionRequest, RESPONSE <: AcknowledgedResponse](action: ActionType[RESPONSE], request: REQUEST): Task[RESPONSE] = { executeT(action, request) - .tapEval(response => Task.delay(logger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) + .tapEval(response => Task.delay(noRequestIdLogger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) } private def supportedActions: Map[ActionType[ActionResponse], TransportAction[ActionRequest, ActionResponse]] = { diff --git a/es90x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala b/es90x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala index 40ae6d97e0..f24d74c52d 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.support.WriteRequest.RefreshPolicy import org.elasticsearch.client.internal.node.NodeClient @@ -37,7 +37,7 @@ import scala.jdk.CollectionConverters.* class EsIndexJsonContentService(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexJsonContentService - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -62,14 +62,14 @@ class EsIndexJsonContentService(client: NodeClient, Option(response.getSourceAsMap) match { case Some(map) => val source = map.asScala.toMap.asStringMap - logger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") Right(source) case None => - logger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") + noRequestIdLogger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") Right(Map.empty[String, String]) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(ContentNotFound) } } @@ -77,7 +77,7 @@ class EsIndexJsonContentService(client: NodeClient, .onErrorRecover { case _: ResourceNotFoundException => Left(ContentNotFound) case ex => - logger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) Left(CannotReachContentSource) } } @@ -103,14 +103,14 @@ class EsIndexJsonContentService(client: NodeClient, case status if status / 100 == 2 => Right(()) case status => - logger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") Left(CannotWriteToIndex) } } .executeOn(RorSchedulers.blockingScheduler) .onErrorRecover { case ex => - logger.error(s"Cannot write to document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]", ex) Left(CannotWriteToIndex) } } diff --git a/es90x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala b/es90x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala index 2a2669e8b4..619cb6daf2 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala @@ -22,7 +22,7 @@ import cats.kernel.Monoid import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task import monix.execution.{CancelablePromise, Scheduler} -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction.{ResolvedAlias, ResolvedIndex} @@ -65,7 +65,7 @@ class EsServerBasedRorClusterService(nodeName: String, threadPool: ThreadPool) (implicit val scheduler: Scheduler) extends RorClusterService - with Logging { + with RequestIdAwareLogging { import EsServerBasedRorClusterService.* @@ -156,7 +156,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractAccessibilityFrom) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify get request. Blocking document", ex) + logger.error(s"Could not verify get request. Blocking document", ex)(id) Inaccessible } } @@ -168,7 +168,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractResultsFromSearchResponse) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify documents returned by multi get response. Blocking all returned documents", ex) + logger.error(s"Could not verify documents returned by multi get response. Blocking all returned documents", ex)(id) blockAllDocsReturned(documents) } .map(results => zip(results, documents)) @@ -277,7 +277,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService): Task[List[FullRemoteDataStreamWithAliases]] = { getRemoteClusterClient(remoteClusterService, remoteClusterName) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -333,7 +333,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService) = { getRemoteClusterClient(remoteClusterService, remoteClusterName) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -423,7 +423,7 @@ class EsServerBasedRorClusterService(nodeName: String, } } case None => - logger.error("Cannot supply Snapshots Service. Please, report the issue!!!") + noRequestIdLogger.error("Cannot supply Snapshots Service. Please, report the issue!!!") Task.now(Set.empty[Snapshot]) } } diff --git a/es90x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala b/es90x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala index 003823547c..e5fef1d090 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.services import cats.data.NonEmptyList -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.bulk.{BulkProcessor, BulkRequest, BulkResponse} import org.elasticsearch.action.index.IndexRequest import org.elasticsearch.action.{ActionListener, DocWriteRequest} @@ -40,7 +40,7 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, (using Clock) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { private val bulkProcessor = BulkProcessor @@ -81,25 +81,25 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, private class AuditSinkBulkProcessorListener extends BulkProcessor.Listener { override def beforeBulk(executionId: Long, request: BulkRequest): Unit = { - logger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") + noRequestIdLogger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") } override def afterBulk(executionId: Long, request: BulkRequest, response: BulkResponse): Unit = { if (response.hasFailures) { - logger.error("Some failures flushing the BulkProcessor: ") + noRequestIdLogger.error("Some failures flushing the BulkProcessor: ") response .getItems.to(LazyList) .filter(_.isFailed) .map(_.getFailureMessage) .groupBy(identity) .foreach { case (message, stream) => - logger.error(s"${stream.size}x: $message") + noRequestIdLogger.error(s"${stream.size}x: $message") } } } override def afterBulk(executionId: Long, request: BulkRequest, failure: Throwable): Unit = { - logger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) + noRequestIdLogger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) } } diff --git a/es90x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala b/es90x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala index a8def0ec7a..b3c5593c36 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala @@ -22,7 +22,7 @@ import org.apache.http.auth.{AuthScope, Credentials, UsernamePasswordCredentials import org.apache.http.conn.ssl.NoopHostnameVerifier import org.apache.http.impl.client.BasicCredentialsProvider import org.apache.http.impl.nio.client.HttpAsyncClientBuilder -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.* import org.elasticsearch.client.RestClient.FailureListener import tech.beshu.ror.accesscontrol.audit.sink.AuditDataStreamCreator @@ -38,7 +38,7 @@ import scala.collection.parallel.CollectionConverters.* final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient]) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { override def submit(indexName: IndexName.Full, documentId: String, jsonRecord: String) (implicit requestId: RequestId): Unit = { @@ -77,21 +77,21 @@ final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient] override def onSuccess(response: Response): Unit = { response.getStatusLine.getStatusCode / 100 match { case 2 => // 2xx - logger.debug(s"[${requestId.show}] Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") + logger.debug(s"Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") case _ => - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") } } override def onFailure(ex: Exception): Unit = { - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId]", ex) + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId]", ex) } } override val dataStreamCreator: AuditDataStreamCreator = new AuditDataStreamCreator(clients.map(new RestClientDataStreamService(_))) } -object RestClientAuditSinkService extends Logging { +object RestClientAuditSinkService extends RequestIdAwareLogging { def create(remoteCluster: AuditCluster.RemoteAuditCluster): RestClientAuditSinkService = { remoteCluster.mode match { @@ -122,7 +122,7 @@ object RestClientAuditSinkService extends Logging { .setFailureListener( new FailureListener { override def onFailure(node: Node): Unit = { - logger.debug( + noRequestIdLogger.debug( s"[AUDIT] Node marked dead: ${node.getHost.getSchemeName}://${node.getHost.getHostName}:${node.getHost.getPort}. The client will attempt failover.", ) } diff --git a/es90x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala b/es90x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala index 1f00261ee4..6344d8c3ae 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.Channel import io.netty.handler.ssl.NotSslRecordException -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.bulk.IncrementalBulkService.Enabled import org.elasticsearch.common.network.NetworkService import org.elasticsearch.common.settings.{ClusterSettings, Settings} @@ -42,7 +42,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, tracer: Tracer, fipsCompliant: Boolean) extends Netty4HttpServerTransport(settings, networkService, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory, tracer, TLSConfig.noTLS(), null, null) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, ssl.clientAuthenticationEnabled) @@ -50,7 +50,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, override def onException(channel: HttpChannel, cause: Exception): Unit = { if (!this.lifecycle.started) return - else if (cause.getCause.isInstanceOf[NotSslRecordException]) logger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) + else if (cause.getCause.isInstanceOf[NotSslRecordException]) noRequestIdLogger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) else super.onException(channel, cause) channel.close() } diff --git a/es90x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala b/es90x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala index 2fa1d7871c..2d2b0360d4 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.* import io.netty.handler.ssl.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.TransportVersion import org.elasticsearch.cluster.node.DiscoveryNode import org.elasticsearch.common.io.stream.NamedWriteableRegistry @@ -46,7 +46,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, sharedGroupFactory: SharedGroupFactory, fipsCompliant: Boolean) extends Netty4Transport(settings, TransportVersion.current(), threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = SSLCertHelper.prepareClientSSLContext(ssl, fipsCompliant, ssl.certificateVerificationEnabled) private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, clientAuthenticationEnabled = false) @@ -78,7 +78,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, override def exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable): Unit = { if (cause.isInstanceOf[NotSslRecordException] || (cause.getCause != null && cause.getCause.isInstanceOf[NotSslRecordException])) { - logger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") + noRequestIdLogger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") ctx.channel.close } else { super.exceptionCaught(ctx, cause) diff --git a/es90x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala b/es90x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala index bdb78c1fca..d552559499 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.utils import cats.Show import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.client.internal.node.NodeClient import org.elasticsearch.rest.* @@ -35,7 +35,7 @@ import java.util import scala.util.Try class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandler) - extends RestHandler with Logging { + extends RestHandler with RequestIdAwareLogging { private val wrapped = doPrivileged { wrapSomeActions(underlying) @@ -96,11 +96,11 @@ class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandle private def logError(error: AuthorizationValueError): Unit = { { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorSanitizedShow - logger.warn(s"The incoming request was malformed. Cause: ${error.show}") + noRequestIdLogger.warn(s"The incoming request was malformed. Cause: ${error.show}") } if (logger.delegate.isDebugEnabled()) { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorWithDetailsShow - logger.debug(s"Malformed request detailed cause: ${error.show}") + noRequestIdLogger.debug(s"Malformed request detailed cause: ${error.show}") } } diff --git a/es90x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala b/es90x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala index 5ab1e35742..a9af8f710a 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala @@ -16,13 +16,13 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.settings.Settings import tech.beshu.ror.tools.core.patches.PatchingVerifier import tech.beshu.ror.tools.core.patches.PatchingVerifier.Error.{CannotVerifyIfPatched, EsNotPatched} import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -object EsPatchVerifier extends Logging { +object EsPatchVerifier extends RequestIdAwareLogging { def verify(settings: Settings): Unit = doPrivileged { pathHomeFrom(settings).flatMap(PatchingVerifier.verify) match { @@ -30,7 +30,7 @@ object EsPatchVerifier extends Logging { case Left(e@EsNotPatched(_)) => throw new IllegalStateException(e.message) case Left(e@CannotVerifyIfPatched(_)) => - logger.warn(e.message) + noRequestIdLogger.warn(e.message) } } diff --git a/es90x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala b/es90x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala index b73104a175..c292a44ed2 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.internal.node.NodeClient import org.elasticsearch.transport.RemoteClusterService import org.joor.Reflect.on @@ -26,14 +26,14 @@ import java.util.function.Supplier import scala.util.{Failure, Success, Try} class RemoteClusterServiceSupplier(nodeClient: NodeClient) - extends Supplier[Option[RemoteClusterService]] with Logging { + extends Supplier[Option[RemoteClusterService]] with RequestIdAwareLogging { override def get(): Option[RemoteClusterService] = { extractRemoteClusterService() match { case Success(remoteClusterService) => remoteClusterService case Failure(ex) => - logger.error("Cannot extract RemoteClusterService from NodeClient", ex) + noRequestIdLogger.error("Cannot extract RemoteClusterService from NodeClient", ex) None } } diff --git a/es91x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es91x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index 8ecc9c9488..8d7939fddf 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.support.{ActionFilter, ActionFilterChain} import org.elasticsearch.action.{ActionListener, ActionRequest, ActionResponse} import org.elasticsearch.client.internal.node.NodeClient @@ -62,7 +62,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, rorEsConfig: ReadonlyRestEsConfig) (implicit environmentConfig: EnvironmentConfig) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = environmentConfig.uniqueIdentifierGenerator @@ -208,12 +208,12 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def handleRorNotReadyYet(esContext: EsContext): Unit = { - logger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") + noRequestIdLogger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") rorNotAvailableRequestHandler.handleRorNotReadyYet(esContext) } private def handleRorFailedToStart(esContext: EsContext): Unit = { - logger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") + noRequestIdLogger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") rorNotAvailableRequestHandler.handleRorFailedToStart(esContext) } @@ -235,7 +235,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def logAndSetStartingFailureState(failure: StartingFailure): Unit = { - logger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) + noRequestIdLogger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) rorInstanceState.set(RorInstanceStartingState.NotStarted(failure)) } } diff --git a/es91x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala b/es91x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala index 1fb22fc79d..53452eb8e6 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.xcontent.LoggingDeprecationHandler import org.elasticsearch.rest.RestResponse import org.elasticsearch.transport.BytesRefRecycler @@ -32,7 +32,7 @@ import tech.beshu.ror.accesscontrol.domain.ResponseFieldsFiltering.{AccessMode, import scala.jdk.CollectionConverters.* trait ResponseFieldsFiltering { - this: Logging => + this: RequestIdAwareLogging => private val responseFieldsRestrictions: Atomic[Option[ResponseFieldsRestrictions]] = Atomic(None: Option[ResponseFieldsRestrictions]) diff --git a/es91x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala b/es91x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala index 0f26750588..da95de59a4 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.action.{ActionListener, ActionResponse} import org.elasticsearch.threadpool.ThreadPool @@ -37,7 +37,7 @@ sealed abstract class RorActionListener[T](val underlying: ActionListener[T]) ex final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionListener[T], correlationId: Eval[CorrelationId]) - extends RorActionListener[T](underlying) with Logging { + extends RorActionListener[T](underlying) with RequestIdAwareLogging { override def onFailure(e: Exception): Unit = { super.onFailure(adaptExceptionIfNeeded(e)) @@ -47,7 +47,7 @@ final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionLis ex match { case esException: ElasticsearchException => esException case other => - logger.error(s"[${correlationId.value.show}] Internal error.", other) + noRequestIdLogger.error(s"[${correlationId.value.show}] Internal error.", other) new ElasticsearchException(s"[${correlationId.value.show}] Internal error. See logs for details.") } } diff --git a/es91x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala b/es91x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala index 4f0bc8c6fa..c68cc24623 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.http.HttpChannel import org.elasticsearch.rest.{AbstractRestChannel, RestChannel as EsRestChannel, RestRequest as EsRestRequest, RestResponse as EsRestResponse} import squants.information.{Bytes, Information} @@ -40,7 +40,7 @@ object RorRestChannel { final class RorRestChannel private(underlying: EsRestChannel, val restRequest: RorRestRequest) extends AbstractRestChannel(underlying.request(), true) with ResponseFieldsFiltering - with Logging { + with RequestIdAwareLogging { override def sendResponse(response: EsRestResponse): Unit = { ThreadRepo.removeRestChannel(this) diff --git a/es91x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala b/es91x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala index 6babc712b9..3c80750a25 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala @@ -18,16 +18,15 @@ package tech.beshu.ror.es.actions.rradmin import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.ConfigApi.ConfigResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAdminActionHandler extends Logging { +class RRAdminActionHandler extends RequestIdAwareLogging { private implicit val adminRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +51,7 @@ class RRAdminActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAdminResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAdminAction internal error", ex) + logger.error("RRAdminAction internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es91x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala b/es91x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala index c55835a1d0..ce45c6f48e 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala @@ -16,18 +16,15 @@ */ package tech.beshu.ror.es.actions.rrauthmock -import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.AuthMockApi.AuthMockResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier -import tech.beshu.ror.implicits.* +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAuthMockActionHandler extends Logging { +class RRAuthMockActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -53,7 +50,7 @@ class RRAuthMockActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAuthMockResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAuthMock internal error", ex) + logger.error("RRAuthMock internal error", ex) listener.onFailure(new Exception(ex)) } } diff --git a/es91x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala b/es91x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala index aa8bb31e67..640084c4ec 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestconfig import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.TestConfigApi.TestConfigResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestConfigActionHandler extends Logging { +class RRTestConfigActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +52,7 @@ class RRTestConfigActionHandler extends Logging { case Right(response) => listener.onResponse(new RRTestConfigResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRTestConfig internal error", ex) + logger.error(s"RRTestConfig internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es91x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala b/es91x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala index 494e9150b4..98cc0c945d 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.dlsfls import cats.data.StateT import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.DirectoryReader import org.elasticsearch.common.util.concurrent.ThreadContext import org.elasticsearch.core.CheckedFunction @@ -31,7 +31,7 @@ import java.io.IOException import java.util.function.{Function => JavaFunction} import scala.util.{Failure, Success, Try} -object RoleIndexSearcherWrapper extends Logging { +object RoleIndexSearcherWrapper extends RequestIdAwareLogging { val instance: JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] = new JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] { @@ -54,7 +54,7 @@ object RoleIndexSearcherWrapper extends Logging { } .map(r => (r, r)) case None => - logger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") + noRequestIdLogger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") Success((reader, reader)) } } @@ -66,13 +66,13 @@ object RoleIndexSearcherWrapper extends Logging { nel <- NonEmptyString.from(value) match { case Right(nel) => Success(nel) case Left(_) => - logger.debug("FLS: empty header value") + noRequestIdLogger.debug("FLS: empty header value") failure } fields <- transientFieldsFromHeaderValue.fromRawValue(nel) match { case result@Success(_) => result case Failure(ex) => - logger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) + noRequestIdLogger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) failure } } yield fields diff --git a/es91x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala b/es91x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala index 6e90eedff3..e4e18e54b7 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.dlsfls import com.google.common.collect.Iterators -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.codecs.StoredFieldsReader import org.apache.lucene.index.* import org.apache.lucene.index.StoredFieldVisitor.Status @@ -39,21 +39,21 @@ import scala.jdk.CollectionConverters.* import scala.util.Try private class RorDocumentFieldReader(reader: LeafReader, fieldsRestrictions: FieldsRestrictions) - extends SequentialStoredFieldsLeafReader(reader) with Logging { + extends SequentialStoredFieldsLeafReader(reader) with RequestIdAwareLogging { private val policy = new FieldsPolicy(fieldsRestrictions) private val remainingFieldsInfo = { val fInfos = in.getFieldInfos val newInfos = if (fInfos.asScala.isEmpty) { - logger.warn("original fields were empty! This is weird!") + noRequestIdLogger.warn("original fields were empty! This is weird!") fInfos } else { val remainingFields = fInfos.asScala.filter(f => policy.canKeep(f.name)).toSet new FieldInfos(remainingFields.toArray) } - logger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") - logger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") - logger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") + noRequestIdLogger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") newInfos } private val jsonPolicyBasedFilterer = new JsonPolicyBasedFilterer(policy) diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala index 2f6a3aac03..215d65b036 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.* import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest import org.elasticsearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest @@ -87,7 +87,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, threadPool: ThreadPool) (implicit generator: UniqueIdentifierGenerator, scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle(engines: Engines, esContext: EsContext): Task[Either[Error, Unit]] = { @@ -243,7 +243,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, case SearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case MultiSearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case _ => - logger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") + noRequestIdLogger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") regularRequestHandler.handle(new DummyCompositeIndicesEsRequestContext(request, esContext, aclContext, clusterService, threadPool)) } // rest diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala index cab02aff37..100edd72ac 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.common.io.stream.StreamOutput import org.elasticsearch.xcontent.{ToXContent, ToXContentObject, XContentBuilder} @@ -45,7 +45,7 @@ import scala.util.{Failure, Success, Try} class CurrentUserMetadataRequestHandler(engine: Engine, esContext: EsContext) - extends Logging { + extends RequestIdAwareLogging { def handle(request: RequestContext.Aux[CurrentUserMetadataRequestBlockContext] with EsRequest[CurrentUserMetadataRequestBlockContext]): Task[Unit] = { engine.core.accessControl @@ -69,7 +69,7 @@ class CurrentUserMetadataRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(ex.asInstanceOf[Exception]) } } @@ -86,13 +86,13 @@ class CurrentUserMetadataRequestHandler(engine: Engine, )) } - private def onPassThrough(requestContext: RequestContext): Unit = { - logger.warn(s"[${requestContext.id.toRequestId.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") + private def onPassThrough(implicit requestContext: RequestContext): Unit = { + logger.warn(s"Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") esContext.listener.onFailure(createRorNotEnabledResponse()) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala index 2fb01dcc41..c5c44fda92 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala @@ -20,7 +20,7 @@ import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.RegularRequestResult @@ -49,7 +49,7 @@ class RegularRequestHandler(engine: Engine, esContext: EsContext, threadPool: ThreadPool) (implicit scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle[B <: BlockContext : BlockContextUpdater](request: RequestContext.Aux[B] with EsRequest[B]): Task[Unit] = { engine.core.accessControl @@ -85,7 +85,7 @@ class RegularRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(new Exception(ex)) } } @@ -99,7 +99,7 @@ class RegularRequestHandler(engine: Engine, case ModificationResult.ShouldBeInterrupted => onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case ModificationResult.CannotModify => - logger.error(s"[${request.id.toRequestId.show}] Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") + noRequestIdLogger.error(s"Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case CustomResponse(response) => respond(request, response) @@ -247,7 +247,7 @@ class RegularRequestHandler(engine: Engine, esContext.listener.onResponse(response) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } \ No newline at end of file diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala index f4f832dedc..bfc421bdd5 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.index.query.{AbstractQueryBuilder, QueryBuilder, QueryBuilders} import org.elasticsearch.search.aggregations.AggregatorFactories @@ -40,7 +40,7 @@ import tech.beshu.ror.implicits.* import java.util.UUID import scala.jdk.CollectionConverters.* -object SearchRequestOps extends Logging { +object SearchRequestOps extends RequestIdAwareLogging { implicit class QueryBuilderOps(val builder: Option[QueryBuilder]) extends AnyVal { @@ -52,7 +52,7 @@ object SearchRequestOps extends Logging { val modifiedQuery: AbstractQueryBuilder[_] = provideNewQueryWithAppliedFilter(builder, filterQuery) Some(modifiedQuery) case None => - logger.debug(s"[${requestId.show}] No filter applied to query.") + logger.debug(s"No filter applied to query.") builder } } @@ -92,7 +92,7 @@ object SearchRequestOps extends Logging { case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, requestId) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) disableCaching(requestId) case BasedOnBlockContextOnly.NotAllowedFieldsUsed(notAllowedFields) => modifyNotAllowedFieldsInRequest(notAllowedFields) @@ -138,8 +138,8 @@ object SearchRequestOps extends Logging { } } - private def disableCaching(requestId: RequestContext.Id) = { - logger.debug(s"[${requestId.show}] ACL uses context header for fields rule, will disable request cache for SearchRequest") + private def disableCaching(implicit requestId: RequestContext.Id) = { + logger.debug(s"ACL uses context header for fields rule, will disable request cache for SearchRequest") request.requestCache(false) } } diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala index 993bdbd7a0..f0d04a6837 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala @@ -17,7 +17,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.action.{CompositeIndicesRequest, IndicesRequest} import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -32,7 +31,7 @@ import java.time.Instant abstract class BaseEsRequestContext[B <: BlockContext](esContext: EsContext, clusterService: RorClusterService) - extends RequestContext with Logging { + extends RequestContext { override type BLOCK_CONTEXT = B diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala index ae8abbe1f5..0ee2967364 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala @@ -18,7 +18,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -26,8 +25,9 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import scala.util.Try +import tech.beshu.ror.utils.RequestIdAwareLogging -trait EsRequest[B <: BlockContext] extends Logging { +trait EsRequest[B <: BlockContext] extends RequestIdAwareLogging { implicit def threadPool: ThreadPool final def modifyUsing(blockContext: B): ModificationResult = { @@ -35,7 +35,7 @@ trait EsRequest[B <: BlockContext] extends Logging { Try(modifyRequest(blockContext)) .fold( ex => { - logger.error(s"[${blockContext.requestContext.id.show}] Cannot modify request with filtered data", ex) + logger.error(s"Cannot modify request with filtered data", ex)(blockContext) ModificationResult.CannotModify }, identity diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala index c6a9dcbefd..f773b3efb1 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala @@ -51,7 +51,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest private def discoverDataStreams() = { val dataStreams = dataStreamsFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered data streams: ${dataStreams.show}") + logger.debug(s"Discovered data streams: ${dataStreams.show}") dataStreams } @@ -59,7 +59,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest val backingIndices = backingIndicesFrom(actionRequest) backingIndices match { case BackingIndices.IndicesInvolved(filteredIndices, _) => - logger.debug(s"[${id.show}] Discovered indices: ${filteredIndices.show}") + logger.debug(s"Discovered indices: ${filteredIndices.show}") case BackingIndices.IndicesNotInvolved => } backingIndices diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala index c091179cb6..d150709314 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala @@ -85,7 +85,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: case Some(indices) => update(actionRequest, indices, blockContext.filter, blockContext.fieldLevelSecurity) case None => - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -101,7 +101,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } \ No newline at end of file diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala index 71d462de57..48014e1bdc 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala @@ -73,7 +73,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, } yield update(actionRequest, filteredIndices, allAllowedIndices) result.getOrElse { - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -86,7 +86,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala index 95d882c3b5..f607c0e347 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala @@ -50,7 +50,7 @@ abstract class BaseRepositoriesEsRequestContext[R <: ActionRequest](actionReques case Some(repositories) => update(actionRequest, repositories) case None => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") ShouldBeInterrupted } } diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala index b3b1d66238..7ef0f32014 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala @@ -42,7 +42,7 @@ abstract class BaseSingleIndexEsRequestContext[R <: ActionRequest](actionRequest filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } update(request, filteredIndices.head) } diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala index b5ab70fe7a..c1b2e7ea27 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala @@ -62,7 +62,7 @@ class BulkEsRequestContext(actionRequest: BulkRequest, case (_, _) => ShouldBeInterrupted } } else { - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because origin request contained different " + + logger.error(s"Cannot alter MultiGetRequest request, because origin request contained different " + s"number of requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } @@ -90,18 +90,18 @@ class BulkEsRequestContext(actionRequest: BulkRequest, updateRequestWithIndices(request, nel) Modified case None => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because empty list of indices was found") + logger.error(s"Cannot alter MultiGetRequest request, because empty list of indices was found") ShouldBeInterrupted } case Indices.NotFound => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because no allowed indices were found") + logger.error(s"Cannot alter MultiGetRequest request, because no allowed indices were found") ShouldBeInterrupted } } private def updateRequestWithIndices(request: DocWriteRequest[_], indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } request.index(indices.head.stringify) } diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala index 75a75fcef5..96a043b298 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala @@ -53,14 +53,14 @@ class BulkShardEsRequestContext(actionRequest: BulkShardRequest, case Success(_) => Modified case Failure(ex) => - logger.error(s"[${id.show}] Cannot modify BulkShardRequest", ex) + logger.error(s"Cannot modify BulkShardRequest", ex) CannotModify } } private def tryUpdate(request: BulkShardRequest, indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } val singleIndex = indices.head val uuid = clusterService.indexOrAliasUuids(singleIndex.name).toList.head diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala index 65a168092a..158ac485a5 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala @@ -45,14 +45,14 @@ class ClusterAllocationExplainEsRequestContext(actionRequest: ClusterAllocationE getRequestedIndexFrom(request) match { case Some(_) => if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateIndexIn(request, filteredIndices.head) Modified case None if filteredIndices.exists(_.name === ClusterIndexName.Local.wildcard) => Modified case None => - logger.error(s"[${id.show}] Cluster allocation explain request without index name is unavailable when block contains `indices` rule") + logger.error(s"Cluster allocation explain request without index name is unavailable when block contains `indices` rule") ShouldBeInterrupted } } diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala index 61fdab9d83..5bf09449c5 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala @@ -79,7 +79,7 @@ class EsqlIndicesEsRequestContext private(actionRequest: ActionRequest with Comp request } case Left(ClassificationError.ParsingException(ex)) => - logger.debug(s"[${id.show}] Cannot parse ESQL statement - we can pass it though, because ES is going to reject it. Cause:", ex) + logger.debug(s"Cannot parse ESQL statement - we can pass it though, because ES is going to reject it. Cause:", ex) request } } @@ -90,7 +90,7 @@ class EsqlIndicesEsRequestContext private(actionRequest: ActionRequest with Comp case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala index 5778b8968d..02dec730ed 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala @@ -66,7 +66,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, updateAliases(actionRequest, aliases) UpdateResponse.sync(updateAliasesResponse(aliases.includedOnly, _)) case None => - logger.error(s"[${id.show}] At least one alias and one index has to be allowed. " + + logger.error(s"At least one alias and one index has to be allowed. " + s"Found allowed indices: [${blockContext.indices.show}]." + s"Found allowed aliases: [${blockContext.aliases.show}]") ShouldBeInterrupted @@ -114,7 +114,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, .indices().asSafeSet .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } @@ -122,7 +122,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, val aliases = rawRequestAliasesSet(request) .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered aliases: ${aliases.show}") + logger.debug(s"Discovered aliases: ${aliases.show}") aliases } diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala index abb85d42b7..f9e2c87e53 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala @@ -55,7 +55,7 @@ class IndicesAliasesEsRequestContext(actionRequest: IndicesAliasesRequest, if (originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala index 584c97e9f5..834bff8e8e 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala @@ -120,7 +120,7 @@ class MultiGetEsRequestContext(actionRequest: MultiGetRequest, case Nil => updateItemWithNonExistingIndex(item) case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } item.index(index.stringify) } diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala index 989956d79a..9e13edee8d 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala @@ -78,7 +78,7 @@ class MultiSearchEsRequestContext(actionRequest: MultiSearchRequest, } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala index 9191e33b66..5a61356f48 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala @@ -47,7 +47,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { request.getRequests.removeIf { request => removeOrAlter(request, filteredIndices.toCovariantSet) } if (request.getRequests.asScala.isEmpty) { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") ShouldBeInterrupted } else { Modified @@ -63,7 +63,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, true case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") } request.index(index.stringify) false diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala index c411df93c5..c7b99f6e85 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala @@ -52,7 +52,7 @@ class PutRollupJobEsRequestContext private(actionRequest: ActionRequest, if(originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala index ba5b52b4f1..f80e716349 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler.request.context.types import cats.data.NonEmptyList import cats.implicits.* import com.google.common.collect.Sets -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionRequest import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.AccessControlStaticContext @@ -51,7 +51,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (tryUpdate(actionRequest, filteredIndices)) Modified else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") ShouldBeInterrupted } } @@ -66,7 +66,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques } } -object ReflectionBasedIndicesEsRequestContext extends Logging { +object ReflectionBasedIndicesEsRequestContext extends RequestIdAwareLogging { def unapply(arg: ReflectionBasedActionRequest): Option[ReflectionBasedIndicesEsRequestContext] = { requestedIndicesFrom(arg.esContext.actionRequest) diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala index 489d0187bc..c42dfc3b78 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala @@ -58,10 +58,10 @@ class ReindexEsRequestContext(actionRequest: ReindexRequest, Modified } else { if (!isDestinationIndexOnFilteredIndicesList) { - logger.info(s"[${id.show}] Destination index of _reindex request is forbidden") + logger.info(s"Destination index of _reindex request is forbidden") } if (!isSearchRequestComposedOnlyOfAllowedIndices) { - logger.info(s"[${id.show}] At least one index from sources indices list of _reindex request is forbidden") + logger.info(s"At least one index from sources indices list of _reindex request is forbidden") } ShouldBeInterrupted } diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala index 2c1b0014e0..97b8ccd9c5 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala @@ -74,7 +74,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo request } case Left(_) => - logger.debug(s"[${id.show}] Cannot parse SQL statement - we can pass it though, because ES is going to reject it") + logger.debug(s"Cannot parse SQL statement - we can pass it though, because ES is going to reject it") request } } @@ -85,7 +85,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala index 0c67384c1e..d7e743e648 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CleanupRepositoryEsRequestContext(actionRequest: CleanupRepositoryRequest, override protected def update(request: CleanupRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala index 44b7d78dfd..d09015139b 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CreateRepositoryEsRequestContext(actionRequest: PutRepositoryRequest, override protected def update(request: PutRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala index eaf9334872..0cf32e1bea 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class DeleteRepositoryEsRequestContext(actionRequest: DeleteRepositoryRequest, override protected def update(request: DeleteRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala index cee0bffd4c..d1410eff3d 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class VerifyRepositoryEsRequestContext(actionRequest: VerifyRepositoryRequest, override protected def update(request: VerifyRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala index ead4fcf250..20501516d5 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala @@ -68,32 +68,32 @@ class CreateSnapshotEsRequestContext(actionRequest: CreateSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala index a56aba660e..621d744767 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala @@ -60,7 +60,7 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -71,14 +71,14 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, .toRight(()) } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala index 22869bbb4f..b81f333174 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala @@ -68,7 +68,7 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, case r => r } case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala index 88887db96c..156deb5b80 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala @@ -63,7 +63,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -75,7 +75,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") } Right(snapshot) } @@ -88,7 +88,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala index 44ee8397ec..e522e440f1 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala @@ -100,12 +100,12 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { val repositories = blockContext.repositories if (allRepositoriesRequested(repositories)) { Right(RepositoryName.All) @@ -115,7 +115,7 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala index 9b58e1b7b5..0a42f8dc82 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.rollover.RolloverConfiguration import org.elasticsearch.action.admin.indices.template.get.GetComposableIndexTemplateAction import org.elasticsearch.cluster.metadata @@ -111,7 +111,7 @@ class GetComposableIndexTemplateEsRequestContext(actionRequest: GetComposableInd } -private[templates] object GetComposableIndexTemplateEsRequestContext extends Logging { +private[templates] object GetComposableIndexTemplateEsRequestContext extends RequestIdAwareLogging { def filter(templates: Map[String, ComposableIndexTemplate], usingTemplate: Set[Template] => Set[Template]) diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala index bd74c3a18f..1c6eecf409 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.{GetIndexTemplatesRequest, GetIndexTemplatesResponse} import org.elasticsearch.cluster.metadata.{AliasMetadata, IndexTemplateMetadata} import org.elasticsearch.common.collect.ImmutableOpenMap @@ -104,7 +104,7 @@ class GetTemplatesEsRequestContext(actionRequest: GetIndexTemplatesRequest, } -private[templates] object GetTemplatesEsRequestContext extends Logging { +private[templates] object GetTemplatesEsRequestContext extends RequestIdAwareLogging { def filter(templates: Iterable[IndexTemplateMetadata], usingTemplate: Set[Template] => Set[Template]) diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala index a8951de5b1..32116d8212 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala @@ -72,7 +72,7 @@ class MultiSearchTemplateEsRequestContext private(actionRequest: ActionRequest w } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala index e6f6d8916e..434787a686 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala @@ -55,7 +55,7 @@ class SimulateIndexTemplateRequestEsRequestContext(actionRequest: SimulateIndexT filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateRequest(request, filteredIndices.head, allAllowedIndices) } diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala index dae9f408ea..ff1bec011a 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala @@ -110,7 +110,7 @@ class SimulateExistingTemplateRequestEsRequestContext(existingTemplateName: Temp case Some(_) => updateResponse(namePatterns.toList, blockContext.allAllowedIndices.toList) case None => - logger.info(s"[${id.show}] User has no access to template ${existingTemplateName.show}") + logger.info(s"User has no access to template ${existingTemplateName.show}") ModificationResult.ShouldBeInterrupted } case other => diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala index f4217184af..88811c3d87 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.queries import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.index.query.* import org.joor.Reflect.on import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.RequestFieldsUsage @@ -30,7 +30,7 @@ trait QueryFieldsUsage[QUERY <: QueryBuilder] { def fieldsIn(query: QUERY): RequestFieldsUsage } -object QueryFieldsUsage extends Logging { +object QueryFieldsUsage extends RequestIdAwareLogging { def apply[QUERY <: QueryBuilder](implicit ev: QueryFieldsUsage[QUERY]): QueryFieldsUsage[QUERY] = ev implicit class Ops[QUERY <: QueryBuilder : QueryFieldsUsage](val query: QUERY) { @@ -61,7 +61,7 @@ object QueryFieldsUsage extends Logging { Option(on(query).call("getFieldName").get[String]) match { case Some(fieldName: String) => UsingFields(NonEmptyList.one(UsedField(fieldName))) case _ => - logger.debug(s"Cannot extract fields for terms set query") + noRequestIdLogger.debug(s"Cannot extract fields for terms set query") CannotExtractFields } } @@ -87,7 +87,7 @@ object QueryFieldsUsage extends Logging { case builder: TermsSetQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder: WildcardQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder => - logger.debug(s"Cannot extract fields for query: ${builder.getName}") + noRequestIdLogger.debug(s"Cannot extract fields for query: ${builder.getName}") CannotExtractFields } diff --git a/es91x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala b/es91x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala index 0998bb9a5b..b4671e9e4d 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.handler.response import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.FieldsRestrictions import tech.beshu.ror.accesscontrol.domain.Header @@ -26,17 +26,17 @@ import tech.beshu.ror.accesscontrol.headerValues.transientFieldsToHeaderValue import tech.beshu.ror.accesscontrol.request.RequestContext import tech.beshu.ror.implicits.* -object FLSContextHeaderHandler extends Logging { +object FLSContextHeaderHandler extends RequestIdAwareLogging { def addContextHeader(threadPool: ThreadPool, - fieldsRestrictions: FieldsRestrictions, - requestId: RequestContext.Id): Unit = { + fieldsRestrictions: FieldsRestrictions) + (implicit requestId: RequestContext.Id): Unit = { val threadContext = threadPool.getThreadContext val header = createContextHeader(fieldsRestrictions) Option(threadContext.getHeader(header.name.value.value)) match { case None => implicit val show = headerShow - logger.debug(s"[${requestId.show}] Adding thread context header required by lucene. Header: '${header.show}'") + logger.debug(s"Adding thread context header required by lucene. Header: '${header.show}'") threadContext.putHeader(header.name.value.value, header.value.value) case Some(_) => } diff --git a/es91x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala b/es91x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala index 8e0e1e29a2..93a6c3fe55 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.admin.indices.template.get.{GetComponentTemplateAction, GetComposableIndexTemplateAction} import org.elasticsearch.action.admin.indices.template.put.{PutComponentTemplateAction, TransportPutComposableIndexTemplateAction} @@ -47,7 +47,7 @@ import scala.jdk.CollectionConverters.* final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJsonParserFactory)(using Clock) extends DataStreamService - with Logging { + with RequestIdAwareLogging { private val masterNodeTimeout: TimeValue = TimeValue(30000) private val ackTimeout: TimeValue = TimeValue(30000) @@ -205,11 +205,11 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ response <- Task.measure( task = Task.delay(nodeClient.execute(action, request).actionGet()), logTimeMeasurement = duration => Task.delay { - logger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") + noRequestIdLogger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") } ) _ <- Task.delay { - logger.debug(s"Action ${action.name()} response: ${response.toString}") + noRequestIdLogger.debug(s"Action ${action.name()} response: ${response.toString}") } } yield response } @@ -217,7 +217,7 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ def executeAck[REQUEST <: ActionRequest, RESPONSE <: AcknowledgedResponse](action: ActionType[RESPONSE], request: REQUEST): Task[RESPONSE] = { executeT(action, request) - .tapEval(response => Task.delay(logger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) + .tapEval(response => Task.delay(noRequestIdLogger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) } private def supportedActions: Map[ActionType[ActionResponse], TransportAction[ActionRequest, ActionResponse]] = { diff --git a/es91x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala b/es91x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala index 40ae6d97e0..f24d74c52d 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.support.WriteRequest.RefreshPolicy import org.elasticsearch.client.internal.node.NodeClient @@ -37,7 +37,7 @@ import scala.jdk.CollectionConverters.* class EsIndexJsonContentService(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexJsonContentService - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -62,14 +62,14 @@ class EsIndexJsonContentService(client: NodeClient, Option(response.getSourceAsMap) match { case Some(map) => val source = map.asScala.toMap.asStringMap - logger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") Right(source) case None => - logger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") + noRequestIdLogger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") Right(Map.empty[String, String]) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(ContentNotFound) } } @@ -77,7 +77,7 @@ class EsIndexJsonContentService(client: NodeClient, .onErrorRecover { case _: ResourceNotFoundException => Left(ContentNotFound) case ex => - logger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) Left(CannotReachContentSource) } } @@ -103,14 +103,14 @@ class EsIndexJsonContentService(client: NodeClient, case status if status / 100 == 2 => Right(()) case status => - logger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") Left(CannotWriteToIndex) } } .executeOn(RorSchedulers.blockingScheduler) .onErrorRecover { case ex => - logger.error(s"Cannot write to document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]", ex) Left(CannotWriteToIndex) } } diff --git a/es91x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala b/es91x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala index 468ab307ba..f12b3c9b90 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala @@ -22,7 +22,7 @@ import cats.kernel.Monoid import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task import monix.execution.{CancelablePromise, Scheduler} -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction.{ResolvedAlias, ResolvedIndex} @@ -65,7 +65,7 @@ class EsServerBasedRorClusterService(nodeName: String, threadPool: ThreadPool) (implicit val scheduler: Scheduler) extends RorClusterService - with Logging { + with RequestIdAwareLogging { import EsServerBasedRorClusterService.* @@ -159,7 +159,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractAccessibilityFrom) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify get request. Blocking document", ex) + logger.error(s"Could not verify get request. Blocking document", ex)(id) Inaccessible } } @@ -171,7 +171,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractResultsFromSearchResponse) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify documents returned by multi get response. Blocking all returned documents", ex) + logger.error(s"Could not verify documents returned by multi get response. Blocking all returned documents", ex)(id) blockAllDocsReturned(documents) } .map(results => zip(results, documents)) @@ -280,7 +280,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService): Task[List[FullRemoteDataStreamWithAliases]] = { getRemoteClusterClient(remoteClusterService, remoteClusterName) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -336,7 +336,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService) = { getRemoteClusterClient(remoteClusterService, remoteClusterName) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -427,7 +427,7 @@ class EsServerBasedRorClusterService(nodeName: String, } } case None => - logger.error("Cannot supply Snapshots Service. Please, report the issue!!!") + noRequestIdLogger.error("Cannot supply Snapshots Service. Please, report the issue!!!") Task.now(Set.empty[Snapshot]) } } diff --git a/es91x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala b/es91x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala index 82d11a46ac..b76ae9fd0f 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.services import cats.data.NonEmptyList -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.bulk.{BulkProcessor2, BulkRequest, BulkResponse} import org.elasticsearch.action.index.IndexRequest import org.elasticsearch.action.{ActionListener, DocWriteRequest} @@ -41,7 +41,7 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, (using Clock) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { private val bulkProcessor = BulkProcessor2 @@ -81,25 +81,25 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, private class AuditSinkBulkProcessorListener extends BulkProcessor2.Listener { override def beforeBulk(executionId: Long, request: BulkRequest): Unit = { - logger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") + noRequestIdLogger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") } override def afterBulk(executionId: Long, request: BulkRequest, response: BulkResponse): Unit = { if (response.hasFailures) { - logger.error("Some failures flushing the BulkProcessor: ") + noRequestIdLogger.error("Some failures flushing the BulkProcessor: ") response .getItems.to(LazyList) .filter(_.isFailed) .map(_.getFailureMessage) .groupBy(identity) .foreach { case (message, stream) => - logger.error(s"${stream.size}x: $message") + noRequestIdLogger.error(s"${stream.size}x: $message") } } } override def afterBulk(executionId: Long, request: BulkRequest, failure: Exception): Unit = { - logger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) + noRequestIdLogger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) } } diff --git a/es91x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala b/es91x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala index a8def0ec7a..b3c5593c36 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala @@ -22,7 +22,7 @@ import org.apache.http.auth.{AuthScope, Credentials, UsernamePasswordCredentials import org.apache.http.conn.ssl.NoopHostnameVerifier import org.apache.http.impl.client.BasicCredentialsProvider import org.apache.http.impl.nio.client.HttpAsyncClientBuilder -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.* import org.elasticsearch.client.RestClient.FailureListener import tech.beshu.ror.accesscontrol.audit.sink.AuditDataStreamCreator @@ -38,7 +38,7 @@ import scala.collection.parallel.CollectionConverters.* final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient]) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { override def submit(indexName: IndexName.Full, documentId: String, jsonRecord: String) (implicit requestId: RequestId): Unit = { @@ -77,21 +77,21 @@ final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient] override def onSuccess(response: Response): Unit = { response.getStatusLine.getStatusCode / 100 match { case 2 => // 2xx - logger.debug(s"[${requestId.show}] Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") + logger.debug(s"Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") case _ => - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") } } override def onFailure(ex: Exception): Unit = { - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId]", ex) + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId]", ex) } } override val dataStreamCreator: AuditDataStreamCreator = new AuditDataStreamCreator(clients.map(new RestClientDataStreamService(_))) } -object RestClientAuditSinkService extends Logging { +object RestClientAuditSinkService extends RequestIdAwareLogging { def create(remoteCluster: AuditCluster.RemoteAuditCluster): RestClientAuditSinkService = { remoteCluster.mode match { @@ -122,7 +122,7 @@ object RestClientAuditSinkService extends Logging { .setFailureListener( new FailureListener { override def onFailure(node: Node): Unit = { - logger.debug( + noRequestIdLogger.debug( s"[AUDIT] Node marked dead: ${node.getHost.getSchemeName}://${node.getHost.getHostName}:${node.getHost.getPort}. The client will attempt failover.", ) } diff --git a/es91x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala b/es91x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala index ce17639c06..b18c4fbfee 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.Channel import io.netty.handler.ssl.NotSslRecordException -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.network.NetworkService import org.elasticsearch.common.settings.{ClusterSettings, Settings} import org.elasticsearch.http.netty4.Netty4HttpServerTransport @@ -41,7 +41,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, tracer: Tracer, fipsCompliant: Boolean) extends Netty4HttpServerTransport(settings, networkService, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory, tracer, TLSConfig.noTLS(), null, null) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, ssl.clientAuthenticationEnabled) @@ -49,7 +49,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, override def onException(channel: HttpChannel, cause: Exception): Unit = { if (!this.lifecycle.started) return - else if (cause.getCause.isInstanceOf[NotSslRecordException]) logger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) + else if (cause.getCause.isInstanceOf[NotSslRecordException]) noRequestIdLogger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) else super.onException(channel, cause) channel.close() } diff --git a/es91x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala b/es91x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala index 2fa1d7871c..2d2b0360d4 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.* import io.netty.handler.ssl.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.TransportVersion import org.elasticsearch.cluster.node.DiscoveryNode import org.elasticsearch.common.io.stream.NamedWriteableRegistry @@ -46,7 +46,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, sharedGroupFactory: SharedGroupFactory, fipsCompliant: Boolean) extends Netty4Transport(settings, TransportVersion.current(), threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = SSLCertHelper.prepareClientSSLContext(ssl, fipsCompliant, ssl.certificateVerificationEnabled) private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, clientAuthenticationEnabled = false) @@ -78,7 +78,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, override def exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable): Unit = { if (cause.isInstanceOf[NotSslRecordException] || (cause.getCause != null && cause.getCause.isInstanceOf[NotSslRecordException])) { - logger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") + noRequestIdLogger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") ctx.channel.close } else { super.exceptionCaught(ctx, cause) diff --git a/es91x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala b/es91x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala index bdb78c1fca..d552559499 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.utils import cats.Show import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.client.internal.node.NodeClient import org.elasticsearch.rest.* @@ -35,7 +35,7 @@ import java.util import scala.util.Try class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandler) - extends RestHandler with Logging { + extends RestHandler with RequestIdAwareLogging { private val wrapped = doPrivileged { wrapSomeActions(underlying) @@ -96,11 +96,11 @@ class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandle private def logError(error: AuthorizationValueError): Unit = { { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorSanitizedShow - logger.warn(s"The incoming request was malformed. Cause: ${error.show}") + noRequestIdLogger.warn(s"The incoming request was malformed. Cause: ${error.show}") } if (logger.delegate.isDebugEnabled()) { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorWithDetailsShow - logger.debug(s"Malformed request detailed cause: ${error.show}") + noRequestIdLogger.debug(s"Malformed request detailed cause: ${error.show}") } } diff --git a/es91x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala b/es91x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala index 5ab1e35742..a9af8f710a 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala @@ -16,13 +16,13 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.settings.Settings import tech.beshu.ror.tools.core.patches.PatchingVerifier import tech.beshu.ror.tools.core.patches.PatchingVerifier.Error.{CannotVerifyIfPatched, EsNotPatched} import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -object EsPatchVerifier extends Logging { +object EsPatchVerifier extends RequestIdAwareLogging { def verify(settings: Settings): Unit = doPrivileged { pathHomeFrom(settings).flatMap(PatchingVerifier.verify) match { @@ -30,7 +30,7 @@ object EsPatchVerifier extends Logging { case Left(e@EsNotPatched(_)) => throw new IllegalStateException(e.message) case Left(e@CannotVerifyIfPatched(_)) => - logger.warn(e.message) + noRequestIdLogger.warn(e.message) } } diff --git a/es91x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala b/es91x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala index b73104a175..c292a44ed2 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.internal.node.NodeClient import org.elasticsearch.transport.RemoteClusterService import org.joor.Reflect.on @@ -26,14 +26,14 @@ import java.util.function.Supplier import scala.util.{Failure, Success, Try} class RemoteClusterServiceSupplier(nodeClient: NodeClient) - extends Supplier[Option[RemoteClusterService]] with Logging { + extends Supplier[Option[RemoteClusterService]] with RequestIdAwareLogging { override def get(): Option[RemoteClusterService] = { extractRemoteClusterService() match { case Success(remoteClusterService) => remoteClusterService case Failure(ex) => - logger.error("Cannot extract RemoteClusterService from NodeClient", ex) + noRequestIdLogger.error("Cannot extract RemoteClusterService from NodeClient", ex) None } } diff --git a/es92x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es92x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index 8ecc9c9488..8d7939fddf 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.support.{ActionFilter, ActionFilterChain} import org.elasticsearch.action.{ActionListener, ActionRequest, ActionResponse} import org.elasticsearch.client.internal.node.NodeClient @@ -62,7 +62,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, rorEsConfig: ReadonlyRestEsConfig) (implicit environmentConfig: EnvironmentConfig) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = environmentConfig.uniqueIdentifierGenerator @@ -208,12 +208,12 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def handleRorNotReadyYet(esContext: EsContext): Unit = { - logger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") + noRequestIdLogger.warn(s"[${esContext.correlationId.value.show}] Cannot handle the request ${esContext.channel.restRequest.path.show} because ReadonlyREST hasn't started yet") rorNotAvailableRequestHandler.handleRorNotReadyYet(esContext) } private def handleRorFailedToStart(esContext: EsContext): Unit = { - logger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") + noRequestIdLogger.error(s"[${esContext.correlationId.value.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST failed to start") rorNotAvailableRequestHandler.handleRorFailedToStart(esContext) } @@ -235,7 +235,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, } private def logAndSetStartingFailureState(failure: StartingFailure): Unit = { - logger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) + noRequestIdLogger.error(s"ROR starting failure: ${failure.message}", failure.throwable.orNull) rorInstanceState.set(RorInstanceStartingState.NotStarted(failure)) } } diff --git a/es92x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala b/es92x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala index 1fb22fc79d..53452eb8e6 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/ResponseFieldsFiltering.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es import monix.execution.atomic.Atomic -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.xcontent.LoggingDeprecationHandler import org.elasticsearch.rest.RestResponse import org.elasticsearch.transport.BytesRefRecycler @@ -32,7 +32,7 @@ import tech.beshu.ror.accesscontrol.domain.ResponseFieldsFiltering.{AccessMode, import scala.jdk.CollectionConverters.* trait ResponseFieldsFiltering { - this: Logging => + this: RequestIdAwareLogging => private val responseFieldsRestrictions: Atomic[Option[ResponseFieldsRestrictions]] = Atomic(None: Option[ResponseFieldsRestrictions]) diff --git a/es92x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala b/es92x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala index 0f26750588..da95de59a4 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/RorActionListener.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.action.{ActionListener, ActionResponse} import org.elasticsearch.threadpool.ThreadPool @@ -37,7 +37,7 @@ sealed abstract class RorActionListener[T](val underlying: ActionListener[T]) ex final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionListener[T], correlationId: Eval[CorrelationId]) - extends RorActionListener[T](underlying) with Logging { + extends RorActionListener[T](underlying) with RequestIdAwareLogging { override def onFailure(e: Exception): Unit = { super.onFailure(adaptExceptionIfNeeded(e)) @@ -47,7 +47,7 @@ final class HidingInternalErrorDetailsRorActionListener[T](underlying: ActionLis ex match { case esException: ElasticsearchException => esException case other => - logger.error(s"[${correlationId.value.show}] Internal error.", other) + noRequestIdLogger.error(s"[${correlationId.value.show}] Internal error.", other) new ElasticsearchException(s"[${correlationId.value.show}] Internal error. See logs for details.") } } diff --git a/es92x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala b/es92x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala index 4f0bc8c6fa..c68cc24623 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/RorRestChannel.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.http.HttpChannel import org.elasticsearch.rest.{AbstractRestChannel, RestChannel as EsRestChannel, RestRequest as EsRestRequest, RestResponse as EsRestResponse} import squants.information.{Bytes, Information} @@ -40,7 +40,7 @@ object RorRestChannel { final class RorRestChannel private(underlying: EsRestChannel, val restRequest: RorRestRequest) extends AbstractRestChannel(underlying.request(), true) with ResponseFieldsFiltering - with Logging { + with RequestIdAwareLogging { override def sendResponse(response: EsRestResponse): Unit = { ThreadRepo.removeRestChannel(this) diff --git a/es92x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala b/es92x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala index 6babc712b9..3c80750a25 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/actions/rradmin/RRAdminActionHandler.scala @@ -18,16 +18,15 @@ package tech.beshu.ror.es.actions.rradmin import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.ConfigApi.ConfigResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAdminActionHandler extends Logging { +class RRAdminActionHandler extends RequestIdAwareLogging { private implicit val adminRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +51,7 @@ class RRAdminActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAdminResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAdminAction internal error", ex) + logger.error("RRAdminAction internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es92x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala b/es92x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala index c55835a1d0..ce45c6f48e 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/actions/rrauthmock/RRAuthMockActionHandler.scala @@ -16,18 +16,15 @@ */ package tech.beshu.ror.es.actions.rrauthmock -import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.AuthMockApi.AuthMockResponse import tech.beshu.ror.boot.RorSchedulers import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -import tech.beshu.ror.utils.RorInstanceSupplier -import tech.beshu.ror.implicits.* +import tech.beshu.ror.utils.{RequestIdAwareLogging, RorInstanceSupplier} -class RRAuthMockActionHandler extends Logging { +class RRAuthMockActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -53,7 +50,7 @@ class RRAuthMockActionHandler extends Logging { case Right(response) => listener.onResponse(new RRAuthMockResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRAuthMock internal error", ex) + logger.error("RRAuthMock internal error", ex) listener.onFailure(new Exception(ex)) } } diff --git a/es92x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala b/es92x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala index aa8bb31e67..640084c4ec 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/actions/rrtestconfig/RRTestConfigActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestconfig import cats.implicits.toShow import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.api.TestConfigApi.TestConfigResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestConfigActionHandler extends Logging { +class RRTestConfigActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +52,7 @@ class RRTestConfigActionHandler extends Logging { case Right(response) => listener.onResponse(new RRTestConfigResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] RRTestConfig internal error", ex) + logger.error(s"RRTestConfig internal error", ex) listener.onFailure(new Exception(ex)) } diff --git a/es92x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala b/es92x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala index 494e9150b4..98cc0c945d 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/dlsfls/RoleIndexSearcherWrapper.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.dlsfls import cats.data.StateT import cats.implicits.* import eu.timepit.refined.types.string.NonEmptyString -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.index.DirectoryReader import org.elasticsearch.common.util.concurrent.ThreadContext import org.elasticsearch.core.CheckedFunction @@ -31,7 +31,7 @@ import java.io.IOException import java.util.function.{Function => JavaFunction} import scala.util.{Failure, Success, Try} -object RoleIndexSearcherWrapper extends Logging { +object RoleIndexSearcherWrapper extends RequestIdAwareLogging { val instance: JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] = new JavaFunction[IndexService, CheckedFunction[DirectoryReader, DirectoryReader, IOException]] { @@ -54,7 +54,7 @@ object RoleIndexSearcherWrapper extends Logging { } .map(r => (r, r)) case None => - logger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") + noRequestIdLogger.debug(s"FLS: ${constants.FIELDS_TRANSIENT} not found in threadContext") Success((reader, reader)) } } @@ -66,13 +66,13 @@ object RoleIndexSearcherWrapper extends Logging { nel <- NonEmptyString.from(value) match { case Right(nel) => Success(nel) case Left(_) => - logger.debug("FLS: empty header value") + noRequestIdLogger.debug("FLS: empty header value") failure } fields <- transientFieldsFromHeaderValue.fromRawValue(nel) match { case result@Success(_) => result case Failure(ex) => - logger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) + noRequestIdLogger.debug(s"FLS: Cannot decode fields from ${constants.FIELDS_TRANSIENT} header value", ex) failure } } yield fields diff --git a/es92x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala b/es92x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala index 6e90eedff3..e4e18e54b7 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/dlsfls/RorDocumentFieldReader.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.dlsfls import com.google.common.collect.Iterators -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.apache.lucene.codecs.StoredFieldsReader import org.apache.lucene.index.* import org.apache.lucene.index.StoredFieldVisitor.Status @@ -39,21 +39,21 @@ import scala.jdk.CollectionConverters.* import scala.util.Try private class RorDocumentFieldReader(reader: LeafReader, fieldsRestrictions: FieldsRestrictions) - extends SequentialStoredFieldsLeafReader(reader) with Logging { + extends SequentialStoredFieldsLeafReader(reader) with RequestIdAwareLogging { private val policy = new FieldsPolicy(fieldsRestrictions) private val remainingFieldsInfo = { val fInfos = in.getFieldInfos val newInfos = if (fInfos.asScala.isEmpty) { - logger.warn("original fields were empty! This is weird!") + noRequestIdLogger.warn("original fields were empty! This is weird!") fInfos } else { val remainingFields = fInfos.asScala.filter(f => policy.canKeep(f.name)).toSet new FieldInfos(remainingFields.toArray) } - logger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") - logger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") - logger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"always allow: ${constants.FIELDS_ALWAYS_ALLOW.mkString(",")}") + noRequestIdLogger.debug(s"original fields were: ${fInfos.asScala.map(_.name).mkString(",")}") + noRequestIdLogger.debug(s"new fields are: ${newInfos.asScala.map(_.name).mkString(",")}") newInfos } private val jsonPolicyBasedFilterer = new JsonPolicyBasedFilterer(policy) diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala index 2f6a3aac03..215d65b036 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala @@ -20,7 +20,7 @@ import cats.Eval import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.* import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest import org.elasticsearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest @@ -87,7 +87,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, threadPool: ThreadPool) (implicit generator: UniqueIdentifierGenerator, scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle(engines: Engines, esContext: EsContext): Task[Either[Error, Unit]] = { @@ -243,7 +243,7 @@ class AclAwareRequestFilter(clusterService: RorClusterService, case SearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case MultiSearchTemplateEsRequestContext(r) => regularRequestHandler.handle(r) case _ => - logger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") + noRequestIdLogger.error(s"Found an child request of CompositeIndicesRequest that could not be handled: report this as a bug immediately! ${request.getClass.show}") regularRequestHandler.handle(new DummyCompositeIndicesEsRequestContext(request, esContext, aclContext, clusterService, threadPool)) } // rest diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala index cab02aff37..100edd72ac 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/CurrentUserMetadataRequestHandler.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.common.io.stream.StreamOutput import org.elasticsearch.xcontent.{ToXContent, ToXContentObject, XContentBuilder} @@ -45,7 +45,7 @@ import scala.util.{Failure, Success, Try} class CurrentUserMetadataRequestHandler(engine: Engine, esContext: EsContext) - extends Logging { + extends RequestIdAwareLogging { def handle(request: RequestContext.Aux[CurrentUserMetadataRequestBlockContext] with EsRequest[CurrentUserMetadataRequestBlockContext]): Task[Unit] = { engine.core.accessControl @@ -69,7 +69,7 @@ class CurrentUserMetadataRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(ex.asInstanceOf[Exception]) } } @@ -86,13 +86,13 @@ class CurrentUserMetadataRequestHandler(engine: Engine, )) } - private def onPassThrough(requestContext: RequestContext): Unit = { - logger.warn(s"[${requestContext.id.toRequestId.show}] Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") + private def onPassThrough(implicit requestContext: RequestContext): Unit = { + logger.warn(s"Cannot handle the ${esContext.channel.restRequest.path.show} request because ReadonlyREST plugin was disabled in settings") esContext.listener.onFailure(createRorNotEnabledResponse()) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala index 2fb01dcc41..c5c44fda92 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/RegularRequestHandler.scala @@ -20,7 +20,7 @@ import cats.data.NonEmptyList import cats.implicits.* import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.RegularRequestResult @@ -49,7 +49,7 @@ class RegularRequestHandler(engine: Engine, esContext: EsContext, threadPool: ThreadPool) (implicit scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { def handle[B <: BlockContext : BlockContextUpdater](request: RequestContext.Aux[B] with EsRequest[B]): Task[Unit] = { engine.core.accessControl @@ -85,7 +85,7 @@ class RegularRequestHandler(engine: Engine, } match { case Success(_) => case Failure(ex) => - logger.errorEx(s"[${request.id.toRequestId.show}] ACL committing result failure", ex) + logger.errorEx(s"ACL committing result failure", ex)(request) esContext.listener.onFailure(new Exception(ex)) } } @@ -99,7 +99,7 @@ class RegularRequestHandler(engine: Engine, case ModificationResult.ShouldBeInterrupted => onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case ModificationResult.CannotModify => - logger.error(s"[${request.id.toRequestId.show}] Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") + noRequestIdLogger.error(s"Cannot modify incoming request. Passing it could lead to a security leak. Report this issue as fast as you can.") onForbidden(request, NonEmptyList.one(OperationNotAllowed)) case CustomResponse(response) => respond(request, response) @@ -247,7 +247,7 @@ class RegularRequestHandler(engine: Engine, esContext.listener.onResponse(response) } - private def logRequestProcessingTime(requestContext: RequestContext): Unit = { - logger.debug(s"[${requestContext.id.toRequestId.show}] Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") + private def logRequestProcessingTime(implicit requestContext: RequestContext): Unit = { + logger.debug(s"Request processing time: ${Duration.between(requestContext.timestamp, Instant.now()).toMillis}ms") } } \ No newline at end of file diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala index f4f832dedc..bfc421bdd5 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/SearchRequestOps.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.index.query.{AbstractQueryBuilder, QueryBuilder, QueryBuilders} import org.elasticsearch.search.aggregations.AggregatorFactories @@ -40,7 +40,7 @@ import tech.beshu.ror.implicits.* import java.util.UUID import scala.jdk.CollectionConverters.* -object SearchRequestOps extends Logging { +object SearchRequestOps extends RequestIdAwareLogging { implicit class QueryBuilderOps(val builder: Option[QueryBuilder]) extends AnyVal { @@ -52,7 +52,7 @@ object SearchRequestOps extends Logging { val modifiedQuery: AbstractQueryBuilder[_] = provideNewQueryWithAppliedFilter(builder, filterQuery) Some(modifiedQuery) case None => - logger.debug(s"[${requestId.show}] No filter applied to query.") + logger.debug(s"No filter applied to query.") builder } } @@ -92,7 +92,7 @@ object SearchRequestOps extends Logging { case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, requestId) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) disableCaching(requestId) case BasedOnBlockContextOnly.NotAllowedFieldsUsed(notAllowedFields) => modifyNotAllowedFieldsInRequest(notAllowedFields) @@ -138,8 +138,8 @@ object SearchRequestOps extends Logging { } } - private def disableCaching(requestId: RequestContext.Id) = { - logger.debug(s"[${requestId.show}] ACL uses context header for fields rule, will disable request cache for SearchRequest") + private def disableCaching(implicit requestId: RequestContext.Id) = { + logger.debug(s"ACL uses context header for fields rule, will disable request cache for SearchRequest") request.requestCache(false) } } diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala index 993bdbd7a0..f0d04a6837 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/BaseEsRequestContext.scala @@ -17,7 +17,6 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.action.{CompositeIndicesRequest, IndicesRequest} import tech.beshu.ror.accesscontrol.blocks.BlockContext @@ -32,7 +31,7 @@ import java.time.Instant abstract class BaseEsRequestContext[B <: BlockContext](esContext: EsContext, clusterService: RorClusterService) - extends RequestContext with Logging { + extends RequestContext { override type BLOCK_CONTEXT = B diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala index ae8abbe1f5..2ac2595a94 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/EsRequest.scala @@ -18,16 +18,15 @@ package tech.beshu.ror.es.handler.request.context import monix.eval.Task import monix.execution.Scheduler -import org.apache.logging.log4j.scala.Logging import org.elasticsearch.action.ActionResponse import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.blocks.BlockContext -import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import scala.util.Try +import tech.beshu.ror.utils.RequestIdAwareLogging -trait EsRequest[B <: BlockContext] extends Logging { +trait EsRequest[B <: BlockContext] extends RequestIdAwareLogging { implicit def threadPool: ThreadPool final def modifyUsing(blockContext: B): ModificationResult = { @@ -35,7 +34,7 @@ trait EsRequest[B <: BlockContext] extends Logging { Try(modifyRequest(blockContext)) .fold( ex => { - logger.error(s"[${blockContext.requestContext.id.show}] Cannot modify request with filtered data", ex) + logger.error(s"Cannot modify request with filtered data", ex)(blockContext) ModificationResult.CannotModify }, identity diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala index c6a9dcbefd..f773b3efb1 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseDataStreamsEsRequestContext.scala @@ -51,7 +51,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest private def discoverDataStreams() = { val dataStreams = dataStreamsFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered data streams: ${dataStreams.show}") + logger.debug(s"Discovered data streams: ${dataStreams.show}") dataStreams } @@ -59,7 +59,7 @@ abstract class BaseDataStreamsEsRequestContext[R <: ActionRequest](actionRequest val backingIndices = backingIndicesFrom(actionRequest) backingIndices match { case BackingIndices.IndicesInvolved(filteredIndices, _) => - logger.debug(s"[${id.show}] Discovered indices: ${filteredIndices.show}") + logger.debug(s"Discovered indices: ${filteredIndices.show}") case BackingIndices.IndicesNotInvolved => } backingIndices diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala index c091179cb6..d150709314 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseFilterableEsRequestContext.scala @@ -85,7 +85,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: case Some(indices) => update(actionRequest, indices, blockContext.filter, blockContext.fieldLevelSecurity) case None => - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -101,7 +101,7 @@ abstract class BaseFilterableEsRequestContext[R <: ActionRequest](actionRequest: private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } \ No newline at end of file diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala index 71d462de57..48014e1bdc 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseIndicesEsRequestContext.scala @@ -73,7 +73,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, } yield update(actionRequest, filteredIndices, allAllowedIndices) result.getOrElse { - logger.warn(s"[${id.show}] empty list of indices produced, so we have to interrupt the request processing") + logger.warn(s"empty list of indices produced, so we have to interrupt the request processing") ShouldBeInterrupted } } @@ -86,7 +86,7 @@ abstract class BaseIndicesEsRequestContext[R <: ActionRequest](actionRequest: R, private def discoverIndices() = { val indices = requestedIndicesFrom(actionRequest).orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } } diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala index 95d882c3b5..f607c0e347 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseRepositoriesEsRequestContext.scala @@ -50,7 +50,7 @@ abstract class BaseRepositoriesEsRequestContext[R <: ActionRequest](actionReques case Some(repositories) => update(actionRequest, repositories) case None => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request, because of empty repositories list.") ShouldBeInterrupted } } diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala index b3b1d66238..7ef0f32014 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BaseSingleIndexEsRequestContext.scala @@ -42,7 +42,7 @@ abstract class BaseSingleIndexEsRequestContext[R <: ActionRequest](actionRequest filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } update(request, filteredIndices.head) } diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala index b5ab70fe7a..c1b2e7ea27 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkEsRequestContext.scala @@ -62,7 +62,7 @@ class BulkEsRequestContext(actionRequest: BulkRequest, case (_, _) => ShouldBeInterrupted } } else { - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because origin request contained different " + + logger.error(s"Cannot alter MultiGetRequest request, because origin request contained different " + s"number of requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } @@ -90,18 +90,18 @@ class BulkEsRequestContext(actionRequest: BulkRequest, updateRequestWithIndices(request, nel) Modified case None => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because empty list of indices was found") + logger.error(s"Cannot alter MultiGetRequest request, because empty list of indices was found") ShouldBeInterrupted } case Indices.NotFound => - logger.error(s"[${id.show}] Cannot alter MultiGetRequest request, because no allowed indices were found") + logger.error(s"Cannot alter MultiGetRequest request, because no allowed indices were found") ShouldBeInterrupted } } private def updateRequestWithIndices(request: DocWriteRequest[_], indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } request.index(indices.head.stringify) } diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala index 75a75fcef5..96a043b298 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/BulkShardEsRequestContext.scala @@ -53,14 +53,14 @@ class BulkShardEsRequestContext(actionRequest: BulkShardRequest, case Success(_) => Modified case Failure(ex) => - logger.error(s"[${id.show}] Cannot modify BulkShardRequest", ex) + logger.error(s"Cannot modify BulkShardRequest", ex) CannotModify } } private def tryUpdate(request: BulkShardRequest, indices: NonEmptyList[RequestedIndex[ClusterIndexName]]) = { if (indices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } val singleIndex = indices.head val uuid = clusterService.indexOrAliasUuids(singleIndex.name).toList.head diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala index 65a168092a..158ac485a5 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ClusterAllocationExplainEsRequestContext.scala @@ -45,14 +45,14 @@ class ClusterAllocationExplainEsRequestContext(actionRequest: ClusterAllocationE getRequestedIndexFrom(request) match { case Some(_) => if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateIndexIn(request, filteredIndices.head) Modified case None if filteredIndices.exists(_.name === ClusterIndexName.Local.wildcard) => Modified case None => - logger.error(s"[${id.show}] Cluster allocation explain request without index name is unavailable when block contains `indices` rule") + logger.error(s"Cluster allocation explain request without index name is unavailable when block contains `indices` rule") ShouldBeInterrupted } } diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala index 61fdab9d83..5bf09449c5 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala @@ -79,7 +79,7 @@ class EsqlIndicesEsRequestContext private(actionRequest: ActionRequest with Comp request } case Left(ClassificationError.ParsingException(ex)) => - logger.debug(s"[${id.show}] Cannot parse ESQL statement - we can pass it though, because ES is going to reject it. Cause:", ex) + logger.debug(s"Cannot parse ESQL statement - we can pass it though, because ES is going to reject it. Cause:", ex) request } } @@ -90,7 +90,7 @@ class EsqlIndicesEsRequestContext private(actionRequest: ActionRequest with Comp case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala index 5778b8968d..02dec730ed 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/GetAliasesEsRequestContext.scala @@ -66,7 +66,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, updateAliases(actionRequest, aliases) UpdateResponse.sync(updateAliasesResponse(aliases.includedOnly, _)) case None => - logger.error(s"[${id.show}] At least one alias and one index has to be allowed. " + + logger.error(s"At least one alias and one index has to be allowed. " + s"Found allowed indices: [${blockContext.indices.show}]." + s"Found allowed aliases: [${blockContext.aliases.show}]") ShouldBeInterrupted @@ -114,7 +114,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, .indices().asSafeSet .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered indices: ${indices.show}") + logger.debug(s"Discovered indices: ${indices.show}") indices } @@ -122,7 +122,7 @@ class GetAliasesEsRequestContext(actionRequest: GetAliasesRequest, val aliases = rawRequestAliasesSet(request) .flatMap(RequestedIndex.fromString) .orWildcardWhenEmpty - logger.debug(s"[${id.show}] Discovered aliases: ${aliases.show}") + logger.debug(s"Discovered aliases: ${aliases.show}") aliases } diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala index abb85d42b7..f9e2c87e53 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/IndicesAliasesEsRequestContext.scala @@ -55,7 +55,7 @@ class IndicesAliasesEsRequestContext(actionRequest: IndicesAliasesRequest, if (originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala index 584c97e9f5..834bff8e8e 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiGetEsRequestContext.scala @@ -120,7 +120,7 @@ class MultiGetEsRequestContext(actionRequest: MultiGetRequest, case Nil => updateItemWithNonExistingIndex(item) case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${indices.show}]") } item.index(index.stringify) } diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala index 989956d79a..9e13edee8d 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiSearchEsRequestContext.scala @@ -78,7 +78,7 @@ class MultiSearchEsRequestContext(actionRequest: MultiSearchRequest, } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala index 9191e33b66..5a61356f48 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/MultiTermVectorsEsRequestContext.scala @@ -47,7 +47,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { request.getRequests.removeIf { request => removeOrAlter(request, filteredIndices.toCovariantSet) } if (request.getRequests.asScala.isEmpty) { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. All indices were filtered out.") ShouldBeInterrupted } else { Modified @@ -63,7 +63,7 @@ class MultiTermVectorsEsRequestContext(actionRequest: MultiTermVectorsRequest, true case index :: rest => if (rest.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${remaining.show}]") } request.index(index.stringify) false diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala index c411df93c5..c7b99f6e85 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/PutRollupJobEsRequestContext.scala @@ -52,7 +52,7 @@ class PutRollupJobEsRequestContext private(actionRequest: ActionRequest, if(originIndices == filteredIndices.toList.toCovariantSet) { Modified } else { - logger.error(s"[${id.show}] Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") + logger.error(s"Write request with indices requires the same set of indices after filtering as at the beginning. Please report the issue.") ShouldBeInterrupted } } diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala index ba5b52b4f1..f80e716349 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReflectionBasedIndicesEsRequestContext.scala @@ -19,7 +19,7 @@ package tech.beshu.ror.es.handler.request.context.types import cats.data.NonEmptyList import cats.implicits.* import com.google.common.collect.Sets -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionRequest import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.AccessControlList.AccessControlStaticContext @@ -51,7 +51,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (tryUpdate(actionRequest, filteredIndices)) Modified else { - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. We're using reflection to modify the request indices and it fails. Please, report the issue.") ShouldBeInterrupted } } @@ -66,7 +66,7 @@ class ReflectionBasedIndicesEsRequestContext private(actionRequest: ActionReques } } -object ReflectionBasedIndicesEsRequestContext extends Logging { +object ReflectionBasedIndicesEsRequestContext extends RequestIdAwareLogging { def unapply(arg: ReflectionBasedActionRequest): Option[ReflectionBasedIndicesEsRequestContext] = { requestedIndicesFrom(arg.esContext.actionRequest) diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala index 489d0187bc..c42dfc3b78 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/ReindexEsRequestContext.scala @@ -58,10 +58,10 @@ class ReindexEsRequestContext(actionRequest: ReindexRequest, Modified } else { if (!isDestinationIndexOnFilteredIndicesList) { - logger.info(s"[${id.show}] Destination index of _reindex request is forbidden") + logger.info(s"Destination index of _reindex request is forbidden") } if (!isSearchRequestComposedOnlyOfAllowedIndices) { - logger.info(s"[${id.show}] At least one index from sources indices list of _reindex request is forbidden") + logger.info(s"At least one index from sources indices list of _reindex request is forbidden") } ShouldBeInterrupted } diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala index 2c1b0014e0..97b8ccd9c5 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/SqlIndicesEsRequestContext.scala @@ -74,7 +74,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo request } case Left(_) => - logger.debug(s"[${id.show}] Cannot parse SQL statement - we can pass it though, because ES is going to reject it") + logger.debug(s"Cannot parse SQL statement - we can pass it though, because ES is going to reject it") request } } @@ -85,7 +85,7 @@ class SqlIndicesEsRequestContext private(actionRequest: ActionRequest with Compo case Some(definedFields) => definedFields.strategy match { case FlsAtLuceneLevelApproach => - FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions, id) + FLSContextHeaderHandler.addContextHeader(threadPool, definedFields.restrictions) request case BasedOnBlockContextOnly.NotAllowedFieldsUsed(_) | BasedOnBlockContextOnly.EverythingAllowed => request diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala index 0c67384c1e..d7e743e648 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CleanupRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CleanupRepositoryEsRequestContext(actionRequest: CleanupRepositoryRequest, override protected def update(request: CleanupRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala index 44b7d78dfd..d09015139b 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/CreateRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class CreateRepositoryEsRequestContext(actionRequest: PutRepositoryRequest, override protected def update(request: PutRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala index eaf9334872..0cf32e1bea 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/DeleteRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class DeleteRepositoryEsRequestContext(actionRequest: DeleteRepositoryRequest, override protected def update(request: DeleteRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala index cee0bffd4c..d1410eff3d 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/repositories/VerifyRepositoryEsRequestContext.scala @@ -45,7 +45,7 @@ class VerifyRepositoryEsRequestContext(actionRequest: VerifyRepositoryRequest, override protected def update(request: VerifyRepositoryRequest, repositories: NonEmptyList[RepositoryName]): ModificationResult = { if (repositories.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } request.name(RepositoryName.toString(repositories.head)) Modified diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala index ead4fcf250..20501516d5 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/CreateSnapshotEsRequestContext.scala @@ -68,32 +68,32 @@ class CreateSnapshotEsRequestContext(actionRequest: CreateSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def snapshotFrom(blockContext: SnapshotRequestBlockContext) = { + private def snapshotFrom(implicit blockContext: SnapshotRequestBlockContext) = { val snapshots = blockContext.snapshots.toList snapshots match { case Nil => Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of snapshots [${snapshots.show}]") } Right(snapshot) } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala index a56aba660e..621d744767 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/DeleteSnapshotEsRequestContext.scala @@ -60,7 +60,7 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -71,14 +71,14 @@ class DeleteSnapshotEsRequestContext(actionRequest: DeleteSnapshotRequest, .toRight(()) } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext) = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext) = { val repositories = blockContext.repositories.toList repositories match { case Nil => Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala index 22869bbb4f..b81f333174 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/GetSnapshotsEsRequestContext.scala @@ -68,7 +68,7 @@ class GetSnapshotsEsRequestContext(actionRequest: GetSnapshotsRequest, case r => r } case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala index 88887db96c..156deb5b80 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/RestoreSnapshotEsRequestContext.scala @@ -63,7 +63,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } @@ -75,7 +75,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case snapshot :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") + logger.warn(s"Filtered result contains more than one snapshot. First was taken. The whole set of repositories [${snapshots.show}]") } Right(snapshot) } @@ -88,7 +88,7 @@ class RestoreSnapshotEsRequestContext private(actionRequest: RestoreSnapshotRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala index 44ee8397ec..e522e440f1 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/snapshots/SnapshotsStatusEsRequestContext.scala @@ -100,12 +100,12 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ case Right(_) => ModificationResult.Modified case Left(_) => - logger.error(s"[${id.show}] Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") + logger.error(s"Cannot update ${actionRequest.getClass.show} request. It's safer to forbid the request, but it looks like an issue. Please, report it as soon as possible.") ModificationResult.ShouldBeInterrupted } } - private def repositoryFrom(blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { + private def repositoryFrom(implicit blockContext: SnapshotRequestBlockContext): Either[Unit, RepositoryName] = { val repositories = blockContext.repositories if (allRepositoriesRequested(repositories)) { Right(RepositoryName.All) @@ -115,7 +115,7 @@ class SnapshotsStatusEsRequestContext private(actionRequest: SnapshotsStatusRequ Left(()) case repository :: rest => if (rest.nonEmpty) { - logger.warn(s"[${blockContext.requestContext.id.show}] Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") + logger.warn(s"Filtered result contains more than one repository. First was taken. The whole set of repositories [${repositories.show}]") } Right(repository) } diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala index 9b58e1b7b5..0a42f8dc82 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetComposableIndexTemplateEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.rollover.RolloverConfiguration import org.elasticsearch.action.admin.indices.template.get.GetComposableIndexTemplateAction import org.elasticsearch.cluster.metadata @@ -111,7 +111,7 @@ class GetComposableIndexTemplateEsRequestContext(actionRequest: GetComposableInd } -private[templates] object GetComposableIndexTemplateEsRequestContext extends Logging { +private[templates] object GetComposableIndexTemplateEsRequestContext extends RequestIdAwareLogging { def filter(templates: Map[String, ComposableIndexTemplate], usingTemplate: Set[Template] => Set[Template]) diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala index bd74c3a18f..1c6eecf409 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/GetTemplatesEsRequestContext.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.context.types.templates import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.admin.indices.template.get.{GetIndexTemplatesRequest, GetIndexTemplatesResponse} import org.elasticsearch.cluster.metadata.{AliasMetadata, IndexTemplateMetadata} import org.elasticsearch.common.collect.ImmutableOpenMap @@ -104,7 +104,7 @@ class GetTemplatesEsRequestContext(actionRequest: GetIndexTemplatesRequest, } -private[templates] object GetTemplatesEsRequestContext extends Logging { +private[templates] object GetTemplatesEsRequestContext extends RequestIdAwareLogging { def filter(templates: Iterable[IndexTemplateMetadata], usingTemplate: Set[Template] => Set[Template]) diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala index a8951de5b1..32116d8212 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/MultiSearchTemplateEsRequestContext.scala @@ -72,7 +72,7 @@ class MultiSearchTemplateEsRequestContext private(actionRequest: ActionRequest w } ModificationResult.UpdateResponse.sync(filterFieldsFromResponse(blockContext.fieldLevelSecurity)) } else { - logger.error(s"[${id.show}] Cannot alter MultiSearchRequest request, because origin request contained different number of" + + logger.error(s"Cannot alter MultiSearchRequest request, because origin request contained different number of" + s" inner requests, than altered one. This can be security issue. So, it's better for forbid the request") ShouldBeInterrupted } diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala index e6f6d8916e..434787a686 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateIndexTemplateRequestEsRequestContext.scala @@ -55,7 +55,7 @@ class SimulateIndexTemplateRequestEsRequestContext(actionRequest: SimulateIndexT filteredIndices: NonEmptyList[RequestedIndex[ClusterIndexName]], allAllowedIndices: NonEmptyList[ClusterIndexName]): ModificationResult = { if (filteredIndices.tail.nonEmpty) { - logger.warn(s"[${id.show}] Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") + logger.warn(s"Filtered result contains more than one index. First was taken. The whole set of indices [${filteredIndices.show}]") } updateRequest(request, filteredIndices.head, allAllowedIndices) } diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala index dae9f408ea..ff1bec011a 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/templates/SimulateTemplateRequestEsRequestContext.scala @@ -110,7 +110,7 @@ class SimulateExistingTemplateRequestEsRequestContext(existingTemplateName: Temp case Some(_) => updateResponse(namePatterns.toList, blockContext.allAllowedIndices.toList) case None => - logger.info(s"[${id.show}] User has no access to template ${existingTemplateName.show}") + logger.info(s"User has no access to template ${existingTemplateName.show}") ModificationResult.ShouldBeInterrupted } case other => diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala index f4217184af..88811c3d87 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/request/queries/QueryFieldsUsage.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.handler.request.queries import cats.data.NonEmptyList import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.index.query.* import org.joor.Reflect.on import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.RequestFieldsUsage @@ -30,7 +30,7 @@ trait QueryFieldsUsage[QUERY <: QueryBuilder] { def fieldsIn(query: QUERY): RequestFieldsUsage } -object QueryFieldsUsage extends Logging { +object QueryFieldsUsage extends RequestIdAwareLogging { def apply[QUERY <: QueryBuilder](implicit ev: QueryFieldsUsage[QUERY]): QueryFieldsUsage[QUERY] = ev implicit class Ops[QUERY <: QueryBuilder : QueryFieldsUsage](val query: QUERY) { @@ -61,7 +61,7 @@ object QueryFieldsUsage extends Logging { Option(on(query).call("getFieldName").get[String]) match { case Some(fieldName: String) => UsingFields(NonEmptyList.one(UsedField(fieldName))) case _ => - logger.debug(s"Cannot extract fields for terms set query") + noRequestIdLogger.debug(s"Cannot extract fields for terms set query") CannotExtractFields } } @@ -87,7 +87,7 @@ object QueryFieldsUsage extends Logging { case builder: TermsSetQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder: WildcardQueryBuilder => resolveFieldsUsageForLeafQuery(builder) case builder => - logger.debug(s"Cannot extract fields for query: ${builder.getName}") + noRequestIdLogger.debug(s"Cannot extract fields for query: ${builder.getName}") CannotExtractFields } diff --git a/es92x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala b/es92x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala index 0998bb9a5b..b4671e9e4d 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/handler/response/FLSContextHeaderHandler.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.handler.response import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.threadpool.ThreadPool import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.FieldsRestrictions import tech.beshu.ror.accesscontrol.domain.Header @@ -26,17 +26,17 @@ import tech.beshu.ror.accesscontrol.headerValues.transientFieldsToHeaderValue import tech.beshu.ror.accesscontrol.request.RequestContext import tech.beshu.ror.implicits.* -object FLSContextHeaderHandler extends Logging { +object FLSContextHeaderHandler extends RequestIdAwareLogging { def addContextHeader(threadPool: ThreadPool, - fieldsRestrictions: FieldsRestrictions, - requestId: RequestContext.Id): Unit = { + fieldsRestrictions: FieldsRestrictions) + (implicit requestId: RequestContext.Id): Unit = { val threadContext = threadPool.getThreadContext val header = createContextHeader(fieldsRestrictions) Option(threadContext.getHeader(header.name.value.value)) match { case None => implicit val show = headerShow - logger.debug(s"[${requestId.show}] Adding thread context header required by lucene. Header: '${header.show}'") + logger.debug(s"Adding thread context header required by lucene. Header: '${header.show}'") threadContext.putHeader(header.name.value.value, header.value.value) case Some(_) => } diff --git a/es92x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala b/es92x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala index 8e0e1e29a2..93a6c3fe55 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/services/EsDataStreamService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.admin.indices.template.get.{GetComponentTemplateAction, GetComposableIndexTemplateAction} import org.elasticsearch.action.admin.indices.template.put.{PutComponentTemplateAction, TransportPutComposableIndexTemplateAction} @@ -47,7 +47,7 @@ import scala.jdk.CollectionConverters.* final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJsonParserFactory)(using Clock) extends DataStreamService - with Logging { + with RequestIdAwareLogging { private val masterNodeTimeout: TimeValue = TimeValue(30000) private val ackTimeout: TimeValue = TimeValue(30000) @@ -205,11 +205,11 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ response <- Task.measure( task = Task.delay(nodeClient.execute(action, request).actionGet()), logTimeMeasurement = duration => Task.delay { - logger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") + noRequestIdLogger.debug(s"Action ${action.name()} request: ${request.toString}, taken ${duration.toMillis}ms") } ) _ <- Task.delay { - logger.debug(s"Action ${action.name()} response: ${response.toString}") + noRequestIdLogger.debug(s"Action ${action.name()} response: ${response.toString}") } } yield response } @@ -217,7 +217,7 @@ final class EsDataStreamService(client: NodeClient, jsonParserFactory: XContentJ def executeAck[REQUEST <: ActionRequest, RESPONSE <: AcknowledgedResponse](action: ActionType[RESPONSE], request: REQUEST): Task[RESPONSE] = { executeT(action, request) - .tapEval(response => Task.delay(logger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) + .tapEval(response => Task.delay(noRequestIdLogger.debug(s"Action ${action.name()} acknowledged: ${response.isAcknowledged}"))) } private def supportedActions: Map[ActionType[ActionResponse], TransportAction[ActionRequest, ActionResponse]] = { diff --git a/es92x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala b/es92x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala index 40ae6d97e0..f24d74c52d 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/services/EsIndexJsonContentService.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.services import cats.implicits.* import monix.eval.Task -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ResourceNotFoundException import org.elasticsearch.action.support.WriteRequest.RefreshPolicy import org.elasticsearch.client.internal.node.NodeClient @@ -37,7 +37,7 @@ import scala.jdk.CollectionConverters.* class EsIndexJsonContentService(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexJsonContentService - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -62,14 +62,14 @@ class EsIndexJsonContentService(client: NodeClient, Option(response.getSourceAsMap) match { case Some(map) => val source = map.asScala.toMap.asStringMap - logger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: ${showSource(source)}") Right(source) case None => - logger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") + noRequestIdLogger.warn(s"Document [${index.show} ID=$id] _source is not available. Assuming it's empty") Right(Map.empty[String, String]) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(ContentNotFound) } } @@ -77,7 +77,7 @@ class EsIndexJsonContentService(client: NodeClient, .onErrorRecover { case _: ResourceNotFoundException => Left(ContentNotFound) case ex => - logger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot get source of document [${index.show} ID=$id]", ex) Left(CannotReachContentSource) } } @@ -103,14 +103,14 @@ class EsIndexJsonContentService(client: NodeClient, case status if status / 100 == 2 => Right(()) case status => - logger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]. Unexpected response: HTTP $status, response: ${response.toString}") Left(CannotWriteToIndex) } } .executeOn(RorSchedulers.blockingScheduler) .onErrorRecover { case ex => - logger.error(s"Cannot write to document [${index.show} ID=$id]", ex) + noRequestIdLogger.error(s"Cannot write to document [${index.show} ID=$id]", ex) Left(CannotWriteToIndex) } } diff --git a/es92x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala b/es92x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala index 468ab307ba..f12b3c9b90 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/services/EsServerBasedRorClusterService.scala @@ -22,7 +22,7 @@ import cats.kernel.Monoid import eu.timepit.refined.types.string.NonEmptyString import monix.eval.Task import monix.execution.{CancelablePromise, Scheduler} -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.ActionListener import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction.{ResolvedAlias, ResolvedIndex} @@ -65,7 +65,7 @@ class EsServerBasedRorClusterService(nodeName: String, threadPool: ThreadPool) (implicit val scheduler: Scheduler) extends RorClusterService - with Logging { + with RequestIdAwareLogging { import EsServerBasedRorClusterService.* @@ -159,7 +159,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractAccessibilityFrom) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify get request. Blocking document", ex) + logger.error(s"Could not verify get request. Blocking document", ex)(id) Inaccessible } } @@ -171,7 +171,7 @@ class EsServerBasedRorClusterService(nodeName: String, .call(extractResultsFromSearchResponse) .onErrorRecover { case ex => - logger.error(s"[${id.show}] Could not verify documents returned by multi get response. Blocking all returned documents", ex) + logger.error(s"Could not verify documents returned by multi get response. Blocking all returned documents", ex)(id) blockAllDocsReturned(documents) } .map(results => zip(results, documents)) @@ -280,7 +280,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService): Task[List[FullRemoteDataStreamWithAliases]] = { getRemoteClusterClient(remoteClusterService, remoteClusterName) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -336,7 +336,7 @@ class EsServerBasedRorClusterService(nodeName: String, remoteClusterService: RemoteClusterService) = { getRemoteClusterClient(remoteClusterService, remoteClusterName) match { case Failure(_) => - logger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") + noRequestIdLogger.error(s"Cannot get remote cluster client for remote cluster with name: ${remoteClusterName.show}") Task.now(List.empty) case Success(client) => resolveRemoteIndicesUsing(client) @@ -427,7 +427,7 @@ class EsServerBasedRorClusterService(nodeName: String, } } case None => - logger.error("Cannot supply Snapshots Service. Please, report the issue!!!") + noRequestIdLogger.error("Cannot supply Snapshots Service. Please, report the issue!!!") Task.now(Set.empty[Snapshot]) } } diff --git a/es92x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala b/es92x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala index 82d11a46ac..b76ae9fd0f 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/services/NodeClientBasedAuditSinkService.scala @@ -17,7 +17,7 @@ package tech.beshu.ror.es.services import cats.data.NonEmptyList -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.action.bulk.{BulkProcessor2, BulkRequest, BulkResponse} import org.elasticsearch.action.index.IndexRequest import org.elasticsearch.action.{ActionListener, DocWriteRequest} @@ -41,7 +41,7 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, (using Clock) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { private val bulkProcessor = BulkProcessor2 @@ -81,25 +81,25 @@ final class NodeClientBasedAuditSinkService(client: NodeClient, private class AuditSinkBulkProcessorListener extends BulkProcessor2.Listener { override def beforeBulk(executionId: Long, request: BulkRequest): Unit = { - logger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") + noRequestIdLogger.debug(s"Flushing ${request.numberOfActions} bulk actions ...") } override def afterBulk(executionId: Long, request: BulkRequest, response: BulkResponse): Unit = { if (response.hasFailures) { - logger.error("Some failures flushing the BulkProcessor: ") + noRequestIdLogger.error("Some failures flushing the BulkProcessor: ") response .getItems.to(LazyList) .filter(_.isFailed) .map(_.getFailureMessage) .groupBy(identity) .foreach { case (message, stream) => - logger.error(s"${stream.size}x: $message") + noRequestIdLogger.error(s"${stream.size}x: $message") } } } override def afterBulk(executionId: Long, request: BulkRequest, failure: Exception): Unit = { - logger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) + noRequestIdLogger.error(s"Failed flushing the BulkProcessor: ${failure.getMessage}", failure) } } diff --git a/es92x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala b/es92x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala index a8def0ec7a..b3c5593c36 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/services/RestClientAuditSinkService.scala @@ -22,7 +22,7 @@ import org.apache.http.auth.{AuthScope, Credentials, UsernamePasswordCredentials import org.apache.http.conn.ssl.NoopHostnameVerifier import org.apache.http.impl.client.BasicCredentialsProvider import org.apache.http.impl.nio.client.HttpAsyncClientBuilder -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.* import org.elasticsearch.client.RestClient.FailureListener import tech.beshu.ror.accesscontrol.audit.sink.AuditDataStreamCreator @@ -38,7 +38,7 @@ import scala.collection.parallel.CollectionConverters.* final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient]) extends IndexBasedAuditSinkService with DataStreamBasedAuditSinkService - with Logging { + with RequestIdAwareLogging { override def submit(indexName: IndexName.Full, documentId: String, jsonRecord: String) (implicit requestId: RequestId): Unit = { @@ -77,21 +77,21 @@ final class RestClientAuditSinkService private(clients: NonEmptyList[RestClient] override def onSuccess(response: Response): Unit = { response.getStatusLine.getStatusCode / 100 match { case 2 => // 2xx - logger.debug(s"[${requestId.show}] Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") + logger.debug(s"Audit event handled by node ${response.getHost.getHostName}:${response.getHost.getPort}") case _ => - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId] - response code: ${response.getStatusLine.getStatusCode}") } } override def onFailure(ex: Exception): Unit = { - logger.error(s"[${requestId.show}] Cannot submit audit event [index: $indexName, doc: $documentId]", ex) + logger.error(s"Cannot submit audit event [index: $indexName, doc: $documentId]", ex) } } override val dataStreamCreator: AuditDataStreamCreator = new AuditDataStreamCreator(clients.map(new RestClientDataStreamService(_))) } -object RestClientAuditSinkService extends Logging { +object RestClientAuditSinkService extends RequestIdAwareLogging { def create(remoteCluster: AuditCluster.RemoteAuditCluster): RestClientAuditSinkService = { remoteCluster.mode match { @@ -122,7 +122,7 @@ object RestClientAuditSinkService extends Logging { .setFailureListener( new FailureListener { override def onFailure(node: Node): Unit = { - logger.debug( + noRequestIdLogger.debug( s"[AUDIT] Node marked dead: ${node.getHost.getSchemeName}://${node.getHost.getHostName}:${node.getHost.getPort}. The client will attempt failover.", ) } diff --git a/es92x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala b/es92x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala index 95fd8dbc81..799d858ab0 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4HttpServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.Channel import io.netty.handler.ssl.NotSslRecordException -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.network.NetworkService import org.elasticsearch.common.settings.{ClusterSettings, Settings} import org.elasticsearch.http.netty4.Netty4HttpServerTransport @@ -41,7 +41,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, telemetryProvider: TelemetryProvider, fipsCompliant: Boolean) extends Netty4HttpServerTransport(settings, networkService, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory, telemetryProvider, TLSConfig.noTLS(), null, null) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, ssl.clientAuthenticationEnabled) @@ -49,7 +49,7 @@ class SSLNetty4HttpServerTransport(settings: Settings, override def onException(channel: HttpChannel, cause: Exception): Unit = { if (!this.lifecycle.started) return - else if (cause.getCause.isInstanceOf[NotSslRecordException]) logger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) + else if (cause.getCause.isInstanceOf[NotSslRecordException]) noRequestIdLogger.warn(cause.getMessage + " connecting from: " + channel.getRemoteAddress) else super.onException(channel, cause) channel.close() } diff --git a/es92x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala b/es92x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala index 2fa1d7871c..2d2b0360d4 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.ssl import io.netty.channel.* import io.netty.handler.ssl.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.TransportVersion import org.elasticsearch.cluster.node.DiscoveryNode import org.elasticsearch.common.io.stream.NamedWriteableRegistry @@ -46,7 +46,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, sharedGroupFactory: SharedGroupFactory, fipsCompliant: Boolean) extends Netty4Transport(settings, TransportVersion.current(), threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = SSLCertHelper.prepareClientSSLContext(ssl, fipsCompliant, ssl.certificateVerificationEnabled) private val serverSslContext = SSLCertHelper.prepareServerSSLContext(ssl, fipsCompliant, clientAuthenticationEnabled = false) @@ -78,7 +78,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, override def exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable): Unit = { if (cause.isInstanceOf[NotSslRecordException] || (cause.getCause != null && cause.getCause.isInstanceOf[NotSslRecordException])) { - logger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") + noRequestIdLogger.error("Receiving non-SSL connections from: (" + ctx.channel.remoteAddress + "). Will disconnect") ctx.channel.close } else { super.exceptionCaught(ctx, cause) diff --git a/es92x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala b/es92x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala index bdb78c1fca..d552559499 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/utils/ChannelInterceptingRestHandlerDecorator.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.utils import cats.Show import cats.implicits.* -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.ElasticsearchException import org.elasticsearch.client.internal.node.NodeClient import org.elasticsearch.rest.* @@ -35,7 +35,7 @@ import java.util import scala.util.Try class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandler) - extends RestHandler with Logging { + extends RestHandler with RequestIdAwareLogging { private val wrapped = doPrivileged { wrapSomeActions(underlying) @@ -96,11 +96,11 @@ class ChannelInterceptingRestHandlerDecorator private(val underlying: RestHandle private def logError(error: AuthorizationValueError): Unit = { { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorSanitizedShow - logger.warn(s"The incoming request was malformed. Cause: ${error.show}") + noRequestIdLogger.warn(s"The incoming request was malformed. Cause: ${error.show}") } if (logger.delegate.isDebugEnabled()) { implicit val show: Show[AuthorizationValueError] = authorizationValueErrorWithDetailsShow - logger.debug(s"Malformed request detailed cause: ${error.show}") + noRequestIdLogger.debug(s"Malformed request detailed cause: ${error.show}") } } diff --git a/es92x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala b/es92x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala index 5ab1e35742..a9af8f710a 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/utils/EsPatchVerifier.scala @@ -16,13 +16,13 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.common.settings.Settings import tech.beshu.ror.tools.core.patches.PatchingVerifier import tech.beshu.ror.tools.core.patches.PatchingVerifier.Error.{CannotVerifyIfPatched, EsNotPatched} import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged -object EsPatchVerifier extends Logging { +object EsPatchVerifier extends RequestIdAwareLogging { def verify(settings: Settings): Unit = doPrivileged { pathHomeFrom(settings).flatMap(PatchingVerifier.verify) match { @@ -30,7 +30,7 @@ object EsPatchVerifier extends Logging { case Left(e@EsNotPatched(_)) => throw new IllegalStateException(e.message) case Left(e@CannotVerifyIfPatched(_)) => - logger.warn(e.message) + noRequestIdLogger.warn(e.message) } } diff --git a/es92x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala b/es92x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala index b73104a175..c292a44ed2 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/utils/RemoteClusterServiceSupplier.scala @@ -16,7 +16,7 @@ */ package tech.beshu.ror.es.utils -import org.apache.logging.log4j.scala.Logging +import tech.beshu.ror.utils.RequestIdAwareLogging import org.elasticsearch.client.internal.node.NodeClient import org.elasticsearch.transport.RemoteClusterService import org.joor.Reflect.on @@ -26,14 +26,14 @@ import java.util.function.Supplier import scala.util.{Failure, Success, Try} class RemoteClusterServiceSupplier(nodeClient: NodeClient) - extends Supplier[Option[RemoteClusterService]] with Logging { + extends Supplier[Option[RemoteClusterService]] with RequestIdAwareLogging { override def get(): Option[RemoteClusterService] = { extractRemoteClusterService() match { case Success(remoteClusterService) => remoteClusterService case Failure(ex) => - logger.error("Cannot extract RemoteClusterService from NodeClient", ex) + noRequestIdLogger.error("Cannot extract RemoteClusterService from NodeClient", ex) None } }