summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-common/recipes-phosphor/interfaces/bmcweb/telemetry/0002-Sync-Telmetry-service-with-EventService.patch
blob: d32c85356bf03b34b45d9422b58b4c2170552c13 (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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
From 77e8a0b5037a555b1520823b667595ac8780c675 Mon Sep 17 00:00:00 2001
From: "Wludzik, Jozef" <jozef.wludzik@intel.com>
Date: Tue, 15 Dec 2020 12:30:31 +0100
Subject: [PATCH] Sync Telmetry service with EventService

Synced the latest changes in Telemetry service with Event Service
code. Now assembling MetricReport is covered in single place in
code. Updated method of fetching Readings from Telemetry by
Event Service. Using ReportUpdate signal is no longer
supported. Now Event Service monitors for PropertiesChanged signal
from /xyz/openbmc_project/Telemetry/Reports path.

Tested:
 - Verified that EventListener received MetricReport response from
   Event Service in insecure http push style eventing mode

Change-Id: I2fc1841a6c9259a8bff30b34bddc0d4aabd41912
Signed-off-by: Wludzik, Jozef <jozef.wludzik@intel.com>
---
 .../include/event_service_manager.hpp         | 156 ++++++------------
 redfish-core/lib/metric_report.hpp            |  28 ++--
 2 files changed, 69 insertions(+), 115 deletions(-)

diff --git a/redfish-core/include/event_service_manager.hpp b/redfish-core/include/event_service_manager.hpp
index d89b789..4faaddd 100644
--- a/redfish-core/include/event_service_manager.hpp
+++ b/redfish-core/include/event_service_manager.hpp
@@ -14,6 +14,7 @@
 // limitations under the License.
 */
 #pragma once
+#include "metric_report.hpp"
 #include "registries.hpp"
 #include "registries/base_message_registry.hpp"
 #include "registries/openbmc_message_registry.hpp"
@@ -511,47 +512,32 @@ class Subscription : public persistent_data::UserSubscription
     }
 #endif
 
-    void filterAndSendReports(const std::string& id2,
-                              const std::string& readingsTs,
-                              const ReadingsObjType& readings)
+    void filterAndSendReports(
+        const std::string& id,
+        const std::variant<telemetry::TimestampReadings>& var)
     {
-        std::string metricReportDef =
-            "/redfish/v1/TelemetryService/MetricReportDefinitions/" + id2;
+        std::string mrdUri = telemetry::metricReportDefinitionUri + id;
 
         // Empty list means no filter. Send everything.
         if (metricReportDefinitions.size())
         {
             if (std::find(metricReportDefinitions.begin(),
                           metricReportDefinitions.end(),
-                          metricReportDef) == metricReportDefinitions.end())
+                          mrdUri) == metricReportDefinitions.end())
             {
                 return;
             }
         }
 
-        nlohmann::json metricValuesArray = nlohmann::json::array();
-        for (const auto& it : readings)
+        nlohmann::json msg;
+        if (!telemetry::fillReport(msg, id, var))
         {
-            metricValuesArray.push_back({});
-            nlohmann::json& entry = metricValuesArray.back();
-
-            auto& [id, property, value, timestamp] = it;
-
-            entry = {{"MetricId", id},
-                     {"MetricProperty", property},
-                     {"MetricValue", std::to_string(value)},
-                     {"Timestamp", crow::utility::getDateTime(timestamp)}};
+            BMCWEB_LOG_ERROR << "Failed to fill the MetricReport for DBus "
+                                "Report with id "
+                             << id;
+            return;
         }
 
-        nlohmann::json msg = {
-            {"@odata.id", "/redfish/v1/TelemetryService/MetricReports/" + id},
-            {"@odata.type", "#MetricReport.v1_3_0.MetricReport"},
-            {"Id", id2},
-            {"Name", id2},
-            {"Timestamp", readingsTs},
-            {"MetricReportDefinition", {{"@odata.id", metricReportDef}}},
-            {"MetricValues", metricValuesArray}};
-
         this->sendEvent(
             msg.dump(2, ' ', true, nlohmann::json::error_handler_t::replace));
     }
@@ -1317,75 +1303,6 @@ class EventServiceManager
     }
 
 #endif
-
-    void getMetricReading(const std::string& service,
-                          const std::string& objPath, const std::string& intf)
-    {
-        std::size_t found = objPath.find_last_of('/');
-        if (found == std::string::npos)
-        {
-            BMCWEB_LOG_DEBUG << "Invalid objPath received";
-            return;
-        }
-
-        std::string idStr = objPath.substr(found + 1);
-        if (idStr.empty())
-        {
-            BMCWEB_LOG_DEBUG << "Invalid ID in objPath";
-            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;
-                }
-
-                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);
-    }
-
     void unregisterMetricReportSignal()
     {
         if (matchTelemetryMonitor)
@@ -1405,9 +1322,11 @@ class EventServiceManager
         }
 
         BMCWEB_LOG_DEBUG << "Metrics report signal - Register";
-        std::string matchStr(
-            "type='signal',member='ReportUpdate', "
-            "interface='xyz.openbmc_project.MonitoringService.Report'");
+        std::string matchStr = "type='signal',member='PropertiesChanged',"
+                               "interface='org.freedesktop.DBus.Properties',"
+                               "path_namespace=/xyz/openbmc_project/Telemetry/"
+                               "Reports/TelemetryService,"
+                               "arg0=xyz.openbmc_project.Telemetry.Report";
 
         matchTelemetryMonitor = std::make_shared<sdbusplus::bus::match::match>(
             *crow::connections::systemBus, matchStr,
@@ -1418,10 +1337,43 @@ class EventServiceManager
                     return;
                 }
 
-                std::string service = msg.get_sender();
-                std::string objPath = msg.get_path();
-                std::string intf = msg.get_interface();
-                getMetricReading(service, objPath, intf);
+                sdbusplus::message::object_path path(msg.get_path());
+                std::string id = path.filename();
+                if (id.empty())
+                {
+                    BMCWEB_LOG_ERROR << "Failed to get Id from path";
+                    return;
+                }
+
+                std::string intf;
+                std::vector<std::pair<
+                    std::string, std::variant<telemetry::TimestampReadings>>>
+                    props;
+                std::vector<std::string> invalidProps;
+                msg.read(intf, props, invalidProps);
+
+                auto found =
+                    std::find_if(props.begin(), props.end(), [](const auto& x) {
+                        return x.first == "Readings";
+                    });
+                if (found == props.end())
+                {
+                    BMCWEB_LOG_ERROR
+                        << "Failed to get Readings from Report properties";
+                    return;
+                }
+
+                std::variant<telemetry::TimestampReadings>& readings =
+                    found->second;
+                for (const auto& it :
+                     EventServiceManager::getInstance().subscriptionsMap)
+                {
+                    Subscription& entry = *it.second.get();
+                    if (entry.eventFormatType == metricReportFormatType)
+                    {
+                        entry.filterAndSendReports(id, readings);
+                    }
+                }
             });
     }
 
diff --git a/redfish-core/lib/metric_report.hpp b/redfish-core/lib/metric_report.hpp
index 63c8c19..7fe281d 100644
--- a/redfish-core/lib/metric_report.hpp
+++ b/redfish-core/lib/metric_report.hpp
@@ -33,16 +33,14 @@ inline nlohmann::json toMetricValues(const Readings& readings)
     return metricValues;
 }
 
-inline void fillReport(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
-                       const std::string& id,
+inline bool fillReport(nlohmann::json& json, const std::string& id,
                        const std::variant<TimestampReadings>& var)
 {
-    asyncResp->res.jsonValue["@odata.type"] =
-        "#MetricReport.v1_3_0.MetricReport";
-    asyncResp->res.jsonValue["@odata.id"] = telemetry::metricReportUri + id;
-    asyncResp->res.jsonValue["Id"] = id;
-    asyncResp->res.jsonValue["Name"] = id;
-    asyncResp->res.jsonValue["MetricReportDefinition"]["@odata.id"] =
+    json["@odata.type"] = "#MetricReport.v1_3_0.MetricReport";
+    json["@odata.id"] = telemetry::metricReportUri + id;
+    json["Id"] = id;
+    json["Name"] = id;
+    json["MetricReportDefinition"]["@odata.id"] =
         telemetry::metricReportDefinitionUri + id;
 
     const TimestampReadings* timestampReadings =
@@ -50,14 +48,14 @@ inline void fillReport(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
     if (!timestampReadings)
     {
         BMCWEB_LOG_ERROR << "Property type mismatch or property is missing";
-        messages::internalError(asyncResp->res);
-        return;
+        return false;
     }
 
     const auto& [timestamp, readings] = *timestampReadings;
-    asyncResp->res.jsonValue["Timestamp"] =
+    json["Timestamp"] =
         crow::utility::getDateTime(static_cast<time_t>(timestamp));
-    asyncResp->res.jsonValue["MetricValues"] = toMetricValues(readings);
+    json["MetricValues"] = toMetricValues(readings);
+    return true;
 }
 } // namespace telemetry
 
@@ -118,7 +116,11 @@ inline void requestRoutesMetricReport(App& app)
                                     return;
                                 }
 
-                                telemetry::fillReport(asyncResp, id, ret);
+                                if (!telemetry::fillReport(
+                                        asyncResp->res.jsonValue, id, ret))
+                                {
+                                    messages::internalError(asyncResp->res);
+                                }
                             },
                             telemetry::service, reportPath,
                             "org.freedesktop.DBus.Properties", "Get",
-- 
2.25.1