Fix: MetricReportDefinitions filter not working
The metric reports are not sending when user configures
the MetricReportDefinitions filter. This is of odata json
object type. Corrected code to properly handle odata type
object and store it as string array to make filters faster.
Tested:
- Created metric report EventService subscription type
with MetricReportDefinitions and events properly sent to
Event listener.
Signed-off-by: AppaRao Puli <apparao.puli@linux.intel.com>
Change-Id: If96564219da7d38a2ee5e415b89824ba25cd686d
diff --git a/redfish-core/include/event_service_manager.hpp b/redfish-core/include/event_service_manager.hpp
index f3f9f39..9220a28 100644
--- a/redfish-core/include/event_service_manager.hpp
+++ b/redfish-core/include/event_service_manager.hpp
@@ -283,7 +283,7 @@
bool readSSEQueryParams(std::string sseFilter, std::string& formatType,
std::vector<std::string>& messageIds,
std::vector<std::string>& registryPrefixes,
- std::vector<nlohmann::json>& metricReportDefinitions)
+ std::vector<std::string>& metricReportDefinitions)
{
sseFilter.erase(std::remove_if(sseFilter.begin(), sseFilter.end(),
isFilterQuerySpecialChar),
@@ -370,7 +370,7 @@
std::vector<std::string> registryPrefixes;
std::vector<std::string> resourceTypes;
std::vector<nlohmann::json> httpHeaders; // key-value pair
- std::vector<nlohmann::json> metricReportDefinitions;
+ std::vector<std::string> metricReportDefinitions;
Subscription(const Subscription&) = delete;
Subscription& operator=(const Subscription&) = delete;
diff --git a/redfish-core/lib/event_service.hpp b/redfish-core/lib/event_service.hpp
index 4d9d4d9..b532815 100644
--- a/redfish-core/lib/event_service.hpp
+++ b/redfish-core/lib/event_service.hpp
@@ -239,7 +239,7 @@
std::optional<std::vector<std::string>> regPrefixes;
std::optional<std::vector<std::string>> resTypes;
std::optional<std::vector<nlohmann::json>> headers;
- std::optional<std::vector<nlohmann::json>> metricReportDefinitions;
+ std::optional<std::vector<nlohmann::json>> mrdJsonArray;
if (!json_util::readJson(
req, res, "Destination", destUrl, "Context", context,
@@ -247,7 +247,7 @@
"EventFormatType", eventFormatType, "HttpHeaders", headers,
"RegistryPrefixes", regPrefixes, "MessageIds", msgIds,
"DeliveryRetryPolicy", retryPolicy, "MetricReportDefinitions",
- metricReportDefinitions, "ResourceTypes", resTypes))
+ mrdJsonArray, "ResourceTypes", resTypes))
{
return;
}
@@ -413,9 +413,24 @@
subValue->retryPolicy = "TerminateAfterRetries";
}
- if (metricReportDefinitions)
+ if (mrdJsonArray)
{
- subValue->metricReportDefinitions = *metricReportDefinitions;
+ for (nlohmann::json& mrdObj : *mrdJsonArray)
+ {
+ std::string mrdUri;
+ if (json_util::getValueFromJsonObject(mrdObj, "@odata.id",
+ mrdUri))
+ {
+ subValue->metricReportDefinitions.emplace_back(mrdUri);
+ }
+ else
+ {
+ messages::propertyValueFormatError(
+ asyncResp->res, mrdObj.dump(),
+ "MetricReportDefinitions");
+ return;
+ }
+ }
}
std::string id =
@@ -593,8 +608,13 @@
asyncResp->res.jsonValue["MessageIds"] = subValue->registryMsgIds;
asyncResp->res.jsonValue["DeliveryRetryPolicy"] = subValue->retryPolicy;
- asyncResp->res.jsonValue["MetricReportDefinitions"] =
- subValue->metricReportDefinitions;
+
+ std::vector<nlohmann::json> mrdJsonArray;
+ for (const auto& mdrUri : subValue->metricReportDefinitions)
+ {
+ mrdJsonArray.push_back({{"@odata.id", mdrUri}});
+ }
+ asyncResp->res.jsonValue["MetricReportDefinitions"] = mrdJsonArray;
}
void doPatch(crow::Response& res, const crow::Request& req,