-
Notifications
You must be signed in to change notification settings - Fork 15.1k
KAFKA-9152; Improve Sensor Retrieval #7928
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -193,16 +193,235 @@ private void addSensorsOnAllLevels(final Metrics metrics, final StreamsMetricsIm | |
| streamsMetrics.storeLevelSensor(THREAD_ID, TASK_ID, storeName, sensorName2, RecordingLevel.INFO); | ||
| } | ||
|
|
||
| private void setupGetSensorTest(final Metrics metrics, | ||
| final String level, | ||
| final RecordingLevel recordingLevel) { | ||
| final String fullSensorName = | ||
| INTERNAL_PREFIX + SENSOR_PREFIX_DELIMITER + level + SENSOR_NAME_DELIMITER + sensorName1; | ||
| private void setupGetNewSensorTest(final Metrics metrics, | ||
| final String level, | ||
| final RecordingLevel recordingLevel) { | ||
| final String fullSensorName = fullSensorName(level); | ||
| expect(metrics.getSensor(fullSensorName)).andStubReturn(null); | ||
| final Sensor[] parents = {}; | ||
| expect(metrics.sensor(fullSensorName, recordingLevel, parents)).andReturn(sensor); | ||
| replay(metrics); | ||
| } | ||
|
|
||
| private void setupGetExistingSensorTest(final Metrics metrics, | ||
| final String level) { | ||
| final String fullSensorName = fullSensorName(level); | ||
| expect(metrics.getSensor(fullSensorName)).andStubReturn(sensor); | ||
| replay(metrics); | ||
| } | ||
|
|
||
| private String fullSensorName(final String level) { | ||
| return INTERNAL_PREFIX + SENSOR_PREFIX_DELIMITER + level + SENSOR_NAME_DELIMITER + sensorName1; | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldGetNewThreadLevelSensor() { | ||
| final Metrics metrics = mock(Metrics.class); | ||
| final RecordingLevel recordingLevel = RecordingLevel.INFO; | ||
| setupGetNewSensorTest(metrics, THREAD_ID, recordingLevel); | ||
| final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, CLIENT_ID, VERSION); | ||
|
|
||
| final Sensor actualSensor = streamsMetrics.threadLevelSensor( | ||
| THREAD_ID, | ||
| sensorName1, | ||
| recordingLevel | ||
| ); | ||
|
|
||
| verify(metrics); | ||
| assertThat(actualSensor, is(equalToObject(sensor))); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is on me. In this verification it is important to check for reference equality, because you want that
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I get that we want to make sure the same instance is returned. But since
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I used
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair enough, let's just leave it as is then. Thanks for the explanation. |
||
| } | ||
|
|
||
| @Test | ||
| public void shouldGetExistingThreadLevelSensor() { | ||
| final Metrics metrics = mock(Metrics.class); | ||
| final RecordingLevel recordingLevel = RecordingLevel.INFO; | ||
| setupGetExistingSensorTest(metrics, THREAD_ID); | ||
| final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, CLIENT_ID, VERSION); | ||
|
|
||
| final Sensor actualSensor = streamsMetrics.threadLevelSensor( | ||
| THREAD_ID, | ||
| sensorName1, | ||
| recordingLevel | ||
| ); | ||
|
|
||
| verify(metrics); | ||
| assertThat(actualSensor, is(equalToObject(sensor))); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
| } | ||
|
|
||
| @Test | ||
| public void shouldGetNewTaskLevelSensor() { | ||
| final Metrics metrics = mock(Metrics.class); | ||
| final RecordingLevel recordingLevel = RecordingLevel.INFO; | ||
| setupGetNewSensorTest(metrics, THREAD_ID + ".task." + TASK_ID, recordingLevel); | ||
| final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, CLIENT_ID, VERSION); | ||
|
|
||
| final Sensor actualSensor = streamsMetrics.taskLevelSensor( | ||
| THREAD_ID, | ||
| TASK_ID, | ||
| sensorName1, | ||
| recordingLevel | ||
| ); | ||
|
|
||
| verify(metrics); | ||
| assertThat(actualSensor, is(equalToObject(sensor))); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto and same for tests below, I won't repeat this comment. |
||
| } | ||
|
|
||
| @Test | ||
| public void shouldGetExistingTaskLevelSensor() { | ||
| final Metrics metrics = mock(Metrics.class); | ||
| final RecordingLevel recordingLevel = RecordingLevel.INFO; | ||
| setupGetExistingSensorTest(metrics, THREAD_ID + ".task." + TASK_ID); | ||
| final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, CLIENT_ID, VERSION); | ||
|
|
||
| final Sensor actualSensor = streamsMetrics.taskLevelSensor( | ||
| THREAD_ID, | ||
| TASK_ID, | ||
| sensorName1, | ||
| recordingLevel | ||
| ); | ||
|
|
||
| verify(metrics); | ||
| assertThat(actualSensor, is(equalToObject(sensor))); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldGetNewStoreLevelSensor() { | ||
| final Metrics metrics = mock(Metrics.class); | ||
| final RecordingLevel recordingLevel = RecordingLevel.INFO; | ||
| setupGetNewSensorTest( | ||
| metrics, | ||
| THREAD_ID + ".task." + storeName + SENSOR_PREFIX_DELIMITER + storeName + SENSOR_PREFIX_DELIMITER | ||
| + TASK_ID, | ||
| recordingLevel | ||
| ); | ||
| final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, CLIENT_ID, VERSION); | ||
|
|
||
| final Sensor actualSensor = streamsMetrics.storeLevelSensor( | ||
| THREAD_ID, | ||
| storeName, | ||
| TASK_ID, | ||
| sensorName1, | ||
| recordingLevel | ||
| ); | ||
|
|
||
| verify(metrics); | ||
| assertThat(actualSensor, is(equalToObject(sensor))); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldGetExistingStoreLevelSensor() { | ||
| final Metrics metrics = mock(Metrics.class); | ||
| final RecordingLevel recordingLevel = RecordingLevel.INFO; | ||
| setupGetExistingSensorTest( | ||
| metrics, THREAD_ID + ".task." + storeName + SENSOR_PREFIX_DELIMITER + storeName + SENSOR_PREFIX_DELIMITER | ||
| + TASK_ID | ||
| ); | ||
| final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, CLIENT_ID, VERSION); | ||
|
|
||
| final Sensor actualSensor = streamsMetrics.storeLevelSensor( | ||
| THREAD_ID, | ||
| storeName, | ||
| TASK_ID, | ||
| sensorName1, | ||
| recordingLevel | ||
| ); | ||
|
|
||
| verify(metrics); | ||
| assertThat(actualSensor, is(equalToObject(sensor))); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldGetNewNodeLevelSensor() { | ||
| final Metrics metrics = mock(Metrics.class); | ||
| final RecordingLevel recordingLevel = RecordingLevel.INFO; | ||
| final String processorNodeName = "processorNodeName"; | ||
| setupGetNewSensorTest(metrics, THREAD_ID + ".task." + TASK_ID + SENSOR_PREFIX_DELIMITER + "node" | ||
| + SENSOR_PREFIX_DELIMITER + processorNodeName, | ||
| recordingLevel | ||
| ); | ||
| final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, CLIENT_ID, VERSION); | ||
|
|
||
| final Sensor actualSensor = streamsMetrics.nodeLevelSensor( | ||
| THREAD_ID, | ||
| TASK_ID, | ||
| processorNodeName, | ||
| sensorName1, | ||
| recordingLevel | ||
| ); | ||
|
|
||
| verify(metrics); | ||
| assertThat(actualSensor, is(equalToObject(sensor))); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldGetExistingNodeLevelSensor() { | ||
| final Metrics metrics = mock(Metrics.class); | ||
| final RecordingLevel recordingLevel = RecordingLevel.INFO; | ||
| final String processorNodeName = "processorNodeName"; | ||
| setupGetExistingSensorTest( | ||
| metrics, THREAD_ID + ".task." + TASK_ID + SENSOR_PREFIX_DELIMITER | ||
| + "node" + SENSOR_PREFIX_DELIMITER + processorNodeName | ||
| ); | ||
| final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, CLIENT_ID, VERSION); | ||
|
|
||
| final Sensor actualSensor = streamsMetrics.nodeLevelSensor( | ||
| THREAD_ID, | ||
| TASK_ID, | ||
| processorNodeName, | ||
| sensorName1, | ||
| recordingLevel | ||
| ); | ||
|
|
||
| verify(metrics); | ||
| assertThat(actualSensor, is(equalToObject(sensor))); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldGetNewCacheLevelSensor() { | ||
| final Metrics metrics = mock(Metrics.class); | ||
| final RecordingLevel recordingLevel = RecordingLevel.INFO; | ||
| final String processorCacheName = "processorNodeName"; | ||
| setupGetNewSensorTest( | ||
| metrics, THREAD_ID + ".task." + TASK_ID + SENSOR_PREFIX_DELIMITER | ||
| + "cache" + SENSOR_PREFIX_DELIMITER + processorCacheName, | ||
| recordingLevel | ||
| ); | ||
| final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, CLIENT_ID, VERSION); | ||
|
|
||
| final Sensor actualSensor = streamsMetrics.cacheLevelSensor( | ||
| THREAD_ID, | ||
| TASK_ID, | ||
| processorCacheName, | ||
| sensorName1, | ||
| recordingLevel | ||
| ); | ||
|
|
||
| verify(metrics); | ||
| assertThat(actualSensor, is(equalToObject(sensor))); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldGetExistingCacheLevelSensor() { | ||
| final Metrics metrics = mock(Metrics.class); | ||
| final RecordingLevel recordingLevel = RecordingLevel.INFO; | ||
| final String processorCacheName = "processorNodeName"; | ||
| setupGetExistingSensorTest( | ||
| metrics, THREAD_ID + ".task." + TASK_ID + SENSOR_PREFIX_DELIMITER | ||
| + "cache" + SENSOR_PREFIX_DELIMITER + processorCacheName | ||
| ); | ||
| final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, CLIENT_ID, VERSION); | ||
|
|
||
| final Sensor actualSensor = streamsMetrics.cacheLevelSensor( | ||
| THREAD_ID, TASK_ID, | ||
| processorCacheName, | ||
| sensorName1, | ||
| recordingLevel | ||
| ); | ||
|
|
||
| verify(metrics); | ||
| assertThat(actualSensor, is(equalToObject(sensor))); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldAddClientLevelImmutableMetric() { | ||
| final Metrics metrics = mock(Metrics.class); | ||
|
|
@@ -244,19 +463,6 @@ public void shouldProvideCorrectStrings() { | |
| assertThat(ROLLUP_VALUE, is("all")); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldGetThreadLevelSensor() { | ||
| final Metrics metrics = mock(Metrics.class); | ||
| final RecordingLevel recordingLevel = RecordingLevel.INFO; | ||
| setupGetSensorTest(metrics, THREAD_ID, recordingLevel); | ||
| final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, CLIENT_ID, VERSION); | ||
|
|
||
| final Sensor actualSensor = streamsMetrics.threadLevelSensor(THREAD_ID, sensorName1, recordingLevel); | ||
|
|
||
| verify(metrics); | ||
| assertThat(actualSensor, is(equalToObject(sensor))); | ||
| } | ||
|
|
||
| private void setupRemoveSensorsTest(final Metrics metrics, | ||
| final String level, | ||
| final RecordingLevel recordingLevel) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.