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

add test for preserving custom statistic #1004

Merged
merged 1 commit into from
Nov 11, 2022
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 @@ -18,7 +18,6 @@
import com.netflix.spectator.api.Clock;
import com.netflix.spectator.api.Counter;
import com.netflix.spectator.api.Id;
import com.netflix.spectator.api.Registry;
import com.netflix.spectator.api.Statistic;
import com.netflix.spectator.impl.StepDouble;

Expand All @@ -33,12 +32,12 @@ class AtlasCounter extends AtlasMeter implements Counter {
private final Id stat;

/** Create a new instance. */
AtlasCounter(Registry registry, Id id, Clock clock, long ttl, long step) {
AtlasCounter(Id id, Clock clock, long ttl, long step) {
super(id, clock, ttl);
this.value = new StepDouble(0.0, clock, step);
// Add the statistic for typing. Re-adding the tags from the id is to retain
// the statistic from the id if it was already set
this.stat = registry.createId(id.name())
this.stat = Id.create(id.name())
.withTag(Statistic.count)
.withTag(DsType.rate)
.withTags(id.tags());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ synchronized List<RollupPolicy.Result> getBatches(long t) {
}

@Override protected Counter newCounter(Id id) {
return new AtlasCounter(this, id, clock(), meterTTL, lwcStepMillis);
return new AtlasCounter(id, clock(), meterTTL, lwcStepMillis);
}

@Override protected DistributionSummary newDistributionSummary(Id id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
*/
package com.netflix.spectator.atlas;

import com.netflix.spectator.api.DefaultRegistry;
import com.netflix.spectator.api.Id;
import com.netflix.spectator.api.ManualClock;
import com.netflix.spectator.api.Measurement;
import com.netflix.spectator.api.Registry;
import com.netflix.spectator.api.Statistic;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
Expand All @@ -27,10 +26,8 @@
public class AtlasCounterTest {

private final ManualClock clock = new ManualClock();
private final Registry registry = new DefaultRegistry();
private final long step = 10000L;
private final AtlasCounter counter = new AtlasCounter(registry,
registry.createId("test"), clock, step, step);
private final AtlasCounter counter = new AtlasCounter(Id.create("test"), clock, step, step);

private void checkValue(double expected) {
int count = 0;
Expand Down Expand Up @@ -119,4 +116,12 @@ public void expiration() {
counter.increment(42L);
Assertions.assertFalse(counter.hasExpired());
}

@Test
public void preferStatisticFromTags() {
Id id = Id.create("test").withTag(Statistic.percentile);
AtlasCounter c = new AtlasCounter(id, clock, step, step);
Id actual = c.measure().iterator().next().id();
Assertions.assertEquals(id.withTag(DsType.rate), actual);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@

import java.util.Arrays;

import com.netflix.spectator.api.DefaultRegistry;
import com.netflix.spectator.api.DistributionSummary;
import com.netflix.spectator.api.Id;
import com.netflix.spectator.api.Measurement;
import com.netflix.spectator.api.Registry;
import com.netflix.spectator.api.Utils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
Expand Down