Fix issues in MRD patch requests
After commit [1] 'null' value was being rejected with
[json_utils.hpp] Value for key Metrics was incorrect type: null
Using 'null' here seems to be one of the cases that [2] describes
Commit [3] fixed an issue where {} replaced "MetricProperties" of
a metric with an empty array but introduced a different one
- trying to replace a metric caused new values in "MetricProperties"
to get added to old ones.
if (metric.find("MetricProperties") == metric.end()) check was initially
present in [4] but got removed at some point,
re-adding it fixes the issue
Tested:
Patch request to [5] with body: {"Metrics": [null]} no longer fails
and deletes a metric
Patch request with {"Metrics": [{}]} leaves metric unchanged
Patch request with
{"Metrics": [{"MetricProperties": ["<path_to_sensor>"]}]}
updates metric properly,
without appending to old "MetricProperties" values
Patch requests containing mixed values also work correctly
[1]: b14f357f527eae05aa1bd7a115d3f6ed237a35bb
[2]: 8099c51796bf6f94ad5fbb1f6844d700f498d3bb
[3]: ba498310f761b3c0f475ecbdb293cf1386544a33
[4]: https://gerrit.openbmc.org/c/openbmc/bmcweb/+/72319
[5]: https://<bmcip>/redfish/v1/TelemetryService/MetricReportDefinitions/<existing_mrd_name>
Change-Id: Ia3d4699784f493bd63a2df4d6edf5053760221e1
Signed-off-by: Boleslaw Ogonczyk Makowski <boleslawx.ogonczyk-makowski@intel.com>
diff --git a/redfish-core/lib/metric_report_definition.hpp b/redfish-core/lib/metric_report_definition.hpp
index 9a6b25e..5006936 100644
--- a/redfish-core/lib/metric_report_definition.hpp
+++ b/redfish-core/lib/metric_report_definition.hpp
@@ -1190,7 +1190,8 @@
inline void setReportMetrics(
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, std::string_view id,
- std::vector<nlohmann::json::object_t>&& metrics)
+ std::vector<std::variant<nlohmann::json::object_t, std::nullptr_t>>&&
+ metrics)
{
dbus::utility::getAllProperties(
telemetry::service, telemetry::getDbusReportPath(id),
@@ -1222,8 +1223,17 @@
chassisSensors;
size_t index = 0;
- for (nlohmann::json::object_t& metric : redfishMetrics)
+ for (std::variant<nlohmann::json::object_t, std::nullptr_t>&
+ metricVariant : redfishMetrics)
{
+ nlohmann::json::object_t* metric =
+ std::get_if<nlohmann::json::object_t>(&metricVariant);
+ if (metric == nullptr)
+ {
+ index++;
+ continue;
+ }
+
AddReportArgs::MetricArgs metricArgs;
std::vector<
std::tuple<sdbusplus::message::object_path, std::string>>
@@ -1240,7 +1250,7 @@
metricArgs.collectionDuration = std::get<3>(existing);
}
- if (!getUserMetric(asyncResp->res, metric, metricArgs))
+ if (!getUserMetric(asyncResp->res, *metric, metricArgs))
{
return;
}
@@ -1332,7 +1342,9 @@
std::optional<std::string> reportingTypeStr;
std::optional<std::string> reportUpdatesStr;
std::optional<bool> metricReportDefinitionEnabled;
- std::optional<std::vector<nlohmann::json::object_t>> metrics;
+ std::optional<
+ std::vector<std::variant<nlohmann::json::object_t, std::nullptr_t>>>
+ metrics;
std::optional<std::vector<std::string>> reportActionsStr;
std::optional<std::string> scheduleDurationStr;