From fd58862e59cafe877d8110172d747d38fee2834c Mon Sep 17 00:00:00 2001 From: Matt Hicks Date: Sat, 23 Dec 2023 08:38:14 -0600 Subject: [PATCH] Added preliminary testing of WAL monitor --- .../outr/arango/monitor/ArangoDBMonitor.scala | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 monitor/src/main/scala/com/outr/arango/monitor/ArangoDBMonitor.scala diff --git a/monitor/src/main/scala/com/outr/arango/monitor/ArangoDBMonitor.scala b/monitor/src/main/scala/com/outr/arango/monitor/ArangoDBMonitor.scala new file mode 100644 index 00000000..4eef2c32 --- /dev/null +++ b/monitor/src/main/scala/com/outr/arango/monitor/ArangoDBMonitor.scala @@ -0,0 +1,43 @@ +package com.outr.arango.monitor + +import cats.effect.{ExitCode, IO, IOApp} +import com.outr.arango.Graph +import com.outr.arango.core.ArangoDBConfig +import fabric.Json +import fabric.io.JsonFormatter +import spice.http.client.HttpClient +import spice.net._ + +// TODO: Work in progress +case class ArangoDBMonitor(config: ArangoDBConfig = ArangoDBConfig()) { + private lazy val client = HttpClient + .url(URL( + protocol = if (config.ssl) Protocol.Https else Protocol.Http, + host = config.hosts.head.host, + port = config.hosts.head.port + )) + // http://localhost:8529/_api/wal/tail?from=188771 + // TODO: Handle user authentication + def tail(db: Option[String] = None, + from: Option[Int] = None, + to: Option[Int] = None, + syncerId: Option[String] = None): IO[Unit] = { + val path = db match { + case Some(dbName) => s"/_db/$dbName/_api/wal/tail" + case None => "/_api/wal/tail" + } + client + .path(URLPath.parse(path)) + .call[Json] + .map { json => + scribe.info(s"Tail: ${JsonFormatter.Default(json)}") + } + } +} + +object ArangoDBMonitor extends IOApp { + override def run(args: List[String]): IO[ExitCode] = { + val monitor = ArangoDBMonitor() + monitor.tail().map(_ => ExitCode.Success) + } +} \ No newline at end of file