use of org.apache.kafka.common.metrics.MetricConfig in project kafka by apache.
the class RocksDBStoreTest method shouldVerifyThatMetricsRecordedFromPropertiesGetMeasurementsFromRocksDB.
@Test
public void shouldVerifyThatMetricsRecordedFromPropertiesGetMeasurementsFromRocksDB() {
final TaskId taskId = new TaskId(0, 0);
final Metrics metrics = new Metrics(new MetricConfig().recordLevel(RecordingLevel.INFO));
final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, "test-application", StreamsConfig.METRICS_LATEST, time);
context = EasyMock.niceMock(InternalMockProcessorContext.class);
EasyMock.expect(context.metrics()).andStubReturn(streamsMetrics);
EasyMock.expect(context.taskId()).andStubReturn(taskId);
EasyMock.expect(context.appConfigs()).andStubReturn(new StreamsConfig(StreamsTestUtils.getStreamsConfig()).originals());
EasyMock.expect(context.stateDir()).andStubReturn(dir);
final MonotonicProcessorRecordContext processorRecordContext = new MonotonicProcessorRecordContext("test", 0);
EasyMock.expect(context.recordMetadata()).andStubReturn(Optional.of(processorRecordContext));
EasyMock.replay(context);
rocksDBStore.init((StateStoreContext) context, rocksDBStore);
final byte[] key = "hello".getBytes();
final byte[] value = "world".getBytes();
rocksDBStore.put(Bytes.wrap(key), value);
final Metric numberOfEntriesActiveMemTable = metrics.metric(new MetricName("num-entries-active-mem-table", StreamsMetricsImpl.STATE_STORE_LEVEL_GROUP, "description is not verified", streamsMetrics.storeLevelTagMap(taskId.toString(), METRICS_SCOPE, DB_NAME)));
assertThat(numberOfEntriesActiveMemTable, notNullValue());
assertThat((BigInteger) numberOfEntriesActiveMemTable.metricValue(), greaterThan(BigInteger.valueOf(0)));
}
use of org.apache.kafka.common.metrics.MetricConfig in project kafka by apache.
the class StreamsMetricsImplTest method shouldAddValue.
@Test
public void shouldAddValue() {
StreamsMetricsImpl.addValueMetricToSensor(sensor, group, tags, metricNamePrefix, DESCRIPTION1);
final KafkaMetric ratioMetric = metrics.metric(new MetricName(metricNamePrefix, group, DESCRIPTION1, tags));
assertThat(ratioMetric, is(notNullValue()));
final MetricConfig metricConfig = new MetricConfig();
final double value1 = 42.0;
sensor.record(value1);
assertThat(ratioMetric.measurable().measure(metricConfig, time.milliseconds()), equalTo(42.0));
final double value2 = 18.0;
sensor.record(value2);
assertThat(ratioMetric.measurable().measure(metricConfig, time.milliseconds()), equalTo(18.0));
// one metric is added automatically in the constructor of Metrics
assertThat(metrics.metrics().size(), equalTo(1 + 1));
}
use of org.apache.kafka.common.metrics.MetricConfig in project kafka by apache.
the class StreamsMetricsImplTest method shouldAddAmountRate.
@Test
public void shouldAddAmountRate() {
StreamsMetricsImpl.addRateOfSumMetricToSensor(sensor, group, tags, metricNamePrefix, DESCRIPTION1);
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);
// one metric is added automatically in the constructor of Metrics
assertThat(metrics.metrics().size(), equalTo(1 + 1));
}
use of org.apache.kafka.common.metrics.MetricConfig in project kafka by apache.
the class StreamsMetricsImplTest method shouldAddClientLevelImmutableMetric.
@Test
public void shouldAddClientLevelImmutableMetric() {
final Metrics metrics = mock(Metrics.class);
final RecordingLevel recordingLevel = RecordingLevel.INFO;
final MetricConfig metricConfig = new MetricConfig().recordLevel(recordingLevel);
final String value = "immutable-value";
final ImmutableMetricValue immutableValue = new ImmutableMetricValue<>(value);
expect(metrics.metricName(METRIC_NAME1, CLIENT_LEVEL_GROUP, DESCRIPTION1, clientLevelTags)).andReturn(metricName1);
metrics.addMetric(eq(metricName1), eqMetricConfig(metricConfig), eq(immutableValue));
replay(metrics);
final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, CLIENT_ID, VERSION, time);
streamsMetrics.addClientLevelImmutableMetric(METRIC_NAME1, DESCRIPTION1, recordingLevel, value);
verify(metrics);
}
Aggregations