Don't store LogEntry IDs across requests

Because the previous timestamp is stored across Entries requests,
a single entry will increment the ID on every refresh since the
previous timestamp will always match.

This change clears the previous timestamp on the first entry of
each request.

Tested:
Refreshed a single LogEntry many times and confirmed that the ID
does not change.

Change-Id: I8bf81b6c2eb6ac4037a17008ba54ebfccb42e0dd
Signed-off-by: Jason M. Bills <jason.m.bills@linux.intel.com>
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index c74bfa2..94496a1 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -257,11 +257,17 @@
     return true;
 }
 
-static bool getUniqueEntryID(sd_journal *journal, std::string &entryID)
+static bool getUniqueEntryID(sd_journal *journal, std::string &entryID,
+                             const bool firstEntry = true)
 {
     int ret = 0;
     static uint64_t prevTs = 0;
     static int index = 0;
+    if (firstEntry)
+    {
+        prevTs = 0;
+    }
+
     // Get the entry timestamp
     uint64_t curTs = 0;
     ret = sd_journal_get_realtime_usec(journal, &curTs);
@@ -292,10 +298,16 @@
     return true;
 }
 
-static bool getUniqueEntryID(const std::string &logEntry, std::string &entryID)
+static bool getUniqueEntryID(const std::string &logEntry, std::string &entryID,
+                             const bool firstEntry = true)
 {
     static uint64_t prevTs = 0;
     static int index = 0;
+    if (firstEntry)
+    {
+        prevTs = 0;
+    }
+
     // Get the entry timestamp
     uint64_t curTs = 0;
     std::tm timeStruct = {};
@@ -713,6 +725,8 @@
                 continue;
             }
 
+            // Reset the unique ID on the first entry
+            bool firstEntry = true;
             while (std::getline(logStream, logEntry))
             {
                 entryCount++;
@@ -724,11 +738,16 @@
                 }
 
                 std::string idStr;
-                if (!getUniqueEntryID(logEntry, idStr))
+                if (!getUniqueEntryID(logEntry, idStr, firstEntry))
                 {
                     continue;
                 }
 
+                if (firstEntry)
+                {
+                    firstEntry = false;
+                }
+
                 logEntryArray.push_back({});
                 nlohmann::json &bmcLogEntry = logEntryArray.back();
                 if (fillEventLogEntryJson(idStr, logEntry, bmcLogEntry) != 0)
@@ -1250,6 +1269,8 @@
             journalTmp, sd_journal_close);
         journalTmp = nullptr;
         uint64_t entryCount = 0;
+        // Reset the unique ID on the first entry
+        bool firstEntry = true;
         SD_JOURNAL_FOREACH(journal.get())
         {
             entryCount++;
@@ -1261,11 +1282,16 @@
             }
 
             std::string idStr;
-            if (!getUniqueEntryID(journal.get(), idStr))
+            if (!getUniqueEntryID(journal.get(), idStr, firstEntry))
             {
                 continue;
             }
 
+            if (firstEntry)
+            {
+                firstEntry = false;
+            }
+
             logEntryArray.push_back({});
             nlohmann::json &bmcJournalLogEntry = logEntryArray.back();
             if (fillBMCJournalLogEntryJson(idStr, journal.get(),