summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-common/recipes-phosphor/interfaces/bmcweb/0027-EventService-Improvements-and-limitations.patch
blob: 23b8a429c709026b79c1ca80de467f83bd867a3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
From 1a848063c3a90dd0910a33e8d5d01ef6fd48fdd6 Mon Sep 17 00:00:00 2001
From: AppaRao Puli <apparao.puli@linux.intel.com>
Date: Fri, 2 Oct 2020 02:03:08 +0530
Subject: [PATCH] EventService: Improvements and limitations
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Below improvements are made for MetricReport event
format Types:
 - To reduce load on D-Bus, removed “GetAll” D-Bus
   method call. Use “PropertiesChanged” Signal
   instead of “ReportUpdated” signal
 - Optimize the getDateTime function call
 - Set the sublimit of 2 for MetricReport subscriptions.
 - Read ReportTimestamp from signal & fromat it.

Tested:
 - Stressed EventService along with Telemetry reports and
   it works fine.
 - Tried adding more than two MetricReport subscriptions
   and it returns error as expected.
 - Report timestamp works.

Change-Id: I58773ea4e25eb0c792c2c43b7450ef52f01996fa
Signed-off-by: AppaRao Puli <apparao.puli@linux.intel.com>
---
 http/utility.h                                 |  14 ++-
 redfish-core/include/event_service_manager.hpp | 116 +++++++++++++------------
 redfish-core/lib/event_service.hpp             |  17 ++++
 3 files changed, 83 insertions(+), 64 deletions(-)

diff --git a/http/utility.h b/http/utility.h
index 8254091..666c13e 100644
--- a/http/utility.h
+++ b/http/utility.h
@@ -775,18 +775,16 @@ inline void convertToLinks(std::string& s)
  */
 inline std::string getDateTime(const std::time_t& time)
 {
-    std::array<char, 128> dateTime;
-    std::string redfishDateTime("0000-00-00T00:00:00Z00:00");
+    std::array<char, sizeof("0000-00-00T00:00:00+00:00\0")> dateTime;
 
-    if (std::strftime(dateTime.begin(), dateTime.size(), "%FT%T%z",
-                      std::localtime(&time)))
+    size_t sz = std::strftime(dateTime.begin(), dateTime.size(), "%FT%T+00:00",
+                              std::gmtime(&time));
+    if (sz == 0 || sz > dateTime.size())
     {
-        // insert the colon required by the ISO 8601 standard
-        redfishDateTime = std::string(dateTime.data());
-        redfishDateTime.insert(redfishDateTime.end() - 2, ':');
+        return "";
     }
 
-    return redfishDateTime;
+    return std::string(dateTime.data(), sz);
 }
 
 inline std::string dateTimeNow()
diff --git a/redfish-core/include/event_service_manager.hpp b/redfish-core/include/event_service_manager.hpp
index 8397159..b503e2f 100644
--- a/redfish-core/include/event_service_manager.hpp
+++ b/redfish-core/include/event_service_manager.hpp
@@ -40,6 +40,7 @@ namespace redfish
 
 using ReadingsObjType =
     std::vector<std::tuple<std::string, std::string, double, int32_t>>;
+using ReadingsAndTimestamp = std::tuple<int32_t, ReadingsObjType>;
 using EventServiceConfig = std::tuple<bool, uint32_t, uint32_t>;
 
 static constexpr const char* eventFormatType = "Event";
@@ -1026,6 +1027,11 @@ class EventServiceManager
         return count;
     }
 
+    size_t getMetricReportSubscriptionsCount()
+    {
+        return noOfMetricReportSubscribers;
+    }
+
     std::vector<std::string> getAllIDs()
     {
         std::vector<std::string> idList;
@@ -1294,8 +1300,8 @@ class EventServiceManager
 
 #endif
 
-    void getMetricReading(const std::string& service,
-                          const std::string& objPath, const std::string& intf)
+    void getMetricReading(const std::string& objPath, const int32_t& reportTs,
+                          const ReadingsObjType& readings)
     {
         std::size_t found = objPath.find_last_of("/");
         if (found == std::string::npos)
@@ -1311,55 +1317,22 @@ class EventServiceManager
             return;
         }
 
-        crow::connections::systemBus->async_method_call(
-            [idStr{std::move(idStr)}](
-                const boost::system::error_code ec,
-                boost::container::flat_map<
-                    std::string, std::variant<int32_t, ReadingsObjType>>&
-                    resp) {
-                if (ec)
-                {
-                    BMCWEB_LOG_DEBUG
-                        << "D-Bus call failed to GetAll metric readings.";
-                    return;
-                }
-
-                const int32_t* timestampPtr =
-                    std::get_if<int32_t>(&resp["Timestamp"]);
-                if (!timestampPtr)
-                {
-                    BMCWEB_LOG_DEBUG << "Failed to Get timestamp.";
-                    return;
-                }
-
-                ReadingsObjType* readingsPtr =
-                    std::get_if<ReadingsObjType>(&resp["Readings"]);
-                if (!readingsPtr)
-                {
-                    BMCWEB_LOG_DEBUG << "Failed to Get Readings property.";
-                    return;
-                }
-
-                if (!readingsPtr->size())
-                {
-                    BMCWEB_LOG_DEBUG << "No metrics report to be transferred";
-                    return;
-                }
+        if (!readings.size())
+        {
+            BMCWEB_LOG_DEBUG << "No metrics in report to be transferred";
+            return;
+        }
 
-                for (const auto& it :
-                     EventServiceManager::getInstance().subscriptionsMap)
-                {
-                    std::shared_ptr<Subscription> entry = it.second;
-                    if (entry->eventFormatType == metricReportFormatType)
-                    {
-                        entry->filterAndSendReports(
-                            idStr, crow::utility::getDateTime(*timestampPtr),
-                            *readingsPtr);
-                    }
-                }
-            },
-            service, objPath, "org.freedesktop.DBus.Properties", "GetAll",
-            intf);
+        for (const auto& it :
+             EventServiceManager::getInstance().subscriptionsMap)
+        {
+            std::shared_ptr<Subscription> entry = it.second;
+            if (entry->eventFormatType == metricReportFormatType)
+            {
+                entry->filterAndSendReports(
+                    idStr, crow::utility::getDateTime(reportTs), readings);
+            }
+        }
     }
 
     void unregisterMetricReportSignal()
@@ -1382,22 +1355,53 @@ class EventServiceManager
 
         BMCWEB_LOG_DEBUG << "Metrics report signal - Register";
         std::string matchStr(
-            "type='signal',member='ReportUpdate', "
-            "interface='xyz.openbmc_project.MonitoringService.Report'");
+            "type='signal',member='PropertiesChanged',"
+            "sender='xyz.openbmc_project.MonitoringService',"
+            "interface='org.freedesktop.DBus.Properties',"
+            "path_namespace='/xyz/openbmc_project/MonitoringService/Reports/"
+            "TelemetryService',"
+            "arg0='xyz.openbmc_project.MonitoringService.Report'");
 
         matchTelemetryMonitor = std::make_shared<sdbusplus::bus::match::match>(
             *crow::connections::systemBus, matchStr,
             [this](sdbusplus::message::message& msg) {
                 if (msg.is_method_error())
                 {
-                    BMCWEB_LOG_ERROR << "TelemetryMonitor Signal error";
+                    BMCWEB_LOG_ERROR << "Received error in monitor signal";
                     return;
                 }
 
-                std::string service = msg.get_sender();
                 std::string objPath = msg.get_path();
-                std::string intf = msg.get_interface();
-                getMetricReading(service, objPath, intf);
+                std::string intf;
+                std::vector<
+                    std::pair<std::string, std::variant<ReadingsAndTimestamp>>>
+                    msgData;
+                msg.read(intf, msgData);
+
+                if (intf != "xyz.openbmc_project.MonitoringService.Report")
+                {
+                    BMCWEB_LOG_ERROR
+                        << "Received property from wrong interface";
+                    return;
+                }
+
+                const ReadingsAndTimestamp* dataPtr = nullptr;
+                for (const auto& [key, var] : msgData)
+                {
+                    if (key == "Readings")
+                    {
+                        dataPtr = std::get_if<ReadingsAndTimestamp>(&var);
+                        break;
+                    }
+                }
+                if (!dataPtr)
+                {
+                    BMCWEB_LOG_ERROR << "Failed to get readings from signal";
+                    return;
+                }
+
+                const auto& [timestamp, readings] = *dataPtr;
+                getMetricReading(objPath, timestamp, readings);
             });
     }
 
diff --git a/redfish-core/lib/event_service.hpp b/redfish-core/lib/event_service.hpp
index 40758e7..c3addca 100644
--- a/redfish-core/lib/event_service.hpp
+++ b/redfish-core/lib/event_service.hpp
@@ -28,6 +28,7 @@ static constexpr const std::array<const char*, 3> supportedRetryPolicies = {
 
 static constexpr const uint8_t maxNoOfSubscriptions = 20;
 static constexpr const uint8_t maxNoOfSSESubscriptions = 10;
+static constexpr const uint8_t maxNoOfMetricReportSubscriptions = 2;
 
 class EventService : public Node
 {
@@ -253,6 +254,22 @@ class EventDestinationCollection : public Node
             }
         }
 
+        if (eventFormatType)
+        {
+            if (*eventFormatType == metricReportFormatType)
+            {
+                if (EventServiceManager::getInstance()
+                        .getMetricReportSubscriptionsCount() >=
+                    maxNoOfMetricReportSubscriptions)
+                {
+                    BMCWEB_LOG_ERROR
+                        << "Max metric report subscription limit reached";
+                    messages::eventSubscriptionLimitExceeded(asyncResp->res);
+                    return;
+                }
+            }
+        }
+
         // Validate the URL using regex expression
         // Format: <protocol>://<host>:<port>/<uri>
         // protocol: http/https
-- 
2.7.4