mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-03 16:25:35 +00:00
Heartbeat: Try backup1 and backup2, refactor sentry reporting
This commit is contained in:
parent
c0faff5b05
commit
fe6e1e6266
@ -62,6 +62,8 @@ public:
|
||||
|
||||
static std::string GetBackendUrlForAuth() { return "auth.beammp.com"; }
|
||||
static std::string GetBackendHostname() { return "backend.beammp.com"; }
|
||||
static std::string GetBackup1Hostname() { return "backup1.beammp.com"; }
|
||||
static std::string GetBackup2Hostname() { return "backup2.beammp.com"; }
|
||||
static std::string GetBackendUrlForSocketIO() { return "https://backend.beammp.com"; }
|
||||
|
||||
private:
|
||||
|
@ -18,8 +18,8 @@ public:
|
||||
void SetupUser();
|
||||
void Log(sentry_level_t level, const std::string& logger, const std::string& text);
|
||||
void LogError(const std::string& text, const std::string& file, const std::string& line);
|
||||
void AddExtra(const std::string& key, const sentry_value_t& value);
|
||||
void AddExtra(const std::string& key, const std::string& value);
|
||||
void SetExtra(const std::string& key, const sentry_value_t& value);
|
||||
void SetExtra(const std::string& key, const std::string& value);
|
||||
void LogException(const std::exception& e, const std::string& file, const std::string& line);
|
||||
void AddErrorBreadcrumb(const std::string& msg, const std::string& file, const std::string& line);
|
||||
// cleared when Logged
|
||||
|
@ -124,14 +124,14 @@ std::string Http::POST(const std::string& host, const std::string& target, const
|
||||
|
||||
http::read(stream, buffer, response);
|
||||
|
||||
Sentry.AddExtra("reponse-code", std::to_string(response.result_int()));
|
||||
Sentry.SetExtra("reponse-code", std::to_string(response.result_int()));
|
||||
|
||||
for (const auto& header : response.base()) {
|
||||
// need to do explicit casts to convert string_view to string
|
||||
// since string_view may not be null-terminated (and in fact isn't, here)
|
||||
std::string KeyString(header.name_string());
|
||||
std::string ValueString(header.value());
|
||||
Sentry.AddExtra(KeyString, ValueString);
|
||||
Sentry.SetExtra(KeyString, ValueString);
|
||||
}
|
||||
|
||||
std::stringstream result;
|
||||
|
@ -39,32 +39,46 @@ void THeartbeatThread::operator()() {
|
||||
T = Http::POST(Application::GetBackendHostname(), Target, {}, Body, false);
|
||||
|
||||
if (T.substr(0, 2) != "20") {
|
||||
auto SentryReportError = [&](const std::string& transaction) {
|
||||
if (T.size() > std::string("YOU_SHALL_NOT_PASS").size()
|
||||
&& Application::Settings.Key.size() == 36) {
|
||||
auto Lock = Sentry.CreateExclusiveContext();
|
||||
Sentry.SetExtra("response-body", T);
|
||||
Sentry.SetExtra("request-body", Body);
|
||||
Sentry.SetTransaction(transaction);
|
||||
Sentry.Log(SENTRY_LEVEL_ERROR, "default", "wrong backend response format");
|
||||
}
|
||||
};
|
||||
SentryReportError(Application::GetBackendHostname() + Target);
|
||||
|
||||
//Backend system refused server startup!
|
||||
warn("Backend system refused server! Server might not show in the public list");
|
||||
debug("server returned \"" + T + "\"");
|
||||
if (T.size() > std::string("YOU_SHALL_NOT_PASS").size()
|
||||
&& Application::Settings.Key.size() == 36) {
|
||||
auto Lock = Sentry.CreateExclusiveContext();
|
||||
Sentry.AddExtra("response-body", T);
|
||||
Sentry.AddExtra("request-body", Body);
|
||||
Sentry.SetTransaction(Application::GetBackendHostname() + Target);
|
||||
Sentry.Log(SENTRY_LEVEL_ERROR, "default", "wrong backend response format");
|
||||
}
|
||||
isAuth = false;
|
||||
}
|
||||
|
||||
if (!isAuth) {
|
||||
if (T == "2000") {
|
||||
info(("Authenticated!"));
|
||||
isAuth = true;
|
||||
} else if (T == "200") {
|
||||
info(("Resumed authenticated session!"));
|
||||
isAuth = true;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
T = Http::POST(Application::GetBackup1Hostname(), Target, {}, Body, false);
|
||||
if (T.substr(0, 2) != "20") {
|
||||
SentryReportError(Application::GetBackup1Hostname() + Target);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
T = Http::POST(Application::GetBackup2Hostname(), Target, {}, Body, false);
|
||||
if (T.substr(0, 2) != "20") {
|
||||
warn("Backend system refused server! Server might not show in the public list");
|
||||
isAuth = false;
|
||||
SentryReportError(Application::GetBackup2Hostname() + Target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//SocketIO::Get().SetAuthenticated(isAuth);
|
||||
}
|
||||
|
||||
if (!isAuth) {
|
||||
if (T == "2000") {
|
||||
info(("Authenticated!"));
|
||||
isAuth = true;
|
||||
} else if (T == "200") {
|
||||
info(("Resumed authenticated session!"));
|
||||
isAuth = true;
|
||||
}
|
||||
}
|
||||
|
||||
//SocketIO::Get().SetAuthenticated(isAuth);
|
||||
}
|
||||
}
|
||||
std::string THeartbeatThread::GenerateCall() {
|
||||
std::stringstream Ret;
|
||||
|
@ -298,8 +298,8 @@ void TNetwork::Authentication(SOCKET TCPSock) {
|
||||
ClientKick(*Client, "Backend returned invalid auth response format.");
|
||||
error("Backend returned invalid auth response format. This should never happen.");
|
||||
auto Lock = Sentry.CreateExclusiveContext();
|
||||
Sentry.AddExtra("response-body", Rc);
|
||||
Sentry.AddExtra("key", RequestString);
|
||||
Sentry.SetExtra("response-body", Rc);
|
||||
Sentry.SetExtra("key", RequestString);
|
||||
Sentry.SetTransaction(Application::GetBackendUrlForAuth() + Target);
|
||||
Sentry.Log(SENTRY_LEVEL_ERROR, "default", "auth: wrong backend response format");
|
||||
return;
|
||||
|
@ -49,18 +49,18 @@ void TSentry::LogError(const std::string& text, const std::string& file, const s
|
||||
Log(SENTRY_LEVEL_ERROR, "default", file + ": " + text);
|
||||
}
|
||||
|
||||
void TSentry::AddExtra(const std::string& key, const sentry_value_t& value) {
|
||||
void TSentry::SetExtra(const std::string& key, const sentry_value_t& value) {
|
||||
if (!mValid) {
|
||||
return;
|
||||
}
|
||||
sentry_set_extra(key.c_str(), value);
|
||||
}
|
||||
|
||||
void TSentry::AddExtra(const std::string& key, const std::string& value) {
|
||||
void TSentry::SetExtra(const std::string& key, const std::string& value) {
|
||||
if (!mValid) {
|
||||
return;
|
||||
}
|
||||
AddExtra(key.c_str(), sentry_value_new_string(value.c_str()));
|
||||
SetExtra(key.c_str(), sentry_value_new_string(value.c_str()));
|
||||
}
|
||||
|
||||
void TSentry::LogException(const std::exception& e, const std::string& file, const std::string& line) {
|
||||
|
@ -324,9 +324,9 @@ void TServer::Apply(TClient& c, int VID, const std::string& pckt) {
|
||||
if (VD.empty()) {
|
||||
error("Tried to apply change to vehicle that does not exist");
|
||||
auto Lock = Sentry.CreateExclusiveContext();
|
||||
Sentry.AddExtra("packet", Packet);
|
||||
Sentry.AddExtra("vehicle-id", std::to_string(VID));
|
||||
Sentry.AddExtra("client-car-count", std::to_string(c.GetCarCount()));
|
||||
Sentry.SetExtra("packet", Packet);
|
||||
Sentry.SetExtra("vehicle-id", std::to_string(VID));
|
||||
Sentry.SetExtra("client-car-count", std::to_string(c.GetCarCount()));
|
||||
Sentry.LogError("attempt to apply change to nonexistent vehicle", _file_basename, _line);
|
||||
return;
|
||||
}
|
||||
@ -335,7 +335,7 @@ void TServer::Apply(TClient& c, int VID, const std::string& pckt) {
|
||||
FoundPos = VD.find('{');
|
||||
if (FoundPos == std::string::npos) {
|
||||
auto Lock = Sentry.CreateExclusiveContext();
|
||||
Sentry.AddExtra("packet", VD);
|
||||
Sentry.SetExtra("packet", VD);
|
||||
Sentry.LogError("malformed packet", _file_basename, _line);
|
||||
error("Malformed packet received, no '{' found");
|
||||
return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user