Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 3 | #include "interfaces/clock.hpp" |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 4 | #include "interfaces/json_storage.hpp" |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 5 | #include "interfaces/metric.hpp" |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 6 | #include "interfaces/metric_listener.hpp" |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 7 | #include "interfaces/report.hpp" |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 8 | #include "interfaces/report_factory.hpp" |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 9 | #include "interfaces/report_manager.hpp" |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame] | 10 | #include "state.hpp" |
| 11 | #include "types/error_message.hpp" |
Krzysztof Grobelny | 493e62e | 2022-02-14 10:55:50 +0100 | [diff] [blame] | 12 | #include "types/readings.hpp" |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 13 | #include "types/report_action.hpp" |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 14 | #include "types/report_types.hpp" |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 15 | #include "types/report_updates.hpp" |
| 16 | #include "types/reporting_type.hpp" |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 17 | #include "utils/circular_vector.hpp" |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame] | 18 | #include "utils/dbus_path_utils.hpp" |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 19 | #include "utils/ensure.hpp" |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 20 | #include "utils/messanger.hpp" |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 21 | |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 22 | #include <boost/asio/io_context.hpp> |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 23 | #include <boost/asio/steady_timer.hpp> |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 24 | #include <sdbusplus/asio/object_server.hpp> |
| 25 | |
| 26 | #include <chrono> |
| 27 | #include <memory> |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 28 | #include <unordered_set> |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 29 | |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 30 | class Report : public interfaces::Report, public interfaces::MetricListener |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 31 | { |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 32 | class OnChangeContext |
| 33 | { |
| 34 | public: |
Patrick Williams | 3a1c297 | 2023-05-10 07:51:04 -0500 | [diff] [blame] | 35 | OnChangeContext(Report& report) : report(report) {} |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 36 | |
| 37 | ~OnChangeContext() |
| 38 | { |
| 39 | if (updated) |
| 40 | { |
| 41 | report.updateReadings(); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | void metricUpdated() |
| 46 | { |
| 47 | updated = true; |
| 48 | } |
| 49 | |
| 50 | private: |
| 51 | Report& report; |
| 52 | bool updated = false; |
| 53 | }; |
| 54 | |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 55 | public: |
| 56 | Report(boost::asio::io_context& ioc, |
| 57 | const std::shared_ptr<sdbusplus::asio::object_server>& objServer, |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 58 | const std::string& reportId, const std::string& reportName, |
| 59 | const ReportingType reportingType, |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 60 | std::vector<ReportAction> reportActions, const Milliseconds period, |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 61 | const uint64_t appendLimitIn, const ReportUpdates reportUpdatesIn, |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 62 | interfaces::ReportManager& reportManager, |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 63 | interfaces::JsonStorage& reportStorage, |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 64 | std::vector<std::shared_ptr<interfaces::Metric>> metrics, |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 65 | const interfaces::ReportFactory& reportFactory, const bool enabled, |
Krzysztof Grobelny | 493e62e | 2022-02-14 10:55:50 +0100 | [diff] [blame] | 66 | std::unique_ptr<interfaces::Clock> clock, Readings); |
| 67 | ~Report(); |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 68 | |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 69 | Report(const Report&) = delete; |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 70 | Report(Report&&) = delete; |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 71 | Report& operator=(const Report&) = delete; |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 72 | Report& operator=(Report&&) = delete; |
| 73 | |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 74 | std::string getId() const override |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 75 | { |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 76 | return id; |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | std::string getPath() const override |
| 80 | { |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame] | 81 | return path.str; |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 82 | } |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 83 | |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 84 | void metricUpdated() override; |
| 85 | |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame] | 86 | void activate(); |
| 87 | void deactivate(); |
| 88 | |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 89 | private: |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 90 | std::unique_ptr<sdbusplus::asio::dbus_interface> |
| 91 | makeReportInterface(const interfaces::ReportFactory& reportFactory); |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 92 | static void timerProcForPeriodicReport(boost::system::error_code, |
| 93 | Report& self); |
| 94 | static void timerProcForOnChangeReport(boost::system::error_code, |
| 95 | Report& self); |
| 96 | void scheduleTimerForPeriodicReport(Milliseconds interval); |
| 97 | void scheduleTimerForOnChangeReport(); |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 98 | uint64_t deduceBufferSize(const ReportUpdates reportUpdatesIn, |
| 99 | const ReportingType reportingTypeIn) const; |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 100 | void setReadingBuffer(const ReportUpdates newReportUpdates); |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 101 | void setReportUpdates(const ReportUpdates newReportUpdates); |
Krzysztof Grobelny | 18e7101 | 2022-11-02 13:17:01 +0000 | [diff] [blame] | 102 | static uint64_t getMetricCount( |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 103 | const std::vector<std::shared_ptr<interfaces::Metric>>& metrics); |
Krzysztof Grobelny | 493e62e | 2022-02-14 10:55:50 +0100 | [diff] [blame] | 104 | interfaces::JsonStorage::FilePath reportFileName() const; |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 105 | std::unordered_set<std::string> |
| 106 | collectTriggerIds(boost::asio::io_context& ioc) const; |
| 107 | bool storeConfiguration() const; |
Krzysztof Grobelny | 493e62e | 2022-02-14 10:55:50 +0100 | [diff] [blame] | 108 | bool shouldStoreMetricValues() const; |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 109 | void updateReadings(); |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame] | 110 | void scheduleTimer(); |
Krzysztof Grobelny | cff70c1 | 2022-10-27 07:16:08 +0000 | [diff] [blame] | 111 | static std::vector<ErrorMessage> verify(ReportingType, Milliseconds); |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 112 | |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 113 | std::string id; |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame] | 114 | const sdbusplus::message::object_path path; |
Szymon Dompke | e28aa53 | 2021-10-27 12:33:12 +0200 | [diff] [blame] | 115 | std::string name; |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 116 | ReportingType reportingType; |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 117 | Milliseconds interval; |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 118 | std::unordered_set<ReportAction> reportActions; |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 119 | ReadingParameters readingParameters; |
Krzysztof Grobelny | 85db8bd | 2021-05-28 12:13:23 +0000 | [diff] [blame] | 120 | bool persistency = false; |
Krzysztof Grobelny | 18e7101 | 2022-11-02 13:17:01 +0000 | [diff] [blame] | 121 | uint64_t metricCount; |
| 122 | uint64_t appendLimit; |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 123 | ReportUpdates reportUpdates; |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 124 | Readings readings = {}; |
Krzysztof Grobelny | 493e62e | 2022-02-14 10:55:50 +0100 | [diff] [blame] | 125 | CircularVector<ReadingData> readingsBuffer; |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 126 | std::shared_ptr<sdbusplus::asio::object_server> objServer; |
| 127 | std::unique_ptr<sdbusplus::asio::dbus_interface> reportIface; |
| 128 | std::unique_ptr<sdbusplus::asio::dbus_interface> deleteIface; |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 129 | std::vector<std::shared_ptr<interfaces::Metric>> metrics; |
| 130 | boost::asio::steady_timer timer; |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 131 | std::unordered_set<std::string> triggerIds; |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 132 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 133 | interfaces::JsonStorage& reportStorage; |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 134 | std::unique_ptr<interfaces::Clock> clock; |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 135 | utils::Messanger messanger; |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 136 | std::optional<OnChangeContext> onChangeContext; |
| 137 | utils::Ensure<std::function<void()>> unregisterFromMetrics; |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame] | 138 | State<ReportFlags, Report, ReportFlags::enabled, ReportFlags::valid> state{ |
| 139 | *this}; |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 140 | |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 141 | public: |
| 142 | static constexpr const char* reportIfaceName = |
| 143 | "xyz.openbmc_project.Telemetry.Report"; |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 144 | static constexpr const char* deleteIfaceName = |
| 145 | "xyz.openbmc_project.Object.Delete"; |
Krzysztof Grobelny | 18e7101 | 2022-11-02 13:17:01 +0000 | [diff] [blame] | 146 | static constexpr size_t reportVersion = 7; |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 147 | }; |