Search in sources :

Example 41 with MetricConfig

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)));
}
Also used : MetricConfig(org.apache.kafka.common.metrics.MetricConfig) MetricName(org.apache.kafka.common.MetricName) Metrics(org.apache.kafka.common.metrics.Metrics) TaskId(org.apache.kafka.streams.processor.TaskId) Metric(org.apache.kafka.common.Metric) StreamsMetricsImpl(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl) InternalMockProcessorContext(org.apache.kafka.test.InternalMockProcessorContext) StreamsConfig(org.apache.kafka.streams.StreamsConfig) Test(org.junit.Test)

Example 42 with MetricConfig

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));
}
Also used : MetricConfig(org.apache.kafka.common.metrics.MetricConfig) MetricName(org.apache.kafka.common.MetricName) KafkaMetric(org.apache.kafka.common.metrics.KafkaMetric) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 43 with MetricConfig

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));
}
Also used : MetricConfig(org.apache.kafka.common.metrics.MetricConfig) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 44 with MetricConfig

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);
}
Also used : RecordingLevel(org.apache.kafka.common.metrics.Sensor.RecordingLevel) MetricConfig(org.apache.kafka.common.metrics.MetricConfig) Metrics(org.apache.kafka.common.metrics.Metrics) EasyMock.anyString(org.easymock.EasyMock.anyString) ImmutableMetricValue(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl.ImmutableMetricValue) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

MetricConfig (org.apache.kafka.common.metrics.MetricConfig)44 Metrics (org.apache.kafka.common.metrics.Metrics)32 MetricName (org.apache.kafka.common.MetricName)23 Test (org.junit.Test)14 KafkaMetric (org.apache.kafka.common.metrics.KafkaMetric)8 Sensor (org.apache.kafka.common.metrics.Sensor)8 MockTime (org.apache.kafka.common.utils.MockTime)8 HashSet (java.util.HashSet)7 LinkedHashMap (java.util.LinkedHashMap)7 MetricNameTemplate (org.apache.kafka.common.MetricNameTemplate)7 JmxReporter (org.apache.kafka.common.metrics.JmxReporter)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 KafkaException (org.apache.kafka.common.KafkaException)6 Collections (java.util.Collections)5 Map (java.util.Map)5 TimeUnit (java.util.concurrent.TimeUnit)5 Metric (org.apache.kafka.common.Metric)5 TopicPartition (org.apache.kafka.common.TopicPartition)5