aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralexvru <alexvru@ydb.tech>2023-06-28 21:35:59 +0300
committeralexvru <alexvru@ydb.tech>2023-06-28 21:35:59 +0300
commit17a85ebbecab569ae12788ada1352c56cc9b1e1c (patch)
tree26ac0f41e343d831b2c97d7c77bd323323a34c90
parent0abb29c131758b92583251c6051e12add7083c29 (diff)
downloadydb-17a85ebbecab569ae12788ada1352c56cc9b1e1c.tar.gz
Improve monitoring
-rw-r--r--library/cpp/monlib/service/pages/index_mon_page.cpp23
-rw-r--r--library/cpp/monlib/service/pages/index_mon_page.h8
-rw-r--r--ydb/core/mon/async_http_mon.cpp12
-rw-r--r--ydb/core/mon/async_http_mon.h2
4 files changed, 23 insertions, 22 deletions
diff --git a/library/cpp/monlib/service/pages/index_mon_page.cpp b/library/cpp/monlib/service/pages/index_mon_page.cpp
index 2bfa0faca81..c9b2f82cc02 100644
--- a/library/cpp/monlib/service/pages/index_mon_page.cpp
+++ b/library/cpp/monlib/service/pages/index_mon_page.cpp
@@ -28,9 +28,8 @@ void TIndexMonPage::Output(IMonHttpRequest& request) {
TGuard<TMutex> g(Mtx);
TStringBuf pathTmp = request.GetPathInfo();
for (;;) {
- TPagesByPath::iterator i = PagesByPath.find(pathTmp);
- if (i != PagesByPath.end()) {
- found = i->second;
+ if (TPagesByPath::iterator i = PagesByPath.find(pathTmp); i != PagesByPath.end()) {
+ found = *i->second;
pathInfo = request.GetPathInfo().substr(pathTmp.size());
Y_VERIFY(pathInfo.empty() || pathInfo.StartsWith('/'));
break;
@@ -67,18 +66,12 @@ void TIndexMonPage::OutputIndex(IOutputStream& out, bool pathEndsWithSlash) {
void TIndexMonPage::Register(TMonPagePtr page) {
TGuard<TMutex> g(Mtx);
- auto insres = PagesByPath.insert(std::make_pair("/" + page->GetPath(), page));
- if (insres.second) {
- // new unique page just inserted, update Pages
- Pages.push_back(page);
+ if (auto [it, inserted] = PagesByPath.try_emplace("/" + page->GetPath()); inserted) {
+ // new unique page just inserted, insert it to the end
+ it->second = Pages.insert(Pages.end(), page);
} else {
// a page with the given path is already present, replace it with the new page
-
- // find old page, sorry for O(n)
- auto it = std::find(Pages.begin(), Pages.end(), insres.first->second);
- *it = page;
- // this already present, replace it
- insres.first->second = page;
+ *it->second = page;
}
page->Parent = this;
}
@@ -101,7 +94,7 @@ IMonPage* TIndexMonPage::FindPage(const TString& relativePath) {
if (i == PagesByPath.end()) {
return nullptr;
} else {
- return i->second.Get();
+ return i->second->Get();
}
}
@@ -171,7 +164,7 @@ void TIndexMonPage::OutputBody(IMonHttpRequest& req) {
void TIndexMonPage::SortPages() {
TGuard<TMutex> g(Mtx);
- std::sort(Pages.begin(), Pages.end(), [](const TMonPagePtr& a, const TMonPagePtr& b) {
+ Pages.sort([](const TMonPagePtr& a, const TMonPagePtr& b) {
return AsciiCompareIgnoreCase(a->GetTitle(), b->GetTitle()) < 0;
});
}
diff --git a/library/cpp/monlib/service/pages/index_mon_page.h b/library/cpp/monlib/service/pages/index_mon_page.h
index af96bcd2b9c..0aaf826d469 100644
--- a/library/cpp/monlib/service/pages/index_mon_page.h
+++ b/library/cpp/monlib/service/pages/index_mon_page.h
@@ -2,12 +2,14 @@
#include "mon_page.h"
+#include <list>
+
namespace NMonitoring {
struct TIndexMonPage: public IMonPage {
TMutex Mtx;
- typedef TVector<TMonPagePtr> TPages;
- TPages Pages;
- typedef THashMap<TString, TMonPagePtr> TPagesByPath;
+ using TPages = std::list<TMonPagePtr>;
+ TPages Pages; // a list of pages to maintain specific order
+ using TPagesByPath = THashMap<TString, TPages::iterator>;
TPagesByPath PagesByPath;
TIndexMonPage(const TString& path, const TString& title)
diff --git a/ydb/core/mon/async_http_mon.cpp b/ydb/core/mon/async_http_mon.cpp
index 369140fe998..fa5d69165a0 100644
--- a/ydb/core/mon/async_http_mon.cpp
+++ b/ydb/core/mon/async_http_mon.cpp
@@ -394,6 +394,7 @@ public:
STATEFN(StateWork) {
switch (ev->GetTypeRewrite()) {
hFunc(NHttp::TEvHttpProxy::TEvHttpIncomingRequest, Handle);
+ cFunc(TEvents::TSystem::Poison, PassAway);
}
}
@@ -458,6 +459,7 @@ public:
STATEFN(StateWork) {
switch (ev->GetTypeRewrite()) {
hFunc(NHttp::TEvHttpProxy::TEvHttpIncomingRequest, Handle);
+ cFunc(TEvents::TSystem::Poison, PassAway);
}
}
@@ -660,6 +662,7 @@ public:
switch (ev->GetTypeRewrite()) {
hFunc(NHttp::TEvHttpProxy::TEvHttpIncomingRequest, Handle);
hFunc(TEvMon::TEvMonitoringRequest, Handle);
+ cFunc(TEvents::TSystem::Poison, PassAway);
}
}
@@ -729,7 +732,7 @@ void TAsyncHttpMon::Stop() {
IndexMonPage->ClearPages(); // it's required to avoid loop-reference
if (ActorSystem) {
TGuard<TMutex> g(Mutex);
- for (const TActorId& actorId : ActorServices) {
+ for (const auto& [path, actorId] : ActorServices) {
ActorSystem->Send(actorId, new TEvents::TEvPoisonPill);
}
ActorSystem->Send(NodeProxyServiceActorId, new TEvents::TEvPoisonPill);
@@ -752,12 +755,15 @@ NMonitoring::TIndexMonPage* TAsyncHttpMon::RegisterIndexPage(const TString& path
void TAsyncHttpMon::RegisterActorMonPage(const TActorMonPageInfo& pageInfo) {
if (ActorSystem) {
TActorMonPage* actorMonPage = static_cast<TActorMonPage*>(pageInfo.Page.Get());
- auto actorId = ActorSystem->Register(
+ auto& actorId = ActorServices[pageInfo.Path];
+ if (actorId) {
+ ActorSystem->Send(new IEventHandle(TEvents::TSystem::Poison, 0, actorId, {}, nullptr, 0));
+ }
+ actorId = ActorSystem->Register(
new THttpMonServiceLegacyActor(actorMonPage),
TMailboxType::ReadAsFilled,
ActorSystem->AppData<NKikimr::TAppData>()->UserPoolId);
ActorSystem->Send(HttpProxyActorId, new NHttp::TEvHttpProxy::TEvRegisterHandler(pageInfo.Path, actorId));
- ActorServices.push_back(actorId);
}
}
diff --git a/ydb/core/mon/async_http_mon.h b/ydb/core/mon/async_http_mon.h
index aff58155b40..3bed45c1069 100644
--- a/ydb/core/mon/async_http_mon.h
+++ b/ydb/core/mon/async_http_mon.h
@@ -41,7 +41,7 @@ protected:
TMutex Mutex;
std::vector<TActorMonPageInfo> ActorMonPages;
- std::vector<TActorId> ActorServices;
+ THashMap<TString, TActorId> ActorServices;
void RegisterActorMonPage(const TActorMonPageInfo& pageInfo);
};