Update Metric Collector to Handle Incorrect Kernel File Values
Sometimes a port is recognized as existing but not properly configured which leads to kernel files not being correctly populated with correct values with respect to their properties. We should only consider a port to be Up/Active if the values match the spec and ignore any nonsense values. For example, negative speed does not make sense for a non active port.
Tested: Negative speed in /sys/class/net/speed file is ignored.
Change-Id: I0d6fb8c475e35c508a3e1166126b583a6bd3dcd7
Signed-off-by: Edward Lee <edwarddl@google.com>
diff --git a/recipes-google/metric-collector/metric-collector/0002-Metric-Collection-Daemon.patch b/recipes-google/metric-collector/metric-collector/0002-Metric-Collection-Daemon.patch
index af46e45..37e9208 100644
--- a/recipes-google/metric-collector/metric-collector/0002-Metric-Collection-Daemon.patch
+++ b/recipes-google/metric-collector/metric-collector/0002-Metric-Collection-Daemon.patch
@@ -75,7 +75,7 @@
Signed-off-by: Edward Lee <edwarddl@google.com>
Signed-off-by: Willy Tu <wltu@google.com>
-Change-Id: I8cd6b341b65a2ce0414b1a545aedb0a82c06186f
+Change-Id: I88ec028efcd9373f72589a321bc8246c3664d40f
---
.gitignore | 1 +
meson.build | 1 +
@@ -86,11 +86,11 @@
.../metricCollector.cpp | 392 ++++++++++++++++++
.../metricCollector.hpp | 79 ++++
.../phosphor-metric-collector.service.in | 11 +
- subprojects/metric-collection-daemon/port.cpp | 193 +++++++++
+ subprojects/metric-collection-daemon/port.cpp | 197 +++++++++
subprojects/metric-collection-daemon/port.hpp | 64 +++
.../metric-collection-daemon/utils.cpp | 179 ++++++++
.../metric-collection-daemon/utils.hpp | 35 ++
- 13 files changed, 1284 insertions(+)
+ 13 files changed, 1288 insertions(+)
create mode 120000 metric-collection-daemon
create mode 100644 subprojects/metric-collection-daemon/daemon.cpp
create mode 100644 subprojects/metric-collection-daemon/daemon.hpp
@@ -984,10 +984,10 @@
+WantedBy=multi-user.target
diff --git a/subprojects/metric-collection-daemon/port.cpp b/subprojects/metric-collection-daemon/port.cpp
new file mode 100644
-index 0000000..6eb847d
+index 0000000..8ffba8f
--- /dev/null
+++ b/subprojects/metric-collection-daemon/port.cpp
-@@ -0,0 +1,193 @@
+@@ -0,0 +1,197 @@
+#include "port.hpp"
+
+#include "utils.hpp"
@@ -1080,7 +1080,7 @@
+ auto res = std::from_chars(speedFile.data(),
+ speedFile.data() + speedFile.size(), speed);
+
-+ if (res.ec != std::errc())
++ if (res.ec != std::errc() || speed < 0)
+ {
+ return 0;
+ }
@@ -1093,6 +1093,8 @@
+ const std::string& dormantPath =
+ fmt::format("/sys/class/net/{}/dormant", interfaceName);
+ // https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-net
++
++ // If dormant is non 0, it should be considered disabled
+ return toSizeT(readFileIntoString(dormantPath)) == 0;
+}
+
@@ -1101,7 +1103,9 @@
+ const std::string& linkUpPath =
+ fmt::format("/sys/class/net/{}/carrier", interfaceName);
+ // https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-net
-+ return toSizeT(readFileIntoString(linkUpPath)) != 0;
++
++ // If linkUp is not 1, it should be considered down
++ return toSizeT(readFileIntoString(linkUpPath)) == 1;
+}
+
+void Port::updatePortProperties()
@@ -1478,5 +1482,5 @@
+
+std::optional<std::string> getPortIdByNum(const int portNum);
--
-2.40.0.348.gf938b09366-goog
+2.40.0.577.gac1e443424-goog