NVMeMetric: MetricStore constructor allows empty Metric The MetricStore now can accept empty metric from nvmed and nvmed plugins, by ignoring these empty metrics. The purposes are: * prevent a daemon crash from an ill-written plugin * allows the MetricStore owner pushes empty metric intentionally Signed-off-by: Hao Jiang <jianghao@google.com> Change-Id: I1f47c8042e3b2b8004632cc7058f38085aa08e53
diff --git a/src/NVMeMetricStore.hpp b/src/NVMeMetricStore.hpp index 1cb84b3..607108b 100644 --- a/src/NVMeMetricStore.hpp +++ b/src/NVMeMetricStore.hpp
@@ -55,13 +55,18 @@ sdbusplus::xyz::openbmc_project::NVMe::server::MetricStore( dynamic_cast<sdbusplus::bus_t&>(*conn), objectPath.c_str()), path(objectPath), io(io), - metricStore{ - {std::string{metrics->getIdentifier()}, std::move(metrics)}...}, + metricStore{{std::string{metrics ? metrics->getIdentifier() : ""}, + std::move(metrics)}...}, validFlag(std::make_shared<bool>()) { + metricStore.erase(""); auto vuMetrics = getVendorMatrics(path); for (auto& metric : vuMetrics) { + if (!metric) + { + continue; + } auto [itr, res] = metricStore.try_emplace( std::string{metric->getIdentifier()}, std::move(metric)); if (!res)