use of com.codahale.metrics.Clock 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.Clock in project lucene-solr by apache.
the class MetricSuppliers method getClock.
private static Clock getClock(PluginInfo info, String param) {
if (info == null) {
return Clock.defaultClock();
}
String clock = null;
if (info.attributes != null) {
clock = info.attributes.get(param);
}
if (clock == null && info.initArgs != null) {
clock = (String) info.initArgs.get(param);
}
Clock clk = Clock.defaultClock();
if (clock != null) {
if (clock.equalsIgnoreCase(CLOCK_USER)) {
clk = USER_CLOCK;
} else if (clock.equalsIgnoreCase(CLOCK_CPU)) {
clk = CPU_CLOCK;
}
}
return clk;
}
use of com.codahale.metrics.Clock in project metrics by dropwizard.
the class HealthCheckTest method toStringWorksEvenForNullAttributes.
@Test
public void toStringWorksEvenForNullAttributes() {
ZonedDateTime dateTime = ZonedDateTime.now().minusMinutes(25);
Clock clock = clockWithFixedTime(dateTime);
final HealthCheck.Result resultWithNullDetailValue = HealthCheck.Result.builder().unhealthy().withDetail("aNullDetail", null).usingClock(clock).build();
assertThat(resultWithNullDetailValue.toString()).contains("Result{isHealthy=false, duration=0, timestamp=" + DATE_TIME_FORMATTER.format(dateTime), ", aNullDetail=null}");
}
use of com.codahale.metrics.Clock in project metrics by dropwizard.
the class HealthCheckTest method canHaveUserSuppliedClockForTimestamp.
@Test
public void canHaveUserSuppliedClockForTimestamp() {
ZonedDateTime dateTime = ZonedDateTime.now().minusMinutes(10);
Clock clock = clockWithFixedTime(dateTime);
HealthCheck.Result result = HealthCheck.Result.builder().healthy().usingClock(clock).build();
assertThat(result.isHealthy()).isTrue();
assertThat(result.getTime()).isEqualTo(clock.getTime());
assertThat(result.getTimestamp()).isEqualTo(DATE_TIME_FORMATTER.format(dateTime));
}
use of com.codahale.metrics.Clock in project lucene-solr by apache.
the class MetricsConfigTest method testDefaults.
@Test
public void testDefaults() throws Exception {
NodeConfig cfg = loadNodeConfig();
SolrMetricManager mgr = new SolrMetricManager(loader, cfg.getMetricsConfig());
assertTrue(mgr.getCounterSupplier() instanceof MetricSuppliers.DefaultCounterSupplier);
assertTrue(mgr.getMeterSupplier() instanceof MetricSuppliers.DefaultMeterSupplier);
assertTrue(mgr.getTimerSupplier() instanceof MetricSuppliers.DefaultTimerSupplier);
assertTrue(mgr.getHistogramSupplier() instanceof MetricSuppliers.DefaultHistogramSupplier);
Clock clk = ((MetricSuppliers.DefaultTimerSupplier) mgr.getTimerSupplier()).clk;
assertTrue(clk instanceof Clock.UserTimeClock);
Reservoir rsv = ((MetricSuppliers.DefaultTimerSupplier) mgr.getTimerSupplier()).getReservoir();
assertTrue(rsv instanceof ExponentiallyDecayingReservoir);
}
Aggregations