@ -16,6 +16,7 @@
* /
* /
package org.apache.kafka.streams.processor.internals.metrics ;
package org.apache.kafka.streams.processor.internals.metrics ;
import org.apache.kafka.common.MetricName ;
import org.apache.kafka.common.metrics.Sensor ;
import org.apache.kafka.common.metrics.Sensor ;
import org.apache.kafka.common.metrics.Sensor.RecordingLevel ;
import org.apache.kafka.common.metrics.Sensor.RecordingLevel ;
import org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl.Version ;
import org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl.Version ;
@ -35,6 +36,8 @@ import java.util.Collections;
import java.util.Map ;
import java.util.Map ;
import static org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl.ROLLUP_VALUE ;
import static org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl.ROLLUP_VALUE ;
import static org.easymock.EasyMock.anyObject ;
import static org.easymock.EasyMock.eq ;
import static org.easymock.EasyMock.expect ;
import static org.easymock.EasyMock.expect ;
import static org.easymock.EasyMock.mock ;
import static org.easymock.EasyMock.mock ;
import static org.hamcrest.CoreMatchers.is ;
import static org.hamcrest.CoreMatchers.is ;
@ -75,7 +78,6 @@ public class ThreadMetricsTest {
@Before
@Before
public void setUp ( ) {
public void setUp ( ) {
expect ( streamsMetrics . version ( ) ) . andReturn ( builtInMetricsVersion ) . anyTimes ( ) ;
expect ( streamsMetrics . version ( ) ) . andReturn ( builtInMetricsVersion ) . anyTimes ( ) ;
mockStatic ( StreamsMetricsImpl . class ) ;
}
}
@Test
@Test
@ -85,6 +87,7 @@ public class ThreadMetricsTest {
final String rateDescription = "The average per-second number of newly created tasks" ;
final String rateDescription = "The average per-second number of newly created tasks" ;
expect ( streamsMetrics . threadLevelSensor ( THREAD_ID , operation , RecordingLevel . INFO ) ) . andReturn ( expectedSensor ) ;
expect ( streamsMetrics . threadLevelSensor ( THREAD_ID , operation , RecordingLevel . INFO ) ) . andReturn ( expectedSensor ) ;
expect ( streamsMetrics . threadLevelTagMap ( THREAD_ID ) ) . andReturn ( tagMap ) ;
expect ( streamsMetrics . threadLevelTagMap ( THREAD_ID ) ) . andReturn ( tagMap ) ;
mockStatic ( StreamsMetricsImpl . class ) ;
StreamsMetricsImpl . addInvocationRateAndCountToSensor (
StreamsMetricsImpl . addInvocationRateAndCountToSensor (
expectedSensor ,
expectedSensor ,
threadLevelGroup ,
threadLevelGroup ,
@ -108,6 +111,7 @@ public class ThreadMetricsTest {
final String rateDescription = "The average per-second number of closed tasks" ;
final String rateDescription = "The average per-second number of closed tasks" ;
expect ( streamsMetrics . threadLevelSensor ( THREAD_ID , operation , RecordingLevel . INFO ) ) . andReturn ( expectedSensor ) ;
expect ( streamsMetrics . threadLevelSensor ( THREAD_ID , operation , RecordingLevel . INFO ) ) . andReturn ( expectedSensor ) ;
expect ( streamsMetrics . threadLevelTagMap ( THREAD_ID ) ) . andReturn ( tagMap ) ;
expect ( streamsMetrics . threadLevelTagMap ( THREAD_ID ) ) . andReturn ( tagMap ) ;
mockStatic ( StreamsMetricsImpl . class ) ;
StreamsMetricsImpl . addInvocationRateAndCountToSensor (
StreamsMetricsImpl . addInvocationRateAndCountToSensor (
expectedSensor ,
expectedSensor ,
threadLevelGroup ,
threadLevelGroup ,
@ -134,6 +138,7 @@ public class ThreadMetricsTest {
final String maxLatencyDescription = "The maximum commit latency" ;
final String maxLatencyDescription = "The maximum commit latency" ;
expect ( streamsMetrics . threadLevelSensor ( THREAD_ID , operation , RecordingLevel . INFO ) ) . andReturn ( expectedSensor ) ;
expect ( streamsMetrics . threadLevelSensor ( THREAD_ID , operation , RecordingLevel . INFO ) ) . andReturn ( expectedSensor ) ;
expect ( streamsMetrics . threadLevelTagMap ( THREAD_ID ) ) . andReturn ( tagMap ) ;
expect ( streamsMetrics . threadLevelTagMap ( THREAD_ID ) ) . andReturn ( tagMap ) ;
mockStatic ( StreamsMetricsImpl . class ) ;
StreamsMetricsImpl . addInvocationRateAndCountToSensor (
StreamsMetricsImpl . addInvocationRateAndCountToSensor (
expectedSensor ,
expectedSensor ,
threadLevelGroup ,
threadLevelGroup ,
@ -167,6 +172,7 @@ public class ThreadMetricsTest {
final String maxLatencyDescription = "The maximum poll latency" ;
final String maxLatencyDescription = "The maximum poll latency" ;
expect ( streamsMetrics . threadLevelSensor ( THREAD_ID , operation , RecordingLevel . INFO ) ) . andReturn ( expectedSensor ) ;
expect ( streamsMetrics . threadLevelSensor ( THREAD_ID , operation , RecordingLevel . INFO ) ) . andReturn ( expectedSensor ) ;
expect ( streamsMetrics . threadLevelTagMap ( THREAD_ID ) ) . andReturn ( tagMap ) ;
expect ( streamsMetrics . threadLevelTagMap ( THREAD_ID ) ) . andReturn ( tagMap ) ;
mockStatic ( StreamsMetricsImpl . class ) ;
StreamsMetricsImpl . addInvocationRateAndCountToSensor (
StreamsMetricsImpl . addInvocationRateAndCountToSensor (
expectedSensor ,
expectedSensor ,
threadLevelGroup ,
threadLevelGroup ,
@ -192,34 +198,52 @@ public class ThreadMetricsTest {
}
}
@Test
@Test
public void shouldGetProcessSensor ( ) {
public void shouldGetProcessLatencySensor ( ) {
final String operation = "process" ;
expect ( streamsMetrics . threadLevelSensor ( THREAD_ID , "process-latency" , RecordingLevel . INFO ) )
final String operationLatency = operation + StreamsMetricsImpl . LATENCY_SUFFIX ;
. andReturn ( expectedSensor ) ;
final String totalDescription = "The total number of calls to process" ;
final String rateDescription = "The average per-second number of calls to process" ;
final String avgLatencyDescription = "The average process latency" ;
final String maxLatencyDescription = "The maximum process latency" ;
expect ( streamsMetrics . threadLevelSensor ( THREAD_ID , operation , RecordingLevel . INFO ) ) . andReturn ( expectedSensor ) ;
expect ( streamsMetrics . threadLevelTagMap ( THREAD_ID ) ) . andReturn ( tagMap ) ;
expect ( streamsMetrics . threadLevelTagMap ( THREAD_ID ) ) . andReturn ( tagMap ) ;
StreamsMetricsImpl . addInvocationRateAndCountToSensor (
expect ( expectedSensor . add ( eq ( new MetricName (
expectedSensor ,
"process-latency-avg" ,
threadLevelGroup ,
threadLevelGroup ,
tagMap ,
"The average execution time in ms for processing, across all running tasks of this thread." ,
operation ,
tagMap
rateDescription ,
) ) , anyObject ( ) ) ) . andReturn ( true ) ;
totalDescription
) ;
expect ( expectedSensor . add ( eq ( new MetricName (
StreamsMetricsImpl . addAvgAndMaxToSensor (
"process-latency-max" ,
expectedSensor ,
threadLevelGroup ,
threadLevelGroup ,
tagMap ,
"The maximum execution time in ms for processing across all running tasks of this thread." ,
operationLatency ,
tagMap
avgLatencyDescription ,
) ) , anyObject ( ) ) ) . andReturn ( true ) ;
maxLatencyDescription
replay ( StreamsMetricsImpl . class , streamsMetrics , expectedSensor ) ;
) ;
replay ( StreamsMetricsImpl . class , streamsMetrics ) ;
final Sensor sensor = ThreadMetrics . processSensor ( THREAD_ID , streamsMetrics ) ;
final Sensor sensor = ThreadMetrics . processLatencySensor ( THREAD_ID , streamsMetrics ) ;
verify ( StreamsMetricsImpl . class , streamsMetrics ) ;
assertThat ( sensor , is ( expectedSensor ) ) ;
}
@Test
public void shouldGetProcessRateSensor ( ) {
expect ( streamsMetrics . threadLevelSensor ( THREAD_ID , "process-rate" , RecordingLevel . INFO ) )
. andReturn ( expectedSensor ) ;
expect ( streamsMetrics . threadLevelTagMap ( THREAD_ID ) ) . andReturn ( tagMap ) ;
expect ( expectedSensor . add ( eq ( new MetricName (
"process-rate" ,
threadLevelGroup ,
"The average per-second number of calls to process" ,
tagMap
) ) , anyObject ( ) ) ) . andReturn ( true ) ;
expect ( expectedSensor . add ( eq ( new MetricName (
"process-total" ,
threadLevelGroup ,
"The total number of calls to process" ,
tagMap
) ) , anyObject ( ) ) ) . andReturn ( true ) ;
replay ( StreamsMetricsImpl . class , streamsMetrics , expectedSensor ) ;
final Sensor sensor = ThreadMetrics . processRateSensor ( THREAD_ID , streamsMetrics ) ;
verify ( StreamsMetricsImpl . class , streamsMetrics ) ;
verify ( StreamsMetricsImpl . class , streamsMetrics ) ;
assertThat ( sensor , is ( expectedSensor ) ) ;
assertThat ( sensor , is ( expectedSensor ) ) ;
@ -235,6 +259,7 @@ public class ThreadMetricsTest {
final String maxLatencyDescription = "The maximum punctuate latency" ;
final String maxLatencyDescription = "The maximum punctuate latency" ;
expect ( streamsMetrics . threadLevelSensor ( THREAD_ID , operation , RecordingLevel . INFO ) ) . andReturn ( expectedSensor ) ;
expect ( streamsMetrics . threadLevelSensor ( THREAD_ID , operation , RecordingLevel . INFO ) ) . andReturn ( expectedSensor ) ;
expect ( streamsMetrics . threadLevelTagMap ( THREAD_ID ) ) . andReturn ( tagMap ) ;
expect ( streamsMetrics . threadLevelTagMap ( THREAD_ID ) ) . andReturn ( tagMap ) ;
mockStatic ( StreamsMetricsImpl . class ) ;
StreamsMetricsImpl . addInvocationRateAndCountToSensor (
StreamsMetricsImpl . addInvocationRateAndCountToSensor (
expectedSensor ,
expectedSensor ,
threadLevelGroup ,
threadLevelGroup ,
@ -266,6 +291,7 @@ public class ThreadMetricsTest {
expect ( streamsMetrics . threadLevelSensor ( THREAD_ID , operation , RecordingLevel . INFO ) )
expect ( streamsMetrics . threadLevelSensor ( THREAD_ID , operation , RecordingLevel . INFO ) )
. andReturn ( expectedSensor ) ;
. andReturn ( expectedSensor ) ;
expect ( streamsMetrics . threadLevelTagMap ( THREAD_ID ) ) . andReturn ( tagMap ) ;
expect ( streamsMetrics . threadLevelTagMap ( THREAD_ID ) ) . andReturn ( tagMap ) ;
mockStatic ( StreamsMetricsImpl . class ) ;
StreamsMetricsImpl . addInvocationRateAndCountToSensor (
StreamsMetricsImpl . addInvocationRateAndCountToSensor (
expectedSensor ,
expectedSensor ,
threadLevelGroup ,
threadLevelGroup ,
@ -296,6 +322,7 @@ public class ThreadMetricsTest {
"The maximum commit latency over all tasks assigned to one stream thread" ;
"The maximum commit latency over all tasks assigned to one stream thread" ;
expect ( streamsMetrics . threadLevelSensor ( THREAD_ID , operation , RecordingLevel . DEBUG ) ) . andReturn ( expectedSensor ) ;
expect ( streamsMetrics . threadLevelSensor ( THREAD_ID , operation , RecordingLevel . DEBUG ) ) . andReturn ( expectedSensor ) ;
expect ( streamsMetrics . taskLevelTagMap ( THREAD_ID , ROLLUP_VALUE ) ) . andReturn ( tagMap ) ;
expect ( streamsMetrics . taskLevelTagMap ( THREAD_ID , ROLLUP_VALUE ) ) . andReturn ( tagMap ) ;
mockStatic ( StreamsMetricsImpl . class ) ;
StreamsMetricsImpl . addInvocationRateAndCountToSensor (
StreamsMetricsImpl . addInvocationRateAndCountToSensor (
expectedSensor ,
expectedSensor ,
TASK_LEVEL_GROUP ,
TASK_LEVEL_GROUP ,