Implement a cap on the number of committed errors
Resolves openbmc/openbmc#1617
Change-Id: I5850e5addb723e6f5102eb4677bb365285c1a633
Signed-off-by: Marri Devender Rao <devenrao@in.ibm.com>
diff --git a/configure.ac b/configure.ac
index 977bcb0..5cc1c2e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -89,6 +89,10 @@
[AX_APPEND_COMPILE_FLAGS([-DPROCESS_META], [CXXFLAGS])]
)
+AC_ARG_VAR(ERROR_CAP, [Max number of error entries allowed for commit])
+AS_IF([test "x$ERROR_CAP" == "x"], [ERROR_CAP=100])
+AC_DEFINE_UNQUOTED([ERROR_CAP], [$ERROR_CAP], [Max number of error entries allowed for commit])
+
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([Makefile test/Makefile])
AC_CONFIG_FILES([phosphor-logging.pc])
diff --git a/log_manager.cpp b/log_manager.cpp
index 6ae59fd..29c0ffe 100644
--- a/log_manager.cpp
+++ b/log_manager.cpp
@@ -26,6 +26,19 @@
void Manager::commit(uint64_t transactionId, std::string errMsg)
{
+ if (capped)
+ {
+ return;
+ }
+ if (entries.size() >= ERROR_CAP)
+ {
+ log<level::ERR>("Reached error cap, Ignoring error",
+ entry("SIZE=%d", entries.size()),
+ entry("ERROR_CAP=%d", ERROR_CAP));
+ capped = true;
+ return;
+ }
+
constexpr const auto transactionIdVar = "TRANSACTION_ID";
// Length of 'TRANSACTION_ID' string.
constexpr const auto transactionIdVarSize = strlen(transactionIdVar);
@@ -194,6 +207,11 @@
entries.erase(entry);
}
+
+ if (entries.size() < ERROR_CAP)
+ {
+ capped = false;
+ }
}
void Manager::restore()
diff --git a/log_manager.hpp b/log_manager.hpp
index 730f63e..f366684 100644
--- a/log_manager.hpp
+++ b/log_manager.hpp
@@ -46,7 +46,8 @@
Manager(sdbusplus::bus::bus& bus, const char* objPath) :
details::ServerObject<details::ManagerIface>(bus, objPath),
busLog(bus),
- entryId(0) {};
+ entryId(0),
+ capped(false) {};
/*
* @fn commit()
@@ -91,6 +92,16 @@
/** @brief Id of last error log entry */
uint32_t entryId;
+
+ /**
+ * @brief Flag to log error for the first time when error cap is
+ * reached.
+ * @details Flag used to log error message for the first time when the
+ * error cap value is reached. It is reset when user delete's error
+ * entries and total entries existing is less than the error cap
+ * value.
+ */
+ bool capped;
};
} // namespace logging