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

Consistently use baseTimeUnit in StatsD #5687

Closed
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 @@ -43,9 +43,9 @@ public class StatsdTimer extends AbstractTimer {

StatsdTimer(Id id, StatsdLineBuilder lineBuilder, FluxSink<String> sink, Clock clock,
DistributionStatisticConfig distributionStatisticConfig, PauseDetector pauseDetector, TimeUnit baseTimeUnit,
long stepMillis) {
long stepBaseUnits) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
long stepBaseUnits) {
long amount) {

super(id, clock, distributionStatisticConfig, pauseDetector, baseTimeUnit, false);
this.max = new StepDouble(clock, stepMillis);
this.max = new StepDouble(clock, stepBaseUnits);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.max = new StepDouble(clock, stepBaseUnits);
this.max = new StepDouble(clock, amount);

this.lineBuilder = lineBuilder;
this.sink = sink;
}
Expand All @@ -55,13 +55,13 @@ protected void recordNonNegative(long amount, TimeUnit unit) {
if (!shutdown && amount >= 0) {
count.increment();

double msAmount = TimeUtils.convert(amount, unit, TimeUnit.MILLISECONDS);
totalTime.add(msAmount);
double baseUnitAmount = TimeUtils.convert(amount, unit, baseTimeUnit());
totalTime.add(baseUnitAmount);

// not necessary to ship max, as most StatsD agents calculate this themselves
max.getCurrent().add(Math.max(msAmount - max.getCurrent().doubleValue(), 0));
max.getCurrent().add(Math.max(baseUnitAmount - max.getCurrent().doubleValue(), 0));

sink.next(lineBuilder.timing(msAmount));
sink.next(lineBuilder.timing(baseUnitAmount));
}
}

Expand All @@ -72,7 +72,7 @@ public long count() {

@Override
public double totalTime(TimeUnit unit) {
return TimeUtils.convert(totalTime.doubleValue(), TimeUnit.MILLISECONDS, unit);
return TimeUtils.convert(totalTime.doubleValue(), baseTimeUnit(), unit);
}

/**
Expand All @@ -82,7 +82,7 @@ public double totalTime(TimeUnit unit) {
*/
@Override
public double max(TimeUnit unit) {
return TimeUtils.convert(max.poll(), TimeUnit.MILLISECONDS, unit);
return TimeUtils.convert(max.poll(), baseTimeUnit(), unit);
}

void shutdown() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public void record(Runnable f) {
@Override
public final void record(long amount, TimeUnit unit) {
if (amount >= 0) {
histogram.recordLong(TimeUnit.NANOSECONDS.convert(amount, unit));
histogram.recordLong(baseTimeUnit().convert(amount, unit));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this change, this should be recorded as nanos and converted to the right unit at publish-time.

recordNonNegative(amount, unit);

if (intervalEstimator != null) {
Expand Down