Ethanlm commented on a change in pull request #3417:
URL: https://github.com/apache/storm/pull/3417#discussion_r733111555
##########
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:
This can be confusing when this is invoked (by multiple reporters who
don't recognize PerReporterGauge). Thinking we should add some comment at least
##########
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 {
Review comment:
This has nothing to do with IMetric anymore. Feel like we should
simplify it since we are here
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]