You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by bb...@apache.org on 2018/11/06 22:55:55 UTC

[1/2] nifi git commit: NIFI-5796: Addressed issue that caused Counters' values to show the wrong value in Status History

Repository: nifi
Updated Branches:
  refs/heads/master 931bb0bc3 -> da1f9eaf6


NIFI-5796: Addressed issue that caused Counters' values to show the wrong value in Status History

Signed-off-by: Bryan Bende <bb...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/4069d755
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/4069d755
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/4069d755

Branch: refs/heads/master
Commit: 4069d755505444b8730fe7f3f4a1a702a281e78c
Parents: 931bb0b
Author: Mark Payne <ma...@hotmail.com>
Authored: Tue Nov 6 16:20:57 2018 -0500
Committer: Bryan Bende <bb...@apache.org>
Committed: Tue Nov 6 17:55:09 2018 -0500

----------------------------------------------------------------------
 .../status/history/MetricDescriptor.java        |  5 +
 .../history/AbstractMetricDescriptor.java       | 98 ++++++++++++++++++++
 .../status/history/CounterMetricDescriptor.java | 63 +++++++++++++
 .../history/StandardMetricDescriptor.java       | 74 ++-------------
 .../status/history/StandardStatusSnapshot.java  |  6 +-
 .../org/apache/nifi/util/ComponentMetrics.java  |  4 +-
 6 files changed, 181 insertions(+), 69 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/4069d755/nifi-framework-api/src/main/java/org/apache/nifi/controller/status/history/MetricDescriptor.java
----------------------------------------------------------------------
diff --git a/nifi-framework-api/src/main/java/org/apache/nifi/controller/status/history/MetricDescriptor.java b/nifi-framework-api/src/main/java/org/apache/nifi/controller/status/history/MetricDescriptor.java
index c0c52b6..14887ef 100644
--- a/nifi-framework-api/src/main/java/org/apache/nifi/controller/status/history/MetricDescriptor.java
+++ b/nifi-framework-api/src/main/java/org/apache/nifi/controller/status/history/MetricDescriptor.java
@@ -64,4 +64,9 @@ public interface MetricDescriptor<T> {
      * into a single Long value
      */
     ValueReducer<StatusSnapshot, Long> getValueReducer();
+
+    /**
+     * @return <code>true</code> if the metric is for a component Counter, <code>false</code> otherwise
+     */
+    boolean isCounter();
 }

http://git-wip-us.apache.org/repos/asf/nifi/blob/4069d755/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/AbstractMetricDescriptor.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/AbstractMetricDescriptor.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/AbstractMetricDescriptor.java
new file mode 100644
index 0000000..980efdd
--- /dev/null
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/AbstractMetricDescriptor.java
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.controller.status.history;
+
+import java.util.List;
+
+public abstract class AbstractMetricDescriptor<T> implements MetricDescriptor<T> {
+    private final IndexableMetric indexableMetric;
+    private final String field;
+    private final String label;
+    private final String description;
+    private final MetricDescriptor.Formatter formatter;
+    private final ValueMapper<T> valueMapper;
+    private final ValueReducer<StatusSnapshot, Long> reducer;
+
+    public AbstractMetricDescriptor(final IndexableMetric indexableMetric, final String field, final String label, final String description,
+                                    final MetricDescriptor.Formatter formatter, final ValueMapper<T> valueFunction) {
+        this(indexableMetric, field, label, description, formatter, valueFunction, null);
+    }
+
+    public AbstractMetricDescriptor(final IndexableMetric indexableMetric, final String field, final String label, final String description,
+                                    final MetricDescriptor.Formatter formatter, final ValueMapper<T> valueFunction, final ValueReducer<StatusSnapshot, Long> reducer) {
+        this.indexableMetric = indexableMetric;
+        this.field = field;
+        this.label = label;
+        this.description = description;
+        this.formatter = formatter;
+        this.valueMapper = valueFunction;
+        this.reducer = reducer == null ? new SumReducer() : reducer;
+    }
+
+    @Override
+    public int getMetricIdentifier() {
+        return indexableMetric.getIndex();
+    }
+
+    @Override
+    public String getField() {
+        return field;
+    }
+
+    @Override
+    public boolean isCounter() {
+        return false;
+    }
+
+    @Override
+    public String getLabel() {
+        return label;
+    }
+
+    @Override
+    public String getDescription() {
+        return description;
+    }
+
+    @Override
+    public MetricDescriptor.Formatter getFormatter() {
+        return formatter;
+    }
+
+    @Override
+    public ValueMapper<T> getValueFunction() {
+        return valueMapper;
+    }
+
+    @Override
+    public ValueReducer<StatusSnapshot, Long> getValueReducer() {
+        return reducer;
+    }
+
+    class SumReducer implements ValueReducer<StatusSnapshot, Long> {
+
+        @Override
+        public Long reduce(final List<StatusSnapshot> values) {
+            long sum = 0;
+            for (final StatusSnapshot snapshot : values) {
+                sum += snapshot.getStatusMetric(AbstractMetricDescriptor.this);
+            }
+
+            return sum;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/nifi/blob/4069d755/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/CounterMetricDescriptor.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/CounterMetricDescriptor.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/CounterMetricDescriptor.java
new file mode 100644
index 0000000..5aa7a72
--- /dev/null
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/CounterMetricDescriptor.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.controller.status.history;
+
+public class CounterMetricDescriptor<T> extends AbstractMetricDescriptor<T> {
+
+    private static final IndexableMetric ILLEGAL_INDEXABLE_METRIC = () -> {
+        throw new UnsupportedOperationException();
+    };
+
+    public CounterMetricDescriptor(final String field, final String label, final String description,
+                                   final MetricDescriptor.Formatter formatter, final ValueMapper<T> valueFunction) {
+        super(ILLEGAL_INDEXABLE_METRIC, field, label, description, formatter, valueFunction, null);
+    }
+
+    public CounterMetricDescriptor(final String field, final String label, final String description,
+                                   final MetricDescriptor.Formatter formatter, final ValueMapper<T> valueFunction, final ValueReducer<StatusSnapshot, Long> reducer) {
+        super(ILLEGAL_INDEXABLE_METRIC, field, label, description, formatter, valueFunction, reducer);
+    }
+
+    @Override
+    public boolean isCounter() {
+        return true;
+    }
+
+    @Override
+    public String toString() {
+        return "StandardMetricDescriptor[" + getLabel() + "]";
+    }
+
+    @Override
+    public int hashCode() {
+        return 239891 + getFormatter().name().hashCode() + 4 * getLabel().hashCode() + 8 * getField().hashCode() + 28 * getDescription().hashCode();
+    }
+
+    @Override
+    public boolean equals(final Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!(obj instanceof CounterMetricDescriptor)) {
+            return false;
+        }
+
+        MetricDescriptor<?> other = (MetricDescriptor<?>) obj;
+        return getField().equals(other.getField());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/nifi/blob/4069d755/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/StandardMetricDescriptor.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/StandardMetricDescriptor.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/StandardMetricDescriptor.java
index de5e0b5..1b6f65f 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/StandardMetricDescriptor.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/StandardMetricDescriptor.java
@@ -16,77 +16,31 @@
  */
 package org.apache.nifi.controller.status.history;
 
-import java.util.List;
-
-public class StandardMetricDescriptor<T> implements MetricDescriptor<T> {
-
-    private final IndexableMetric indexableMetric;
-    private final String field;
-    private final String label;
-    private final String description;
-    private final MetricDescriptor.Formatter formatter;
-    private final ValueMapper<T> valueMapper;
-    private final ValueReducer<StatusSnapshot, Long> reducer;
+public class StandardMetricDescriptor<T> extends AbstractMetricDescriptor<T> {
 
     public StandardMetricDescriptor(final IndexableMetric indexableMetric, final String field, final String label, final String description,
                                     final MetricDescriptor.Formatter formatter, final ValueMapper<T> valueFunction) {
-        this(indexableMetric, field, label, description, formatter, valueFunction, null);
+        super(indexableMetric, field, label, description, formatter, valueFunction);
     }
 
     public StandardMetricDescriptor(final IndexableMetric indexableMetric, final String field, final String label, final String description,
                                     final MetricDescriptor.Formatter formatter, final ValueMapper<T> valueFunction, final ValueReducer<StatusSnapshot, Long> reducer) {
-        this.indexableMetric = indexableMetric;
-        this.field = field;
-        this.label = label;
-        this.description = description;
-        this.formatter = formatter;
-        this.valueMapper = valueFunction;
-        this.reducer = reducer == null ? new SumReducer() : reducer;
-    }
-
-    @Override
-    public int getMetricIdentifier() {
-        return indexableMetric.getIndex();
-    }
-
-    @Override
-    public String getField() {
-        return field;
-    }
-
-    @Override
-    public String getLabel() {
-        return label;
-    }
-
-    @Override
-    public String getDescription() {
-        return description;
-    }
-
-    @Override
-    public MetricDescriptor.Formatter getFormatter() {
-        return formatter;
-    }
-
-    @Override
-    public ValueMapper<T> getValueFunction() {
-        return valueMapper;
+        super(indexableMetric, field, label, description, formatter, valueFunction, reducer);
     }
 
     @Override
-    public ValueReducer<StatusSnapshot, Long> getValueReducer() {
-        return reducer;
+    public boolean isCounter() {
+        return false;
     }
 
     @Override
     public String toString() {
-        return "StandardMetricDescriptor[" + label + "]";
+        return "StandardMetricDescriptor[" + getLabel() + "]";
     }
 
     @Override
     public int hashCode() {
-        return 23987 + formatter.name().hashCode() + 4 * label.hashCode() + 8 * field.hashCode() + 28 * description.hashCode();
+        return 23987 + getFormatter().name().hashCode() + 4 * getLabel().hashCode() + 8 * getField().hashCode() + 28 * getDescription().hashCode();
     }
 
     @Override
@@ -99,19 +53,7 @@ public class StandardMetricDescriptor<T> implements MetricDescriptor<T> {
         }
 
         MetricDescriptor<?> other = (MetricDescriptor<?>) obj;
-        return field.equals(other.getField());
+        return getField().equals(other.getField());
     }
 
-    class SumReducer implements ValueReducer<StatusSnapshot, Long> {
-
-        @Override
-        public Long reduce(final List<StatusSnapshot> values) {
-            long sum = 0;
-            for (final StatusSnapshot snapshot : values) {
-                sum += snapshot.getStatusMetric(StandardMetricDescriptor.this);
-            }
-
-            return sum;
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/nifi/blob/4069d755/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/StandardStatusSnapshot.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/StandardStatusSnapshot.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/StandardStatusSnapshot.java
index fb9112b..8e78c5e 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/StandardStatusSnapshot.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/StandardStatusSnapshot.java
@@ -65,7 +65,11 @@ public class StandardStatusSnapshot implements StatusSnapshot {
 
     @Override
     public Long getStatusMetric(final MetricDescriptor<?> descriptor) {
-        return values[descriptor.getMetricIdentifier()];
+        if (descriptor.isCounter()) {
+            return counterValues.get(descriptor);
+        } else {
+            return values[descriptor.getMetricIdentifier()];
+        }
     }
 
     public void setTimestamp(final Date timestamp) {

http://git-wip-us.apache.org/repos/asf/nifi/blob/4069d755/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/util/ComponentMetrics.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/util/ComponentMetrics.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/util/ComponentMetrics.java
index 9c1505c..7fa2278 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/util/ComponentMetrics.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/util/ComponentMetrics.java
@@ -21,11 +21,11 @@ import org.apache.nifi.controller.status.ProcessGroupStatus;
 import org.apache.nifi.controller.status.ProcessorStatus;
 import org.apache.nifi.controller.status.RemoteProcessGroupStatus;
 import org.apache.nifi.controller.status.history.ConnectionStatusDescriptor;
+import org.apache.nifi.controller.status.history.CounterMetricDescriptor;
 import org.apache.nifi.controller.status.history.MetricDescriptor;
 import org.apache.nifi.controller.status.history.ProcessGroupStatusDescriptor;
 import org.apache.nifi.controller.status.history.ProcessorStatusDescriptor;
 import org.apache.nifi.controller.status.history.RemoteProcessGroupStatusDescriptor;
-import org.apache.nifi.controller.status.history.StandardMetricDescriptor;
 import org.apache.nifi.controller.status.history.StandardStatusSnapshot;
 import org.apache.nifi.controller.status.history.StatusSnapshot;
 
@@ -84,7 +84,7 @@ public class ComponentMetrics {
                 final String counterName = entry.getKey();
 
                 final String label = entry.getKey() + " (5 mins)";
-                final MetricDescriptor<ProcessorStatus> metricDescriptor = new StandardMetricDescriptor<>(() -> 0, entry.getKey(), label, label, MetricDescriptor.Formatter.COUNT,
+                final MetricDescriptor<ProcessorStatus> metricDescriptor = new CounterMetricDescriptor<>(entry.getKey(), label, label, MetricDescriptor.Formatter.COUNT,
                         s -> s.getCounters() == null ? null : s.getCounters().get(counterName));
 
                 snapshot.addCounterStatusMetric(metricDescriptor, entry.getValue());


[2/2] nifi git commit: NIFI-5796 Addressed bug in subtract() method for keeping running total of counters for status history

Posted by bb...@apache.org.
NIFI-5796 Addressed bug in subtract() method for keeping running total of counters for status history

This closes #3136.

Signed-off-by: Bryan Bende <bb...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/da1f9eaf
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/da1f9eaf
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/da1f9eaf

Branch: refs/heads/master
Commit: da1f9eaf6a82f7cb0b10cf94c708e3b800071972
Parents: 4069d75
Author: Mark Payne <ma...@hotmail.com>
Authored: Tue Nov 6 17:38:46 2018 -0500
Committer: Bryan Bende <bb...@apache.org>
Committed: Tue Nov 6 17:55:21 2018 -0500

----------------------------------------------------------------------
 .../apache/nifi/controller/repository/metrics/EventSumValue.java   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/da1f9eaf/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/metrics/EventSumValue.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/metrics/EventSumValue.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/metrics/EventSumValue.java
index 210f7ac..a618812 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/metrics/EventSumValue.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/metrics/EventSumValue.java
@@ -180,7 +180,7 @@ public class EventSumValue {
                     final String counterName = entry.getKey();
                     final Long counterValue = entry.getValue();
 
-                    counters.compute(counterName, (key, value) -> value == null ? counterValue : counterValue - value);
+                    counters.compute(counterName, (key, value) -> value == null ? -counterValue : value - counterValue);
                 }
             }
         }