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 1f5f0860b0..6f89c4a249 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} @@ -150,7 +150,7 @@ final class AuditingTool private(auditSinks: NonEmptyList[BaseAuditSink]) } -object AuditingTool extends Logging { +object AuditingTool extends RequestIdAwareLogging { final case class AuditSettings(auditSinks: NonEmptyList[AuditSettings.AuditSink], esNodeSettings: EsNodeSettings) @@ -216,10 +216,10 @@ object AuditingTool extends Logging { _.map { case Some(auditSinks) => implicit val auditEnvironmentContext: AuditEnvironmentContext = new AuditEnvironmentContextBasedOnEsNodeSettings(settings.esNodeSettings) - 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 46a426992b..e05c18c69e 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 b6885320ee..a51a2a030e 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} @@ -86,7 +86,7 @@ class UnboundidLdapConnectionPoolProvider { } -object UnboundidLdapConnectionPoolProvider extends Logging { +object UnboundidLdapConnectionPoolProvider extends RequestIdAwareLogging { final case class LdapConnectionConfig(poolName: LdapService.Name, connectionMethod: ConnectionMethod, @@ -250,7 +250,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 f5328c0f55..b491183f7f 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 authenticate as: ${credentials.user.show}") + logger.debug(s"Attempting authenticate 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 e28d22a4f7..8cb37c1d54 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.* @@ -38,7 +38,7 @@ trait KibanaRelatedRule { } abstract class BaseKibanaRule(val settings: Settings) - extends RegularRule with KibanaRelatedRule with Logging { + extends RegularRule with KibanaRelatedRule with RequestIdAwareLogging { import BaseKibanaRule.* @@ -57,13 +57,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 } @@ -79,7 +79,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 } @@ -92,7 +92,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 } @@ -106,7 +106,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 } @@ -132,7 +132,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 } @@ -142,7 +142,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 } @@ -164,7 +164,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 } @@ -177,7 +177,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 } @@ -187,7 +187,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 } @@ -197,43 +197,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 } @@ -244,7 +244,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 2dd0c51a06..48e8fc0239 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/CoreFactory.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/factory/CoreFactory.scala index 39a096ac50..0b7e29cfd6 100644 --- a/core/src/main/scala/tech/beshu/ror/accesscontrol/factory/CoreFactory.scala +++ b/core/src/main/scala/tech/beshu/ror/accesscontrol/factory/CoreFactory.scala @@ -20,8 +20,8 @@ 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.SystemContext +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.* import tech.beshu.ror.accesscontrol.EnabledAccessControlList.AccessControlListStaticContext import tech.beshu.ror.accesscontrol.audit.{AuditingTool, LoggingContext} @@ -71,7 +71,7 @@ trait CoreFactory { class RawRorSettingsBasedCoreFactory(esEnv: EsEnv) (implicit systemContext: SystemContext) - extends CoreFactory with Logging { + extends CoreFactory with RequestIdAwareLogging { override def createCoreFrom(rorSettings: RawRorSettings, rorSettingsIndex: RorSettingsIndex, @@ -389,7 +389,7 @@ class RawRorSettingsBasedCoreFactory(esEnv: EsEnv) } } 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/HttpClientsFactory.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/factory/HttpClientsFactory.scala index 40c7f8104f..9a14adb902 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.* @@ -81,7 +82,7 @@ object HttpClientsFactory { } // todo: remove synchronized, use more sophisticated lock mechanism -class AsyncHttpClientsFactory extends HttpClientsFactory with Logging { +class AsyncHttpClientsFactory extends HttpClientsFactory with RequestIdAwareLogging { private val existingClients = new CopyOnWriteArrayList[AsyncHttpClient]() private val isWorking = AtomicBoolean(true) @@ -117,16 +118,17 @@ class AsyncHttpClientsFactory extends HttpClientsFactory with Logging { } } catch { case ex: Throwable => - logger.error("ERR: ", ex) + noRequestIdLogger.error("ERR: ", ex) throw ex } } } 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 => @@ -148,7 +150,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) @@ -170,6 +173,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/decoders/AuditingSettingsDecoder.scala b/core/src/main/scala/tech/beshu/ror/accesscontrol/factory/decoders/AuditingSettingsDecoder.scala index ff0070c7a2..44797e67bb 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(esEnv: EsEnv): Decoder[Option[AuditingTool.AuditSettings]] = { for { @@ -355,7 +355,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 6c334da301..b381b50ac3 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 f72c832ed7..081174b371 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 8f9322301a..e7ef369d1d 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.RawRorSettingsBasedCoreFactory.CoreCreationError.Reason.Message import tech.beshu.ror.accesscontrol.factory.RawRorSettingsBasedCoreFactory.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 f0e0ed79e0..bda68044f7 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(settingsIndex: RorSettingsIndex, 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]] = @@ -126,7 +126,7 @@ class KibanaUserDataRuleDecoder(settingsIndex: RorSettingsIndex, 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 3b88b01b3f..b94f38be8d 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} @@ -40,12 +40,12 @@ class AccessControlListLoggingDecorator(val underlying: AccessControlList, auditingTool: Option[AuditingTool]) (implicit loggingContext: LoggingContext, 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 { @@ -69,13 +69,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 { @@ -91,7 +91,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) } } @@ -101,7 +101,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) => @@ -113,7 +113,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 56f49b2183..1b56143e17 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} @@ -38,7 +38,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/MainSettingsApi.scala b/core/src/main/scala/tech/beshu/ror/api/MainSettingsApi.scala index 28ae1ac9f0..0564df23e7 100644 --- a/core/src/main/scala/tech/beshu/ror/api/MainSettingsApi.scala +++ b/core/src/main/scala/tech/beshu/ror/api/MainSettingsApi.scala @@ -21,7 +21,6 @@ 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.accesscontrol.domain.RequestId import tech.beshu.ror.api.MainSettingsApi.* import tech.beshu.ror.api.MainSettingsApi.MainSettingsRequest.Type @@ -35,12 +34,13 @@ import tech.beshu.ror.settings.ror.source.ReadOnlySettingsSource.SettingsLoading import tech.beshu.ror.settings.ror.source.{FileSettingsSource, IndexSettingsSource} import tech.beshu.ror.settings.ror.{MainRorSettings, RawRorSettings, RawRorSettingsYamlParser} import tech.beshu.ror.utils.CirceOps.toCirceErrorOps +import tech.beshu.ror.utils.RequestIdAwareLogging class MainSettingsApi(rorInstance: RorInstance, settingsYamlParser: RawRorSettingsYamlParser, mainSettingsIndexSource: IndexSettingsSource[MainRorSettings], mainSettingsFileSource: FileSettingsSource[MainRorSettings]) - extends Logging { + extends RequestIdAwareLogging { import MainSettingsApi.Utils.* import MainSettingsApi.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 3640c428c1..c73cec283d 100644 --- a/core/src/main/scala/tech/beshu/ror/boot/ReadonlyRest.scala +++ b/core/src/main/scala/tech/beshu/ror/boot/ReadonlyRest.scala @@ -19,9 +19,9 @@ 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.SystemContext import tech.beshu.ror.accesscontrol.audit.AuditingTool.AuditSettings +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.accesscontrol.audit.sink.AuditSinkServiceCreator import tech.beshu.ror.accesscontrol.audit.{AuditingTool, LoggingContext} import tech.beshu.ror.accesscontrol.blocks.definitions.ldap.implementations.UnboundidLdapConnectionPoolProvider @@ -47,7 +47,7 @@ class ReadonlyRest(coreFactory: CoreFactory, auditSinkServiceCreator: AuditSinkServiceCreator) (implicit systemContext: SystemContext, scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { private[boot] val authServicesMocksProvider = new MutableMocksProviderWithCachePerRequest(AuthServicesMocks.empty) @@ -95,7 +95,7 @@ class ReadonlyRest(coreFactory: CoreFactory, expiration = TestEngine.Expiration(testSettings.expiration.ttl, testSettings.expiration.validTo) ) 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.") invalidatedTestEngine(testSettings) } } yield testEngine @@ -183,9 +183,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 e3d95bc477..72deed0eb3 100644 --- a/core/src/main/scala/tech/beshu/ror/boot/RorInstance.scala +++ b/core/src/main/scala/tech/beshu/ror/boot/RorInstance.scala @@ -21,7 +21,7 @@ import cats.syntax.either.* import monix.catnap.Semaphore 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.SystemContext import tech.beshu.ror.accesscontrol.blocks.mocks.{AuthServicesMocks, MocksProvider} import tech.beshu.ror.accesscontrol.domain.RequestId @@ -50,7 +50,7 @@ class RorInstance private(boot: ReadonlyRest, testReloadInProgress: Semaphore[Task]) (implicit systemContext: SystemContext, scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { import RorInstance.* import creators.* @@ -80,7 +80,7 @@ class RorInstance private(boot: ReadonlyRest, settingsAutoReloader.start() val id: String = UUID.randomUUID().toString - logger.info(s"[$id] ReadonlyREST was loaded!") + noRequestIdLogger.info(s"[$id] ReadonlyREST was loaded!") def engines: Option[Engines] = theMainSettingsEngine.engine.map(Engines(_, theTestSettingsEngine.engine)) diff --git a/core/src/main/scala/tech/beshu/ror/boot/RorSettingsAutoReloader.scala b/core/src/main/scala/tech/beshu/ror/boot/RorSettingsAutoReloader.scala index cba9edf674..9ad05d9cac 100644 --- a/core/src/main/scala/tech/beshu/ror/boot/RorSettingsAutoReloader.scala +++ b/core/src/main/scala/tech/beshu/ror/boot/RorSettingsAutoReloader.scala @@ -20,13 +20,13 @@ import cats.Show import cats.implicits.toShow import monix.eval.Task import monix.execution.{Cancelable, Scheduler} -import org.apache.logging.log4j.scala.Logging import tech.beshu.ror.SystemContext import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.boot.RorInstance.ScheduledReloadError.{EngineReloadError, ReloadingInProgress} import tech.beshu.ror.boot.RorInstance.{IndexSettingsReloadError, RawSettingsReloadError, ScheduledReloadError} import tech.beshu.ror.utils.DurationOps.PositiveFiniteDuration import tech.beshu.ror.implicits.* +import tech.beshu.ror.utils.RequestIdAwareLogging import java.util.concurrent.atomic.AtomicReference @@ -39,12 +39,12 @@ class EnabledRorSettingsAutoReloader(reloadInterval: PositiveFiniteDuration, instance: RorInstance) (implicit systemContext: SystemContext, scheduler: Scheduler) - extends RorSettingsAutoReloader with Logging { + extends RorSettingsAutoReloader with RequestIdAwareLogging { private val reloadTaskState: AtomicReference[ReloadTaskState] = new AtomicReference(ReloadTaskState.NotInitiated) override def start(): Unit = { - logger.info(s"[CLUSTERWIDE SETTINGS] Auto reloading of ReadonlyREST in-index settings enabled") + noRequestIdLogger.info(s"[CLUSTERWIDE SETTINGS] Auto reloading of ReadonlyREST in-index settings enabled") scheduleEnginesReload(reloadInterval) } @@ -144,19 +144,19 @@ class EnabledRorSettingsAutoReloader(reloadInterval: PositiveFiniteDuration, } private final class CancelableWithRequestId(cancelable: Cancelable, requestId: RequestId) - extends Logging { + extends RequestIdAwareLogging { def cancel(): Unit = { - logger.debug(s"[CLUSTERWIDE SETTINGS][${requestId.show}] Scheduling next in-index settings check cancelled!") + logger.debug(s"[CLUSTERWIDE SETTINGS] Scheduling next in-index settings check cancelled!")(requestId) cancelable.cancel() } } } -object DisabledRorSettingsAutoReloader extends RorSettingsAutoReloader with Logging { +object DisabledRorSettingsAutoReloader extends RorSettingsAutoReloader with RequestIdAwareLogging { override def start(): Unit = { - logger.info(s"[CLUSTERWIDE SETTINGS] Auto reloading of ReadonlyREST in-index settings disabled") + noRequestIdLogger.info(s"[CLUSTERWIDE SETTINGS] Auto reloading of ReadonlyREST in-index settings disabled") } override def stop(): Task[Unit] = Task.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 7b104b7be1..99aff7a584 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.SystemContext import tech.beshu.ror.accesscontrol.domain.RequestId import tech.beshu.ror.boot.ReadonlyRest @@ -47,14 +47,14 @@ private[engines] abstract class BaseReloadableEngine(val name: String, reloadInProgress: Semaphore[Task]) (implicit systemContext: SystemContext, scheduler: Scheduler) - extends Logging { + extends RequestIdAwareLogging { import BaseReloadableEngine.EngineUpdateType private val currentEngine: Atomic[EngineState] = AtomicAny[EngineState]( initialEngine match { case InitialEngine.Configured(engine, settings, expiration) => - logger.info(s"ROR ${name.show} engine (id=${settings.hashString().show}) was initiated (${engine.core.accessControl.description.show}).") + noRequestIdLogger.info(s"ROR ${name.show} engine (id=${settings.hashString().show}) was initiated (${engine.core.accessControl.description.show}).") stateFromInitial(EngineWithSettings(engine, settings, expiration))(RequestId(systemContext.uuidProvider.random.toString)) case InitialEngine.NotConfigured => EngineState.NotStartedYet(recentSettings = None, recentExpiration = None) @@ -78,7 +78,7 @@ private[engines] abstract class BaseReloadableEngine(val name: String, state match { case EngineState.NotStartedYet(_, _) => case working@EngineState.Working(engineWithSetting, _) => - logger.info(s"[${requestId.show}] ROR ${name.show} engine (id=${engineWithSetting.settings.hashString().show}) will be stopped ...") + logger.info(s"ROR ${name.show} engine (id=${engineWithSetting.settings.hashString().show}) will be stopped ...") stopNow(working) case EngineState.Stopped => } @@ -99,7 +99,7 @@ private[engines] abstract class BaseReloadableEngine(val name: String, EngineState.NotStartedYet(recentSettings = None, recentExpiration = None) } case oldWorkingEngine@EngineState.Working(engineWithSetting, _) => - logger.info(s"[${requestId.show}] ROR ${name.show} engine (id=${engineWithSetting.settings.hashString().show}) will be invalidated ...") + logger.info(s"ROR ${name.show} engine (id=${engineWithSetting.settings.hashString().show}) will be invalidated ...") stopEarly(oldWorkingEngine) if (keepPreviousSettings) { EngineState.NotStartedYet( @@ -155,7 +155,7 @@ private[engines] abstract class BaseReloadableEngine(val name: String, case _: EngineState.NotStartedYet => NotStartedYet(recentSettings = Some(newSettings), recentExpiration = Some(newExpiration)) case working: EngineState.Working => - logger.info(s"[${requestId.show}] ROR ${name.show} engine (id=${working.engineWithSetting.settings.hashString().show}) will be invalidated ...") + logger.info(s"ROR ${name.show} engine (id=${working.engineWithSetting.settings.hashString().show}) will be invalidated ...") stopEarly(working) NotStartedYet(recentSettings = Some(newSettings), recentExpiration = Some(newExpiration)) case EngineState.Stopped => @@ -280,14 +280,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=${newEngineWithSettings.settings.hashString().show}) is going to be used ...") + logger.info(s"ROR ${name.show} engine (id=${newEngineWithSettings.settings.hashString().show}) is going to be used ...") workingStateFrom(newEngineWithSettings) case oldWorkingEngine@EngineState.Working(_, _) => - logger.info(s"[${requestId.show}] ROR ${name.show} engine (id=${oldWorkingEngine.engineWithSetting.settings.hashString().show}) will be replaced with engine (id=${newEngineWithSettings.settings.hashString().show}) ...") + logger.info(s"ROR ${name.show} engine (id=${oldWorkingEngine.engineWithSetting.settings.hashString().show}) will be replaced with engine (id=${newEngineWithSettings.settings.hashString().show}) ...") stopEarly(oldWorkingEngine) workingStateFrom(newEngineWithSettings) case EngineState.Stopped => - logger.warn(s"[${requestId.show}] ROR ${name.show} engine (id=${newEngineWithSettings.settings.hashString().show}) cannot be used because the ROR is already stopped!") + logger.warn(s"ROR ${name.show} engine (id=${newEngineWithSettings.settings.hashString().show}) cannot be used because the ROR is already stopped!") newEngineWithSettings.engine.shutdown() EngineState.Stopped } @@ -313,7 +313,7 @@ private[engines] abstract class BaseReloadableEngine(val name: String, private def stopEngine(engineWithSetting: EngineWithSettings) (implicit requestId: RequestId): Unit = { - logger.info(s"[${requestId.show}] ROR ${name.show} engine (id=${engineWithSetting.settings.hashString().show}) is being stopped after TTL were reached ...") + logger.info(s"ROR ${name.show} engine (id=${engineWithSetting.settings.hashString().show}) is being stopped after TTL were reached ...") stop(engineWithSetting) currentEngine.transform { case EngineState.NotStartedYet(_, _) => @@ -365,7 +365,7 @@ private[engines] abstract class BaseReloadableEngine(val name: String, case EngineState.NotStartedYet(recentSettings, recentExpiration) => EngineState.NotStartedYet(recentSettings, recentExpiration) case EngineState.Working(engineWithSetting, scheduledShutdownJob) => - logger.info(s"[${requestId.show}] ROR ${name.show} engine (id=${engineWithSetting.settings.hashString().show}) is being updated with new TTL ...") + logger.info(s"ROR ${name.show} engine (id=${engineWithSetting.settings.hashString().show}) is being updated with new TTL ...") scheduledShutdownJob.foreach(_.cancel()) val engineWithNewExpiration = engineWithSetting.copy(expiration = Some(engineExpiration(expiration))) workingStateFrom(engineWithNewExpiration) @@ -388,14 +388,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.engineWithSetting.settings.hashString().show}) is being stopped early ...") + logger.info(s"ROR ${name.show} engine (id=${engineState.engineWithSetting.settings.hashString().show}) is being stopped early ...") stop(engineState.engineWithSetting) } } private def stopNow(engineState: EngineState.Working) (implicit requestId: RequestId): Unit = { - logger.info(s"[${requestId.show}] ROR ${name.show} engine (id=${engineState.engineWithSetting.settings.hashString().show}) is being stopped now ...") + logger.info(s"ROR ${name.show} engine (id=${engineState.engineWithSetting.settings.hashString().show}) is being stopped now ...") engineState.scheduledShutdownJob.foreach(_.cancel()) stop(engineState.engineWithSetting) } @@ -403,7 +403,7 @@ private[engines] abstract class BaseReloadableEngine(val name: String, private def stop(engineWithSetting: EngineWithSettings) (implicit requestId: RequestId): Unit = { engineWithSetting.engine.shutdown() - logger.info(s"[${requestId.show}] ROR ${name.show} engine (id=${engineWithSetting.settings.hashString().show}) stopped!") + logger.info(s"ROR ${name.show} engine (id=${engineWithSetting.settings.hashString().show}) stopped!") } private def isStillValid(validTo: Instant) = { diff --git a/core/src/main/scala/tech/beshu/ror/settings/RorProperties.scala b/core/src/main/scala/tech/beshu/ror/settings/RorProperties.scala index 910e74ded1..cb5c5674cd 100644 --- a/core/src/main/scala/tech/beshu/ror/settings/RorProperties.scala +++ b/core/src/main/scala/tech/beshu/ror/settings/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.accesscontrol.domain.RorSettingsFile import tech.beshu.ror.implicits.* @@ -37,7 +37,7 @@ import scala.concurrent.duration.* import scala.language.postfixOps import scala.util.{Failure, Success, Try} -object RorProperties extends Logging { +object RorProperties extends RequestIdAwareLogging { private object defaults { val refreshInterval: PositiveFiniteDuration = (5 second).toRefinedPositiveUnsafe @@ -102,7 +102,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/settings/es/RorSslSettings.scala b/core/src/main/scala/tech/beshu/ror/settings/es/RorSslSettings.scala index 958646a025..68f735ba26 100644 --- a/core/src/main/scala/tech/beshu/ror/settings/es/RorSslSettings.scala +++ b/core/src/main/scala/tech/beshu/ror/settings/es/RorSslSettings.scala @@ -20,7 +20,6 @@ import better.files.* import cats.data.{EitherT, NonEmptyList} import io.circe.{Decoder, DecodingFailure, HCursor} import monix.eval.Task -import org.apache.logging.log4j.scala.Logging import tech.beshu.ror.SystemContext import tech.beshu.ror.accesscontrol.domain.{EsConfigFile, RorSettingsFile} import tech.beshu.ror.accesscontrol.utils.CirceOps.DecoderHelpers @@ -28,11 +27,11 @@ import tech.beshu.ror.es.EsEnv import tech.beshu.ror.implicits.* import tech.beshu.ror.settings.es.SslSettings.* import tech.beshu.ror.settings.es.YamlFileBasedSettingsLoader.LoadingError -import tech.beshu.ror.utils.SSLCertHelper +import tech.beshu.ror.utils.{RequestIdAwareLogging, SSLCertHelper} import tech.beshu.ror.utils.yaml.YamlKeyDecoder sealed trait RorSslSettings -object RorSslSettings extends YamlFileBasedSettingsLoaderSupport with Logging { +object RorSslSettings extends YamlFileBasedSettingsLoaderSupport with RequestIdAwareLogging { final case class OnlyExternalSslSettings(ssl: ExternalSslSettings) extends RorSslSettings final case class OnlyInternodeSslSettings(ssl: InternodeSslSettings) extends RorSslSettings @@ -107,7 +106,7 @@ object RorSslSettings extends YamlFileBasedSettingsLoaderSupport with Logging { for { settings <- loadSslSettingsFrom(settingsFile) _ <- lift(settings match { - case None => logger.warn(s"Defining SSL settings in ReadonlyREST file is deprecated and will be removed in the future. Move your ReadonlyREST SSL settings to Elasticsearch config file. See https://docs.readonlyrest.com/elasticsearch#encryption for details") + case None => noRequestIdLogger.warn(s"Defining SSL settings in ReadonlyREST file is deprecated and will be removed in the future. Move your ReadonlyREST SSL settings to Elasticsearch config file. See https://docs.readonlyrest.com/elasticsearch#encryption for details") case Some(_) => }) } yield settings @@ -120,9 +119,9 @@ object RorSslSettings extends YamlFileBasedSettingsLoaderSupport with Logging { (implicit decoder: Decoder[Option[RorSslSettings]], systemContext: SystemContext) = { for { - _ <- lift(logger.info(s"Trying to load ROR SSL settings from '${settingsFile.show}' file ...")) + _ <- lift(noRequestIdLogger.info(s"Trying to load ROR SSL settings from '${settingsFile.show}' file ...")) settings <- EitherT(loadSetting[Option[RorSslSettings]](settingsFile, "ROR SSL settings")) - _ <- lift(logger.info(settings match { + _ <- lift(noRequestIdLogger.info(settings match { case Some(_) => s"ROR SSL settings loaded from '${settingsFile.show}' file." case None => s"No ROR SSL settings found in '${settingsFile.show}' file." })) @@ -232,7 +231,7 @@ object SslSettings { } -private object SslDecoders extends Logging { +private object SslDecoders extends RequestIdAwareLogging { object consts { val rorSection = "readonlyrest" @@ -285,7 +284,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 settings section" - logger.error(errorMessage) + noRequestIdLogger.error(errorMessage) Left(DecodingFailure(errorMessage, List.empty)) } else if (presentKeys.intersect(truststoreBasedKeys).nonEmpty) { truststoreBasedClientCertificateSettingsDecoder(c) @@ -296,7 +295,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 { @@ -320,7 +319,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 settings section" - logger.error(errorMessage) + noRequestIdLogger.error(errorMessage) Left(DecodingFailure(errorMessage, List.empty)) } else if (presentKeys.intersect(keystoreBasedKeys).nonEmpty) { keystoreBasedServerCertificateSettingsDecoder(c) @@ -329,12 +328,12 @@ private object SslDecoders extends Logging { fileBasedServerCertificateSettingsDecoder(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 settings present for server" - logger.error(errorMessage) + noRequestIdLogger.error(errorMessage) Left(DecodingFailure(errorMessage, List.empty)) } } diff --git a/core/src/main/scala/tech/beshu/ror/settings/ror/loader/ForceLoadRorSettingsFromFileLoader.scala b/core/src/main/scala/tech/beshu/ror/settings/ror/loader/ForceLoadRorSettingsFromFileLoader.scala index 1ba99f0c5b..36e6bc5470 100644 --- a/core/src/main/scala/tech/beshu/ror/settings/ror/loader/ForceLoadRorSettingsFromFileLoader.scala +++ b/core/src/main/scala/tech/beshu/ror/settings/ror/loader/ForceLoadRorSettingsFromFileLoader.scala @@ -17,13 +17,13 @@ package tech.beshu.ror.settings.ror.loader import monix.eval.Task -import org.apache.logging.log4j.scala.Logging import tech.beshu.ror.implicits.* import tech.beshu.ror.settings.ror.source.FileSettingsSource import tech.beshu.ror.settings.ror.{MainRorSettings, TestRorSettings} +import tech.beshu.ror.utils.RequestIdAwareLogging class ForceLoadRorSettingsFromFileLoader(mainSettingsFileSource: FileSettingsSource[MainRorSettings]) - extends StartingRorSettingsLoader with Logging { + extends StartingRorSettingsLoader with RequestIdAwareLogging { override def load(): Task[Either[LoadingError, (MainRorSettings, Option[TestRorSettings])]] = { val result = loadSettingsFromSource( diff --git a/core/src/main/scala/tech/beshu/ror/settings/ror/loader/RetryStrategy.scala b/core/src/main/scala/tech/beshu/ror/settings/ror/loader/RetryStrategy.scala index b8434813e9..6b459555eb 100644 --- a/core/src/main/scala/tech/beshu/ror/settings/ror/loader/RetryStrategy.scala +++ b/core/src/main/scala/tech/beshu/ror/settings/ror/loader/RetryStrategy.scala @@ -20,9 +20,9 @@ import cats.Show import cats.data.EitherT import cats.implicits.toShow import monix.eval.Task -import org.apache.logging.log4j.scala.Logging import tech.beshu.ror.implicits.* import tech.beshu.ror.settings.es.RorCoreSettingsLoadingStrategy.LoadingRetryStrategySettings +import tech.beshu.ror.utils.RequestIdAwareLogging trait RetryStrategy { def withRetry[ERROR: Show, RESULT](operation: Task[Either[ERROR, RESULT]], @@ -33,7 +33,7 @@ trait RetryStrategy { } class ConfigurableRetryStrategy(config: LoadingRetryStrategySettings) - extends RetryStrategy with Logging { + extends RetryStrategy with RequestIdAwareLogging { override def withRetry[ERROR: Show, RESULT](operation: Task[Either[ERROR, RESULT]], operationDescription: String): Task[Either[ERROR, RESULT]] = @@ -51,10 +51,10 @@ class ConfigurableRetryStrategy(config: LoadingRetryStrategySettings) case Right(value) => Task.now(Right(value)) case Left(error) if shouldRetry(currentAttempt, maxAttempts) => - logger.debug(s"$operationDescription - retry attempt $currentAttempt/$maxAttempts failed. Retrying in ${config.attemptsInterval.show}...") + noRequestIdLogger.debug(s"$operationDescription - retry attempt $currentAttempt/$maxAttempts failed. Retrying in ${config.attemptsInterval.show}...") attemptWithRetry(operation, currentAttempt + 1, maxAttempts, operationDescription) case Left(error) => - logger.debug(s"$operationDescription - failed permanently after $currentAttempt attempts: ${error.show}") + noRequestIdLogger.debug(s"$operationDescription - failed permanently after $currentAttempt attempts: ${error.show}") Task.now(Left(error)) } } yield finalResult diff --git a/core/src/main/scala/tech/beshu/ror/settings/ror/loader/RetryableIndexSourceWithFileSourceFallbackRorSettingsLoader.scala b/core/src/main/scala/tech/beshu/ror/settings/ror/loader/RetryableIndexSourceWithFileSourceFallbackRorSettingsLoader.scala index 8426e9ed0d..2328a91798 100644 --- a/core/src/main/scala/tech/beshu/ror/settings/ror/loader/RetryableIndexSourceWithFileSourceFallbackRorSettingsLoader.scala +++ b/core/src/main/scala/tech/beshu/ror/settings/ror/loader/RetryableIndexSourceWithFileSourceFallbackRorSettingsLoader.scala @@ -17,16 +17,16 @@ package tech.beshu.ror.settings.ror.loader import monix.eval.Task -import org.apache.logging.log4j.scala.Logging import tech.beshu.ror.implicits.* import tech.beshu.ror.settings.ror.source.* import tech.beshu.ror.settings.ror.{MainRorSettings, TestRorSettings} +import tech.beshu.ror.utils.RequestIdAwareLogging class RetryableIndexSourceWithFileSourceFallbackRorSettingsLoader(mainSettingsIndexSource: MainSettingsIndexSource, mainSettingsIndexLoadingRetryStrategy: RetryStrategy, mainSettingsFileSource: MainSettingsFileSource, testSettingsIndexSource: TestSettingsIndexSource) - extends StartingRorSettingsLoader with Logging { + extends StartingRorSettingsLoader with RequestIdAwareLogging { override def load(): Task[Either[LoadingError, (MainRorSettings, Option[TestRorSettings])]] = { val result = for { diff --git a/core/src/main/scala/tech/beshu/ror/settings/ror/loader/StartingRorSettingsLoader.scala b/core/src/main/scala/tech/beshu/ror/settings/ror/loader/StartingRorSettingsLoader.scala index 5b7aa0799d..8af463bd4d 100644 --- a/core/src/main/scala/tech/beshu/ror/settings/ror/loader/StartingRorSettingsLoader.scala +++ b/core/src/main/scala/tech/beshu/ror/settings/ror/loader/StartingRorSettingsLoader.scala @@ -19,25 +19,25 @@ package tech.beshu.ror.settings.ror.loader import cats.Show import cats.data.EitherT import monix.eval.Task -import org.apache.logging.log4j.scala.Logging import tech.beshu.ror.implicits.* import tech.beshu.ror.settings.ror.source.ReadOnlySettingsSource import tech.beshu.ror.settings.ror.{MainRorSettings, TestRorSettings} +import tech.beshu.ror.utils.RequestIdAwareLogging import tech.beshu.ror.utils.ScalaOps.{EitherTOps, LoggerOps} trait StartingRorSettingsLoader { - this: Logging => + this: RequestIdAwareLogging => def load(): Task[Either[LoadingError, (MainRorSettings, Option[TestRorSettings])]] protected def loadSettingsFromSource[S: Show, E: Show](source: ReadOnlySettingsSource[S, E], settingsDescription: String): EitherT[Task, LoadingError, S] = { for { - _ <- EitherT.liftTask(logger.info(s"Loading ReadonlyREST $settingsDescription ...")) + _ <- EitherT.liftTask(noRequestIdLogger.info(s"Loading ReadonlyREST $settingsDescription ...")) loadedSettings <- EitherT(source.load()) .biSemiflatTap( - error => logger.dInfo(s"Loading ReadonlyREST $settingsDescription failed: ${error.show}"), - settings => logger.dDebug(s"Loaded ReadonlyREST $settingsDescription:\n${settings.show}") + error => noRequestIdLogger.dInfo(s"Loading ReadonlyREST $settingsDescription failed: ${error.show}"), + settings => noRequestIdLogger.dDebug(s"Loaded ReadonlyREST $settingsDescription:\n${settings.show}") ) .leftMap(error => error.show) } yield loadedSettings 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 b6e07c5180..e836489418 100644 --- a/core/src/main/scala/tech/beshu/ror/utils/SSLCertHelper.scala +++ b/core/src/main/scala/tech/beshu/ror/utils/SSLCertHelper.scala @@ -22,7 +22,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 @@ -42,7 +41,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(keystoreBasedSettings) .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 keystoreBasedSettings: KeystoreBasedSettings => getPrivateKeyAndCertificateChainFromKeystore(keystoreBasedSettings) }).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) } } @@ -175,7 +174,7 @@ object SSLCertHelper extends Logging { trySetProtocolsAndCiphersInsideNewEngine(sslContextBuilder: SslContextBuilder, sslSettings) .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 @@ -203,10 +202,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) @@ -217,14 +216,14 @@ object SSLCertHelper extends Logging { private def loadKeystore(keystoreBasedSettings: KeystoreBasedSettings, fipsCompliant: Boolean): IO[KeyStore] = { for { - _ <- IO(logger.info("Preparing keystore...")) + _ <- IO(noRequestIdLogger.info("Preparing keystore...")) keystore <- loadKeystoreFromFile(keystoreBasedSettings.keystoreFile.value, keystoreBasedSettings.keystorePassword, fipsCompliant) } yield keystore } private def loadTruststore(truststoreBasedSettings: TruststoreBasedSettings, fipsCompliant: Boolean): IO[KeyStore] = { for { - _ <- IO(logger.info("Preparing truststore...")) + _ <- IO(noRequestIdLogger.info("Preparing truststore...")) truststore <- loadKeystoreFromFile(truststoreBasedSettings.truststoreFile.value, truststoreBasedSettings.truststorePassword, fipsCompliant) } yield truststore } @@ -233,7 +232,7 @@ object SSLCertHelper extends Logging { settings.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!") @@ -250,7 +249,7 @@ object SSLCertHelper extends Logging { loadKeystore(keystoreBasedSettings, fipsCompliant = true) .map { keystore => if (keystoreBasedSettings.keyPass.isDefined) { - logger.warn("ROR settings 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 settings 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, keystoreBasedSettings)) val kmf = getKeyManagerFactoryInstance(fipsCompliant = true) @@ -312,15 +311,15 @@ object SSLCertHelper extends Logging { private def trySetProtocolsAndCiphersInsideNewEngine(sslContextBuilder: SslContextBuilder, sslSettings: SslSettings) = 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 (sslSettings.allowedCiphers.nonEmpty) { sslEngine.setEnabledCipherSuites(sslSettings.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 (sslSettings.allowedProtocols.nonEmpty) { sslEngine.setEnabledProtocols(sslSettings.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}") } } @@ -332,7 +331,7 @@ object SSLCertHelper extends Logging { } getFipsCompliantKeyManagerFactory(keystoreBasedSettings) .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 { @@ -342,7 +341,7 @@ object SSLCertHelper extends Logging { case keystoreBasedSettings: KeystoreBasedSettings => getPrivateKeyAndCertificateChainFromKeystore(keystoreBasedSettings) }).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/core/src/test/scala/tech/beshu/ror/unit/acl/blocks/rules/http/HeaderOrRuleTests.scala b/core/src/test/scala/tech/beshu/ror/unit/acl/blocks/rules/http/HeaderOrRuleTests.scala index bac92f9953..1d1b9e24f5 100644 --- a/core/src/test/scala/tech/beshu/ror/unit/acl/blocks/rules/http/HeaderOrRuleTests.scala +++ b/core/src/test/scala/tech/beshu/ror/unit/acl/blocks/rules/http/HeaderOrRuleTests.scala @@ -25,7 +25,7 @@ import tech.beshu.ror.accesscontrol.blocks.BlockContext.GeneralNonIndexRequestBl import tech.beshu.ror.accesscontrol.blocks.metadata.UserMetadata import tech.beshu.ror.accesscontrol.blocks.rules.Rule.RuleResult.{Fulfilled, Rejected} import tech.beshu.ror.accesscontrol.blocks.rules.http.HeadersOrRule -import tech.beshu.ror.accesscontrol.domain.{AccessRequirement, Header, UriPath} +import tech.beshu.ror.accesscontrol.domain.{AccessRequirement, Header, RequestId, UriPath} import tech.beshu.ror.accesscontrol.orders.* import tech.beshu.ror.accesscontrol.request.{RequestContext, RestRequest} import tech.beshu.ror.syntax.* @@ -178,7 +178,7 @@ class HeaderOrRuleTests extends AnyWordSpec with MockFactory { (() => restRequest.path).expects().returning(UriPath.from("/_cat/indices")) val requestContext = mock[RequestContext] (() => requestContext.restRequest).expects().returning(restRequest).anyNumberOfTimes() - (() => requestContext.id).expects().returning(RequestContext.Id.fromString("1")).anyNumberOfTimes() + (() => requestContext.requestId).expects().returning(RequestId("1")).anyNumberOfTimes() val blockContext = GeneralNonIndexRequestBlockContext( requestContext = requestContext, userMetadata = UserMetadata.empty, diff --git a/core/src/test/scala/tech/beshu/ror/unit/acl/blocks/rules/http/HeadersAndRuleTests.scala b/core/src/test/scala/tech/beshu/ror/unit/acl/blocks/rules/http/HeadersAndRuleTests.scala index f63d963e89..71ed192374 100644 --- a/core/src/test/scala/tech/beshu/ror/unit/acl/blocks/rules/http/HeadersAndRuleTests.scala +++ b/core/src/test/scala/tech/beshu/ror/unit/acl/blocks/rules/http/HeadersAndRuleTests.scala @@ -25,7 +25,7 @@ import tech.beshu.ror.accesscontrol.blocks.BlockContext.GeneralNonIndexRequestBl import tech.beshu.ror.accesscontrol.blocks.metadata.UserMetadata import tech.beshu.ror.accesscontrol.blocks.rules.Rule.RuleResult.{Fulfilled, Rejected} import tech.beshu.ror.accesscontrol.blocks.rules.http.HeadersAndRule -import tech.beshu.ror.accesscontrol.domain.{AccessRequirement, Header, UriPath} +import tech.beshu.ror.accesscontrol.domain.{AccessRequirement, Header, RequestId, UriPath} import tech.beshu.ror.accesscontrol.orders.* import tech.beshu.ror.accesscontrol.request.{RequestContext, RestRequest} import tech.beshu.ror.syntax.* @@ -214,7 +214,7 @@ class HeadersAndRuleTests extends AnyWordSpec with MockFactory { (() => restRequest.path).expects().returning(UriPath.from("/_cat/indices")) val requestContext = mock[RequestContext] (() => requestContext.restRequest).expects().returning(restRequest).anyNumberOfTimes() - (() => requestContext.id).expects().returning(RequestContext.Id.fromString("1")).anyNumberOfTimes() + (() => requestContext.requestId).expects().returning(RequestId("1")).anyNumberOfTimes() val blockContext = GeneralNonIndexRequestBlockContext( requestContext = requestContext, userMetadata = UserMetadata.empty, diff --git a/core/src/test/scala/tech/beshu/ror/unit/acl/blocks/rules/http/SessionMaxIdleRuleTest.scala b/core/src/test/scala/tech/beshu/ror/unit/acl/blocks/rules/http/SessionMaxIdleRuleTest.scala index 44da8899df..048b2cfe17 100644 --- a/core/src/test/scala/tech/beshu/ror/unit/acl/blocks/rules/http/SessionMaxIdleRuleTest.scala +++ b/core/src/test/scala/tech/beshu/ror/unit/acl/blocks/rules/http/SessionMaxIdleRuleTest.scala @@ -26,7 +26,7 @@ import tech.beshu.ror.accesscontrol.blocks.rules.Rule.RuleResult.{Fulfilled, Rej import tech.beshu.ror.accesscontrol.blocks.rules.http.SessionMaxIdleRule import tech.beshu.ror.accesscontrol.blocks.rules.http.SessionMaxIdleRule.Settings import tech.beshu.ror.accesscontrol.domain.LoggedUser.DirectlyLoggedUser -import tech.beshu.ror.accesscontrol.domain.{CaseSensitivity, Header, User} +import tech.beshu.ror.accesscontrol.domain.{CaseSensitivity, Header, RequestId, User} import tech.beshu.ror.accesscontrol.request.{RequestContext, RestRequest} import tech.beshu.ror.providers.UuidProvider import tech.beshu.ror.syntax.* @@ -142,7 +142,7 @@ class SessionMaxIdleRuleTest extends AnyWordSpec with MockFactory { (() => restRequest.allHeaders).expects().returning(headers) val requestContext = mock[RequestContext] (() => requestContext.restRequest).expects().returning(restRequest) - (() => requestContext.id).expects().returning(RequestContext.Id.fromString("dummy")).anyNumberOfTimes() + (() => requestContext.requestId).expects().returning(RequestId("dummy")).anyNumberOfTimes() val blockContext = CurrentUserMetadataRequestBlockContext( requestContext = requestContext, userMetadata = loggedUser match { 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 b791d55d2d..df043681ab 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 @@ -61,7 +61,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, esConfigBasedRorSettings: EsConfigBasedRorSettings) (implicit systemContext: SystemContext) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = systemContext.uniqueIdentifierGenerator @@ -202,12 +202,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) } @@ -229,7 +229,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 3165661004..13df2ed723 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.MainSettingsApi.MainSettingsResponse 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/rrtestsettings/RRTestSettingsActionHandler.scala b/es67x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala index 3fe2540c1b..dc95b1a616 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestsettings 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.TestSettingsApi.TestSettingsResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestSettingsActionHandler extends Logging { +class RRTestSettingsActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler 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 4749a51bfc..b374837154 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 @@ -59,13 +59,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/EsIndexDocumentManager.scala b/es67x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala index 9b4400d45e..ade28f0104 100644 --- a/es67x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala +++ b/es67x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala @@ -20,7 +20,7 @@ import cats.implicits.* import io.circe.Json import io.circe.parser.* 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.annotation.unused class EsIndexDocumentManager(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexDocumentManager - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -61,17 +61,17 @@ class EsIndexDocumentManager(client: NodeClient, if (response.isExists) { Option(response.getSourceAsString) match { case Some(source) => - logger.debug(s"Document [${index.show} ID=$id] _source: $source") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: $source") parse(source) match { case Right(value) => Right(value) case Left(failure) => throw new IllegalStateException(s"Cannot parse document source to JSON: ${failure.toString}") } 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(Json.Null) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(DocumentNotFound) } } @@ -80,7 +80,7 @@ class EsIndexDocumentManager(client: NodeClient, case _: IndexNotFoundException => Left(IndexNotFound) case _: ResourceNotFoundException => Left(DocumentNotFound) 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(DocumentUnreachable) } } @@ -105,14 +105,14 @@ class EsIndexDocumentManager(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 4fecea0cd1..1c0f95b011 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, dispatcher: HttpServerTransport.Dispatcher, ssl: ExternalSslSettings) extends Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, ssl.clientAuthenticationEnabled) @@ -48,7 +48,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 a4fec091cb..613ddf49c3 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 @@ -45,7 +45,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, networkService: NetworkService, ssl: InternodeSslSettings) extends Netty4Transport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = doPrivileged { SSLCertHelper.prepareClientSSLContext(ssl) } private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, 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/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/es70x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es70x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index b791d55d2d..df043681ab 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 @@ -61,7 +61,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, esConfigBasedRorSettings: EsConfigBasedRorSettings) (implicit systemContext: SystemContext) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = systemContext.uniqueIdentifierGenerator @@ -202,12 +202,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) } @@ -229,7 +229,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 3165661004..13df2ed723 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.MainSettingsApi.MainSettingsResponse 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/rrtestsettings/RRTestSettingsActionHandler.scala b/es70x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala index 3fe2540c1b..dc95b1a616 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestsettings 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.TestSettingsApi.TestSettingsResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestSettingsActionHandler extends Logging { +class RRTestSettingsActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler 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 4749a51bfc..b374837154 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 @@ -59,13 +59,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/EsIndexDocumentManager.scala b/es70x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala index e7f5ac4866..3049cf80ea 100644 --- a/es70x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala +++ b/es70x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala @@ -20,7 +20,7 @@ import cats.implicits.* import io.circe.Json import io.circe.parser.* 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.annotation.unused class EsIndexDocumentManager(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexDocumentManager - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -61,17 +61,17 @@ class EsIndexDocumentManager(client: NodeClient, if (response.isExists) { Option(response.getSourceAsString) match { case Some(source) => - logger.debug(s"Document [${index.show} ID=$id] _source: $source") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: $source") parse(source) match { case Right(value) => Right(value) case Left(failure) => throw new IllegalStateException(s"Cannot parse document source to JSON: ${failure.toString}") } 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(Json.Null) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(DocumentNotFound) } } @@ -80,7 +80,7 @@ class EsIndexDocumentManager(client: NodeClient, case _: IndexNotFoundException => Left(IndexNotFound) case _: ResourceNotFoundException => Left(DocumentNotFound) 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(DocumentUnreachable) } } @@ -104,14 +104,14 @@ class EsIndexDocumentManager(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 bae2f793b0..44f1aa098e 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, dispatcher: HttpServerTransport.Dispatcher, ssl: ExternalSslSettings) extends Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, ssl.clientAuthenticationEnabled) @@ -48,7 +48,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 a4fec091cb..613ddf49c3 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 @@ -45,7 +45,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, networkService: NetworkService, ssl: InternodeSslSettings) extends Netty4Transport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = doPrivileged { SSLCertHelper.prepareClientSSLContext(ssl) } private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, 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/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/es710x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es710x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index 1c63128a26..6c6aa44c7f 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 @@ -63,7 +63,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, esConfigBasedRorSettings: EsConfigBasedRorSettings) (implicit systemContext: SystemContext) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = systemContext.uniqueIdentifierGenerator @@ -213,12 +213,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) } @@ -240,7 +240,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 3165661004..13df2ed723 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.MainSettingsApi.MainSettingsResponse 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/rrtestsettings/RRTestSettingsActionHandler.scala b/es710x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala index 3fe2540c1b..dc95b1a616 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestsettings 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.TestSettingsApi.TestSettingsResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestSettingsActionHandler extends Logging { +class RRTestSettingsActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler 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 6121dabc12..9699924b80 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]] { @@ -65,13 +65,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/EsIndexDocumentManager.scala b/es710x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala index e7f5ac4866..3049cf80ea 100644 --- a/es710x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala +++ b/es710x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala @@ -20,7 +20,7 @@ import cats.implicits.* import io.circe.Json import io.circe.parser.* 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.annotation.unused class EsIndexDocumentManager(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexDocumentManager - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -61,17 +61,17 @@ class EsIndexDocumentManager(client: NodeClient, if (response.isExists) { Option(response.getSourceAsString) match { case Some(source) => - logger.debug(s"Document [${index.show} ID=$id] _source: $source") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: $source") parse(source) match { case Right(value) => Right(value) case Left(failure) => throw new IllegalStateException(s"Cannot parse document source to JSON: ${failure.toString}") } 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(Json.Null) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(DocumentNotFound) } } @@ -80,7 +80,7 @@ class EsIndexDocumentManager(client: NodeClient, case _: IndexNotFoundException => Left(IndexNotFound) case _: ResourceNotFoundException => Left(DocumentNotFound) 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(DocumentUnreachable) } } @@ -104,14 +104,14 @@ class EsIndexDocumentManager(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 7c3b1fda94..aea3bf1105 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, clusterSettings: ClusterSettings, sharedGroupFactory: SharedGroupFactory) extends Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, ssl.clientAuthenticationEnabled) @@ -51,7 +51,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 6919f5755d..87805d5c55 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 @@ -47,7 +47,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, ssl: InternodeSslSettings, sharedGroupFactory: SharedGroupFactory) extends Netty4Transport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = doPrivileged { SSLCertHelper.prepareClientSSLContext(ssl) } private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, 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/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/es711x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es711x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index 1c63128a26..6c6aa44c7f 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 @@ -63,7 +63,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, esConfigBasedRorSettings: EsConfigBasedRorSettings) (implicit systemContext: SystemContext) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = systemContext.uniqueIdentifierGenerator @@ -213,12 +213,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) } @@ -240,7 +240,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 3165661004..13df2ed723 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.MainSettingsApi.MainSettingsResponse 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/rrtestsettings/RRTestSettingsActionHandler.scala b/es711x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala index 3fe2540c1b..111beb5916 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestsettings 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.TestSettingsApi.TestSettingsResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestSettingsActionHandler extends Logging { +class RRTestSettingsActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +52,7 @@ class RRTestSettingsActionHandler extends Logging { case Right(response) => listener.onResponse(new RRTestSettingsResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] Internal error", ex) + logger.error(s"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 6121dabc12..9699924b80 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]] { @@ -65,13 +65,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/EsIndexDocumentManager.scala b/es711x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala index e7f5ac4866..3049cf80ea 100644 --- a/es711x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala +++ b/es711x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala @@ -20,7 +20,7 @@ import cats.implicits.* import io.circe.Json import io.circe.parser.* 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.annotation.unused class EsIndexDocumentManager(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexDocumentManager - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -61,17 +61,17 @@ class EsIndexDocumentManager(client: NodeClient, if (response.isExists) { Option(response.getSourceAsString) match { case Some(source) => - logger.debug(s"Document [${index.show} ID=$id] _source: $source") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: $source") parse(source) match { case Right(value) => Right(value) case Left(failure) => throw new IllegalStateException(s"Cannot parse document source to JSON: ${failure.toString}") } 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(Json.Null) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(DocumentNotFound) } } @@ -80,7 +80,7 @@ class EsIndexDocumentManager(client: NodeClient, case _: IndexNotFoundException => Left(IndexNotFound) case _: ResourceNotFoundException => Left(DocumentNotFound) 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(DocumentUnreachable) } } @@ -104,14 +104,14 @@ class EsIndexDocumentManager(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 7c3b1fda94..aea3bf1105 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, clusterSettings: ClusterSettings, sharedGroupFactory: SharedGroupFactory) extends Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, ssl.clientAuthenticationEnabled) @@ -51,7 +51,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 6919f5755d..87805d5c55 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 @@ -47,7 +47,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, ssl: InternodeSslSettings, sharedGroupFactory: SharedGroupFactory) extends Netty4Transport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = doPrivileged { SSLCertHelper.prepareClientSSLContext(ssl) } private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, 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/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/es714x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es714x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index 1c63128a26..6c6aa44c7f 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 @@ -63,7 +63,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, esConfigBasedRorSettings: EsConfigBasedRorSettings) (implicit systemContext: SystemContext) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = systemContext.uniqueIdentifierGenerator @@ -213,12 +213,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) } @@ -240,7 +240,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 3165661004..13df2ed723 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.MainSettingsApi.MainSettingsResponse 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/rrtestsettings/RRTestSettingsActionHandler.scala b/es714x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala index 3fe2540c1b..dc95b1a616 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestsettings 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.TestSettingsApi.TestSettingsResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestSettingsActionHandler extends Logging { +class RRTestSettingsActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler 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 438011eecf..51b5ecfa3a 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]] { @@ -65,13 +65,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/EsIndexDocumentManager.scala b/es714x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala index e7f5ac4866..3049cf80ea 100644 --- a/es714x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala +++ b/es714x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala @@ -20,7 +20,7 @@ import cats.implicits.* import io.circe.Json import io.circe.parser.* 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.annotation.unused class EsIndexDocumentManager(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexDocumentManager - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -61,17 +61,17 @@ class EsIndexDocumentManager(client: NodeClient, if (response.isExists) { Option(response.getSourceAsString) match { case Some(source) => - logger.debug(s"Document [${index.show} ID=$id] _source: $source") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: $source") parse(source) match { case Right(value) => Right(value) case Left(failure) => throw new IllegalStateException(s"Cannot parse document source to JSON: ${failure.toString}") } 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(Json.Null) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(DocumentNotFound) } } @@ -80,7 +80,7 @@ class EsIndexDocumentManager(client: NodeClient, case _: IndexNotFoundException => Left(IndexNotFound) case _: ResourceNotFoundException => Left(DocumentNotFound) 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(DocumentUnreachable) } } @@ -104,14 +104,14 @@ class EsIndexDocumentManager(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 7c3b1fda94..aea3bf1105 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, clusterSettings: ClusterSettings, sharedGroupFactory: SharedGroupFactory) extends Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, ssl.clientAuthenticationEnabled) @@ -51,7 +51,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 6919f5755d..87805d5c55 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 @@ -47,7 +47,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, ssl: InternodeSslSettings, sharedGroupFactory: SharedGroupFactory) extends Netty4Transport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = doPrivileged { SSLCertHelper.prepareClientSSLContext(ssl) } private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, 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/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/es716x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es716x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index d3f1c12ba2..92acba4e0f 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 @@ -63,7 +63,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, esConfigBasedRorSettings: EsConfigBasedRorSettings) (implicit systemContext: SystemContext) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = systemContext.uniqueIdentifierGenerator @@ -213,12 +213,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) } @@ -240,7 +240,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 3165661004..13df2ed723 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.MainSettingsApi.MainSettingsResponse 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/rrtestsettings/RRTestSettingsActionHandler.scala b/es716x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala index 3fe2540c1b..111beb5916 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestsettings 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.TestSettingsApi.TestSettingsResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestSettingsActionHandler extends Logging { +class RRTestSettingsActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +52,7 @@ class RRTestSettingsActionHandler extends Logging { case Right(response) => listener.onResponse(new RRTestSettingsResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] Internal error", ex) + logger.error(s"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 438011eecf..51b5ecfa3a 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]] { @@ -65,13 +65,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/EsIndexDocumentManager.scala b/es716x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala index 71f6ba880d..5b99c2c109 100644 --- a/es716x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala +++ b/es716x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala @@ -20,7 +20,7 @@ import cats.implicits.* import io.circe.Json import io.circe.parser.* 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.annotation.unused class EsIndexDocumentManager(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexDocumentManager - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -61,17 +61,17 @@ class EsIndexDocumentManager(client: NodeClient, if (response.isExists) { Option(response.getSourceAsString) match { case Some(source) => - logger.debug(s"Document [${index.show} ID=$id] _source: $source") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: $source") parse(source) match { case Right(value) => Right(value) case Left(failure) => throw new IllegalStateException(s"Cannot parse document source to JSON: ${failure.toString}") } 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(Json.Null) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(DocumentNotFound) } } @@ -80,7 +80,7 @@ class EsIndexDocumentManager(client: NodeClient, case _: IndexNotFoundException => Left(IndexNotFound) case _: ResourceNotFoundException => Left(DocumentNotFound) 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(DocumentUnreachable) } } @@ -104,14 +104,14 @@ class EsIndexDocumentManager(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 58d8c8c639..287806dac8 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, clusterSettings: ClusterSettings, sharedGroupFactory: SharedGroupFactory) extends Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, ssl.clientAuthenticationEnabled) @@ -51,7 +51,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 6919f5755d..87805d5c55 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 @@ -47,7 +47,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, ssl: InternodeSslSettings, sharedGroupFactory: SharedGroupFactory) extends Netty4Transport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = doPrivileged { SSLCertHelper.prepareClientSSLContext(ssl) } private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, 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/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/es717x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es717x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index d3f1c12ba2..92acba4e0f 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 @@ -63,7 +63,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, esConfigBasedRorSettings: EsConfigBasedRorSettings) (implicit systemContext: SystemContext) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = systemContext.uniqueIdentifierGenerator @@ -213,12 +213,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) } @@ -240,7 +240,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 3165661004..13df2ed723 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.MainSettingsApi.MainSettingsResponse 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/rrtestsettings/RRTestSettingsActionHandler.scala b/es717x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala index 3fe2540c1b..dc95b1a616 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestsettings 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.TestSettingsApi.TestSettingsResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestSettingsActionHandler extends Logging { +class RRTestSettingsActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler 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 438011eecf..51b5ecfa3a 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]] { @@ -65,13 +65,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/EsIndexDocumentManager.scala b/es717x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala index 71f6ba880d..5b99c2c109 100644 --- a/es717x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala +++ b/es717x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala @@ -20,7 +20,7 @@ import cats.implicits.* import io.circe.Json import io.circe.parser.* 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.annotation.unused class EsIndexDocumentManager(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexDocumentManager - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -61,17 +61,17 @@ class EsIndexDocumentManager(client: NodeClient, if (response.isExists) { Option(response.getSourceAsString) match { case Some(source) => - logger.debug(s"Document [${index.show} ID=$id] _source: $source") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: $source") parse(source) match { case Right(value) => Right(value) case Left(failure) => throw new IllegalStateException(s"Cannot parse document source to JSON: ${failure.toString}") } 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(Json.Null) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(DocumentNotFound) } } @@ -80,7 +80,7 @@ class EsIndexDocumentManager(client: NodeClient, case _: IndexNotFoundException => Left(IndexNotFound) case _: ResourceNotFoundException => Left(DocumentNotFound) 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(DocumentUnreachable) } } @@ -104,14 +104,14 @@ class EsIndexDocumentManager(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 1af576d24f..527ca1b19d 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, clusterSettings: ClusterSettings, sharedGroupFactory: SharedGroupFactory) extends Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory, null) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, ssl.clientAuthenticationEnabled) @@ -51,7 +51,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 6919f5755d..87805d5c55 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 @@ -47,7 +47,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, ssl: InternodeSslSettings, sharedGroupFactory: SharedGroupFactory) extends Netty4Transport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = doPrivileged { SSLCertHelper.prepareClientSSLContext(ssl) } private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, 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/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/es72x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es72x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index b791d55d2d..df043681ab 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 @@ -61,7 +61,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, esConfigBasedRorSettings: EsConfigBasedRorSettings) (implicit systemContext: SystemContext) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = systemContext.uniqueIdentifierGenerator @@ -202,12 +202,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) } @@ -229,7 +229,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 3165661004..13df2ed723 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.MainSettingsApi.MainSettingsResponse 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/rrtestsettings/RRTestSettingsActionHandler.scala b/es72x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala index 3fe2540c1b..dc95b1a616 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestsettings 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.TestSettingsApi.TestSettingsResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestSettingsActionHandler extends Logging { +class RRTestSettingsActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler 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 4749a51bfc..b374837154 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 @@ -59,13 +59,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/EsIndexDocumentManager.scala b/es72x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala index e7f5ac4866..3049cf80ea 100644 --- a/es72x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala +++ b/es72x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala @@ -20,7 +20,7 @@ import cats.implicits.* import io.circe.Json import io.circe.parser.* 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.annotation.unused class EsIndexDocumentManager(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexDocumentManager - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -61,17 +61,17 @@ class EsIndexDocumentManager(client: NodeClient, if (response.isExists) { Option(response.getSourceAsString) match { case Some(source) => - logger.debug(s"Document [${index.show} ID=$id] _source: $source") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: $source") parse(source) match { case Right(value) => Right(value) case Left(failure) => throw new IllegalStateException(s"Cannot parse document source to JSON: ${failure.toString}") } 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(Json.Null) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(DocumentNotFound) } } @@ -80,7 +80,7 @@ class EsIndexDocumentManager(client: NodeClient, case _: IndexNotFoundException => Left(IndexNotFound) case _: ResourceNotFoundException => Left(DocumentNotFound) 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(DocumentUnreachable) } } @@ -104,14 +104,14 @@ class EsIndexDocumentManager(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 bae2f793b0..44f1aa098e 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, dispatcher: HttpServerTransport.Dispatcher, ssl: ExternalSslSettings) extends Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, ssl.clientAuthenticationEnabled) @@ -48,7 +48,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 a4fec091cb..613ddf49c3 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 @@ -45,7 +45,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, networkService: NetworkService, ssl: InternodeSslSettings) extends Netty4Transport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = doPrivileged { SSLCertHelper.prepareClientSSLContext(ssl) } private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, 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/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/es73x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es73x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index b791d55d2d..df043681ab 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 @@ -61,7 +61,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, esConfigBasedRorSettings: EsConfigBasedRorSettings) (implicit systemContext: SystemContext) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = systemContext.uniqueIdentifierGenerator @@ -202,12 +202,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) } @@ -229,7 +229,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 3165661004..13df2ed723 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.MainSettingsApi.MainSettingsResponse 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/rrtestsettings/RRTestSettingsActionHandler.scala b/es73x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala index 3fe2540c1b..dc95b1a616 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestsettings 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.TestSettingsApi.TestSettingsResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestSettingsActionHandler extends Logging { +class RRTestSettingsActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler 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 6121dabc12..9699924b80 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]] { @@ -65,13 +65,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/EsIndexDocumentManager.scala b/es73x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala index e7f5ac4866..3049cf80ea 100644 --- a/es73x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala +++ b/es73x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala @@ -20,7 +20,7 @@ import cats.implicits.* import io.circe.Json import io.circe.parser.* 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.annotation.unused class EsIndexDocumentManager(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexDocumentManager - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -61,17 +61,17 @@ class EsIndexDocumentManager(client: NodeClient, if (response.isExists) { Option(response.getSourceAsString) match { case Some(source) => - logger.debug(s"Document [${index.show} ID=$id] _source: $source") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: $source") parse(source) match { case Right(value) => Right(value) case Left(failure) => throw new IllegalStateException(s"Cannot parse document source to JSON: ${failure.toString}") } 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(Json.Null) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(DocumentNotFound) } } @@ -80,7 +80,7 @@ class EsIndexDocumentManager(client: NodeClient, case _: IndexNotFoundException => Left(IndexNotFound) case _: ResourceNotFoundException => Left(DocumentNotFound) 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(DocumentUnreachable) } } @@ -104,14 +104,14 @@ class EsIndexDocumentManager(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 bae2f793b0..44f1aa098e 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, dispatcher: HttpServerTransport.Dispatcher, ssl: ExternalSslSettings) extends Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, ssl.clientAuthenticationEnabled) @@ -48,7 +48,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 a4fec091cb..613ddf49c3 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 @@ -45,7 +45,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, networkService: NetworkService, ssl: InternodeSslSettings) extends Netty4Transport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = doPrivileged { SSLCertHelper.prepareClientSSLContext(ssl) } private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, 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/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/es74x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es74x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index b791d55d2d..df043681ab 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 @@ -61,7 +61,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, esConfigBasedRorSettings: EsConfigBasedRorSettings) (implicit systemContext: SystemContext) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = systemContext.uniqueIdentifierGenerator @@ -202,12 +202,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) } @@ -229,7 +229,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 3165661004..13df2ed723 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.MainSettingsApi.MainSettingsResponse 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/rrtestsettings/RRTestSettingsActionHandler.scala b/es74x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala index 3fe2540c1b..dc95b1a616 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestsettings 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.TestSettingsApi.TestSettingsResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestSettingsActionHandler extends Logging { +class RRTestSettingsActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler 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 6121dabc12..9699924b80 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]] { @@ -65,13 +65,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/EsIndexDocumentManager.scala b/es74x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala index e7f5ac4866..3049cf80ea 100644 --- a/es74x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala +++ b/es74x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala @@ -20,7 +20,7 @@ import cats.implicits.* import io.circe.Json import io.circe.parser.* 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.annotation.unused class EsIndexDocumentManager(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexDocumentManager - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -61,17 +61,17 @@ class EsIndexDocumentManager(client: NodeClient, if (response.isExists) { Option(response.getSourceAsString) match { case Some(source) => - logger.debug(s"Document [${index.show} ID=$id] _source: $source") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: $source") parse(source) match { case Right(value) => Right(value) case Left(failure) => throw new IllegalStateException(s"Cannot parse document source to JSON: ${failure.toString}") } 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(Json.Null) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(DocumentNotFound) } } @@ -80,7 +80,7 @@ class EsIndexDocumentManager(client: NodeClient, case _: IndexNotFoundException => Left(IndexNotFound) case _: ResourceNotFoundException => Left(DocumentNotFound) 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(DocumentUnreachable) } } @@ -104,14 +104,14 @@ class EsIndexDocumentManager(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 bae2f793b0..44f1aa098e 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, dispatcher: HttpServerTransport.Dispatcher, ssl: ExternalSslSettings) extends Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, ssl.clientAuthenticationEnabled) @@ -48,7 +48,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 a4fec091cb..613ddf49c3 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 @@ -45,7 +45,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, networkService: NetworkService, ssl: InternodeSslSettings) extends Netty4Transport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = doPrivileged { SSLCertHelper.prepareClientSSLContext(ssl) } private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, 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/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/es77x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es77x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index 00752386cc..67010c956d 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 @@ -61,7 +61,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, esConfigBasedRorSettings: EsConfigBasedRorSettings) (implicit systemContext: SystemContext) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = systemContext.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/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 3165661004..13df2ed723 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.MainSettingsApi.MainSettingsResponse 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/rrtestsettings/RRTestSettingsActionHandler.scala b/es77x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala index 3fe2540c1b..dc95b1a616 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestsettings 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.TestSettingsApi.TestSettingsResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestSettingsActionHandler extends Logging { +class RRTestSettingsActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler 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 6121dabc12..9699924b80 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]] { @@ -65,13 +65,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/EsIndexDocumentManager.scala b/es77x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala index e7f5ac4866..3049cf80ea 100644 --- a/es77x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala +++ b/es77x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala @@ -20,7 +20,7 @@ import cats.implicits.* import io.circe.Json import io.circe.parser.* 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.annotation.unused class EsIndexDocumentManager(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexDocumentManager - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -61,17 +61,17 @@ class EsIndexDocumentManager(client: NodeClient, if (response.isExists) { Option(response.getSourceAsString) match { case Some(source) => - logger.debug(s"Document [${index.show} ID=$id] _source: $source") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: $source") parse(source) match { case Right(value) => Right(value) case Left(failure) => throw new IllegalStateException(s"Cannot parse document source to JSON: ${failure.toString}") } 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(Json.Null) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(DocumentNotFound) } } @@ -80,7 +80,7 @@ class EsIndexDocumentManager(client: NodeClient, case _: IndexNotFoundException => Left(IndexNotFound) case _: ResourceNotFoundException => Left(DocumentNotFound) 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(DocumentUnreachable) } } @@ -104,14 +104,14 @@ class EsIndexDocumentManager(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 606c0f4c18..cedf5c1035 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, ssl: ExternalSslSettings, clusterSettings: ClusterSettings) extends Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher, clusterSettings) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, 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/es77x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala b/es77x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala index a4fec091cb..613ddf49c3 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 @@ -45,7 +45,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, networkService: NetworkService, ssl: InternodeSslSettings) extends Netty4Transport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = doPrivileged { SSLCertHelper.prepareClientSSLContext(ssl) } private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, 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/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/es78x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es78x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index 015f4f4905..87be0cf51f 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 @@ -61,7 +61,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, esConfigBasedRorSettings: EsConfigBasedRorSettings) (implicit systemContext: SystemContext) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = systemContext.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/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 3165661004..13df2ed723 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.MainSettingsApi.MainSettingsResponse 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/rrtestsettings/RRTestSettingsActionHandler.scala b/es78x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala index 3fe2540c1b..dc95b1a616 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestsettings 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.TestSettingsApi.TestSettingsResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestSettingsActionHandler extends Logging { +class RRTestSettingsActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler 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 6121dabc12..9699924b80 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]] { @@ -65,13 +65,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/EsIndexDocumentManager.scala b/es78x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala index e7f5ac4866..3049cf80ea 100644 --- a/es78x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala +++ b/es78x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala @@ -20,7 +20,7 @@ import cats.implicits.* import io.circe.Json import io.circe.parser.* 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.annotation.unused class EsIndexDocumentManager(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexDocumentManager - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -61,17 +61,17 @@ class EsIndexDocumentManager(client: NodeClient, if (response.isExists) { Option(response.getSourceAsString) match { case Some(source) => - logger.debug(s"Document [${index.show} ID=$id] _source: $source") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: $source") parse(source) match { case Right(value) => Right(value) case Left(failure) => throw new IllegalStateException(s"Cannot parse document source to JSON: ${failure.toString}") } 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(Json.Null) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(DocumentNotFound) } } @@ -80,7 +80,7 @@ class EsIndexDocumentManager(client: NodeClient, case _: IndexNotFoundException => Left(IndexNotFound) case _: ResourceNotFoundException => Left(DocumentNotFound) 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(DocumentUnreachable) } } @@ -104,14 +104,14 @@ class EsIndexDocumentManager(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 606c0f4c18..cedf5c1035 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, ssl: ExternalSslSettings, clusterSettings: ClusterSettings) extends Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher, clusterSettings) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, 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/es78x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala b/es78x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala index a4fec091cb..613ddf49c3 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 @@ -45,7 +45,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, networkService: NetworkService, ssl: InternodeSslSettings) extends Netty4Transport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = doPrivileged { SSLCertHelper.prepareClientSSLContext(ssl) } private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, 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/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/es79x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es79x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index 1c63128a26..6c6aa44c7f 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 @@ -63,7 +63,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, esConfigBasedRorSettings: EsConfigBasedRorSettings) (implicit systemContext: SystemContext) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = systemContext.uniqueIdentifierGenerator @@ -213,12 +213,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) } @@ -240,7 +240,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 3165661004..13df2ed723 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.MainSettingsApi.MainSettingsResponse 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/rrtestsettings/RRTestSettingsActionHandler.scala b/es79x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala index 3fe2540c1b..dc95b1a616 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestsettings 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.TestSettingsApi.TestSettingsResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestSettingsActionHandler extends Logging { +class RRTestSettingsActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler 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 6121dabc12..9699924b80 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]] { @@ -65,13 +65,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/EsIndexDocumentManager.scala b/es79x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala index e7f5ac4866..3049cf80ea 100644 --- a/es79x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala +++ b/es79x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala @@ -20,7 +20,7 @@ import cats.implicits.* import io.circe.Json import io.circe.parser.* 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.annotation.unused class EsIndexDocumentManager(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexDocumentManager - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -61,17 +61,17 @@ class EsIndexDocumentManager(client: NodeClient, if (response.isExists) { Option(response.getSourceAsString) match { case Some(source) => - logger.debug(s"Document [${index.show} ID=$id] _source: $source") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: $source") parse(source) match { case Right(value) => Right(value) case Left(failure) => throw new IllegalStateException(s"Cannot parse document source to JSON: ${failure.toString}") } 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(Json.Null) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(DocumentNotFound) } } @@ -80,7 +80,7 @@ class EsIndexDocumentManager(client: NodeClient, case _: IndexNotFoundException => Left(IndexNotFound) case _: ResourceNotFoundException => Left(DocumentNotFound) 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(DocumentUnreachable) } } @@ -104,14 +104,14 @@ class EsIndexDocumentManager(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 7c3b1fda94..aea3bf1105 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, clusterSettings: ClusterSettings, sharedGroupFactory: SharedGroupFactory) extends Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, ssl.clientAuthenticationEnabled) @@ -51,7 +51,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 6919f5755d..87805d5c55 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 @@ -47,7 +47,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, ssl: InternodeSslSettings, sharedGroupFactory: SharedGroupFactory) extends Netty4Transport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = doPrivileged { SSLCertHelper.prepareClientSSLContext(ssl) } private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, 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/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/es80x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala b/es80x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala index d3f1c12ba2..92acba4e0f 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 @@ -63,7 +63,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, esConfigBasedRorSettings: EsConfigBasedRorSettings) (implicit systemContext: SystemContext) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = systemContext.uniqueIdentifierGenerator @@ -213,12 +213,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) } @@ -240,7 +240,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 3165661004..13df2ed723 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.MainSettingsApi.MainSettingsResponse 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/rrtestsettings/RRTestSettingsActionHandler.scala b/es80x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala index 3fe2540c1b..dc95b1a616 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestsettings 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.TestSettingsApi.TestSettingsResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestSettingsActionHandler extends Logging { +class RRTestSettingsActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler 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 438011eecf..51b5ecfa3a 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]] { @@ -65,13 +65,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/EsIndexDocumentManager.scala b/es80x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala index 71f6ba880d..5b99c2c109 100644 --- a/es80x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala +++ b/es80x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala @@ -20,7 +20,7 @@ import cats.implicits.* import io.circe.Json import io.circe.parser.* 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.annotation.unused class EsIndexDocumentManager(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexDocumentManager - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -61,17 +61,17 @@ class EsIndexDocumentManager(client: NodeClient, if (response.isExists) { Option(response.getSourceAsString) match { case Some(source) => - logger.debug(s"Document [${index.show} ID=$id] _source: $source") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: $source") parse(source) match { case Right(value) => Right(value) case Left(failure) => throw new IllegalStateException(s"Cannot parse document source to JSON: ${failure.toString}") } 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(Json.Null) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(DocumentNotFound) } } @@ -80,7 +80,7 @@ class EsIndexDocumentManager(client: NodeClient, case _: IndexNotFoundException => Left(IndexNotFound) case _: ResourceNotFoundException => Left(DocumentNotFound) 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(DocumentUnreachable) } } @@ -104,14 +104,14 @@ class EsIndexDocumentManager(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 c40f2af9e6..c169605a28 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, clusterSettings: ClusterSettings, sharedGroupFactory: SharedGroupFactory) extends Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, ssl.clientAuthenticationEnabled) @@ -51,7 +51,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 e78670311e..08854c2ba4 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 @@ -46,7 +46,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, ssl: InternodeSslSettings, sharedGroupFactory: SharedGroupFactory) extends Netty4Transport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = doPrivileged { SSLCertHelper.prepareClientSSLContext(ssl) } private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, 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/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/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 a369e8f646..6e788de1f0 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 @@ -63,7 +63,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, esConfigBasedRorSettings: EsConfigBasedRorSettings) (implicit systemContext: SystemContext) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = systemContext.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/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 3165661004..13df2ed723 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.MainSettingsApi.MainSettingsResponse 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/rrtestsettings/RRTestSettingsActionHandler.scala b/es810x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala index 3fe2540c1b..dc95b1a616 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestsettings 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.TestSettingsApi.TestSettingsResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestSettingsActionHandler extends Logging { +class RRTestSettingsActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler 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 438011eecf..51b5ecfa3a 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]] { @@ -65,13 +65,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/EsIndexDocumentManager.scala b/es810x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala index 26296f7491..0b6744d767 100644 --- a/es810x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala +++ b/es810x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala @@ -20,7 +20,7 @@ import cats.implicits.* import io.circe.Json import io.circe.parser.* 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.annotation.unused class EsIndexDocumentManager(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexDocumentManager - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -61,17 +61,17 @@ class EsIndexDocumentManager(client: NodeClient, if (response.isExists) { Option(response.getSourceAsString) match { case Some(source) => - logger.debug(s"Document [${index.show} ID=$id] _source: $source") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: $source") parse(source) match { case Right(value) => Right(value) case Left(failure) => throw new IllegalStateException(s"Cannot parse document source to JSON: ${failure.toString}") } 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(Json.Null) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(DocumentNotFound) } } @@ -80,7 +80,7 @@ class EsIndexDocumentManager(client: NodeClient, case _: IndexNotFoundException => Left(IndexNotFound) case _: ResourceNotFoundException => Left(DocumentNotFound) 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(DocumentUnreachable) } } @@ -104,14 +104,14 @@ class EsIndexDocumentManager(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 ef14b6eb89..fe53340da8 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, sharedGroupFactory: SharedGroupFactory, tracer: Tracer) extends Netty4HttpServerTransport(settings, networkService, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory, tracer, TLSConfig.noTLS(), null, null) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, ssl.clientAuthenticationEnabled) @@ -51,7 +51,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 88b9d3c808..2af4407a96 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 @@ -47,7 +47,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, ssl: InternodeSslSettings, sharedGroupFactory: SharedGroupFactory) extends Netty4Transport(settings, TransportVersion.current(), threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = doPrivileged { SSLCertHelper.prepareClientSSLContext(ssl) } private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, clientAuthenticationEnabled = false) } @@ -79,7 +79,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/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 a369e8f646..6e788de1f0 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 @@ -63,7 +63,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, esConfigBasedRorSettings: EsConfigBasedRorSettings) (implicit systemContext: SystemContext) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = systemContext.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/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 3165661004..13df2ed723 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.MainSettingsApi.MainSettingsResponse 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/rrtestsettings/RRTestSettingsActionHandler.scala b/es811x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala index 3fe2540c1b..dc95b1a616 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestsettings 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.TestSettingsApi.TestSettingsResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestSettingsActionHandler extends Logging { +class RRTestSettingsActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler 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 438011eecf..51b5ecfa3a 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]] { @@ -65,13 +65,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/EsIndexDocumentManager.scala b/es811x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala index 26296f7491..0b6744d767 100644 --- a/es811x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala +++ b/es811x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala @@ -20,7 +20,7 @@ import cats.implicits.* import io.circe.Json import io.circe.parser.* 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.annotation.unused class EsIndexDocumentManager(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexDocumentManager - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -61,17 +61,17 @@ class EsIndexDocumentManager(client: NodeClient, if (response.isExists) { Option(response.getSourceAsString) match { case Some(source) => - logger.debug(s"Document [${index.show} ID=$id] _source: $source") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: $source") parse(source) match { case Right(value) => Right(value) case Left(failure) => throw new IllegalStateException(s"Cannot parse document source to JSON: ${failure.toString}") } 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(Json.Null) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(DocumentNotFound) } } @@ -80,7 +80,7 @@ class EsIndexDocumentManager(client: NodeClient, case _: IndexNotFoundException => Left(IndexNotFound) case _: ResourceNotFoundException => Left(DocumentNotFound) 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(DocumentUnreachable) } } @@ -104,14 +104,14 @@ class EsIndexDocumentManager(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 81b7891185..f69cf7c7e0 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, sharedGroupFactory: SharedGroupFactory, tracer: Tracer) extends Netty4HttpServerTransport(settings, networkService, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory, tracer, TLSConfig.noTLS(), null, null) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, ssl.clientAuthenticationEnabled) @@ -51,7 +51,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 88b9d3c808..2af4407a96 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 @@ -47,7 +47,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, ssl: InternodeSslSettings, sharedGroupFactory: SharedGroupFactory) extends Netty4Transport(settings, TransportVersion.current(), threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = doPrivileged { SSLCertHelper.prepareClientSSLContext(ssl) } private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, clientAuthenticationEnabled = false) } @@ -79,7 +79,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/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 a369e8f646..6e788de1f0 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 @@ -63,7 +63,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, esConfigBasedRorSettings: EsConfigBasedRorSettings) (implicit systemContext: SystemContext) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = systemContext.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/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 3165661004..13df2ed723 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.MainSettingsApi.MainSettingsResponse 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/rrtestsettings/RRTestSettingsActionHandler.scala b/es812x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala index 3fe2540c1b..dc95b1a616 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestsettings 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.TestSettingsApi.TestSettingsResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestSettingsActionHandler extends Logging { +class RRTestSettingsActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler 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 438011eecf..51b5ecfa3a 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]] { @@ -65,13 +65,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/EsIndexDocumentManager.scala b/es812x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala index 26296f7491..0b6744d767 100644 --- a/es812x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala +++ b/es812x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala @@ -20,7 +20,7 @@ import cats.implicits.* import io.circe.Json import io.circe.parser.* 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.annotation.unused class EsIndexDocumentManager(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexDocumentManager - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -61,17 +61,17 @@ class EsIndexDocumentManager(client: NodeClient, if (response.isExists) { Option(response.getSourceAsString) match { case Some(source) => - logger.debug(s"Document [${index.show} ID=$id] _source: $source") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: $source") parse(source) match { case Right(value) => Right(value) case Left(failure) => throw new IllegalStateException(s"Cannot parse document source to JSON: ${failure.toString}") } 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(Json.Null) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(DocumentNotFound) } } @@ -80,7 +80,7 @@ class EsIndexDocumentManager(client: NodeClient, case _: IndexNotFoundException => Left(IndexNotFound) case _: ResourceNotFoundException => Left(DocumentNotFound) 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(DocumentUnreachable) } } @@ -104,14 +104,14 @@ class EsIndexDocumentManager(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 81b7891185..f69cf7c7e0 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, sharedGroupFactory: SharedGroupFactory, tracer: Tracer) extends Netty4HttpServerTransport(settings, networkService, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory, tracer, TLSConfig.noTLS(), null, null) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, ssl.clientAuthenticationEnabled) @@ -51,7 +51,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 88b9d3c808..2af4407a96 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 @@ -47,7 +47,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, ssl: InternodeSslSettings, sharedGroupFactory: SharedGroupFactory) extends Netty4Transport(settings, TransportVersion.current(), threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = doPrivileged { SSLCertHelper.prepareClientSSLContext(ssl) } private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, clientAuthenticationEnabled = false) } @@ -79,7 +79,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/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 a369e8f646..6e788de1f0 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 @@ -63,7 +63,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, esConfigBasedRorSettings: EsConfigBasedRorSettings) (implicit systemContext: SystemContext) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = systemContext.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/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 3165661004..13df2ed723 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.MainSettingsApi.MainSettingsResponse 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/rrtestsettings/RRTestSettingsActionHandler.scala b/es813x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala index 3fe2540c1b..dc95b1a616 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestsettings 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.TestSettingsApi.TestSettingsResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestSettingsActionHandler extends Logging { +class RRTestSettingsActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler 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 438011eecf..51b5ecfa3a 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]] { @@ -65,13 +65,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/EsIndexDocumentManager.scala b/es813x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala index 26296f7491..0b6744d767 100644 --- a/es813x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala +++ b/es813x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala @@ -20,7 +20,7 @@ import cats.implicits.* import io.circe.Json import io.circe.parser.* 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.annotation.unused class EsIndexDocumentManager(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexDocumentManager - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -61,17 +61,17 @@ class EsIndexDocumentManager(client: NodeClient, if (response.isExists) { Option(response.getSourceAsString) match { case Some(source) => - logger.debug(s"Document [${index.show} ID=$id] _source: $source") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: $source") parse(source) match { case Right(value) => Right(value) case Left(failure) => throw new IllegalStateException(s"Cannot parse document source to JSON: ${failure.toString}") } 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(Json.Null) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(DocumentNotFound) } } @@ -80,7 +80,7 @@ class EsIndexDocumentManager(client: NodeClient, case _: IndexNotFoundException => Left(IndexNotFound) case _: ResourceNotFoundException => Left(DocumentNotFound) 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(DocumentUnreachable) } } @@ -104,14 +104,14 @@ class EsIndexDocumentManager(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 81b7891185..f69cf7c7e0 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, sharedGroupFactory: SharedGroupFactory, tracer: Tracer) extends Netty4HttpServerTransport(settings, networkService, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory, tracer, TLSConfig.noTLS(), null, null) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, ssl.clientAuthenticationEnabled) @@ -51,7 +51,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 88b9d3c808..2af4407a96 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 @@ -47,7 +47,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, ssl: InternodeSslSettings, sharedGroupFactory: SharedGroupFactory) extends Netty4Transport(settings, TransportVersion.current(), threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = doPrivileged { SSLCertHelper.prepareClientSSLContext(ssl) } private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, clientAuthenticationEnabled = false) } @@ -79,7 +79,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/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 a369e8f646..6e788de1f0 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 @@ -63,7 +63,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, esConfigBasedRorSettings: EsConfigBasedRorSettings) (implicit systemContext: SystemContext) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = systemContext.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/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 3165661004..13df2ed723 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.MainSettingsApi.MainSettingsResponse 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/rrtestsettings/RRTestSettingsActionHandler.scala b/es814x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala index 3fe2540c1b..dc95b1a616 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestsettings 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.TestSettingsApi.TestSettingsResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestSettingsActionHandler extends Logging { +class RRTestSettingsActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler 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 438011eecf..51b5ecfa3a 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]] { @@ -65,13 +65,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/EsIndexDocumentManager.scala b/es814x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala index 26296f7491..0b6744d767 100644 --- a/es814x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala +++ b/es814x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala @@ -20,7 +20,7 @@ import cats.implicits.* import io.circe.Json import io.circe.parser.* 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.annotation.unused class EsIndexDocumentManager(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexDocumentManager - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -61,17 +61,17 @@ class EsIndexDocumentManager(client: NodeClient, if (response.isExists) { Option(response.getSourceAsString) match { case Some(source) => - logger.debug(s"Document [${index.show} ID=$id] _source: $source") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: $source") parse(source) match { case Right(value) => Right(value) case Left(failure) => throw new IllegalStateException(s"Cannot parse document source to JSON: ${failure.toString}") } 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(Json.Null) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(DocumentNotFound) } } @@ -80,7 +80,7 @@ class EsIndexDocumentManager(client: NodeClient, case _: IndexNotFoundException => Left(IndexNotFound) case _: ResourceNotFoundException => Left(DocumentNotFound) 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(DocumentUnreachable) } } @@ -104,14 +104,14 @@ class EsIndexDocumentManager(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 81b7891185..f69cf7c7e0 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, sharedGroupFactory: SharedGroupFactory, tracer: Tracer) extends Netty4HttpServerTransport(settings, networkService, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory, tracer, TLSConfig.noTLS(), null, null) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, ssl.clientAuthenticationEnabled) @@ -51,7 +51,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 88b9d3c808..2af4407a96 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 @@ -47,7 +47,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, ssl: InternodeSslSettings, sharedGroupFactory: SharedGroupFactory) extends Netty4Transport(settings, TransportVersion.current(), threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = doPrivileged { SSLCertHelper.prepareClientSSLContext(ssl) } private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, clientAuthenticationEnabled = false) } @@ -79,7 +79,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/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 a369e8f646..6e788de1f0 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 @@ -63,7 +63,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, esConfigBasedRorSettings: EsConfigBasedRorSettings) (implicit systemContext: SystemContext) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = systemContext.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/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 3165661004..13df2ed723 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.MainSettingsApi.MainSettingsResponse 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/rrtestsettings/RRTestSettingsActionHandler.scala b/es815x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala index 3fe2540c1b..dc95b1a616 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestsettings 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.TestSettingsApi.TestSettingsResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestSettingsActionHandler extends Logging { +class RRTestSettingsActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler 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 438011eecf..51b5ecfa3a 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]] { @@ -65,13 +65,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/EsIndexDocumentManager.scala b/es815x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala index 26296f7491..0b6744d767 100644 --- a/es815x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala +++ b/es815x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala @@ -20,7 +20,7 @@ import cats.implicits.* import io.circe.Json import io.circe.parser.* 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.annotation.unused class EsIndexDocumentManager(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexDocumentManager - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -61,17 +61,17 @@ class EsIndexDocumentManager(client: NodeClient, if (response.isExists) { Option(response.getSourceAsString) match { case Some(source) => - logger.debug(s"Document [${index.show} ID=$id] _source: $source") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: $source") parse(source) match { case Right(value) => Right(value) case Left(failure) => throw new IllegalStateException(s"Cannot parse document source to JSON: ${failure.toString}") } 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(Json.Null) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(DocumentNotFound) } } @@ -80,7 +80,7 @@ class EsIndexDocumentManager(client: NodeClient, case _: IndexNotFoundException => Left(IndexNotFound) case _: ResourceNotFoundException => Left(DocumentNotFound) 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(DocumentUnreachable) } } @@ -104,14 +104,14 @@ class EsIndexDocumentManager(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 81b7891185..f69cf7c7e0 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, sharedGroupFactory: SharedGroupFactory, tracer: Tracer) extends Netty4HttpServerTransport(settings, networkService, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory, tracer, TLSConfig.noTLS(), null, null) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, ssl.clientAuthenticationEnabled) @@ -51,7 +51,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 88b9d3c808..2af4407a96 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 @@ -47,7 +47,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, ssl: InternodeSslSettings, sharedGroupFactory: SharedGroupFactory) extends Netty4Transport(settings, TransportVersion.current(), threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = doPrivileged { SSLCertHelper.prepareClientSSLContext(ssl) } private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, clientAuthenticationEnabled = false) } @@ -79,7 +79,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/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 a369e8f646..6e788de1f0 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 @@ -63,7 +63,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, esConfigBasedRorSettings: EsConfigBasedRorSettings) (implicit systemContext: SystemContext) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = systemContext.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/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 3165661004..13df2ed723 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.MainSettingsApi.MainSettingsResponse 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/rrtestsettings/RRTestSettingsActionHandler.scala b/es816x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala index 3fe2540c1b..dc95b1a616 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestsettings 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.TestSettingsApi.TestSettingsResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestSettingsActionHandler extends Logging { +class RRTestSettingsActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler 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 438011eecf..51b5ecfa3a 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]] { @@ -65,13 +65,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/EsIndexDocumentManager.scala b/es816x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala index c1c6c8a26b..558eaa7641 100644 --- a/es816x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala +++ b/es816x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala @@ -20,7 +20,7 @@ import cats.implicits.* import io.circe.Json import io.circe.parser.* 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.annotation.unused class EsIndexDocumentManager(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexDocumentManager - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -61,17 +61,17 @@ class EsIndexDocumentManager(client: NodeClient, if (response.isExists) { Option(response.getSourceAsString) match { case Some(source) => - logger.debug(s"Document [${index.show} ID=$id] _source: $source") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: $source") parse(source) match { case Right(value) => Right(value) case Left(failure) => throw new IllegalStateException(s"Cannot parse document source to JSON: ${failure.toString}") } 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(Json.Null) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(DocumentNotFound) } } @@ -80,7 +80,7 @@ class EsIndexDocumentManager(client: NodeClient, case _: IndexNotFoundException => Left(IndexNotFound) case _: ResourceNotFoundException => Left(DocumentNotFound) 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(DocumentUnreachable) } } @@ -104,14 +104,14 @@ class EsIndexDocumentManager(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 46d402b70a..ef798f964c 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, sharedGroupFactory: SharedGroupFactory, tracer: Tracer) extends Netty4HttpServerTransport(settings, networkService, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory, tracer, TLSConfig.noTLS(), null, null) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, ssl.clientAuthenticationEnabled) @@ -52,7 +52,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 88b9d3c808..2af4407a96 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 @@ -47,7 +47,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, ssl: InternodeSslSettings, sharedGroupFactory: SharedGroupFactory) extends Netty4Transport(settings, TransportVersion.current(), threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = doPrivileged { SSLCertHelper.prepareClientSSLContext(ssl) } private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, clientAuthenticationEnabled = false) } @@ -79,7 +79,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/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 011b4e7216..95080e0988 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 @@ -63,7 +63,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, esConfigBasedRorSettings: EsConfigBasedRorSettings) (implicit systemContext: SystemContext) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = systemContext.uniqueIdentifierGenerator @@ -213,12 +213,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) } @@ -240,7 +240,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 3165661004..13df2ed723 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.MainSettingsApi.MainSettingsResponse 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/rrtestsettings/RRTestSettingsActionHandler.scala b/es818x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala index 3fe2540c1b..dc95b1a616 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestsettings 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.TestSettingsApi.TestSettingsResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestSettingsActionHandler extends Logging { +class RRTestSettingsActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler 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 438011eecf..51b5ecfa3a 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]] { @@ -65,13 +65,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/EsIndexDocumentManager.scala b/es818x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala index c1c6c8a26b..558eaa7641 100644 --- a/es818x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala +++ b/es818x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala @@ -20,7 +20,7 @@ import cats.implicits.* import io.circe.Json import io.circe.parser.* 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.annotation.unused class EsIndexDocumentManager(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexDocumentManager - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -61,17 +61,17 @@ class EsIndexDocumentManager(client: NodeClient, if (response.isExists) { Option(response.getSourceAsString) match { case Some(source) => - logger.debug(s"Document [${index.show} ID=$id] _source: $source") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: $source") parse(source) match { case Right(value) => Right(value) case Left(failure) => throw new IllegalStateException(s"Cannot parse document source to JSON: ${failure.toString}") } 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(Json.Null) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(DocumentNotFound) } } @@ -80,7 +80,7 @@ class EsIndexDocumentManager(client: NodeClient, case _: IndexNotFoundException => Left(IndexNotFound) case _: ResourceNotFoundException => Left(DocumentNotFound) 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(DocumentUnreachable) } } @@ -104,14 +104,14 @@ class EsIndexDocumentManager(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 46d402b70a..ef798f964c 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, sharedGroupFactory: SharedGroupFactory, tracer: Tracer) extends Netty4HttpServerTransport(settings, networkService, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory, tracer, TLSConfig.noTLS(), null, null) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, ssl.clientAuthenticationEnabled) @@ -52,7 +52,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 88b9d3c808..2af4407a96 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 @@ -47,7 +47,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, ssl: InternodeSslSettings, sharedGroupFactory: SharedGroupFactory) extends Netty4Transport(settings, TransportVersion.current(), threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = doPrivileged { SSLCertHelper.prepareClientSSLContext(ssl) } private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, clientAuthenticationEnabled = false) } @@ -79,7 +79,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/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 acfef36a08..1c8921b1db 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 @@ -63,7 +63,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, esConfigBasedRorSettings: EsConfigBasedRorSettings) (implicit systemContext: SystemContext) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = systemContext.uniqueIdentifierGenerator @@ -213,12 +213,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) } @@ -240,7 +240,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 3165661004..13df2ed723 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.MainSettingsApi.MainSettingsResponse 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/rrtestsettings/RRTestSettingsActionHandler.scala b/es81x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala index 3fe2540c1b..dc95b1a616 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestsettings 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.TestSettingsApi.TestSettingsResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestSettingsActionHandler extends Logging { +class RRTestSettingsActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler 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 438011eecf..51b5ecfa3a 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]] { @@ -65,13 +65,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/EsIndexDocumentManager.scala b/es81x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala index 26296f7491..0b6744d767 100644 --- a/es81x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala +++ b/es81x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala @@ -20,7 +20,7 @@ import cats.implicits.* import io.circe.Json import io.circe.parser.* 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.annotation.unused class EsIndexDocumentManager(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexDocumentManager - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -61,17 +61,17 @@ class EsIndexDocumentManager(client: NodeClient, if (response.isExists) { Option(response.getSourceAsString) match { case Some(source) => - logger.debug(s"Document [${index.show} ID=$id] _source: $source") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: $source") parse(source) match { case Right(value) => Right(value) case Left(failure) => throw new IllegalStateException(s"Cannot parse document source to JSON: ${failure.toString}") } 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(Json.Null) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(DocumentNotFound) } } @@ -80,7 +80,7 @@ class EsIndexDocumentManager(client: NodeClient, case _: IndexNotFoundException => Left(IndexNotFound) case _: ResourceNotFoundException => Left(DocumentNotFound) 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(DocumentUnreachable) } } @@ -104,14 +104,14 @@ class EsIndexDocumentManager(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 c40f2af9e6..c169605a28 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, clusterSettings: ClusterSettings, sharedGroupFactory: SharedGroupFactory) extends Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, ssl.clientAuthenticationEnabled) @@ -51,7 +51,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 e78670311e..08854c2ba4 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 @@ -46,7 +46,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, ssl: InternodeSslSettings, sharedGroupFactory: SharedGroupFactory) extends Netty4Transport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = doPrivileged { SSLCertHelper.prepareClientSSLContext(ssl) } private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, 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/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/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 acfef36a08..1c8921b1db 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 @@ -63,7 +63,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, esConfigBasedRorSettings: EsConfigBasedRorSettings) (implicit systemContext: SystemContext) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = systemContext.uniqueIdentifierGenerator @@ -213,12 +213,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) } @@ -240,7 +240,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 3165661004..13df2ed723 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.MainSettingsApi.MainSettingsResponse 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/rrtestsettings/RRTestSettingsActionHandler.scala b/es82x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala index 3fe2540c1b..111beb5916 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestsettings 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.TestSettingsApi.TestSettingsResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestSettingsActionHandler extends Logging { +class RRTestSettingsActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +52,7 @@ class RRTestSettingsActionHandler extends Logging { case Right(response) => listener.onResponse(new RRTestSettingsResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] Internal error", ex) + logger.error(s"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 438011eecf..51b5ecfa3a 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]] { @@ -65,13 +65,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/EsIndexDocumentManager.scala b/es82x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala index 26296f7491..0b6744d767 100644 --- a/es82x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala +++ b/es82x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala @@ -20,7 +20,7 @@ import cats.implicits.* import io.circe.Json import io.circe.parser.* 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.annotation.unused class EsIndexDocumentManager(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexDocumentManager - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -61,17 +61,17 @@ class EsIndexDocumentManager(client: NodeClient, if (response.isExists) { Option(response.getSourceAsString) match { case Some(source) => - logger.debug(s"Document [${index.show} ID=$id] _source: $source") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: $source") parse(source) match { case Right(value) => Right(value) case Left(failure) => throw new IllegalStateException(s"Cannot parse document source to JSON: ${failure.toString}") } 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(Json.Null) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(DocumentNotFound) } } @@ -80,7 +80,7 @@ class EsIndexDocumentManager(client: NodeClient, case _: IndexNotFoundException => Left(IndexNotFound) case _: ResourceNotFoundException => Left(DocumentNotFound) 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(DocumentUnreachable) } } @@ -104,14 +104,14 @@ class EsIndexDocumentManager(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 c40f2af9e6..c169605a28 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, clusterSettings: ClusterSettings, sharedGroupFactory: SharedGroupFactory) extends Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, ssl.clientAuthenticationEnabled) @@ -51,7 +51,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 e78670311e..08854c2ba4 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 @@ -46,7 +46,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, ssl: InternodeSslSettings, sharedGroupFactory: SharedGroupFactory) extends Netty4Transport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = doPrivileged { SSLCertHelper.prepareClientSSLContext(ssl) } private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, 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/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/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 acfef36a08..1c8921b1db 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 @@ -63,7 +63,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, esConfigBasedRorSettings: EsConfigBasedRorSettings) (implicit systemContext: SystemContext) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = systemContext.uniqueIdentifierGenerator @@ -213,12 +213,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) } @@ -240,7 +240,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 3165661004..13df2ed723 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.MainSettingsApi.MainSettingsResponse 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/rrtestsettings/RRTestSettingsActionHandler.scala b/es83x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala index 3fe2540c1b..dc95b1a616 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestsettings 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.TestSettingsApi.TestSettingsResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestSettingsActionHandler extends Logging { +class RRTestSettingsActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler 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 438011eecf..51b5ecfa3a 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]] { @@ -65,13 +65,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/EsIndexDocumentManager.scala b/es83x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala index 26296f7491..0b6744d767 100644 --- a/es83x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala +++ b/es83x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala @@ -20,7 +20,7 @@ import cats.implicits.* import io.circe.Json import io.circe.parser.* 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.annotation.unused class EsIndexDocumentManager(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexDocumentManager - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -61,17 +61,17 @@ class EsIndexDocumentManager(client: NodeClient, if (response.isExists) { Option(response.getSourceAsString) match { case Some(source) => - logger.debug(s"Document [${index.show} ID=$id] _source: $source") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: $source") parse(source) match { case Right(value) => Right(value) case Left(failure) => throw new IllegalStateException(s"Cannot parse document source to JSON: ${failure.toString}") } 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(Json.Null) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(DocumentNotFound) } } @@ -80,7 +80,7 @@ class EsIndexDocumentManager(client: NodeClient, case _: IndexNotFoundException => Left(IndexNotFound) case _: ResourceNotFoundException => Left(DocumentNotFound) 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(DocumentUnreachable) } } @@ -104,14 +104,14 @@ class EsIndexDocumentManager(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 31767410bc..7673050c9f 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, clusterSettings: ClusterSettings, sharedGroupFactory: SharedGroupFactory) extends Netty4HttpServerTransport(settings, networkService, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, 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/es83x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala b/es83x/src/main/scala/tech/beshu/ror/es/ssl/SSLNetty4InternodeServerTransport.scala index e78670311e..08854c2ba4 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 @@ -46,7 +46,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, ssl: InternodeSslSettings, sharedGroupFactory: SharedGroupFactory) extends Netty4Transport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = doPrivileged { SSLCertHelper.prepareClientSSLContext(ssl) } private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, 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/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/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 acfef36a08..1c8921b1db 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 @@ -63,7 +63,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, esConfigBasedRorSettings: EsConfigBasedRorSettings) (implicit systemContext: SystemContext) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = systemContext.uniqueIdentifierGenerator @@ -213,12 +213,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) } @@ -240,7 +240,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 3165661004..13df2ed723 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.MainSettingsApi.MainSettingsResponse 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/rrtestsettings/RRTestSettingsActionHandler.scala b/es84x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala index 3fe2540c1b..dc95b1a616 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestsettings 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.TestSettingsApi.TestSettingsResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestSettingsActionHandler extends Logging { +class RRTestSettingsActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler 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 438011eecf..51b5ecfa3a 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]] { @@ -65,13 +65,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/EsIndexDocumentManager.scala b/es84x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala index 26296f7491..0b6744d767 100644 --- a/es84x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala +++ b/es84x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala @@ -20,7 +20,7 @@ import cats.implicits.* import io.circe.Json import io.circe.parser.* 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.annotation.unused class EsIndexDocumentManager(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexDocumentManager - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -61,17 +61,17 @@ class EsIndexDocumentManager(client: NodeClient, if (response.isExists) { Option(response.getSourceAsString) match { case Some(source) => - logger.debug(s"Document [${index.show} ID=$id] _source: $source") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: $source") parse(source) match { case Right(value) => Right(value) case Left(failure) => throw new IllegalStateException(s"Cannot parse document source to JSON: ${failure.toString}") } 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(Json.Null) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(DocumentNotFound) } } @@ -80,7 +80,7 @@ class EsIndexDocumentManager(client: NodeClient, case _: IndexNotFoundException => Left(IndexNotFound) case _: ResourceNotFoundException => Left(DocumentNotFound) 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(DocumentUnreachable) } } @@ -104,14 +104,14 @@ class EsIndexDocumentManager(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 b4eb8b51bb..a5adfec482 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, sharedGroupFactory: SharedGroupFactory, tracer: Tracer) extends Netty4HttpServerTransport(settings, networkService, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory, tracer) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, ssl.clientAuthenticationEnabled) @@ -51,7 +51,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 e78670311e..08854c2ba4 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 @@ -46,7 +46,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, ssl: InternodeSslSettings, sharedGroupFactory: SharedGroupFactory) extends Netty4Transport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = doPrivileged { SSLCertHelper.prepareClientSSLContext(ssl) } private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, 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/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/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 a369e8f646..6e788de1f0 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 @@ -63,7 +63,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, esConfigBasedRorSettings: EsConfigBasedRorSettings) (implicit systemContext: SystemContext) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = systemContext.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/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 3165661004..13df2ed723 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.MainSettingsApi.MainSettingsResponse 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/rrtestsettings/RRTestSettingsActionHandler.scala b/es85x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala index 3fe2540c1b..dc95b1a616 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestsettings 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.TestSettingsApi.TestSettingsResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestSettingsActionHandler extends Logging { +class RRTestSettingsActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler 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 438011eecf..51b5ecfa3a 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]] { @@ -65,13 +65,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/EsIndexDocumentManager.scala b/es85x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala index 26296f7491..0b6744d767 100644 --- a/es85x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala +++ b/es85x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala @@ -20,7 +20,7 @@ import cats.implicits.* import io.circe.Json import io.circe.parser.* 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.annotation.unused class EsIndexDocumentManager(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexDocumentManager - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -61,17 +61,17 @@ class EsIndexDocumentManager(client: NodeClient, if (response.isExists) { Option(response.getSourceAsString) match { case Some(source) => - logger.debug(s"Document [${index.show} ID=$id] _source: $source") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: $source") parse(source) match { case Right(value) => Right(value) case Left(failure) => throw new IllegalStateException(s"Cannot parse document source to JSON: ${failure.toString}") } 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(Json.Null) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(DocumentNotFound) } } @@ -80,7 +80,7 @@ class EsIndexDocumentManager(client: NodeClient, case _: IndexNotFoundException => Left(IndexNotFound) case _: ResourceNotFoundException => Left(DocumentNotFound) 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(DocumentUnreachable) } } @@ -104,14 +104,14 @@ class EsIndexDocumentManager(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 b4eb8b51bb..a5adfec482 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, sharedGroupFactory: SharedGroupFactory, tracer: Tracer) extends Netty4HttpServerTransport(settings, networkService, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory, tracer) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, ssl.clientAuthenticationEnabled) @@ -51,7 +51,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 e78670311e..08854c2ba4 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 @@ -46,7 +46,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, ssl: InternodeSslSettings, sharedGroupFactory: SharedGroupFactory) extends Netty4Transport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = doPrivileged { SSLCertHelper.prepareClientSSLContext(ssl) } private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, 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/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/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 a369e8f646..6e788de1f0 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 @@ -63,7 +63,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, esConfigBasedRorSettings: EsConfigBasedRorSettings) (implicit systemContext: SystemContext) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = systemContext.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/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 3165661004..13df2ed723 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.MainSettingsApi.MainSettingsResponse 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/rrtestsettings/RRTestSettingsActionHandler.scala b/es87x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala index 3fe2540c1b..dc95b1a616 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestsettings 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.TestSettingsApi.TestSettingsResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestSettingsActionHandler extends Logging { +class RRTestSettingsActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler 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 438011eecf..51b5ecfa3a 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]] { @@ -65,13 +65,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/EsIndexDocumentManager.scala b/es87x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala index 26296f7491..0b6744d767 100644 --- a/es87x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala +++ b/es87x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala @@ -20,7 +20,7 @@ import cats.implicits.* import io.circe.Json import io.circe.parser.* 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.annotation.unused class EsIndexDocumentManager(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexDocumentManager - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -61,17 +61,17 @@ class EsIndexDocumentManager(client: NodeClient, if (response.isExists) { Option(response.getSourceAsString) match { case Some(source) => - logger.debug(s"Document [${index.show} ID=$id] _source: $source") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: $source") parse(source) match { case Right(value) => Right(value) case Left(failure) => throw new IllegalStateException(s"Cannot parse document source to JSON: ${failure.toString}") } 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(Json.Null) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(DocumentNotFound) } } @@ -80,7 +80,7 @@ class EsIndexDocumentManager(client: NodeClient, case _: IndexNotFoundException => Left(IndexNotFound) case _: ResourceNotFoundException => Left(DocumentNotFound) 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(DocumentUnreachable) } } @@ -104,14 +104,14 @@ class EsIndexDocumentManager(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 0851dcb123..35ed5a3c14 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, sharedGroupFactory: SharedGroupFactory, tracer: Tracer) extends Netty4HttpServerTransport(settings, networkService, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory, tracer, TLSConfig.noTLS(), null) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, ssl.clientAuthenticationEnabled) @@ -51,7 +51,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 8562edfc25..d17c97297d 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 @@ -47,7 +47,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, ssl: InternodeSslSettings, sharedGroupFactory: SharedGroupFactory) extends Netty4Transport(settings, TransportVersion.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = doPrivileged { SSLCertHelper.prepareClientSSLContext(ssl) } private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, clientAuthenticationEnabled = false) } @@ -79,7 +79,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/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 a369e8f646..6e788de1f0 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 @@ -63,7 +63,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, esConfigBasedRorSettings: EsConfigBasedRorSettings) (implicit systemContext: SystemContext) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = systemContext.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/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 3165661004..13df2ed723 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.MainSettingsApi.MainSettingsResponse 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/rrtestsettings/RRTestSettingsActionHandler.scala b/es88x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala index 3fe2540c1b..111beb5916 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestsettings 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.TestSettingsApi.TestSettingsResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestSettingsActionHandler extends Logging { +class RRTestSettingsActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler @@ -52,7 +52,7 @@ class RRTestSettingsActionHandler extends Logging { case Right(response) => listener.onResponse(new RRTestSettingsResponse(response)) case Left(ex) => - logger.error(s"[${requestId.show}] Internal error", ex) + logger.error(s"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 438011eecf..51b5ecfa3a 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]] { @@ -65,13 +65,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/EsIndexDocumentManager.scala b/es88x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala index 26296f7491..0b6744d767 100644 --- a/es88x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala +++ b/es88x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala @@ -20,7 +20,7 @@ import cats.implicits.* import io.circe.Json import io.circe.parser.* 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.annotation.unused class EsIndexDocumentManager(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexDocumentManager - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -61,17 +61,17 @@ class EsIndexDocumentManager(client: NodeClient, if (response.isExists) { Option(response.getSourceAsString) match { case Some(source) => - logger.debug(s"Document [${index.show} ID=$id] _source: $source") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: $source") parse(source) match { case Right(value) => Right(value) case Left(failure) => throw new IllegalStateException(s"Cannot parse document source to JSON: ${failure.toString}") } 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(Json.Null) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(DocumentNotFound) } } @@ -80,7 +80,7 @@ class EsIndexDocumentManager(client: NodeClient, case _: IndexNotFoundException => Left(IndexNotFound) case _: ResourceNotFoundException => Left(DocumentNotFound) 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(DocumentUnreachable) } } @@ -104,14 +104,14 @@ class EsIndexDocumentManager(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 473df8e3cb..e266777747 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, sharedGroupFactory: SharedGroupFactory, tracer: Tracer) extends Netty4HttpServerTransport(settings, networkService, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory, tracer, TLSConfig.noTLS(), null, null) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, ssl.clientAuthenticationEnabled) @@ -51,7 +51,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 8562edfc25..d17c97297d 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 @@ -47,7 +47,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, ssl: InternodeSslSettings, sharedGroupFactory: SharedGroupFactory) extends Netty4Transport(settings, TransportVersion.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = doPrivileged { SSLCertHelper.prepareClientSSLContext(ssl) } private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, clientAuthenticationEnabled = false) } @@ -79,7 +79,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/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 a369e8f646..6e788de1f0 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 @@ -63,7 +63,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, esConfigBasedRorSettings: EsConfigBasedRorSettings) (implicit systemContext: SystemContext) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = systemContext.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/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 3165661004..13df2ed723 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.MainSettingsApi.MainSettingsResponse 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/rrtestsettings/RRTestSettingsActionHandler.scala b/es89x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala index 3fe2540c1b..dc95b1a616 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestsettings 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.TestSettingsApi.TestSettingsResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestSettingsActionHandler extends Logging { +class RRTestSettingsActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler 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 438011eecf..51b5ecfa3a 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]] { @@ -65,13 +65,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/EsIndexDocumentManager.scala b/es89x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala index 26296f7491..0b6744d767 100644 --- a/es89x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala +++ b/es89x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala @@ -20,7 +20,7 @@ import cats.implicits.* import io.circe.Json import io.circe.parser.* 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.annotation.unused class EsIndexDocumentManager(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexDocumentManager - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -61,17 +61,17 @@ class EsIndexDocumentManager(client: NodeClient, if (response.isExists) { Option(response.getSourceAsString) match { case Some(source) => - logger.debug(s"Document [${index.show} ID=$id] _source: $source") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: $source") parse(source) match { case Right(value) => Right(value) case Left(failure) => throw new IllegalStateException(s"Cannot parse document source to JSON: ${failure.toString}") } 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(Json.Null) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(DocumentNotFound) } } @@ -80,7 +80,7 @@ class EsIndexDocumentManager(client: NodeClient, case _: IndexNotFoundException => Left(IndexNotFound) case _: ResourceNotFoundException => Left(DocumentNotFound) 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(DocumentUnreachable) } } @@ -104,14 +104,14 @@ class EsIndexDocumentManager(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 ef14b6eb89..fe53340da8 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, sharedGroupFactory: SharedGroupFactory, tracer: Tracer) extends Netty4HttpServerTransport(settings, networkService, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory, tracer, TLSConfig.noTLS(), null, null) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, ssl.clientAuthenticationEnabled) @@ -51,7 +51,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 88b9d3c808..2af4407a96 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 @@ -47,7 +47,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, ssl: InternodeSslSettings, sharedGroupFactory: SharedGroupFactory) extends Netty4Transport(settings, TransportVersion.current(), threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = doPrivileged { SSLCertHelper.prepareClientSSLContext(ssl) } private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, clientAuthenticationEnabled = false) } @@ -79,7 +79,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/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 2c10ed0012..6d0f0fcbfa 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 @@ -63,7 +63,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, esConfigBasedRorSettings: EsConfigBasedRorSettings) (implicit systemContext: SystemContext) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = systemContext.uniqueIdentifierGenerator @@ -209,12 +209,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) } @@ -236,7 +236,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 3165661004..13df2ed723 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.MainSettingsApi.MainSettingsResponse 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/rrtestsettings/RRTestSettingsActionHandler.scala b/es90x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala index 3fe2540c1b..dc95b1a616 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestsettings 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.TestSettingsApi.TestSettingsResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestSettingsActionHandler extends Logging { +class RRTestSettingsActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler 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 438011eecf..51b5ecfa3a 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]] { @@ -65,13 +65,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/EsIndexDocumentManager.scala b/es90x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala index c1c6c8a26b..558eaa7641 100644 --- a/es90x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala +++ b/es90x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala @@ -20,7 +20,7 @@ import cats.implicits.* import io.circe.Json import io.circe.parser.* 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.annotation.unused class EsIndexDocumentManager(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexDocumentManager - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -61,17 +61,17 @@ class EsIndexDocumentManager(client: NodeClient, if (response.isExists) { Option(response.getSourceAsString) match { case Some(source) => - logger.debug(s"Document [${index.show} ID=$id] _source: $source") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: $source") parse(source) match { case Right(value) => Right(value) case Left(failure) => throw new IllegalStateException(s"Cannot parse document source to JSON: ${failure.toString}") } 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(Json.Null) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(DocumentNotFound) } } @@ -80,7 +80,7 @@ class EsIndexDocumentManager(client: NodeClient, case _: IndexNotFoundException => Left(IndexNotFound) case _: ResourceNotFoundException => Left(DocumentNotFound) 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(DocumentUnreachable) } } @@ -104,14 +104,14 @@ class EsIndexDocumentManager(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 46d402b70a..ef798f964c 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, sharedGroupFactory: SharedGroupFactory, tracer: Tracer) extends Netty4HttpServerTransport(settings, networkService, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory, tracer, TLSConfig.noTLS(), null, null) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, ssl.clientAuthenticationEnabled) @@ -52,7 +52,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 88b9d3c808..2af4407a96 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 @@ -47,7 +47,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, ssl: InternodeSslSettings, sharedGroupFactory: SharedGroupFactory) extends Netty4Transport(settings, TransportVersion.current(), threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = doPrivileged { SSLCertHelper.prepareClientSSLContext(ssl) } private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, clientAuthenticationEnabled = false) } @@ -79,7 +79,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/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 1b4bda121a..bdfb2657d2 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 @@ -63,7 +63,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, esConfigBasedRorSettings: EsConfigBasedRorSettings) (implicit systemContext: SystemContext) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = systemContext.uniqueIdentifierGenerator @@ -209,12 +209,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) } @@ -236,7 +236,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 3165661004..13df2ed723 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.MainSettingsApi.MainSettingsResponse 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/rrtestsettings/RRTestSettingsActionHandler.scala b/es91x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala index 3fe2540c1b..dc95b1a616 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestsettings 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.TestSettingsApi.TestSettingsResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestSettingsActionHandler extends Logging { +class RRTestSettingsActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler 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 438011eecf..51b5ecfa3a 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]] { @@ -65,13 +65,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 9365230fe3..9abe861fe3 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/EsIndexDocumentManager.scala b/es91x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala index c1c6c8a26b..558eaa7641 100644 --- a/es91x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala +++ b/es91x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala @@ -20,7 +20,7 @@ import cats.implicits.* import io.circe.Json import io.circe.parser.* 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.annotation.unused class EsIndexDocumentManager(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexDocumentManager - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -61,17 +61,17 @@ class EsIndexDocumentManager(client: NodeClient, if (response.isExists) { Option(response.getSourceAsString) match { case Some(source) => - logger.debug(s"Document [${index.show} ID=$id] _source: $source") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: $source") parse(source) match { case Right(value) => Right(value) case Left(failure) => throw new IllegalStateException(s"Cannot parse document source to JSON: ${failure.toString}") } 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(Json.Null) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(DocumentNotFound) } } @@ -80,7 +80,7 @@ class EsIndexDocumentManager(client: NodeClient, case _: IndexNotFoundException => Left(IndexNotFound) case _: ResourceNotFoundException => Left(DocumentNotFound) 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(DocumentUnreachable) } } @@ -104,14 +104,14 @@ class EsIndexDocumentManager(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 81b7891185..f69cf7c7e0 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, sharedGroupFactory: SharedGroupFactory, tracer: Tracer) extends Netty4HttpServerTransport(settings, networkService, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory, tracer, TLSConfig.noTLS(), null, null) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, ssl.clientAuthenticationEnabled) @@ -51,7 +51,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 88b9d3c808..2af4407a96 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 @@ -47,7 +47,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, ssl: InternodeSslSettings, sharedGroupFactory: SharedGroupFactory) extends Netty4Transport(settings, TransportVersion.current(), threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = doPrivileged { SSLCertHelper.prepareClientSSLContext(ssl) } private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, clientAuthenticationEnabled = false) } @@ -79,7 +79,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/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 1b4bda121a..bdfb2657d2 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 @@ -63,7 +63,7 @@ class IndexLevelActionFilter(clusterService: ClusterService, esInitListener: EsInitListener, esConfigBasedRorSettings: EsConfigBasedRorSettings) (implicit systemContext: SystemContext) - extends ActionFilter with Logging { + extends ActionFilter with RequestIdAwareLogging { private implicit val generator: UniqueIdentifierGenerator = systemContext.uniqueIdentifierGenerator @@ -209,12 +209,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) } @@ -236,7 +236,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 3165661004..13df2ed723 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.MainSettingsApi.MainSettingsResponse 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/rrtestsettings/RRTestSettingsActionHandler.scala b/es92x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala index 3fe2540c1b..dc95b1a616 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/actions/rrtestsettings/RRTestSettingsActionHandler.scala @@ -18,7 +18,7 @@ package tech.beshu.ror.es.actions.rrtestsettings 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.TestSettingsApi.TestSettingsResponse @@ -27,7 +27,7 @@ import tech.beshu.ror.implicits.* import tech.beshu.ror.utils.AccessControllerHelper.doPrivileged import tech.beshu.ror.utils.RorInstanceSupplier -class RRTestSettingsActionHandler extends Logging { +class RRTestSettingsActionHandler extends RequestIdAwareLogging { private implicit val rorRestApiScheduler: Scheduler = RorSchedulers.restApiScheduler 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 438011eecf..51b5ecfa3a 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]] { @@ -65,13 +65,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 9365230fe3..9abe861fe3 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/EsIndexDocumentManager.scala b/es92x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala index c1c6c8a26b..558eaa7641 100644 --- a/es92x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala +++ b/es92x/src/main/scala/tech/beshu/ror/es/services/EsIndexDocumentManager.scala @@ -20,7 +20,7 @@ import cats.implicits.* import io.circe.Json import io.circe.parser.* 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.annotation.unused class EsIndexDocumentManager(client: NodeClient, @unused constructorDiscriminator: Unit) extends IndexDocumentManager - with Logging { + with RequestIdAwareLogging { @Inject def this(client: NodeClient) = { @@ -61,17 +61,17 @@ class EsIndexDocumentManager(client: NodeClient, if (response.isExists) { Option(response.getSourceAsString) match { case Some(source) => - logger.debug(s"Document [${index.show} ID=$id] _source: $source") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] _source: $source") parse(source) match { case Right(value) => Right(value) case Left(failure) => throw new IllegalStateException(s"Cannot parse document source to JSON: ${failure.toString}") } 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(Json.Null) } } else { - logger.debug(s"Document [${index.show} ID=$id] not exist") + noRequestIdLogger.debug(s"Document [${index.show} ID=$id] not exist") Left(DocumentNotFound) } } @@ -80,7 +80,7 @@ class EsIndexDocumentManager(client: NodeClient, case _: IndexNotFoundException => Left(IndexNotFound) case _: ResourceNotFoundException => Left(DocumentNotFound) 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(DocumentUnreachable) } } @@ -104,14 +104,14 @@ class EsIndexDocumentManager(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 9180fa06e7..e6ef3800a2 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, sharedGroupFactory: SharedGroupFactory, telemetryProvider: TelemetryProvider) extends Netty4HttpServerTransport(settings, networkService, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory, telemetryProvider, TLSConfig.noTLS(), null, null) - with Logging { + with RequestIdAwareLogging { private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, ssl.clientAuthenticationEnabled) @@ -51,7 +51,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 88b9d3c808..2af4407a96 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 @@ -47,7 +47,7 @@ class SSLNetty4InternodeServerTransport(settings: Settings, ssl: InternodeSslSettings, sharedGroupFactory: SharedGroupFactory) extends Netty4Transport(settings, TransportVersion.current(), threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, sharedGroupFactory) - with Logging { + with RequestIdAwareLogging { private val clientSslContext = doPrivileged { SSLCertHelper.prepareClientSSLContext(ssl) } private val serverSslContext = doPrivileged { SSLCertHelper.prepareServerSSLContext(ssl, clientAuthenticationEnabled = false) } @@ -79,7 +79,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/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 } }