kl0u commented on a change in pull request #7095: [FLINK-10857][metrics] Cache 
logical scopes separately for each reporter
URL: https://github.com/apache/flink/pull/7095#discussion_r233781547
 
 

 ##########
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/metrics/groups/AbstractMetricGroup.java
 ##########
 @@ -152,14 +153,35 @@ public String getLogicalScope(CharacterFilter filter) {
         * @return logical scope
         */
        public String getLogicalScope(CharacterFilter filter, char delimiter) {
-               if (logicalScopeString == null) {
+               return getLogicalScope(filter, delimiter, -1);
+       }
+
+       /**
+        * Returns the logical scope of this group, for example
+        * {@code "taskmanager.job.task"}.
+        *
+        * @param filter character filter which is applied to the scope 
components
+        * @param delimiter delimiter to use for concatenating scope components
+        * @param reporterIndex index of the reporter
+        * @return logical scope
+        */
+       public String getLogicalScope(CharacterFilter filter, char delimiter, 
int reporterIndex) {
 
 Review comment:
   This method could become package private and if I did not mess up, it could 
become something like:
   
   ```
   String getLogicalScope(CharacterFilter filter, char delimiter, int 
reporterIndex) {
                if (logicalScopeStrings.length == 0 || (reporterIndex < 0 || 
reporterIndex >= logicalScopeStrings.length)) {
                        return getChildLogicalScope(filter, delimiter);
                }
   
                if (logicalScopeStrings[reporterIndex] == null) {
                        logicalScopeStrings[reporterIndex] = 
getChildLogicalScope(filter, delimiter);
                }
                return logicalScopeStrings[reporterIndex];
        }
   
        private String getChildLogicalScope(CharacterFilter filter, char 
delimiter) {
                final String groupName = getGroupName(filter);
                return parent == null
                                ? groupName
                                : parent.getLogicalScope(filter, delimiter) + 
delimiter + groupName;
        }
   ```
   
   I find this more readable and with less `return`s.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to