Skip to content
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

Fix gc duration metric in runtime-telemetry-java17 #12256

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,12 @@
*/
public final class DurationUtil {
private static final double NANOS_PER_SECOND = TimeUnit.SECONDS.toNanos(1);
private static final double MILLIS_PER_SECOND = TimeUnit.SECONDS.toMillis(1);

/** Returns the duration as seconds, with fractional part included. */
public static double toSeconds(Duration duration) {
double epochSecs = (double) duration.getSeconds();
return epochSecs + duration.getNano() / NANOS_PER_SECOND;
}

public static double millisToSeconds(long milliseconds) {
return milliseconds / MILLIS_PER_SECOND;
}

private DurationUtil() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public G1GarbageCollectionHandler(Meter meter) {

@Override
public void accept(RecordedEvent ev) {
histogram.record(DurationUtil.millisToSeconds(ev.getLong(Constants.DURATION)), ATTR);
histogram.record(DurationUtil.toSeconds(ev.getDuration()), ATTR);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public OldGarbageCollectionHandler(Meter meter, String gc) {

@Override
public void accept(RecordedEvent ev) {
histogram.record(DurationUtil.millisToSeconds(ev.getLong(Constants.DURATION)), attributes);
histogram.record(DurationUtil.toSeconds(ev.getDuration()), attributes);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public YoungGarbageCollectionHandler(Meter meter, String gc) {

@Override
public void accept(RecordedEvent ev) {
histogram.record(DurationUtil.millisToSeconds(ev.getLong(Constants.DURATION)), attributes);
histogram.record(DurationUtil.toSeconds(ev.getDuration()), attributes);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import static org.assertj.core.api.Assertions.assertThat;

import java.time.Duration;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;

class DurationUtilTest {
Expand All @@ -19,10 +18,4 @@ void convertDurationToSeconds() {
double seconds = DurationUtil.toSeconds(duration);
assertThat(seconds).isEqualTo(7.000000144);
}

@Test
void convertMillisSeconds() {
double seconds = DurationUtil.millisToSeconds(TimeUnit.SECONDS.toMillis(5));
assertThat(seconds).isEqualTo(5);
}
}
Loading