mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 02:18:26 +00:00
Consistent logging of request/responses to solr
Using a middleware. Also add missing changesets for mariadb.
This commit is contained in:
@ -2,6 +2,6 @@ package docspell.ftssolr
|
||||
|
||||
import docspell.common._
|
||||
|
||||
final case class SolrConfig(url: LenientUri, commitWithin: Int)
|
||||
final case class SolrConfig(url: LenientUri, commitWithin: Int, logVerbose: Boolean)
|
||||
|
||||
object SolrConfig {}
|
||||
|
@ -4,6 +4,8 @@ import fs2.Stream
|
||||
import cats.effect._
|
||||
import cats.implicits._
|
||||
import org.http4s.client.Client
|
||||
import org.http4s.client.middleware.Logger
|
||||
import org.log4s.getLogger
|
||||
|
||||
import docspell.common._
|
||||
import docspell.ftsclient._
|
||||
@ -50,17 +52,30 @@ final class SolrFtsClient[F[_]: Effect](
|
||||
}
|
||||
|
||||
object SolrFtsClient {
|
||||
private[this] val logger = getLogger
|
||||
|
||||
def apply[F[_]: ConcurrentEffect](
|
||||
cfg: SolrConfig,
|
||||
httpClient: Client[F]
|
||||
): Resource[F, FtsClient[F]] =
|
||||
): Resource[F, FtsClient[F]] = {
|
||||
val client = loggingMiddleware(cfg, httpClient)
|
||||
Resource.pure[F, FtsClient[F]](
|
||||
new SolrFtsClient(
|
||||
SolrUpdate(cfg, httpClient),
|
||||
SolrSetup(cfg, httpClient),
|
||||
SolrQuery(cfg, httpClient)
|
||||
SolrUpdate(cfg, client),
|
||||
SolrSetup(cfg, client),
|
||||
SolrQuery(cfg, client)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
private def loggingMiddleware[F[_]: Concurrent](
|
||||
cfg: SolrConfig,
|
||||
client: Client[F]
|
||||
): Client[F] =
|
||||
Logger(
|
||||
logHeaders = true,
|
||||
logBody = cfg.logVerbose,
|
||||
logAction = Some((msg: String) => Sync[F].delay(logger.trace(msg)))
|
||||
)(client)
|
||||
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ import org.http4s.circe._
|
||||
import org.http4s.circe.CirceEntityDecoder._
|
||||
import org.http4s.client.dsl.Http4sClientDsl
|
||||
import _root_.io.circe.syntax._
|
||||
import org.log4s.getLogger
|
||||
|
||||
import docspell.ftsclient._
|
||||
import JsonCodec._
|
||||
@ -42,8 +41,6 @@ trait SolrQuery[F[_]] {
|
||||
}
|
||||
|
||||
object SolrQuery {
|
||||
private[this] val logger = getLogger
|
||||
|
||||
def apply[F[_]: ConcurrentEffect](cfg: SolrConfig, client: Client[F]): SolrQuery[F] = {
|
||||
val dsl = new Http4sClientDsl[F] {}
|
||||
import dsl._
|
||||
@ -53,7 +50,6 @@ object SolrQuery {
|
||||
|
||||
def query(q: QueryData): F[FtsResult] = {
|
||||
val req = Method.POST(q.asJson, url)
|
||||
logger.trace(s"Running query: $req : ${q.asJson}")
|
||||
client.expect[FtsResult](req)
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,6 @@ import cats.implicits._
|
||||
import org.http4s.client.Client
|
||||
import org.http4s.circe._
|
||||
import org.http4s.client.dsl.Http4sClientDsl
|
||||
import org.log4s.getLogger
|
||||
import _root_.io.circe.syntax._
|
||||
import _root_.io.circe._
|
||||
import _root_.io.circe.generic.semiauto._
|
||||
@ -19,7 +18,6 @@ trait SolrSetup[F[_]] {
|
||||
}
|
||||
|
||||
object SolrSetup {
|
||||
private[this] val logger = getLogger
|
||||
|
||||
def apply[F[_]: ConcurrentEffect](cfg: SolrConfig, client: Client[F]): SolrSetup[F] = {
|
||||
val dsl = new Http4sClientDsl[F] {}
|
||||
@ -59,8 +57,7 @@ object SolrSetup {
|
||||
|
||||
private def run(cmd: Json): F[Unit] = {
|
||||
val req = Method.POST(cmd, url)
|
||||
logger.debug(s"Running request $req: ${cmd.noSpaces}")
|
||||
client.expect[String](req).map(r => logger.debug(s"Response: $r"))
|
||||
client.expect[Unit](req)
|
||||
}
|
||||
|
||||
private def addStringField(field: Field): F[Unit] =
|
||||
|
@ -2,13 +2,11 @@ package docspell.ftssolr
|
||||
|
||||
import cats.effect._
|
||||
import org.http4s._
|
||||
import cats.implicits._
|
||||
import org.http4s.client.Client
|
||||
import org.http4s.circe._
|
||||
import org.http4s.client.dsl.Http4sClientDsl
|
||||
import _root_.io.circe._
|
||||
import _root_.io.circe.syntax._
|
||||
import org.log4s.getLogger
|
||||
|
||||
import docspell.ftsclient._
|
||||
import JsonCodec._
|
||||
@ -23,7 +21,6 @@ trait SolrUpdate[F[_]] {
|
||||
}
|
||||
|
||||
object SolrUpdate {
|
||||
private[this] val logger = getLogger
|
||||
|
||||
def apply[F[_]: ConcurrentEffect](cfg: SolrConfig, client: Client[F]): SolrUpdate[F] = {
|
||||
val dsl = new Http4sClientDsl[F] {}
|
||||
@ -37,17 +34,17 @@ object SolrUpdate {
|
||||
|
||||
def add(tds: List[TextData]): F[Unit] = {
|
||||
val req = Method.POST(tds.asJson, url)
|
||||
client.expect[String](req).map(r => logger.trace(s"Req: $req Response: $r"))
|
||||
client.expect[Unit](req)
|
||||
}
|
||||
|
||||
def update(tds: List[TextData]): F[Unit] = {
|
||||
val req = Method.POST(tds.filter(minOneChange).map(SetFields).asJson, url)
|
||||
client.expect[String](req).map(r => logger.trace(s"Req: $req Response: $r"))
|
||||
client.expect[Unit](req)
|
||||
}
|
||||
|
||||
def delete(q: String): F[Unit] = {
|
||||
val req = Method.POST(Delete(q).asJson, url)
|
||||
client.expect[String](req).map(r => logger.trace(s"Req: $req Response: $r"))
|
||||
client.expect[Unit](req)
|
||||
}
|
||||
|
||||
private val minOneChange: TextData => Boolean =
|
||||
|
Reference in New Issue
Block a user