summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-common/recipes-phosphor/interfaces/bmcweb/telemetry/0008-Generalize-ReadingType-in-MetricDefinition.patch
blob: bd6e643464d4bf411256319d89d9f3249676b6b0 (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
From d9baec3ccdff5ed4d1620f374a252c769de5b45b Mon Sep 17 00:00:00 2001
From: Krzysztof Grobelny <krzysztof.grobelny@intel.com>
Date: Thu, 19 Aug 2021 10:55:38 +0000
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 | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/redfish-core/lib/metric_definition.hpp b/redfish-core/lib/metric_definition.hpp
index 019168b..df29b65 100644
--- a/redfish-core/lib/metric_definition.hpp
+++ b/redfish-core/lib/metric_definition.hpp
@@ -33,6 +33,18 @@ bool containsOdata(const nlohmann::json& json, const std::string& odataId)
     return it != json.end();
 }
 
+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)
 {
@@ -52,8 +64,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);
 
         if (!containsOdata(members, odataId))
         {
@@ -149,15 +160,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;
@@ -168,7 +179,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 =
@@ -179,7 +190,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);
             }
-- 
2.25.1