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

Commit

Permalink
Remove agent id and use machine id instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Michel Zimmer committed Jul 22, 2022
1 parent 9c24910 commit df719a5
Show file tree
Hide file tree
Showing 18 changed files with 72 additions and 127 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ LABEL org.opencontainers.image.vendor="neuland – Büro für Informatik GmbH"
LABEL org.opencontainers.image.licenses="Apache-2.0"
LABEL org.opencontainers.image.title="bandwhichd-server"
LABEL org.opencontainers.image.description="bandwhichd server collecting measurements and calculating statistics"
LABEL org.opencontainers.image.version="0.6.0-rc5"
LABEL org.opencontainers.image.version="0.6.0-rc6"
USER guest
ENTRYPOINT ["/opt/java/openjdk/bin/java"]
CMD ["-jar", "/opt/bandwhichd-server.jar"]
EXPOSE 8080
STOPSIGNAL SIGTERM
COPY --from=build --chown=root:root /tmp/bandwhichd-server/target/scala-3.1.3/bandwhichd-server-assembly-0.6.0-rc5.jar /opt/bandwhichd-server.jar
COPY --from=build --chown=root:root /tmp/bandwhichd-server/target/scala-3.1.3/bandwhichd-server-assembly-0.6.0-rc6.jar /opt/bandwhichd-server.jar
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ lazy val root = (project in file("."))
.settings(
organization := "de.neuland-bfi",
name := "bandwhichd-server",
version := "0.6.0-rc5",
version := "0.6.0-rc6",
scalaVersion := "3.1.3",
Compile / scalaSource := baseDirectory.value / "src" / "main" / "scala",
Test / scalaSource := baseDirectory.value / "src" / "test" / "scala",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ object Message {
case MeasurementMessage(nc: Measurement.NetworkConfiguration) =>
Json.obj(
"type" -> Json.fromString(
"bandwhichd/measurement/network-configuration/v1"
"bandwhichd/measurement/agent-network-configuration/v1"
),
"content" -> Encoder[Measurement.NetworkConfiguration].apply(nc)
)
case MeasurementMessage(nu: Measurement.NetworkUtilization) =>
Json.obj(
"type" -> Json.fromString(
"bandwhichd/measurement/network-utilization/v1"
"bandwhichd/measurement/agent-network-utilization/v1"
),
"content" -> Encoder[Measurement.NetworkUtilization].apply(nu)
)
Expand All @@ -46,29 +46,27 @@ object Message {
for {
`type` <- c.get[String]("type")
message <- `type` match
case "bandwhichd/measurement/network-configuration/v1" =>
case "bandwhichd/measurement/agent-network-configuration/v1" =>
c.get[Measurement.NetworkConfiguration]("content")
.map(MeasurementMessage.apply)
case "bandwhichd/measurement/network-utilization/v1" =>
case "bandwhichd/measurement/agent-network-utilization/v1" =>
c.get[Measurement.NetworkUtilization]("content")
.map(MeasurementMessage.apply)
case _ =>
Left(DecodingFailure(s"invalid message type ${`type`}", c.history))
} yield message

given Codec[Measurement.NetworkConfiguration] =
Codec.forProduct6(
"agent_id",
"timestamp",
Codec.forProduct5(
"machine_id",
"timestamp",
"hostname",
"interfaces",
"open_sockets"
)(Measurement.NetworkConfiguration.apply)(nc =>
(
nc.agentId,
nc.timing,
nc.machineId,
nc.timing,
nc.hostname,
nc.interfaces,
nc.openSockets
Expand All @@ -77,12 +75,12 @@ object Message {

given Codec[Measurement.NetworkUtilization] =
Codec.forProduct3(
"agent_id",
"machine_id",
"timeframe",
"connections"
)(Measurement.NetworkUtilization.apply)(nu =>
(
nu.agentId,
nu.machineId,
nu.timing,
nu.connections
)
Expand Down Expand Up @@ -153,8 +151,6 @@ object Message {
Decoder[A].map(Sent.apply)
///////////////////////

given Encoder[AgentId] = Encoder[UUID].contramap(_.value)
given Decoder[AgentId] = Decoder[UUID].map(AgentId.apply)
given Encoder[BytesCount] = Encoder[String].contramap(_.value.toString)
given Decoder[BytesCount] = Decoder[BigInt].map(BytesCount.apply)
given Encoder[InterfaceName] = Encoder[String].contramap(_.value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@ class CassandraMigration[F[_]: Async](
| date date,
| timestamp timestamp,
| end_timestamp timestamp,
| agent_id uuid,
| machine_id uuid,
| measurement_type ascii,
| network_configuration_machine_id uuid,
| network_configuration_hostname text,
| network_configuration_interfaces frozen<list<frozen<measurement_network_configuration_interface>>>,
| network_configuration_open_sockets frozen<list<frozen<measurement_network_configuration_open_socket>>>,
| network_utilization_connections frozen<list<frozen<measurement_network_utilization_connection>>>,
| primary key ((date), timestamp, agent_id, measurement_type),
| primary key ((date), timestamp, machine_id, measurement_type),
|) with clustering order by (timestamp asc)""".stripMargin
)
.setKeyspace(configuration.measurementsKeyspace)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,21 @@ import de.neuland.bandwhichd.server.domain.measurement.*
import de.neuland.bandwhichd.server.lib.time.Interval
import io.circe.*

import java.time.*
import java.time.ZoneOffset.UTC
import java.time.format.DateTimeFormatter.ISO_DATE_TIME
import java.time.format.{DateTimeFormatter, DateTimeFormatterBuilder}
import java.time.*
import java.util.UUID
import scala.util.Try

object MeasurementCassandraCodecs {
given Codec[Measurement[Timing]] =
Codec.forProduct10(
Codec.forProduct9(
"date",
"timestamp",
"end_timestamp",
"agent_id",
"machine_id",
"measurement_type",
"network_configuration_machine_id",
"network_configuration_hostname",
"network_configuration_interfaces",
"network_configuration_open_sockets",
Expand All @@ -33,9 +32,8 @@ object MeasurementCassandraCodecs {
_: String,
timestamp: Timing.Timestamp,
endTimestamp: Timing.Timestamp,
agentId: AgentId,
machineId: MachineId,
measurementType: String,
machinedId: MachineId,
hostname: Hostname,
interfaces: Seq[Interface],
openSockets: Seq[OpenSocket],
Expand All @@ -44,16 +42,15 @@ object MeasurementCassandraCodecs {
measurementType match
case "network_configuration" =>
Measurement.NetworkConfiguration(
agentId = agentId,
machineId = machineId,
timing = timestamp,
machineId = machinedId,
hostname = hostname,
interfaces = interfaces,
openSockets = openSockets
)
case "network_utilization" =>
Measurement.NetworkUtilization(
agentId = agentId,
machineId = machineId,
timing = Timing.Timeframe(
Interval(
start = timestamp.instant,
Expand All @@ -69,9 +66,8 @@ object MeasurementCassandraCodecs {
)
)(_ match
case Measurement.NetworkConfiguration(
agentId,
timing,
machineId,
timing,
hostname,
interfaces,
openSockets
Expand All @@ -80,26 +76,24 @@ object MeasurementCassandraCodecs {
LocalDate.ofInstant(timing.value, UTC).toString,
timing,
Timing.Timestamp(Instant.EPOCH),
agentId,
"network_configuration",
machineId,
"network_configuration",
hostname,
interfaces,
openSockets,
Seq.empty[Connection]
)
case Measurement.NetworkUtilization(
agentId,
machineId,
timing,
connections
) =>
(
LocalDate.ofInstant(timing.value.normalizedStart, UTC).toString,
Timing.Timestamp(timing.value.normalizedStart),
Timing.Timestamp(timing.value.normalizedStop),
agentId,
machineId,
"network_utilization",
MachineId(new UUID(0, 0)),
Hostname.fromString("a").get,
Seq.empty[Interface],
Seq.empty[OpenSocket],
Expand Down Expand Up @@ -182,8 +176,6 @@ object MeasurementCassandraCodecs {

///////////////////////

given Encoder[AgentId] = Encoder[UUID].contramap(_.value)
given Decoder[AgentId] = Decoder[UUID].map(AgentId.apply)
given Encoder[BytesCount] = Encoder[BigInt].contramap(_.value)
given Decoder[BytesCount] = Decoder[BigInt].map(BytesCount.apply)
given Encoder[InterfaceName] = Encoder[String].contramap(_.value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.datastax.oss.driver.api.core.cql.{SimpleStatement, Statement}
import de.neuland.bandwhichd.server.adapter.out.measurement.MeasurementCassandraCodecs.given
import de.neuland.bandwhichd.server.boot.Configuration
import de.neuland.bandwhichd.server.domain.measurement.*
import de.neuland.bandwhichd.server.domain.{AgentId, Interface, MachineId}
import de.neuland.bandwhichd.server.domain.{Interface, MachineId}
import de.neuland.bandwhichd.server.lib.cassandra.CassandraContext
import de.neuland.bandwhichd.server.lib.time.Interval
import fs2.Stream
Expand Down
13 changes: 0 additions & 13 deletions src/main/scala/de/neuland/bandwhichd/server/domain/AgentId.scala

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.comcast.ip4s.Hostname
import de.neuland.bandwhichd.server.domain.*

sealed trait Measurement[+T <: Timing] {
def agentId: AgentId
def machineId: MachineId
def timing: T
def timestamp: Timing.Timestamp =
timing match
Expand All @@ -14,16 +14,15 @@ sealed trait Measurement[+T <: Timing] {

object Measurement {
case class NetworkConfiguration(
agentId: AgentId,
timing: Timing.Timestamp,
machineId: MachineId,
timing: Timing.Timestamp,
hostname: Hostname,
interfaces: Seq[Interface],
openSockets: Seq[OpenSocket]
) extends Measurement[Timing.Timestamp]

case class NetworkUtilization(
agentId: AgentId,
machineId: MachineId,
timing: Timing.Timeframe,
connections: Seq[Connection]
) extends Measurement[Timing.Timeframe]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ object MachineIdHost {

case class MonitoredHost(
hostId: HostId.MachineId,
agentIds: Set[AgentId],
hostname: Hostname,
additionalHostnames: Set[Hostname],
interfaces: Set[Interface]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ object Stats {
): MonitoredStats =
measurement match
case Measurement.NetworkConfiguration(
agentId,
timing,
machineId,
timing,
hostname,
interfaces,
_
Expand All @@ -75,9 +74,6 @@ object Stats {
: Option[Bundle[HostId.MachineId, MonitoredHost, HostId]] =
stats.bundles
.get(hostId)
.orElse {
stats.bundles.values.find(_.host.agentIds.contains(agentId))
}
.orElse {
stats.bundles.values.find(_.host.hostnames.contains(hostname))
}
Expand All @@ -87,7 +83,6 @@ object Stats {
Stats.Bundle(
host = MonitoredHost(
hostId = hostId,
agentIds = Set(agentId),
hostname = hostname,
additionalHostnames = Set.empty,
interfaces = interfaces.toSet
Expand All @@ -99,7 +94,6 @@ object Stats {
bundle.copy(
host = MonitoredHost(
hostId = hostId,
agentIds = bundle.host.agentIds + agentId,
hostname = hostname,
additionalHostnames = bundle.host.hostnames - hostname,
interfaces = bundle.host.interfaces ++ interfaces
Expand All @@ -111,12 +105,14 @@ object Stats {
new Stats(stats.bundles + (hostId -> bundle))

case Measurement.NetworkUtilization(
agentId,
machineId,
timing,
connections
) =>
stats.bundles.values
.find(_.host.agentIds.contains(agentId))
val hostId: HostId.MachineId = HostId(machineId)

stats.bundles
.get(hostId)
.fold(stats) { bundle =>
new Stats(
stats.bundles + (bundle.host.hostId -> bundle.copy(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"type": "bandwhichd/measurement/network-configuration/v1",
"type": "bandwhichd/measurement/agent-network-configuration/v1",
"content": {
"agent_id": "d254aebd-e092-4ced-b698-0448a46eaf7d",
"timestamp": "2022-05-06T15:14:51.742Z",
"machine_id": "c414c2da-714c-4b68-b97e-3f31e18053d2",
"timestamp": "2022-05-06T15:14:51.742Z",
"hostname": "some-host.example.com",
"interfaces": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type": "bandwhichd/measurement/network-utilization/v1",
"type": "bandwhichd/measurement/agent-network-utilization/v1",
"content": {
"agent_id": "d254aebd-e092-4ced-b698-0448a46eaf7d",
"machine_id": "c414c2da-714c-4b68-b97e-3f31e18053d2",
"timeframe": "2022-05-06T15:14:51.942Z/PT10.001S",
"connections": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ object ApiV1MessageV1Fixtures {
Using(
Source.fromURL(
getClass.getClassLoader.getResource(
"de/neuland/bandwhichd/server/adapter/in/v1/message/bandwhichd/measurement/network-configuration/v1/example.json"
"de/neuland/bandwhichd/server/adapter/in/v1/message/bandwhichd/measurement/agent-network-configuration/v1/example.json"
)
)
)(_.mkString).get
Expand All @@ -24,7 +24,7 @@ object ApiV1MessageV1Fixtures {
Using(
Source.fromURL(
getClass.getClassLoader.getResource(
"de/neuland/bandwhichd/server/adapter/in/v1/message/bandwhichd/measurement/network-utilization/v1/example.json"
"de/neuland/bandwhichd/server/adapter/in/v1/message/bandwhichd/measurement/agent-network-utilization/v1/example.json"
)
)
)(_.mkString).get
Expand Down
Loading

0 comments on commit df719a5

Please sign in to comment.