use of org.apache.kafka.common.metrics.MetricConfig in project apache-kafka-on-k8s by banzaicloud.
the class SenderTest method testSenderMetricsTemplates.
@Test
public void testSenderMetricsTemplates() throws Exception {
metrics.close();
Map<String, String> clientTags = Collections.singletonMap("client-id", "clientA");
metrics = new Metrics(new MetricConfig().tags(clientTags));
SenderMetricsRegistry metricsRegistry = new SenderMetricsRegistry(metrics);
Sender sender = new Sender(logContext, client, metadata, this.accumulator, false, MAX_REQUEST_SIZE, ACKS_ALL, 1, metricsRegistry, time, REQUEST_TIMEOUT, 50, null, apiVersions);
// Append a message so that topic metrics are created
accumulator.append(tp0, 0L, "key".getBytes(), "value".getBytes(), null, null, MAX_BLOCK_TIMEOUT);
// connect
sender.run(time.milliseconds());
// send produce request
sender.run(time.milliseconds());
client.respond(produceResponse(tp0, 0, Errors.NONE, 0));
sender.run(time.milliseconds());
// Create throttle time metrics
Sender.throttleTimeSensor(metricsRegistry);
// Verify that all metrics except metrics-count have registered templates
Set<MetricNameTemplate> allMetrics = new HashSet<>();
for (MetricName n : metrics.metrics().keySet()) {
if (!n.group().equals("kafka-metrics-count"))
allMetrics.add(new MetricNameTemplate(n.name(), n.group(), "", n.tags().keySet()));
}
TestUtils.checkEquals(allMetrics, new HashSet<>(metricsRegistry.allTemplates()), "metrics", "templates");
}
use of org.apache.kafka.common.metrics.MetricConfig in project apache-kafka-on-k8s by banzaicloud.
the class TransactionManagerTest method setup.
@Before
public void setup() {
Map<String, String> metricTags = new LinkedHashMap<>();
metricTags.put("client-id", CLIENT_ID);
int batchSize = 16 * 1024;
MetricConfig metricConfig = new MetricConfig().tags(metricTags);
this.brokerNode = new Node(0, "localhost", 2211);
this.transactionManager = new TransactionManager(logContext, transactionalId, transactionTimeoutMs, DEFAULT_RETRY_BACKOFF_MS);
Metrics metrics = new Metrics(metricConfig, time);
SenderMetricsRegistry senderMetrics = new SenderMetricsRegistry(metrics);
this.accumulator = new RecordAccumulator(logContext, batchSize, 1024 * 1024, CompressionType.NONE, 0L, 0L, metrics, time, apiVersions, transactionManager);
this.sender = new Sender(logContext, this.client, this.metadata, this.accumulator, true, MAX_REQUEST_SIZE, ACKS_ALL, MAX_RETRIES, senderMetrics, this.time, REQUEST_TIMEOUT, 50, transactionManager, apiVersions);
this.metadata.update(this.cluster, Collections.<String>emptySet(), time.milliseconds());
client.setNode(brokerNode);
}
use of org.apache.kafka.common.metrics.MetricConfig in project apache-kafka-on-k8s by banzaicloud.
the class MeterTest method testMeter.
@Test
public void testMeter() {
Map<String, String> emptyTags = Collections.emptyMap();
MetricName rateMetricName = new MetricName("rate", "test", "", emptyTags);
MetricName totalMetricName = new MetricName("total", "test", "", emptyTags);
Meter meter = new Meter(rateMetricName, totalMetricName);
List<NamedMeasurable> stats = meter.stats();
assertEquals(2, stats.size());
NamedMeasurable total = stats.get(0);
NamedMeasurable rate = stats.get(1);
assertEquals(rateMetricName, rate.name());
assertEquals(totalMetricName, total.name());
Rate rateStat = (Rate) rate.stat();
Total totalStat = (Total) total.stat();
MetricConfig config = new MetricConfig();
double nextValue = 0.0;
double expectedTotal = 0.0;
long now = 0;
double intervalMs = 100;
double delta = 5.0;
// for time windows and that the total is cumulative.
for (int i = 1; i <= 100; i++) {
for (; now < i * 1000; now += intervalMs, nextValue += delta) {
expectedTotal += nextValue;
meter.record(config, nextValue, now);
}
assertEquals(expectedTotal, totalStat.measure(config, now), EPS);
long windowSizeMs = rateStat.windowSize(config, now);
long windowStartMs = Math.max(now - windowSizeMs, 0);
double sampledTotal = 0.0;
double prevValue = nextValue - delta;
for (long timeMs = now - 100; timeMs >= windowStartMs; timeMs -= intervalMs, prevValue -= delta) sampledTotal += prevValue;
assertEquals(sampledTotal * 1000 / windowSizeMs, rateStat.measure(config, now), EPS);
}
}
use of org.apache.kafka.common.metrics.MetricConfig in project kafka by apache.
the class IntGaugeSuiteTest method createIntGaugeSuite.
private static IntGaugeSuite<String> createIntGaugeSuite() {
MetricConfig config = new MetricConfig();
Metrics metrics = new Metrics(config);
IntGaugeSuite<String> suite = new IntGaugeSuite<>(log, "mySuite", metrics, name -> new MetricName(name, "group", "myMetric", Collections.emptyMap()), 3);
return suite;
}
use of org.apache.kafka.common.metrics.MetricConfig in project kafka by apache.
the class FrequenciesTest method setup.
@BeforeEach
public void setup() {
config = new MetricConfig().eventWindow(50).samples(2);
time = new MockTime();
metrics = new Metrics(config, Arrays.asList(new JmxReporter()), time, true);
}
Aggregations