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 2021/10/19 20:20:51 UTC

[GitHub] [storm] bipinprasad commented on a change in pull request #3417: STORM-3801 add option for gauges to report values per reporter if sup…

bipinprasad commented on a change in pull request #3417:
URL: https://github.com/apache/storm/pull/3417#discussion_r732214003



##########
File path: storm-client/src/jvm/org/apache/storm/metric/SystemBolt.java
##########
@@ -63,33 +65,46 @@ public Long getValue() {
             }
         });
 
-        // newWorkerEvent: 1 when a worker is first started and 0 all other times.
-        // This can be used to tell when a worker has crashed and is restarted.
-        final IMetric newWorkerEvent = new IMetric() {
-            boolean doEvent = true;
 
-            @Override
-            public Object getValueAndReset() {
-                if (doEvent) {
-                    doEvent = false;
-                    return 1;
-                } else {
-                    return 0;
-                }
-            }
-        };
-        context.registerGauge("newWorkerEvent", new Gauge<Integer>() {
-            @Override
-            public Integer getValue() {
-                return (Integer) newWorkerEvent.getValueAndReset();
-            }
-        });
+        context.registerGauge("newWorkerEvent", new NewWorkerGauge());
 
         int bucketSize = ObjectReader.getInt(topoConf.get(Config.TOPOLOGY_BUILTIN_METRICS_BUCKET_SIZE_SECS));
         registerMetrics(context, (Map<String, String>) topoConf.get(Config.WORKER_METRICS), bucketSize, topoConf);
         registerMetrics(context, (Map<String, String>) topoConf.get(Config.TOPOLOGY_WORKER_METRICS), bucketSize, topoConf);
     }
 
+    // newWorkerEvent: 1 when a worker is first started and 0 all other times.
+    // This can be used to tell when a worker has crashed and is restarted.
+    private class NewWorkerImetric implements IMetric {
+        boolean doEvent = true;
+
+        @Override
+        public Object getValueAndReset() {
+            if (doEvent) {
+                doEvent = false;
+                return 1;
+            } else {
+                return 0;
+            }
+        }
+    }
+
+    // allow reporting new worker metric for multiple reporters if they support getValueForReporter().
+    private class NewWorkerGauge extends PerReporterGauge<Integer> {
+        private final NewWorkerImetric defaultValue = new NewWorkerImetric();
+        private final Map<Object, NewWorkerImetric> reporterValues = new HashMap<>();
+
+        @Override
+        public Integer getValue() {
+            return (Integer) defaultValue.getValueAndReset();
+        }

Review comment:
       Should this be ever called?




-- 
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