Search in sources :

Example 6 with RecordingLevel

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

the class StreamsMetricsImplTest method shouldGetExistingStoreLevelSensor.

@Test
public void shouldGetExistingStoreLevelSensor() {
    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.storeLevelSensor(TASK_ID1, STORE_NAME1, 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 7 with RecordingLevel

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

the class StreamsMetricsImplTest method shouldGetNewClientLevelSensor.

@Test
public void shouldGetNewClientLevelSensor() {
    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.clientLevelSensor(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 8 with RecordingLevel

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

the class StreamsMetricsImpl method getSensors.

private Sensor getSensors(final Map<String, Deque<String>> sensors, final String sensorName, final String key, final RecordingLevel recordingLevel, final Sensor... parents) {
    final String fullSensorName = key + SENSOR_NAME_DELIMITER + sensorName;
    final Sensor sensor = metrics.getSensor(fullSensorName);
    if (sensor == null) {
        sensors.computeIfAbsent(key, ignored -> new LinkedList<>()).push(fullSensorName);
        return metrics.sensor(fullSensorName, recordingLevel, parents);
    }
    return sensor;
}
Also used : Max(org.apache.kafka.common.metrics.stats.Max) RecordingLevel(org.apache.kafka.common.metrics.Sensor.RecordingLevel) Rate(org.apache.kafka.common.metrics.stats.Rate) RocksDBMetricsRecordingTrigger(org.apache.kafka.streams.state.internals.metrics.RocksDBMetricsRecordingTrigger) HashMap(java.util.HashMap) CumulativeCount(org.apache.kafka.common.metrics.stats.CumulativeCount) Deque(java.util.Deque) Supplier(java.util.function.Supplier) ConcurrentMap(java.util.concurrent.ConcurrentMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Metric(org.apache.kafka.common.Metric) MetricName(org.apache.kafka.common.MetricName) WindowedSum(org.apache.kafka.common.metrics.stats.WindowedSum) LinkedList(java.util.LinkedList) Value(org.apache.kafka.common.metrics.stats.Value) Sensor(org.apache.kafka.common.metrics.Sensor) Time(org.apache.kafka.common.utils.Time) MetricConfig(org.apache.kafka.common.metrics.MetricConfig) CumulativeSum(org.apache.kafka.common.metrics.stats.CumulativeSum) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) Metrics(org.apache.kafka.common.metrics.Metrics) WindowedCount(org.apache.kafka.common.metrics.stats.WindowedCount) Avg(org.apache.kafka.common.metrics.stats.Avg) Min(org.apache.kafka.common.metrics.stats.Min) Gauge(org.apache.kafka.common.metrics.Gauge) StreamsMetrics(org.apache.kafka.streams.StreamsMetrics) Collections(java.util.Collections) LinkedList(java.util.LinkedList) Sensor(org.apache.kafka.common.metrics.Sensor)

Example 9 with RecordingLevel

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

the class StreamsMetricsImpl method addStoreLevelMutableMetric.

public <T> void addStoreLevelMutableMetric(final String taskId, final String metricsScope, final String storeName, final String name, final String description, final RecordingLevel recordingLevel, final Gauge<T> valueProvider) {
    final MetricName metricName = metrics.metricName(name, STATE_STORE_LEVEL_GROUP, description, storeLevelTagMap(taskId, metricsScope, storeName));
    if (metrics.metric(metricName) == null) {
        final MetricConfig metricConfig = new MetricConfig().recordLevel(recordingLevel);
        final String key = storeSensorPrefix(Thread.currentThread().getName(), taskId, storeName);
        metrics.addMetric(metricName, metricConfig, valueProvider);
        storeLevelMetrics.computeIfAbsent(key, ignored -> new LinkedList<>()).push(metricName);
    }
}
Also used : MetricConfig(org.apache.kafka.common.metrics.MetricConfig) Max(org.apache.kafka.common.metrics.stats.Max) RecordingLevel(org.apache.kafka.common.metrics.Sensor.RecordingLevel) Rate(org.apache.kafka.common.metrics.stats.Rate) RocksDBMetricsRecordingTrigger(org.apache.kafka.streams.state.internals.metrics.RocksDBMetricsRecordingTrigger) HashMap(java.util.HashMap) CumulativeCount(org.apache.kafka.common.metrics.stats.CumulativeCount) Deque(java.util.Deque) Supplier(java.util.function.Supplier) ConcurrentMap(java.util.concurrent.ConcurrentMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Metric(org.apache.kafka.common.Metric) MetricName(org.apache.kafka.common.MetricName) WindowedSum(org.apache.kafka.common.metrics.stats.WindowedSum) LinkedList(java.util.LinkedList) Value(org.apache.kafka.common.metrics.stats.Value) Sensor(org.apache.kafka.common.metrics.Sensor) Time(org.apache.kafka.common.utils.Time) MetricConfig(org.apache.kafka.common.metrics.MetricConfig) CumulativeSum(org.apache.kafka.common.metrics.stats.CumulativeSum) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) Metrics(org.apache.kafka.common.metrics.Metrics) WindowedCount(org.apache.kafka.common.metrics.stats.WindowedCount) Avg(org.apache.kafka.common.metrics.stats.Avg) Min(org.apache.kafka.common.metrics.stats.Min) Gauge(org.apache.kafka.common.metrics.Gauge) StreamsMetrics(org.apache.kafka.streams.StreamsMetrics) Collections(java.util.Collections) MetricName(org.apache.kafka.common.MetricName) LinkedList(java.util.LinkedList)

Example 10 with RecordingLevel

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

the class StreamsMetricsImplTest method shouldGetNewTaskLevelSensor.

@Test
public void shouldGetNewTaskLevelSensor() {
    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.taskLevelSensor(THREAD_ID1, TASK_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