Github user tillrohrmann commented on a diff in the pull request:

    https://github.com/apache/flink/pull/2363#discussion_r77540202
  
    --- Diff: 
flink-runtime-web/src/main/java/org/apache/flink/runtime/webmonitor/metrics/MetricStore.java
 ---
    @@ -35,109 +46,111 @@
        final Map<String, TaskManagerMetricStore> taskManagers = new 
HashMap<>();
        final Map<String, JobMetricStore> jobs = new HashMap<>();
     
    -   /**
    -    * Adds a metric to this MetricStore.
    -    *
    -    * @param name  the metric identifier
    -    * @param value the metric value
    -    */
    -   public void add(String name, Object value) {
    -           TaskManagerMetricStore tm;
    -           JobMetricStore job;
    -           TaskMetricStore task;
    -
    +   public void add(MetricDump metric) {
                try {
    -                   String[] components = name.split(":");
    -                   switch (components[0]) {
    -                           /**
    -                            * JobManagerMetricStore metric
    -                            * format: 0:<user_scope>.<name>
    -                            */
    -                           case "0":
    -                                   jobManager.metrics.put(components[1], 
value);
    -                                   break;
    -                           /**
    -                            * TaskManager metric
    -                            * format: 1:<tm_id>:<user_scope>.<name>
    -                            */
    -                           case "1":
    -                                   if (components.length != 3) {
    -                                           break;
    -                                   }
    -                                   tm = taskManagers.get(components[1]);
    +                   QueryScopeInfo info = metric.scopeInfo;
    +                   TaskManagerMetricStore tm;
    +                   JobMetricStore job;
    +                   TaskMetricStore task;
    +
    +                   String name = info.scope.isEmpty()
    +                           ? metric.name
    +                           : info.scope + "." + metric.name;
    +                   
    +                   if (name.isEmpty()) { // malformed transmission
    +                           return;
    +                   }
    +
    +                   switch (info.getCategory()) {
    +                           case INFO_CATEGORY_JM:
    --- End diff --
    
    That is true. Performance-wise it is the more efficient way to execute it, 
no doubt. I was just wondering whether this is not a case of premature 
optimization with the price of harder maintainability.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to