NVMeMetric: Enable NVMe Metric only for primary controllers

Currently we don't need to read NVMe Metrics from the secondary
controllers, which is align with the client behavior before the BMC
cache interface.

Tested: via the fake interface. DBus interface appears only for PF
Signed-off-by: Hao Jiang <jianghao@google.com>
Change-Id: I15762209231b3dcec0da91774c1ad5d0c1b2f1fb
diff --git a/src/NVMeController.cpp b/src/NVMeController.cpp
index 83cd747..c0fa961 100644
--- a/src/NVMeController.cpp
+++ b/src/NVMeController.cpp
@@ -177,73 +177,75 @@
 {
     this->NVMeController::start(nvmePlugin);
 
-    // only to test compilation. need to remove.
-    this->metricStore.emplace(this->NVMeController::io,
-                              this->NVMeController::conn,
-                              this->NVMeController::path);
+    if (isPrimary)
+    {
+        // only to test compilation. need to remove.
+        this->metricStore.emplace(this->NVMeController::io,
+                                  this->NVMeController::conn,
+                                  this->NVMeController::path);
 
-    auto scheduler = Scheduler<SchedulerClockType>::getScheduler(path);
+        auto scheduler = Scheduler<SchedulerClockType>::getScheduler(path);
 
-    using IdentifyMetric =
-        IdentifyMetric<NVME_IDENTIFY_CNS_CTRL, SchedulerClockType>;
+        using IdentifyMetric =
+            IdentifyMetric<NVME_IDENTIFY_CNS_CTRL, SchedulerClockType>;
 
-    using ErrorInfoMetric =
-        ControllerLogPageMetric<NVME_LOG_LID_ERROR, SchedulerClockType>;
-    using SMARTMetric =
-        ControllerLogPageMetric<NVME_LOG_LID_SMART, SchedulerClockType>;
-    using FwSlotMetric =
-        ControllerLogPageMetric<NVME_LOG_LID_FW_SLOT, SchedulerClockType>;
-    using SelfTestMetric =
-        ControllerLogPageMetric<NVME_LOG_LID_DEVICE_SELF_TEST,
-                                SchedulerClockType>;
-    using HostTelemetryMetric =
-        ControllerLogPageMetric<NVME_LOG_LID_TELEMETRY_HOST,
-                                SchedulerClockType>;
+        using ErrorInfoMetric =
+            ControllerLogPageMetric<NVME_LOG_LID_ERROR, SchedulerClockType>;
+        using SMARTMetric =
+            ControllerLogPageMetric<NVME_LOG_LID_SMART, SchedulerClockType>;
+        using FwSlotMetric =
+            ControllerLogPageMetric<NVME_LOG_LID_FW_SLOT, SchedulerClockType>;
+        using SelfTestMetric =
+            ControllerLogPageMetric<NVME_LOG_LID_DEVICE_SELF_TEST,
+                                    SchedulerClockType>;
+        using HostTelemetryMetric =
+            ControllerLogPageMetric<NVME_LOG_LID_TELEMETRY_HOST,
+                                    SchedulerClockType>;
 
-    // NOLINTBEGIN(modernize-make-shared)
-    auto identify = std::shared_ptr<IdentifyMetric>(new IdentifyMetric(
-        this->shared_from_this(), scheduler,
-        // Metigate solution before Knuckle FW fix for b/404610159
-        std::chrono::seconds(60)));
+        // NOLINTBEGIN(modernize-make-shared)
+        auto identify = std::shared_ptr<IdentifyMetric>(new IdentifyMetric(
+            this->shared_from_this(), scheduler,
+            // Metigate solution before Knuckle FW fix for b/404610159
+            std::chrono::seconds(60)));
 
-    auto errorInfo = std::shared_ptr<ErrorInfoMetric>(new ErrorInfoMetric(
-        this->weak_from_this(), scheduler,
-        // TODO: configurable interval
-        std::chrono::duration_cast<SchedulerClockType::duration>(
-            std::chrono::seconds(60))));
-
-    auto smart = std::shared_ptr<SMARTMetric>(new SMARTMetric(
-        this->weak_from_this(), scheduler,
-        // TODO: configurable interval
-        std::chrono::duration_cast<SchedulerClockType::duration>(
-            std::chrono::seconds(60))));
-
-    auto fwSlot = std::shared_ptr<FwSlotMetric>(new FwSlotMetric(
-        this->weak_from_this(), scheduler,
-        // TODO: configurable interval
-        std::chrono::duration_cast<SchedulerClockType::duration>(
-            std::chrono::seconds(60))));
-
-    auto selfTest = std::shared_ptr<SelfTestMetric>(new SelfTestMetric(
-        this->weak_from_this(), scheduler,
-        // TODO: configurable interval
-        std::chrono::duration_cast<SchedulerClockType::duration>(
-            std::chrono::seconds(60))));
-
-    auto hostTelemetry =
-        std::shared_ptr<HostTelemetryMetric>(new HostTelemetryMetric(
+        auto errorInfo = std::shared_ptr<ErrorInfoMetric>(new ErrorInfoMetric(
             this->weak_from_this(), scheduler,
             // TODO: configurable interval
             std::chrono::duration_cast<SchedulerClockType::duration>(
-                std::chrono::seconds(900))));
-    // NOLINTEND(modernize-make-shared)
+                std::chrono::seconds(60))));
 
-    this->metricStore.emplace(
-        this->NVMeController::io, this->NVMeController::conn,
-        this->NVMeController::path, std::move(identify), std::move(errorInfo),
-        std::move(smart), std::move(fwSlot), std::move(selfTest),
-        std::move(hostTelemetry));
+        auto smart = std::shared_ptr<SMARTMetric>(new SMARTMetric(
+            this->weak_from_this(), scheduler,
+            // TODO: configurable interval
+            std::chrono::duration_cast<SchedulerClockType::duration>(
+                std::chrono::seconds(60))));
 
+        auto fwSlot = std::shared_ptr<FwSlotMetric>(new FwSlotMetric(
+            this->weak_from_this(), scheduler,
+            // TODO: configurable interval
+            std::chrono::duration_cast<SchedulerClockType::duration>(
+                std::chrono::seconds(60))));
+
+        auto selfTest = std::shared_ptr<SelfTestMetric>(new SelfTestMetric(
+            this->weak_from_this(), scheduler,
+            // TODO: configurable interval
+            std::chrono::duration_cast<SchedulerClockType::duration>(
+                std::chrono::seconds(60))));
+
+        auto hostTelemetry =
+            std::shared_ptr<HostTelemetryMetric>(new HostTelemetryMetric(
+                this->weak_from_this(), scheduler,
+                // TODO: configurable interval
+                std::chrono::duration_cast<SchedulerClockType::duration>(
+                    std::chrono::seconds(900))));
+        // NOLINTEND(modernize-make-shared)
+
+        this->metricStore.emplace(
+            this->NVMeController::io, this->NVMeController::conn,
+            this->NVMeController::path, std::move(identify),
+            std::move(errorInfo), std::move(smart), std::move(fwSlot),
+            std::move(selfTest), std::move(hostTelemetry));
+    }
     status = Status::Enabled;
 }