You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@storm.apache.org by GitBox <gi...@apache.org> on 2022/02/10 20:40:01 UTC

[GitHub] [storm] ben-roling opened a new pull request #3441: STORM-3822 fix visualization when streamId contains colon

ben-roling opened a new pull request #3441:
URL: https://github.com/apache/storm/pull/3441


   ## What is the purpose of the change
   
   This fixes [STORM-3822](https://issues.apache.org/jira/browse/STORM-3822), making the Topology Visualization UI render correctly when a streamId contains a colon character.
   
   ## How was the change tested
   
   I have tested with a modified version of WordCountTopology where I used a custom streamId ("my:stream") containing a colon and verified the UI loads successfully.  I have also tested with some of my team's real topologies that utilize streamIds containing colons.
   
   Further, I have added a unit test for the function of the sanitizeStreamName() method modified in this PR.
   
   ## Notes
   
   The sanitizeStreamName() method body was a bit cryptic and hard to follow.  I refactored it in an attempt to make it more readable.  I could have gone a little further.  In the initial version in the PR I have just added comments, renamed variables, and created an if/else block where previously there was a default assignment followed by a reassignment in an if condition.
   
   The real change I made was simply to remove ':' as one of the allowed (not replaced) characters such that it would be replaced by '_' like other classes of characters that aren't allowed.
   
   I have also done a couple of other things discussed in [STORM-3817](https://issues.apache.org/jira/browse/STORM-3817):
   * removed yetus dependency exclusion that was causing me local build failures
   * cherry-picked 1988a47f2b82ec103fffb02fc323aab0de3b09c6 so hopefully travis will build successfully
   
   These last two items can be removed from this PR before merge, assuming they get incorporated elsewhere.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@storm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [storm] ben-roling commented on a change in pull request #3441: STORM-3822 fix visualization when streamId contains colon

Posted by GitBox <gi...@apache.org>.
ben-roling commented on a change in pull request #3441:
URL: https://github.com/apache/storm/pull/3441#discussion_r804094495



##########
File path: storm-webapp/src/main/java/org/apache/storm/daemon/ui/UIHelpers.java
##########
@@ -1746,19 +1746,26 @@ private static Double nullToZero(Double value) {
     }
 
     /**
-     * sanitizeStreamName.
+     * Sanitizes streamName for use as an identifier in the visualization.  Replaces all characters except A-Z, a-z,
+     * '.', '-', and '_' with '_'.  If streamName does not start with A-Z or a-z, adds '_s' prefix.
      * @param streamName streamName
-     * @return sanitizeStreamName
+     * @return sanitized stream name
      */
     public static String sanitizeStreamName(String streamName) {
-        Pattern pattern = Pattern.compile("(?![A-Za-z_\\-:\\.]).");
-        Pattern pattern2 = Pattern.compile("^[A-Za-z]");
-        Matcher matcher = pattern2.matcher(streamName);
-        Matcher matcher2 = pattern.matcher("\\s" + streamName);
-        if (matcher.find()) {
-            matcher2 = pattern.matcher(streamName);
+        Pattern startsWithLetterPattern = Pattern.compile("^[A-Za-z]");
+        Pattern problemCharacterPattern = Pattern.compile("(?![A-Za-z_\\-\\.]).");

Review comment:
       The only "real" change I made was to remove the colon character from this pattern (previously named `pattern`).




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@storm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [storm] agresch commented on a change in pull request #3441: STORM-3822 fix visualization when streamId contains colon

Posted by GitBox <gi...@apache.org>.
agresch commented on a change in pull request #3441:
URL: https://github.com/apache/storm/pull/3441#discussion_r836833239



##########
File path: .travis.yml
##########
@@ -25,7 +25,7 @@ env:
   - MODULES=Integration-Test
   - MODULES=Check-Updated-License-Files
 
-dist: xenial
+dist: bionic

Review comment:
       This should be put up as a separate JIRA if needed.

##########
File path: storm-shaded-deps/pom.xml
##########
@@ -71,24 +71,12 @@
                     <groupId>jline</groupId>
                     <artifactId>jline</artifactId>
                 </exclusion>

Review comment:
       This should be put up as a separate JIRA if needed.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@storm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [storm] ben-roling commented on a change in pull request #3441: STORM-3822 fix visualization when streamId contains colon

Posted by GitBox <gi...@apache.org>.
ben-roling commented on a change in pull request #3441:
URL: https://github.com/apache/storm/pull/3441#discussion_r839007483



##########
File path: storm-webapp/src/main/java/org/apache/storm/daemon/ui/UIHelpers.java
##########
@@ -1746,19 +1746,26 @@ private static Double nullToZero(Double value) {
     }
 
     /**
-     * sanitizeStreamName.
+     * Sanitizes streamName for use as an identifier in the visualization.  Replaces all characters except A-Z, a-z,
+     * '.', '-', and '_' with '_'.  If streamName does not start with A-Z or a-z, adds '_s' prefix.
      * @param streamName streamName
-     * @return sanitizeStreamName
+     * @return sanitized stream name
      */
     public static String sanitizeStreamName(String streamName) {
-        Pattern pattern = Pattern.compile("(?![A-Za-z_\\-:\\.]).");
-        Pattern pattern2 = Pattern.compile("^[A-Za-z]");
-        Matcher matcher = pattern2.matcher(streamName);
-        Matcher matcher2 = pattern.matcher("\\s" + streamName);
-        if (matcher.find()) {
-            matcher2 = pattern.matcher(streamName);
+        Pattern startsWithLetterPattern = Pattern.compile("^[A-Za-z]");
+        Pattern problemCharacterPattern = Pattern.compile("(?![A-Za-z_\\-\\.]).");
+
+        Matcher startsWithLetterMatcher = startsWithLetterPattern.matcher(streamName);
+        Matcher problemCharacterMatcher;
+        if (startsWithLetterMatcher.find()) {
+            problemCharacterMatcher = problemCharacterPattern.matcher(streamName);
+        } else {
+            // if the streamName starts with non-letter character, prepend "\s".  The backslash will then
+            // get replaced by an underscore, resulting in the prefix of "_s" in the final sanitized name
+            problemCharacterMatcher = problemCharacterPattern.matcher("\\s" + streamName);

Review comment:
       I've added the simplification as you suggest.  Perhaps I should have done that straight away.
   
   https://github.com/apache/storm/pull/3441/commits/b7f04e7e6d9d0b05d449795279fd8c250cd92abf




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@storm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [storm] ben-roling commented on a change in pull request #3441: STORM-3822 fix visualization when streamId contains colon

Posted by GitBox <gi...@apache.org>.
ben-roling commented on a change in pull request #3441:
URL: https://github.com/apache/storm/pull/3441#discussion_r839009169



##########
File path: storm-webapp/src/main/java/org/apache/storm/daemon/ui/UIHelpers.java
##########
@@ -1746,19 +1746,21 @@ private static Double nullToZero(Double value) {
     }
 
     /**
-     * sanitizeStreamName.
-     * @param streamName streamName
-     * @return sanitizeStreamName
+     * Sanitizes streamName for use as an identifier in the visualization.  Replaces all characters except A-Z, a-z,
+     * '.', '-', and '_' with '_'.  If streamName does not start with A-Z or a-z, adds '_s' prefix.
+     * @param streamName non-null, non-empty streamName
+     * @return sanitized stream name
      */
     public static String sanitizeStreamName(String streamName) {
-        Pattern pattern = Pattern.compile("(?![A-Za-z_\\-:\\.]).");
-        Pattern pattern2 = Pattern.compile("^[A-Za-z]");
-        Matcher matcher = pattern2.matcher(streamName);
-        Matcher matcher2 = pattern.matcher("\\s" + streamName);
-        if (matcher.find()) {
-            matcher2 = pattern.matcher(streamName);
-        }
-        return matcher2.replaceAll("_");
+        if (streamName == null || streamName.isEmpty()) {

Review comment:
       It doesn't seem the streamName would ever be null or empty but I added this precondition checking to fail faster if it ever was.  Without it the exception could occur at `Character.isLetter(streamName.charAt(0)`.  I can delete this and let that happen instead if there is a preference.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@storm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [storm] bipinprasad commented on pull request #3441: STORM-3822 fix visualization when streamId contains colon

Posted by GitBox <gi...@apache.org>.
bipinprasad commented on pull request #3441:
URL: https://github.com/apache/storm/pull/3441#issuecomment-1086287137


   I restarted the failed check.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@storm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [storm] ben-roling commented on pull request #3441: STORM-3822 fix visualization when streamId contains colon

Posted by GitBox <gi...@apache.org>.
ben-roling commented on pull request #3441:
URL: https://github.com/apache/storm/pull/3441#issuecomment-1086276428


   I notice the last travis build failed on one integration test that seems completely unrelated to the changes in this PR:
   org.apache.storm.st.tests.window.SlidingWindowTest.testTimeWindow
   
   Is there a mechanism for me to trigger a new build?  Anything more I can do to help move this along?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@storm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [storm] bipinprasad commented on a change in pull request #3441: STORM-3822 fix visualization when streamId contains colon

Posted by GitBox <gi...@apache.org>.
bipinprasad commented on a change in pull request #3441:
URL: https://github.com/apache/storm/pull/3441#discussion_r839123497



##########
File path: storm-webapp/src/main/java/org/apache/storm/daemon/ui/UIHelpers.java
##########
@@ -1746,19 +1746,21 @@ private static Double nullToZero(Double value) {
     }
 
     /**
-     * sanitizeStreamName.
-     * @param streamName streamName
-     * @return sanitizeStreamName
+     * Sanitizes streamName for use as an identifier in the visualization.  Replaces all characters except A-Z, a-z,
+     * '.', '-', and '_' with '_'.  If streamName does not start with A-Z or a-z, adds '_s' prefix.
+     * @param streamName non-null, non-empty streamName
+     * @return sanitized stream name
      */
     public static String sanitizeStreamName(String streamName) {
-        Pattern pattern = Pattern.compile("(?![A-Za-z_\\-:\\.]).");
-        Pattern pattern2 = Pattern.compile("^[A-Za-z]");
-        Matcher matcher = pattern2.matcher(streamName);
-        Matcher matcher2 = pattern.matcher("\\s" + streamName);
-        if (matcher.find()) {
-            matcher2 = pattern.matcher(streamName);
-        }
-        return matcher2.replaceAll("_");
+        if (streamName == null || streamName.isEmpty()) {
+            throw new IllegalArgumentException("streamName: " + streamName == null ? "null" : "empty");

Review comment:
       Since this is used in the UI, it is better to return the string as is when null or empty. 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@storm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [storm] ben-roling commented on a change in pull request #3441: STORM-3822 fix visualization when streamId contains colon

Posted by GitBox <gi...@apache.org>.
ben-roling commented on a change in pull request #3441:
URL: https://github.com/apache/storm/pull/3441#discussion_r839822444



##########
File path: storm-webapp/src/main/java/org/apache/storm/daemon/ui/UIHelpers.java
##########
@@ -1746,19 +1746,21 @@ private static Double nullToZero(Double value) {
     }
 
     /**
-     * sanitizeStreamName.
-     * @param streamName streamName
-     * @return sanitizeStreamName
+     * Sanitizes streamName for use as an identifier in the visualization.  Replaces all characters except A-Z, a-z,
+     * '.', '-', and '_' with '_'.  If streamName does not start with A-Z or a-z, adds '_s' prefix.
+     * @param streamName non-null, non-empty streamName
+     * @return sanitized stream name
      */
     public static String sanitizeStreamName(String streamName) {
-        Pattern pattern = Pattern.compile("(?![A-Za-z_\\-:\\.]).");
-        Pattern pattern2 = Pattern.compile("^[A-Za-z]");
-        Matcher matcher = pattern2.matcher(streamName);
-        Matcher matcher2 = pattern.matcher("\\s" + streamName);
-        if (matcher.find()) {
-            matcher2 = pattern.matcher(streamName);
-        }
-        return matcher2.replaceAll("_");
+        if (streamName == null || streamName.isEmpty()) {
+            throw new IllegalArgumentException("streamName: " + streamName == null ? "null" : "empty");

Review comment:
       I've restored parity with how null and empty were handled before any of my changes:
   https://github.com/apache/storm/pull/3441/commits/177976b929bf18dd0542bb4131cd801e99a827f7
   
   If streamName is null, it will result in NPE just as it did before.  I don't think there is any way streamName would ever be null.  I don't think it would ever be empty either, but since I have at least a small degree of uncertainty this way we can be sure it at least behaves the same way it used to.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@storm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [storm] ben-roling commented on pull request #3441: STORM-3822 fix visualization when streamId contains colon

Posted by GitBox <gi...@apache.org>.
ben-roling commented on pull request #3441:
URL: https://github.com/apache/storm/pull/3441#issuecomment-1082408932


   @agresch @rzo1, I've rebased leaving in only the essential changes.  We'll see how things go with the travis build.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@storm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [storm] ben-roling commented on a change in pull request #3441: STORM-3822 fix visualization when streamId contains colon

Posted by GitBox <gi...@apache.org>.
ben-roling commented on a change in pull request #3441:
URL: https://github.com/apache/storm/pull/3441#discussion_r804090549



##########
File path: storm-webapp/src/main/java/org/apache/storm/daemon/ui/UIHelpers.java
##########
@@ -1746,19 +1746,26 @@ private static Double nullToZero(Double value) {
     }
 
     /**
-     * sanitizeStreamName.
+     * Sanitizes streamName for use as an identifier in the visualization.  Replaces all characters except A-Z, a-z,
+     * '.', '-', and '_' with '_'.  If streamName does not start with A-Z or a-z, adds '_s' prefix.
      * @param streamName streamName
-     * @return sanitizeStreamName
+     * @return sanitized stream name
      */
     public static String sanitizeStreamName(String streamName) {
-        Pattern pattern = Pattern.compile("(?![A-Za-z_\\-:\\.]).");
-        Pattern pattern2 = Pattern.compile("^[A-Za-z]");
-        Matcher matcher = pattern2.matcher(streamName);
-        Matcher matcher2 = pattern.matcher("\\s" + streamName);
-        if (matcher.find()) {
-            matcher2 = pattern.matcher(streamName);
+        Pattern startsWithLetterPattern = Pattern.compile("^[A-Za-z]");
+        Pattern problemCharacterPattern = Pattern.compile("(?![A-Za-z_\\-\\.]).");

Review comment:
       The use of zero-width negative lookahead (?!X) here seemed odd to me.  I didn't understand what it was at first and still don't understand why it was structured this way but I left it alone.  If anyone can explain that I'd be curious to learn.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@storm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [storm] ben-roling commented on a change in pull request #3441: STORM-3822 fix visualization when streamId contains colon

Posted by GitBox <gi...@apache.org>.
ben-roling commented on a change in pull request #3441:
URL: https://github.com/apache/storm/pull/3441#discussion_r804088332



##########
File path: storm-webapp/src/main/java/org/apache/storm/daemon/ui/UIHelpers.java
##########
@@ -1746,19 +1746,26 @@ private static Double nullToZero(Double value) {
     }
 
     /**
-     * sanitizeStreamName.
+     * Sanitizes streamName for use as an identifier in the visualization.  Replaces all characters except A-Z, a-z,
+     * '.', '-', and '_' with '_'.  If streamName does not start with A-Z or a-z, adds '_s' prefix.
      * @param streamName streamName
-     * @return sanitizeStreamName
+     * @return sanitized stream name
      */
     public static String sanitizeStreamName(String streamName) {
-        Pattern pattern = Pattern.compile("(?![A-Za-z_\\-:\\.]).");
-        Pattern pattern2 = Pattern.compile("^[A-Za-z]");
-        Matcher matcher = pattern2.matcher(streamName);
-        Matcher matcher2 = pattern.matcher("\\s" + streamName);
-        if (matcher.find()) {
-            matcher2 = pattern.matcher(streamName);
+        Pattern startsWithLetterPattern = Pattern.compile("^[A-Za-z]");
+        Pattern problemCharacterPattern = Pattern.compile("(?![A-Za-z_\\-\\.]).");
+
+        Matcher startsWithLetterMatcher = startsWithLetterPattern.matcher(streamName);
+        Matcher problemCharacterMatcher;
+        if (startsWithLetterMatcher.find()) {
+            problemCharacterMatcher = problemCharacterPattern.matcher(streamName);
+        } else {
+            // if the streamName starts with non-letter character, prepend "\s".  The backslash will then
+            // get replaced by an underscore, resulting in the prefix of "_s" in the final sanitized name
+            problemCharacterMatcher = problemCharacterPattern.matcher("\\s" + streamName);

Review comment:
       This bit is a little bizarre.  I don't know why the original code was prefixing the steamName this way, but I left it as it was.  The prefix will ultimately become "_s" with the replaceAll() call that follows.  It might as well have been "_s" here as well.  I could change that if it make sense to others.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@storm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [storm] bipinprasad commented on a change in pull request #3441: STORM-3822 fix visualization when streamId contains colon

Posted by GitBox <gi...@apache.org>.
bipinprasad commented on a change in pull request #3441:
URL: https://github.com/apache/storm/pull/3441#discussion_r838733444



##########
File path: storm-webapp/src/main/java/org/apache/storm/daemon/ui/UIHelpers.java
##########
@@ -1746,19 +1746,26 @@ private static Double nullToZero(Double value) {
     }
 
     /**
-     * sanitizeStreamName.
+     * Sanitizes streamName for use as an identifier in the visualization.  Replaces all characters except A-Z, a-z,
+     * '.', '-', and '_' with '_'.  If streamName does not start with A-Z or a-z, adds '_s' prefix.
      * @param streamName streamName
-     * @return sanitizeStreamName
+     * @return sanitized stream name
      */
     public static String sanitizeStreamName(String streamName) {
-        Pattern pattern = Pattern.compile("(?![A-Za-z_\\-:\\.]).");
-        Pattern pattern2 = Pattern.compile("^[A-Za-z]");
-        Matcher matcher = pattern2.matcher(streamName);
-        Matcher matcher2 = pattern.matcher("\\s" + streamName);
-        if (matcher.find()) {
-            matcher2 = pattern.matcher(streamName);
+        Pattern startsWithLetterPattern = Pattern.compile("^[A-Za-z]");
+        Pattern problemCharacterPattern = Pattern.compile("(?![A-Za-z_\\-\\.]).");
+
+        Matcher startsWithLetterMatcher = startsWithLetterPattern.matcher(streamName);
+        Matcher problemCharacterMatcher;
+        if (startsWithLetterMatcher.find()) {
+            problemCharacterMatcher = problemCharacterPattern.matcher(streamName);
+        } else {
+            // if the streamName starts with non-letter character, prepend "\s".  The backslash will then
+            // get replaced by an underscore, resulting in the prefix of "_s" in the final sanitized name
+            problemCharacterMatcher = problemCharacterPattern.matcher("\\s" + streamName);

Review comment:
       Can you add a test. 
   
   The old code will do the following
   `String "////////" sanitized to "_s________"
   String "abc:ef///" sanitized to "abc:ef___"
   String "a//b/c/d" sanitized to "a__b_c_d"
   String "_sxyz" sanitized to "_s_sxyz"      <--- probably why "\\s" was used
   `
   
   However, the code can be cleaned up:
   `        if (Character.isLetter(streamName.charAt(0))) {
               return pattern.matcher(streamName).replaceAll("_");
           } else {
               return "_s" + pattern.matcher(streamName).replaceAll("_");
           }
   `




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@storm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [storm] bipinprasad merged pull request #3441: STORM-3822 fix visualization when streamId contains colon

Posted by GitBox <gi...@apache.org>.
bipinprasad merged pull request #3441:
URL: https://github.com/apache/storm/pull/3441


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@storm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [storm] rzo1 commented on pull request #3441: STORM-3822 fix visualization when streamId contains colon

Posted by GitBox <gi...@apache.org>.
rzo1 commented on pull request #3441:
URL: https://github.com/apache/storm/pull/3441#issuecomment-1081577266


   @ben-roling think this needs a rebase with master.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@storm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [storm] ben-roling commented on pull request #3441: STORM-3822 fix visualization when streamId contains colon

Posted by GitBox <gi...@apache.org>.
ben-roling commented on pull request #3441:
URL: https://github.com/apache/storm/pull/3441#issuecomment-1082183582


   @agresch @rzo1 thanks for taking a look at this!  I'll try to revisit it later today.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@storm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [storm] bipinprasad commented on a change in pull request #3441: STORM-3822 fix visualization when streamId contains colon

Posted by GitBox <gi...@apache.org>.
bipinprasad commented on a change in pull request #3441:
URL: https://github.com/apache/storm/pull/3441#discussion_r838733444



##########
File path: storm-webapp/src/main/java/org/apache/storm/daemon/ui/UIHelpers.java
##########
@@ -1746,19 +1746,26 @@ private static Double nullToZero(Double value) {
     }
 
     /**
-     * sanitizeStreamName.
+     * Sanitizes streamName for use as an identifier in the visualization.  Replaces all characters except A-Z, a-z,
+     * '.', '-', and '_' with '_'.  If streamName does not start with A-Z or a-z, adds '_s' prefix.
      * @param streamName streamName
-     * @return sanitizeStreamName
+     * @return sanitized stream name
      */
     public static String sanitizeStreamName(String streamName) {
-        Pattern pattern = Pattern.compile("(?![A-Za-z_\\-:\\.]).");
-        Pattern pattern2 = Pattern.compile("^[A-Za-z]");
-        Matcher matcher = pattern2.matcher(streamName);
-        Matcher matcher2 = pattern.matcher("\\s" + streamName);
-        if (matcher.find()) {
-            matcher2 = pattern.matcher(streamName);
+        Pattern startsWithLetterPattern = Pattern.compile("^[A-Za-z]");
+        Pattern problemCharacterPattern = Pattern.compile("(?![A-Za-z_\\-\\.]).");
+
+        Matcher startsWithLetterMatcher = startsWithLetterPattern.matcher(streamName);
+        Matcher problemCharacterMatcher;
+        if (startsWithLetterMatcher.find()) {
+            problemCharacterMatcher = problemCharacterPattern.matcher(streamName);
+        } else {
+            // if the streamName starts with non-letter character, prepend "\s".  The backslash will then
+            // get replaced by an underscore, resulting in the prefix of "_s" in the final sanitized name
+            problemCharacterMatcher = problemCharacterPattern.matcher("\\s" + streamName);

Review comment:
       Can you add a test. 
   
   The old code will do the following
   
   >     String "////////" sanitized to "_s________"
   >     String "abc:ef///" sanitized to "abc:ef___"
   >     String "a//b/c/d" sanitized to "a__b_c_d"
   >     String "_sxyz" sanitized to "_s_sxyz" 
   >     String "\sxyz" sanitized to "_s_sxyz"
   
   
   However, the code can be cleaned up:
   >         if (Character.isLetter(streamName.charAt(0))) {
   >             return pattern.matcher(streamName).replaceAll("_");
   >         } else {
   >             return "_s" + pattern.matcher(streamName).replaceAll("_");
   >         }
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@storm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [storm] bipinprasad commented on a change in pull request #3441: STORM-3822 fix visualization when streamId contains colon

Posted by GitBox <gi...@apache.org>.
bipinprasad commented on a change in pull request #3441:
URL: https://github.com/apache/storm/pull/3441#discussion_r838733444



##########
File path: storm-webapp/src/main/java/org/apache/storm/daemon/ui/UIHelpers.java
##########
@@ -1746,19 +1746,26 @@ private static Double nullToZero(Double value) {
     }
 
     /**
-     * sanitizeStreamName.
+     * Sanitizes streamName for use as an identifier in the visualization.  Replaces all characters except A-Z, a-z,
+     * '.', '-', and '_' with '_'.  If streamName does not start with A-Z or a-z, adds '_s' prefix.
      * @param streamName streamName
-     * @return sanitizeStreamName
+     * @return sanitized stream name
      */
     public static String sanitizeStreamName(String streamName) {
-        Pattern pattern = Pattern.compile("(?![A-Za-z_\\-:\\.]).");
-        Pattern pattern2 = Pattern.compile("^[A-Za-z]");
-        Matcher matcher = pattern2.matcher(streamName);
-        Matcher matcher2 = pattern.matcher("\\s" + streamName);
-        if (matcher.find()) {
-            matcher2 = pattern.matcher(streamName);
+        Pattern startsWithLetterPattern = Pattern.compile("^[A-Za-z]");
+        Pattern problemCharacterPattern = Pattern.compile("(?![A-Za-z_\\-\\.]).");
+
+        Matcher startsWithLetterMatcher = startsWithLetterPattern.matcher(streamName);
+        Matcher problemCharacterMatcher;
+        if (startsWithLetterMatcher.find()) {
+            problemCharacterMatcher = problemCharacterPattern.matcher(streamName);
+        } else {
+            // if the streamName starts with non-letter character, prepend "\s".  The backslash will then
+            // get replaced by an underscore, resulting in the prefix of "_s" in the final sanitized name
+            problemCharacterMatcher = problemCharacterPattern.matcher("\\s" + streamName);

Review comment:
       The old code will do the following
   
   >     String "////////" sanitized to "_s________"
   >     String "abc:ef///" sanitized to "abc:ef___"
   >     String "a//b/c/d" sanitized to "a__b_c_d"
   >     String "_sxyz" sanitized to "_s_sxyz" 
   >     String "\sxyz" sanitized to "_s_sxyz"
   
   
   However, the code can be cleaned up:
   >         if (Character.isLetter(streamName.charAt(0))) {
   >             return pattern.matcher(streamName).replaceAll("_");
   >         } else {
   >             return "_s" + pattern.matcher(streamName).replaceAll("_");
   >         }
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@storm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [storm] bipinprasad commented on a change in pull request #3441: STORM-3822 fix visualization when streamId contains colon

Posted by GitBox <gi...@apache.org>.
bipinprasad commented on a change in pull request #3441:
URL: https://github.com/apache/storm/pull/3441#discussion_r838754865



##########
File path: storm-webapp/src/test/java/org/apache/storm/daemon/ui/UIHelpersTest.java
##########
@@ -485,6 +485,19 @@ void test_getTopologySpoutAggStatsMap_generalFields() {
         assertEquals("", spoutResult.get("lastError"), "No error should be reported as empty string");
     }
 
+    /**
+     * Tests that santizeStreamName() does the expected manipulations
+     */
+    @Test
+    public void testSanitizeStreamName() {

Review comment:
       Thanks for adding the test case




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@storm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [storm] bipinprasad commented on a change in pull request #3441: STORM-3822 fix visualization when streamId contains colon

Posted by GitBox <gi...@apache.org>.
bipinprasad commented on a change in pull request #3441:
URL: https://github.com/apache/storm/pull/3441#discussion_r838733444



##########
File path: storm-webapp/src/main/java/org/apache/storm/daemon/ui/UIHelpers.java
##########
@@ -1746,19 +1746,26 @@ private static Double nullToZero(Double value) {
     }
 
     /**
-     * sanitizeStreamName.
+     * Sanitizes streamName for use as an identifier in the visualization.  Replaces all characters except A-Z, a-z,
+     * '.', '-', and '_' with '_'.  If streamName does not start with A-Z or a-z, adds '_s' prefix.
      * @param streamName streamName
-     * @return sanitizeStreamName
+     * @return sanitized stream name
      */
     public static String sanitizeStreamName(String streamName) {
-        Pattern pattern = Pattern.compile("(?![A-Za-z_\\-:\\.]).");
-        Pattern pattern2 = Pattern.compile("^[A-Za-z]");
-        Matcher matcher = pattern2.matcher(streamName);
-        Matcher matcher2 = pattern.matcher("\\s" + streamName);
-        if (matcher.find()) {
-            matcher2 = pattern.matcher(streamName);
+        Pattern startsWithLetterPattern = Pattern.compile("^[A-Za-z]");
+        Pattern problemCharacterPattern = Pattern.compile("(?![A-Za-z_\\-\\.]).");
+
+        Matcher startsWithLetterMatcher = startsWithLetterPattern.matcher(streamName);
+        Matcher problemCharacterMatcher;
+        if (startsWithLetterMatcher.find()) {
+            problemCharacterMatcher = problemCharacterPattern.matcher(streamName);
+        } else {
+            // if the streamName starts with non-letter character, prepend "\s".  The backslash will then
+            // get replaced by an underscore, resulting in the prefix of "_s" in the final sanitized name
+            problemCharacterMatcher = problemCharacterPattern.matcher("\\s" + streamName);

Review comment:
       Can you add a test. 
   
   The old code will do the following
   
   > String "////////" sanitized to "_s________"
   > String "abc:ef///" sanitized to "abc:ef___"
   > String "a//b/c/d" sanitized to "a__b_c_d"
   > String "_sxyz" sanitized to "_s_sxyz" 
   > String "\sxyz" sanitized to "_s_sxyz"
   
   
   However, the code can be cleaned up:
   >         if (Character.isLetter(streamName.charAt(0))) {
   >             return pattern.matcher(streamName).replaceAll("_");
   >         } else {
   >             return "_s" + pattern.matcher(streamName).replaceAll("_");
   >         }
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@storm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org