aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/monlib
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 /library/cpp/monlib
parent0abb29c131758b92583251c6051e12add7083c29 (diff)
downloadydb-17a85ebbecab569ae12788ada1352c56cc9b1e1c.tar.gz
Improve monitoring
Diffstat (limited to 'library/cpp/monlib')
-rw-r--r--library/cpp/monlib/service/pages/index_mon_page.cpp23
-rw-r--r--library/cpp/monlib/service/pages/index_mon_page.h8
2 files changed, 13 insertions, 18 deletions
diff --git a/library/cpp/monlib/service/pages/index_mon_page.cpp b/library/cpp/monlib/service/pages/index_mon_page.cpp
index 2bfa0faca8..c9b2f82cc0 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 af96bcd2b9..0aaf826d46 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)