ORE Studio 0.0.4
Loading...
Searching...
No Matches
ClientTelemetryLogModel.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2025 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef ORES_QT_CLIENT_TELEMETRY_LOG_MODEL_HPP
21#define ORES_QT_CLIENT_TELEMETRY_LOG_MODEL_HPP
22
23#include <vector>
24#include <optional>
25#include <QFutureWatcher>
26#include <QAbstractTableModel>
27#include "ores.qt/AbstractClientModel.hpp"
28#include <boost/uuid/uuid.hpp>
29#include "ores.qt/ClientManager.hpp"
30#include "ores.logging/make_logger.hpp"
31#include "ores.telemetry/domain/telemetry_log_entry.hpp"
32
33namespace ores::qt {
34
42 Q_OBJECT
43
44private:
45 inline static std::string_view logger_name =
46 "ores.qt.client_telemetry_log_model";
47
48 [[nodiscard]] static auto& lg() {
49 using namespace ores::logging;
50 static auto instance = make_logger(logger_name);
51 return instance;
52 }
53
54public:
55 enum Column {
56 Timestamp,
57 Level,
58 Source,
59 Component,
60 Tag,
61 Message,
62 ColumnCount
63 };
64
65 explicit ClientTelemetryLogModel(ClientManager* clientManager,
66 QObject* parent = nullptr);
67 ~ClientTelemetryLogModel() override = default;
68
69 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
70 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
71 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
72 QVariant headerData(int section, Qt::Orientation orientation,
73 int role = Qt::DisplayRole) const override;
74
80 void load_session_logs(const boost::uuids::uuid& session_id);
81
88 void load_logs(std::chrono::system_clock::time_point start_time,
89 std::chrono::system_clock::time_point end_time);
90
97 void load_page(std::uint32_t offset, std::uint32_t limit);
98
102 void clear();
103
108
112 std::uint32_t page_size() const { return page_size_; }
113
117 void set_page_size(std::uint32_t size);
118
122 std::uint64_t total_available_count() const { return total_available_count_; }
123
129 void set_min_level(const std::optional<std::string>& level);
130
136 void set_message_filter(const std::optional<std::string>& text);
137
143 void set_tag_filter(const std::optional<std::string>& tag);
144
150 void set_component_filter(const std::optional<std::string>& component);
151
155 std::optional<boost::uuids::uuid> current_session_id() const {
156 return current_session_id_;
157 }
158
159signals:
160
161private slots:
162 void onLogsLoaded();
163
164private:
165 struct FetchResult {
166 bool success;
167 std::vector<telemetry::domain::telemetry_log_entry> entries;
168 std::uint64_t total_count;
169 QString error_message;
170 QString error_details;
171 };
172
173 void fetch_logs();
174
175 ClientManager* clientManager_;
176 std::vector<telemetry::domain::telemetry_log_entry> entries_;
177 QFutureWatcher<FetchResult>* watcher_;
178
179 std::optional<boost::uuids::uuid> current_session_id_;
180 std::chrono::system_clock::time_point start_time_;
181 std::chrono::system_clock::time_point end_time_;
182 std::optional<std::string> min_level_;
183 std::optional<std::string> message_filter_;
184 std::optional<std::string> tag_filter_;
185 std::optional<std::string> component_filter_;
186
187 std::uint32_t page_size_{100};
188 std::uint32_t current_offset_{0};
189 std::uint64_t total_available_count_{0};
190 bool is_fetching_{false};
191};
192
193}
194
195#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:29
Base class for all client-side entity models.
Definition AbstractClientModel.hpp:36
Manages the lifecycle of the NATS client and login state.
Definition ClientManager.hpp:109
Model for displaying telemetry log entries from the server.
Definition ClientTelemetryLogModel.hpp:41
void set_component_filter(const std::optional< std::string > &component)
Set the component prefix filter.
Definition ClientTelemetryLogModel.cpp:181
void set_page_size(std::uint32_t size)
Set the page size for pagination.
Definition ClientTelemetryLogModel.cpp:155
void set_min_level(const std::optional< std::string > &level)
Set the minimum log level filter.
Definition ClientTelemetryLogModel.cpp:166
const telemetry::domain::telemetry_log_entry * get_entry(int row) const
Get log entry at the specified row.
Definition ClientTelemetryLogModel.cpp:149
void load_logs(std::chrono::system_clock::time_point start_time, std::chrono::system_clock::time_point end_time)
Load logs within a time range.
Definition ClientTelemetryLogModel.cpp:121
std::optional< boost::uuids::uuid > current_session_id() const
Get the currently filtered session ID.
Definition ClientTelemetryLogModel.hpp:155
void set_message_filter(const std::optional< std::string > &text)
Set the message search filter.
Definition ClientTelemetryLogModel.cpp:171
void load_session_logs(const boost::uuids::uuid &session_id)
Load logs for a specific session.
Definition ClientTelemetryLogModel.cpp:112
void load_page(std::uint32_t offset, std::uint32_t limit)
Load a specific page of log data.
Definition ClientTelemetryLogModel.cpp:131
std::uint64_t total_available_count() const
Get the total number of records available on the server.
Definition ClientTelemetryLogModel.hpp:122
void clear()
Clear all log entries.
Definition ClientTelemetryLogModel.cpp:139
std::uint32_t page_size() const
Get the page size used for pagination.
Definition ClientTelemetryLogModel.hpp:112
void set_tag_filter(const std::optional< std::string > &tag)
Set the tag filter (exact match).
Definition ClientTelemetryLogModel.cpp:176
A persisted telemetry log entry.
Definition telemetry_log_entry.hpp:41