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