This is an automated email from the ASF dual-hosted git repository. ddanielr pushed a commit to branch elasticity in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/elasticity by this push: new e364ca6c54 Add comments (#4189) e364ca6c54 is described below commit e364ca6c54683c0ba4adadbc452daefccba93168 Author: Daniel Roberts <ddani...@gmail.com> AuthorDate: Wed Jan 24 15:12:38 2024 -0500 Add comments (#4189) Add additional comments for describing the goal of formatString --- .../org/apache/accumulo/core/metrics/MetricsUtil.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/org/apache/accumulo/core/metrics/MetricsUtil.java b/core/src/main/java/org/apache/accumulo/core/metrics/MetricsUtil.java index 581c30f7eb..311bb5e190 100644 --- a/core/src/main/java/org/apache/accumulo/core/metrics/MetricsUtil.java +++ b/core/src/main/java/org/apache/accumulo/core/metrics/MetricsUtil.java @@ -142,29 +142,34 @@ public class MetricsUtil { } /** - * Centralize any specific string formatting for metric names and/or tags. Ensure strings match - * the micrometer naming convention. + * This method replaces any intended delimiters with the "." delimiter that is used by micrometer. + * Micrometer will then transform these delimiters to the metric producer's delimiter. Example: + * "compactorQueue" becomes "compactor.queue" in micrometer. When using Prometheus, + * "compactor.queue" would become "compactor_queue". + * */ public static String formatString(String name) { - // Handle spaces + // Replace spaces with dot delimiter name = name.replace(" ", "."); - // Handle snake_case notation + // Replace snake_case with dot delimiter name = name.replace("_", "."); - // Handle Hyphens + // Replace hyphens with dot delimiter name = name.replace("-", "."); - // Handle camelCase notation + // Insert a dot delimiter before each capital letter found in the regex pattern. Matcher matcher = camelCasePattern.matcher(name); StringBuilder output = new StringBuilder(name); int insertCount = 0; while (matcher.find()) { - // Pattern matches at a lowercase letter, but the insert is at the second position. + // Pattern matches on a "aAa" pattern and inserts the dot before the uppercase character. + // Results in "aAa" becoming "a.Aa". output.insert(matcher.start() + 1 + insertCount, "."); // The correct index position will shift as inserts occur. insertCount++; } name = output.toString(); + // remove all capital letters after the dot delimiters have been inserted. return name.toLowerCase(); }