Skip to content

Commit

Permalink
Merge pull request #263 from brharrington/digest-registry-gauges
Browse files Browse the repository at this point in the history
TDigestRegistry should add gauges to underlying
  • Loading branch information
brharrington committed Jan 19, 2016
2 parents dc6c4ac + 9054ff7 commit 9964289
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private Meter compute(Meter m, Meter fallback) {
return (meters.size() >= Config.maxNumberOfMeters()) ? fallback : m;
}

@Override public final void register(Meter meter) {
@Override public void register(Meter meter) {
Meter aggr = (meters.size() >= Config.maxNumberOfMeters())
? meters.get(meter.id())
: meters.computeIfAbsent(meter.id(), AggrMeter::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,8 @@ private StepDigest newDigest(Id id) {
final long step = config.getPollingFrequency(TimeUnit.MILLISECONDS);
return new StepDigest(underlying, id, config.getCompressionFactor(), step);
}

@Override public void register(Meter meter) {
underlying.register(meter);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Copyright 2014-2016 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.netflix.spectator.tdigest;

import com.netflix.spectator.api.DefaultRegistry;
import com.netflix.spectator.api.Id;
import com.netflix.spectator.api.ManualClock;
import com.typesafe.config.ConfigFactory;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.util.concurrent.atomic.AtomicInteger;

@RunWith(JUnit4.class)
public class TDigestRegistryTest {

private final ManualClock clock = new ManualClock();
private final DefaultRegistry registry = new DefaultRegistry(clock);
private final TDigestConfig config = new TDigestConfig(
ConfigFactory.parseString("polling-frequency = 60s"));

@Test
public void gaugesAreRegisteredWithUnderlying() throws Exception {
TDigestRegistry tdr = new TDigestRegistry(registry, config);
Id id = tdr.createId("test");
AtomicInteger value = new AtomicInteger(0);
tdr.gauge(id, value);
Assert.assertNotNull(registry.get(id));
}
}

0 comments on commit 9964289

Please sign in to comment.