-
Notifications
You must be signed in to change notification settings - Fork 858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory Mode: Adding 3rd and last part support for synchronous instruments - exponential histogram #6136
Merged
jack-berg
merged 25 commits into
open-telemetry:main
from
streamnative:memory-mode-sync-instruments-part3
Jan 25, 2024
Merged
Memory Mode: Adding 3rd and last part support for synchronous instruments - exponential histogram #6136
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
0c001b8
First part of synchronous support for memory mode.
asafm e986511
lint + improved error message
asafm 3672a23
Update sdk/common/src/main/java/io/opentelemetry/sdk/common/export/Me…
asafm 8a0330e
Update sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/ViewBui…
asafm 9fbb0b7
PR fixes 1
asafm fb8358d
Merge remote-tracking branch 'origin/memory-mode-sync-instruments-par…
asafm e49c5b4
PR fixes 2
asafm 3444c2c
PR fixes 3
asafm 35cdf26
All seems good. After checking it several times
asafm 1ef3ca8
Check gradle task fixes
asafm 8fda642
Merge remote-tracking branch 'upstream/main' into memory-mode-sync-in…
asafm a021020
Added missing tests to complete the code coverage, where it made sense
asafm 411f73a
Fixes build fails
asafm 55c7ac4
PR fixes - first part
asafm bb074f4
Merge remote-tracking branch 'upstream/main' into memory-mode-sync-in…
asafm 010022c
PR fixes - second part
asafm 6327f9e
Linter fixed and 1 bug fix
asafm ccfce83
More PR fixes
asafm 95690f1
Added sanity unit testing 2 data classes just to pass code coverage
asafm 6a124c5
Linter fixes
asafm 9b0d48e
Added more tests for code coverage
asafm c236048
(Last) part-3 of adding memory mode support for Synchronous instrumen…
asafm c49d2f9
Merge remote-tracking branch 'upstream/main' into memory-mode-sync-in…
asafm 1802396
Fixed last PR comment.
asafm 82337b5
Tiny fix
asafm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
42 changes: 42 additions & 0 deletions
42
...src/jmhBasedTest/java/io/opentelemetry/sdk/metrics/internal/state/TestInstrumentType.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,42 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.sdk.metrics.internal.state; | ||
|
||
import io.opentelemetry.api.common.Attributes; | ||
import io.opentelemetry.sdk.metrics.Aggregation; | ||
import io.opentelemetry.sdk.metrics.SdkMeterProvider; | ||
import io.opentelemetry.sdk.metrics.internal.state.tester.AsyncCounterTester; | ||
import io.opentelemetry.sdk.metrics.internal.state.tester.ExponentialHistogramTester; | ||
import java.util.List; | ||
import java.util.Random; | ||
|
||
public enum TestInstrumentType { | ||
ASYNC_COUNTER(AsyncCounterTester.class), | ||
EXPONENTIAL_HISTOGRAM(ExponentialHistogramTester.class); | ||
|
||
final Class<? extends InstrumentTester> instrumentTesterClass; | ||
|
||
TestInstrumentType(Class<? extends InstrumentTester> instrumentTesterClass) { | ||
this.instrumentTesterClass = instrumentTesterClass; | ||
} | ||
|
||
public interface InstrumentTester { | ||
Aggregation testedAggregation(); | ||
|
||
TestInstrumentsState buildInstruments( | ||
double instrumentCount, | ||
SdkMeterProvider sdkMeterProvider, | ||
List<Attributes> attributesList, | ||
Random random); | ||
|
||
void recordValuesInInstruments( | ||
TestInstrumentsState testInstrumentsState, List<Attributes> attributesList, Random random); | ||
} | ||
|
||
public interface TestInstrumentsState {} | ||
|
||
public static class EmptyInstrumentsState implements TestInstrumentsState {} | ||
} |
51 changes: 51 additions & 0 deletions
51
...BasedTest/java/io/opentelemetry/sdk/metrics/internal/state/tester/AsyncCounterTester.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.sdk.metrics.Aggregation; | ||
import io.opentelemetry.sdk.metrics.SdkMeterProvider; | ||
import io.opentelemetry.sdk.metrics.internal.state.TestInstrumentType; | ||
import io.opentelemetry.sdk.metrics.internal.state.TestInstrumentType.EmptyInstrumentsState; | ||
import java.util.List; | ||
import java.util.Random; | ||
|
||
public class AsyncCounterTester implements TestInstrumentType.InstrumentTester { | ||
@Override | ||
public Aggregation testedAggregation() { | ||
return Aggregation.sum(); | ||
} | ||
|
||
@SuppressWarnings("ForLoopReplaceableByForEach") // This is for GC sensitivity testing: no streams | ||
@Override | ||
public TestInstrumentType.TestInstrumentsState buildInstruments( | ||
double instrumentCount, | ||
SdkMeterProvider sdkMeterProvider, | ||
List<Attributes> attributesList, | ||
Random random) { | ||
for (int i = 0; i < instrumentCount; i++) { | ||
sdkMeterProvider | ||
.get("meter") | ||
.counterBuilder("counter" + i) | ||
.buildWithCallback( | ||
observableLongMeasurement -> { | ||
for (int j = 0; j < attributesList.size(); j++) { | ||
Attributes attributes = attributesList.get(j); | ||
observableLongMeasurement.record(random.nextInt(10_000), attributes); | ||
} | ||
}); | ||
} | ||
return new EmptyInstrumentsState(); | ||
} | ||
|
||
@Override | ||
public void recordValuesInInstruments( | ||
TestInstrumentType.TestInstrumentsState testInstrumentsState, | ||
List<Attributes> attributesList, | ||
Random random) { | ||
// No need, all done via the callbacks | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...t/java/io/opentelemetry/sdk/metrics/internal/state/tester/ExponentialHistogramTester.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,57 @@ | ||
/* | ||
* 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.DoubleHistogram; | ||
import io.opentelemetry.sdk.metrics.Aggregation; | ||
import io.opentelemetry.sdk.metrics.SdkMeterProvider; | ||
import io.opentelemetry.sdk.metrics.internal.state.TestInstrumentType; | ||
import io.opentelemetry.sdk.metrics.internal.state.TestInstrumentType.InstrumentTester; | ||
import java.util.List; | ||
import java.util.Random; | ||
|
||
public class ExponentialHistogramTester implements InstrumentTester { | ||
|
||
static class ExponentialHistogramState implements TestInstrumentType.TestInstrumentsState { | ||
DoubleHistogram doubleHistogram; | ||
} | ||
|
||
private static final int measurementsPerAttributeSet = 1_000; | ||
|
||
@Override | ||
public Aggregation testedAggregation() { | ||
return Aggregation.base2ExponentialBucketHistogram(); | ||
} | ||
|
||
@Override | ||
public TestInstrumentType.TestInstrumentsState buildInstruments( | ||
double instrumentCount, | ||
SdkMeterProvider sdkMeterProvider, | ||
List<Attributes> attributesList, | ||
Random random) { | ||
ExponentialHistogramState state = new ExponentialHistogramState(); | ||
state.doubleHistogram = sdkMeterProvider.get("meter").histogramBuilder("testhistogram").build(); | ||
return state; | ||
} | ||
|
||
@SuppressWarnings("ForLoopReplaceableByForEach") // This is for GC sensitivity testing: no streams | ||
@Override | ||
public void recordValuesInInstruments( | ||
TestInstrumentType.TestInstrumentsState testInstrumentsState, | ||
List<Attributes> attributesList, | ||
Random random) { | ||
|
||
ExponentialHistogramState state = (ExponentialHistogramState) testInstrumentsState; | ||
|
||
for (int j = 0; j < attributesList.size(); j++) { | ||
Attributes attributes = attributesList.get(j); | ||
for (int i = 0; i < measurementsPerAttributeSet; i++) { | ||
state.doubleHistogram.record(random.nextInt(10_000), attributes); | ||
} | ||
} | ||
} | ||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#nit: If you change
instrumentTesterClass
fromClass<? extends InstrumentTester>
toSupplier<InstrumentTester>
, and configure each element in theTestInstrumentType
enum with a factory method for creating new instances ofInstrumentTester
:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Much better.
I did it with an abstract method since error prone recommended it, and it does seem cleaner.
I also added the
ProfileBenchmark
and linked to it from the test