-
Notifications
You must be signed in to change notification settings - Fork 831
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Memory mode: Adding support for synchronous instruments - Last Value …
…aggregation (#6196)
- Loading branch information
Showing
9 changed files
with
275 additions
and
45 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
50 changes: 50 additions & 0 deletions
50
...edTest/java/io/opentelemetry/sdk/metrics/internal/state/tester/DoubleLastValueTester.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,50 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.sdk.metrics.internal.state.tester; | ||
|
||
import io.opentelemetry.api.common.Attributes; | ||
import io.opentelemetry.api.metrics.Meter; | ||
import io.opentelemetry.sdk.metrics.Aggregation; | ||
import io.opentelemetry.sdk.metrics.SdkMeterProvider; | ||
import io.opentelemetry.sdk.metrics.internal.state.TestInstrumentType; | ||
import java.util.List; | ||
import java.util.Random; | ||
|
||
public class DoubleLastValueTester implements TestInstrumentType.InstrumentTester { | ||
|
||
@Override | ||
public Aggregation testedAggregation() { | ||
return Aggregation.lastValue(); | ||
} | ||
|
||
@SuppressWarnings("ForLoopReplaceableByForEach") // This is for GC sensitivity testing: no streams | ||
@Override | ||
public TestInstrumentType.TestInstrumentsState buildInstruments( | ||
double instrumentCount, | ||
SdkMeterProvider sdkMeterProvider, | ||
List<Attributes> attributesList, | ||
Random random) { | ||
Meter meter = sdkMeterProvider.meterBuilder("meter").build(); | ||
meter | ||
.gaugeBuilder("test.double.last.value") | ||
.buildWithCallback( | ||
observableDoubleMeasurement -> { | ||
for (int j = 0; j < attributesList.size(); j++) { | ||
observableDoubleMeasurement.record(1.2f, attributesList.get(j)); | ||
} | ||
}); | ||
|
||
return new TestInstrumentType.EmptyInstrumentsState(); | ||
} | ||
|
||
@Override | ||
public void recordValuesInInstruments( | ||
TestInstrumentType.TestInstrumentsState testInstrumentsState, | ||
List<Attributes> attributesList, | ||
Random random) { | ||
// Recording is done by the callback define above | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...asedTest/java/io/opentelemetry/sdk/metrics/internal/state/tester/LongLastValueTester.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,51 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.sdk.metrics.internal.state.tester; | ||
|
||
import io.opentelemetry.api.common.Attributes; | ||
import io.opentelemetry.api.metrics.Meter; | ||
import io.opentelemetry.sdk.metrics.Aggregation; | ||
import io.opentelemetry.sdk.metrics.SdkMeterProvider; | ||
import io.opentelemetry.sdk.metrics.internal.state.TestInstrumentType; | ||
import java.util.List; | ||
import java.util.Random; | ||
|
||
public class LongLastValueTester implements TestInstrumentType.InstrumentTester { | ||
|
||
@Override | ||
public Aggregation testedAggregation() { | ||
return Aggregation.lastValue(); | ||
} | ||
|
||
@SuppressWarnings({"ForLoopReplaceableByForEach", "resource"}) | ||
@Override | ||
public TestInstrumentType.TestInstrumentsState buildInstruments( | ||
double instrumentCount, | ||
SdkMeterProvider sdkMeterProvider, | ||
List<Attributes> attributesList, | ||
Random random) { | ||
Meter meter = sdkMeterProvider.meterBuilder("meter").build(); | ||
meter | ||
.gaugeBuilder("test.long.last.value") | ||
.ofLongs() | ||
.buildWithCallback( | ||
observableLongMeasurement -> { | ||
for (int j = 0; j < attributesList.size(); j++) { | ||
observableLongMeasurement.record(1, attributesList.get(j)); | ||
} | ||
}); | ||
|
||
return new TestInstrumentType.EmptyInstrumentsState(); | ||
} | ||
|
||
@Override | ||
public void recordValuesInInstruments( | ||
TestInstrumentType.TestInstrumentsState testInstrumentsState, | ||
List<Attributes> attributesList, | ||
Random random) { | ||
// Recording is done by the callback define above | ||
} | ||
} |
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
Oops, something went wrong.