diff --git a/server/src/main/java/org/elasticsearch/ingest/IngestMetric.java b/server/src/main/java/org/elasticsearch/ingest/IngestMetric.java index 4e809aa5b444e..bbfd6e21c3b22 100644 --- a/server/src/main/java/org/elasticsearch/ingest/IngestMetric.java +++ b/server/src/main/java/org/elasticsearch/ingest/IngestMetric.java @@ -22,6 +22,8 @@ import org.elasticsearch.common.metrics.CounterMetric; import org.elasticsearch.common.metrics.MeanMetric; +import java.util.concurrent.atomic.AtomicLong; + /** *

Metrics to measure ingest actions. *

This counts measure documents and timings for a given scope. @@ -39,7 +41,7 @@ class IngestMetric { * The current count of things being measure. Should most likely ever be 0 or 1. * Useful when aggregating multiple metrics to see how many things are in flight. */ - private final CounterMetric ingestCurrent = new CounterMetric(); + private final AtomicLong ingestCurrent = new AtomicLong(); /** * The ever increasing count of things being measured */ @@ -53,7 +55,7 @@ class IngestMetric { * Call this prior to the ingest action. */ void preIngest() { - ingestCurrent.inc(); + ingestCurrent.incrementAndGet(); } /** @@ -61,7 +63,7 @@ void preIngest() { * @param ingestTimeInMillis The time it took to perform the action. */ void postIngest(long ingestTimeInMillis) { - ingestCurrent.dec(); + ingestCurrent.decrementAndGet(); ingestTime.inc(ingestTimeInMillis); ingestCount.inc(); } @@ -90,6 +92,6 @@ void add(IngestMetric metrics) { * Creates a serializable representation for these metrics. */ IngestStats.Stats createStats() { - return new IngestStats.Stats(ingestCount.count(), ingestTime.sum(), ingestCurrent.count(), ingestFailed.count()); + return new IngestStats.Stats(ingestCount.count(), ingestTime.sum(), ingestCurrent.get(), ingestFailed.count()); } }