Skip to content

Commit

Permalink
code review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Rzeszutek committed Jan 10, 2022
1 parent 4c91065 commit 1ff3b2e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void increment(double v) {
@Override
public double count() {
UnsupportedReadLogger.logWarning();
return 0;
return Double.NaN;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ final class OpenTelemetryFunctionCounter<T> implements FunctionCounter, Removabl
@Override
public double count() {
UnsupportedReadLogger.logWarning();
return 0;
return Double.NaN;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,17 @@ final class OpenTelemetryFunctionTimer<T> implements FunctionTimer, RemovableMet
/* baseUnit = */ "ms",
attributes,
obj,
new ConvertToMillisDecorator<>(totalTimeFunction, totalTimeFunctionUnit));
val ->
TimeUtils.convert(
totalTimeFunction.applyAsDouble(val),
totalTimeFunctionUnit,
TimeUnit.MILLISECONDS));
}

@Override
public double count() {
UnsupportedReadLogger.logWarning();
return 0;
return Double.NaN;
}

@Override
Expand All @@ -66,6 +70,12 @@ public double totalTime(TimeUnit unit) {
return Double.NaN;
}

@Override
public double mean(TimeUnit unit) {
UnsupportedReadLogger.logWarning();
return Double.NaN;
}

@Override
public TimeUnit baseTimeUnit() {
return TimeUnit.MILLISECONDS;
Expand Down Expand Up @@ -98,21 +108,4 @@ public boolean equals(Object o) {
public int hashCode() {
return MeterEquivalence.hashCode(this);
}

private static final class ConvertToMillisDecorator<T> implements ToDoubleFunction<T> {

private final ToDoubleFunction<T> original;
private final TimeUnit originalUnit;

private ConvertToMillisDecorator(ToDoubleFunction<T> original, TimeUnit originalUnit) {
this.original = original;
this.originalUnit = originalUnit;
}

@Override
public double applyAsDouble(T value) {
double time = original.applyAsDouble(value);
return TimeUtils.convert(time, originalUnit, TimeUnit.MILLISECONDS);
}
}
}

0 comments on commit 1ff3b2e

Please sign in to comment.