-
Notifications
You must be signed in to change notification settings - Fork 848
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert histogram measurements to double before passing recording exe…
…mplar reservoir
- Loading branch information
Showing
7 changed files
with
286 additions
and
6 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
35 changes: 35 additions & 0 deletions
35
...in/java/io/opentelemetry/sdk/metrics/internal/exemplar/LongToDoubleExemplarReservoir.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,35 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.sdk.metrics.internal.exemplar; | ||
|
||
import io.opentelemetry.api.common.Attributes; | ||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.sdk.metrics.data.ExemplarData; | ||
import java.util.List; | ||
|
||
class LongToDoubleExemplarReservoir<T extends ExemplarData> implements ExemplarReservoir<T> { | ||
|
||
private final ExemplarReservoir<T> delegate; | ||
|
||
LongToDoubleExemplarReservoir(ExemplarReservoir<T> delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
@Override | ||
public void offerDoubleMeasurement(double value, Attributes attributes, Context context) { | ||
delegate.offerDoubleMeasurement(value, attributes, context); | ||
} | ||
|
||
@Override | ||
public void offerLongMeasurement(long value, Attributes attributes, Context context) { | ||
offerDoubleMeasurement((double) value, attributes, context); | ||
} | ||
|
||
@Override | ||
public List<T> collectAndReset(Attributes pointAttributes) { | ||
return delegate.collectAndReset(pointAttributes); | ||
} | ||
} |
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
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
39 changes: 39 additions & 0 deletions
39
...ava/io/opentelemetry/sdk/metrics/internal/exemplar/LongToDoubleExemplarReservoirTest.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,39 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.sdk.metrics.internal.exemplar; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyLong; | ||
import static org.mockito.Mockito.never; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import io.opentelemetry.api.common.Attributes; | ||
import io.opentelemetry.context.Context; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class LongToDoubleExemplarReservoirTest { | ||
@Mock ExemplarReservoir<?> delegate; | ||
|
||
@Test | ||
void offerDoubleMeasurement() { | ||
ExemplarReservoir<?> filtered = new LongToDoubleExemplarReservoir<>(delegate); | ||
filtered.offerDoubleMeasurement(1.0, Attributes.empty(), Context.root()); | ||
verify(delegate).offerDoubleMeasurement(1.0, Attributes.empty(), Context.root()); | ||
verify(delegate, never()).offerLongMeasurement(anyLong(), any(), any()); | ||
} | ||
|
||
@Test | ||
void offerLongMeasurement() { | ||
ExemplarReservoir<?> filtered = new LongToDoubleExemplarReservoir<>(delegate); | ||
filtered.offerLongMeasurement(1L, Attributes.empty(), Context.root()); | ||
verify(delegate).offerDoubleMeasurement(1.0, Attributes.empty(), Context.root()); | ||
verify(delegate, never()).offerLongMeasurement(anyLong(), any(), any()); | ||
} | ||
} |