-
Notifications
You must be signed in to change notification settings - Fork 871
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
Update units of time based metrics from millis to seconds for Java17 … #12084
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
package io.opentelemetry.instrumentation.runtimemetrics.java17.internal.garbagecollection; | ||
|
||
import io.opentelemetry.api.common.Attributes; | ||
import io.opentelemetry.api.metrics.LongHistogram; | ||
import io.opentelemetry.api.metrics.DoubleHistogram; | ||
import io.opentelemetry.api.metrics.Meter; | ||
import io.opentelemetry.instrumentation.runtimemetrics.java17.JfrFeature; | ||
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.Constants; | ||
|
@@ -27,21 +27,20 @@ public final class G1GarbageCollectionHandler implements RecordedEventHandler { | |
"G1 Young Generation", | ||
Constants.ATTR_GC_ACTION, | ||
Constants.END_OF_MINOR_GC); | ||
private final LongHistogram histogram; | ||
private final DoubleHistogram histogram; | ||
|
||
public G1GarbageCollectionHandler(Meter meter) { | ||
histogram = | ||
meter | ||
.histogramBuilder(Constants.METRIC_NAME_GC_DURATION) | ||
.setDescription(Constants.METRIC_DESCRIPTION_GC_DURATION) | ||
.setUnit(Constants.MILLISECONDS) | ||
.ofLongs() | ||
.setUnit(Constants.SECONDS) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public void accept(RecordedEvent ev) { | ||
histogram.record(ev.getLong(Constants.DURATION), ATTR); | ||
histogram.record(ev.getDouble(Constants.DURATION), ATTR); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @robsunday I'm writing up the release notes for the upcoming release and had a question here, does this need a conversion from milliseconds to seconds? thanks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, you are right - conversion should be added here and in all other modified handlers. Thanks for a great catch - I missed that. I'll update it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hopefully resolved with #12244 |
||
} | ||
|
||
@Override | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.runtimemetrics.java17.internal; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.time.Duration; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class DurationUtilTest { | ||
|
||
@Test | ||
void shouldConvertDurationToSeconds() { | ||
// Given | ||
Duration duration = Duration.ofSeconds(7, 144); | ||
|
||
// When | ||
double seconds = DurationUtil.toSeconds(duration); | ||
|
||
// Then | ||
assertEquals(7.000000144, seconds); | ||
} | ||
} |
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.
elsewhere we use
TimeUnit.SECONDS.toNanos(1)
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.
Yes, that is correct, I kept this scientific notation because it was already there. It may be a good idea to apply unified approach, however it would be even better to define it in a single place. I'll take a look at this. Thanks for the feedback.