ORE Studio 0.0.4
Loading...
Searching...
No Matches
telemetry_repository.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_TELEMETRY_REPOSITORY_TELEMETRY_REPOSITORY_HPP
21#define ORES_TELEMETRY_REPOSITORY_TELEMETRY_REPOSITORY_HPP
22
23#include <string>
24#include <vector>
25#include <optional>
26#include <boost/uuid/uuid.hpp>
27#include <sqlgen/postgres.hpp>
28#include "ores.logging/make_logger.hpp"
29#include "ores.database/domain/context.hpp"
30#include "ores.telemetry/domain/telemetry_log_entry.hpp"
31#include "ores.telemetry/domain/telemetry_query.hpp"
32#include "ores.telemetry/domain/telemetry_stats.hpp"
33#include "ores.telemetry/domain/telemetry_batch.hpp"
34
36
44private:
45 inline static std::string_view logger_name =
46 "ores.telemetry.repository.telemetry_repository";
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:
56 explicit telemetry_repository(context ctx);
57
61 std::string sql();
62
66 void create(const domain::telemetry_log_entry& entry);
67
75 std::size_t create_batch(const domain::telemetry_batch& batch);
76
80 std::vector<domain::telemetry_log_entry> query(
82
88 std::uint64_t count(const domain::telemetry_query& q);
89
97 std::vector<domain::telemetry_log_entry> read_by_session(
98 const boost::uuids::uuid& session_id,
99 std::uint32_t limit = 1000);
100
109 std::vector<domain::telemetry_log_entry> read_by_account(
110 const boost::uuids::uuid& account_id,
111 const std::chrono::system_clock::time_point& start,
112 const std::chrono::system_clock::time_point& end,
113 std::uint32_t limit = 1000);
114
118 std::vector<domain::telemetry_stats> read_hourly_stats(
120
124 std::vector<domain::telemetry_stats> read_daily_stats(
126
132 domain::telemetry_summary get_summary(std::uint32_t hours = 24);
133
139 std::uint64_t count_errors(const std::string& source_name,
140 std::uint32_t hours = 1);
141
152 std::uint64_t delete_old_logs(
153 const std::chrono::system_clock::time_point& older_than);
154
155private:
156 context ctx_;
157};
158
159}
160
161#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Database persistence layer for telemetry data.
Definition ores.telemetry.repository.hpp:36
Context for the operations on a postgres database.
Definition context.hpp:30
A batch of telemetry log entries from a single source.
Definition telemetry_batch.hpp:37
A persisted telemetry log entry.
Definition telemetry_log_entry.hpp:41
Query parameters for retrieving telemetry logs.
Definition telemetry_query.hpp:38
Query parameters for retrieving telemetry statistics.
Definition telemetry_query.hpp:140
Summary statistics for a telemetry overview.
Definition telemetry_stats.hpp:91
Repository for telemetry log persistence and querying.
Definition telemetry_repository.hpp:43
std::uint64_t delete_old_logs(const std::chrono::system_clock::time_point &older_than)
Deletes logs older than the specified retention period.
Definition telemetry_repository.cpp:479
domain::telemetry_summary get_summary(std::uint32_t hours=24)
Gets a summary of telemetry activity.
Definition telemetry_repository.cpp:398
std::size_t create_batch(const domain::telemetry_batch &batch)
Creates multiple log entries in a batch.
Definition telemetry_repository.cpp:57
std::vector< domain::telemetry_log_entry > query(const domain::telemetry_query &q)
Queries log entries with filters.
Definition telemetry_repository.cpp:180
std::vector< domain::telemetry_log_entry > read_by_account(const boost::uuids::uuid &account_id, const std::chrono::system_clock::time_point &start, const std::chrono::system_clock::time_point &end, std::uint32_t limit=1000)
Reads logs for a specific account.
Definition telemetry_repository.cpp:287
std::vector< domain::telemetry_stats > read_daily_stats(const domain::telemetry_stats_query &q)
Reads daily statistics.
Definition telemetry_repository.cpp:357
std::vector< domain::telemetry_stats > read_hourly_stats(const domain::telemetry_stats_query &q)
Reads hourly statistics.
Definition telemetry_repository.cpp:319
std::uint64_t count_errors(const std::string &source_name, std::uint32_t hours=1)
Counts error logs in the last N hours for a source.
Definition telemetry_repository.cpp:451
std::uint64_t count(const domain::telemetry_query &q)
Counts log entries matching a query.
Definition telemetry_repository.cpp:233
void create(const domain::telemetry_log_entry &entry)
Creates a single log entry.
Definition telemetry_repository.cpp:46
std::string sql()
Returns the SQL created by sqlgen to construct the table.
Definition telemetry_repository.cpp:42
std::vector< domain::telemetry_log_entry > read_by_session(const boost::uuids::uuid &session_id, std::uint32_t limit=1000)
Reads logs for a specific session.
Definition telemetry_repository.cpp:261