Skip to content

Commit

Permalink
Merge pull request #12 from Netflix/bugfix/spectator_gauge
Browse files Browse the repository at this point in the history
Fix spectator gauge
  • Loading branch information
elandau authored Feb 7, 2018
2 parents 1e01b56 + 0744ff5 commit 4f3d51c
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 15 deletions.
2 changes: 2 additions & 0 deletions concurrency-limits-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ plugins {
sourceCompatibility = JavaVersion.VERSION_1_8

dependencies {
compile "org.slf4j:slf4j-api:1.7.+"

testCompile 'junit:junit-dep:4.10'
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,20 @@ interface SampleListener {
SampleListener registerDistribution(String id, String... tagNameValuePairs);

/**
* Register a guage using the provided supplier. The supplier will be polled whenever the guage
* Register a gauge using the provided supplier. The supplier will be polled whenever the guage
* value is flushed by the registry.
*
* @param id
* @param tagNameValuePairs Pairs of tag name and tag value. Number of parameters must be a multiple of 2.
* @param supplier
*/
void registerGuage(String id, Supplier<Number> supplier, String... tagNameValuePairs);
void registerGauge(String id, Supplier<Number> supplier, String... tagNameValuePairs);

/**
* @deprecated Call MetricRegistry#registerGauge
*/
@Deprecated
default void registerGuage(String id, Supplier<Number> supplier, String... tagNameValuePairs) {
registerGauge(id, supplier, tagNameValuePairs);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public SampleListener registerDistribution(String id, String... tagNameValuePair
}

@Override
public void registerGuage(String id, Supplier<Number> supplier, String... tagNameValuePairs) {
public void registerGauge(String id, Supplier<Number> supplier, String... tagNameValuePairs) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static VegasLimit newDefault() {
*/
private volatile int estimatedLimit;

private long rtt_noload;
private volatile long rtt_noload;

private boolean didDrop = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private LookupPartitionStrategy(Builder<T> builder) {

this.lookup = builder.lookup;

builder.registry.registerGuage(MetricIds.LIMIT_GUAGE_NAME, this::getLimit);
builder.registry.registerGauge(MetricIds.LIMIT_GUAGE_NAME, this::getLimit);
}

@Override
Expand Down Expand Up @@ -118,7 +118,7 @@ public Partition(String name, double pct) {

public void createMetrics(MetricRegistry registry) {
this.busyDistribution = registry.registerDistribution(MetricIds.INFLIGHT_GUAGE_NAME, PARTITION_TAG_NAME, name);
registry.registerGuage(MetricIds.PARTITION_LIMIT_GUAGE_NAME, this::getLimit, PARTITION_TAG_NAME, name);
registry.registerGauge(MetricIds.PARTITION_LIMIT_GUAGE_NAME, this::getLimit, PARTITION_TAG_NAME, name);
}

public void updateLimit(int totalLimit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private PredicatePartitionStrategy(Builder<T> builder) {
this.partitions = new ArrayList<>(builder.partitions);
this.partitions.forEach(partition -> partition.createMetrics(builder.registry));

builder.registry.registerGuage(MetricIds.LIMIT_GUAGE_NAME, this::getLimit);
builder.registry.registerGauge(MetricIds.LIMIT_GUAGE_NAME, this::getLimit);
}

@Override
Expand Down Expand Up @@ -116,7 +116,7 @@ public Partition(String name, double pct, Predicate<T> predicate) {

public void createMetrics(MetricRegistry registry) {
this.inflightDistribution = registry.registerDistribution(MetricIds.INFLIGHT_GUAGE_NAME, PARTITION_TAG_NAME, name);
registry.registerGuage(MetricIds.PARTITION_LIMIT_GUAGE_NAME, this::getLimit, PARTITION_TAG_NAME, name);
registry.registerGauge(MetricIds.PARTITION_LIMIT_GUAGE_NAME, this::getLimit, PARTITION_TAG_NAME, name);
}

public void updateLimit(int totalLimit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public SimpleStrategy() {

public SimpleStrategy(MetricRegistry registry) {
this.inflightMetric = registry.registerDistribution(MetricIds.INFLIGHT_GUAGE_NAME);
registry.registerGuage(MetricIds.LIMIT_GUAGE_NAME, this::getLimit);
registry.registerGauge(MetricIds.LIMIT_GUAGE_NAME, this::getLimit);
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions concurrency-limits-grpc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ sourceCompatibility = JavaVersion.VERSION_1_8
dependencies {
compile project(":concurrency-limits-core")

compile "io.grpc:grpc-core:1.3.1"
compile "io.grpc:grpc-core:1.9.0"

testCompile project(":concurrency-limits-spectator")

testCompile "io.grpc:grpc-netty:1.3.1"
testCompile "io.grpc:grpc-stub:1.3.1"
testCompile "io.grpc:grpc-netty:1.9.0"
testCompile "io.grpc:grpc-stub:1.9.0"
testCompile "junit:junit-dep:4.10"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

import java.util.function.Supplier;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class SpectatorMetricRegistry implements MetricRegistry {
private final Registry registry;
private final Id baseId;
Expand All @@ -24,10 +27,10 @@ public SampleListener registerDistribution(String id, String... tagNameValuePair
}

@Override
public void registerGuage(String id, Supplier<Number> supplier, String... tagNameValuePairs) {
public void registerGauge(String id, Supplier<Number> supplier, String... tagNameValuePairs) {
PolledMeter.using(registry)
.withId(suffixBaseId(id).withTags(tagNameValuePairs))
.monitorValue(this, o -> supplier.get().doubleValue());
.monitorValue(supplier, ignore -> supplier.get().doubleValue());
}

private Id suffixBaseId(String suffix) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public void testGuage() {
DefaultRegistry registry = new DefaultRegistry();
SpectatorMetricRegistry metricRegistry = new SpectatorMetricRegistry(registry, registry.createId("foo"));

metricRegistry.registerGuage("bar", () -> 10);
metricRegistry.registerGauge("bar", () -> 10);

PolledMeter.update(registry);

Expand Down

0 comments on commit 4f3d51c

Please sign in to comment.