Search in sources :

Example 11 with RecordingLevel

use of org.apache.kafka.common.metrics.Sensor.RecordingLevel in project kafka by apache.

the class StreamsMetricsImplTest method shouldAddClientLevelMutableMetric.

@Test
public void shouldAddClientLevelMutableMetric() {
    final Metrics metrics = mock(Metrics.class);
    final RecordingLevel recordingLevel = RecordingLevel.INFO;
    final MetricConfig metricConfig = new MetricConfig().recordLevel(recordingLevel);
    final Gauge<String> valueProvider = (config, now) -> "mutable-value";
    expect(metrics.metricName(METRIC_NAME1, CLIENT_LEVEL_GROUP, DESCRIPTION1, clientLevelTags)).andReturn(metricName1);
    metrics.addMetric(EasyMock.eq(metricName1), eqMetricConfig(metricConfig), eq(valueProvider));
    replay(metrics);
    final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, CLIENT_ID, VERSION, time);
    streamsMetrics.addClientLevelMutableMetric(METRIC_NAME1, DESCRIPTION1, recordingLevel, valueProvider);
    verify(metrics);
}
Also used : RecordingLevel(org.apache.kafka.common.metrics.Sensor.RecordingLevel) MetricConfig(org.apache.kafka.common.metrics.MetricConfig) CoreMatchers.is(org.hamcrest.CoreMatchers.is) RecordingLevel(org.apache.kafka.common.metrics.Sensor.RecordingLevel) MockTime(org.apache.kafka.common.utils.MockTime) Arrays(java.util.Arrays) Rate(org.apache.kafka.common.metrics.stats.Rate) EasyMock.capture(org.easymock.EasyMock.capture) THREAD_LEVEL_GROUP(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl.THREAD_LEVEL_GROUP) ImmutableMetricValue(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl.ImmutableMetricValue) RATE_SUFFIX(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl.RATE_SUFFIX) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) Utils.mkMap(org.apache.kafka.common.utils.Utils.mkMap) IArgumentMatcher(org.easymock.IArgumentMatcher) ROLLUP_VALUE(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl.ROLLUP_VALUE) Duration(java.time.Duration) Map(java.util.Map) AVG_SUFFIX(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl.AVG_SUFFIX) MetricName(org.apache.kafka.common.MetricName) EasyMock.eq(org.easymock.EasyMock.eq) Sensor(org.apache.kafka.common.metrics.Sensor) TOTAL_SUFFIX(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl.TOTAL_SUFFIX) Time(org.apache.kafka.common.utils.Time) EasyMock.newCapture(org.easymock.EasyMock.newCapture) MetricConfig(org.apache.kafka.common.metrics.MetricConfig) EasyMock.resetToDefault(org.easymock.EasyMock.resetToDefault) List(java.util.List) Metrics(org.apache.kafka.common.metrics.Metrics) Utils.mkEntry(org.apache.kafka.common.utils.Utils.mkEntry) Matchers.equalTo(org.hamcrest.Matchers.equalTo) KafkaMetric(org.apache.kafka.common.metrics.KafkaMetric) CoreMatchers.equalToObject(org.hamcrest.CoreMatchers.equalToObject) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) CLIENT_LEVEL_GROUP(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl.CLIENT_LEVEL_GROUP) PowerMock.createMock(org.powermock.api.easymock.PowerMock.createMock) StreamsConfig(org.apache.kafka.streams.StreamsConfig) Assert.assertThrows(org.junit.Assert.assertThrows) RunWith(org.junit.runner.RunWith) CoreMatchers.not(org.hamcrest.CoreMatchers.not) CLIENT_ID_TAG(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl.CLIENT_ID_TAG) EasyMock.mock(org.easymock.EasyMock.mock) StreamsMetricsImpl.addInvocationRateAndCountToSensor(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl.addInvocationRateAndCountToSensor) StreamsMetricsImpl.addAvgAndMaxLatencyToSensor(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl.addAvgAndMaxLatencyToSensor) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) EasyMock.replay(org.easymock.EasyMock.replay) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) PowerMockRunner(org.powermock.modules.junit4.PowerMockRunner) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) EasyMock.anyObject(org.easymock.EasyMock.anyObject) Capture(org.easymock.Capture) EasyMock.anyString(org.easymock.EasyMock.anyString) MAX_SUFFIX(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl.MAX_SUFFIX) EasyMock.niceMock(org.easymock.EasyMock.niceMock) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) LATENCY_SUFFIX(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl.LATENCY_SUFFIX) Version(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl.Version) EasyMock(org.easymock.EasyMock) EasyMock.expect(org.easymock.EasyMock.expect) TimeUnit(java.util.concurrent.TimeUnit) STATE_STORE_LEVEL_GROUP(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl.STATE_STORE_LEVEL_GROUP) CaptureType(org.easymock.CaptureType) Gauge(org.apache.kafka.common.metrics.Gauge) StreamsTestUtils(org.apache.kafka.test.StreamsTestUtils) EasyMock.verify(org.easymock.EasyMock.verify) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) PROCESSOR_NODE_LEVEL_GROUP(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl.PROCESSOR_NODE_LEVEL_GROUP) Metrics(org.apache.kafka.common.metrics.Metrics) EasyMock.anyString(org.easymock.EasyMock.anyString) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 12 with RecordingLevel

use of org.apache.kafka.common.metrics.Sensor.RecordingLevel in project kafka by apache.

the class StreamsMetricsImplTest method shouldGetExistingNodeLevelSensor.

@Test
public void shouldGetExistingNodeLevelSensor() {
    final Metrics metrics = mock(Metrics.class);
    final RecordingLevel recordingLevel = RecordingLevel.INFO;
    final String processorNodeName = "processorNodeName";
    setupGetExistingSensorTest(metrics);
    final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, CLIENT_ID, VERSION, time);
    final Sensor actualSensor = streamsMetrics.nodeLevelSensor(THREAD_ID1, TASK_ID1, processorNodeName, SENSOR_NAME_1, recordingLevel);
    verify(metrics);
    assertThat(actualSensor, is(equalToObject(sensor)));
}
Also used : RecordingLevel(org.apache.kafka.common.metrics.Sensor.RecordingLevel) Metrics(org.apache.kafka.common.metrics.Metrics) EasyMock.anyString(org.easymock.EasyMock.anyString) Sensor(org.apache.kafka.common.metrics.Sensor) StreamsMetricsImpl.addInvocationRateAndCountToSensor(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl.addInvocationRateAndCountToSensor) StreamsMetricsImpl.addAvgAndMaxLatencyToSensor(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl.addAvgAndMaxLatencyToSensor) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 13 with RecordingLevel

use of org.apache.kafka.common.metrics.Sensor.RecordingLevel in project kafka by apache.

the class StreamsMetricsImplTest method shouldGetExistingThreadLevelSensor.

@Test
public void shouldGetExistingThreadLevelSensor() {
    final Metrics metrics = mock(Metrics.class);
    final RecordingLevel recordingLevel = RecordingLevel.INFO;
    setupGetExistingSensorTest(metrics);
    final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, CLIENT_ID, VERSION, time);
    final Sensor actualSensor = streamsMetrics.threadLevelSensor(THREAD_ID1, SENSOR_NAME_1, recordingLevel);
    verify(metrics);
    assertThat(actualSensor, is(equalToObject(sensor)));
}
Also used : RecordingLevel(org.apache.kafka.common.metrics.Sensor.RecordingLevel) Metrics(org.apache.kafka.common.metrics.Metrics) Sensor(org.apache.kafka.common.metrics.Sensor) StreamsMetricsImpl.addInvocationRateAndCountToSensor(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl.addInvocationRateAndCountToSensor) StreamsMetricsImpl.addAvgAndMaxLatencyToSensor(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl.addAvgAndMaxLatencyToSensor) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 14 with RecordingLevel

use of org.apache.kafka.common.metrics.Sensor.RecordingLevel in project kafka by apache.

the class StreamsMetricsImplTest method shouldGetExistingCacheLevelSensor.

@Test
public void shouldGetExistingCacheLevelSensor() {
    final Metrics metrics = mock(Metrics.class);
    final RecordingLevel recordingLevel = RecordingLevel.INFO;
    final String processorCacheName = "processorNodeName";
    setupGetExistingSensorTest(metrics);
    final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, CLIENT_ID, VERSION, time);
    final Sensor actualSensor = streamsMetrics.cacheLevelSensor(THREAD_ID1, TASK_ID1, processorCacheName, SENSOR_NAME_1, recordingLevel);
    verify(metrics);
    assertThat(actualSensor, is(equalToObject(sensor)));
}
Also used : RecordingLevel(org.apache.kafka.common.metrics.Sensor.RecordingLevel) Metrics(org.apache.kafka.common.metrics.Metrics) EasyMock.anyString(org.easymock.EasyMock.anyString) Sensor(org.apache.kafka.common.metrics.Sensor) StreamsMetricsImpl.addInvocationRateAndCountToSensor(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl.addInvocationRateAndCountToSensor) StreamsMetricsImpl.addAvgAndMaxLatencyToSensor(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl.addAvgAndMaxLatencyToSensor) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 15 with RecordingLevel

use of org.apache.kafka.common.metrics.Sensor.RecordingLevel in project kafka by apache.

the class StreamsMetricsImplTest method shouldGetNewThreadLevelSensor.

@Test
public void shouldGetNewThreadLevelSensor() {
    final Metrics metrics = mock(Metrics.class);
    final RecordingLevel recordingLevel = RecordingLevel.INFO;
    setupGetNewSensorTest(metrics, recordingLevel);
    final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, CLIENT_ID, VERSION, time);
    final Sensor actualSensor = streamsMetrics.threadLevelSensor(THREAD_ID1, SENSOR_NAME_1, recordingLevel);
    verify(metrics);
    assertThat(actualSensor, is(equalToObject(sensor)));
}
Also used : RecordingLevel(org.apache.kafka.common.metrics.Sensor.RecordingLevel) Metrics(org.apache.kafka.common.metrics.Metrics) Sensor(org.apache.kafka.common.metrics.Sensor) StreamsMetricsImpl.addInvocationRateAndCountToSensor(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl.addInvocationRateAndCountToSensor) StreamsMetricsImpl.addAvgAndMaxLatencyToSensor(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl.addAvgAndMaxLatencyToSensor) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Metrics (org.apache.kafka.common.metrics.Metrics)16 RecordingLevel (org.apache.kafka.common.metrics.Sensor.RecordingLevel)16 Sensor (org.apache.kafka.common.metrics.Sensor)15 Test (org.junit.Test)14 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)14 StreamsMetricsImpl.addAvgAndMaxLatencyToSensor (org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl.addAvgAndMaxLatencyToSensor)13 StreamsMetricsImpl.addInvocationRateAndCountToSensor (org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl.addInvocationRateAndCountToSensor)13 EasyMock.anyString (org.easymock.EasyMock.anyString)7 MetricConfig (org.apache.kafka.common.metrics.MetricConfig)4 Collections (java.util.Collections)3 Map (java.util.Map)3 TimeUnit (java.util.concurrent.TimeUnit)3 MetricName (org.apache.kafka.common.MetricName)3 Gauge (org.apache.kafka.common.metrics.Gauge)3 Rate (org.apache.kafka.common.metrics.stats.Rate)3 Time (org.apache.kafka.common.utils.Time)3 Deque (java.util.Deque)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedList (java.util.LinkedList)2