Consistent logging of request/responses to solr

Using a middleware. Also add missing changesets for mariadb.
This commit is contained in:
Eike Kettner 2020-06-24 21:25:46 +02:00
parent 47697a8056
commit 532caed84c
9 changed files with 50 additions and 26 deletions

View File

@ -2,6 +2,6 @@ package docspell.ftssolr
import docspell.common._ import docspell.common._
final case class SolrConfig(url: LenientUri, commitWithin: Int) final case class SolrConfig(url: LenientUri, commitWithin: Int, logVerbose: Boolean)
object SolrConfig {} object SolrConfig {}

View File

@ -4,6 +4,8 @@ import fs2.Stream
import cats.effect._ import cats.effect._
import cats.implicits._ import cats.implicits._
import org.http4s.client.Client import org.http4s.client.Client
import org.http4s.client.middleware.Logger
import org.log4s.getLogger
import docspell.common._ import docspell.common._
import docspell.ftsclient._ import docspell.ftsclient._
@ -50,17 +52,30 @@ final class SolrFtsClient[F[_]: Effect](
} }
object SolrFtsClient { object SolrFtsClient {
private[this] val logger = getLogger
def apply[F[_]: ConcurrentEffect]( def apply[F[_]: ConcurrentEffect](
cfg: SolrConfig, cfg: SolrConfig,
httpClient: Client[F] httpClient: Client[F]
): Resource[F, FtsClient[F]] = ): Resource[F, FtsClient[F]] = {
val client = loggingMiddleware(cfg, httpClient)
Resource.pure[F, FtsClient[F]]( Resource.pure[F, FtsClient[F]](
new SolrFtsClient( new SolrFtsClient(
SolrUpdate(cfg, httpClient), SolrUpdate(cfg, client),
SolrSetup(cfg, httpClient), SolrSetup(cfg, client),
SolrQuery(cfg, httpClient) 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)
} }

View File

@ -7,7 +7,6 @@ import org.http4s.circe._
import org.http4s.circe.CirceEntityDecoder._ import org.http4s.circe.CirceEntityDecoder._
import org.http4s.client.dsl.Http4sClientDsl import org.http4s.client.dsl.Http4sClientDsl
import _root_.io.circe.syntax._ import _root_.io.circe.syntax._
import org.log4s.getLogger
import docspell.ftsclient._ import docspell.ftsclient._
import JsonCodec._ import JsonCodec._
@ -42,8 +41,6 @@ trait SolrQuery[F[_]] {
} }
object SolrQuery { object SolrQuery {
private[this] val logger = getLogger
def apply[F[_]: ConcurrentEffect](cfg: SolrConfig, client: Client[F]): SolrQuery[F] = { def apply[F[_]: ConcurrentEffect](cfg: SolrConfig, client: Client[F]): SolrQuery[F] = {
val dsl = new Http4sClientDsl[F] {} val dsl = new Http4sClientDsl[F] {}
import dsl._ import dsl._
@ -53,7 +50,6 @@ object SolrQuery {
def query(q: QueryData): F[FtsResult] = { def query(q: QueryData): F[FtsResult] = {
val req = Method.POST(q.asJson, url) val req = Method.POST(q.asJson, url)
logger.trace(s"Running query: $req : ${q.asJson}")
client.expect[FtsResult](req) client.expect[FtsResult](req)
} }

View File

@ -6,7 +6,6 @@ import cats.implicits._
import org.http4s.client.Client import org.http4s.client.Client
import org.http4s.circe._ import org.http4s.circe._
import org.http4s.client.dsl.Http4sClientDsl import org.http4s.client.dsl.Http4sClientDsl
import org.log4s.getLogger
import _root_.io.circe.syntax._ import _root_.io.circe.syntax._
import _root_.io.circe._ import _root_.io.circe._
import _root_.io.circe.generic.semiauto._ import _root_.io.circe.generic.semiauto._
@ -19,7 +18,6 @@ trait SolrSetup[F[_]] {
} }
object SolrSetup { object SolrSetup {
private[this] val logger = getLogger
def apply[F[_]: ConcurrentEffect](cfg: SolrConfig, client: Client[F]): SolrSetup[F] = { def apply[F[_]: ConcurrentEffect](cfg: SolrConfig, client: Client[F]): SolrSetup[F] = {
val dsl = new Http4sClientDsl[F] {} val dsl = new Http4sClientDsl[F] {}
@ -59,8 +57,7 @@ object SolrSetup {
private def run(cmd: Json): F[Unit] = { private def run(cmd: Json): F[Unit] = {
val req = Method.POST(cmd, url) val req = Method.POST(cmd, url)
logger.debug(s"Running request $req: ${cmd.noSpaces}") client.expect[Unit](req)
client.expect[String](req).map(r => logger.debug(s"Response: $r"))
} }
private def addStringField(field: Field): F[Unit] = private def addStringField(field: Field): F[Unit] =

View File

@ -2,13 +2,11 @@ package docspell.ftssolr
import cats.effect._ import cats.effect._
import org.http4s._ import org.http4s._
import cats.implicits._
import org.http4s.client.Client import org.http4s.client.Client
import org.http4s.circe._ import org.http4s.circe._
import org.http4s.client.dsl.Http4sClientDsl import org.http4s.client.dsl.Http4sClientDsl
import _root_.io.circe._ import _root_.io.circe._
import _root_.io.circe.syntax._ import _root_.io.circe.syntax._
import org.log4s.getLogger
import docspell.ftsclient._ import docspell.ftsclient._
import JsonCodec._ import JsonCodec._
@ -23,7 +21,6 @@ trait SolrUpdate[F[_]] {
} }
object SolrUpdate { object SolrUpdate {
private[this] val logger = getLogger
def apply[F[_]: ConcurrentEffect](cfg: SolrConfig, client: Client[F]): SolrUpdate[F] = { def apply[F[_]: ConcurrentEffect](cfg: SolrConfig, client: Client[F]): SolrUpdate[F] = {
val dsl = new Http4sClientDsl[F] {} val dsl = new Http4sClientDsl[F] {}
@ -37,17 +34,17 @@ object SolrUpdate {
def add(tds: List[TextData]): F[Unit] = { def add(tds: List[TextData]): F[Unit] = {
val req = Method.POST(tds.asJson, url) 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] = { def update(tds: List[TextData]): F[Unit] = {
val req = Method.POST(tds.filter(minOneChange).map(SetFields).asJson, url) 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] = { def delete(q: String): F[Unit] = {
val req = Method.POST(Delete(q).asJson, url) 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 = private val minOneChange: TextData => Boolean =

View File

@ -368,16 +368,20 @@ docspell.joex {
# Configuration of the full-text search engine. # Configuration of the full-text search engine.
full-text-search { full-text-search {
# The full-text search feature can be disabled. It requires an # The full-text search feature can be disabled. It requires an
# additional index server available which needs additional # additional index server which needs additional memory and disk
# memory and disk space. It can be enabled later any time. # space. It can be enabled later any time.
# #
# Currently the SOLR search platform is supported. # Currently the SOLR search platform is supported.
enabled = false enabled = false
# Configuration for the SOLR backend. # Configuration for the SOLR backend.
solr = { solr = {
# The URL to solr
url = "http://localhost:8983/solr/docspell" url = "http://localhost:8983/solr/docspell"
# Used to tell solr when to commit the data
commit-within = 1000 commit-within = 1000
# If true, logs request and response bodies
log-verbose = false
} }
# Settings for running the index migration tasks # Settings for running the index migration tasks

View File

@ -87,8 +87,8 @@ docspell.server {
# Configuration of the full-text search engine. # Configuration of the full-text search engine.
full-text-search { full-text-search {
# The full-text search feature can be disabled. It requires an # The full-text search feature can be disabled. It requires an
# additional index server available which needs additional # additional index server which needs additional memory and disk
# memory and disk space. It can be enabled later any time. # space. It can be enabled later any time.
# #
# Currently the SOLR search platform is supported. # Currently the SOLR search platform is supported.
enabled = false enabled = false
@ -103,9 +103,14 @@ docspell.server {
# Configuration for the SOLR backend. # Configuration for the SOLR backend.
solr = { solr = {
# The URL to solr
url = "http://localhost:8983/solr/docspell" url = "http://localhost:8983/solr/docspell"
# Used to tell solr when to commit the data
commit-within = 1000 commit-within = 1000
# If true, logs request and response bodies
log-verbose = false
} }
} }
# Configuration for the backend. # Configuration for the backend.

View File

@ -0,0 +1,10 @@
CREATE TABLE `fts_migration` (
`id` varchar(254) not null primary key,
`version` int not null,
`fts_engine` varchar(254) not null,
`description` varchar(254) not null,
`created` timestamp not null
);
CREATE UNIQUE INDEX `fts_migration_version_engine_idx`
ON `fts_migration`(`version`, `fts_engine`);

View File

@ -89,7 +89,7 @@
} }
.default-layout .ui.cards .ui.card .content.search-highlight { .default-layout .ui.cards .ui.card .content.search-highlight {
background: rgba(246, 255, 158, 0.15); background: rgba(246, 255, 158, 0.1);
font-size: smaller; font-size: smaller;
max-height: 25em; max-height: 25em;
overflow: auto; overflow: auto;
@ -97,11 +97,11 @@
.default-layout .ui.cards .ui.card .content.search-highlight .ui.list .item .content .header { .default-layout .ui.cards .ui.card .content.search-highlight .ui.list .item .content .header {
} }
.default-layout .ui.cards .ui.card .content.search-highlight .ui.list .item .content .description { .default-layout .ui.cards .ui.card .content.search-highlight .ui.list .item .content .description {
color: rgba(0,0,0,.55); color: rgba(0,0,0,.6);
margin-left: 0.75em; margin-left: 0.75em;
} }
.default-layout .ui.cards .ui.card .content.search-highlight .ui.list .item .content .description strong > em { .default-layout .ui.cards .ui.card .content.search-highlight .ui.list .item .content .description strong > em {
color: rgba(0,0,0,.65); background: rgba(220, 255, 71, 0.6);
} }
.markdown-preview { .markdown-preview {