Github user abhishekagarwal87 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1560#discussion_r70787174
--- Diff:
storm-core/src/jvm/org/apache/storm/metric/util/DataPointPopulator.java ---
@@ -0,0 +1,61 @@
+package org.apache.storm.metric.util;
+
+import org.apache.storm.metric.api.IMetricsConsumer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+public class DataPointPopulator implements Serializable {
+ public static final Logger LOG =
LoggerFactory.getLogger(DataPointPopulator.class);
+
+ private final boolean populateMapType;
+ private final String metricNameSeparator;
+
+ public DataPointPopulator(boolean populateMapType, String
metricNameSeparator) {
+ this.populateMapType = populateMapType;
+ this.metricNameSeparator = metricNameSeparator;
+ }
+
+ public Collection<IMetricsConsumer.DataPoint>
populateDataPoints(Collection<IMetricsConsumer.DataPoint> dataPoints) {
+ if (!populateMapType) {
+ return dataPoints;
+ }
+
+ List<IMetricsConsumer.DataPoint> populatedDataPoints = new
ArrayList<>();
+
+ for (IMetricsConsumer.DataPoint dataPoint : dataPoints) {
+ populatedDataPoints.addAll(populateDataPoint(dataPoint));
+ }
+
+ return populatedDataPoints;
+ }
+
+ public Collection<IMetricsConsumer.DataPoint>
populateDataPoint(IMetricsConsumer.DataPoint dataPoint) {
+ if (!populateMapType) {
+ return Collections.singletonList(dataPoint);
+ }
+
+ List<IMetricsConsumer.DataPoint> dataPoints = new ArrayList<>();
+
+ if (dataPoint.value == null) {
+ LOG.warn("Data point with name " + dataPoint.name + " is null.
Discarding." + dataPoint.name);
+ } else if (dataPoint.value instanceof Map) {
+ Map<String, Object> dataMap = (Map<String, Object>) dataPoint.value;
--- End diff --
There is no guarantee that key type will be string. Might be better to
assume it to of Object type and wrap entry.getKey() in String.valueOf
---
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.
---