Skip to content

Commit

Permalink
Merge pull request #136 from Tradeshift/vizog-metric_name
Browse files Browse the repository at this point in the history
Add additional tags for MaterializerActor
  • Loading branch information
jypma authored Oct 31, 2019
2 parents 57691ff + 572bbc5 commit 13cf254
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public abstract class MaterializerActor<E> 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;
Expand Down Expand Up @@ -434,6 +434,14 @@ private CompletionStage<Done> persistSequential(int workerIndex, Seq<E> 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<String, String> 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,7 +11,7 @@
import kamon.metric.MeasurementUnit;

public class MaterializerMetrics {
private final HashMap<String, String> baseTags;
private final Map<String, String> baseTags;
private final CounterMetric events;
private final Counter restarts;
private final Gauge reimportRemaining;
Expand All @@ -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<String, String> tags = baseTags.toJavaMap();
public MaterializerMetrics(String name, Map<String, String> additionalTags) {
baseTags = additionalTags.put("journal-materializer", name);
java.util.Map<String, String> 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);
Expand Down

0 comments on commit 13cf254

Please sign in to comment.