diff --git a/ts-reaktive-actors/src/main/java/com/tradeshift/reaktive/materialize/MaterializerActor.java b/ts-reaktive-actors/src/main/java/com/tradeshift/reaktive/materialize/MaterializerActor.java index e5bb4412..1be6ae3a 100644 --- a/ts-reaktive-actors/src/main/java/com/tradeshift/reaktive/materialize/MaterializerActor.java +++ b/ts-reaktive-actors/src/main/java/com/tradeshift/reaktive/materialize/MaterializerActor.java @@ -61,7 +61,7 @@ public abstract class MaterializerActor extends AbstractPersistentActor { protected final LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this); private final MaterializerMetrics metrics = new MaterializerMetrics( // Turn CamelCase to camel-case. - getClass().getSimpleName().replaceAll("([a-z])([A-Z]+)", "$1-$2").toLowerCase()); + getClass().getSimpleName().replaceAll("([a-z])([A-Z]+)", "$1-$2").toLowerCase(), getAdditionalMetricTags()); private final FiniteDuration rollback; private final FiniteDuration updateAccuracy; private final FiniteDuration restartDelay; @@ -434,6 +434,14 @@ private CompletionStage persistSequential(int workerIndex, Seq seq) { */ public abstract Instant timestampOf(E envelope); + /** + * @return the custom tags which will be attached to materializer metrics reported by Kamon. + * By default, only the class name is attached as a tag in Kamon metrics and there are no custom tags. + */ + protected Map getAdditionalMetricTags() { + return HashMap.empty(); + } + /** * Message that can be sent to this actor to start a secondary re-import of certain UUIDs. * The main import stream will keep running while the re-import is underway. diff --git a/ts-reaktive-actors/src/main/java/com/tradeshift/reaktive/materialize/MaterializerMetrics.java b/ts-reaktive-actors/src/main/java/com/tradeshift/reaktive/materialize/MaterializerMetrics.java index 0c87b954..acd1a629 100644 --- a/ts-reaktive-actors/src/main/java/com/tradeshift/reaktive/materialize/MaterializerMetrics.java +++ b/ts-reaktive-actors/src/main/java/com/tradeshift/reaktive/materialize/MaterializerMetrics.java @@ -1,8 +1,6 @@ package com.tradeshift.reaktive.materialize; -import java.util.Map; - -import io.vavr.collection.HashMap; +import io.vavr.collection.Map; import kamon.Kamon; import kamon.metric.Counter; import kamon.metric.CounterMetric; @@ -13,7 +11,7 @@ import kamon.metric.MeasurementUnit; public class MaterializerMetrics { - private final HashMap baseTags; + private final Map baseTags; private final CounterMetric events; private final Counter restarts; private final Gauge reimportRemaining; @@ -26,9 +24,9 @@ public class MaterializerMetrics { /** The duration, milliseconds, of materializing a single event */ private final HistogramMetric materializationDuration; - public MaterializerMetrics(String name) { - baseTags = HashMap.of("journal-materializer", name); - Map tags = baseTags.toJavaMap(); + public MaterializerMetrics(String name, Map additionalTags) { + baseTags = additionalTags.put("journal-materializer", name); + java.util.Map tags = baseTags.toJavaMap(); this.events = Kamon.counter("journal-materializer.events"); this.restarts = Kamon.counter("journal-materializer.restarts").refine(tags); this.reimportRemaining = Kamon.gauge("journal-materializer.reimport-remaining", MeasurementUnit.time().milliseconds()).refine(tags);