-
Notifications
You must be signed in to change notification settings - Fork 846
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
125 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
sdk/trace/src/jmh/java/io/opentelemetry/sdk/trace/export/BatchSpanProcessorMetrics.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.sdk.trace.export; | ||
|
||
import io.opentelemetry.sdk.metrics.data.LongPointData; | ||
import io.opentelemetry.sdk.metrics.data.MetricData; | ||
import java.util.Collection; | ||
import java.util.Optional; | ||
|
||
public class BatchSpanProcessorMetrics { | ||
private final Collection<MetricData> allMetrics; | ||
private final int numThreads; | ||
|
||
public BatchSpanProcessorMetrics(Collection<MetricData> allMetrics, int numThreads) { | ||
this.allMetrics = allMetrics; | ||
this.numThreads = numThreads; | ||
} | ||
|
||
public double dropRatio() { | ||
long exported = getMetric(true); | ||
long dropped = getMetric(false); | ||
long total = exported + dropped; | ||
// Due to peculiarities of JMH reporting we have to divide this by the number of the | ||
// concurrent threads running the actual benchmark. | ||
return total == 0 ? 0 : (double) dropped / total / numThreads; | ||
} | ||
|
||
public long exportedSpans() { | ||
return getMetric(false) / numThreads; | ||
} | ||
|
||
public long droppedSpans() { | ||
return getMetric(true) / numThreads; | ||
} | ||
|
||
private long getMetric(boolean dropped) { | ||
String labelValue = String.valueOf(dropped); | ||
Optional<Long> value = | ||
allMetrics.stream() | ||
.filter(metricData -> metricData.getName().equals("processedSpans")) | ||
.filter(metricData -> !metricData.isEmpty()) | ||
.map(metricData -> metricData.getLongSumData().getPoints()) | ||
.flatMap(Collection::stream) | ||
.filter(point -> labelValue.equals(point.getLabels().get("dropped"))) | ||
.map(LongPointData::getValue) | ||
.findFirst(); | ||
return value.isPresent() ? value.get() : 0; | ||
} | ||
} |
Oops, something went wrong.