summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-common/recipes-phosphor/interfaces/bmcweb/telemetry/0007-Generalize-ReadingType-in-MetricDefinition.patch
blob: 1cdd59d4b0733e7d4fea9f72ec5282b5f214a31f (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
From 872a7bdb9c272944914d7c5babc751e6bb33afec Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adrian=20Ambro=C5=BCewicz?= <adrian.ambrozewicz@intel.com>
Date: Tue, 3 Aug 2021 13:59:31 +0200
Subject: [PATCH] Generalize ReadingType  in MetricDefinition

Recent addition of PMT required adding new type of sensor 'count', which
doesnt comply with any of Redfish-defined Sensor.ReadingType values.

To support property of this kind MetricDefinition implementation was
altered to support sensor types not covered by Redfish types by
a 'fallback' to direct usage of sensor type. Populating 'Units' was also
modified, so it won't be shown if value does not have any units mapped.

Testing:
- PMT counters are shown properly in MetricDefinitions/Count
- Redfish Validator passes
---
 redfish-core/lib/metric_definition.hpp | 63 ++++++++++++++++----------
 1 file changed, 39 insertions(+), 24 deletions(-)

diff --git a/redfish-core/lib/metric_definition.hpp b/redfish-core/lib/metric_definition.hpp
index 2443996..fcab44d 100644
--- a/redfish-core/lib/metric_definition.hpp
+++ b/redfish-core/lib/metric_definition.hpp
@@ -11,6 +11,18 @@ namespace redfish
 namespace telemetry
 {
 
+std::string groupName(const std::string& sensorType)
+{
+    std::string group = sensors::toReadingType(sensorType);
+    if (group.empty())
+    {
+        // Fallback for types not covered by standard Redfish Sensor.ReadingType
+        group = sensorType;
+        group[0] = static_cast<char>(std::toupper(group[0]));
+    }
+    return group;
+}
+
 void addMembers(crow::Response& res,
                 const boost::container::flat_map<std::string, std::string>& el)
 {
@@ -30,8 +42,7 @@ void addMembers(crow::Response& res,
         nlohmann::json& members = res.jsonValue["Members"];
 
         const std::string odataId =
-            std::string(telemetry::metricDefinitionUri) +
-            sensors::toReadingType(type);
+            std::string(telemetry::metricDefinitionUri) + groupName(type);
 
         const auto it = std::find_if(members.begin(), members.end(),
                                      [&odataId](const nlohmann::json& item) {
@@ -125,15 +136,15 @@ inline void requestRoutesMetricDefinitionCollection(App& app)
 namespace telemetry
 {
 
-bool isSensorIdSupported(std::string_view readingType)
+bool isSensorIdSupported(std::string_view group)
 {
     for (const std::pair<std::string_view, std::vector<const char*>>&
              typeToPaths : sensors::dbus::paths)
     {
         for (const char* supportedPath : typeToPaths.second)
         {
-            if (readingType ==
-                sensors::toReadingType(
+            if (group ==
+                groupName(
                     sdbusplus::message::object_path(supportedPath).filename()))
             {
                 return true;
@@ -144,7 +155,7 @@ bool isSensorIdSupported(std::string_view readingType)
 }
 
 void addMetricProperty(
-    bmcweb::AsyncResp& asyncResp, const std::string& readingType,
+    bmcweb::AsyncResp& asyncResp, const std::string& group,
     const boost::container::flat_map<std::string, std::string>& el)
 {
     nlohmann::json& metricProperties =
@@ -155,7 +166,7 @@ void addMetricProperty(
         std::string sensorId;
         if (dbus::utility::getNthStringFromPath(dbusSensor, 3, sensorId))
         {
-            if (sensors::toReadingType(sensorId) == readingType)
+            if (groupName(sensorId) == group)
             {
                 metricProperties.push_back(redfishSensor);
             }
@@ -172,33 +183,37 @@ inline void requestRoutesMetricDefinition(App& app)
         .methods(boost::beast::http::verb::get)(
             [](const crow::Request&,
                const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
-               const std::string& readingType) {
-                if (!telemetry::isSensorIdSupported(readingType))
+               const std::string& group) {
+                if (!telemetry::isSensorIdSupported(group))
                 {
                     messages::resourceNotFound(asyncResp->res,
-                                               "MetricDefinition", readingType);
+                                               "MetricDefinition", group);
                     return;
                 }
 
                 asyncResp->res.jsonValue["MetricProperties"] =
                     nlohmann::json::array();
-                asyncResp->res.jsonValue["Id"] = readingType;
-                asyncResp->res.jsonValue["Name"] = readingType;
+                asyncResp->res.jsonValue["Id"] = group;
+                asyncResp->res.jsonValue["Name"] = group;
                 asyncResp->res.jsonValue["@odata.id"] =
-                    telemetry::metricDefinitionUri + readingType;
+                    telemetry::metricDefinitionUri + group;
                 asyncResp->res.jsonValue["@odata.type"] =
                     "#MetricDefinition.v1_0_3.MetricDefinition";
                 asyncResp->res.jsonValue["MetricDataType"] = "Decimal";
                 asyncResp->res.jsonValue["MetricType"] = "Numeric";
                 asyncResp->res.jsonValue["IsLinear"] = true;
                 asyncResp->res.jsonValue["Implementation"] = "PhysicalSensor";
-                asyncResp->res.jsonValue["Units"] =
-                    sensors::toReadingUnits(readingType);
+
+                std::string readingUnits = sensors::toReadingUnits(group);
+                if (!readingUnits.empty())
+                {
+                    asyncResp->res.jsonValue["Units"] = readingUnits;
+                }
 
                 utils::getChassisNames(
-                    [asyncResp, readingType](
-                        boost::system::error_code ec,
-                        const std::vector<std::string>& chassisNames) {
+                    [asyncResp,
+                     group](boost::system::error_code ec,
+                            const std::vector<std::string>& chassisNames) {
                         if (ec)
                         {
                             messages::internalError(asyncResp->res);
@@ -208,10 +223,10 @@ inline void requestRoutesMetricDefinition(App& app)
                         }
 
                         auto handleRetrieveUriToDbusMap =
-                            [asyncResp, readingType](
-                                const boost::beast::http::status status,
-                                const boost::container::flat_map<
-                                    std::string, std::string>& uriToDbus) {
+                            [asyncResp,
+                             group](const boost::beast::http::status status,
+                                    const boost::container::flat_map<
+                                        std::string, std::string>& uriToDbus) {
                                 if (status != boost::beast::http::status::ok)
                                 {
                                     BMCWEB_LOG_ERROR
@@ -221,8 +236,8 @@ inline void requestRoutesMetricDefinition(App& app)
                                     messages::internalError(asyncResp->res);
                                     return;
                                 }
-                                telemetry::addMetricProperty(
-                                    *asyncResp, readingType, uriToDbus);
+                                telemetry::addMetricProperty(*asyncResp, group,
+                                                             uriToDbus);
                             };
 
                         for (const std::string& chassisName : chassisNames)
-- 
2.25.1