use of org.apache.kafka.common.metrics.stats.WindowedSum in project kafka by apache.
the class SensorTest method testIdempotentAdd.
@Test
public void testIdempotentAdd() {
final Metrics metrics = new Metrics();
final Sensor sensor = metrics.sensor("sensor");
assertTrue(sensor.add(metrics.metricName("test-metric", "test-group"), new Avg()));
// adding the same metric to the same sensor is a no-op
assertTrue(sensor.add(metrics.metricName("test-metric", "test-group"), new Avg()));
// but adding the same metric to a DIFFERENT sensor is an error
final Sensor anotherSensor = metrics.sensor("another-sensor");
try {
anotherSensor.add(metrics.metricName("test-metric", "test-group"), new Avg());
fail("should have thrown");
} catch (final IllegalArgumentException ignored) {
// pass
}
// note that adding a different metric with the same name is also a no-op
assertTrue(sensor.add(metrics.metricName("test-metric", "test-group"), new WindowedSum()));
// so after all this, we still just have the original metric registered
assertEquals(1, sensor.metrics().size());
assertEquals(org.apache.kafka.common.metrics.stats.Avg.class, sensor.metrics().get(0).measurable().getClass());
}
use of org.apache.kafka.common.metrics.stats.WindowedSum in project kafka by apache.
the class KafkaMbeanTest method setup.
@BeforeEach
public void setup() throws Exception {
metrics = new Metrics();
metrics.addReporter(new JmxReporter());
sensor = metrics.sensor("kafka.requests");
countMetricName = metrics.metricName("pack.bean1.count", "grp1");
sensor.add(countMetricName, new WindowedCount());
sumMetricName = metrics.metricName("pack.bean1.sum", "grp1");
sensor.add(sumMetricName, new WindowedSum());
}
use of org.apache.kafka.common.metrics.stats.WindowedSum in project kafka by apache.
the class MetricsTest method testSampledStatReturnsInitialValueWhenNoValuesExist.
/**
* Some implementations of SampledStat make sense to return the initial value
* when there are no values set
*/
@Test
public void testSampledStatReturnsInitialValueWhenNoValuesExist() {
WindowedCount count = new WindowedCount();
WindowedSum sampledTotal = new WindowedSum();
long windowMs = 100;
int samples = 2;
MetricConfig config = new MetricConfig().timeWindow(windowMs, TimeUnit.MILLISECONDS).samples(samples);
count.record(config, 50, time.milliseconds());
sampledTotal.record(config, 50, time.milliseconds());
time.sleep(samples * windowMs);
assertEquals(0, count.measure(config, time.milliseconds()), EPS);
assertEquals(0.0, sampledTotal.measure(config, time.milliseconds()), EPS);
}
use of org.apache.kafka.common.metrics.stats.WindowedSum in project kafka by apache.
the class SensorTest method shouldReturnPresenceOfMetrics.
@Test
public void shouldReturnPresenceOfMetrics() {
final Metrics metrics = new Metrics();
final Sensor sensor = metrics.sensor("sensor");
assertFalse(sensor.hasMetrics());
sensor.add(new MetricName("name1", "group1", "description1", Collections.emptyMap()), new WindowedSum());
assertTrue(sensor.hasMetrics());
sensor.add(new MetricName("name2", "group2", "description2", Collections.emptyMap()), new CumulativeCount());
assertTrue(sensor.hasMetrics());
}
Aggregations