manager: rate limit dbus errors
If there is a misconfiguration between sysfs and led-manager,
the manager will be very spammy about dbus errors at it tries
to update the sysfs value. Rate limit this to once per hour
per LED.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I2896377ff64318159ca3963d09c2ab5bf7452862
diff --git a/manager/manager.cpp b/manager/manager.cpp
index b571546..336f819 100644
--- a/manager/manager.cpp
+++ b/manager/manager.cpp
@@ -7,8 +7,10 @@
#include <xyz/openbmc_project/Led/Physical/server.hpp>
#include <algorithm>
+#include <chrono>
#include <iostream>
#include <string>
+
namespace phosphor
{
namespace led
@@ -232,9 +234,24 @@
}
catch (const sdbusplus::exception_t& e)
{
+ // This can be a really spammy event log, so we rate limit it to once an
+ // hour per LED.
+ auto now = std::chrono::steady_clock::now();
+
+ if (auto it = physicalLEDErrors.find(objPath);
+ it != physicalLEDErrors.end())
+ {
+ using namespace std::literals::chrono_literals;
+ if ((now - it->second) < 1h)
+ {
+ return -1;
+ }
+ }
+
lg2::error(
"Error setting property for physical LED, ERROR = {ERROR}, OBJECT_PATH = {PATH}",
"ERROR", e, "PATH", objPath);
+ physicalLEDErrors[objPath] = now;
return -1;
}