use of com.codahale.metrics.Reservoir in project riposte by Nike-Inc.
the class SignalFxEndpointMetricsHandlerTest method RollingWindowTimerBuilder_newMetric_creates_new_timer_with_SlidingTimeWindowReservoir_with_expected_values.
@DataProvider(value = { "42 | DAYS", "123 | SECONDS", "999 | MILLISECONDS", "3 | HOURS" }, splitBy = "\\|")
@Test
public void RollingWindowTimerBuilder_newMetric_creates_new_timer_with_SlidingTimeWindowReservoir_with_expected_values(long amount, TimeUnit timeUnit) {
// given
RollingWindowTimerBuilder rwtb = new RollingWindowTimerBuilder(amount, timeUnit);
// when
Timer timer = rwtb.newMetric();
// then
Histogram histogram = (Histogram) getInternalState(timer, "histogram");
Reservoir reservoir = (Reservoir) getInternalState(histogram, "reservoir");
assertThat(reservoir).isInstanceOf(SlidingTimeWindowReservoir.class);
// The expected value here comes from logic in the SlidingTimeWindowReservoir constructor.
assertThat(getInternalState(reservoir, "window")).isEqualTo(timeUnit.toNanos(amount) * 256);
}
use of com.codahale.metrics.Reservoir in project lucene-solr by apache.
the class MetricSuppliers method getReservoir.
private static final Reservoir getReservoir(SolrResourceLoader loader, PluginInfo info) {
if (info == null) {
return new ExponentiallyDecayingReservoir();
}
Clock clk = getClock(info, CLOCK);
String clazz = ExponentiallyDecayingReservoir.class.getName();
int size = -1;
double alpha = -1;
long window = -1;
if (info.initArgs != null) {
if (info.initArgs.get(RESERVOIR) != null) {
String val = String.valueOf(info.initArgs.get(RESERVOIR)).trim();
if (!val.isEmpty()) {
clazz = val;
}
}
Number n = (Number) info.initArgs.get(RESERVOIR_SIZE);
if (n != null) {
size = n.intValue();
}
n = (Number) info.initArgs.get(RESERVOIR_EDR_ALPHA);
if (n != null) {
alpha = n.doubleValue();
}
n = (Number) info.initArgs.get(RESERVOIR_WINDOW);
if (n != null) {
window = n.longValue();
}
}
if (size <= 0) {
size = DEFAULT_SIZE;
}
if (alpha <= 0) {
alpha = DEFAULT_ALPHA;
}
// special case for core implementations
if (clazz.equals(EDR_CLAZZ)) {
return new ExponentiallyDecayingReservoir(size, alpha, clk);
} else if (clazz.equals(UNI_CLAZZ)) {
return new UniformReservoir(size);
} else if (clazz.equals(STW_CLAZZ)) {
if (window <= 0) {
// 5 minutes, comparable to EDR
window = DEFAULT_WINDOW;
}
return new SlidingTimeWindowReservoir(window, TimeUnit.SECONDS);
} else if (clazz.equals(SW_CLAZZ)) {
return new SlidingWindowReservoir(size);
} else {
// custom reservoir
Reservoir reservoir;
try {
reservoir = loader.newInstance(clazz, Reservoir.class);
if (reservoir instanceof PluginInfoInitialized) {
((PluginInfoInitialized) reservoir).init(info);
} else {
SolrPluginUtils.invokeSetters(reservoir, info.initArgs, true);
}
return reservoir;
} catch (Exception e) {
log.warn("Error initializing custom Reservoir implementation (will use default): " + info, e);
return new ExponentiallyDecayingReservoir(size, alpha, clk);
}
}
}
use of com.codahale.metrics.Reservoir in project torodb by torodb.
the class ToroMetricRegistry method histogram.
/**
*
* @param name
* @param resetOnSnapshot This is usually true if you're using snapshots as a means of defining
* the window in which you want to calculate, say, the 99.9th percentile
* @return
*/
public Histogram histogram(MetricName name, boolean resetOnSnapshot) {
Reservoir reservoir;
if (resetOnSnapshot) {
reservoir = new HdrHistogramResetOnSnapshotReservoir();
} else {
reservoir = new HdrHistogramReservoir();
}
Histogram histogram = register(name, new Histogram(reservoir));
return histogram;
}
use of com.codahale.metrics.Reservoir in project riposte by Nike-Inc.
the class SignalFxEndpointMetricsHandlerTest method RollingWindowHistogramBuilder_newMetric_creates_new_histogram_with_SlidingTimeWindowReservoir_with_expected_values.
@DataProvider(value = { "42 | DAYS", "123 | SECONDS", "999 | MILLISECONDS", "3 | HOURS" }, splitBy = "\\|")
@Test
public void RollingWindowHistogramBuilder_newMetric_creates_new_histogram_with_SlidingTimeWindowReservoir_with_expected_values(long amount, TimeUnit timeUnit) {
// given
RollingWindowHistogramBuilder rwhb = new RollingWindowHistogramBuilder(amount, timeUnit);
// when
Histogram histogram = rwhb.newMetric();
// then
Reservoir reservoir = (Reservoir) getInternalState(histogram, "reservoir");
assertThat(reservoir).isInstanceOf(SlidingTimeWindowReservoir.class);
// The expected value here comes from logic in the SlidingTimeWindowReservoir constructor.
assertThat(getInternalState(reservoir, "window")).isEqualTo(timeUnit.toNanos(amount) * 256);
}
use of com.codahale.metrics.Reservoir in project ambry by linkedin.
the class CachedHistogramTest method testCache.
/**
* Test caching behavior.
*/
@Test
public void testCache() {
AtomicInteger snapshotCalls = new AtomicInteger(0);
MockClock clock = new MockClock();
Reservoir reservoir = new ExponentiallyDecayingReservoir();
CachedHistogram histogram = new CachedHistogram(clock, reservoir, TimeUnit.SECONDS.toMillis(1), 0.50) {
@Override
public Snapshot getSnapshot() {
// count number of calls to test caching
snapshotCalls.getAndIncrement();
return super.getSnapshot();
}
};
long value = 2;
double epsilon = 0.01;
histogram.update(value);
// getSnapshot should be called the first time
assertEquals(value, histogram.getCachedValue(), epsilon);
assertEquals(1, snapshotCalls.get());
// the cached value should be used and getSnapshot should not be called.
assertEquals(value, histogram.getCachedValue(), epsilon);
assertEquals(1, snapshotCalls.get());
// after progressing time, the cached value should expire and getSnapshot should be called
clock.tick(1);
assertEquals(value, histogram.getCachedValue(), epsilon);
assertEquals(2, snapshotCalls.get());
}
Aggregations