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