Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,7 @@ public void recordThrottleException(RpcThrottlingException.Type throttleType, St
private static String qualifyThrottleMetric(RpcThrottlingException.Type throttleType, String user,
String table) {
return String.format("RpcThrottlingException_Type_%s_User_%s_Table_%s", throttleType.name(),
sanitizeMetricName(user), sanitizeMetricName(table));
}

private static String sanitizeMetricName(String name) {
if (name == null) {
return "unknown";
}
// Only replace characters that are problematic for JMX ObjectNames
// Keep meaningful characters like hyphens, periods, etc.
return name.replaceAll("[,=:*?\"\\n]", "_");
user, table);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -342,18 +342,5 @@ public void testThrottleExceptionMetricsIntegration() {
serverSource);
HELPER.assertCounter("RpcThrottlingException_Type_ReadSizeExceeded_User_charlie_Table_metadata",
1L, serverSource);

// Test metric name sanitization through the integration
rsm.recordThrottleException(RpcThrottlingException.Type.RequestSizeExceeded,
"user.with@special", "table:with,problematic=chars");
HELPER.assertCounter(
"RpcThrottlingException_Type_RequestSizeExceeded_User_user.with@special_Table_table_with_problematic_chars",
1L, serverSource);

// Test null handling through the integration
rsm.recordThrottleException(RpcThrottlingException.Type.ReadCapacityUnitExceeded, null, null);
HELPER.assertCounter(
"RpcThrottlingException_Type_ReadCapacityUnitExceeded_User_unknown_Table_unknown", 1L,
serverSource);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,48 +112,6 @@ public void testCounterIncrement() {
verifyCounter(testRegistry, metricName, 3);
}

@Test
public void testMetricNameSanitization() {
setupTestMetrics();

// Test that meaningful characters are preserved (hyphens, periods, etc.)
throttleMetrics.recordThrottleException(RpcThrottlingException.Type.WriteSizeExceeded,
"user.name@company", "my-table-prod");

// Verify meaningful characters are preserved, only JMX-problematic chars are replaced
String expectedMetricName =
"RpcThrottlingException_Type_WriteSizeExceeded_User_user.name@company_Table_my-table-prod";
verifyCounter(testRegistry, expectedMetricName, 1);

// Test that JMX-problematic characters are sanitized
throttleMetrics.recordThrottleException(RpcThrottlingException.Type.ReadSizeExceeded,
"user,with=bad:chars*", "table?with\"quotes");
String problematicMetricName =
"RpcThrottlingException_Type_ReadSizeExceeded_User_user_with_bad_chars__Table_table_with_quotes";
verifyCounter(testRegistry, problematicMetricName, 1);
}

@Test
public void testNullHandling() {
setupTestMetrics();

// Test null user and table names
throttleMetrics.recordThrottleException(RpcThrottlingException.Type.NumRequestsExceeded, null,
null);
throttleMetrics.recordThrottleException(RpcThrottlingException.Type.WriteSizeExceeded, "alice",
null);
throttleMetrics.recordThrottleException(RpcThrottlingException.Type.ReadSizeExceeded, null,
"users");

// Verify null values are replaced with "unknown"
verifyCounter(testRegistry,
"RpcThrottlingException_Type_NumRequestsExceeded_User_unknown_Table_unknown", 1);
verifyCounter(testRegistry,
"RpcThrottlingException_Type_WriteSizeExceeded_User_alice_Table_unknown", 1);
verifyCounter(testRegistry,
"RpcThrottlingException_Type_ReadSizeExceeded_User_unknown_Table_users", 1);
}

@Test
public void testConcurrentAccess() throws InterruptedException {
setupTestMetrics();
Expand Down Expand Up @@ -211,11 +169,10 @@ public void testCommonTableNamePatterns() {
throttleMetrics.recordThrottleException(RpcThrottlingException.Type.ReadSizeExceeded,
"user_123", "test_table_v2");

// Verify common patterns are preserved correctly (note: colon gets replaced with underscore)
verifyCounter(testRegistry,
"RpcThrottlingException_Type_NumRequestsExceeded_User_service-user_Table_my-app-logs", 1);
verifyCounter(testRegistry,
"RpcThrottlingException_Type_WriteSizeExceeded_User_batch.process_Table_namespace_table-name",
"RpcThrottlingException_Type_WriteSizeExceeded_User_batch.process_Table_namespace:table-name",
1);
verifyCounter(testRegistry,
"RpcThrottlingException_Type_ReadSizeExceeded_User_user_123_Table_test_table_v2", 1);
Expand Down