use of org.apache.kafka.common.metrics.MetricConfig in project kafka by apache.
the class StreamsMetricsImplTest method shouldAddNewStoreLevelMutableMetric.
@Test
public void shouldAddNewStoreLevelMutableMetric() {
final Metrics metrics = mock(Metrics.class);
final MetricName metricName = new MetricName(METRIC_NAME1, STATE_STORE_LEVEL_GROUP, DESCRIPTION1, STORE_LEVEL_TAG_MAP);
final MetricConfig metricConfig = new MetricConfig().recordLevel(INFO_RECORDING_LEVEL);
expect(metrics.metricName(METRIC_NAME1, STATE_STORE_LEVEL_GROUP, DESCRIPTION1, STORE_LEVEL_TAG_MAP)).andReturn(metricName);
expect(metrics.metric(metricName)).andReturn(null);
metrics.addMetric(eq(metricName), eqMetricConfig(metricConfig), eq(VALUE_PROVIDER));
replay(metrics);
final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, CLIENT_ID, VERSION, time);
streamsMetrics.addStoreLevelMutableMetric(TASK_ID1, SCOPE_NAME, STORE_NAME1, METRIC_NAME1, DESCRIPTION1, INFO_RECORDING_LEVEL, VALUE_PROVIDER);
verify(metrics);
}
use of org.apache.kafka.common.metrics.MetricConfig in project kafka by apache.
the class StreamsMetricsImplTest method testTotalMetricDoesntDecrease.
@Test
public void testTotalMetricDoesntDecrease() {
final MockTime time = new MockTime(1);
final MetricConfig config = new MetricConfig().timeWindow(1, TimeUnit.MILLISECONDS);
final Metrics metrics = new Metrics(config, time);
final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, "", VERSION, time);
final String scope = "scope";
final String entity = "entity";
final String operation = "op";
final Sensor sensor = streamsMetrics.addLatencyRateTotalSensor(scope, entity, operation, RecordingLevel.INFO);
final double latency = 100.0;
final MetricName totalMetricName = metrics.metricName("op-total", "stream-scope-metrics", "", "thread-id", Thread.currentThread().getName(), "scope-id", "entity");
final KafkaMetric totalMetric = metrics.metric(totalMetricName);
for (int i = 0; i < 10; i++) {
assertEquals(i, Math.round(totalMetric.measurable().measure(config, time.milliseconds())));
sensor.record(latency, time.milliseconds());
}
}
use of org.apache.kafka.common.metrics.MetricConfig in project kafka by apache.
the class StreamsMetricsImplTest method shouldAddAmountRateAndSum.
@Test
public void shouldAddAmountRateAndSum() {
StreamsMetricsImpl.addRateOfSumAndSumMetricsToSensor(sensor, group, tags, metricNamePrefix, DESCRIPTION1, DESCRIPTION2);
final double valueToRecord1 = 18.0;
final double valueToRecord2 = 72.0;
final long defaultWindowSizeInSeconds = Duration.ofMillis(new MetricConfig().timeWindowMs()).getSeconds();
final double expectedRateMetricValue = (valueToRecord1 + valueToRecord2) / defaultWindowSizeInSeconds;
verifyMetric(metricNamePrefix + "-rate", DESCRIPTION1, valueToRecord1, valueToRecord2, expectedRateMetricValue);
// values are recorded once for each metric verification
final double expectedSumMetricValue = 2 * valueToRecord1 + 2 * valueToRecord2;
verifyMetric(metricNamePrefix + "-total", DESCRIPTION2, valueToRecord1, valueToRecord2, expectedSumMetricValue);
// one metric is added automatically in the constructor of Metrics
assertThat(metrics.metrics().size(), equalTo(2 + 1));
}
use of org.apache.kafka.common.metrics.MetricConfig in project kafka by apache.
the class StreamsMetricsImpl method addStoreLevelMutableMetric.
public <T> void addStoreLevelMutableMetric(final String taskId, final String metricsScope, final String storeName, final String name, final String description, final RecordingLevel recordingLevel, final Gauge<T> valueProvider) {
final MetricName metricName = metrics.metricName(name, STATE_STORE_LEVEL_GROUP, description, storeLevelTagMap(taskId, metricsScope, storeName));
if (metrics.metric(metricName) == null) {
final MetricConfig metricConfig = new MetricConfig().recordLevel(recordingLevel);
final String key = storeSensorPrefix(Thread.currentThread().getName(), taskId, storeName);
metrics.addMetric(metricName, metricConfig, valueProvider);
storeLevelMetrics.computeIfAbsent(key, ignored -> new LinkedList<>()).push(metricName);
}
}
use of org.apache.kafka.common.metrics.MetricConfig in project kafka by apache.
the class TopologyTestDriver method setupMetrics.
private StreamsMetricsImpl setupMetrics(final StreamsConfig streamsConfig) {
final String threadId = Thread.currentThread().getName();
final MetricConfig metricConfig = new MetricConfig().samples(streamsConfig.getInt(StreamsConfig.METRICS_NUM_SAMPLES_CONFIG)).recordLevel(Sensor.RecordingLevel.forName(streamsConfig.getString(StreamsConfig.METRICS_RECORDING_LEVEL_CONFIG))).timeWindow(streamsConfig.getLong(StreamsConfig.METRICS_SAMPLE_WINDOW_MS_CONFIG), TimeUnit.MILLISECONDS);
metrics = new Metrics(metricConfig, mockWallClockTime);
final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, "test-client", streamsConfig.getString(StreamsConfig.BUILT_IN_METRICS_VERSION_CONFIG), mockWallClockTime);
TaskMetrics.droppedRecordsSensor(threadId, TASK_ID.toString(), streamsMetrics);
return streamsMetrics;
}
Aggregations