Skip to content
This repository was archived by the owner on Mar 27, 2023. It is now read-only.

Commit 15969d0

Browse files
author
Michel Zimmer
committed
Add connections and unmonitored hosts to stats in JSON format
1 parent 1ada532 commit 15969d0

File tree

5 files changed

+45
-11
lines changed

5 files changed

+45
-11
lines changed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ LABEL org.opencontainers.image.vendor="neuland – Büro für Informatik GmbH"
1212
LABEL org.opencontainers.image.licenses="Apache-2.0"
1313
LABEL org.opencontainers.image.title="bandwhichd-server"
1414
LABEL org.opencontainers.image.description="bandwhichd server collecting measurements and calculating statistics"
15-
LABEL org.opencontainers.image.version="0.6.0-rc7"
15+
LABEL org.opencontainers.image.version="0.6.0-rc8"
1616
USER guest
1717
ENTRYPOINT ["/opt/java/openjdk/bin/java"]
1818
CMD ["-jar", "/opt/bandwhichd-server.jar"]
1919
EXPOSE 8080
2020
STOPSIGNAL SIGTERM
21-
COPY --from=build --chown=root:root /tmp/bandwhichd-server/target/scala-3.1.3/bandwhichd-server-assembly-0.6.0-rc7.jar /opt/bandwhichd-server.jar
21+
COPY --from=build --chown=root:root /tmp/bandwhichd-server/target/scala-3.1.3/bandwhichd-server-assembly-0.6.0-rc8.jar /opt/bandwhichd-server.jar

build.sbt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ lazy val root = (project in file("."))
22
.settings(
33
organization := "de.neuland-bfi",
44
name := "bandwhichd-server",
5-
version := "0.6.0-rc7",
5+
version := "0.6.0-rc8",
66
scalaVersion := "3.1.3",
77
Compile / scalaSource := baseDirectory.value / "src" / "main" / "scala",
88
Test / scalaSource := baseDirectory.value / "src" / "test" / "scala",
@@ -22,12 +22,12 @@ lazy val root = (project in file("."))
2222
val oldStrategy = (ThisBuild / assemblyMergeStrategy).value
2323
oldStrategy(path)
2424
},
25-
libraryDependencies += "co.fs2" %% "fs2-core" % "3.2.8",
26-
libraryDependencies += "co.fs2" %% "fs2-reactive-streams" % "3.2.8",
25+
libraryDependencies += "co.fs2" %% "fs2-core" % "3.2.12",
26+
libraryDependencies += "co.fs2" %% "fs2-reactive-streams" % "3.2.12",
2727
libraryDependencies += "com.comcast" %% "ip4s-core" % "3.1.3",
2828
libraryDependencies += "com.comcast" %% "ip4s-test-kit" % "3.1.3" % "test",
2929
libraryDependencies += "com.datastax.oss" % "java-driver-core" % "4.14.1",
30-
libraryDependencies += "com.dimafeng" %% "testcontainers-scala-scalatest" % "0.40.8" % "test",
30+
libraryDependencies += "com.dimafeng" %% "testcontainers-scala-scalatest" % "0.40.10" % "test",
3131
libraryDependencies += "io.circe" %% "circe-core" % "0.14.2",
3232
libraryDependencies += "io.circe" %% "circe-parser" % "0.14.2",
3333
libraryDependencies += "org.http4s" %% "http4s-circe" % "1.0.0-M32",
@@ -36,8 +36,8 @@ lazy val root = (project in file("."))
3636
libraryDependencies += "org.http4s" %% "http4s-ember-server" % "1.0.0-M32",
3737
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.12" % "test",
3838
libraryDependencies += "org.scalatestplus" %% "scalacheck-1-16" % "3.2.12.0" % "test",
39-
libraryDependencies += "org.slf4j" % "slf4j-simple" % "1.7.36" % "runtime",
40-
libraryDependencies += "org.typelevel" %% "cats-effect" % "3.3.12",
39+
libraryDependencies += "org.slf4j" % "slf4j-simple" % "2.0.0" % "runtime",
40+
libraryDependencies += "org.typelevel" %% "cats-effect" % "3.3.14",
4141
libraryDependencies += "org.typelevel" %% "cats-effect-testing-scalatest" % "1.4.0" % "test",
42-
libraryDependencies += "org.typelevel" %% "log4cats-slf4j" % "2.3.2"
42+
libraryDependencies += "org.typelevel" %% "log4cats-slf4j" % "2.4.0"
4343
)

src/main/scala/de/neuland/bandwhichd/server/adapter/in/v1/stats/StatsCodecs.scala

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,25 @@ object StatsCodecs {
1919
monitoredHost.additionalHostnames.map(additionalHostname =>
2020
Json.fromString(additionalHostname.toString)
2121
)
22-
)
22+
),
23+
"connections" -> stats
24+
.connectionsFor(monitoredHost.hostId)
25+
.fold(Json.obj())(hostIdsToConnections => {
26+
Json.fromFields(
27+
hostIdsToConnections.map[(String, Json)]((hostId, _) => {
28+
hostId.uuid.toString -> Json.obj()
29+
})
30+
)
31+
})
2332
)
2433
)
34+
),
35+
"unmonitoredHosts" -> Json.fromFields(
36+
stats.unidentifiedRemoteHosts.map(unidentifiedRemoteHost => {
37+
unidentifiedRemoteHost.hostId.uuid.toString -> Json.obj(
38+
"host" -> Json.fromString(unidentifiedRemoteHost.host.toString)
39+
)
40+
})
2541
)
2642
)
2743

src/main/scala/de/neuland/bandwhichd/server/domain/stats/Stats.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ class Stats[L <: HostId, H <: AnyHost[L], R <: HostId] private (
3131
}
3232
}.toSet
3333

34+
def connectionsFor(hostId: L): Option[Map[R, Stats.Connection]] =
35+
bundles
36+
.get(hostId)
37+
.map(bundle =>
38+
bundle.connections.view.mapValues(_ => Stats.Connection()).toMap
39+
)
40+
3441
def dropBefore(timestamp: Timing.Timestamp): Stats[L, H, R] =
3542
new Stats(
3643
bundles
@@ -186,6 +193,8 @@ object Stats {
186193
stats.hosts ++ stats.unidentifiedRemoteHosts
187194
}
188195

196+
case class Connection()
197+
189198
private[Stats] case class Bundle[L <: HostId, H <: AnyHost[L], R <: HostId](
190199
host: H,
191200
lastSeenAt: Timing.Timestamp,

src/test/scala/de/neuland/bandwhichd/server/BandwhichdServerApiV1Spec.scala

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,16 @@ class BandwhichdServerApiV1Spec
299299
"hosts" -> obj(
300300
"c414c2da-714c-4b68-b97e-3f31e18053d2" -> obj(
301301
"hostname" -> fromString("some-host.example.com"),
302-
"additional_hostnames" -> arr()
302+
"additional_hostnames" -> arr(),
303+
"connections" -> obj(
304+
"c414c2da-714c-4b68-b97e-3f31e18053d2" -> obj(),
305+
"959619ee-30a2-3bc8-9b79-4384b5f3f05d" -> obj()
306+
)
307+
)
308+
),
309+
"unmonitoredHosts" -> obj(
310+
"959619ee-30a2-3bc8-9b79-4384b5f3f05d" -> obj(
311+
"host" -> fromString("192.168.10.34")
303312
)
304313
)
305314
)

0 commit comments

Comments
 (0)