Krzysztof Grobelny | 64b75a5 | 2020-09-18 10:17:16 +0200 | [diff] [blame] | 1 | #include "report_manager.hpp" |
| 2 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 3 | #include "report.hpp" |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 4 | #include "types/report_types.hpp" |
Krzysztof Grobelny | e8fc575 | 2021-02-05 14:30:45 +0000 | [diff] [blame] | 5 | #include "utils/conversion.hpp" |
Szymon Dompke | 32305f1 | 2022-07-05 15:37:21 +0200 | [diff] [blame] | 6 | #include "utils/dbus_path_utils.hpp" |
| 7 | #include "utils/make_id_name.hpp" |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 8 | #include "utils/transform.hpp" |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 9 | |
| 10 | #include <phosphor-logging/log.hpp> |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 11 | #include <sdbusplus/exception.hpp> |
| 12 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 13 | #include <stdexcept> |
Krzysztof Grobelny | 64b75a5 | 2020-09-18 10:17:16 +0200 | [diff] [blame] | 14 | #include <system_error> |
| 15 | |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 16 | ReadingParameters |
| 17 | convertToReadingParameters(ReadingParametersPastVersion params) |
| 18 | { |
| 19 | return utils::transform(params, [](const auto& param) { |
| 20 | using namespace std::chrono_literals; |
| 21 | |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 22 | const auto& [sensorPath, operationType, id, metadata] = param; |
| 23 | |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 24 | return ReadingParameters::value_type( |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 25 | std::vector< |
| 26 | std::tuple<sdbusplus::message::object_path, std::string>>{ |
| 27 | {sensorPath, metadata}}, |
| 28 | operationType, id, utils::enumToString(CollectionTimeScope::point), |
| 29 | 0u); |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 30 | }); |
| 31 | } |
| 32 | |
Krzysztof Grobelny | 64b75a5 | 2020-09-18 10:17:16 +0200 | [diff] [blame] | 33 | ReportManager::ReportManager( |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 34 | std::unique_ptr<interfaces::ReportFactory> reportFactoryIn, |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 35 | std::unique_ptr<interfaces::JsonStorage> reportStorageIn, |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 36 | const std::shared_ptr<sdbusplus::asio::object_server>& objServerIn) : |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 37 | reportFactory(std::move(reportFactoryIn)), |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 38 | reportStorage(std::move(reportStorageIn)), objServer(objServerIn) |
Krzysztof Grobelny | 64b75a5 | 2020-09-18 10:17:16 +0200 | [diff] [blame] | 39 | { |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 40 | reports.reserve(maxReports); |
Krzysztof Grobelny | 6ccfcbf | 2020-11-04 09:31:36 +0100 | [diff] [blame] | 41 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 42 | loadFromPersistent(); |
Krzysztof Grobelny | 64b75a5 | 2020-09-18 10:17:16 +0200 | [diff] [blame] | 43 | |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 44 | reportManagerIface = objServer->add_unique_interface( |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 45 | reportManagerPath, reportManagerIfaceName, [this](auto& dbusIface) { |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 46 | dbusIface.register_property_r( |
Wludzik, Jozef | 503c158 | 2020-12-11 14:48:01 +0100 | [diff] [blame] | 47 | "MaxReports", size_t{}, sdbusplus::vtable::property_::const_, |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 48 | [](const auto&) { return maxReports; }); |
| 49 | dbusIface.register_property_r( |
| 50 | "MinInterval", uint64_t{}, sdbusplus::vtable::property_::const_, |
| 51 | [](const auto&) -> uint64_t { return minInterval.count(); }); |
Krzysztof Grobelny | 60fee07 | 2022-01-13 16:25:04 +0100 | [diff] [blame] | 52 | dbusIface.register_property_r( |
| 53 | "SupportedOperationTypes", std::vector<std::string>{}, |
| 54 | sdbusplus::vtable::property_::const_, |
| 55 | [](const auto&) -> std::vector<std::string> { |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 56 | return utils::transform<std::vector>( |
Krzysztof Grobelny | 60fee07 | 2022-01-13 16:25:04 +0100 | [diff] [blame] | 57 | utils::convDataOperationType, [](const auto& item) { |
| 58 | return std::string(item.first); |
| 59 | }); |
| 60 | }); |
Krzysztof Grobelny | 64b75a5 | 2020-09-18 10:17:16 +0200 | [diff] [blame] | 61 | |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 62 | dbusIface.register_method( |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 63 | "AddReport", [this](boost::asio::yield_context& yield, |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 64 | const std::string& reportId, |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 65 | const std::string& reportingType, |
| 66 | const bool emitsReadingsUpdate, |
| 67 | const bool logToMetricReportsCollection, |
| 68 | const uint64_t interval, |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 69 | ReadingParametersPastVersion metricParams) { |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 70 | constexpr auto enabledDefault = true; |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 71 | constexpr uint64_t appendLimitDefault = 0; |
| 72 | constexpr ReportUpdates reportUpdatesDefault = |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 73 | ReportUpdates::overwrite; |
| 74 | |
| 75 | std::vector<ReportAction> reportActions; |
| 76 | |
| 77 | if (emitsReadingsUpdate) |
| 78 | { |
| 79 | reportActions.emplace_back( |
| 80 | ReportAction::emitsReadingsUpdate); |
| 81 | } |
| 82 | if (logToMetricReportsCollection) |
| 83 | { |
| 84 | reportActions.emplace_back( |
| 85 | ReportAction::logToMetricReportsCollection); |
| 86 | } |
| 87 | |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 88 | return addReport(yield, reportId, reportId, |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 89 | utils::toReportingType(reportingType), |
| 90 | reportActions, Milliseconds(interval), |
| 91 | appendLimitDefault, reportUpdatesDefault, |
| 92 | convertToReadingParameters( |
| 93 | std::move(metricParams)), |
| 94 | enabledDefault) |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 95 | .getPath(); |
| 96 | }); |
| 97 | |
| 98 | dbusIface.register_method( |
| 99 | "AddReportFutureVersion", |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 100 | [this]( |
| 101 | boost::asio::yield_context& yield, |
| 102 | const std::string& reportId, const std::string& reportName, |
| 103 | const std::string& reportingType, |
| 104 | const std::string& reportUpdates, |
| 105 | const uint64_t appendLimit, |
| 106 | const std::vector<std::string>& reportActions, |
| 107 | const uint64_t interval, ReadingParameters metricParams) { |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 108 | constexpr auto enabledDefault = true; |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 109 | return addReport(yield, reportId, reportName, |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 110 | utils::toReportingType(reportingType), |
| 111 | utils::transform( |
| 112 | reportActions, |
| 113 | [](const auto& reportAction) { |
| 114 | return utils::toReportAction( |
| 115 | reportAction); |
| 116 | }), |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 117 | Milliseconds(interval), appendLimit, |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 118 | utils::toReportUpdates(reportUpdates), |
| 119 | std::move(metricParams), enabledDefault) |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 120 | .getPath(); |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 121 | }); |
| 122 | }); |
Krzysztof Grobelny | 64b75a5 | 2020-09-18 10:17:16 +0200 | [diff] [blame] | 123 | } |
| 124 | |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 125 | void ReportManager::removeReport(const interfaces::Report* report) |
Krzysztof Grobelny | 64b75a5 | 2020-09-18 10:17:16 +0200 | [diff] [blame] | 126 | { |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 127 | reports.erase( |
| 128 | std::remove_if(reports.begin(), reports.end(), |
| 129 | [report](const auto& x) { return report == x.get(); }), |
| 130 | reports.end()); |
Krzysztof Grobelny | 64b75a5 | 2020-09-18 10:17:16 +0200 | [diff] [blame] | 131 | } |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 132 | |
Szymon Dompke | 32305f1 | 2022-07-05 15:37:21 +0200 | [diff] [blame] | 133 | void ReportManager::verifyMetricParameters( |
| 134 | const std::vector<LabeledMetricParameters>& readingParams) |
| 135 | { |
| 136 | namespace ts = utils::tstring; |
| 137 | |
| 138 | for (auto readingParam : readingParams) |
| 139 | { |
| 140 | if (readingParam.at_label<ts::Id>().length() > |
| 141 | utils::constants::maxIdNameLength) |
| 142 | { |
| 143 | throw sdbusplus::exception::SdBusError( |
| 144 | static_cast<int>(std::errc::invalid_argument), |
| 145 | "MetricId too long"); |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 150 | void ReportManager::verifyAddReport( |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 151 | const std::string& reportId, const std::string& reportName, |
| 152 | const ReportingType reportingType, Milliseconds interval, |
Ankita Vilas Gawade | cd5b0b7 | 2022-01-20 20:55:04 +0000 | [diff] [blame] | 153 | const ReportUpdates reportUpdates, const uint64_t appendLimit, |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 154 | const std::vector<LabeledMetricParameters>& readingParams) |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 155 | { |
Szymon Dompke | 32305f1 | 2022-07-05 15:37:21 +0200 | [diff] [blame] | 156 | namespace ts = utils::tstring; |
| 157 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 158 | if (reports.size() >= maxReports) |
| 159 | { |
| 160 | throw sdbusplus::exception::SdBusError( |
| 161 | static_cast<int>(std::errc::too_many_files_open), |
| 162 | "Reached maximal report count"); |
| 163 | } |
| 164 | |
Krzysztof Grobelny | e6c417c | 2022-02-02 17:25:53 +0100 | [diff] [blame] | 165 | if (appendLimit > maxAppendLimit && |
| 166 | appendLimit != std::numeric_limits<uint64_t>::max()) |
Ankita Vilas Gawade | cd5b0b7 | 2022-01-20 20:55:04 +0000 | [diff] [blame] | 167 | { |
| 168 | throw sdbusplus::exception::SdBusError( |
| 169 | static_cast<int>(std::errc::invalid_argument), |
| 170 | "Append limit out of range"); |
| 171 | } |
| 172 | |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame] | 173 | if ((reportingType == ReportingType::periodic && interval < minInterval) || |
| 174 | (reportingType != ReportingType::periodic && |
| 175 | interval != Milliseconds{0})) |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 176 | { |
| 177 | throw sdbusplus::exception::SdBusError( |
| 178 | static_cast<int>(std::errc::invalid_argument), "Invalid interval"); |
| 179 | } |
Wludzik, Jozef | bc766b4 | 2020-12-08 16:06:22 +0100 | [diff] [blame] | 180 | |
Ankita Vilas Gawade | cd5b0b7 | 2022-01-20 20:55:04 +0000 | [diff] [blame] | 181 | size_t metricCount = 0; |
| 182 | for (auto metricParam : readingParams) |
| 183 | { |
| 184 | auto metricParamsVec = |
| 185 | metricParam.at_label<utils::tstring::SensorPath>(); |
| 186 | metricCount += metricParamsVec.size(); |
| 187 | } |
Krzysztof Grobelny | e8fc575 | 2021-02-05 14:30:45 +0000 | [diff] [blame] | 188 | |
Ankita Vilas Gawade | cd5b0b7 | 2022-01-20 20:55:04 +0000 | [diff] [blame] | 189 | if (readingParams.size() > maxNumberMetrics || |
| 190 | metricCount > maxNumberMetrics) |
Wludzik, Jozef | bc766b4 | 2020-12-08 16:06:22 +0100 | [diff] [blame] | 191 | { |
| 192 | throw sdbusplus::exception::SdBusError( |
| 193 | static_cast<int>(std::errc::argument_list_too_long), |
| 194 | "Too many reading parameters"); |
| 195 | } |
Krzysztof Grobelny | e8fc575 | 2021-02-05 14:30:45 +0000 | [diff] [blame] | 196 | |
Szymon Dompke | 32305f1 | 2022-07-05 15:37:21 +0200 | [diff] [blame] | 197 | verifyMetricParameters(readingParams); |
| 198 | |
Krzysztof Grobelny | e8fc575 | 2021-02-05 14:30:45 +0000 | [diff] [blame] | 199 | try |
| 200 | { |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 201 | for (const LabeledMetricParameters& item : readingParams) |
Krzysztof Grobelny | e8fc575 | 2021-02-05 14:30:45 +0000 | [diff] [blame] | 202 | { |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 203 | utils::toOperationType( |
| 204 | utils::toUnderlying(item.at_label<ts::OperationType>())); |
Krzysztof Grobelny | e8fc575 | 2021-02-05 14:30:45 +0000 | [diff] [blame] | 205 | } |
| 206 | } |
| 207 | catch (const std::exception& e) |
| 208 | { |
| 209 | throw sdbusplus::exception::SdBusError( |
| 210 | static_cast<int>(std::errc::invalid_argument), e.what()); |
| 211 | } |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 212 | } |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 213 | |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 214 | interfaces::Report& ReportManager::addReport( |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 215 | boost::asio::yield_context& yield, const std::string& reportId, |
| 216 | const std::string& reportName, const ReportingType reportingType, |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 217 | const std::vector<ReportAction>& reportActions, Milliseconds interval, |
| 218 | const uint64_t appendLimit, const ReportUpdates reportUpdates, |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 219 | ReadingParameters metricParams, const bool enabled) |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 220 | { |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 221 | auto labeledMetricParams = |
| 222 | reportFactory->convertMetricParams(yield, metricParams); |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 223 | |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 224 | return addReport(reportId, reportName, reportingType, reportActions, |
| 225 | interval, appendLimit, reportUpdates, |
Krzysztof Grobelny | 493e62e | 2022-02-14 10:55:50 +0100 | [diff] [blame] | 226 | std::move(labeledMetricParams), enabled, Readings{}); |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | interfaces::Report& ReportManager::addReport( |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 230 | const std::string& reportId, const std::string& reportName, |
| 231 | const ReportingType reportingType, |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 232 | const std::vector<ReportAction>& reportActions, Milliseconds interval, |
| 233 | const uint64_t appendLimit, const ReportUpdates reportUpdates, |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 234 | std::vector<LabeledMetricParameters> labeledMetricParams, |
Krzysztof Grobelny | 493e62e | 2022-02-14 10:55:50 +0100 | [diff] [blame] | 235 | const bool enabled, Readings readings) |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 236 | { |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 237 | const auto existingReportIds = utils::transform( |
| 238 | reports, [](const auto& report) { return report->getId(); }); |
| 239 | |
Szymon Dompke | 32305f1 | 2022-07-05 15:37:21 +0200 | [diff] [blame] | 240 | auto [id, name] = utils::makeIdName(reportId, reportName, reportNameDefault, |
| 241 | existingReportIds); |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 242 | |
| 243 | verifyAddReport(id, name, reportingType, interval, reportUpdates, |
Ankita Vilas Gawade | cd5b0b7 | 2022-01-20 20:55:04 +0000 | [diff] [blame] | 244 | appendLimit, labeledMetricParams); |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 245 | |
Krzysztof Grobelny | 493e62e | 2022-02-14 10:55:50 +0100 | [diff] [blame] | 246 | reports.emplace_back( |
| 247 | reportFactory->make(id, name, reportingType, reportActions, interval, |
| 248 | appendLimit, reportUpdates, *this, *reportStorage, |
| 249 | labeledMetricParams, enabled, std::move(readings))); |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 250 | return *reports.back(); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | void ReportManager::loadFromPersistent() |
| 254 | { |
| 255 | std::vector<interfaces::JsonStorage::FilePath> paths = |
| 256 | reportStorage->list(); |
| 257 | |
| 258 | for (const auto& path : paths) |
| 259 | { |
| 260 | std::optional<nlohmann::json> data = reportStorage->load(path); |
| 261 | try |
| 262 | { |
| 263 | size_t version = data->at("Version").get<size_t>(); |
| 264 | if (version != Report::reportVersion) |
| 265 | { |
| 266 | throw std::logic_error("Invalid version"); |
| 267 | } |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 268 | bool enabled = data->at("Enabled").get<bool>(); |
| 269 | std::string& id = data->at("Id").get_ref<std::string&>(); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 270 | std::string& name = data->at("Name").get_ref<std::string&>(); |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 271 | |
| 272 | uint32_t reportingType = data->at("ReportingType").get<uint32_t>(); |
| 273 | std::vector<ReportAction> reportActions = utils::transform( |
| 274 | data->at("ReportActions").get<std::vector<uint32_t>>(), |
| 275 | [](const auto reportAction) { |
| 276 | return utils::toReportAction(reportAction); |
| 277 | }); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 278 | uint64_t interval = data->at("Interval").get<uint64_t>(); |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 279 | uint64_t appendLimit = data->at("AppendLimit").get<uint64_t>(); |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 280 | uint32_t reportUpdates = data->at("ReportUpdates").get<uint32_t>(); |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 281 | auto readingParameters = |
| 282 | data->at("ReadingParameters") |
| 283 | .get<std::vector<LabeledMetricParameters>>(); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 284 | |
Krzysztof Grobelny | 493e62e | 2022-02-14 10:55:50 +0100 | [diff] [blame] | 285 | Readings readings = {}; |
| 286 | |
| 287 | if (auto it = data->find("MetricValues"); it != data->end()) |
| 288 | { |
| 289 | const auto labeledReadings = it->get<LabeledReadings>(); |
| 290 | readings = utils::toReadings(labeledReadings); |
| 291 | } |
| 292 | |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 293 | addReport(id, name, utils::toReportingType(reportingType), |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 294 | reportActions, Milliseconds(interval), appendLimit, |
| 295 | utils::toReportUpdates(reportUpdates), |
Krzysztof Grobelny | 493e62e | 2022-02-14 10:55:50 +0100 | [diff] [blame] | 296 | std::move(readingParameters), enabled, |
| 297 | std::move(readings)); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 298 | } |
| 299 | catch (const std::exception& e) |
| 300 | { |
| 301 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 302 | "Failed to load report from storage", |
| 303 | phosphor::logging::entry( |
Wludzik, Jozef | 982c5b5 | 2021-01-02 12:05:21 +0100 | [diff] [blame] | 304 | "FILENAME=%s", |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 305 | static_cast<std::filesystem::path>(path).c_str()), |
Wludzik, Jozef | 982c5b5 | 2021-01-02 12:05:21 +0100 | [diff] [blame] | 306 | phosphor::logging::entry("EXCEPTION_MSG=%s", e.what())); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 307 | reportStorage->remove(path); |
| 308 | } |
| 309 | } |
| 310 | } |