From ff651329821944e272c88b1479a1f9fa628262c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20J=C3=B3siak?= Date: Mon, 29 Nov 2021 11:37:10 +0100 Subject: [PATCH 1/3] Bump up opentelemetry metrics to 1.7 --- example/docker/otel-collector-config.yaml | 2 - example/src/main/scala/example/Boot.scala | 26 ++++---- .../extension/upstream/LabelsFactory.scala | 61 +++++++++++++------ .../OpenTelemetryActorMetricsMonitor.scala | 57 +++++++++-------- .../OpenTelemetryActorSystemMonitor.scala | 4 +- .../OpenTelemetryClusterMetricsMonitor.scala | 30 +++++---- ...elemetryHttpConnectionMetricsMonitor.scala | 12 ++-- .../OpenTelemetryHttpMetricsMonitor.scala | 9 +-- ...enTelemetryPersistenceMetricsMonitor.scala | 12 ++-- .../OpenTelemetryStreamMetricsMonitor.scala | 8 ++- ...elemetryStreamOperatorMetricsMonitor.scala | 9 +-- .../upstream/opentelemetry/Synchronized.scala | 36 ++++------- .../WrappedAsynchronousInstrument.scala | 45 ++++++++------ .../WrappedSynchronousInstrument.scala | 40 +++++------- ...OpenTelemetryActorMetricsMonitorTest.scala | 1 - .../util/OpenTelemetryNoopMeter.scala | 4 +- project/Dependencies.scala | 34 +++++------ 17 files changed, 208 insertions(+), 182 deletions(-) diff --git a/example/docker/otel-collector-config.yaml b/example/docker/otel-collector-config.yaml index af0c45249..784f82155 100644 --- a/example/docker/otel-collector-config.yaml +++ b/example/docker/otel-collector-config.yaml @@ -7,8 +7,6 @@ exporters: prometheus: endpoint: "0.0.0.0:8889" namespace: promexample - const_labels: - label1: value1 logging: loglevel: info diff --git a/example/src/main/scala/example/Boot.scala b/example/src/main/scala/example/Boot.scala index dd148aeef..580266db8 100644 --- a/example/src/main/scala/example/Boot.scala +++ b/example/src/main/scala/example/Boot.scala @@ -1,7 +1,5 @@ package example -import java.util.Collections - import akka.actor.typed.ActorSystem import akka.actor.typed.scaladsl.Behaviors import akka.cluster.sharding.typed.scaladsl.ClusterSharding @@ -19,7 +17,7 @@ import example.domain.AccountStateActor import example.domain.JsonCodecs import io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter import io.opentelemetry.sdk.metrics.SdkMeterProvider -import io.opentelemetry.sdk.metrics.export.IntervalMetricReader +import io.opentelemetry.sdk.metrics.export.PeriodicMetricReader import org.slf4j.Logger import org.slf4j.LoggerFactory @@ -27,6 +25,7 @@ import scala.concurrent.ExecutionContext import scala.concurrent.duration._ import scala.io.StdIn import scala.jdk.CollectionConverters._ +import scala.jdk.DurationConverters._ import scala.language.postfixOps import scala.util.Failure import scala.util.Success @@ -43,17 +42,18 @@ object Boot extends App with FailFastCirceSupport with JsonCodecs { ) .resolve - def initOpenTelemetryMetrics(exportInterval: Long): IntervalMetricReader = { - val metricExporter: OtlpGrpcMetricExporter = OtlpGrpcMetricExporter.getDefault() + def initOpenTelemetryMetrics(exportInterval: FiniteDuration): Unit = { + + val metricExporter: OtlpGrpcMetricExporter = OtlpGrpcMetricExporter.getDefault - val meterProvider: SdkMeterProvider = SdkMeterProvider.builder().buildAndRegisterGlobal() + val factory = PeriodicMetricReader.create(metricExporter, exportInterval.toJava) - IntervalMetricReader + val meterProvider: SdkMeterProvider = SdkMeterProvider .builder() - .setMetricExporter(metricExporter) - .setMetricProducers(Collections.singleton(meterProvider)) - .setExportIntervalMillis(exportInterval) - .buildAndStart() + .registerMetricReader(factory) + .buildAndRegisterGlobal() + + sys.addShutdownHook(meterProvider.shutdown()) } def startUp(local: Boolean): Unit = { @@ -74,7 +74,7 @@ object Boot extends App with FailFastCirceSupport with JsonCodecs { // this is important to initialize metric exporting before actor system when starting mesmer from configuration // mesmer on initialization gets hook to OTel metricProvider and if it's not initialized before it defaults to noop logger.info("Starting metric exporter") - val metricReader = initOpenTelemetryMetrics(exportInterval) + initOpenTelemetryMetrics(exportInterval.millis) implicit val system: ActorSystem[Nothing] = ActorSystem[Nothing](Behaviors.empty, systemName, config) @@ -110,8 +110,6 @@ object Boot extends App with FailFastCirceSupport with JsonCodecs { StdIn.readLine() - sys.addShutdownHook(metricReader.shutdown()) - sys.addShutdownHook { binding .flatMap(_.unbind()) diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/LabelsFactory.scala b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/LabelsFactory.scala index a43401e20..f0f8137d7 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/LabelsFactory.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/LabelsFactory.scala @@ -1,48 +1,71 @@ package io.scalac.mesmer.extension.upstream -import io.opentelemetry.api.metrics.common.Labels +import io.opentelemetry.api.common.AttributeKey +import io.opentelemetry.api.common.Attributes import scala.annotation.switch -import scala.collection.mutable.ArrayBuffer object LabelsFactory { - def of(required: (String, String)*)(optionals: (String, Option[String])*): Labels = - Labels.of( - (required ++ optionals.collect { case (k, Some(v)) => (k, v) }).flatMap { case (k, v) => Seq(k, v) }: _* - ) + def of(required: (String, String)*)(optionals: (String, Option[String])*): Attributes = + of(required ++ optionals.collect { case (k, Some(v)) => (k, v) }) /** * Microoptimized version that produce OpenTelemetry labels from sequence of tuples * @param labels * @return */ - def of(labels: Seq[(String, String)]): Labels = { + def of(labels: Seq[(String, String)]): Attributes = { val size = labels.size (size: @switch) match { case 1 => val Seq((key, value)) = labels - Labels.of(key, value) + Attributes.of(AttributeKey.stringKey(key), value) case 2 => val Seq((key1, value1), (key2, value2)) = labels - Labels.of(key1, value1, key2, value2) + Attributes.of(AttributeKey.stringKey(key1), (value1), AttributeKey.stringKey(key2), value2) case 3 => val Seq((key1, value1), (key2, value2), (key3, value3)) = labels - Labels.of(key1, value1, key2, value2, key3, value3) + Attributes.of( + AttributeKey.stringKey(key1), + value1, + AttributeKey.stringKey(key2), + value2, + AttributeKey.stringKey(key3), + value3 + ) case 4 => val Seq((key1, value1), (key2, value2), (key3, value3), (key4, value4)) = labels - Labels.of(key1, value1, key2, value2, key3, value3, key4, value4) + Attributes.of( + AttributeKey.stringKey(key1), + value1, + AttributeKey.stringKey(key2), + value2, + AttributeKey.stringKey(key3), + value3, + AttributeKey.stringKey(key4), + value4 + ) case 5 => val Seq((key1, value1), (key2, value2), (key3, value3), (key4, value4), (key5, value5)) = labels - Labels.of(key1, value1, key2, value2, key3, value3, key4, value4, key5, value5) + Attributes.of( + AttributeKey.stringKey(key1), + value1, + AttributeKey.stringKey(key2), + value2, + AttributeKey.stringKey(key3), + value3, + AttributeKey.stringKey(key4), + value4, + AttributeKey.stringKey(key5), + value5 + ) case _ => - val buffer = new ArrayBuffer[String](size * 2) - labels.foreach { case (key, value) => - buffer.append(key) - buffer.append(value) - } - - Labels.of(buffer.toArray: _*) + labels + .foldLeft(Attributes.builder()) { case (builder, (key, value)) => + builder.put(key, value) + } + .build() } } diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryActorMetricsMonitor.scala b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryActorMetricsMonitor.scala index 4d0099356..b4c7859a1 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryActorMetricsMonitor.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryActorMetricsMonitor.scala @@ -151,93 +151,102 @@ final class OpenTelemetryActorMetricsMonitor( metricNames: MetricNames ) extends ActorMetricsMonitor { - private lazy val mailboxSizeObserver = new LongMetricObserverBuilderAdapter[ActorMetricsMonitor.Labels]( + private lazy val mailboxSizeObserver = new GaugeBuilderAdapter[ActorMetricsMonitor.Labels]( meter - .longValueObserverBuilder(metricNames.mailboxSize) + .gaugeBuilder(metricNames.mailboxSize) + .ofLongs() .setDescription("Tracks the size of an Actor's mailbox") ) - private lazy val mailboxTimeCountObserver = new LongMetricObserverBuilderAdapter[ActorMetricsMonitor.Labels]( + private lazy val mailboxTimeCountObserver = new GaugeBuilderAdapter[ActorMetricsMonitor.Labels]( meter - .longValueObserverBuilder(metricNames.mailboxTimeCount) + .gaugeBuilder(metricNames.mailboxTimeCount) + .ofLongs() .setDescription("Tracks the count of messages in an Actor's mailbox") ) - private lazy val mailboxTimeMinObserver = new LongMetricObserverBuilderAdapter[ActorMetricsMonitor.Labels]( + private lazy val mailboxTimeMinObserver = new GaugeBuilderAdapter[ActorMetricsMonitor.Labels]( meter - .longValueObserverBuilder(metricNames.mailboxTimeMin) + .gaugeBuilder(metricNames.mailboxTimeMin) + .ofLongs() .setDescription("Tracks the minimum time of an message in an Actor's mailbox") ) - private lazy val mailboxTimeMaxObserver = new LongMetricObserverBuilderAdapter[ActorMetricsMonitor.Labels]( + private lazy val mailboxTimeMaxObserver = new GaugeBuilderAdapter[ActorMetricsMonitor.Labels]( meter - .longValueObserverBuilder(metricNames.mailboxTimeMax) + .gaugeBuilder(metricNames.mailboxTimeMax) + .ofLongs() .setDescription("Tracks the maximum time of an message in an Actor's mailbox") ) - private lazy val mailboxTimeSumObserver = new LongMetricObserverBuilderAdapter[ActorMetricsMonitor.Labels]( + private lazy val mailboxTimeSumObserver = new GaugeBuilderAdapter[ActorMetricsMonitor.Labels]( meter - .longValueObserverBuilder(metricNames.mailboxTimeSum) + .gaugeBuilder(metricNames.mailboxTimeSum) + .ofLongs() .setDescription("Tracks the sum time of the messages in an Actor's mailbox") ) private lazy val stashSizeCounter = new LongSumObserverBuilderAdapter[ActorMetricsMonitor.Labels]( meter - .longSumObserverBuilder(metricNames.stashedMessages) + .counterBuilder(metricNames.stashedMessages) .setDescription("Tracks stash operations on actors") ) private lazy val receivedMessagesSumObserver = new LongSumObserverBuilderAdapter[ActorMetricsMonitor.Labels]( meter - .longSumObserverBuilder(metricNames.receivedMessages) + .counterBuilder(metricNames.receivedMessages) .setDescription("Tracks the sum of received messages in an Actor") ) private lazy val processedMessagesSumObserver = new LongSumObserverBuilderAdapter[ActorMetricsMonitor.Labels]( meter - .longSumObserverBuilder(metricNames.processedMessages) + .counterBuilder(metricNames.processedMessages) .setDescription("Tracks the sum of processed messages in an Actor") ) private lazy val failedMessagesSumObserver = new LongSumObserverBuilderAdapter[ActorMetricsMonitor.Labels]( meter - .longSumObserverBuilder(metricNames.failedMessages) + .counterBuilder(metricNames.failedMessages) .setDescription("Tracks the sum of failed messages in an Actor") ) - private lazy val processingTimeCountObserver = new LongMetricObserverBuilderAdapter[ActorMetricsMonitor.Labels]( + private lazy val processingTimeCountObserver = new GaugeBuilderAdapter[ActorMetricsMonitor.Labels]( meter - .longValueObserverBuilder(metricNames.processingTimeCount) + .gaugeBuilder(metricNames.processingTimeCount) + .ofLongs() .setDescription("Tracks the amount of processed messages") ) - private lazy val processingTimeMinObserver = new LongMetricObserverBuilderAdapter[ActorMetricsMonitor.Labels]( + private lazy val processingTimeMinObserver = new GaugeBuilderAdapter[ActorMetricsMonitor.Labels]( meter - .longValueObserverBuilder(metricNames.processingTimeMin) + .gaugeBuilder(metricNames.processingTimeMin) + .ofLongs() .setDescription("Tracks the miminum processing time of an message in an Actor's receive handler") ) - private lazy val processingTimeMaxObserver = new LongMetricObserverBuilderAdapter[ActorMetricsMonitor.Labels]( + private lazy val processingTimeMaxObserver = new GaugeBuilderAdapter[ActorMetricsMonitor.Labels]( meter - .longValueObserverBuilder(metricNames.processingTimeMax) + .gaugeBuilder(metricNames.processingTimeMax) + .ofLongs() .setDescription("Tracks the maximum processing time of an message in an Actor's receive handler") ) - private lazy val processingTimeSumObserver = new LongMetricObserverBuilderAdapter[ActorMetricsMonitor.Labels]( + private lazy val processingTimeSumObserver = new GaugeBuilderAdapter[ActorMetricsMonitor.Labels]( meter - .longValueObserverBuilder(metricNames.processingTimeSum) + .gaugeBuilder(metricNames.processingTimeSum) + .ofLongs() .setDescription("Tracks the sum processing time of an message in an Actor's receive handler") ) private lazy val sentMessagesObserver = new LongSumObserverBuilderAdapter[ActorMetricsMonitor.Labels]( meter - .longSumObserverBuilder(metricNames.sentMessages) + .counterBuilder(metricNames.sentMessages) .setDescription("Tracks the sum of sent messages in an Actor") ) private lazy val droppedMessagesObserver = new LongSumObserverBuilderAdapter[ActorMetricsMonitor.Labels]( meter - .longSumObserverBuilder(metricNames.droppedMessages) + .counterBuilder(metricNames.droppedMessages) .setDescription("Tracks the sum of dropped messages in an Actor") ) diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryActorSystemMonitor.scala b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryActorSystemMonitor.scala index be35235c7..2f0329543 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryActorSystemMonitor.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryActorSystemMonitor.scala @@ -49,12 +49,12 @@ final class OpenTelemetryActorSystemMonitor( ) extends ActorSystemMonitor { private lazy val createdActorsCounter = meter - .longCounterBuilder(metricNames.createdActors) + .counterBuilder(metricNames.createdActors) .setDescription("Amount of actors created measured from Actor System start") .build() private lazy val terminatedActorsCounter = meter - .longCounterBuilder(metricNames.terminatedActors) + .counterBuilder(metricNames.terminatedActors) .setDescription("Amount of actors terminated measured from Actor System start") .build() diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryClusterMetricsMonitor.scala b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryClusterMetricsMonitor.scala index 7361d28a7..294bec1cd 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryClusterMetricsMonitor.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryClusterMetricsMonitor.scala @@ -1,8 +1,8 @@ package io.scalac.mesmer.extension.upstream import com.typesafe.config.Config +import io.opentelemetry.api.common.Attributes import io.opentelemetry.api.metrics.Meter -import io.opentelemetry.api.metrics.common.Labels import io.scalac.mesmer.core.config.MesmerConfiguration import io.scalac.mesmer.core.module.AkkaClusterModule @@ -91,42 +91,46 @@ final class OpenTelemetryClusterMetricsMonitor( metricNames: MetricNames ) extends ClusterMetricsMonitor { - private lazy val shardsPerRegionRecorder = new LongMetricObserverBuilderAdapter[ClusterMetricsMonitor.Labels]( + private lazy val shardsPerRegionRecorder = new GaugeBuilderAdapter[ClusterMetricsMonitor.Labels]( meter - .longValueObserverBuilder(metricNames.shardPerEntity) + .gaugeBuilder(metricNames.shardPerEntity) + .ofLongs() .setDescription("Amount of shards in region") ) - private lazy val entityPerRegionRecorder = new LongMetricObserverBuilderAdapter[ClusterMetricsMonitor.Labels]( + private lazy val entityPerRegionRecorder = new GaugeBuilderAdapter[ClusterMetricsMonitor.Labels]( meter - .longValueObserverBuilder(metricNames.entityPerRegion) + .gaugeBuilder(metricNames.entityPerRegion) + .ofLongs() .setDescription("Amount of entities in region") ) private lazy val reachableNodeCounter = meter - .longUpDownCounterBuilder(metricNames.reachableNodes) + .upDownCounterBuilder(metricNames.reachableNodes) .setDescription("Amount of reachable nodes") .build() private lazy val unreachableNodeCounter = meter - .longUpDownCounterBuilder(metricNames.unreachableNodes) + .upDownCounterBuilder(metricNames.unreachableNodes) .setDescription("Amount of unreachable nodes") .build() - private lazy val shardRegionsOnNodeRecorder = new LongMetricObserverBuilderAdapter[ClusterMetricsMonitor.Labels]( + private lazy val shardRegionsOnNodeRecorder = new GaugeBuilderAdapter[ClusterMetricsMonitor.Labels]( meter - .longValueObserverBuilder(metricNames.shardRegionsOnNode) + .gaugeBuilder(metricNames.shardRegionsOnNode) + .ofLongs() .setDescription("Amount of shard regions on node") ) - private lazy val entitiesOnNodeObserver = new LongMetricObserverBuilderAdapter[ClusterMetricsMonitor.Labels]( + private lazy val entitiesOnNodeObserver = new GaugeBuilderAdapter[ClusterMetricsMonitor.Labels]( meter - .longValueObserverBuilder(metricNames.entitiesOnNode) + .gaugeBuilder(metricNames.entitiesOnNode) + .ofLongs() .setDescription("Amount of entities on node") ) private lazy val nodeDownCounter = meter - .longCounterBuilder(metricNames.nodeDown) + .counterBuilder(metricNames.nodeDown) .setDescription("Counter for node down events") .build() @@ -138,7 +142,7 @@ final class OpenTelemetryClusterMetricsMonitor( with RegisterRoot with SynchronousInstrumentFactory { - protected val otLabels: Labels = LabelsFactory.of(labels.serialize) + protected val otLabels: Attributes = LabelsFactory.of(labels.serialize) lazy val shardPerRegions: MetricObserver[Long, ClusterMetricsMonitor.Labels] = { if (moduleConfig.shardPerRegions) shardsPerRegionRecorder.createObserver(this) else MetricObserver.noop diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryHttpConnectionMetricsMonitor.scala b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryHttpConnectionMetricsMonitor.scala index d08b5fe45..7639157ff 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryHttpConnectionMetricsMonitor.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryHttpConnectionMetricsMonitor.scala @@ -1,8 +1,8 @@ package io.scalac.mesmer.extension.upstream import com.typesafe.config.Config +import io.opentelemetry.api.common.Attributes import io.opentelemetry.api.metrics.Meter -import io.opentelemetry.api.metrics.common import io.scalac.mesmer.core.config.MesmerConfiguration import io.scalac.mesmer.core.module.AkkaHttpModule @@ -49,7 +49,7 @@ final class OpenTelemetryHttpConnectionMetricsMonitor( import HttpConnectionMetricsMonitor._ private lazy val connectionTotalCounter = meter - .longUpDownCounterBuilder(metricNames.connectionTotal) + .upDownCounterBuilder(metricNames.connectionTotal) .setDescription("Amount of connections") .build() @@ -61,10 +61,12 @@ final class OpenTelemetryHttpConnectionMetricsMonitor( with SynchronousInstrumentFactory with RegisterRoot { - protected lazy val otLabels: common.Labels = LabelsFactory.of(labels.serialize) + protected lazy val otLabels: Attributes = LabelsFactory.of(labels.serialize) lazy val connections: UpDownCounter[Long] with Instrument[Long] = - if (moduleConfig.connections) upDownCounter(connectionTotalCounter, otLabels).register(this) - else noopUpDownCounter + if (moduleConfig.connections) + upDownCounter(connectionTotalCounter, otLabels).register(this) + else + noopUpDownCounter } } diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryHttpMetricsMonitor.scala b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryHttpMetricsMonitor.scala index f04edd76a..b14ba238d 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryHttpMetricsMonitor.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryHttpMetricsMonitor.scala @@ -1,8 +1,8 @@ package io.scalac.mesmer.extension.upstream import com.typesafe.config.Config +import io.opentelemetry.api.common.Attributes import io.opentelemetry.api.metrics.Meter -import io.opentelemetry.api.metrics.common import io.scalac.mesmer.core.config.MesmerConfiguration import io.scalac.mesmer.core.module.AkkaHttpModule @@ -58,12 +58,13 @@ final class OpenTelemetryHttpMetricsMonitor( import HttpMetricsMonitor._ private lazy val requestTimeRequest = meter - .longValueRecorderBuilder(metricNames.requestDuration) + .histogramBuilder(metricNames.requestDuration) + .ofLongs() .setDescription("Amount of ms request took to complete") .build() private lazy val requestTotalCounter = meter - .longCounterBuilder(metricNames.requestTotal) + .counterBuilder(metricNames.requestTotal) .setDescription("Amount of requests") .build() @@ -75,7 +76,7 @@ final class OpenTelemetryHttpMetricsMonitor( with SynchronousInstrumentFactory with RegisterRoot { - protected val otLabels: common.Labels = LabelsFactory.of(labels.serialize) + protected val otLabels: Attributes = LabelsFactory.of(labels.serialize) lazy val requestTime: MetricRecorder[Long] with Instrument[Long] = if (moduleConfig.requestTime) metricRecorder(requestTimeRequest, otLabels).register(this) diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryPersistenceMetricsMonitor.scala b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryPersistenceMetricsMonitor.scala index d85d63075..f6af20f86 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryPersistenceMetricsMonitor.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryPersistenceMetricsMonitor.scala @@ -73,27 +73,29 @@ final class OpenTelemetryPersistenceMetricsMonitor( import PersistenceMetricsMonitor._ private lazy val recoveryTimeRecorder = meter - .longValueRecorderBuilder(metricNames.recoveryTime) + .histogramBuilder(metricNames.recoveryTime) + .ofLongs() .setDescription("Amount of time needed for entity recovery") .build() private lazy val recoveryTotalCounter = meter - .longCounterBuilder(metricNames.recoveryTotal) + .counterBuilder(metricNames.recoveryTotal) .setDescription("Amount of recoveries") .build() private lazy val persistentEventRecorder = meter - .longValueRecorderBuilder(metricNames.persistentEvent) + .histogramBuilder(metricNames.persistentEvent) + .ofLongs() .setDescription("Amount of time needed for entity to persist events") .build() private lazy val persistentEventTotalCounter = meter - .longCounterBuilder(metricNames.persistentEventTotal) + .counterBuilder(metricNames.persistentEventTotal) .setDescription("Amount of persist events") .build() private lazy val snapshotCounter = meter - .longCounterBuilder(metricNames.snapshotTotal) + .counterBuilder(metricNames.snapshotTotal) .setDescription("Amount of snapshots created") .build() diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryStreamMetricsMonitor.scala b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryStreamMetricsMonitor.scala index d1fdfd798..bb41489bd 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryStreamMetricsMonitor.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryStreamMetricsMonitor.scala @@ -57,18 +57,20 @@ final class OpenTelemetryStreamMetricsMonitor( import StreamMetricsMonitor._ private lazy val runningStreamsTotalRecorder = meter - .longValueRecorderBuilder(metricNames.runningStreams) + .histogramBuilder(metricNames.runningStreams) + .ofLongs() .setDescription("Amount of running streams on a system") .build() private lazy val streamActorsTotalRecorder = meter - .longValueRecorderBuilder(metricNames.streamActors) + .histogramBuilder(metricNames.streamActors) + .ofLongs() .setDescription("Amount of actors running streams on a system") .build() private lazy val streamProcessedMessagesBuilder = new LongSumObserverBuilderAdapter[Labels]( meter - .longSumObserverBuilder(metricNames.streamProcessed) + .counterBuilder(metricNames.streamProcessed) .setDescription("Amount of messages processed by whole stream") ) diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryStreamOperatorMetricsMonitor.scala b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryStreamOperatorMetricsMonitor.scala index 34358b929..938550882 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryStreamOperatorMetricsMonitor.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryStreamOperatorMetricsMonitor.scala @@ -65,19 +65,20 @@ final class OpenTelemetryStreamOperatorMetricsMonitor( private lazy val processedMessageAdapter = new LongSumObserverBuilderAdapter[Labels]( meter - .longSumObserverBuilder(metricNames.operatorProcessed) + .counterBuilder(metricNames.operatorProcessed) .setDescription("Amount of messages process by operator") ) - private lazy val operatorsAdapter = new LongMetricObserverBuilderAdapter[Labels]( + private lazy val operatorsAdapter = new GaugeBuilderAdapter[Labels]( meter - .longValueObserverBuilder(metricNames.runningOperators) + .gaugeBuilder(metricNames.runningOperators) + .ofLongs() .setDescription("Amount of operators in a system") ) private lazy val demandAdapter = new LongSumObserverBuilderAdapter[Labels]( meter - .longSumObserverBuilder(metricNames.demand) + .counterBuilder(metricNames.demand) .setDescription("Amount of messages demanded by operator") ) diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/opentelemetry/Synchronized.scala b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/opentelemetry/Synchronized.scala index 0d089d273..9d8f60ba1 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/opentelemetry/Synchronized.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/opentelemetry/Synchronized.scala @@ -1,10 +1,7 @@ package io.scalac.mesmer.extension.upstream.opentelemetry -import io.opentelemetry.api.metrics.BatchRecorder +import io.opentelemetry.api.common.Attributes import io.opentelemetry.api.metrics.Meter -import io.opentelemetry.api.metrics.common.Labels - -import scala.collection.mutable.ListBuffer import io.scalac.mesmer.extension.metric.{ Synchronized => BaseSynchronized } @@ -13,35 +10,24 @@ abstract class Synchronized(private val meter: Meter) extends BaseSynchronized { type Instrument[X] = WrappedSynchronousInstrument[X] - protected val otLabels: Labels + protected val otLabels: Attributes def atomically[A, B](first: Instrument[A], second: Instrument[B]): (A, B) => Unit = { (a, b) => - meter - .newBatchRecorder(extractLabels(otLabels): _*) - .putValue(first, a) - .putValue(second, b) - .record() + first.putValue(a) + second.putValue(b) } - private def extractLabels(labels: Labels): List[String] = { - val buffer: ListBuffer[String] = ListBuffer.empty - labels.forEach { case (key, value) => - buffer ++= List(key, value) - } - buffer.toList - } } object Synchronized { - private[opentelemetry] implicit class RecorderExt(private val recorder: BatchRecorder) extends AnyVal { - def putValue[L](instrument: WrappedSynchronousInstrument[L], value: L): BatchRecorder = { + private[opentelemetry] implicit class RecorderExt(private val instrument: WrappedSynchronousInstrument[_]) + extends AnyVal { + def putValue(value: Any): Unit = instrument match { - case WrappedLongValueRecorder(underlying, _) => recorder.put(underlying, value) - case WrappedCounter(underlying, _) => recorder.put(underlying, value) - case WrappedUpDownCounter(underlying, _) => recorder.put(underlying, value) - case _: WrappedNoOp => // skip any noop monitor + case rec @ WrappedLongValueRecorder(underlying, _) => rec.setValue(value.asInstanceOf[Long]) + case counter @ WrappedCounter(underlying, _) => counter.incValue(value.asInstanceOf[Long]) + case counter @ WrappedUpDownCounter(underlying, _) => counter.incValue(value.asInstanceOf[Long]) + case _: WrappedNoOp => // skip any noop monitor } - recorder - } } } diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/opentelemetry/WrappedAsynchronousInstrument.scala b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/opentelemetry/WrappedAsynchronousInstrument.scala index ee3fde838..352c718ba 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/opentelemetry/WrappedAsynchronousInstrument.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/opentelemetry/WrappedAsynchronousInstrument.scala @@ -3,36 +3,45 @@ package io.scalac.mesmer.extension.upstream.opentelemetry import java.util.concurrent.CopyOnWriteArrayList import java.util.concurrent.atomic.AtomicBoolean -import io.opentelemetry.api.metrics.AsynchronousInstrument -import io.opentelemetry.api.metrics.AsynchronousInstrument.LongResult +import io.opentelemetry.api.common.Attributes import io.opentelemetry.api.metrics._ -import io.opentelemetry.api.metrics.common.Labels import scala.jdk.CollectionConverters._ +import scala.jdk.FunctionConverters._ import io.scalac.mesmer.core.LabelSerializable import io.scalac.mesmer.extension.metric.MetricObserver import io.scalac.mesmer.extension.upstream.LabelsFactory private object Defs { - type WrappedResult[T] = (T, Labels) => Unit + type WrappedResult[T] = (T, Attributes) => Unit type ResultWrapper[R, T] = R => WrappedResult[T] - val longResultWrapper: ResultWrapper[LongResult, Long] = result => result.observe + val longResultWrapper: ResultWrapper[ObservableLongMeasurement, Long] = result => result.observe } import io.scalac.mesmer.extension.upstream.opentelemetry.Defs._ -final class LongMetricObserverBuilderAdapter[L <: LabelSerializable](builder: LongValueObserverBuilder) - extends MetricObserverBuilderAdapter[LongResult, Long, L](builder, longResultWrapper) - -final class LongUpDownSumObserverBuilderAdapter[L <: LabelSerializable](builder: LongUpDownSumObserverBuilder) - extends MetricObserverBuilderAdapter[LongResult, Long, L](builder, longResultWrapper) - -final class LongSumObserverBuilderAdapter[L <: LabelSerializable](builder: LongSumObserverBuilder) - extends MetricObserverBuilderAdapter[LongResult, Long, L](builder, longResultWrapper) - -sealed abstract class MetricObserverBuilderAdapter[R <: AsynchronousInstrument.LongResult, T, L <: LabelSerializable]( - builder: AsynchronousInstrumentBuilder[R], +final class GaugeBuilderAdapter[L <: LabelSerializable](builder: LongGaugeBuilder) + extends MetricObserverBuilderAdapter[ObservableLongMeasurement, Long, L]( + result => builder.buildWithCallback(result.asJava), + longResultWrapper + ) + +final class LongUpDownSumObserverBuilderAdapter[L <: LabelSerializable](builder: LongUpDownCounterBuilder) + extends MetricObserverBuilderAdapter[ObservableLongMeasurement, Long, L]( + result => builder.buildWithCallback(result.asJava), + longResultWrapper + ) + +final class LongSumObserverBuilderAdapter[L <: LabelSerializable](builder: LongCounterBuilder) + extends MetricObserverBuilderAdapter[ObservableLongMeasurement, Long, L]( + result => builder.buildWithCallback(result.asJava), + longResultWrapper + ) + +sealed abstract class MetricObserverBuilderAdapter[R <: ObservableMeasurement, T, L <: LabelSerializable]( +// builder: AsynchronousInstrumentBuilder[R], + register: (R => Unit) => Unit, wrapper: ResultWrapper[R, T] ) { @@ -53,9 +62,7 @@ sealed abstract class MetricObserverBuilderAdapter[R <: AsynchronousInstrument.L private def registerUpdater(observer: => WrappedMetricObserver[T, L]): () => Unit = () => { if (!instrumentStarted.get()) { if (instrumentStarted.compareAndSet(false, true)) { // no-lock way to ensure this is going to be called once - builder - .setUpdater(updateAll) - .build() + register(updateAll) } } observers += observer diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/opentelemetry/WrappedSynchronousInstrument.scala b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/opentelemetry/WrappedSynchronousInstrument.scala index 6b9cfc69d..e813bb3ae 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/opentelemetry/WrappedSynchronousInstrument.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/opentelemetry/WrappedSynchronousInstrument.scala @@ -1,36 +1,35 @@ package io.scalac.mesmer.extension.upstream.opentelemetry +import io.opentelemetry.api.common.Attributes import io.opentelemetry.api.metrics.LongCounter +import io.opentelemetry.api.metrics.LongHistogram import io.opentelemetry.api.metrics.LongUpDownCounter -import io.opentelemetry.api.metrics.LongValueRecorder -import io.opentelemetry.api.metrics.SynchronousInstrument -import io.opentelemetry.api.metrics.common.Labels import io.scalac.mesmer.extension.metric._ trait SynchronousInstrumentFactory { private[upstream] def metricRecorder( - underlying: LongValueRecorder, - labels: Labels + underlying: LongHistogram, + attrs: Attributes ): UnregisteredInstrument[WrappedLongValueRecorder] = { root => - val instrument = WrappedLongValueRecorder(underlying, labels) + val instrument = WrappedLongValueRecorder(underlying, attrs) root.registerUnbind(instrument) instrument } private[upstream] def counter( underlying: LongCounter, - labels: Labels + attributes: Attributes ): UnregisteredInstrument[WrappedCounter] = { root => - val instrument = WrappedCounter(underlying, labels) + val instrument = WrappedCounter(underlying, attributes) root.registerUnbind(instrument) instrument } private[upstream] def upDownCounter( underlying: LongUpDownCounter, - labels: Labels + labels: Attributes ): UnregisteredInstrument[WrappedUpDownCounter] = { root => val instrument = WrappedUpDownCounter(underlying, labels) root.registerUnbind(instrument) @@ -43,16 +42,9 @@ trait SynchronousInstrumentFactory { private[upstream] def noopUpDownCounter[T]: WrappedSynchronousInstrument[T] with UpDownCounter[T] = NoopUpDownCounter } -sealed trait WrappedSynchronousInstrument[-L] extends Unbind with WrappedInstrument { +sealed trait WrappedSynchronousInstrument[-L] extends Unbind with WrappedInstrument - private[extension] def underlying: SynchronousInstrument[_] -} - -sealed trait WrappedNoOp extends WrappedSynchronousInstrument[Any] { - final private[extension] def underlying: SynchronousInstrument[_] = throw new UnsupportedOperationException( - "Cannot get underlying instrument from noop" - ) -} +sealed trait WrappedNoOp extends WrappedSynchronousInstrument[Any] case object NoopLongValueRecorder extends WrappedNoOp with MetricRecorder[Any] { @@ -81,24 +73,24 @@ case object NoopUpDownCounter extends WrappedNoOp with UpDownCounter[Any] { override type Self = Nothing } -final case class WrappedLongValueRecorder private[opentelemetry] (underlying: LongValueRecorder, labels: Labels) +final case class WrappedLongValueRecorder private[opentelemetry] (underlying: LongHistogram, attrs: Attributes) extends WrappedSynchronousInstrument[Long] with MetricRecorder[Long] { type Self = WrappedLongValueRecorder - private[this] lazy val bound = underlying.bind(labels) + private[this] lazy val bound = underlying.bind(attrs) def setValue(value: Long): Unit = bound.record(value) def unbind(): Unit = bound.unbind() } -final case class WrappedUpDownCounter private[opentelemetry] (underlying: LongUpDownCounter, labels: Labels) +final case class WrappedUpDownCounter private[opentelemetry] (underlying: LongUpDownCounter, attrs: Attributes) extends WrappedSynchronousInstrument[Long] with UpDownCounter[Long] { type Self = WrappedUpDownCounter - private[this] lazy val bound = underlying.bind(labels) + private[this] lazy val bound = underlying.bind(attrs) def decValue(value: Long): Unit = bound.add(-value) @@ -107,12 +99,12 @@ final case class WrappedUpDownCounter private[opentelemetry] (underlying: LongUp def unbind(): Unit = bound.unbind() } -final case class WrappedCounter private[opentelemetry] (underlying: LongCounter, labels: Labels) +final case class WrappedCounter private[opentelemetry] (underlying: LongCounter, attrs: Attributes) extends WrappedSynchronousInstrument[Long] with Counter[Long] { type Self = WrappedCounter - private[this] lazy val bound = underlying.bind(labels) + private[this] lazy val bound = underlying.bind(attrs) def incValue(value: Long): Unit = bound.add(value) diff --git a/extension/src/test/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryActorMetricsMonitorTest.scala b/extension/src/test/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryActorMetricsMonitorTest.scala index d8532753e..b836e3423 100644 --- a/extension/src/test/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryActorMetricsMonitorTest.scala +++ b/extension/src/test/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryActorMetricsMonitorTest.scala @@ -80,7 +80,6 @@ class OpenTelemetryActorMetricsMonitorTest extends AnyFlatSpec with Matchers { ) val monitor = sut.bind() - MetricObserver.noop monitor.mailboxSize should be(a[MetricObserver.NoopMetricObserver.type]) monitor.mailboxTimeMin should be(a[MetricObserver.NoopMetricObserver.type]) diff --git a/extension/src/test/scala/io/scalac/mesmer/extension/util/OpenTelemetryNoopMeter.scala b/extension/src/test/scala/io/scalac/mesmer/extension/util/OpenTelemetryNoopMeter.scala index c04c4e446..6cb05486e 100644 --- a/extension/src/test/scala/io/scalac/mesmer/extension/util/OpenTelemetryNoopMeter.scala +++ b/extension/src/test/scala/io/scalac/mesmer/extension/util/OpenTelemetryNoopMeter.scala @@ -1,6 +1,8 @@ package io.opentelemetry.api.metrics +import io.opentelemetry.api.metrics.internal.NoopMeterProvider + object OpenTelemetryNoopMeter { - lazy val instance: Meter = DefaultMeter.getInstance() + lazy val instance: Meter = NoopMeterProvider.getInstance().meterBuilder("tests").build() } diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 669a1473a..f1e0ad8a6 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -1,6 +1,6 @@ import sbt._ -object Dependencies { +object Dependencies { val AkkaHttpVersion = "10.2.6" val AkkaManagementVersion = "1.1.1" @@ -8,11 +8,11 @@ object Dependencies { val CirceVersion = "0.14.1" val LogbackVersion = "1.2.6" val OpentelemetryVersion = "1.7.0" - val OpentelemetryMetricsVersion = "1.2.0-alpha" + val OpentelemetryMetricsVersion = "1.7.0-alpha" val PostgresVersion = "42.2.24" val ScalatestVersion = "3.2.10" val SlickVersion = "3.3.3" - + val akka = Seq( "com.typesafe.akka" %% "akka-http" % AkkaHttpVersion, "com.typesafe.akka" %% "akka-http-spray-json" % AkkaHttpVersion, @@ -62,19 +62,19 @@ object Dependencies { val reflection: String => Seq[ModuleID] = version => Seq("org.scala-lang" % "scala-reflect" % version) val exampleDependencies = Seq( - "io.circe" %% "circe-core" % CirceVersion, - "io.circe" %% "circe-generic" % CirceVersion, - "io.circe" %% "circe-parser" % CirceVersion, - "de.heikoseeberger" %% "akka-http-circe" % "1.38.2", - "org.postgresql" % "postgresql" % PostgresVersion, - "com.typesafe.slick" %% "slick" % SlickVersion, - "com.typesafe.slick" %% "slick-hikaricp" % SlickVersion, - "com.typesafe.akka" %% "akka-discovery" % AkkaVersion, - "com.lightbend.akka.management" %% "akka-management" % AkkaManagementVersion, - "com.lightbend.akka.management" %% "akka-management-cluster-http" % AkkaManagementVersion, - "com.lightbend.akka.management" %% "akka-management-cluster-bootstrap" % AkkaManagementVersion, - "com.lightbend.akka.discovery" %% "akka-discovery-kubernetes-api" % AkkaManagementVersion, - "io.opentelemetry" % "opentelemetry-exporter-otlp-metrics" % OpentelemetryMetricsVersion, - "io.grpc" % "grpc-netty-shaded" % "1.41.0" + "io.circe" %% "circe-core" % CirceVersion, + "io.circe" %% "circe-generic" % CirceVersion, + "io.circe" %% "circe-parser" % CirceVersion, + "de.heikoseeberger" %% "akka-http-circe" % "1.38.2", + "org.postgresql" % "postgresql" % PostgresVersion, + "com.typesafe.slick" %% "slick" % SlickVersion, + "com.typesafe.slick" %% "slick-hikaricp" % SlickVersion, + "com.typesafe.akka" %% "akka-discovery" % AkkaVersion, + "com.lightbend.akka.management" %% "akka-management" % AkkaManagementVersion, + "com.lightbend.akka.management" %% "akka-management-cluster-http" % AkkaManagementVersion, + "com.lightbend.akka.management" %% "akka-management-cluster-bootstrap" % AkkaManagementVersion, + "com.lightbend.akka.discovery" %% "akka-discovery-kubernetes-api" % AkkaManagementVersion, + "io.opentelemetry" % "opentelemetry-exporter-otlp-metrics" % OpentelemetryMetricsVersion, + "io.grpc" % "grpc-netty-shaded" % "1.41.0" ) } From e6fca873c99540cea140fd279735702cacc0b34f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Gajowy?= Date: Tue, 14 Dec 2021 15:41:24 +0100 Subject: [PATCH 2/3] Rename: Label -> Attribute The naming changes in opentelemetry - all the docs refers to "attributes" now. There's no sense to keep "Label" term in our project (it will be confusing). --- .../mesmer/agent/akka/actor/ProxiedQueue.java | 2 +- .../mesmer/core/AttributeSerializer.scala | 12 ++ .../mesmer/core/AttributesSerializable.scala | 7 + .../mesmer/core/LabelSerializable.scala | 7 - .../scalac/mesmer/core/LabelSerializer.scala | 12 -- .../io/scalac/mesmer/core/model/Tag.scala | 10 +- .../io/scalac/mesmer/core/model/package.scala | 29 ++-- .../extension/ActorEventsMonitorActor.scala | 14 +- .../extension/AkkaStreamMonitoring.scala | 26 ++-- .../extension/ClusterEventsMonitor.scala | 4 +- .../ClusterRegionsMonitorActor.scala | 14 +- .../ClusterSelfNodeEventsActor.scala | 4 +- .../mesmer/extension/HttpEventsActor.scala | 12 +- .../extension/PersistenceEventsActor.scala | 6 +- .../metric/ActorMetricsMonitor.scala | 10 +- .../extension/metric/ActorSystemMonitor.scala | 6 +- .../mesmer/extension/metric/Bindable.scala | 18 +-- .../extension/metric/CachingMonitor.scala | 16 +-- .../metric/ClusterMetricsMonitor.scala | 16 +-- .../metric/HttpConnectionMetricsMonitor.scala | 8 +- .../extension/metric/HttpMetricsMonitor.scala | 7 +- .../mesmer/extension/metric/Metric.scala | 2 +- .../metric/PersistenceMetricsMonitor.scala | 7 +- .../metric/StreamMetricsMonitor.scala | 14 +- .../metric/StreamOperatorMetricsMonitor.scala | 20 +-- .../mesmer/extension/metric/package.scala | 15 +- .../extension/service/ActorTreeService.scala | 4 +- ...{LabelNames.scala => AttributeNames.scala} | 2 +- ...sFactory.scala => AttributesFactory.scala} | 22 +-- .../OpenTelemetryActorMetricsMonitor.scala | 60 ++++---- .../OpenTelemetryActorSystemMonitor.scala | 12 +- .../OpenTelemetryClusterMetricsMonitor.scala | 29 ++-- ...elemetryHttpConnectionMetricsMonitor.scala | 10 +- .../OpenTelemetryHttpMetricsMonitor.scala | 12 +- ...enTelemetryPersistenceMetricsMonitor.scala | 16 +-- .../OpenTelemetryStreamMetricsMonitor.scala | 14 +- ...elemetryStreamOperatorMetricsMonitor.scala | 14 +- .../upstream/opentelemetry/Synchronized.scala | 2 +- .../WrappedAsynchronousInstrument.scala | 18 +-- .../WrappedSynchronousInstrument.scala | 20 +-- .../io/scalac/mesmer/extension/DownTest.scala | 8 +- .../mesmer/extension/ReachabilityTest.scala | 3 +- .../ActorEventsMonitorActorTest.scala | 74 +++++----- .../extension/AkkaStreamMonitoringTest.scala | 12 +- .../ClusterSelfNodeEventsActorTest.scala | 14 +- .../extension/HttpEventsActorTest.scala | 96 ++++++------- .../PersistenceEventsActorTest.scala | 130 +++++++++--------- .../extension/metric/CachingMonitorTest.scala | 65 ++++----- .../OpenTelemetryActorSystemMonitorTest.scala | 4 +- ...enTelemetryClusterMetricsMonitorTest.scala | 4 +- ...etryHttpConnectionMetricsMonitorTest.scala | 8 +- .../OpenTelemetryHttpMetricsMonitorTest.scala | 4 +- ...lemetryPersistenceMetricsMonitorTest.scala | 4 +- ...penTelemetryStreamMetricsMonitorTest.scala | 8 +- .../util/probe/ActorMonitorTestProbe.scala | 60 ++++---- .../util/probe/ActorSystemMonitorProbe.scala | 2 +- .../extension/util/probe/BoundTestProbe.scala | 4 +- .../util/probe/ClusterMonitorTestProbe.scala | 22 +-- .../HttpConnectionMetricsTestProbe.scala | 19 +-- .../util/probe/HttpMonitorTestProbe.scala | 19 +-- .../probe/PersistenceMonitorTestProbe.scala | 21 +-- .../StreamOperatorMonitorTestProbe.scala | 20 +-- 62 files changed, 577 insertions(+), 557 deletions(-) create mode 100644 core/src/main/scala/io/scalac/mesmer/core/AttributeSerializer.scala create mode 100644 core/src/main/scala/io/scalac/mesmer/core/AttributesSerializable.scala delete mode 100644 core/src/main/scala/io/scalac/mesmer/core/LabelSerializable.scala delete mode 100644 core/src/main/scala/io/scalac/mesmer/core/LabelSerializer.scala rename extension/src/main/scala/io/scalac/mesmer/extension/upstream/{LabelNames.scala => AttributeNames.scala} (84%) rename extension/src/main/scala/io/scalac/mesmer/extension/upstream/{LabelsFactory.scala => AttributesFactory.scala} (80%) diff --git a/agent/src/main/java/io/scalac/mesmer/agent/akka/actor/ProxiedQueue.java b/agent/src/main/java/io/scalac/mesmer/agent/akka/actor/ProxiedQueue.java index f3bcf65a3..7a34534e1 100644 --- a/agent/src/main/java/io/scalac/mesmer/agent/akka/actor/ProxiedQueue.java +++ b/agent/src/main/java/io/scalac/mesmer/agent/akka/actor/ProxiedQueue.java @@ -12,7 +12,7 @@ public class ProxiedQueue { @OnMethodExit public static void constructor( @FieldValue(value = queueFieldName, readOnly = false) BlockingQueue queue, - @This BlockingQueue self + @This BlockingQueue self ) { queue = new BoundedQueueProxy<>(self); } diff --git a/core/src/main/scala/io/scalac/mesmer/core/AttributeSerializer.scala b/core/src/main/scala/io/scalac/mesmer/core/AttributeSerializer.scala new file mode 100644 index 000000000..f2e269492 --- /dev/null +++ b/core/src/main/scala/io/scalac/mesmer/core/AttributeSerializer.scala @@ -0,0 +1,12 @@ +package io.scalac.mesmer.core + +import io.scalac.mesmer.core.model.RawAttributes + +trait AttributeSerializer[T] extends (T => RawAttributes) { + final def apply(value: T): RawAttributes = serialize(value) + def serialize(value: T): RawAttributes +} + +object AttributeSerializer { + implicit def fromAttributesSerializable[T <: AttributesSerializable]: AttributeSerializer[T] = _.serialize +} diff --git a/core/src/main/scala/io/scalac/mesmer/core/AttributesSerializable.scala b/core/src/main/scala/io/scalac/mesmer/core/AttributesSerializable.scala new file mode 100644 index 000000000..884ebf404 --- /dev/null +++ b/core/src/main/scala/io/scalac/mesmer/core/AttributesSerializable.scala @@ -0,0 +1,7 @@ +package io.scalac.mesmer.core + +import io.scalac.mesmer.core.model.RawAttributes + +trait AttributesSerializable { + def serialize: RawAttributes +} diff --git a/core/src/main/scala/io/scalac/mesmer/core/LabelSerializable.scala b/core/src/main/scala/io/scalac/mesmer/core/LabelSerializable.scala deleted file mode 100644 index b72094f86..000000000 --- a/core/src/main/scala/io/scalac/mesmer/core/LabelSerializable.scala +++ /dev/null @@ -1,7 +0,0 @@ -package io.scalac.mesmer.core - -import io.scalac.mesmer.core.model.RawLabels - -trait LabelSerializable { - def serialize: RawLabels -} diff --git a/core/src/main/scala/io/scalac/mesmer/core/LabelSerializer.scala b/core/src/main/scala/io/scalac/mesmer/core/LabelSerializer.scala deleted file mode 100644 index ac3fce227..000000000 --- a/core/src/main/scala/io/scalac/mesmer/core/LabelSerializer.scala +++ /dev/null @@ -1,12 +0,0 @@ -package io.scalac.mesmer.core - -import io.scalac.mesmer.core.model.RawLabels - -trait LabelSerializer[T] extends (T => RawLabels) { - final def apply(value: T): RawLabels = serialize(value) - def serialize(value: T): RawLabels -} - -object LabelSerializer { - implicit def fromLabelSerializable[T <: LabelSerializable]: LabelSerializer[T] = _.serialize -} diff --git a/core/src/main/scala/io/scalac/mesmer/core/model/Tag.scala b/core/src/main/scala/io/scalac/mesmer/core/model/Tag.scala index 17873fa61..4464444ac 100644 --- a/core/src/main/scala/io/scalac/mesmer/core/model/Tag.scala +++ b/core/src/main/scala/io/scalac/mesmer/core/model/Tag.scala @@ -1,13 +1,13 @@ package io.scalac.mesmer.core.model -import io.scalac.mesmer.core.model.Tag.StreamName.StreamNameLabel +import io.scalac.mesmer.core.model.Tag.StreamName.StreamNameAttributeKey sealed trait Tag extends Any { def serialize: Seq[(String, String)] override def toString: String = - this.serialize.map { case (label, value) => - s"$label -> $value" + this.serialize.map { case (attributeKey, attributeValue) => + s"$attributeKey -> $attributeValue" }.mkString("[", ", ", "]") } @@ -75,7 +75,7 @@ object Tag { sealed trait StreamName extends Any with Tag { def name: String - def serialize: Seq[(String, String)] = Seq(StreamNameLabel -> name) + def serialize: Seq[(String, String)] = Seq(StreamNameAttributeKey -> name) } object StreamName { @@ -84,7 +84,7 @@ object Tag { def apply(matName: StreamName, terminalStage: StageName): StreamName = TerminalOperatorStreamName(matName, terminalStage) - private final val StreamNameLabel = "stream_name" + private final val StreamNameAttributeKey = "stream_name" final class StreamNameImpl(val name: String) extends AnyVal with StreamName diff --git a/core/src/main/scala/io/scalac/mesmer/core/model/package.scala b/core/src/main/scala/io/scalac/mesmer/core/model/package.scala index ee229aa41..22835e186 100644 --- a/core/src/main/scala/io/scalac/mesmer/core/model/package.scala +++ b/core/src/main/scala/io/scalac/mesmer/core/model/package.scala @@ -37,19 +37,21 @@ package object model { type PersistenceId = String @@ PersistenceIdTag type ActorPath = String @@ ActorPathTag type ActorKey = ActorPath - type RawLabels = Seq[(String, String)] - - implicit val nodeLabelSerializer: LabelSerializer[Node] = node => Seq("node" -> node.unwrap) - implicit val interfaceLabelSerializer: LabelSerializer[Interface] = interface => Seq("interface" -> interface.unwrap) - implicit val portLabelSerializer: LabelSerializer[Port] = port => Seq("port" -> port.unwrap.toString) - implicit val regionLabelSerializer: LabelSerializer[Region] = region => Seq("region" -> region.unwrap) - implicit val pathLabelSerializer: LabelSerializer[Path] = path => Seq("path" -> path.unwrap) - implicit val statusLabelSerializer: LabelSerializer[Status] = status => + type RawAttributes = Seq[(String, String)] + + implicit val nodeAttributeSerializer: AttributeSerializer[Node] = node => Seq("node" -> node.unwrap) + implicit val interfaceAttributeSerializer: AttributeSerializer[Interface] = interface => + Seq("interface" -> interface.unwrap) + implicit val portAttributeSerializer: AttributeSerializer[Port] = port => Seq("port" -> port.unwrap.toString) + implicit val regionAttributeSerializer: AttributeSerializer[Region] = region => Seq("region" -> region.unwrap) + implicit val pathAttributeSerializer: AttributeSerializer[Path] = path => Seq("path" -> path.unwrap) + implicit val statusAttributeSerializer: AttributeSerializer[Status] = status => Seq("status" -> status.unwrap, "status_group" -> s"${status.charAt(0)}xx") - implicit val methodLabelSerializer: LabelSerializer[Method] = method => Seq("method" -> method.unwrap) - implicit val actorPathLabelSerializer: LabelSerializer[ActorPath] = actorPath => Seq("actor_path" -> actorPath.unwrap) - implicit val persistenceIdLabelSerializer: LabelSerializer[PersistenceId] = persistenceId => + implicit val methodAttributeSerializer: AttributeSerializer[Method] = method => Seq("method" -> method.unwrap) + implicit val actorPathAttributeSerializer: AttributeSerializer[ActorPath] = actorPath => + Seq("actor_path" -> actorPath.unwrap) + implicit val persistenceIdAttributeSerializer: AttributeSerializer[PersistenceId] = persistenceId => Seq("persistence_id" -> persistenceId.asInstanceOf[String]) /** @@ -78,11 +80,12 @@ package object model { } implicit class SerializationOps[T](private val tag: T) extends AnyVal { - def serialize(implicit ls: LabelSerializer[T]): RawLabels = ls.serialize(tag) + def serialize(implicit ls: AttributeSerializer[T]): RawAttributes = ls.serialize(tag) } implicit class OptionSerializationOps[T](private val optTag: Option[T]) extends AnyVal { - def serialize(implicit ls: LabelSerializer[T]): RawLabels = optTag.fold[RawLabels](Seq.empty)(ls.serialize) + def serialize(implicit ls: AttributeSerializer[T]): RawAttributes = + optTag.fold[RawAttributes](Seq.empty)(ls.serialize) } } diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/ActorEventsMonitorActor.scala b/extension/src/main/scala/io/scalac/mesmer/extension/ActorEventsMonitorActor.scala index c1067f1c2..a1ce4d3d1 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/ActorEventsMonitorActor.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/ActorEventsMonitorActor.scala @@ -29,7 +29,7 @@ import io.scalac.mesmer.extension.ActorEventsMonitorActor._ import io.scalac.mesmer.extension.actor.ActorMetrics import io.scalac.mesmer.extension.actor.MetricStorageFactory import io.scalac.mesmer.extension.metric.ActorMetricsMonitor -import io.scalac.mesmer.extension.metric.ActorMetricsMonitor.Labels +import io.scalac.mesmer.extension.metric.ActorMetricsMonitor.Attributes import io.scalac.mesmer.extension.metric.MetricObserver.Result import io.scalac.mesmer.extension.service.ActorTreeService import io.scalac.mesmer.extension.service.ActorTreeService.Command.GetActorTree @@ -140,13 +140,13 @@ private[extension] class ActorEventsMonitorActor private[extension] ( private[this] val boundMonitor = monitor.bind() - private[this] val treeSnapshot = new AtomicReference[Option[Vector[(Labels, ActorMetrics)]]](None) + private[this] val treeSnapshot = new AtomicReference[Option[Vector[(Attributes, ActorMetrics)]]](None) - private def updateMetric(extractor: ActorMetrics => Option[Long])(result: Result[Long, Labels]): Unit = { + private def updateMetric(extractor: ActorMetrics => Option[Long])(result: Result[Long, Attributes]): Unit = { val state = treeSnapshot.get() state - .foreach(_.foreach { case (labels, metrics) => - extractor(metrics).foreach(value => result.observe(value, labels)) + .foreach(_.foreach { case (attributes, metrics) => + extractor(metrics).foreach(value => result.observe(value, attributes)) }) } @@ -261,8 +261,8 @@ private[extension] class ActorEventsMonitorActor private[extension] ( val metrics = storage.iterable.map { case (key, metrics) => currentSnapshot .find(_._1.actorPath == key) // finds if metric already exists - .fold((Labels(key, node), metrics)) { case (labels, existingMetrics) => - (labels, existingMetrics.addTo(metrics)) + .fold((Attributes(key, node), metrics)) { case (attributes, existingMetrics) => + (attributes, existingMetrics.addTo(metrics)) } }.toVector diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/AkkaStreamMonitoring.scala b/extension/src/main/scala/io/scalac/mesmer/extension/AkkaStreamMonitoring.scala index f38c7f558..542a97be3 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/AkkaStreamMonitoring.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/AkkaStreamMonitoring.scala @@ -40,10 +40,10 @@ import io.scalac.mesmer.extension.config.BufferConfig import io.scalac.mesmer.extension.config.CachingConfig import io.scalac.mesmer.extension.metric.MetricObserver.Result import io.scalac.mesmer.extension.metric.StreamMetricsMonitor -import io.scalac.mesmer.extension.metric.StreamMetricsMonitor.EagerLabels -import io.scalac.mesmer.extension.metric.StreamMetricsMonitor.{ Labels => GlobalLabels } +import io.scalac.mesmer.extension.metric.StreamMetricsMonitor.EagerAttributes +import io.scalac.mesmer.extension.metric.StreamMetricsMonitor.{ Attributes => GlobalAttributes } import io.scalac.mesmer.extension.metric.StreamOperatorMetricsMonitor -import io.scalac.mesmer.extension.metric.StreamOperatorMetricsMonitor.Labels +import io.scalac.mesmer.extension.metric.StreamOperatorMetricsMonitor.Attributes import io.scalac.mesmer.extension.service.ActorTreeService import io.scalac.mesmer.extension.service.ActorTreeService.Command.GetActors import io.scalac.mesmer.extension.service.actorTreeServiceKey @@ -242,7 +242,7 @@ final class AkkaStreamMonitoring( private val bufferConfig = BufferConfig.fromConfig(context.system.settings.config, AkkaStreamModule) private val indexCache = ConnectionsIndexCache.bounded(cachingConfig.maxEntries) private val operationsBoundMonitor = streamOperatorMonitor.bind() - private val boundStreamMonitor = streamMonitor.bind(EagerLabels(node)) + private val boundStreamMonitor = streamMonitor.bind(EagerAttributes(node)) import context._ @@ -265,8 +265,8 @@ final class AkkaStreamMonitoring( val streams = globalProcessedSnapshot.get() streams.foreach { statsSeq => for (stats <- statsSeq) { - val labels = GlobalLabels(node, stats.streamName) - result.observe(stats.processesMessages, labels) + val attributes = GlobalAttributes(node, stats.streamName) + result.observe(stats.processesMessages, attributes) } } } @@ -470,26 +470,26 @@ final class AkkaStreamMonitoring( localDemandSnapshot.clear() } - private def observeSnapshot(result: Result[Long, Labels], snapshot: Option[Seq[SnapshotEntry]]): Unit = + private def observeSnapshot(result: Result[Long, Attributes], snapshot: Option[Seq[SnapshotEntry]]): Unit = snapshot.foreach(_.foreach { case SnapshotEntry(stageInfo, Some(StageData(value, connectedWith))) => - val labels = - Labels( + val attributes = + Attributes( stageInfo.stageName, stageInfo.subStreamName.streamName, stageInfo.terminal, node, Some(connectedWith) ) - result.observe(value, labels) + result.observe(value, attributes) case _ => // ignore metrics without data }) - private def observeOperators(result: Result[Long, Labels], snapshot: Option[Seq[SnapshotEntry]]): Unit = + private def observeOperators(result: Result[Long, Attributes], snapshot: Option[Seq[SnapshotEntry]]): Unit = snapshot.foreach(_.groupBy(_.stage.subStreamName.streamName).foreach { case (streamName, snapshots) => snapshots.groupBy(_.stage.stageName.nameOnly).foreach { case (stageName, elems) => - val labels = Labels(stageName, streamName, terminal = false, node, None) - result.observe(elems.size, labels) + val attributes = Attributes(stageName, streamName, terminal = false, node, None) + result.observe(elems.size, attributes) } }) diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/ClusterEventsMonitor.scala b/extension/src/main/scala/io/scalac/mesmer/extension/ClusterEventsMonitor.scala index 82b4e3193..4ea752d8c 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/ClusterEventsMonitor.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/ClusterEventsMonitor.scala @@ -9,7 +9,7 @@ import akka.cluster.typed.Subscribe import io.scalac.mesmer.core.model._ import io.scalac.mesmer.extension.ClusterEventsMonitor.Command.MemberEventWrapper import io.scalac.mesmer.extension.metric.ClusterMetricsMonitor -import io.scalac.mesmer.extension.metric.ClusterMetricsMonitor.Labels +import io.scalac.mesmer.extension.metric.ClusterMetricsMonitor.Attributes object ClusterEventsMonitor extends ClusterMonitorActor { @@ -29,7 +29,7 @@ object ClusterEventsMonitor extends ClusterMonitorActor { classOf[MemberEvent] ) - val boundMonitor = clusterMonitor.bind(Labels(selfMember.uniqueAddress.toNode)) + val boundMonitor = clusterMonitor.bind(Attributes(selfMember.uniqueAddress.toNode)) boundMonitor.nodeDown.incValue(0L) diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/ClusterRegionsMonitorActor.scala b/extension/src/main/scala/io/scalac/mesmer/extension/ClusterRegionsMonitorActor.scala index 3401344df..d6ba55158 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/ClusterRegionsMonitorActor.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/ClusterRegionsMonitorActor.scala @@ -22,7 +22,7 @@ import io.scalac.mesmer.core.config.ConfigurationUtils._ import io.scalac.mesmer.core.model._ import io.scalac.mesmer.core.util.CachedQueryResult import io.scalac.mesmer.extension.metric.ClusterMetricsMonitor -import io.scalac.mesmer.extension.metric.ClusterMetricsMonitor.Labels +import io.scalac.mesmer.extension.metric.ClusterMetricsMonitor.Attributes class ClusterRegionsMonitorActor object ClusterRegionsMonitorActor extends ClusterMonitorActor { @@ -41,8 +41,8 @@ object ClusterRegionsMonitorActor extends ClusterMonitorActor { import system.executionContext val node = selfMember.uniqueAddress.toNode - val labels = Labels(node) - val boundMonitor = monitor.bind(labels) + val attributes = Attributes(node) + val boundMonitor = monitor.bind(attributes) val regions = new Regions( system, @@ -52,7 +52,7 @@ object ClusterRegionsMonitorActor extends ClusterMonitorActor { .setUpdater(result => entry.get.foreach { regionStats => val entities = regionStats.values.sum - result.observe(entities, Labels(node, Some(region))) + result.observe(entities, Attributes(node, Some(region))) logger.trace("Recorded amount of entities per region {}", entities) } ) @@ -61,7 +61,7 @@ object ClusterRegionsMonitorActor extends ClusterMonitorActor { .setUpdater(result => entry.get.foreach { regionStats => val shards = regionStats.size - result.observe(shards, Labels(node, Some(region))) + result.observe(shards, Attributes(node, Some(region))) logger.trace("Recorded amount of shards per region {}", shards) } ) @@ -71,13 +71,13 @@ object ClusterRegionsMonitorActor extends ClusterMonitorActor { boundMonitor.entitiesOnNode.setUpdater { result => regions.regionStats.map { regionsStats => val entities = regionsStats.view.values.flatMap(_.values).sum - result.observe(entities, labels) + result.observe(entities, attributes) logger.trace("Recorded amount of entities on node {}", entities) } } boundMonitor.shardRegionsOnNode.setUpdater { result => - result.observe(regions.size, labels) + result.observe(regions.size, attributes) logger.trace("Recorded amount of regions on node {}", regions) } diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/ClusterSelfNodeEventsActor.scala b/extension/src/main/scala/io/scalac/mesmer/extension/ClusterSelfNodeEventsActor.scala index abbd610ed..a49b00cdf 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/ClusterSelfNodeEventsActor.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/ClusterSelfNodeEventsActor.scala @@ -13,7 +13,7 @@ import akka.cluster.typed.Subscribe import io.scalac.mesmer.core.model.AkkaNodeOps import io.scalac.mesmer.extension.metric.ClusterMetricsMonitor -import io.scalac.mesmer.extension.metric.ClusterMetricsMonitor.Labels +import io.scalac.mesmer.extension.metric.ClusterMetricsMonitor.Attributes class ClusterSelfNodeEventsActor object ClusterSelfNodeEventsActor extends ClusterMonitorActor { @@ -37,7 +37,7 @@ object ClusterSelfNodeEventsActor extends ClusterMonitorActor { import Command._ - val monitor = clusterMetricsMonitor.bind(Labels(selfMember.uniqueAddress.toNode)) + val monitor = clusterMetricsMonitor.bind(Attributes(selfMember.uniqueAddress.toNode)) val cluster = Cluster(system) // bootstrap messages diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/HttpEventsActor.scala b/extension/src/main/scala/io/scalac/mesmer/extension/HttpEventsActor.scala index 292168b2e..99dee4394 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/HttpEventsActor.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/HttpEventsActor.scala @@ -42,11 +42,11 @@ object HttpEventsActor { Receptionist(ctx.system).ref ! Register(httpServiceKey, ctx.messageAdapter(HttpEventWrapper.apply)) - def createConnectionLabels(connectionEvent: ConnectionEvent): HttpConnectionMetricsMonitor.Labels = - HttpConnectionMetricsMonitor.Labels(node, connectionEvent.interface, connectionEvent.port) + def createConnectionAttributes(connectionEvent: ConnectionEvent): HttpConnectionMetricsMonitor.Attributes = + HttpConnectionMetricsMonitor.Attributes(node, connectionEvent.interface, connectionEvent.port) - def createRequestLabels(path: Path, method: Method, status: Status): HttpMetricsMonitor.Labels = - HttpMetricsMonitor.Labels(node, pathService.template(path), method, status) + def createRequestAttributes(path: Path, method: Method, status: Status): HttpMetricsMonitor.Attributes = + HttpMetricsMonitor.Attributes(node, pathService.template(path), method, status) def monitorHttp( requestStorage: RequestStorage @@ -55,7 +55,7 @@ object HttpEventsActor { .receiveMessagePartial[Event] { case HttpEventWrapper(connectionEvent: ConnectionEvent) => - val counter = httpConnectionMetricMonitor.bind(createConnectionLabels(connectionEvent)).connections + val counter = httpConnectionMetricMonitor.bind(createConnectionAttributes(connectionEvent)).connections connectionEvent match { case _: ConnectionStarted => counter.incValue(1L) case _: ConnectionCompleted => counter.decValue(1L) @@ -73,7 +73,7 @@ object HttpEventsActor { Behaviors.same[Event] } { case (storage, started) => val requestDuration = started.timestamp.interval(timestamp) - val monitorBoundary = createRequestLabels(started.path, started.method, status) + val monitorBoundary = createRequestAttributes(started.path, started.method, status) val monitor = httpMetricMonitor.bind(monitorBoundary) monitor.requestTime.setValue(requestDuration.toMillis) diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/PersistenceEventsActor.scala b/extension/src/main/scala/io/scalac/mesmer/extension/PersistenceEventsActor.scala index 42cfa20ec..46d3d6778 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/PersistenceEventsActor.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/PersistenceEventsActor.scala @@ -10,7 +10,7 @@ import io.scalac.mesmer.core.event.PersistenceEvent import io.scalac.mesmer.core.event.PersistenceEvent._ import io.scalac.mesmer.core.model._ import io.scalac.mesmer.extension.metric.PersistenceMetricsMonitor -import io.scalac.mesmer.extension.metric.PersistenceMetricsMonitor.Labels +import io.scalac.mesmer.extension.metric.PersistenceMetricsMonitor.Attributes import io.scalac.mesmer.extension.persistence.PersistStorage import io.scalac.mesmer.extension.persistence.RecoveryStorage import io.scalac.mesmer.extension.service.PathService @@ -40,9 +40,9 @@ object PersistenceEventsActor { if (pathLastSlashIndex > 0 && path.substring(pathLastSlashIndex + 1, path.length) == persistenceId) { val persistentIdTemplate = templatedPath.substring(templatedPath.lastIndexOf('/', templatedPath.length - 2) + 1, templatedPath.length) - monitor.bind(Labels(node, templatedPath, persistentIdTemplate)) + monitor.bind(Attributes(node, templatedPath, persistentIdTemplate)) } else { - monitor.bind(Labels(node, templatedPath, pathService.template(persistenceId))) + monitor.bind(Attributes(node, templatedPath, pathService.template(persistenceId))) } } diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/metric/ActorMetricsMonitor.scala b/extension/src/main/scala/io/scalac/mesmer/extension/metric/ActorMetricsMonitor.scala index f8f68fba8..9524042fb 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/metric/ActorMetricsMonitor.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/metric/ActorMetricsMonitor.scala @@ -1,14 +1,14 @@ package io.scalac.mesmer.extension.metric -import io.scalac.mesmer.core.LabelSerializable +import io.scalac.mesmer.core.AttributesSerializable import io.scalac.mesmer.core.model._ import io.scalac.mesmer.core.module.AkkaActorModule object ActorMetricsMonitor { - final case class Labels(actorPath: ActorPath, node: Option[Node] = None, tags: Set[Tag] = Set.empty) - extends LabelSerializable { - val serialize: RawLabels = node.serialize ++ actorPath.serialize ++ tags.flatMap(_.serialize) + final case class Attributes(actorPath: ActorPath, node: Option[Node] = None, tags: Set[Tag] = Set.empty) + extends AttributesSerializable { + val serialize: RawAttributes = node.serialize ++ actorPath.serialize ++ tags.flatMap(_.serialize) } - trait BoundMonitor extends Bound with AkkaActorModule.Metrics[MetricObserver[Long, Labels]] {} + trait BoundMonitor extends Bound with AkkaActorModule.Metrics[MetricObserver[Long, Attributes]] {} } diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/metric/ActorSystemMonitor.scala b/extension/src/main/scala/io/scalac/mesmer/extension/metric/ActorSystemMonitor.scala index 70b60f70c..454d17f0b 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/metric/ActorSystemMonitor.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/metric/ActorSystemMonitor.scala @@ -1,12 +1,12 @@ package io.scalac.mesmer.extension.metric -import io.scalac.mesmer.core.LabelSerializable +import io.scalac.mesmer.core.AttributesSerializable import io.scalac.mesmer.core.model._ import io.scalac.mesmer.core.module.AkkaActorSystemModule object ActorSystemMonitor { - final case class Labels(node: Option[Node]) extends LabelSerializable { - override def serialize: RawLabels = node.serialize + final case class Attributes(node: Option[Node]) extends AttributesSerializable { + override def serialize: RawAttributes = node.serialize } trait BoundMonitor extends Bound with AkkaActorSystemModule.All[Metric[Long]] { diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/metric/Bindable.scala b/extension/src/main/scala/io/scalac/mesmer/extension/metric/Bindable.scala index 6675b0d76..943ae43a6 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/metric/Bindable.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/metric/Bindable.scala @@ -1,7 +1,7 @@ package io.scalac.mesmer.extension.metric -import io.scalac.mesmer.core.LabelSerializable -import io.scalac.mesmer.core.model.RawLabels +import io.scalac.mesmer.core.AttributesSerializable +import io.scalac.mesmer.core.model.RawAttributes trait Unbind { private[scalac] def unbind(): Unit @@ -18,19 +18,19 @@ trait RegisterRoot extends Unbind { trait Bound extends Unbind -trait Bindable[L <: LabelSerializable, +B <: Bound] extends (L => B) { - final def apply(labels: L): B = bind(labels) - def bind(labels: L): B +trait Bindable[L <: AttributesSerializable, +B <: Bound] extends (L => B) { + final def apply(attributes: L): B = bind(attributes) + def bind(attributes: L): B } -trait EmptyBind[B <: Bound] extends Bindable[EmptyBind.EmptyLabels, B] { - final def bind(labels: EmptyBind.EmptyLabels): B = this.bind() +trait EmptyBind[B <: Bound] extends Bindable[EmptyBind.EmptyAttributes, B] { + final def bind(attributes: EmptyBind.EmptyAttributes): B = this.bind() def bind(): B } object EmptyBind { // no implementation of this is needed - sealed trait EmptyLabels extends LabelSerializable { - val serialize: RawLabels = Seq.empty + sealed trait EmptyAttributes extends AttributesSerializable { + val serialize: RawAttributes = Seq.empty } } diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/metric/CachingMonitor.scala b/extension/src/main/scala/io/scalac/mesmer/extension/metric/CachingMonitor.scala index a281f1670..1e606d02d 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/metric/CachingMonitor.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/metric/CachingMonitor.scala @@ -7,10 +7,10 @@ import org.slf4j.LoggerFactory import scala.collection.mutable.{ Map => MutableMap } import scala.jdk.CollectionConverters._ -import io.scalac.mesmer.core.LabelSerializable +import io.scalac.mesmer.core.AttributesSerializable import io.scalac.mesmer.extension.config.CachingConfig -case class CachingMonitor[L <: LabelSerializable, B <: Bound]( +case class CachingMonitor[L <: AttributesSerializable, B <: Bound]( bindable: Bindable[L, B], config: CachingConfig = CachingConfig.empty ) extends Bindable[L, B] { @@ -29,14 +29,14 @@ case class CachingMonitor[L <: LabelSerializable, B <: Bound]( }.asScala } - final def bind(labels: L): B = - cachedMonitors.getOrElse(labels, updateMonitors(labels)) + final def bind(attributes: L): B = + cachedMonitors.getOrElse(attributes, updateMonitors(attributes)) - final private def updateMonitors(labels: L): B = + final private def updateMonitors(attributes: L): B = cachedMonitors.getOrElseUpdate( - labels, { - logger.debug("Creating new monitor for lables {}", labels) - bindable(labels) + attributes, { + logger.debug("Creating new monitor for lables {}", attributes) + bindable(attributes) } ) diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/metric/ClusterMetricsMonitor.scala b/extension/src/main/scala/io/scalac/mesmer/extension/metric/ClusterMetricsMonitor.scala index 7c7598271..5e397bfc9 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/metric/ClusterMetricsMonitor.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/metric/ClusterMetricsMonitor.scala @@ -1,23 +1,23 @@ package io.scalac.mesmer.extension.metric -import io.scalac.mesmer.core.LabelSerializable +import io.scalac.mesmer.core.AttributesSerializable import io.scalac.mesmer.core.model._ import io.scalac.mesmer.core.module.AkkaClusterModule object ClusterMetricsMonitor { - final case class Labels(node: Node, region: Option[Region] = None) extends LabelSerializable { + final case class Attributes(node: Node, region: Option[Region] = None) extends AttributesSerializable { - val serialize: RawLabels = node.serialize ++ region.serialize + val serialize: RawAttributes = node.serialize ++ region.serialize - def withRegion(region: Region): Labels = copy(region = Some(region)) + def withRegion(region: Region): Attributes = copy(region = Some(region)) } trait BoundMonitor extends Synchronized with Bound with AkkaClusterModule.All[Metric[Long]] { - def shardPerRegions: MetricObserver[Long, Labels] - def entityPerRegion: MetricObserver[Long, Labels] - def shardRegionsOnNode: MetricObserver[Long, Labels] - def entitiesOnNode: MetricObserver[Long, Labels] + def shardPerRegions: MetricObserver[Long, Attributes] + def entityPerRegion: MetricObserver[Long, Attributes] + def shardRegionsOnNode: MetricObserver[Long, Attributes] + def entitiesOnNode: MetricObserver[Long, Attributes] def reachableNodes: UpDownCounter[Long] with Instrument[Long] def unreachableNodes: UpDownCounter[Long] with Instrument[Long] def nodeDown: Counter[Long] with Instrument[Long] diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/metric/HttpConnectionMetricsMonitor.scala b/extension/src/main/scala/io/scalac/mesmer/extension/metric/HttpConnectionMetricsMonitor.scala index d4ca1a646..36e50732f 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/metric/HttpConnectionMetricsMonitor.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/metric/HttpConnectionMetricsMonitor.scala @@ -1,16 +1,16 @@ package io.scalac.mesmer.extension.metric -import io.scalac.mesmer.core.LabelSerializable +import io.scalac.mesmer.core.AttributesSerializable import io.scalac.mesmer.core.model.Interface import io.scalac.mesmer.core.model.Node import io.scalac.mesmer.core.model.Port -import io.scalac.mesmer.core.model.RawLabels +import io.scalac.mesmer.core.model.RawAttributes import io.scalac.mesmer.core.module.AkkaHttpModule._ object HttpConnectionMetricsMonitor { - final case class Labels(node: Option[Node], interface: Interface, port: Port) extends LabelSerializable { - val serialize: RawLabels = node.serialize ++ interface.serialize ++ port.serialize + final case class Attributes(node: Option[Node], interface: Interface, port: Port) extends AttributesSerializable { + val serialize: RawAttributes = node.serialize ++ interface.serialize ++ port.serialize } trait BoundMonitor extends AkkaHttpConnectionsMetricsDef[Metric[Long]] with Synchronized with Bound { diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/metric/HttpMetricsMonitor.scala b/extension/src/main/scala/io/scalac/mesmer/extension/metric/HttpMetricsMonitor.scala index 3d16bae7d..e60bf76d9 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/metric/HttpMetricsMonitor.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/metric/HttpMetricsMonitor.scala @@ -1,13 +1,14 @@ package io.scalac.mesmer.extension.metric -import io.scalac.mesmer.core.LabelSerializable +import io.scalac.mesmer.core.AttributesSerializable import io.scalac.mesmer.core.model._ import io.scalac.mesmer.core.module.AkkaHttpModule._ object HttpMetricsMonitor { - final case class Labels(node: Option[Node], path: Path, method: Method, status: Status) extends LabelSerializable { - val serialize: RawLabels = node.serialize ++ path.serialize ++ method.serialize ++ status.serialize + final case class Attributes(node: Option[Node], path: Path, method: Method, status: Status) + extends AttributesSerializable { + val serialize: RawAttributes = node.serialize ++ path.serialize ++ method.serialize ++ status.serialize } trait BoundMonitor extends AkkaHttpRequestMetricsDef[Metric[Long]] with Synchronized with Bound { diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/metric/Metric.scala b/extension/src/main/scala/io/scalac/mesmer/extension/metric/Metric.scala index d48005e3a..304c820ce 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/metric/Metric.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/metric/Metric.scala @@ -75,7 +75,7 @@ object MetricObserver { type Updater[+T, +L] = MetricObserver.Result[T, L] => Unit trait Result[-T, -L] { - def observe(value: T, labels: L): Unit + def observe(value: T, attributes: L): Unit } case object NoopMetricObserver extends MetricObserver[Any, Any] { diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/metric/PersistenceMetricsMonitor.scala b/extension/src/main/scala/io/scalac/mesmer/extension/metric/PersistenceMetricsMonitor.scala index d349a48d8..23a929848 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/metric/PersistenceMetricsMonitor.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/metric/PersistenceMetricsMonitor.scala @@ -1,12 +1,13 @@ package io.scalac.mesmer.extension.metric -import io.scalac.mesmer.core.LabelSerializable +import io.scalac.mesmer.core.AttributesSerializable import io.scalac.mesmer.core.model._ import io.scalac.mesmer.core.module.AkkaPersistenceModule object PersistenceMetricsMonitor { - final case class Labels(node: Option[Node], path: Path, persistenceId: PersistenceId) extends LabelSerializable { - val serialize: RawLabels = node.serialize ++ path.serialize ++ persistenceId.serialize + final case class Attributes(node: Option[Node], path: Path, persistenceId: PersistenceId) + extends AttributesSerializable { + val serialize: RawAttributes = node.serialize ++ path.serialize ++ persistenceId.serialize } trait BoundMonitor extends Bound with AkkaPersistenceModule.Metrics[Metric[Long]] { diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/metric/StreamMetricsMonitor.scala b/extension/src/main/scala/io/scalac/mesmer/extension/metric/StreamMetricsMonitor.scala index 47e340b7f..bf87d2ca8 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/metric/StreamMetricsMonitor.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/metric/StreamMetricsMonitor.scala @@ -1,26 +1,26 @@ package io.scalac.mesmer.extension.metric -import io.scalac.mesmer.core.LabelSerializable +import io.scalac.mesmer.core.AttributesSerializable import io.scalac.mesmer.core.model.Tag.StreamName import io.scalac.mesmer.core.model._ import io.scalac.mesmer.core.module.AkkaStreamModule object StreamMetricsMonitor { - final case class EagerLabels( + final case class EagerAttributes( node: Option[Node] - ) extends LabelSerializable { - lazy val serialize: RawLabels = node.serialize + ) extends AttributesSerializable { + lazy val serialize: RawAttributes = node.serialize } - final case class Labels(node: Option[Node], streamName: StreamName) extends LabelSerializable { - lazy val serialize: RawLabels = node.serialize ++ streamName.serialize + final case class Attributes(node: Option[Node], streamName: StreamName) extends AttributesSerializable { + lazy val serialize: RawAttributes = node.serialize ++ streamName.serialize } trait BoundMonitor extends Bound with AkkaStreamModule.StreamMetricsDef[Metric[Long]] { def runningStreamsTotal: MetricRecorder[Long] def streamActorsTotal: MetricRecorder[Long] - def streamProcessedMessages: MetricObserver[Long, Labels] + def streamProcessedMessages: MetricObserver[Long, Attributes] } } diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/metric/StreamOperatorMetricsMonitor.scala b/extension/src/main/scala/io/scalac/mesmer/extension/metric/StreamOperatorMetricsMonitor.scala index 3fc63d7ca..4cd3d0d52 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/metric/StreamOperatorMetricsMonitor.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/metric/StreamOperatorMetricsMonitor.scala @@ -1,34 +1,34 @@ package io.scalac.mesmer.extension.metric -import io.scalac.mesmer.core.LabelSerializable +import io.scalac.mesmer.core.AttributesSerializable import io.scalac.mesmer.core.model.Tag._ import io.scalac.mesmer.core.model._ import io.scalac.mesmer.core.module.AkkaStreamModule object StreamOperatorMetricsMonitor { - final case class Labels( + final case class Attributes( operator: StageName, stream: StreamName, terminal: Boolean, node: Option[Node], connectedWith: Option[String] // TODO change this to StageName - ) extends LabelSerializable { - val serialize: RawLabels = { + ) extends AttributesSerializable { + val serialize: RawAttributes = { - val connected = connectedWith.fold[RawLabels](Seq.empty) { stageName => + val connected = connectedWith.fold[RawAttributes](Seq.empty) { stageName => Seq("connected_with" -> stageName) } - val terminalLabels = if (terminal) Seq("terminal" -> "true") else Seq.empty + val terminalAttributes = if (terminal) Seq("terminal" -> "true") else Seq.empty - operator.serialize ++ stream.serialize ++ node.serialize ++ connected ++ terminalLabels + operator.serialize ++ stream.serialize ++ node.serialize ++ connected ++ terminalAttributes } } trait BoundMonitor extends Bound with AkkaStreamModule.StreamOperatorMetricsDef[Metric[Long]] { - def processedMessages: MetricObserver[Long, StreamOperatorMetricsMonitor.Labels] - def operators: MetricObserver[Long, StreamOperatorMetricsMonitor.Labels] - def demand: MetricObserver[Long, StreamOperatorMetricsMonitor.Labels] + def processedMessages: MetricObserver[Long, StreamOperatorMetricsMonitor.Attributes] + def operators: MetricObserver[Long, StreamOperatorMetricsMonitor.Attributes] + def demand: MetricObserver[Long, StreamOperatorMetricsMonitor.Attributes] } } diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/metric/package.scala b/extension/src/main/scala/io/scalac/mesmer/extension/metric/package.scala index 1fb89a91f..c4e7918c8 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/metric/package.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/metric/package.scala @@ -3,19 +3,20 @@ package io.scalac.mesmer.extension package object metric { /* Disclaimer - Each following type has its companion object that defines the Label and BoundMonitor. + Each following type has its companion object that defines the Attribute and BoundMonitor. To define the type alias here help us to reference monitors in the code instead of to invent a non-conflicting name for them inside namespaces. TODO In Scala 3 we'll have top-level to help us do that. */ type ActorMetricsMonitor = EmptyBind[ActorMetricsMonitor.BoundMonitor] - type HttpMetricsMonitor = Bindable[HttpMetricsMonitor.Labels, HttpMetricsMonitor.BoundMonitor] + type HttpMetricsMonitor = Bindable[HttpMetricsMonitor.Attributes, HttpMetricsMonitor.BoundMonitor] type HttpConnectionMetricsMonitor = - Bindable[HttpConnectionMetricsMonitor.Labels, HttpConnectionMetricsMonitor.BoundMonitor] - type PersistenceMetricsMonitor = Bindable[PersistenceMetricsMonitor.Labels, PersistenceMetricsMonitor.BoundMonitor] - type ClusterMetricsMonitor = Bindable[ClusterMetricsMonitor.Labels, ClusterMetricsMonitor.BoundMonitor] - type StreamMetricsMonitor = Bindable[StreamMetricsMonitor.EagerLabels, StreamMetricsMonitor.BoundMonitor] + Bindable[HttpConnectionMetricsMonitor.Attributes, HttpConnectionMetricsMonitor.BoundMonitor] + type PersistenceMetricsMonitor = + Bindable[PersistenceMetricsMonitor.Attributes, PersistenceMetricsMonitor.BoundMonitor] + type ClusterMetricsMonitor = Bindable[ClusterMetricsMonitor.Attributes, ClusterMetricsMonitor.BoundMonitor] + type StreamMetricsMonitor = Bindable[StreamMetricsMonitor.EagerAttributes, StreamMetricsMonitor.BoundMonitor] type StreamOperatorMetricsMonitor = EmptyBind[StreamOperatorMetricsMonitor.BoundMonitor] - type ActorSystemMonitor = Bindable[ActorSystemMonitor.Labels, ActorSystemMonitor.BoundMonitor] + type ActorSystemMonitor = Bindable[ActorSystemMonitor.Attributes, ActorSystemMonitor.BoundMonitor] } diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/service/ActorTreeService.scala b/extension/src/main/scala/io/scalac/mesmer/extension/service/ActorTreeService.scala index 4cff5e1eb..56c5cd824 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/service/ActorTreeService.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/service/ActorTreeService.scala @@ -16,7 +16,7 @@ import io.scalac.mesmer.core.event.ActorEvent import io.scalac.mesmer.core.model.Tag import io.scalac.mesmer.core.model._ import io.scalac.mesmer.extension.metric.ActorSystemMonitor -import io.scalac.mesmer.extension.metric.ActorSystemMonitor.Labels +import io.scalac.mesmer.extension.metric.ActorSystemMonitor.Attributes import io.scalac.mesmer.extension.service.ActorTreeService.Api import io.scalac.mesmer.extension.service.SubscriptionService.AddSubscriber import io.scalac.mesmer.extension.service.SubscriptionService.Broadcast @@ -139,7 +139,7 @@ final class ActorTreeService( }) private[this] val snapshot = Tree.builder[classic.ActorRef, ActorRefDetails] - private[this] val boundMonitor = monitor.bind(Labels(node)) + private[this] val boundMonitor = monitor.bind(Attributes(node)) private[this] lazy val subscriptions = mutable.Map .empty[Tag, ActorRef[SubscriptionService.Command[ActorRefDetails]]] diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/LabelNames.scala b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/AttributeNames.scala similarity index 84% rename from extension/src/main/scala/io/scalac/mesmer/extension/upstream/LabelNames.scala rename to extension/src/main/scala/io/scalac/mesmer/extension/upstream/AttributeNames.scala index 1966188ea..36c99d65e 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/LabelNames.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/AttributeNames.scala @@ -1,6 +1,6 @@ package io.scalac.mesmer.extension.upstream -object LabelNames { +object AttributeNames { val ActorPath = "actorPath" val Node = "node" val Region = "region" diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/LabelsFactory.scala b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/AttributesFactory.scala similarity index 80% rename from extension/src/main/scala/io/scalac/mesmer/extension/upstream/LabelsFactory.scala rename to extension/src/main/scala/io/scalac/mesmer/extension/upstream/AttributesFactory.scala index f0f8137d7..c15abe04c 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/LabelsFactory.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/AttributesFactory.scala @@ -5,27 +5,27 @@ import io.opentelemetry.api.common.Attributes import scala.annotation.switch -object LabelsFactory { +object AttributesFactory { def of(required: (String, String)*)(optionals: (String, Option[String])*): Attributes = of(required ++ optionals.collect { case (k, Some(v)) => (k, v) }) /** - * Microoptimized version that produce OpenTelemetry labels from sequence of tuples - * @param labels + * Microoptimized version that produce OpenTelemetry attributes from sequence of tuples + * @param attributes * @return */ - def of(labels: Seq[(String, String)]): Attributes = { - val size = labels.size + def of(attributes: Seq[(String, String)]): Attributes = { + val size = attributes.size (size: @switch) match { case 1 => - val Seq((key, value)) = labels + val Seq((key, value)) = attributes Attributes.of(AttributeKey.stringKey(key), value) case 2 => - val Seq((key1, value1), (key2, value2)) = labels + val Seq((key1, value1), (key2, value2)) = attributes Attributes.of(AttributeKey.stringKey(key1), (value1), AttributeKey.stringKey(key2), value2) case 3 => - val Seq((key1, value1), (key2, value2), (key3, value3)) = labels + val Seq((key1, value1), (key2, value2), (key3, value3)) = attributes Attributes.of( AttributeKey.stringKey(key1), value1, @@ -35,7 +35,7 @@ object LabelsFactory { value3 ) case 4 => - val Seq((key1, value1), (key2, value2), (key3, value3), (key4, value4)) = labels + val Seq((key1, value1), (key2, value2), (key3, value3), (key4, value4)) = attributes Attributes.of( AttributeKey.stringKey(key1), value1, @@ -47,7 +47,7 @@ object LabelsFactory { value4 ) case 5 => - val Seq((key1, value1), (key2, value2), (key3, value3), (key4, value4), (key5, value5)) = labels + val Seq((key1, value1), (key2, value2), (key3, value3), (key4, value4), (key5, value5)) = attributes Attributes.of( AttributeKey.stringKey(key1), value1, @@ -61,7 +61,7 @@ object LabelsFactory { value5 ) case _ => - labels + attributes .foldLeft(Attributes.builder()) { case (builder, (key, value)) => builder.put(key, value) } diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryActorMetricsMonitor.scala b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryActorMetricsMonitor.scala index b4c7859a1..526ce1f74 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryActorMetricsMonitor.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryActorMetricsMonitor.scala @@ -151,100 +151,100 @@ final class OpenTelemetryActorMetricsMonitor( metricNames: MetricNames ) extends ActorMetricsMonitor { - private lazy val mailboxSizeObserver = new GaugeBuilderAdapter[ActorMetricsMonitor.Labels]( + private lazy val mailboxSizeObserver = new GaugeBuilderAdapter[ActorMetricsMonitor.Attributes]( meter .gaugeBuilder(metricNames.mailboxSize) .ofLongs() .setDescription("Tracks the size of an Actor's mailbox") ) - private lazy val mailboxTimeCountObserver = new GaugeBuilderAdapter[ActorMetricsMonitor.Labels]( + private lazy val mailboxTimeCountObserver = new GaugeBuilderAdapter[ActorMetricsMonitor.Attributes]( meter .gaugeBuilder(metricNames.mailboxTimeCount) .ofLongs() .setDescription("Tracks the count of messages in an Actor's mailbox") ) - private lazy val mailboxTimeMinObserver = new GaugeBuilderAdapter[ActorMetricsMonitor.Labels]( + private lazy val mailboxTimeMinObserver = new GaugeBuilderAdapter[ActorMetricsMonitor.Attributes]( meter .gaugeBuilder(metricNames.mailboxTimeMin) .ofLongs() .setDescription("Tracks the minimum time of an message in an Actor's mailbox") ) - private lazy val mailboxTimeMaxObserver = new GaugeBuilderAdapter[ActorMetricsMonitor.Labels]( + private lazy val mailboxTimeMaxObserver = new GaugeBuilderAdapter[ActorMetricsMonitor.Attributes]( meter .gaugeBuilder(metricNames.mailboxTimeMax) .ofLongs() .setDescription("Tracks the maximum time of an message in an Actor's mailbox") ) - private lazy val mailboxTimeSumObserver = new GaugeBuilderAdapter[ActorMetricsMonitor.Labels]( + private lazy val mailboxTimeSumObserver = new GaugeBuilderAdapter[ActorMetricsMonitor.Attributes]( meter .gaugeBuilder(metricNames.mailboxTimeSum) .ofLongs() .setDescription("Tracks the sum time of the messages in an Actor's mailbox") ) - private lazy val stashSizeCounter = new LongSumObserverBuilderAdapter[ActorMetricsMonitor.Labels]( + private lazy val stashSizeCounter = new LongSumObserverBuilderAdapter[ActorMetricsMonitor.Attributes]( meter .counterBuilder(metricNames.stashedMessages) .setDescription("Tracks stash operations on actors") ) - private lazy val receivedMessagesSumObserver = new LongSumObserverBuilderAdapter[ActorMetricsMonitor.Labels]( + private lazy val receivedMessagesSumObserver = new LongSumObserverBuilderAdapter[ActorMetricsMonitor.Attributes]( meter .counterBuilder(metricNames.receivedMessages) .setDescription("Tracks the sum of received messages in an Actor") ) - private lazy val processedMessagesSumObserver = new LongSumObserverBuilderAdapter[ActorMetricsMonitor.Labels]( + private lazy val processedMessagesSumObserver = new LongSumObserverBuilderAdapter[ActorMetricsMonitor.Attributes]( meter .counterBuilder(metricNames.processedMessages) .setDescription("Tracks the sum of processed messages in an Actor") ) - private lazy val failedMessagesSumObserver = new LongSumObserverBuilderAdapter[ActorMetricsMonitor.Labels]( + private lazy val failedMessagesSumObserver = new LongSumObserverBuilderAdapter[ActorMetricsMonitor.Attributes]( meter .counterBuilder(metricNames.failedMessages) .setDescription("Tracks the sum of failed messages in an Actor") ) - private lazy val processingTimeCountObserver = new GaugeBuilderAdapter[ActorMetricsMonitor.Labels]( + private lazy val processingTimeCountObserver = new GaugeBuilderAdapter[ActorMetricsMonitor.Attributes]( meter .gaugeBuilder(metricNames.processingTimeCount) .ofLongs() .setDescription("Tracks the amount of processed messages") ) - private lazy val processingTimeMinObserver = new GaugeBuilderAdapter[ActorMetricsMonitor.Labels]( + private lazy val processingTimeMinObserver = new GaugeBuilderAdapter[ActorMetricsMonitor.Attributes]( meter .gaugeBuilder(metricNames.processingTimeMin) .ofLongs() .setDescription("Tracks the miminum processing time of an message in an Actor's receive handler") ) - private lazy val processingTimeMaxObserver = new GaugeBuilderAdapter[ActorMetricsMonitor.Labels]( + private lazy val processingTimeMaxObserver = new GaugeBuilderAdapter[ActorMetricsMonitor.Attributes]( meter .gaugeBuilder(metricNames.processingTimeMax) .ofLongs() .setDescription("Tracks the maximum processing time of an message in an Actor's receive handler") ) - private lazy val processingTimeSumObserver = new GaugeBuilderAdapter[ActorMetricsMonitor.Labels]( + private lazy val processingTimeSumObserver = new GaugeBuilderAdapter[ActorMetricsMonitor.Attributes]( meter .gaugeBuilder(metricNames.processingTimeSum) .ofLongs() .setDescription("Tracks the sum processing time of an message in an Actor's receive handler") ) - private lazy val sentMessagesObserver = new LongSumObserverBuilderAdapter[ActorMetricsMonitor.Labels]( + private lazy val sentMessagesObserver = new LongSumObserverBuilderAdapter[ActorMetricsMonitor.Attributes]( meter .counterBuilder(metricNames.sentMessages) .setDescription("Tracks the sum of sent messages in an Actor") ) - private lazy val droppedMessagesObserver = new LongSumObserverBuilderAdapter[ActorMetricsMonitor.Labels]( + private lazy val droppedMessagesObserver = new LongSumObserverBuilderAdapter[ActorMetricsMonitor.Attributes]( meter .counterBuilder(metricNames.droppedMessages) .setDescription("Tracks the sum of dropped messages in an Actor") @@ -258,49 +258,49 @@ final class OpenTelemetryActorMetricsMonitor( with RegisterRoot with SynchronousInstrumentFactory { - val mailboxSize: MetricObserver[Long, ActorMetricsMonitor.Labels] = + val mailboxSize: MetricObserver[Long, ActorMetricsMonitor.Attributes] = if (moduleConfig.mailboxSize) mailboxSizeObserver.createObserver(this) else MetricObserver.noop - val mailboxTimeCount: MetricObserver[Long, ActorMetricsMonitor.Labels] = + val mailboxTimeCount: MetricObserver[Long, ActorMetricsMonitor.Attributes] = if (moduleConfig.mailboxTimeCount) mailboxTimeCountObserver.createObserver(this) else MetricObserver.noop - val mailboxTimeMin: MetricObserver[Long, ActorMetricsMonitor.Labels] = + val mailboxTimeMin: MetricObserver[Long, ActorMetricsMonitor.Attributes] = if (moduleConfig.mailboxTimeMin) mailboxTimeMinObserver.createObserver(this) else MetricObserver.noop - val mailboxTimeMax: MetricObserver[Long, ActorMetricsMonitor.Labels] = + val mailboxTimeMax: MetricObserver[Long, ActorMetricsMonitor.Attributes] = if (moduleConfig.mailboxTimeMax) mailboxTimeMaxObserver.createObserver(this) else MetricObserver.noop - val mailboxTimeSum: MetricObserver[Long, ActorMetricsMonitor.Labels] = + val mailboxTimeSum: MetricObserver[Long, ActorMetricsMonitor.Attributes] = if (moduleConfig.mailboxTimeSum) mailboxTimeSumObserver.createObserver(this) else MetricObserver.noop - val stashedMessages: MetricObserver[Long, ActorMetricsMonitor.Labels] = + val stashedMessages: MetricObserver[Long, ActorMetricsMonitor.Attributes] = if (moduleConfig.stashedMessages) stashSizeCounter.createObserver(this) else MetricObserver.noop - val receivedMessages: MetricObserver[Long, ActorMetricsMonitor.Labels] = + val receivedMessages: MetricObserver[Long, ActorMetricsMonitor.Attributes] = if (moduleConfig.receivedMessages) receivedMessagesSumObserver.createObserver(this) else MetricObserver.noop - val processedMessages: MetricObserver[Long, ActorMetricsMonitor.Labels] = + val processedMessages: MetricObserver[Long, ActorMetricsMonitor.Attributes] = if (moduleConfig.processedMessages) processedMessagesSumObserver.createObserver(this) else MetricObserver.noop - val failedMessages: MetricObserver[Long, ActorMetricsMonitor.Labels] = + val failedMessages: MetricObserver[Long, ActorMetricsMonitor.Attributes] = if (moduleConfig.failedMessages) failedMessagesSumObserver.createObserver(this) else MetricObserver.noop - val processingTimeCount: MetricObserver[Long, ActorMetricsMonitor.Labels] = + val processingTimeCount: MetricObserver[Long, ActorMetricsMonitor.Attributes] = if (moduleConfig.processingTimeCount) processingTimeCountObserver.createObserver(this) else MetricObserver.noop - val processingTimeMin: MetricObserver[Long, ActorMetricsMonitor.Labels] = + val processingTimeMin: MetricObserver[Long, ActorMetricsMonitor.Attributes] = if (moduleConfig.processingTimeMin) processingTimeMinObserver.createObserver(this) else MetricObserver.noop - val processingTimeMax: MetricObserver[Long, ActorMetricsMonitor.Labels] = + val processingTimeMax: MetricObserver[Long, ActorMetricsMonitor.Attributes] = if (moduleConfig.processingTimeMax) processingTimeMaxObserver.createObserver(this) else MetricObserver.noop - val processingTimeSum: MetricObserver[Long, ActorMetricsMonitor.Labels] = + val processingTimeSum: MetricObserver[Long, ActorMetricsMonitor.Attributes] = if (moduleConfig.processingTimeSum) processingTimeSumObserver.createObserver(this) else MetricObserver.noop - val sentMessages: MetricObserver[Long, ActorMetricsMonitor.Labels] = + val sentMessages: MetricObserver[Long, ActorMetricsMonitor.Attributes] = if (moduleConfig.sentMessages) sentMessagesObserver.createObserver(this) else MetricObserver.noop - val droppedMessages: MetricObserver[Long, ActorMetricsMonitor.Labels] = + val droppedMessages: MetricObserver[Long, ActorMetricsMonitor.Attributes] = if (moduleConfig.droppedMessages) droppedMessagesObserver .createObserver(this) diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryActorSystemMonitor.scala b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryActorSystemMonitor.scala index 2f0329543..c1a97f646 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryActorSystemMonitor.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryActorSystemMonitor.scala @@ -58,19 +58,19 @@ final class OpenTelemetryActorSystemMonitor( .setDescription("Amount of actors terminated measured from Actor System start") .build() - override def bind(labels: ActorSystemMonitor.Labels): ActorSystemMonitor.BoundMonitor = - new ActorSystemBoundMonitor(labels) + override def bind(attributes: ActorSystemMonitor.Attributes): ActorSystemMonitor.BoundMonitor = + new ActorSystemBoundMonitor(attributes) - class ActorSystemBoundMonitor(labels: ActorSystemMonitor.Labels) + class ActorSystemBoundMonitor(attributes: ActorSystemMonitor.Attributes) extends BoundMonitor with RegisterRoot with SynchronousInstrumentFactory { - private[this] val otLabels = LabelsFactory.of(labels.serialize) + private[this] val otAttributes = AttributesFactory.of(attributes.serialize) lazy val createdActors: Counter[Long] = - if (moduleConfig.createdActors) counter(createdActorsCounter, otLabels)(this) else noopCounter + if (moduleConfig.createdActors) counter(createdActorsCounter, otAttributes)(this) else noopCounter lazy val terminatedActors: Counter[Long] = - if (moduleConfig.terminatedActors) counter(terminatedActorsCounter, otLabels)(this) else noopCounter + if (moduleConfig.terminatedActors) counter(terminatedActorsCounter, otAttributes)(this) else noopCounter } } diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryClusterMetricsMonitor.scala b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryClusterMetricsMonitor.scala index 294bec1cd..e9b375d5a 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryClusterMetricsMonitor.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryClusterMetricsMonitor.scala @@ -91,14 +91,14 @@ final class OpenTelemetryClusterMetricsMonitor( metricNames: MetricNames ) extends ClusterMetricsMonitor { - private lazy val shardsPerRegionRecorder = new GaugeBuilderAdapter[ClusterMetricsMonitor.Labels]( + private lazy val shardsPerRegionRecorder = new GaugeBuilderAdapter[ClusterMetricsMonitor.Attributes]( meter .gaugeBuilder(metricNames.shardPerEntity) .ofLongs() .setDescription("Amount of shards in region") ) - private lazy val entityPerRegionRecorder = new GaugeBuilderAdapter[ClusterMetricsMonitor.Labels]( + private lazy val entityPerRegionRecorder = new GaugeBuilderAdapter[ClusterMetricsMonitor.Attributes]( meter .gaugeBuilder(metricNames.entityPerRegion) .ofLongs() @@ -115,14 +115,14 @@ final class OpenTelemetryClusterMetricsMonitor( .setDescription("Amount of unreachable nodes") .build() - private lazy val shardRegionsOnNodeRecorder = new GaugeBuilderAdapter[ClusterMetricsMonitor.Labels]( + private lazy val shardRegionsOnNodeRecorder = new GaugeBuilderAdapter[ClusterMetricsMonitor.Attributes]( meter .gaugeBuilder(metricNames.shardRegionsOnNode) .ofLongs() .setDescription("Amount of shard regions on node") ) - private lazy val entitiesOnNodeObserver = new GaugeBuilderAdapter[ClusterMetricsMonitor.Labels]( + private lazy val entitiesOnNodeObserver = new GaugeBuilderAdapter[ClusterMetricsMonitor.Attributes]( meter .gaugeBuilder(metricNames.entitiesOnNode) .ofLongs() @@ -134,37 +134,38 @@ final class OpenTelemetryClusterMetricsMonitor( .setDescription("Counter for node down events") .build() - def bind(labels: ClusterMetricsMonitor.Labels): ClusterBoundMonitor = new ClusterBoundMonitor(labels) + def bind(attributes: ClusterMetricsMonitor.Attributes): ClusterBoundMonitor = new ClusterBoundMonitor(attributes) - final class ClusterBoundMonitor(labels: ClusterMetricsMonitor.Labels) + final class ClusterBoundMonitor(attributes: ClusterMetricsMonitor.Attributes) extends opentelemetry.Synchronized(meter) with ClusterMetricsMonitor.BoundMonitor with RegisterRoot with SynchronousInstrumentFactory { - protected val otLabels: Attributes = LabelsFactory.of(labels.serialize) + protected val otAttributes: Attributes = AttributesFactory.of(attributes.serialize) - lazy val shardPerRegions: MetricObserver[Long, ClusterMetricsMonitor.Labels] = { + lazy val shardPerRegions: MetricObserver[Long, ClusterMetricsMonitor.Attributes] = { if (moduleConfig.shardPerRegions) shardsPerRegionRecorder.createObserver(this) else MetricObserver.noop } - lazy val entityPerRegion: MetricObserver[Long, ClusterMetricsMonitor.Labels] = + lazy val entityPerRegion: MetricObserver[Long, ClusterMetricsMonitor.Attributes] = if (moduleConfig.entityPerRegion) entityPerRegionRecorder.createObserver(this) else MetricObserver.noop - lazy val shardRegionsOnNode: MetricObserver[Long, ClusterMetricsMonitor.Labels] = + lazy val shardRegionsOnNode: MetricObserver[Long, ClusterMetricsMonitor.Attributes] = if (moduleConfig.shardRegionsOnNode) shardRegionsOnNodeRecorder.createObserver(this) else MetricObserver.noop - lazy val entitiesOnNode: MetricObserver[Long, ClusterMetricsMonitor.Labels] = + lazy val entitiesOnNode: MetricObserver[Long, ClusterMetricsMonitor.Attributes] = if (moduleConfig.entitiesOnNode) entitiesOnNodeObserver.createObserver(this) else MetricObserver.noop lazy val reachableNodes: UpDownCounter[Long] with Instrument[Long] = - if (moduleConfig.reachableNodes) upDownCounter(reachableNodeCounter, otLabels)(this) else noopUpDownCounter + if (moduleConfig.reachableNodes) upDownCounter(reachableNodeCounter, otAttributes)(this) else noopUpDownCounter lazy val unreachableNodes: UpDownCounter[Long] with Instrument[Long] = - if (moduleConfig.unreachableNodes) upDownCounter(unreachableNodeCounter, otLabels)(this) else noopUpDownCounter + if (moduleConfig.unreachableNodes) upDownCounter(unreachableNodeCounter, otAttributes)(this) + else noopUpDownCounter lazy val nodeDown: Counter[Long] with Instrument[Long] = - if (moduleConfig.nodeDown) counter(nodeDownCounter, otLabels)(this) else noopCounter + if (moduleConfig.nodeDown) counter(nodeDownCounter, otAttributes)(this) else noopCounter } } diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryHttpConnectionMetricsMonitor.scala b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryHttpConnectionMetricsMonitor.scala index 7639157ff..32fbc81d8 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryHttpConnectionMetricsMonitor.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryHttpConnectionMetricsMonitor.scala @@ -1,7 +1,7 @@ package io.scalac.mesmer.extension.upstream import com.typesafe.config.Config -import io.opentelemetry.api.common.Attributes +import io.opentelemetry.api.common import io.opentelemetry.api.metrics.Meter import io.scalac.mesmer.core.config.MesmerConfiguration @@ -53,19 +53,19 @@ final class OpenTelemetryHttpConnectionMetricsMonitor( .setDescription("Amount of connections") .build() - def bind(labels: Labels): BoundMonitor = new HttpConnectionMetricBoundMonitor(labels) + def bind(attributes: Attributes): BoundMonitor = new HttpConnectionMetricBoundMonitor(attributes) - class HttpConnectionMetricBoundMonitor(labels: Labels) + class HttpConnectionMetricBoundMonitor(attributes: Attributes) extends opentelemetry.Synchronized(meter) with BoundMonitor with SynchronousInstrumentFactory with RegisterRoot { - protected lazy val otLabels: Attributes = LabelsFactory.of(labels.serialize) + protected lazy val otAttributes: common.Attributes = AttributesFactory.of(attributes.serialize) lazy val connections: UpDownCounter[Long] with Instrument[Long] = if (moduleConfig.connections) - upDownCounter(connectionTotalCounter, otLabels).register(this) + upDownCounter(connectionTotalCounter, otAttributes).register(this) else noopUpDownCounter } diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryHttpMetricsMonitor.scala b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryHttpMetricsMonitor.scala index b14ba238d..69e6aecee 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryHttpMetricsMonitor.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryHttpMetricsMonitor.scala @@ -1,7 +1,7 @@ package io.scalac.mesmer.extension.upstream import com.typesafe.config.Config -import io.opentelemetry.api.common.Attributes +import io.opentelemetry.api.common import io.opentelemetry.api.metrics.Meter import io.scalac.mesmer.core.config.MesmerConfiguration @@ -68,22 +68,22 @@ final class OpenTelemetryHttpMetricsMonitor( .setDescription("Amount of requests") .build() - def bind(labels: Labels): BoundMonitor = new HttpMetricsBoundMonitor(labels) + def bind(attributes: Attributes): BoundMonitor = new HttpMetricsBoundMonitor(attributes) - final class HttpMetricsBoundMonitor(labels: Labels) + final class HttpMetricsBoundMonitor(attributes: Attributes) extends opentelemetry.Synchronized(meter) with BoundMonitor with SynchronousInstrumentFactory with RegisterRoot { - protected val otLabels: Attributes = LabelsFactory.of(labels.serialize) + protected val otAttributes: common.Attributes = AttributesFactory.of(attributes.serialize) lazy val requestTime: MetricRecorder[Long] with Instrument[Long] = - if (moduleConfig.requestTime) metricRecorder(requestTimeRequest, otLabels).register(this) + if (moduleConfig.requestTime) metricRecorder(requestTimeRequest, otAttributes).register(this) else noopMetricRecorder[Long] lazy val requestCounter: Counter[Long] with Instrument[Long] = - if (moduleConfig.requestCounter) counter(requestTotalCounter, otLabels).register(this) else noopCounter[Long] + if (moduleConfig.requestCounter) counter(requestTotalCounter, otAttributes).register(this) else noopCounter[Long] } } diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryPersistenceMetricsMonitor.scala b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryPersistenceMetricsMonitor.scala index f6af20f86..8423ba72f 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryPersistenceMetricsMonitor.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryPersistenceMetricsMonitor.scala @@ -99,31 +99,31 @@ final class OpenTelemetryPersistenceMetricsMonitor( .setDescription("Amount of snapshots created") .build() - def bind(labels: Labels): BoundMonitor = new OpenTelemetryBoundMonitor(labels) + def bind(attributes: Attributes): BoundMonitor = new OpenTelemetryBoundMonitor(attributes) - final class OpenTelemetryBoundMonitor(labels: Labels) + final class OpenTelemetryBoundMonitor(attributes: Attributes) extends BoundMonitor with RegisterRoot with SynchronousInstrumentFactory { - private val openTelemetryLabels = LabelsFactory.of(labels.serialize) + private val otAttributes = AttributesFactory.of(attributes.serialize) lazy val recoveryTime: MetricRecorder[Long] = - if (moduleConfig.recoveryTime) metricRecorder(recoveryTimeRecorder, openTelemetryLabels).register(this) + if (moduleConfig.recoveryTime) metricRecorder(recoveryTimeRecorder, otAttributes).register(this) else noopMetricRecorder lazy val persistentEvent: MetricRecorder[Long] = - if (moduleConfig.persistentEvent) metricRecorder(persistentEventRecorder, openTelemetryLabels).register(this) + if (moduleConfig.persistentEvent) metricRecorder(persistentEventRecorder, otAttributes).register(this) else noopMetricRecorder lazy val persistentEventTotal: Counter[Long] = - if (moduleConfig.persistentEventTotal) counter(persistentEventTotalCounter, openTelemetryLabels).register(this) + if (moduleConfig.persistentEventTotal) counter(persistentEventTotalCounter, otAttributes).register(this) else noopCounter lazy val snapshot: Counter[Long] = - if (moduleConfig.snapshot) counter(snapshotCounter, openTelemetryLabels).register(this) else noopCounter + if (moduleConfig.snapshot) counter(snapshotCounter, otAttributes).register(this) else noopCounter lazy val recoveryTotal: Counter[Long] = - if (moduleConfig.recoveryTotal) counter(recoveryTotalCounter, openTelemetryLabels).register(this) else noopCounter + if (moduleConfig.recoveryTotal) counter(recoveryTotalCounter, otAttributes).register(this) else noopCounter } } diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryStreamMetricsMonitor.scala b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryStreamMetricsMonitor.scala index bb41489bd..1c405b0b9 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryStreamMetricsMonitor.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryStreamMetricsMonitor.scala @@ -68,31 +68,31 @@ final class OpenTelemetryStreamMetricsMonitor( .setDescription("Amount of actors running streams on a system") .build() - private lazy val streamProcessedMessagesBuilder = new LongSumObserverBuilderAdapter[Labels]( + private lazy val streamProcessedMessagesBuilder = new LongSumObserverBuilderAdapter[Attributes]( meter .counterBuilder(metricNames.streamProcessed) .setDescription("Amount of messages processed by whole stream") ) - def bind(labels: EagerLabels): BoundMonitor = new StreamMetricsBoundMonitor(labels) + def bind(attributes: EagerAttributes): BoundMonitor = new StreamMetricsBoundMonitor(attributes) - final class StreamMetricsBoundMonitor(labels: EagerLabels) + final class StreamMetricsBoundMonitor(attributes: EagerAttributes) extends BoundMonitor with RegisterRoot with SynchronousInstrumentFactory { - private val openTelemetryLabels = LabelsFactory.of(labels.serialize) + private val openTelemetryAttributes = AttributesFactory.of(attributes.serialize) lazy val runningStreamsTotal: MetricRecorder[Long] = if (moduleConfig.runningStreamsTotal) - metricRecorder(runningStreamsTotalRecorder, openTelemetryLabels).register(this) + metricRecorder(runningStreamsTotalRecorder, openTelemetryAttributes).register(this) else noopMetricRecorder lazy val streamActorsTotal: MetricRecorder[Long] = if (moduleConfig.streamActorsTotal) - metricRecorder(streamActorsTotalRecorder, openTelemetryLabels).register(this) + metricRecorder(streamActorsTotalRecorder, openTelemetryAttributes).register(this) else noopMetricRecorder - lazy val streamProcessedMessages: MetricObserver[Long, Labels] = + lazy val streamProcessedMessages: MetricObserver[Long, Attributes] = if (moduleConfig.streamProcessedMessages) { streamProcessedMessagesBuilder.createObserver(this) } else MetricObserver.noop diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryStreamOperatorMetricsMonitor.scala b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryStreamOperatorMetricsMonitor.scala index 938550882..9a8b3e2dd 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryStreamOperatorMetricsMonitor.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryStreamOperatorMetricsMonitor.scala @@ -8,8 +8,8 @@ import io.scalac.mesmer.core.module.AkkaStreamModule import io.scalac.mesmer.extension.metric.MetricObserver import io.scalac.mesmer.extension.metric.RegisterRoot import io.scalac.mesmer.extension.metric.StreamOperatorMetricsMonitor +import io.scalac.mesmer.extension.metric.StreamOperatorMetricsMonitor.Attributes import io.scalac.mesmer.extension.metric.StreamOperatorMetricsMonitor.BoundMonitor -import io.scalac.mesmer.extension.metric.StreamOperatorMetricsMonitor.Labels import io.scalac.mesmer.extension.upstream.OpenTelemetryStreamOperatorMetricsMonitor.MetricNames import io.scalac.mesmer.extension.upstream.opentelemetry._ @@ -63,20 +63,20 @@ final class OpenTelemetryStreamOperatorMetricsMonitor( metricNames: MetricNames ) extends StreamOperatorMetricsMonitor { - private lazy val processedMessageAdapter = new LongSumObserverBuilderAdapter[Labels]( + private lazy val processedMessageAdapter = new LongSumObserverBuilderAdapter[Attributes]( meter .counterBuilder(metricNames.operatorProcessed) .setDescription("Amount of messages process by operator") ) - private lazy val operatorsAdapter = new GaugeBuilderAdapter[Labels]( + private lazy val operatorsAdapter = new GaugeBuilderAdapter[Attributes]( meter .gaugeBuilder(metricNames.runningOperators) .ofLongs() .setDescription("Amount of operators in a system") ) - private lazy val demandAdapter = new LongSumObserverBuilderAdapter[Labels]( + private lazy val demandAdapter = new LongSumObserverBuilderAdapter[Attributes]( meter .counterBuilder(metricNames.demand) .setDescription("Amount of messages demanded by operator") @@ -84,13 +84,13 @@ final class OpenTelemetryStreamOperatorMetricsMonitor( def bind(): StreamOperatorMetricsMonitor.BoundMonitor = new BoundMonitor with RegisterRoot { - lazy val processedMessages: MetricObserver[Long, Labels] = + lazy val processedMessages: MetricObserver[Long, Attributes] = if (moduleConfig.processedMessages) processedMessageAdapter.createObserver(this) else MetricObserver.noop - lazy val operators: MetricObserver[Long, Labels] = + lazy val operators: MetricObserver[Long, Attributes] = if (moduleConfig.operators) operatorsAdapter.createObserver(this) else MetricObserver.noop - lazy val demand: MetricObserver[Long, Labels] = + lazy val demand: MetricObserver[Long, Attributes] = if (moduleConfig.demand) demandAdapter.createObserver(this) else MetricObserver.noop } } diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/opentelemetry/Synchronized.scala b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/opentelemetry/Synchronized.scala index 9d8f60ba1..79f2ca96e 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/opentelemetry/Synchronized.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/opentelemetry/Synchronized.scala @@ -10,7 +10,7 @@ abstract class Synchronized(private val meter: Meter) extends BaseSynchronized { type Instrument[X] = WrappedSynchronousInstrument[X] - protected val otLabels: Attributes + protected val otAttributes: Attributes def atomically[A, B](first: Instrument[A], second: Instrument[B]): (A, B) => Unit = { (a, b) => first.putValue(a) diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/opentelemetry/WrappedAsynchronousInstrument.scala b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/opentelemetry/WrappedAsynchronousInstrument.scala index 352c718ba..3b8648e95 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/opentelemetry/WrappedAsynchronousInstrument.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/opentelemetry/WrappedAsynchronousInstrument.scala @@ -9,9 +9,9 @@ import io.opentelemetry.api.metrics._ import scala.jdk.CollectionConverters._ import scala.jdk.FunctionConverters._ -import io.scalac.mesmer.core.LabelSerializable +import io.scalac.mesmer.core.AttributesSerializable import io.scalac.mesmer.extension.metric.MetricObserver -import io.scalac.mesmer.extension.upstream.LabelsFactory +import io.scalac.mesmer.extension.upstream.AttributesFactory private object Defs { type WrappedResult[T] = (T, Attributes) => Unit @@ -21,25 +21,25 @@ private object Defs { import io.scalac.mesmer.extension.upstream.opentelemetry.Defs._ -final class GaugeBuilderAdapter[L <: LabelSerializable](builder: LongGaugeBuilder) +final class GaugeBuilderAdapter[L <: AttributesSerializable](builder: LongGaugeBuilder) extends MetricObserverBuilderAdapter[ObservableLongMeasurement, Long, L]( result => builder.buildWithCallback(result.asJava), longResultWrapper ) -final class LongUpDownSumObserverBuilderAdapter[L <: LabelSerializable](builder: LongUpDownCounterBuilder) +final class LongUpDownSumObserverBuilderAdapter[L <: AttributesSerializable](builder: LongUpDownCounterBuilder) extends MetricObserverBuilderAdapter[ObservableLongMeasurement, Long, L]( result => builder.buildWithCallback(result.asJava), longResultWrapper ) -final class LongSumObserverBuilderAdapter[L <: LabelSerializable](builder: LongCounterBuilder) +final class LongSumObserverBuilderAdapter[L <: AttributesSerializable](builder: LongCounterBuilder) extends MetricObserverBuilderAdapter[ObservableLongMeasurement, Long, L]( result => builder.buildWithCallback(result.asJava), longResultWrapper ) -sealed abstract class MetricObserverBuilderAdapter[R <: ObservableMeasurement, T, L <: LabelSerializable]( +sealed abstract class MetricObserverBuilderAdapter[R <: ObservableMeasurement, T, L <: AttributesSerializable]( // builder: AsynchronousInstrumentBuilder[R], register: (R => Unit) => Unit, wrapper: ResultWrapper[R, T] @@ -72,7 +72,7 @@ sealed abstract class MetricObserverBuilderAdapter[R <: ObservableMeasurement, T observers.foreach(_.update(wrapper(result))) } -final case class WrappedMetricObserver[T, L <: LabelSerializable] private (onSet: () => Unit) +final case class WrappedMetricObserver[T, L <: AttributesSerializable] private (onSet: () => Unit) extends MetricObserver[T, L] with WrappedInstrument { @@ -87,5 +87,7 @@ final case class WrappedMetricObserver[T, L <: LabelSerializable] private (onSet } def update(result: WrappedResult[T]): Unit = - valueUpdater.foreach(updater => updater((value: T, labels: L) => result(value, LabelsFactory.of(labels.serialize)))) + valueUpdater.foreach(updater => + updater((value: T, attributes: L) => result(value, AttributesFactory.of(attributes.serialize))) + ) } diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/opentelemetry/WrappedSynchronousInstrument.scala b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/opentelemetry/WrappedSynchronousInstrument.scala index e813bb3ae..d4ced51f7 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/opentelemetry/WrappedSynchronousInstrument.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/opentelemetry/WrappedSynchronousInstrument.scala @@ -11,9 +11,9 @@ trait SynchronousInstrumentFactory { private[upstream] def metricRecorder( underlying: LongHistogram, - attrs: Attributes + attributes: Attributes ): UnregisteredInstrument[WrappedLongValueRecorder] = { root => - val instrument = WrappedLongValueRecorder(underlying, attrs) + val instrument = WrappedLongValueRecorder(underlying, attributes) root.registerUnbind(instrument) instrument } @@ -29,9 +29,9 @@ trait SynchronousInstrumentFactory { private[upstream] def upDownCounter( underlying: LongUpDownCounter, - labels: Attributes + attributes: Attributes ): UnregisteredInstrument[WrappedUpDownCounter] = { root => - val instrument = WrappedUpDownCounter(underlying, labels) + val instrument = WrappedUpDownCounter(underlying, attributes) root.registerUnbind(instrument) instrument } @@ -73,24 +73,24 @@ case object NoopUpDownCounter extends WrappedNoOp with UpDownCounter[Any] { override type Self = Nothing } -final case class WrappedLongValueRecorder private[opentelemetry] (underlying: LongHistogram, attrs: Attributes) +final case class WrappedLongValueRecorder private[opentelemetry] (underlying: LongHistogram, attributes: Attributes) extends WrappedSynchronousInstrument[Long] with MetricRecorder[Long] { type Self = WrappedLongValueRecorder - private[this] lazy val bound = underlying.bind(attrs) + private[this] lazy val bound = underlying.bind(attributes) def setValue(value: Long): Unit = bound.record(value) def unbind(): Unit = bound.unbind() } -final case class WrappedUpDownCounter private[opentelemetry] (underlying: LongUpDownCounter, attrs: Attributes) +final case class WrappedUpDownCounter private[opentelemetry] (underlying: LongUpDownCounter, attributes: Attributes) extends WrappedSynchronousInstrument[Long] with UpDownCounter[Long] { type Self = WrappedUpDownCounter - private[this] lazy val bound = underlying.bind(attrs) + private[this] lazy val bound = underlying.bind(attributes) def decValue(value: Long): Unit = bound.add(-value) @@ -99,12 +99,12 @@ final case class WrappedUpDownCounter private[opentelemetry] (underlying: LongUp def unbind(): Unit = bound.unbind() } -final case class WrappedCounter private[opentelemetry] (underlying: LongCounter, attrs: Attributes) +final case class WrappedCounter private[opentelemetry] (underlying: LongCounter, attributes: Attributes) extends WrappedSynchronousInstrument[Long] with Counter[Long] { type Self = WrappedCounter - private[this] lazy val bound = underlying.bind(attrs) + private[this] lazy val bound = underlying.bind(attributes) def incValue(value: Long): Unit = bound.add(value) diff --git a/extension/src/multi-jvm/scala/io/scalac/mesmer/extension/DownTest.scala b/extension/src/multi-jvm/scala/io/scalac/mesmer/extension/DownTest.scala index b7df3d2bd..9f80f83b6 100644 --- a/extension/src/multi-jvm/scala/io/scalac/mesmer/extension/DownTest.scala +++ b/extension/src/multi-jvm/scala/io/scalac/mesmer/extension/DownTest.scala @@ -2,17 +2,17 @@ package io.scalac.mesmer.extension import akka.actor.typed.scaladsl.Behaviors import akka.actor.typed.scaladsl.adapter._ -import akka.actor.typed.{ActorSystem, SupervisorStrategy} +import akka.actor.typed.{ ActorSystem, SupervisorStrategy } import akka.cluster.Cluster -import akka.cluster.typed.{ClusterSingleton, SingletonActor} +import akka.cluster.typed.{ ClusterSingleton, SingletonActor } import akka.remote.testkit.MultiNodeSpec import akka.remote.transport.ThrottlerTransportAdapter.Direction import io.scalac.mesmer.core.util.ScalaTestMultiNodeSpec import io.scalac.mesmer.core.util.probe.ObserverCollector.ScheduledCollectorImpl import io.scalac.mesmer.extension.ThreeNodesConfig._ -import io.scalac.mesmer.extension.util.probe.BoundTestProbe.{Dec, Inc} +import io.scalac.mesmer.extension.util.probe.BoundTestProbe.{ Dec, Inc } import io.scalac.mesmer.extension.util.probe.ClusterMonitorTestProbe -import org.scalatest.{BeforeAndAfterAll, Inspectors} +import org.scalatest.{ BeforeAndAfterAll, Inspectors } import scala.concurrent.duration._ import scala.language.postfixOps diff --git a/extension/src/multi-jvm/scala/io/scalac/mesmer/extension/ReachabilityTest.scala b/extension/src/multi-jvm/scala/io/scalac/mesmer/extension/ReachabilityTest.scala index 84cb0209f..585c1833c 100644 --- a/extension/src/multi-jvm/scala/io/scalac/mesmer/extension/ReachabilityTest.scala +++ b/extension/src/multi-jvm/scala/io/scalac/mesmer/extension/ReachabilityTest.scala @@ -8,8 +8,7 @@ import akka.remote.transport.ThrottlerTransportAdapter.Direction import io.scalac.mesmer.core.util.ScalaTestMultiNodeSpec import io.scalac.mesmer.extension.util.probe.ClusterMonitorTestProbe import io.scalac.mesmer.core.util.probe.ObserverCollector.ScheduledCollectorImpl -import io.scalac.mesmer.extension.util.probe.BoundTestProbe.{Dec, Inc} -import io.scalac.mesmer.extension.util.probe.ClusterMonitorTestProbe +import io.scalac.mesmer.extension.util.probe.BoundTestProbe.{ Dec, Inc } import org.scalatest.Inspectors import scala.concurrent.duration._ diff --git a/extension/src/test/scala/io/scalac/mesmer/extension/ActorEventsMonitorActorTest.scala b/extension/src/test/scala/io/scalac/mesmer/extension/ActorEventsMonitorActorTest.scala index c54940996..690cc9c8a 100644 --- a/extension/src/test/scala/io/scalac/mesmer/extension/ActorEventsMonitorActorTest.scala +++ b/extension/src/test/scala/io/scalac/mesmer/extension/ActorEventsMonitorActorTest.scala @@ -35,7 +35,7 @@ import io.scalac.mesmer.core.util.probe.ObserverCollector.ManualCollectorImpl import io.scalac.mesmer.extension.ActorEventsMonitorActor._ import io.scalac.mesmer.extension.actor.ActorMetrics import io.scalac.mesmer.extension.actor.MutableActorMetricStorageFactory -import io.scalac.mesmer.extension.metric.ActorMetricsMonitor.Labels +import io.scalac.mesmer.extension.metric.ActorMetricsMonitor.Attributes import io.scalac.mesmer.extension.service.ActorTreeService import io.scalac.mesmer.extension.service.ActorTreeService.Command.GetActorTree import io.scalac.mesmer.extension.service.ActorTreeService.Command.TagSubscribe @@ -262,35 +262,35 @@ final class ActorEventsMonitorActorTest def runUpdaters()(implicit context: Context): Unit = context.monitor.collector.collectAll() - private def rootLabels(tree: Tree[ActorRefDetails]): Labels = - Labels(ActorPathOps.getPathString(tree.unfix.value.ref)) + private def rootLabels(tree: Tree[ActorRefDetails]): Attributes = + Attributes(ActorPathOps.getPathString(tree.unfix.value.ref)) - private def nonRootLabels(tree: Tree[ActorRefDetails]): Option[Labels] = - tree.unfix.foldRight[Option[Labels]] { + private def nonRootLabels(tree: Tree[ActorRefDetails]): Option[Attributes] = + tree.unfix.foldRight[Option[Attributes]] { case TreeF(value, Vector()) => - Some(Labels(ActorPathOps.getPathString(value.ref))) + Some(Attributes(ActorPathOps.getPathString(value.ref))) case TreeF(_, children) => Random.shuffle(children.flatten).headOption } behavior of "ActorEventsMonitor" private def expect( - selectProbe: ActorMonitorTestProbe => TestProbe[MetricObserverCommand[Labels]], - labels: Labels, + selectProbe: ActorMonitorTestProbe => TestProbe[MetricObserverCommand[Attributes]], + attributes: Attributes, value: Long )(implicit context: Context): Unit = selectProbe(context.monitor) .fishForMessage(pingOffset) { - case MetricObserved(_, `labels`) => FishingOutcomes.complete() - case _ => FishingOutcomes.continueAndIgnore() + case MetricObserved(_, `attributes`) => FishingOutcomes.complete() + case _ => FishingOutcomes.continueAndIgnore() } - .loneElement should be(MetricObserved(value, labels)) + .loneElement should be(MetricObserved(value, attributes)) /** * Checks aggregation when there were several metrics collection messages but no export in the meantime */ private def collectMany[T]( - selectProbe: ActorMonitorTestProbe => TestProbe[MetricObserverCommand[Labels]], + selectProbe: ActorMonitorTestProbe => TestProbe[MetricObserverCommand[Attributes]], extract: ActorMetrics => T, name: String, addTo: (T, T) => T, @@ -300,7 +300,7 @@ final class ActorEventsMonitorActorTest val refs = actorConfiguration(spawnTree(3), ActorConfiguration.instanceConfig) val actorService = system.systemActorOf(constRefsActorServiceTree(refs), createUniqueId) - val labels = Labels(ActorPathOps.getPathString(refs.unfix.value.ref)) + val attributes = Attributes(ActorPathOps.getPathString(refs.unfix.value.ref)) val Seq(firstMetrics, metricsTransitions @ _*) = metrics val refsWithMetrics = refs.unfix.mapValues { details => @@ -324,12 +324,12 @@ final class ActorEventsMonitorActorTest } runUpdaters() - expect(selectProbe, labels, expectedValue) + expect(selectProbe, attributes, expectedValue) } } private def collect[T]( - selectProbe: ActorMonitorTestProbe => TestProbe[MetricObserverCommand[Labels]], + selectProbe: ActorMonitorTestProbe => TestProbe[MetricObserverCommand[Attributes]], extract: ActorMetrics => Long, name: String ): Unit = @@ -337,7 +337,7 @@ final class ActorEventsMonitorActorTest val refs = actorConfiguration(spawnTree(3), ActorConfiguration.instanceConfig) val actorService = system.systemActorOf(constRefsActorServiceTree(refs), createUniqueId) - val labels = Labels(ActorPathOps.getPathString(refs.unfix.value.ref)) + val attributes = Attributes(ActorPathOps.getPathString(refs.unfix.value.ref)) val refsWithMetrics = refs.unfix.mapValues { details => details.ref -> ConstActorMetrics @@ -351,13 +351,13 @@ final class ActorEventsMonitorActorTest collectActorMetrics(ackProbe) runUpdaters() - expect(selectProbe, labels, extract(ConstActorMetrics)) + expect(selectProbe, attributes, extract(ConstActorMetrics)) } } private def reportingAggregation[T]( - selectProbe: ActorMonitorTestProbe => TestProbe[MetricObserverCommand[Labels]], + selectProbe: ActorMonitorTestProbe => TestProbe[MetricObserverCommand[Attributes]], extract: ActorMetrics => T, name: String, sum: (T, T) => T, @@ -369,7 +369,7 @@ final class ActorEventsMonitorActorTest val refs = rootGrouping(spawnTree(3), ActorConfiguration.instanceConfig) val actorService = system.systemActorOf(constRefsActorServiceTree(refs), createUniqueId) - val labels = rootLabels(refs) + val attributes = rootLabels(refs) val refsWithMetrics = addMetrics(refs) @@ -385,14 +385,14 @@ final class ActorEventsMonitorActorTest collectActorMetrics(ackProbe) runUpdaters() - expect(selectProbe, labels, expectedValue) + expect(selectProbe, attributes, expectedValue) } } it should s"aggregate ${name} in root node when child have disabled config" in { val refs = rootGrouping(spawnTree(3), ActorConfiguration.disabledConfig) val actorService = system.systemActorOf(constRefsActorServiceTree(refs), createUniqueId) - val labels = rootLabels(refs) + val attributes = rootLabels(refs) val refsWithMetrics = addMetrics(refs) val expectedValue = extractLong(refsWithMetrics.unfix.foldRight[T] { case TreeF((_, metrics), children) => @@ -407,7 +407,7 @@ final class ActorEventsMonitorActorTest collectActorMetrics(ackProbe) runUpdaters() - expect(selectProbe, labels, expectedValue) + expect(selectProbe, attributes, expectedValue) } } @@ -415,12 +415,12 @@ final class ActorEventsMonitorActorTest it should s"publish ${name} for non-root node when child have instance config" in { val refs = rootGrouping(spawnTree(3), ActorConfiguration.instanceConfig) val actorService = system.systemActorOf(constRefsActorServiceTree(refs), createUniqueId) - val labels = nonRootLabels(refs).value + val attributes = nonRootLabels(refs).value val refsWithMetrics = addMetrics(refs) val expectedValue = extractLong(extract(refsWithMetrics.unfix.find { case (ref, _) => - ref.path.toStringWithoutAddress == labels.actorPath + ref.path.toStringWithoutAddress == attributes.actorPath }.map(_._2).value)) testCaseWithSetupAndContext { ctx => @@ -431,14 +431,14 @@ final class ActorEventsMonitorActorTest collectActorMetrics(ackProbe) runUpdaters() - expect(selectProbe, labels, expectedValue) + expect(selectProbe, attributes, expectedValue) } } it should s"not publish ${name} for non-root node when child have disabled config" in { val refs = rootGrouping(spawnTree(3), ActorConfiguration.disabledConfig) val actorService = system.systemActorOf(constRefsActorServiceTree(refs), createUniqueId) - val labels = rootLabels(refs) + val attributes = rootLabels(refs) val refsWithMetrics = addMetrics(refs) @@ -453,7 +453,7 @@ final class ActorEventsMonitorActorTest val probe = selectProbe(context.monitor) inside(probe.receiveMessage) { case MetricObserved(_, l) => - l should be(labels) + l should be(attributes) } probe.expectNoMessage() } @@ -469,7 +469,7 @@ final class ActorEventsMonitorActorTest val actorService = system.systemActorOf(subscribeAllConstRefsActorServiceTree(terminatingRefs)(rootRef), createUniqueId) - val labels = rootLabels(allRefs) + val attributes = rootLabels(allRefs) val refsWithMetrics = addMetrics(allRefs) @@ -485,7 +485,7 @@ final class ActorEventsMonitorActorTest collectActorMetrics(ackProbe) runUpdaters() - expect(selectProbe, labels, expectedValue) + expect(selectProbe, attributes, expectedValue) } } @@ -499,7 +499,7 @@ final class ActorEventsMonitorActorTest val actorService = system.systemActorOf(subscribeAllConstRefsActorServiceTree(terminatingRefs)(rootRef), createUniqueId) - val labels = rootLabels(allRefs) + val attributes = rootLabels(allRefs) val refsWithMetrics = addMetrics(allRefs) @@ -530,14 +530,14 @@ final class ActorEventsMonitorActorTest collectActorMetrics(ackProbe) runUpdaters() - expect(selectProbe, labels, expectedValue) + expect(selectProbe, attributes, expectedValue) } } } def allBehaviorsLong( - selectProbe: ActorMonitorTestProbe => TestProbe[MetricObserverCommand[Labels]], + selectProbe: ActorMonitorTestProbe => TestProbe[MetricObserverCommand[Attributes]], extract: ActorMetrics => Option[Long], name: String ): Unit = { @@ -555,10 +555,10 @@ final class ActorEventsMonitorActorTest } def allBehaviorsAgg( - probeMin: ActorMonitorTestProbe => TestProbe[MetricObserverCommand[Labels]], - probeMax: ActorMonitorTestProbe => TestProbe[MetricObserverCommand[Labels]], - probeSum: ActorMonitorTestProbe => TestProbe[MetricObserverCommand[Labels]], - probeCount: ActorMonitorTestProbe => TestProbe[MetricObserverCommand[Labels]], + probeMin: ActorMonitorTestProbe => TestProbe[MetricObserverCommand[Attributes]], + probeMax: ActorMonitorTestProbe => TestProbe[MetricObserverCommand[Attributes]], + probeSum: ActorMonitorTestProbe => TestProbe[MetricObserverCommand[Attributes]], + probeCount: ActorMonitorTestProbe => TestProbe[MetricObserverCommand[Attributes]], extract: ActorMetrics => Option[LongMinMaxSumCountAggregationImpl], name: String ): Unit = { @@ -566,7 +566,7 @@ final class ActorEventsMonitorActorTest ( String, LongMinMaxSumCountAggregationImpl => Long, - ActorMonitorTestProbe => TestProbe[MetricObserverCommand[Labels]] + ActorMonitorTestProbe => TestProbe[MetricObserverCommand[Attributes]] ) ] = List(("min", _.min, probeMin), ("max", _.max, probeMax), ("sum", _.sum, probeSum), ("count", _.count, probeCount)) diff --git a/extension/src/test/scala/io/scalac/mesmer/extension/AkkaStreamMonitoringTest.scala b/extension/src/test/scala/io/scalac/mesmer/extension/AkkaStreamMonitoringTest.scala index 71bcd25c4..7e15565ef 100644 --- a/extension/src/test/scala/io/scalac/mesmer/extension/AkkaStreamMonitoringTest.scala +++ b/extension/src/test/scala/io/scalac/mesmer/extension/AkkaStreamMonitoringTest.scala @@ -197,18 +197,18 @@ class AkkaStreamMonitoringTest val processed = operations.processedTestProbe.receiveMessages(ExpectedCount * (Flows + 1), OperationsPing) val demand = operations.demandTestProbe.receiveMessages(ExpectedCount * (Flows + 1), OperationsPing) - forAll(processed)(inside(_) { case MetricObserved(value, labels) => + forAll(processed)(inside(_) { case MetricObserved(value, attributes) => value shouldBe Push - labels.node shouldBe empty + attributes.node shouldBe empty }) - operators.collect { case MetricObserved(_, labels) => - labels.operator.name + operators.collect { case MetricObserved(_, attributes) => + attributes.operator.name }.distinct should contain theSameElementsAs StagesNames - forAll(demand)(inside(_) { case MetricObserved(value, labels) => + forAll(demand)(inside(_) { case MetricObserved(value, attributes) => value shouldBe Pull - labels.node shouldBe empty + attributes.node shouldBe empty }) } diff --git a/extension/src/test/scala/io/scalac/mesmer/extension/ClusterSelfNodeEventsActorTest.scala b/extension/src/test/scala/io/scalac/mesmer/extension/ClusterSelfNodeEventsActorTest.scala index 09e52ad39..5bce87533 100644 --- a/extension/src/test/scala/io/scalac/mesmer/extension/ClusterSelfNodeEventsActorTest.scala +++ b/extension/src/test/scala/io/scalac/mesmer/extension/ClusterSelfNodeEventsActorTest.scala @@ -10,7 +10,7 @@ import scala.concurrent.duration._ import io.scalac.mesmer.core.model._ import io.scalac.mesmer.core.util.TestBehaviors import io.scalac.mesmer.core.util.TestBehaviors.SameStop.Command.Same -import io.scalac.mesmer.extension.metric.ClusterMetricsMonitor.Labels +import io.scalac.mesmer.extension.metric.ClusterMetricsMonitor.Attributes import io.scalac.mesmer.extension.util.SingleNodeClusterSpec import io.scalac.mesmer.extension.util.probe.BoundTestProbe._ @@ -22,18 +22,18 @@ class ClusterSelfNodeEventsActorTest extends AsyncFlatSpec with SingleNodeCluste system.systemActorOf(ClusterRegionsMonitorActor(monitor), "sut") for (i <- 0 until 10) ref ! ShardingEnvelope(s"test_$i", Same) val messages = monitor.entityPerRegionProbe.receiveMessages(2, 3 * pingOffset) - messages should contain(MetricObserved(10, Labels(member.uniqueAddress.toNode, Some(region)))) + messages should contain(MetricObserved(10, Attributes(member.uniqueAddress.toNode, Some(region)))) } it should "show a amount of shards per region" in setup(TestBehaviors.SameStop.apply) { case (system, member, ref, monitor, region) => system.systemActorOf(ClusterRegionsMonitorActor(monitor), "sut") for (i <- 0 until 10) ref ! ShardingEnvelope(s"test_$i", Same) - val messages = monitor.shardPerRegionsProbe.receiveMessages(2, 3 * pingOffset) - val ExpectedLabels = Labels(member.uniqueAddress.toNode, Some(region)) + val messages = monitor.shardPerRegionsProbe.receiveMessages(2, 3 * pingOffset) + val ExpectedAttributes = Attributes(member.uniqueAddress.toNode, Some(region)) forAtLeast(1, messages)( _ should matchPattern { - case MetricObserved(value, ExpectedLabels) if value > 0 => + case MetricObserved(value, ExpectedAttributes) if value > 0 => } ) } @@ -43,7 +43,7 @@ class ClusterSelfNodeEventsActorTest extends AsyncFlatSpec with SingleNodeCluste system.systemActorOf(ClusterRegionsMonitorActor(monitor), "sut") for (i <- 0 until 10) ref ! ShardingEnvelope(s"test_$i", Same) val messages = monitor.entitiesOnNodeProbe.receiveMessages(2, 3 * pingOffset) - messages should contain(MetricObserved(10, Labels(member.uniqueAddress.toNode))) + messages should contain(MetricObserved(10, Attributes(member.uniqueAddress.toNode))) } it should "show proper amount of entities on node with 2 regions" in setupN(TestBehaviors.SameStop.apply, n = 2) { @@ -51,7 +51,7 @@ class ClusterSelfNodeEventsActorTest extends AsyncFlatSpec with SingleNodeCluste system.systemActorOf(ClusterRegionsMonitorActor(monitor), "sut") for (i <- 0 until 10) refs(i % refs.length) ! ShardingEnvelope(s"test_$i", Same) val messages = monitor.entitiesOnNodeProbe.receiveMessages(2, 3 * pingOffset) - messages should contain(MetricObserved(10, Labels(member.uniqueAddress.toNode))) + messages should contain(MetricObserved(10, Attributes(member.uniqueAddress.toNode))) } it should "show proper amount of reachable nodes" in setup(TestBehaviors.SameStop.apply) { diff --git a/extension/src/test/scala/io/scalac/mesmer/extension/HttpEventsActorTest.scala b/extension/src/test/scala/io/scalac/mesmer/extension/HttpEventsActorTest.scala index 3e0dc7d71..51f8f91dd 100644 --- a/extension/src/test/scala/io/scalac/mesmer/extension/HttpEventsActorTest.scala +++ b/extension/src/test/scala/io/scalac/mesmer/extension/HttpEventsActorTest.scala @@ -65,101 +65,103 @@ class HttpEventsActorTest protected def createMonitor(implicit s: ActorSystem[_]): Monitor = MonitorImpl(new HttpMonitorTestProbe()(s), new HttpConnectionMetricsTestProbe()(s)) - def connectionStarted(labels: HttpConnectionMetricsMonitor.Labels): Unit = - EventBus(system).publishEvent(ConnectionStarted(labels.interface, labels.port)) + def connectionStarted(attributes: HttpConnectionMetricsMonitor.Attributes): Unit = + EventBus(system).publishEvent(ConnectionStarted(attributes.interface, attributes.port)) - def connectionCompleted(labels: HttpConnectionMetricsMonitor.Labels): Unit = - EventBus(system).publishEvent(ConnectionCompleted(labels.interface, labels.port)) + def connectionCompleted(attributes: HttpConnectionMetricsMonitor.Attributes): Unit = + EventBus(system).publishEvent(ConnectionCompleted(attributes.interface, attributes.port)) - def requestStarted(id: String, labels: HttpMetricsMonitor.Labels): Unit = - EventBus(system).publishEvent(RequestStarted(id, Timestamp.create(), labels.path, labels.method)) + def requestStarted(id: String, attributes: HttpMetricsMonitor.Attributes): Unit = + EventBus(system).publishEvent(RequestStarted(id, Timestamp.create(), attributes.path, attributes.method)) def requestCompleted(id: String, status: model.Status): Unit = EventBus(system).publishEvent(RequestCompleted(id, Timestamp.create(), status)) "HttpEventsActor" should "collect metrics for single request" in testCase { implicit c => - val status: model.Status = "200" - val expectedConnectionLabels = HttpConnectionMetricsMonitor.Labels(None, "0.0.0.0", 8080) - val expectedRequestLabels = HttpMetricsMonitor.Labels(None, "/api/v1/test", "GET", status) + val status: model.Status = "200" + val expectedConnectionAttributes = HttpConnectionMetricsMonitor.Attributes(None, "0.0.0.0", 8080) + val expectedRequestAttributes = HttpMetricsMonitor.Attributes(None, "/api/v1/test", "GET", status) - connectionStarted(expectedConnectionLabels) + connectionStarted(expectedConnectionAttributes) eventually(monitor.connection.boundSize shouldBe 1)(patienceConfig, implicitly, implicitly) val id = createUniqueId - requestStarted(id, expectedRequestLabels) + requestStarted(id, expectedRequestAttributes) Thread.sleep(1050) requestCompleted(id, status) eventually(monitor.request.boundSize shouldBe 1)(patienceConfig, implicitly, implicitly) - monitor.connection.boundLabels should contain theSameElementsAs Seq(expectedConnectionLabels) - monitor.request.boundLabels should contain theSameElementsAs Seq(expectedRequestLabels) + monitor.connection.boundAttributes should contain theSameElementsAs Seq(expectedConnectionAttributes) + monitor.request.boundAttributes should contain theSameElementsAs Seq(expectedRequestAttributes) - val requestBoundProbes = monitor.request.probes(expectedRequestLabels) + val requestBoundProbes = monitor.request.probes(expectedRequestAttributes) requestBoundProbes.value.requestCounterProbe.receiveMessage() should be(Inc(1L)) inside(requestBoundProbes.value.requestTimeProbe.receiveMessage()) { case MetricRecorded(value) => value shouldBe 1000L +- 100L } - val connectionBoundProbes = monitor.connection.probes(expectedConnectionLabels) + val connectionBoundProbes = monitor.connection.probes(expectedConnectionAttributes) connectionBoundProbes.value.connectionCounterProbe.receiveMessage() should be(Inc(1L)) - connectionCompleted(expectedConnectionLabels) + connectionCompleted(expectedConnectionAttributes) connectionBoundProbes.value.connectionCounterProbe.receiveMessage() should be(Dec(1L)) } - it should "reuse monitors for same labels" in testCaseWith(_.withCaching) { implicit c => - val expectedConnectionLabels = List( - HttpConnectionMetricsMonitor.Labels(None, "0.0.0.0", 8080), - HttpConnectionMetricsMonitor.Labels(None, "0.0.0.0", 8081) + it should "reuse monitors for same attributes" in testCaseWith(_.withCaching) { implicit c => + val expectedConnectionAttributes = List( + HttpConnectionMetricsMonitor.Attributes(None, "0.0.0.0", 8080), + HttpConnectionMetricsMonitor.Attributes(None, "0.0.0.0", 8081) ) - val expectedRequestLabels = List( - HttpMetricsMonitor.Labels(None, "/api/v1/test", "GET", "200"), - HttpMetricsMonitor.Labels(None, "/api/v2/test", "POST", "201") + val expectedRequestAttributes = List( + HttpMetricsMonitor.Attributes(None, "/api/v1/test", "GET", "200"), + HttpMetricsMonitor.Attributes(None, "/api/v2/test", "POST", "201") ) val requestCount = 10 - expectedConnectionLabels.foreach(connectionStarted) + expectedConnectionAttributes.foreach(connectionStarted) for { - label <- expectedRequestLabels - id <- List.fill(requestCount)(createUniqueId) + attribute <- expectedRequestAttributes + id <- List.fill(requestCount)(createUniqueId) } { - requestStarted(id, label) - requestCompleted(id, label.status) + requestStarted(id, attribute) + requestCompleted(id, attribute.status) } - expectedConnectionLabels.foreach(connectionCompleted) + expectedConnectionAttributes.foreach(connectionCompleted) - monitor.connection.globalConnectionCounter.receiveMessages(2 * expectedConnectionLabels.size) - monitor.request.globalRequestCounter.receiveMessages(requestCount * expectedRequestLabels.size) + monitor.connection.globalConnectionCounter.receiveMessages(2 * expectedConnectionAttributes.size) + monitor.request.globalRequestCounter.receiveMessages(requestCount * expectedRequestAttributes.size) - monitor.connection.binds should be(expectedConnectionLabels.size) - monitor.request.binds should be(expectedRequestLabels.size) + monitor.connection.binds should be(expectedConnectionAttributes.size) + monitor.request.binds should be(expectedRequestAttributes.size) } it should "collect metric for several concurrent requests" in testCaseWith(_.withCaching) { implicit c => - val connectionLabels = List.tabulate(10)(i => HttpConnectionMetricsMonitor.Labels(None, "0.0.0.0", 8080 + i)) - connectionLabels.foreach(connectionStarted) + val connectionAttributes = + List.tabulate(10)(i => HttpConnectionMetricsMonitor.Attributes(None, "0.0.0.0", 8080 + i)) + connectionAttributes.foreach(connectionStarted) - val requestLabels = List.fill(10)(createUniqueId).map(id => HttpMetricsMonitor.Labels(None, id, "GET", "204")) - val requests = requestLabels.map(l => createUniqueId -> l).toMap + val requestAttributes = + List.fill(10)(createUniqueId).map(id => HttpMetricsMonitor.Attributes(None, id, "GET", "204")) + val requests = requestAttributes.map(l => createUniqueId -> l).toMap requests.foreach(Function.tupled(requestStarted)) Thread.sleep(1050) - requests.foreach { case (id, labels) => - requestCompleted(id, labels.status) + requests.foreach { case (id, attributes) => + requestCompleted(id, attributes.status) } - connectionLabels.foreach(connectionCompleted) + connectionAttributes.foreach(connectionCompleted) - monitor.connection.globalConnectionCounter.receiveMessages(connectionLabels.size) + monitor.connection.globalConnectionCounter.receiveMessages(connectionAttributes.size) monitor.request.globalRequestCounter.receiveMessages(requests.size) - monitor.connection.boundLabels should contain theSameElementsAs connectionLabels - monitor.request.boundLabels should contain theSameElementsAs requestLabels + monitor.connection.boundAttributes should contain theSameElementsAs connectionAttributes + monitor.request.boundAttributes should contain theSameElementsAs requestAttributes - val connectionProbes = connectionLabels.flatMap(monitor.connection.probes) - connectionProbes should have size connectionLabels.size + val connectionProbes = connectionAttributes.flatMap(monitor.connection.probes) + connectionProbes should have size connectionAttributes.size forAll(connectionProbes) { probes => import probes._ connectionCounterProbe.within(500 milliseconds) { @@ -167,8 +169,8 @@ class HttpEventsActorTest } } - val requestProbes = requestLabels.flatMap(monitor.request.probes) - requestProbes should have size requestLabels.size + val requestProbes = requestAttributes.flatMap(monitor.request.probes) + requestProbes should have size requestAttributes.size forAll(requestProbes) { probes => import probes._ requestCounterProbe.within(500 millis) { diff --git a/extension/src/test/scala/io/scalac/mesmer/extension/PersistenceEventsActorTest.scala b/extension/src/test/scala/io/scalac/mesmer/extension/PersistenceEventsActorTest.scala index 1aa4f9fbe..7718a6112 100644 --- a/extension/src/test/scala/io/scalac/mesmer/extension/PersistenceEventsActorTest.scala +++ b/extension/src/test/scala/io/scalac/mesmer/extension/PersistenceEventsActorTest.scala @@ -20,7 +20,7 @@ import io.scalac.mesmer.core.util.TestCase.MonitorTestCaseContext.BasicContext import io.scalac.mesmer.core.util.TestConfig import io.scalac.mesmer.core.util.Timestamp import io.scalac.mesmer.extension.metric.CachingMonitor -import io.scalac.mesmer.extension.metric.PersistenceMetricsMonitor.Labels +import io.scalac.mesmer.extension.metric.PersistenceMetricsMonitor.Attributes import io.scalac.mesmer.extension.persistence.ImmutablePersistStorage import io.scalac.mesmer.extension.persistence.ImmutableRecoveryStorage import io.scalac.mesmer.extension.util.IdentityPathService @@ -51,24 +51,30 @@ class PersistenceEventsActorTest protected def createMonitor(implicit system: ActorSystem[_]): PersistenceMonitorTestProbe = new PersistenceMonitorTestProbe() - def recoveryStarted(labels: Labels)(implicit ctx: BasicContext[PersistenceMonitorTestProbe]): Unit = - EventBus(system).publishEvent(RecoveryStarted(labels.path, labels.persistenceId, Timestamp.create())) + def recoveryStarted(attributes: Attributes)(implicit ctx: BasicContext[PersistenceMonitorTestProbe]): Unit = + EventBus(system).publishEvent(RecoveryStarted(attributes.path, attributes.persistenceId, Timestamp.create())) - def recoveryFinished(labels: Labels)(implicit ctx: BasicContext[PersistenceMonitorTestProbe]): Unit = - EventBus(system).publishEvent(RecoveryFinished(labels.path, labels.persistenceId, Timestamp.create())) + def recoveryFinished(attributes: Attributes)(implicit ctx: BasicContext[PersistenceMonitorTestProbe]): Unit = + EventBus(system).publishEvent(RecoveryFinished(attributes.path, attributes.persistenceId, Timestamp.create())) - def persistEventStarted(seqNo: Long, labels: Labels)(implicit ctx: BasicContext[PersistenceMonitorTestProbe]): Unit = + def persistEventStarted(seqNo: Long, attributes: Attributes)(implicit + ctx: BasicContext[PersistenceMonitorTestProbe] + ): Unit = EventBus(system).publishEvent( - PersistingEventStarted(labels.path, labels.persistenceId, seqNo, Timestamp.create()) + PersistingEventStarted(attributes.path, attributes.persistenceId, seqNo, Timestamp.create()) ) - def persistEventFinished(seqNo: Long, labels: Labels)(implicit ctx: BasicContext[PersistenceMonitorTestProbe]): Unit = + def persistEventFinished(seqNo: Long, attributes: Attributes)(implicit + ctx: BasicContext[PersistenceMonitorTestProbe] + ): Unit = EventBus(system).publishEvent( - PersistingEventFinished(labels.path, labels.persistenceId, seqNo, Timestamp.create()) + PersistingEventFinished(attributes.path, attributes.persistenceId, seqNo, Timestamp.create()) ) - def snapshotCreated(seqNo: Long, labels: Labels)(implicit ctx: BasicContext[PersistenceMonitorTestProbe]): Unit = - EventBus(system).publishEvent(SnapshotCreated(labels.path, labels.persistenceId, seqNo, Timestamp.create())) + def snapshotCreated(seqNo: Long, attributes: Attributes)(implicit + ctx: BasicContext[PersistenceMonitorTestProbe] + ): Unit = + EventBus(system).publishEvent(SnapshotCreated(attributes.path, attributes.persistenceId, seqNo, Timestamp.create())) def expectMetricsUpdates(monitor: PersistenceMonitorTestProbe, amount: Int): Unit = monitor.globalCounter.within(1 second) { @@ -78,13 +84,13 @@ class PersistenceEventsActorTest } "PersistenceEventsActor" should "capture recovery time" in testCase { implicit c => - val expectedLabels = Labels(None, "/some/path", createUniqueId) - recoveryStarted(expectedLabels) + val expectedAttributes = Attributes(None, "/some/path", createUniqueId) + recoveryStarted(expectedAttributes) Thread.sleep(1050) - recoveryFinished(expectedLabels) + recoveryFinished(expectedAttributes) expectMetricsUpdates(monitor, 1) - monitor.boundLabels should have size 1 - val probes = monitor.boundLabels.flatMap(monitor.probes).loneElement + monitor.boundAttributes should have size 1 + val probes = monitor.boundAttributes.flatMap(monitor.probes).loneElement probes.recoveryTotalProbe.receiveMessage() should be(Inc(1L)) inside(probes.recoveryTimeProbe.receiveMessage()) { case MetricRecorded(value) => value should be(1000L +- 100) @@ -92,14 +98,14 @@ class PersistenceEventsActorTest } it should "capture persist event time" in testCase { implicit c => - val seqNo = 100L - val expectedLabels = Labels(None, "/some/path", createUniqueId) - persistEventStarted(seqNo, expectedLabels) + val seqNo = 100L + val expectedAttributes = Attributes(None, "/some/path", createUniqueId) + persistEventStarted(seqNo, expectedAttributes) Thread.sleep(1050) - persistEventFinished(seqNo, expectedLabels) + persistEventFinished(seqNo, expectedAttributes) expectMetricsUpdates(monitor, 1) - monitor.boundLabels should have size 1 - val probes = monitor.boundLabels.flatMap(monitor.probes).loneElement + monitor.boundAttributes should have size 1 + val probes = monitor.boundAttributes.flatMap(monitor.probes).loneElement probes.persistentEventTotalProbe.receiveMessage() should be(Inc(1L)) inside(probes.persistentEventProbe.receiveMessage()) { case MetricRecorded(value) => value should be(1000L +- 100) @@ -108,17 +114,17 @@ class PersistenceEventsActorTest it should "capture amount of snapshots for same entity with same monitor" in testCaseWith(_.withCaching) { implicit c => - val seqNumbers = (100 to 140 by 5).toList - val expectedLabels = Labels(None, "/some/path", createUniqueId) + val seqNumbers = (100 to 140 by 5).toList + val expectedAttributes = Attributes(None, "/some/path", createUniqueId) for { seqNo <- seqNumbers - } snapshotCreated(seqNo, expectedLabels) + } snapshotCreated(seqNo, expectedAttributes) expectMetricsUpdates(monitor, seqNumbers.size) - monitor.boundLabels should have size 1 + monitor.boundAttributes should have size 1 monitor.binds should be(1) - val probes = monitor.boundLabels.flatMap(monitor.probes).loneElement + val probes = monitor.boundAttributes.flatMap(monitor.probes).loneElement forAll(probes.snapshotProbe.receiveMessages(seqNumbers.size))(_ should be(Inc(1L))) } @@ -126,45 +132,45 @@ class PersistenceEventsActorTest _.withCaching ) { implicit c => val seqNumbers = (100 to 140 by 5).toList - val expectedLabels = List.fill(5) { + val expectedAttributes = List.fill(5) { val id = createUniqueId - Labels(None, s"/some/path/$id", id) + Attributes(None, s"/some/path/$id", id) } for { - seqNo <- seqNumbers - labels <- expectedLabels - } snapshotCreated(seqNo, labels) + seqNo <- seqNumbers + attributes <- expectedAttributes + } snapshotCreated(seqNo, attributes) - expectMetricsUpdates(monitor, seqNumbers.size * expectedLabels.size) - monitor.boundLabels should have size expectedLabels.size - monitor.binds should be(expectedLabels.size) + expectMetricsUpdates(monitor, seqNumbers.size * expectedAttributes.size) + monitor.boundAttributes should have size expectedAttributes.size + monitor.binds should be(expectedAttributes.size) - val allProbes = monitor.boundLabels.flatMap(monitor.probes) - allProbes should have size expectedLabels.size + val allProbes = monitor.boundAttributes.flatMap(monitor.probes) + allProbes should have size expectedAttributes.size forAll(allProbes)(probes => forAll(probes.snapshotProbe.receiveMessages(seqNumbers.size))(_ should be(Inc(1L)))) } it should "capture persist event time with resued monitors for many events" in testCaseWith(_.withCaching) { implicit c => val seqNo = 150 - val expectedLabels = List.fill(5) { + val expectedAttributes = List.fill(5) { val id = createUniqueId - Labels(None, s"/some/path/$id", id) + Attributes(None, s"/some/path/$id", id) } for { - labels <- expectedLabels - } persistEventStarted(seqNo, labels) + attributes <- expectedAttributes + } persistEventStarted(seqNo, attributes) Thread.sleep(1050) for { - labels <- expectedLabels - } persistEventFinished(seqNo, labels) + attributes <- expectedAttributes + } persistEventFinished(seqNo, attributes) - expectMetricsUpdates(monitor, expectedLabels.size) - monitor.boundLabels should have size expectedLabels.size - monitor.binds should be(expectedLabels.size) + expectMetricsUpdates(monitor, expectedAttributes.size) + monitor.boundAttributes should have size expectedAttributes.size + monitor.binds should be(expectedAttributes.size) - val allProbes = monitor.boundLabels.flatMap(monitor.probes) - allProbes should have size expectedLabels.size + val allProbes = monitor.boundAttributes.flatMap(monitor.probes) + allProbes should have size expectedAttributes.size forAll(allProbes) { probes => probes.persistentEventTotalProbe.receiveMessage() should be(Inc(1L)) inside(probes.persistentEventProbe.receiveMessage()) { case MetricRecorded(value) => @@ -177,34 +183,34 @@ class PersistenceEventsActorTest val seqNbs = List(150, 151, 152) val expectedRecoveryTime = 1000L val expectedPersistEventTime = 500L - val expectedLabels = List.fill(5) { + val expectedAttributes = List.fill(5) { val id = createUniqueId - Labels(None, s"/some/path/$id", id) + Attributes(None, s"/some/path/$id", id) } - expectedLabels.foreach(recoveryStarted) + expectedAttributes.foreach(recoveryStarted) Thread.sleep(expectedRecoveryTime + 50L) - expectedLabels.foreach(recoveryFinished) + expectedAttributes.foreach(recoveryFinished) seqNbs.foreach { seqNo => for { - labels <- expectedLabels - } persistEventStarted(seqNo, labels) + attributes <- expectedAttributes + } persistEventStarted(seqNo, attributes) Thread.sleep(expectedPersistEventTime + 50L) for { - labels <- expectedLabels + attributes <- expectedAttributes } { - snapshotCreated(seqNo, labels) - persistEventFinished(seqNo, labels) + snapshotCreated(seqNo, attributes) + persistEventFinished(seqNo, attributes) } } - expectMetricsUpdates(monitor, expectedLabels.size * (1 + seqNbs.size * 2)) - monitor.boundLabels should have size expectedLabels.size - monitor.binds should be(expectedLabels.size) + expectMetricsUpdates(monitor, expectedAttributes.size * (1 + seqNbs.size * 2)) + monitor.boundAttributes should have size expectedAttributes.size + monitor.binds should be(expectedAttributes.size) - val allProbes = monitor.boundLabels.flatMap(monitor.probes) - allProbes should have size expectedLabels.size + val allProbes = monitor.boundAttributes.flatMap(monitor.probes) + allProbes should have size expectedAttributes.size forAll(allProbes) { probes => forAll(probes.persistentEventTotalProbe.receiveMessages(seqNbs.size))(_ should be(Inc(1L))) forAll(probes.persistentEventProbe.receiveMessages(seqNbs.size))(mr => diff --git a/extension/src/test/scala/io/scalac/mesmer/extension/metric/CachingMonitorTest.scala b/extension/src/test/scala/io/scalac/mesmer/extension/metric/CachingMonitorTest.scala index ab9f60d7a..a00c49543 100644 --- a/extension/src/test/scala/io/scalac/mesmer/extension/metric/CachingMonitorTest.scala +++ b/extension/src/test/scala/io/scalac/mesmer/extension/metric/CachingMonitorTest.scala @@ -6,32 +6,32 @@ import org.scalatest.matchers.should.Matchers import scala.collection.mutable.ListBuffer -import io.scalac.mesmer.core.LabelSerializable +import io.scalac.mesmer.core.AttributesSerializable import io.scalac.mesmer.core.model._ import io.scalac.mesmer.extension.config.CachingConfig class CachingMonitorTest extends AnyFlatSpec with Matchers with Inspectors { - case class TestLabels(label: String) extends LabelSerializable { - def serialize: RawLabels = Seq("label" -> label) + case class TestAttributes(attribute: String) extends AttributesSerializable { + def serialize: RawAttributes = Seq("attribute" -> attribute) } - case class TestBound(labels: TestLabels) extends Bound { + case class TestBound(attributes: TestAttributes) extends Bound { private[this] var _unbound = false def unbind(): Unit = _unbound = true def unbound: Boolean = _unbound } - class TestBindable extends Bindable[TestLabels, TestBound]() { + class TestBindable extends Bindable[TestAttributes, TestBound]() { - private[this] val _binds: ListBuffer[TestLabels] = ListBuffer.empty + private[this] val _binds: ListBuffer[TestAttributes] = ListBuffer.empty - def bind(labels: TestLabels): TestBound = { - _binds += labels - TestBound(labels) + def bind(attributes: TestAttributes): TestBound = { + _binds += attributes + TestBound(attributes) } - def binds: List[TestLabels] = _binds.toList + def binds: List[TestAttributes] = _binds.toList } type Fixture = TestBindable @@ -42,54 +42,55 @@ class CachingMonitorTest extends AnyFlatSpec with Matchers with Inspectors { "CachingMonitor" should "proxy to wrapped monitor" in test { testBindable => val sut = CachingMonitor(testBindable, CachingConfig.empty) - val labels = List.tabulate(10)(num => s"label_$num").map(TestLabels.apply) + val attributes = List.tabulate(10)(num => s"attribute_$num").map(TestAttributes.apply) - labels.foreach(sut.bind) + attributes.foreach(sut.bind) - testBindable.binds should contain theSameElementsInOrderAs labels + testBindable.binds should contain theSameElementsInOrderAs attributes } it should "return same instance when keys repeat" in test { testBindable => - val sut = CachingMonitor(testBindable, CachingConfig.empty) - val label = TestLabels("label") - val labels = List.fill(10)(label) - val instances = labels.map(sut.bind) + val sut = CachingMonitor(testBindable, CachingConfig.empty) + val attribute = TestAttributes("attribute") + val attributes = List.fill(10)(attribute) + val instances = attributes.map(sut.bind) testBindable.binds should have size 1 - testBindable.binds shouldBe List(label) + testBindable.binds shouldBe List(attribute) forAll(instances.tail)(_ should be theSameInstanceAs instances.head) } it should "evict elements when cache limit is hit" in test { testBindable => - val cacheSize = 5 - val sut = CachingMonitor(testBindable, CachingConfig(cacheSize)) - val labels = List.tabulate(cacheSize + 1)(num => s"label_$num").map(TestLabels.apply) + val cacheSize = 5 + val sut = CachingMonitor(testBindable, CachingConfig(cacheSize)) + val attributes = List.tabulate(cacheSize + 1)(num => s"attribute_$num").map(TestAttributes.apply) - val instances = labels.map(sut.bind) + val instances = attributes.map(sut.bind) instances.head.unbound shouldBe true forAll(instances.tail)(_.unbound shouldBe false) sut.cachedMonitors should have size cacheSize - sut.cachedMonitors.keys should contain theSameElementsAs labels.tail + sut.cachedMonitors.keys should contain theSameElementsAs attributes.tail } it should "evict monitors in LRU manner" in test { testBindable => - val cacheSize = 5 - val sut = CachingMonitor(testBindable, CachingConfig(cacheSize)) - val labels @ firstLabel :: _ :: labelsTail = List.tabulate(cacheSize)(num => s"label_$num").map(TestLabels.apply) - val additionalLabel = TestLabels("evicting_label") + val cacheSize = 5 + val sut = CachingMonitor(testBindable, CachingConfig(cacheSize)) + val attributes @ firstAttribute :: _ :: attributesTail = + List.tabulate(cacheSize)(num => s"attribute_$num").map(TestAttributes.apply) + val additionalAttribute = TestAttributes("evicting_attribute") - val instances @ firstInstance :: secondInstance :: instancesTail = labels.map(sut.bind) - sut.bind(firstLabel) + val instances @ firstInstance :: secondInstance :: instancesTail = attributes.map(sut.bind) + sut.bind(firstAttribute) // forAll(instances)(_.unbound shouldBe false) - sut.cachedMonitors.keys should contain theSameElementsAs labels - val additionalInstance = sut.bind(additionalLabel) + sut.cachedMonitors.keys should contain theSameElementsAs attributes + val additionalInstance = sut.bind(additionalAttribute) secondInstance.unbound shouldBe true forAll(firstInstance :: additionalInstance :: instancesTail)(_.unbound shouldBe false) - sut.cachedMonitors.keys should contain theSameElementsAs (firstLabel :: additionalLabel :: labelsTail) + sut.cachedMonitors.keys should contain theSameElementsAs (firstAttribute :: additionalAttribute :: attributesTail) } } diff --git a/extension/src/test/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryActorSystemMonitorTest.scala b/extension/src/test/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryActorSystemMonitorTest.scala index ea07fd4b1..cb524b786 100644 --- a/extension/src/test/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryActorSystemMonitorTest.scala +++ b/extension/src/test/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryActorSystemMonitorTest.scala @@ -5,14 +5,14 @@ import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers import io.scalac.mesmer.core.module.AkkaActorSystemModule.ActorSystemModuleConfig -import io.scalac.mesmer.extension.metric.ActorSystemMonitor.Labels +import io.scalac.mesmer.extension.metric.ActorSystemMonitor.Attributes import io.scalac.mesmer.extension.upstream.opentelemetry.NoopCounter import io.scalac.mesmer.extension.upstream.opentelemetry.WrappedCounter class OpenTelemetryActorSystemMonitorTest extends AnyFlatSpec with Matchers { behavior of "OpenTelemetryActorSystemMonitor" - val TestLabels: Labels = Labels(None) + val TestLabels: Attributes = Attributes(None) private def config(value: Boolean) = ActorSystemModuleConfig( createdActors = value, diff --git a/extension/src/test/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryClusterMetricsMonitorTest.scala b/extension/src/test/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryClusterMetricsMonitorTest.scala index 7b41ac038..0cbc04bf5 100644 --- a/extension/src/test/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryClusterMetricsMonitorTest.scala +++ b/extension/src/test/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryClusterMetricsMonitorTest.scala @@ -5,7 +5,7 @@ import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers import io.scalac.mesmer.core.module.AkkaClusterModule -import io.scalac.mesmer.extension.metric.ClusterMetricsMonitor.Labels +import io.scalac.mesmer.extension.metric.ClusterMetricsMonitor.Attributes import io.scalac.mesmer.extension.metric.MetricObserver.NoopMetricObserver import io.scalac.mesmer.extension.upstream.opentelemetry._ @@ -13,7 +13,7 @@ class OpenTelemetryClusterMetricsMonitorTest extends AnyFlatSpec with Matchers { behavior of "OpenTelemetryClusterMetricsMonitor" - val TestLabels: Labels = Labels("some-node", None) + val TestLabels: Attributes = Attributes("some-node", None) private def config(value: Boolean) = AkkaClusterModule.Impl( shardPerRegions = value, diff --git a/extension/src/test/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryHttpConnectionMetricsMonitorTest.scala b/extension/src/test/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryHttpConnectionMetricsMonitorTest.scala index 788ecdfe6..3406cbd2a 100644 --- a/extension/src/test/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryHttpConnectionMetricsMonitorTest.scala +++ b/extension/src/test/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryHttpConnectionMetricsMonitorTest.scala @@ -5,7 +5,7 @@ import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers import io.scalac.mesmer.core.module.AkkaHttpModule -import io.scalac.mesmer.extension.metric.HttpConnectionMetricsMonitor.Labels +import io.scalac.mesmer.extension.metric.HttpConnectionMetricsMonitor.Attributes import io.scalac.mesmer.extension.upstream.opentelemetry.NoopUpDownCounter import io.scalac.mesmer.extension.upstream.opentelemetry.WrappedUpDownCounter @@ -13,7 +13,7 @@ class OpenTelemetryHttpConnectionMetricsMonitorTest extends AnyFlatSpec with Mat behavior of "OpenTelemetryHttpConnectionMetricsMonitor" - val TestLabels: Labels = Labels(None, "localhost", 0) + val TestAttributes: Attributes = Attributes(None, "localhost", 0) private def config(value: Boolean) = AkkaHttpModule.Impl( requestTime = value, @@ -28,7 +28,7 @@ class OpenTelemetryHttpConnectionMetricsMonitorTest extends AnyFlatSpec with Mat OpenTelemetryHttpConnectionMetricsMonitor.MetricNames.defaultConfig ) - val bound = sut.bind(TestLabels) + val bound = sut.bind(TestAttributes) bound.connections should be(a[WrappedUpDownCounter]) @@ -41,7 +41,7 @@ class OpenTelemetryHttpConnectionMetricsMonitorTest extends AnyFlatSpec with Mat OpenTelemetryHttpConnectionMetricsMonitor.MetricNames.defaultConfig ) - val bound = sut.bind(TestLabels) + val bound = sut.bind(TestAttributes) bound.connections should be(a[NoopUpDownCounter.type]) } } diff --git a/extension/src/test/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryHttpMetricsMonitorTest.scala b/extension/src/test/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryHttpMetricsMonitorTest.scala index 734ffe11b..601dac692 100644 --- a/extension/src/test/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryHttpMetricsMonitorTest.scala +++ b/extension/src/test/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryHttpMetricsMonitorTest.scala @@ -5,7 +5,7 @@ import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers import io.scalac.mesmer.core.module.AkkaHttpModule -import io.scalac.mesmer.extension.metric.HttpMetricsMonitor.Labels +import io.scalac.mesmer.extension.metric.HttpMetricsMonitor.Attributes import io.scalac.mesmer.extension.upstream.opentelemetry.NoopCounter import io.scalac.mesmer.extension.upstream.opentelemetry.NoopLongValueRecorder import io.scalac.mesmer.extension.upstream.opentelemetry.WrappedCounter @@ -14,7 +14,7 @@ import io.scalac.mesmer.extension.upstream.opentelemetry.WrappedLongValueRecorde class OpenTelemetryHttpMetricsMonitorTest extends AnyFlatSpec with Matchers { behavior of "OpenTelemetryHttpConnectionMetricsMonitor" - val TestLabels: Labels = Labels(None, "/test", "GET", "200") + val TestLabels: Attributes = Attributes(None, "/test", "GET", "200") private def config(value: Boolean) = AkkaHttpModule.Impl( requestTime = value, diff --git a/extension/src/test/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryPersistenceMetricsMonitorTest.scala b/extension/src/test/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryPersistenceMetricsMonitorTest.scala index 84ee719ee..8d4d92d89 100644 --- a/extension/src/test/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryPersistenceMetricsMonitorTest.scala +++ b/extension/src/test/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryPersistenceMetricsMonitorTest.scala @@ -5,7 +5,7 @@ import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers import io.scalac.mesmer.core.module.AkkaPersistenceModule -import io.scalac.mesmer.extension.metric.PersistenceMetricsMonitor.Labels +import io.scalac.mesmer.extension.metric.PersistenceMetricsMonitor.Attributes import io.scalac.mesmer.extension.upstream.opentelemetry.NoopCounter import io.scalac.mesmer.extension.upstream.opentelemetry.NoopLongValueRecorder import io.scalac.mesmer.extension.upstream.opentelemetry.WrappedCounter @@ -14,7 +14,7 @@ import io.scalac.mesmer.extension.upstream.opentelemetry.WrappedLongValueRecorde class OpenTelemetryPersistenceMetricsMonitorTest extends AnyFlatSpec with Matchers { behavior of "OpenTelemetryHttpConnectionMetricsMonitor" - val TestLabels: Labels = Labels(None, "/", "") + val TestLabels: Attributes = Attributes(None, "/", "") private def config(value: Boolean) = AkkaPersistenceModule.Impl( recoveryTime = value, diff --git a/extension/src/test/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryStreamMetricsMonitorTest.scala b/extension/src/test/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryStreamMetricsMonitorTest.scala index afb471223..6175f4180 100644 --- a/extension/src/test/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryStreamMetricsMonitorTest.scala +++ b/extension/src/test/scala/io/scalac/mesmer/extension/upstream/OpenTelemetryStreamMetricsMonitorTest.scala @@ -6,7 +6,7 @@ import org.scalatest.matchers.should.Matchers import io.scalac.mesmer.core.module.AkkaStreamModule import io.scalac.mesmer.extension.metric.MetricObserver -import io.scalac.mesmer.extension.metric.StreamMetricsMonitor.EagerLabels +import io.scalac.mesmer.extension.metric.StreamMetricsMonitor.EagerAttributes import io.scalac.mesmer.extension.upstream.opentelemetry.NoopLongValueRecorder import io.scalac.mesmer.extension.upstream.opentelemetry.WrappedLongValueRecorder import io.scalac.mesmer.extension.upstream.opentelemetry.WrappedMetricObserver @@ -22,7 +22,7 @@ class OpenTelemetryStreamMetricsMonitorTest extends AnyFlatSpec with Matchers { demand = value ) - val testLabels: EagerLabels = EagerLabels(None) + val testAttributes: EagerAttributes = EagerAttributes(None) it should "bind to OpenTelemetry instruments if metric is enabled" in { @@ -32,7 +32,7 @@ class OpenTelemetryStreamMetricsMonitorTest extends AnyFlatSpec with Matchers { OpenTelemetryStreamMetricsMonitor.MetricNames.defaultConfig ) - val bound = sut.bind(testLabels) + val bound = sut.bind(testAttributes) bound.runningStreamsTotal should be(a[WrappedLongValueRecorder]) bound.streamActorsTotal should be(a[WrappedLongValueRecorder]) @@ -47,7 +47,7 @@ class OpenTelemetryStreamMetricsMonitorTest extends AnyFlatSpec with Matchers { OpenTelemetryStreamMetricsMonitor.MetricNames.defaultConfig ) - val bound = sut.bind(testLabels) + val bound = sut.bind(testAttributes) bound.runningStreamsTotal should be(a[NoopLongValueRecorder.type]) bound.streamActorsTotal should be(a[NoopLongValueRecorder.type]) diff --git a/extension/src/test/scala/io/scalac/mesmer/extension/util/probe/ActorMonitorTestProbe.scala b/extension/src/test/scala/io/scalac/mesmer/extension/util/probe/ActorMonitorTestProbe.scala index 24c61bf99..f356390a0 100644 --- a/extension/src/test/scala/io/scalac/mesmer/extension/util/probe/ActorMonitorTestProbe.scala +++ b/extension/src/test/scala/io/scalac/mesmer/extension/util/probe/ActorMonitorTestProbe.scala @@ -11,21 +11,21 @@ import io.scalac.mesmer.extension.metric.MetricObserver import io.scalac.mesmer.extension.util.probe.BoundTestProbe.MetricObserverCommand final case class ActorMonitorTestProbe( - mailboxSizeProbe: TestProbe[MetricObserverCommand[Labels]], - mailboxTimeMinProbe: TestProbe[MetricObserverCommand[Labels]], - mailboxTimeMaxProbe: TestProbe[MetricObserverCommand[Labels]], - mailboxTimeSumProbe: TestProbe[MetricObserverCommand[Labels]], - mailboxTimeCountProbe: TestProbe[MetricObserverCommand[Labels]], - stashedMessagesProbe: TestProbe[MetricObserverCommand[Labels]], - receivedMessagesProbe: TestProbe[MetricObserverCommand[Labels]], - processedMessagesProbe: TestProbe[MetricObserverCommand[Labels]], - failedMessagesProbe: TestProbe[MetricObserverCommand[Labels]], - processingTimeMinProbe: TestProbe[MetricObserverCommand[Labels]], - processingTimeMaxProbe: TestProbe[MetricObserverCommand[Labels]], - processingTimeSumProbe: TestProbe[MetricObserverCommand[Labels]], - processingTimeCountProbe: TestProbe[MetricObserverCommand[Labels]], - sentMessagesProbe: TestProbe[MetricObserverCommand[Labels]], - droppedMessagesProbe: TestProbe[MetricObserverCommand[Labels]], + mailboxSizeProbe: TestProbe[MetricObserverCommand[Attributes]], + mailboxTimeMinProbe: TestProbe[MetricObserverCommand[Attributes]], + mailboxTimeMaxProbe: TestProbe[MetricObserverCommand[Attributes]], + mailboxTimeSumProbe: TestProbe[MetricObserverCommand[Attributes]], + mailboxTimeCountProbe: TestProbe[MetricObserverCommand[Attributes]], + stashedMessagesProbe: TestProbe[MetricObserverCommand[Attributes]], + receivedMessagesProbe: TestProbe[MetricObserverCommand[Attributes]], + processedMessagesProbe: TestProbe[MetricObserverCommand[Attributes]], + failedMessagesProbe: TestProbe[MetricObserverCommand[Attributes]], + processingTimeMinProbe: TestProbe[MetricObserverCommand[Attributes]], + processingTimeMaxProbe: TestProbe[MetricObserverCommand[Attributes]], + processingTimeSumProbe: TestProbe[MetricObserverCommand[Attributes]], + processingTimeCountProbe: TestProbe[MetricObserverCommand[Attributes]], + sentMessagesProbe: TestProbe[MetricObserverCommand[Attributes]], + droppedMessagesProbe: TestProbe[MetricObserverCommand[Attributes]], collector: ObserverCollector )(implicit val actorSystem: ActorSystem[_]) extends ActorMetricsMonitor @@ -38,36 +38,36 @@ final case class ActorMonitorTestProbe( } class ActorMonitorTestBoundMonitor extends BoundMonitor { - val mailboxSize: MetricObserver[Long, Labels] = + val mailboxSize: MetricObserver[Long, Attributes] = ObserverTestProbeWrapper(mailboxSizeProbe, collector) - val mailboxTimeCount: MetricObserver[Long, Labels] = + val mailboxTimeCount: MetricObserver[Long, Attributes] = ObserverTestProbeWrapper(mailboxTimeCountProbe, collector) - val mailboxTimeMin: MetricObserver[Long, Labels] = + val mailboxTimeMin: MetricObserver[Long, Attributes] = ObserverTestProbeWrapper(mailboxTimeMinProbe, collector) - val mailboxTimeMax: MetricObserver[Long, Labels] = + val mailboxTimeMax: MetricObserver[Long, Attributes] = ObserverTestProbeWrapper(mailboxTimeMaxProbe, collector) - val mailboxTimeSum: MetricObserver[Long, Labels] = + val mailboxTimeSum: MetricObserver[Long, Attributes] = ObserverTestProbeWrapper(mailboxTimeSumProbe, collector) - val stashedMessages: MetricObserver[Long, Labels] = + val stashedMessages: MetricObserver[Long, Attributes] = ObserverTestProbeWrapper(stashedMessagesProbe, collector) - val receivedMessages: MetricObserver[Long, Labels] = + val receivedMessages: MetricObserver[Long, Attributes] = ObserverTestProbeWrapper(receivedMessagesProbe, collector) - val processedMessages: MetricObserver[Long, Labels] = + val processedMessages: MetricObserver[Long, Attributes] = ObserverTestProbeWrapper(processedMessagesProbe, collector) - val failedMessages: MetricObserver[Long, Labels] = + val failedMessages: MetricObserver[Long, Attributes] = ObserverTestProbeWrapper(failedMessagesProbe, collector) - val processingTimeCount: MetricObserver[Long, Labels] = + val processingTimeCount: MetricObserver[Long, Attributes] = ObserverTestProbeWrapper(processingTimeCountProbe, collector) - val processingTimeMin: MetricObserver[Long, Labels] = + val processingTimeMin: MetricObserver[Long, Attributes] = ObserverTestProbeWrapper(processingTimeMinProbe, collector) - val processingTimeMax: MetricObserver[Long, Labels] = + val processingTimeMax: MetricObserver[Long, Attributes] = ObserverTestProbeWrapper(processingTimeMaxProbe, collector) - val processingTimeSum: MetricObserver[Long, Labels] = + val processingTimeSum: MetricObserver[Long, Attributes] = ObserverTestProbeWrapper(processingTimeSumProbe, collector) - val sentMessages: MetricObserver[Long, Labels] = + val sentMessages: MetricObserver[Long, Attributes] = ObserverTestProbeWrapper(sentMessagesProbe, collector) - val droppedMessages: MetricObserver[Long, Labels] = + val droppedMessages: MetricObserver[Long, Attributes] = ObserverTestProbeWrapper(droppedMessagesProbe, collector) def unbind(): Unit = { diff --git a/extension/src/test/scala/io/scalac/mesmer/extension/util/probe/ActorSystemMonitorProbe.scala b/extension/src/test/scala/io/scalac/mesmer/extension/util/probe/ActorSystemMonitorProbe.scala index 0b2888d75..e80942289 100644 --- a/extension/src/test/scala/io/scalac/mesmer/extension/util/probe/ActorSystemMonitorProbe.scala +++ b/extension/src/test/scala/io/scalac/mesmer/extension/util/probe/ActorSystemMonitorProbe.scala @@ -13,7 +13,7 @@ final case class ActorSystemMonitorProbe( terminatedActorsProbe: TestProbe[CounterCommand] ) extends ActorSystemMonitor with BindUnbindMonitor { - override def bind(labels: ActorSystemMonitor.Labels): ActorSystemMonitor.BoundMonitor = { + override def bind(attributes: ActorSystemMonitor.Attributes): ActorSystemMonitor.BoundMonitor = { onBind() new ActorSystemTestBoundMonitor with UnbindMonitor } diff --git a/extension/src/test/scala/io/scalac/mesmer/extension/util/probe/BoundTestProbe.scala b/extension/src/test/scala/io/scalac/mesmer/extension/util/probe/BoundTestProbe.scala index 8aec74660..3b7e078a0 100644 --- a/extension/src/test/scala/io/scalac/mesmer/extension/util/probe/BoundTestProbe.scala +++ b/extension/src/test/scala/io/scalac/mesmer/extension/util/probe/BoundTestProbe.scala @@ -24,7 +24,7 @@ object BoundTestProbe { sealed trait MetricObserverCommand[L] - final case class MetricObserved[L](value: Long, labels: L) extends MetricObserverCommand[L] + final case class MetricObserved[L](value: Long, attributes: L) extends MetricObserverCommand[L] } @@ -85,6 +85,6 @@ final case class ObserverTestProbeWrapper[L]( type Cmd = MetricObserverCommand[L] protected def handleCallback(updater: Updater[Long, L]): Unit = - updater((value, labels) => probe.ref ! MetricObserved(value, labels)) + updater((value, attributes) => probe.ref ! MetricObserved(value, attributes)) } diff --git a/extension/src/test/scala/io/scalac/mesmer/extension/util/probe/ClusterMonitorTestProbe.scala b/extension/src/test/scala/io/scalac/mesmer/extension/util/probe/ClusterMonitorTestProbe.scala index d194e81be..53e06e94a 100644 --- a/extension/src/test/scala/io/scalac/mesmer/extension/util/probe/ClusterMonitorTestProbe.scala +++ b/extension/src/test/scala/io/scalac/mesmer/extension/util/probe/ClusterMonitorTestProbe.scala @@ -4,16 +4,16 @@ import akka.actor.testkit.typed.scaladsl.TestProbe import akka.actor.typed.ActorSystem import io.scalac.mesmer.core.util.probe.ObserverCollector -import io.scalac.mesmer.extension.metric.ClusterMetricsMonitor.Labels +import io.scalac.mesmer.extension.metric.ClusterMetricsMonitor.Attributes import io.scalac.mesmer.extension.metric._ import io.scalac.mesmer.extension.util.TestProbeSynchronized import io.scalac.mesmer.extension.util.probe.BoundTestProbe._ class ClusterMonitorTestProbe private ( - val shardPerRegionsProbe: TestProbe[MetricObserverCommand[Labels]], - val entityPerRegionProbe: TestProbe[MetricObserverCommand[Labels]], - val shardRegionsOnNodeProbe: TestProbe[MetricObserverCommand[Labels]], - val entitiesOnNodeProbe: TestProbe[MetricObserverCommand[Labels]], + val shardPerRegionsProbe: TestProbe[MetricObserverCommand[Attributes]], + val entityPerRegionProbe: TestProbe[MetricObserverCommand[Attributes]], + val shardRegionsOnNodeProbe: TestProbe[MetricObserverCommand[Attributes]], + val entitiesOnNodeProbe: TestProbe[MetricObserverCommand[Attributes]], val reachableNodesProbe: TestProbe[CounterCommand], val unreachableNodesProbe: TestProbe[CounterCommand], val nodeDownProbe: TestProbe[CounterCommand], @@ -21,10 +21,10 @@ class ClusterMonitorTestProbe private ( )(implicit system: ActorSystem[_]) extends ClusterMetricsMonitor { - def bind(node: Labels): ClusterMetricsMonitor.BoundMonitor = + def bind(node: Attributes): ClusterMetricsMonitor.BoundMonitor = new ClusterMetricsMonitor.BoundMonitor with TestProbeSynchronized { - private type CustomMetricObserver = MetricObserver[Long, Labels] with AsyncTestProbe[_] + private type CustomMetricObserver = MetricObserver[Long, Attributes] with AsyncTestProbe[_] val shardPerRegions: CustomMetricObserver = ObserverTestProbeWrapper(shardPerRegionsProbe, collector) @@ -57,10 +57,10 @@ class ClusterMonitorTestProbe private ( object ClusterMonitorTestProbe { def apply(collector: ObserverCollector)(implicit system: ActorSystem[_]): ClusterMonitorTestProbe = { - val shardPerRegionsProbe = TestProbe[MetricObserverCommand[Labels]]("shardPerRegionsProbe") - val entityPerRegionProbe = TestProbe[MetricObserverCommand[Labels]]("entityPerRegionProbe") - val shardRegionsOnNodeProbe = TestProbe[MetricObserverCommand[Labels]]("shardRegionsOnNodeProbe") - val entitiesOnNodeProbe = TestProbe[MetricObserverCommand[Labels]]("entitiesOnNodeProbe") + val shardPerRegionsProbe = TestProbe[MetricObserverCommand[Attributes]]("shardPerRegionsProbe") + val entityPerRegionProbe = TestProbe[MetricObserverCommand[Attributes]]("entityPerRegionProbe") + val shardRegionsOnNodeProbe = TestProbe[MetricObserverCommand[Attributes]]("shardRegionsOnNodeProbe") + val entitiesOnNodeProbe = TestProbe[MetricObserverCommand[Attributes]]("entitiesOnNodeProbe") val reachableNodesProbe = TestProbe[CounterCommand]("reachableNodesProbe") val unreachableNodesProbe = TestProbe[CounterCommand]("unreachableNodesProbe") val nodeDownProbe = TestProbe[CounterCommand]("nodeDownProbe") diff --git a/extension/src/test/scala/io/scalac/mesmer/extension/util/probe/HttpConnectionMetricsTestProbe.scala b/extension/src/test/scala/io/scalac/mesmer/extension/util/probe/HttpConnectionMetricsTestProbe.scala index 130f5b545..f663444b5 100644 --- a/extension/src/test/scala/io/scalac/mesmer/extension/util/probe/HttpConnectionMetricsTestProbe.scala +++ b/extension/src/test/scala/io/scalac/mesmer/extension/util/probe/HttpConnectionMetricsTestProbe.scala @@ -20,19 +20,20 @@ class HttpConnectionMetricsTestProbe(implicit val system: ActorSystem[_]) extend val globalConnectionCounter: TestProbe[CounterCommand] = TestProbe[CounterCommand]() - private[this] val monitors: CMap[Labels, BoundHttpProbes] = new ConcurrentHashMap[Labels, BoundHttpProbes]().asScala - private[this] val _binds: AtomicInteger = new AtomicInteger(0) + private[this] val monitors: CMap[Attributes, BoundHttpProbes] = + new ConcurrentHashMap[Attributes, BoundHttpProbes]().asScala + private[this] val _binds: AtomicInteger = new AtomicInteger(0) - def bind(labels: Labels): BoundHttpProbes = { + def bind(attributes: Attributes): BoundHttpProbes = { _binds.addAndGet(1) - monitors.getOrElseUpdate(labels, createBoundProbes) + monitors.getOrElseUpdate(attributes, createBoundProbes) } - def probes(labels: Labels): Option[BoundHttpProbes] = monitors.get(labels) - def boundLabels: Set[Labels] = monitors.keys.toSet - def boundSize: Int = monitors.size - def binds: Int = _binds.get() - private def createBoundProbes: BoundHttpProbes = new BoundHttpProbes(TestProbe()) + def probes(attributes: Attributes): Option[BoundHttpProbes] = monitors.get(attributes) + def boundAttributes: Set[Attributes] = monitors.keys.toSet + def boundSize: Int = monitors.size + def binds: Int = _binds.get() + private def createBoundProbes: BoundHttpProbes = new BoundHttpProbes(TestProbe()) class BoundHttpProbes( val connectionCounterProbe: TestProbe[CounterCommand] diff --git a/extension/src/test/scala/io/scalac/mesmer/extension/util/probe/HttpMonitorTestProbe.scala b/extension/src/test/scala/io/scalac/mesmer/extension/util/probe/HttpMonitorTestProbe.scala index 8758db7f1..e6ca81743 100644 --- a/extension/src/test/scala/io/scalac/mesmer/extension/util/probe/HttpMonitorTestProbe.scala +++ b/extension/src/test/scala/io/scalac/mesmer/extension/util/probe/HttpMonitorTestProbe.scala @@ -22,19 +22,20 @@ class HttpMonitorTestProbe(implicit val system: ActorSystem[_]) extends HttpMetr val globalRequestCounter: TestProbe[CounterCommand] = TestProbe[CounterCommand]() - private[this] val monitors: CMap[Labels, BoundHttpProbes] = new ConcurrentHashMap[Labels, BoundHttpProbes]().asScala - private[this] val _binds: AtomicInteger = new AtomicInteger(0) + private[this] val monitors: CMap[Attributes, BoundHttpProbes] = + new ConcurrentHashMap[Attributes, BoundHttpProbes]().asScala + private[this] val _binds: AtomicInteger = new AtomicInteger(0) - def bind(labels: Labels): BoundHttpProbes = { + def bind(attributes: Attributes): BoundHttpProbes = { _binds.addAndGet(1) - monitors.getOrElseUpdate(labels, createBoundProbes) + monitors.getOrElseUpdate(attributes, createBoundProbes) } - def probes(labels: Labels): Option[BoundHttpProbes] = monitors.get(labels) - def boundLabels: Set[Labels] = monitors.keys.toSet - def boundSize: Int = monitors.size - def binds: Int = _binds.get() - private def createBoundProbes: BoundHttpProbes = new BoundHttpProbes(TestProbe(), TestProbe()) + def probes(attributes: Attributes): Option[BoundHttpProbes] = monitors.get(attributes) + def boundAttributes: Set[Attributes] = monitors.keys.toSet + def boundSize: Int = monitors.size + def binds: Int = _binds.get() + private def createBoundProbes: BoundHttpProbes = new BoundHttpProbes(TestProbe(), TestProbe()) class BoundHttpProbes( val requestTimeProbe: TestProbe[MetricRecorderCommand], diff --git a/extension/src/test/scala/io/scalac/mesmer/extension/util/probe/PersistenceMonitorTestProbe.scala b/extension/src/test/scala/io/scalac/mesmer/extension/util/probe/PersistenceMonitorTestProbe.scala index 6ec223407..1ed715b8d 100644 --- a/extension/src/test/scala/io/scalac/mesmer/extension/util/probe/PersistenceMonitorTestProbe.scala +++ b/extension/src/test/scala/io/scalac/mesmer/extension/util/probe/PersistenceMonitorTestProbe.scala @@ -12,7 +12,7 @@ import scala.jdk.CollectionConverters._ import io.scalac.mesmer.extension.metric.Counter import io.scalac.mesmer.extension.metric.MetricRecorder import io.scalac.mesmer.extension.metric.PersistenceMetricsMonitor -import io.scalac.mesmer.extension.metric.PersistenceMetricsMonitor.Labels +import io.scalac.mesmer.extension.metric.PersistenceMetricsMonitor.Attributes import io.scalac.mesmer.extension.util.probe.BoundTestProbe.CounterCommand import io.scalac.mesmer.extension.util.probe.BoundTestProbe.MetricRecorderCommand @@ -32,12 +32,13 @@ trait ConcurrentBoundProbes[L] { private[this] val monitors: CMap[L, B] = new ConcurrentHashMap[L, B]().asScala - protected def createBoundProbes(labels: L): B - final protected def concurrentBind(labels: L): B = monitors.getOrElseUpdate(labels, createBoundProbes(labels)) + protected def createBoundProbes(attributes: L): B + final protected def concurrentBind(attributes: L): B = + monitors.getOrElseUpdate(attributes, createBoundProbes(attributes)) - def probes(labels: L): Option[B] = monitors.get(labels) - def boundLabels: Set[L] = monitors.keySet.toSet - def boundSize: Int = monitors.size + def probes(attributes: L): Option[B] = monitors.get(attributes) + def boundAttributes: Set[L] = monitors.keySet.toSet + def boundSize: Int = monitors.size } @@ -47,7 +48,7 @@ trait GlobalProbe { class PersistenceMonitorTestProbe(implicit val system: ActorSystem[_]) extends PersistenceMetricsMonitor - with ConcurrentBoundProbes[Labels] + with ConcurrentBoundProbes[Attributes] with BindCounter with GlobalProbe { @@ -55,12 +56,12 @@ class PersistenceMonitorTestProbe(implicit val system: ActorSystem[_]) val globalCounter: TestProbe[CounterCommand] = TestProbe() - def bind(labels: Labels): PersistenceMetricsMonitor.BoundMonitor = + def bind(attributes: Attributes): PersistenceMetricsMonitor.BoundMonitor = counting { - concurrentBind(labels) + concurrentBind(attributes) } - protected def createBoundProbes(labels: Labels): BoundPersistenceProbes = + protected def createBoundProbes(attributes: Attributes): BoundPersistenceProbes = new BoundPersistenceProbes(TestProbe(), TestProbe(), TestProbe(), TestProbe(), TestProbe()) class BoundPersistenceProbes( diff --git a/extension/src/test/scala/io/scalac/mesmer/extension/util/probe/StreamOperatorMonitorTestProbe.scala b/extension/src/test/scala/io/scalac/mesmer/extension/util/probe/StreamOperatorMonitorTestProbe.scala index 2eb3ca8a1..a62af8482 100644 --- a/extension/src/test/scala/io/scalac/mesmer/extension/util/probe/StreamOperatorMonitorTestProbe.scala +++ b/extension/src/test/scala/io/scalac/mesmer/extension/util/probe/StreamOperatorMonitorTestProbe.scala @@ -6,16 +6,16 @@ import akka.actor.typed.ActorSystem import io.scalac.mesmer.core.util.probe.Collected import io.scalac.mesmer.core.util.probe.ObserverCollector import io.scalac.mesmer.extension.metric.StreamMetricsMonitor +import io.scalac.mesmer.extension.metric.StreamMetricsMonitor.Attributes import io.scalac.mesmer.extension.metric.StreamMetricsMonitor.BoundMonitor -import io.scalac.mesmer.extension.metric.StreamMetricsMonitor.Labels import io.scalac.mesmer.extension.metric.StreamOperatorMetricsMonitor import io.scalac.mesmer.extension.util.probe.BoundTestProbe.MetricObserverCommand import io.scalac.mesmer.extension.util.probe.BoundTestProbe.MetricRecorderCommand final case class StreamOperatorMonitorTestProbe( - processedTestProbe: TestProbe[MetricObserverCommand[StreamOperatorMetricsMonitor.Labels]], - runningOperatorsTestProbe: TestProbe[MetricObserverCommand[StreamOperatorMetricsMonitor.Labels]], - demandTestProbe: TestProbe[MetricObserverCommand[StreamOperatorMetricsMonitor.Labels]], + processedTestProbe: TestProbe[MetricObserverCommand[StreamOperatorMetricsMonitor.Attributes]], + runningOperatorsTestProbe: TestProbe[MetricObserverCommand[StreamOperatorMetricsMonitor.Attributes]], + demandTestProbe: TestProbe[MetricObserverCommand[StreamOperatorMetricsMonitor.Attributes]], collector: ObserverCollector )(implicit val system: ActorSystem[_]) extends StreamOperatorMetricsMonitor @@ -32,11 +32,11 @@ final case class StreamOperatorMonitorTestProbe( object StreamOperatorMonitorTestProbe { def apply(collector: ObserverCollector)(implicit system: ActorSystem[_]): StreamOperatorMonitorTestProbe = { val processProbe = - TestProbe[MetricObserverCommand[StreamOperatorMetricsMonitor.Labels]]("akka_stream_processed_messages") + TestProbe[MetricObserverCommand[StreamOperatorMetricsMonitor.Attributes]]("akka_stream_processed_messages") val demandProbe = - TestProbe[MetricObserverCommand[StreamOperatorMetricsMonitor.Labels]]("akka_stream_demand") + TestProbe[MetricObserverCommand[StreamOperatorMetricsMonitor.Attributes]]("akka_stream_demand") val runningOperators = - TestProbe[MetricObserverCommand[StreamOperatorMetricsMonitor.Labels]]("akka_stream_running_operators") + TestProbe[MetricObserverCommand[StreamOperatorMetricsMonitor.Attributes]]("akka_stream_running_operators") StreamOperatorMonitorTestProbe(processProbe, demandProbe, runningOperators, collector) } @@ -45,12 +45,12 @@ object StreamOperatorMonitorTestProbe { class StreamMonitorTestProbe( val runningStreamsProbe: TestProbe[MetricRecorderCommand], val streamActorsProbe: TestProbe[MetricRecorderCommand], - val processedMessagesProbe: TestProbe[MetricObserverCommand[Labels]], + val processedMessagesProbe: TestProbe[MetricObserverCommand[Attributes]], val collector: ObserverCollector )(implicit val system: ActorSystem[_]) extends StreamMetricsMonitor with Collected { - def bind(labels: StreamMetricsMonitor.EagerLabels): StreamMetricsMonitor.BoundMonitor = new BoundMonitor { + def bind(attributes: StreamMetricsMonitor.EagerAttributes): StreamMetricsMonitor.BoundMonitor = new BoundMonitor { val runningStreamsTotal = RecorderTestProbeWrapper(runningStreamsProbe) @@ -66,7 +66,7 @@ object StreamMonitorTestProbe { def apply(collector: ObserverCollector)(implicit system: ActorSystem[_]): StreamMonitorTestProbe = { val runningStream = TestProbe[MetricRecorderCommand]() val streamActorsProbe = TestProbe[MetricRecorderCommand]() - val processedMessagesProbe = TestProbe[MetricObserverCommand[Labels]]() + val processedMessagesProbe = TestProbe[MetricObserverCommand[Attributes]]() new StreamMonitorTestProbe(runningStream, streamActorsProbe, processedMessagesProbe, collector) } } From b9bb955890bee6c03998e27ea099648d5b4620d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Gajowy?= Date: Tue, 14 Dec 2021 16:21:09 +0100 Subject: [PATCH 3/3] Refactor: Remove commented out code --- .../upstream/opentelemetry/WrappedAsynchronousInstrument.scala | 1 - 1 file changed, 1 deletion(-) diff --git a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/opentelemetry/WrappedAsynchronousInstrument.scala b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/opentelemetry/WrappedAsynchronousInstrument.scala index 3b8648e95..91f4409ab 100644 --- a/extension/src/main/scala/io/scalac/mesmer/extension/upstream/opentelemetry/WrappedAsynchronousInstrument.scala +++ b/extension/src/main/scala/io/scalac/mesmer/extension/upstream/opentelemetry/WrappedAsynchronousInstrument.scala @@ -40,7 +40,6 @@ final class LongSumObserverBuilderAdapter[L <: AttributesSerializable](builder: ) sealed abstract class MetricObserverBuilderAdapter[R <: ObservableMeasurement, T, L <: AttributesSerializable]( -// builder: AsynchronousInstrumentBuilder[R], register: (R => Unit) => Unit, wrapper: ResultWrapper[R, T] ) {