diff options
| author | xenoxeno <[email protected]> | 2026-03-10 11:24:41 +0300 |
|---|---|---|
| committer | xenoxeno <[email protected]> | 2026-03-10 11:45:02 +0300 |
| commit | a52478e475ee43363a4610f2b15a98f4c7468872 (patch) | |
| tree | 07bf721169b373708480a320e71e04dfd58f3bf7 /library/cpp/monlib/dynamic_counters | |
| parent | f55ee80f336b3317a4cd26605db7e997be2d20f9 (diff) | |
avoid clashing of counters params
commit_hash:1d15aa793cf4d50dfdab33d413cdb8480b35080a
Diffstat (limited to 'library/cpp/monlib/dynamic_counters')
| -rw-r--r-- | library/cpp/monlib/dynamic_counters/page.cpp | 64 | ||||
| -rw-r--r-- | library/cpp/monlib/dynamic_counters/ya.make | 1 |
2 files changed, 58 insertions, 7 deletions
diff --git a/library/cpp/monlib/dynamic_counters/page.cpp b/library/cpp/monlib/dynamic_counters/page.cpp index 5a660077121..7719d5d3e9a 100644 --- a/library/cpp/monlib/dynamic_counters/page.cpp +++ b/library/cpp/monlib/dynamic_counters/page.cpp @@ -1,6 +1,7 @@ #include "page.h" #include "encode.h" +#include <library/cpp/html/escape/escape.h> #include <library/cpp/monlib/service/pages/templates.h> #include <library/cpp/string_utils/quote/quote.h> @@ -70,8 +71,8 @@ void TDynamicCountersPage::Output(NMonitoring::IMonHttpRequest& request) { } else if (name == "@set") { set = value; } - } else { - parts.push_back(part); + } else if (name == "labels") { + StringSplitter(value).Split(',').SkipEmpty().AddTo(&parts); } return true; }); @@ -168,13 +169,51 @@ void TDynamicCountersPage::BeforePre(IMonHttpRequest& request) { IOutputStream& out = request.Output(); TStringBuf params = GetParams(request); TStringBuilder base; - base << Path << '?'; - if (!params.empty()) { - base << params << '&'; + TString labels; + bool wasParam = false; + base << Path; + StringSplitter(params).Split('&').SkipEmpty().Consume([&](TStringBuf part) { + TStringBuf name; + TStringBuf value; + part.Split('=', name, value); + if (name == "labels") { + if (!labels.empty()) { + labels += ','; + } + labels += value; + } + if (name != "labels") { + if (!wasParam) { + base << '?'; + wasParam = true; + } else { + base << '&'; + } + base << part; + } + }); + + if (!labels.empty()) { + if (!wasParam) { + base << '?'; + wasParam = true; + } else { + base << '&'; + } + base << "labels=" << labels; } + + const TString escapedBase = NHtml::EscapeAttributeValue(base); + HTML(out) { DIV() { - out << "<a href='" << base << "@format=json'>Counters as JSON</a>"; + out << "<a href=\"" << escapedBase; + if (!wasParam) { + out << '?'; + } else { + out << "&"; + } + out << "@format=json\">Counters as JSON</a>"; out << " for Solomon"; } @@ -188,7 +227,18 @@ void TDynamicCountersPage::BeforePre(IMonHttpRequest& request) { auto escValue = value; Quote(escName); Quote(escValue); - out << "\n<a href='" << base << escName << '=' << escValue << "'>" << name << " " << value << "</a>"; + out << "\n<a href=\"" << escapedBase; + if (labels.empty()) { + if (!wasParam) { + out << '?'; + } else { + out << "&"; + } + out << "labels="; + } else { + out << ','; + } + out << escName << '=' << escValue << "\">" << NHtml::EscapeText(name) << " " << NHtml::EscapeText(value) << "</a>"; } }); } diff --git a/library/cpp/monlib/dynamic_counters/ya.make b/library/cpp/monlib/dynamic_counters/ya.make index 67ad8e19483..18c73da5dcd 100644 --- a/library/cpp/monlib/dynamic_counters/ya.make +++ b/library/cpp/monlib/dynamic_counters/ya.make @@ -11,6 +11,7 @@ SRCS( PEERDIR( library/cpp/containers/stack_vector + library/cpp/html/escape library/cpp/monlib/encode/json library/cpp/monlib/encode/spack library/cpp/monlib/encode/prometheus |
