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._
final case class SolrConfig(url: LenientUri, commitWithin: Int)
final case class SolrConfig(url: LenientUri, commitWithin: Int, logVerbose: Boolean)
object SolrConfig {}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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] =

View File

@ -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 =

View File

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

View File

@ -87,8 +87,8 @@ docspell.server {
# Configuration of the full-text search engine.
full-text-search {
# The full-text search feature can be disabled. It requires an
# additional index server available which needs additional
# memory and disk space. It can be enabled later any time.
# additional index server which needs additional memory and disk
# space. It can be enabled later any time.
#
# Currently the SOLR search platform is supported.
enabled = false
@ -103,9 +103,14 @@ docspell.server {
# Configuration for the SOLR backend.
solr = {
# The URL to solr
url = "http://localhost:8983/solr/docspell"
# Used to tell solr when to commit the data
commit-within = 1000
# If true, logs request and response bodies
log-verbose = false
}
}
# 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 {
background: rgba(246, 255, 158, 0.15);
background: rgba(246, 255, 158, 0.1);
font-size: smaller;
max-height: 25em;
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 .description {
color: rgba(0,0,0,.55);
color: rgba(0,0,0,.6);
margin-left: 0.75em;
}
.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 {