aboutsummaryrefslogtreecommitdiff
path: root/src/zenhttp/diagsvcs.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2023-06-30 10:55:49 +0200
committerStefan Boberg <[email protected]>2023-06-30 10:55:49 +0200
commit912cd60c4cdfd6e0253ee1b9ed1abade09ac8b7c (patch)
treeef0994084304dd5ce1fdd42621e36a9b34b191f7 /src/zenhttp/diagsvcs.cpp
parentadded zen::ChunkResolver (diff)
downloadzen-912cd60c4cdfd6e0253ee1b9ed1abade09ac8b7c.tar.xz
zen-912cd60c4cdfd6e0253ee1b9ed1abade09ac8b7c.zip
various zenhttp fixes from sb/proto
* Made HttpHealthService use locks to serialize access to state * Added ToString(HttpResponseCode HttpCode) * Added support for JS source maps * Moved IHttpStatsProvider/IHttpStatsService * Enabled enumeration of stats providers * Disabled build of HttpTestingService unless ZEN_WITH_TESTS is defined
Diffstat (limited to 'src/zenhttp/diagsvcs.cpp')
-rw-r--r--src/zenhttp/diagsvcs.cpp26
1 files changed, 17 insertions, 9 deletions
diff --git a/src/zenhttp/diagsvcs.cpp b/src/zenhttp/diagsvcs.cpp
index 8fa71b375..9a547aa47 100644
--- a/src/zenhttp/diagsvcs.cpp
+++ b/src/zenhttp/diagsvcs.cpp
@@ -17,8 +17,8 @@ namespace zen {
using namespace std::literals;
-bool
-ReadFile(const std::string& Path, StringBuilderBase& Out)
+static bool
+ReadLogFile(const std::string& Path, StringBuilderBase& Out)
{
try
{
@@ -57,10 +57,14 @@ HttpHealthService::HttpHealthService()
HttpServerRequest& HttpReq = RoutedReq.ServerRequest();
CbObjectWriter Writer;
- Writer << "DataRoot"sv << m_HealthInfo.DataRoot.string();
- Writer << "AbsLogPath"sv << m_HealthInfo.AbsLogPath.string();
- Writer << "BuildVersion"sv << m_HealthInfo.BuildVersion;
- Writer << "HttpServerClass"sv << m_HealthInfo.HttpServerClass;
+
+ {
+ RwLock::SharedLockScope _(m_InfoLock);
+ Writer << "DataRoot"sv << m_HealthInfo.DataRoot.string();
+ Writer << "AbsLogPath"sv << m_HealthInfo.AbsLogPath.string();
+ Writer << "BuildVersion"sv << m_HealthInfo.BuildVersion;
+ Writer << "HttpServerClass"sv << m_HealthInfo.HttpServerClass;
+ }
HttpReq.WriteResponse(HttpResponseCode::OK, Writer.Save());
},
@@ -73,11 +77,13 @@ HttpHealthService::HttpHealthService()
zen::Log().flush();
- std::filesystem::path Path =
- m_HealthInfo.AbsLogPath.empty() ? m_HealthInfo.DataRoot / "logs/zenserver.log" : m_HealthInfo.AbsLogPath;
+ std::filesystem::path Path = [&] {
+ RwLock::SharedLockScope _(m_InfoLock);
+ return m_HealthInfo.AbsLogPath.empty() ? m_HealthInfo.DataRoot / "logs/zenserver.log" : m_HealthInfo.AbsLogPath;
+ }();
ExtendableStringBuilder<4096> Sb;
- if (ReadFile(Path.string(), Sb) && Sb.Size() > 0)
+ if (ReadLogFile(Path.string(), Sb) && Sb.Size() > 0)
{
HttpReq.WriteResponse(HttpResponseCode::OK, HttpContentType::kText, Sb.ToView());
}
@@ -87,6 +93,7 @@ HttpHealthService::HttpHealthService()
}
},
HttpVerb::kGet);
+
m_Router.RegisterRoute(
"version",
[this](HttpRouterRequest& RoutedReq) {
@@ -106,6 +113,7 @@ HttpHealthService::HttpHealthService()
void
HttpHealthService::SetHealthInfo(HealthServiceInfo&& Info)
{
+ RwLock::ExclusiveLockScope _(m_InfoLock);
m_HealthInfo = std::move(Info);
}