Reorganize logs, add req/resp to CLI, add last seen to UI

This commit is contained in:
Francesco Mazzoli
2023-02-14 12:21:48 +00:00
parent e580cd5fe9
commit 4288189766
35 changed files with 639 additions and 394 deletions

View File

@@ -79,7 +79,9 @@ int main(int argc, char** argv) {
options.level = std::min<LogLevel>(LogLevel::LOG_DEBUG, options.level);
} else if (arg == "-log-level") {
std::string logLevel = getNextArg();
if (logLevel == "debug") {
if (logLevel == "trace") {
options.level = LogLevel::LOG_TRACE;
} else if (logLevel == "debug") {
options.level = LogLevel::LOG_DEBUG;
} else if (logLevel == "info") {
options.level = LogLevel::LOG_INFO;
@@ -107,8 +109,8 @@ int main(int argc, char** argv) {
}
#ifndef EGGS_DEBUG
if (options.level <= LogLevel::LOG_DEBUG) {
die("Cannot use -verbose for non-debug builds (it won't work).");
if (options.level <= LogLevel::LOG_TRACE) {
die("Cannot use log level trace trace for non-debug builds (it won't work).");
}
#endif

View File

@@ -3,4 +3,4 @@ file(GLOB core_headers CONFIGURE_DEPENDS "*.hpp")
add_library(core ${core_sources} ${core_headers})
add_dependencies(core thirdparty)
target_link_libraries(core PRIVATE z lzma dwarf elf rocksdb lz4 zstd uring unwind xxhash)
target_link_libraries(core PRIVATE rocksdb lz4 zstd uring xxhash)

View File

@@ -9,9 +9,10 @@
#include "Time.hpp"
enum class LogLevel : uint32_t {
LOG_DEBUG = 0,
LOG_INFO = 1,
LOG_ERROR = 2,
LOG_TRACE = 0,
LOG_DEBUG = 1,
LOG_INFO = 2,
LOG_ERROR = 3,
};
std::ostream& operator<<(std::ostream& out, LogLevel ll);
@@ -26,10 +27,6 @@ public:
template<typename ...Args>
void _log(LogLevel level, const std::string& prefix, const char* fmt, Args&&... args) {
if (level < _logLevel) {
return;
}
std::scoped_lock lock(_mutex);
std::stringstream ss;
format_pack(ss, fmt, args...);
@@ -40,6 +37,10 @@ public:
}
}
bool _shouldLog(LogLevel level) {
return level >= _logLevel;
}
void flush() {
std::scoped_lock lock(_mutex);
_out.flush();
@@ -63,28 +64,45 @@ public:
_log(LogLevel::LOG_ERROR, fmt, std::forward<Args>(args)...);
}
bool _shouldLog(LogLevel level) {
return _logger._shouldLog(level);
}
void flush() {
_logger.flush();
}
};
#ifdef EGGS_DEBUG
#define LOG_DEBUG(env, ...) \
#ifdef EGGS_TRACE
#define LOG_TRACE(env, ...) \
do { \
(env)._log(LogLevel::LOG_DEBUG, VALIDATE_FORMAT(__VA_ARGS__)); \
if (unlikely((env)._shouldLog(LogLevel::LOG_TRACE))) { \
(env)._log(LogLevel::LOG_TRACE, VALIDATE_FORMAT(__VA_ARGS__)); \
} \
} while (false)
#else
#define LOG_DEBUG(env, ...) do {} while (false)
#define LOG_TRACE(env, ...) do {} while (false)
#endif
#define LOG_DEBUG(env, ...) \
do { \
if (unlikely((env)._shouldLog(LogLevel::LOG_DEBUG))) { \
(env)._log(LogLevel::LOG_DEBUG, VALIDATE_FORMAT(__VA_ARGS__)); \
} \
} while (false)
#define LOG_INFO(env, ...) \
do { \
(env)._log(LogLevel::LOG_INFO, VALIDATE_FORMAT(__VA_ARGS__)); \
if (likely((env)._shouldLog(LogLevel::LOG_INFO))) { \
(env)._log(LogLevel::LOG_INFO, VALIDATE_FORMAT(__VA_ARGS__)); \
} \
} while (false)
#define LOG_ERROR(env, ...) \
do { \
(env)._log(LogLevel::LOG_ERROR, VALIDATE_FORMAT(__VA_ARGS__)); \
if (likely((env)._shouldLog(LogLevel::LOG_ERROR))) { \
(env)._log(LogLevel::LOG_ERROR, VALIDATE_FORMAT(__VA_ARGS__)); \
} \
} while (false)
// The interface for this will be different -- we want some kind of alert object

View File

@@ -626,6 +626,7 @@ void BlockServiceInfo::pack(BincodeBuf& buf) const {
buf.packScalar<uint64_t>(availableBytes);
buf.packScalar<uint64_t>(blocks);
buf.packBytes(path);
lastSeen.pack(buf);
}
void BlockServiceInfo::unpack(BincodeBuf& buf) {
id = buf.unpackScalar<uint64_t>();
@@ -640,6 +641,7 @@ void BlockServiceInfo::unpack(BincodeBuf& buf) {
availableBytes = buf.unpackScalar<uint64_t>();
blocks = buf.unpackScalar<uint64_t>();
buf.unpackBytes(path);
lastSeen.unpack(buf);
}
void BlockServiceInfo::clear() {
id = uint64_t(0);
@@ -654,6 +656,7 @@ void BlockServiceInfo::clear() {
availableBytes = uint64_t(0);
blocks = uint64_t(0);
path.clear();
lastSeen = EggsTime();
}
bool BlockServiceInfo::operator==(const BlockServiceInfo& rhs) const {
if ((uint64_t)this->id != (uint64_t)rhs.id) { return false; };
@@ -668,32 +671,37 @@ bool BlockServiceInfo::operator==(const BlockServiceInfo& rhs) const {
if ((uint64_t)this->availableBytes != (uint64_t)rhs.availableBytes) { return false; };
if ((uint64_t)this->blocks != (uint64_t)rhs.blocks) { return false; };
if (path != rhs.path) { return false; };
if ((EggsTime)this->lastSeen != (EggsTime)rhs.lastSeen) { return false; };
return true;
}
std::ostream& operator<<(std::ostream& out, const BlockServiceInfo& x) {
out << "BlockServiceInfo(" << "Id=" << x.id << ", " << "Ip1=" << x.ip1 << ", " << "Port1=" << x.port1 << ", " << "Ip2=" << x.ip2 << ", " << "Port2=" << x.port2 << ", " << "StorageClass=" << (int)x.storageClass << ", " << "FailureDomain=" << x.failureDomain << ", " << "SecretKey=" << x.secretKey << ", " << "CapacityBytes=" << x.capacityBytes << ", " << "AvailableBytes=" << x.availableBytes << ", " << "Blocks=" << x.blocks << ", " << "Path=" << x.path << ")";
out << "BlockServiceInfo(" << "Id=" << x.id << ", " << "Ip1=" << x.ip1 << ", " << "Port1=" << x.port1 << ", " << "Ip2=" << x.ip2 << ", " << "Port2=" << x.port2 << ", " << "StorageClass=" << (int)x.storageClass << ", " << "FailureDomain=" << x.failureDomain << ", " << "SecretKey=" << x.secretKey << ", " << "CapacityBytes=" << x.capacityBytes << ", " << "AvailableBytes=" << x.availableBytes << ", " << "Blocks=" << x.blocks << ", " << "Path=" << x.path << ", " << "LastSeen=" << x.lastSeen << ")";
return out;
}
void ShardInfo::pack(BincodeBuf& buf) const {
buf.packFixedBytes<4>(ip);
buf.packScalar<uint16_t>(port);
lastSeen.pack(buf);
}
void ShardInfo::unpack(BincodeBuf& buf) {
buf.unpackFixedBytes<4>(ip);
port = buf.unpackScalar<uint16_t>();
lastSeen.unpack(buf);
}
void ShardInfo::clear() {
ip.clear();
port = uint16_t(0);
lastSeen = EggsTime();
}
bool ShardInfo::operator==(const ShardInfo& rhs) const {
if (ip != rhs.ip) { return false; };
if ((uint16_t)this->port != (uint16_t)rhs.port) { return false; };
if ((EggsTime)this->lastSeen != (EggsTime)rhs.lastSeen) { return false; };
return true;
}
std::ostream& operator<<(std::ostream& out, const ShardInfo& x) {
out << "ShardInfo(" << "Ip=" << x.ip << ", " << "Port=" << x.port << ")";
out << "ShardInfo(" << "Ip=" << x.ip << ", " << "Port=" << x.port << ", " << "LastSeen=" << x.lastSeen << ")";
return out;
}
@@ -2682,22 +2690,26 @@ std::ostream& operator<<(std::ostream& out, const CdcReq& x) {
void CdcResp::pack(BincodeBuf& buf) const {
buf.packFixedBytes<4>(ip);
buf.packScalar<uint16_t>(port);
lastSeen.pack(buf);
}
void CdcResp::unpack(BincodeBuf& buf) {
buf.unpackFixedBytes<4>(ip);
port = buf.unpackScalar<uint16_t>();
lastSeen.unpack(buf);
}
void CdcResp::clear() {
ip.clear();
port = uint16_t(0);
lastSeen = EggsTime();
}
bool CdcResp::operator==(const CdcResp& rhs) const {
if (ip != rhs.ip) { return false; };
if ((uint16_t)this->port != (uint16_t)rhs.port) { return false; };
if ((EggsTime)this->lastSeen != (EggsTime)rhs.lastSeen) { return false; };
return true;
}
std::ostream& operator<<(std::ostream& out, const CdcResp& x) {
out << "CdcResp(" << "Ip=" << x.ip << ", " << "Port=" << x.port << ")";
out << "CdcResp(" << "Ip=" << x.ip << ", " << "Port=" << x.port << ", " << "LastSeen=" << x.lastSeen << ")";
return out;
}

View File

@@ -457,8 +457,9 @@ struct BlockServiceInfo {
uint64_t availableBytes;
uint64_t blocks;
BincodeBytes path;
EggsTime lastSeen;
static constexpr uint16_t STATIC_SIZE = 8 + BincodeFixedBytes<4>::STATIC_SIZE + 2 + BincodeFixedBytes<4>::STATIC_SIZE + 2 + 1 + BincodeFixedBytes<16>::STATIC_SIZE + BincodeFixedBytes<16>::STATIC_SIZE + 8 + 8 + 8 + BincodeBytes::STATIC_SIZE; // id + ip1 + port1 + ip2 + port2 + storageClass + failureDomain + secretKey + capacityBytes + availableBytes + blocks + path
static constexpr uint16_t STATIC_SIZE = 8 + BincodeFixedBytes<4>::STATIC_SIZE + 2 + BincodeFixedBytes<4>::STATIC_SIZE + 2 + 1 + BincodeFixedBytes<16>::STATIC_SIZE + BincodeFixedBytes<16>::STATIC_SIZE + 8 + 8 + 8 + BincodeBytes::STATIC_SIZE + 8; // id + ip1 + port1 + ip2 + port2 + storageClass + failureDomain + secretKey + capacityBytes + availableBytes + blocks + path + lastSeen
BlockServiceInfo() { clear(); }
uint16_t packedSize() const {
@@ -475,6 +476,7 @@ struct BlockServiceInfo {
_size += 8; // availableBytes
_size += 8; // blocks
_size += path.packedSize(); // path
_size += 8; // lastSeen
return _size;
}
void pack(BincodeBuf& buf) const;
@@ -488,14 +490,16 @@ std::ostream& operator<<(std::ostream& out, const BlockServiceInfo& x);
struct ShardInfo {
BincodeFixedBytes<4> ip;
uint16_t port;
EggsTime lastSeen;
static constexpr uint16_t STATIC_SIZE = BincodeFixedBytes<4>::STATIC_SIZE + 2; // ip + port
static constexpr uint16_t STATIC_SIZE = BincodeFixedBytes<4>::STATIC_SIZE + 2 + 8; // ip + port + lastSeen
ShardInfo() { clear(); }
uint16_t packedSize() const {
uint16_t _size = 0;
_size += BincodeFixedBytes<4>::STATIC_SIZE; // ip
_size += 2; // port
_size += 8; // lastSeen
return _size;
}
void pack(BincodeBuf& buf) const;
@@ -2430,14 +2434,16 @@ std::ostream& operator<<(std::ostream& out, const CdcReq& x);
struct CdcResp {
BincodeFixedBytes<4> ip;
uint16_t port;
EggsTime lastSeen;
static constexpr uint16_t STATIC_SIZE = BincodeFixedBytes<4>::STATIC_SIZE + 2; // ip + port
static constexpr uint16_t STATIC_SIZE = BincodeFixedBytes<4>::STATIC_SIZE + 2 + 8; // ip + port + lastSeen
CdcResp() { clear(); }
uint16_t packedSize() const {
uint16_t _size = 0;
_size += BincodeFixedBytes<4>::STATIC_SIZE; // ip
_size += 2; // port
_size += 8; // lastSeen
return _size;
}
void pack(BincodeBuf& buf) const;

View File

@@ -4,6 +4,7 @@
#include <memory>
#include <signal.h>
#include <list>
#include <mutex>
#include "SBRMUnix.hpp"

View File

@@ -1525,7 +1525,8 @@ struct ShardDBImpl {
}
if (err == NO_ERROR) {
LOG_DEBUG(_env, "prepared log entry of kind %s, for request of kind %s: %s", logEntryBody.kind(), req.kind(), logEntryBody);
LOG_DEBUG(_env, "prepared log entry of kind %s, for request of kind %s", logEntryBody.kind(), req.kind());
LOG_TRACE(_env, "log entry body: %s", logEntryBody);
} else {
LOG_INFO(_env, "could not prepare log entry for request of kind %s: %s", req.kind(), err);
}
@@ -2954,7 +2955,7 @@ struct ShardDBImpl {
EggsTime time = logEntry.time;
const auto& logEntryBody = logEntry.body;
LOG_DEBUG(_env, "about to apply log entry %s", logEntryBody);
LOG_TRACE(_env, "about to apply log entry %s", logEntryBody);
switch (logEntryBody.kind()) {
case ShardLogEntryKind::CONSTRUCT_FILE:

View File

@@ -103,7 +103,9 @@ int main(int argc, char** argv) {
options.level = std::min<LogLevel>(LogLevel::LOG_DEBUG, options.level);
} else if (arg == "-log-level") {
std::string logLevel = getNextArg();
if (logLevel == "debug") {
if (logLevel == "trace") {
options.level = LogLevel::LOG_TRACE;
} else if (logLevel == "debug") {
options.level = LogLevel::LOG_DEBUG;
} else if (logLevel == "info") {
options.level = LogLevel::LOG_INFO;
@@ -135,8 +137,8 @@ int main(int argc, char** argv) {
}
#ifndef EGGS_DEBUG
if (options.level <= LogLevel::LOG_DEBUG) {
die("Cannot use -verbose for non-debug builds (it won't work).");
if (options.level <= LogLevel::LOG_TRACE) {
die("Cannot use trace for non-debug builds (it won't work).");
}
#endif