From bd6334dce34ab159d7970ab70a1abbb14ea25fe6 Mon Sep 17 00:00:00 2001 From: Alexander Rutkovsky Date: Thu, 20 Feb 2025 20:13:28 +0300 Subject: Improve NW and distconf HTML monitoring (#14854) --- ydb/core/blobstorage/nodewarden/distconf_mon.cpp | 4 +-- ydb/core/blobstorage/nodewarden/node_warden_impl.h | 1 + .../blobstorage/nodewarden/node_warden_mon.cpp | 40 +++++++++++++++++----- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/ydb/core/blobstorage/nodewarden/distconf_mon.cpp b/ydb/core/blobstorage/nodewarden/distconf_mon.cpp index a9e9b2e5d4a..2db211ff112 100644 --- a/ydb/core/blobstorage/nodewarden/distconf_mon.cpp +++ b/ydb/core/blobstorage/nodewarden/distconf_mon.cpp @@ -170,10 +170,8 @@ namespace NKikimr::NStorage { } DIV_CLASS("panel-body") { if (config) { - TString s; - NProtoBuf::TextFormat::PrintToString(*config, &s); out << "
";
-                                EscapeHtmlString(out, s);
+                                OutputPrettyMessage(out, *config);
                                 out << "
"; } else { out << "not defined"; diff --git a/ydb/core/blobstorage/nodewarden/node_warden_impl.h b/ydb/core/blobstorage/nodewarden/node_warden_impl.h index dbf9f7423cd..580ce60fe13 100644 --- a/ydb/core/blobstorage/nodewarden/node_warden_impl.h +++ b/ydb/core/blobstorage/nodewarden/node_warden_impl.h @@ -685,6 +685,7 @@ namespace NKikimr::NStorage { TString *errorReason); void EscapeHtmlString(IOutputStream& out, const TString& s); + void OutputPrettyMessage(IOutputStream& out, const NProtoBuf::Message& message); } diff --git a/ydb/core/blobstorage/nodewarden/node_warden_mon.cpp b/ydb/core/blobstorage/nodewarden/node_warden_mon.cpp index 8aa7d36c8bc..f10006ca2c8 100644 --- a/ydb/core/blobstorage/nodewarden/node_warden_mon.cpp +++ b/ydb/core/blobstorage/nodewarden/node_warden_mon.cpp @@ -106,28 +106,22 @@ void TNodeWarden::RenderWholePage(IOutputStream& out) { TAG(TH3) { out << "StorageConfig"; } DIV() { out << "

Self-management enabled: " << (SelfManagementEnabled ? "yes" : "no") << "

"; - TString s; - NProtoBuf::TextFormat::PrintToString(StorageConfig, &s); out << "
";
-            EscapeHtmlString(out, s);
+            OutputPrettyMessage(out, StorageConfig);
             out << "
"; } TAG(TH3) { out << "Static service set"; } DIV() { - TString s; - NProtoBuf::TextFormat::PrintToString(StaticServices, &s); out << "
";
-            EscapeHtmlString(out, s);
+            OutputPrettyMessage(out, StaticServices);
             out << "
"; } TAG(TH3) { out << "Dynamic service set"; } DIV() { - TString s; - NProtoBuf::TextFormat::PrintToString(DynamicServices, &s); out << "
";
-            EscapeHtmlString(out, s);
+            OutputPrettyMessage(out, DynamicServices);
             out << "
"; } @@ -406,3 +400,31 @@ void NKikimr::NStorage::EscapeHtmlString(IOutputStream& out, const TString& s) { } dump(s.size()); } + +void NKikimr::NStorage::OutputPrettyMessage(IOutputStream& out, const NProtoBuf::Message& message) { + class TFieldPrinter : public NProtoBuf::TextFormat::FastFieldValuePrinter { + public: + void PrintBytes(const TProtoStringType& value, NProtoBuf::TextFormat::BaseTextGenerator *generator) const override { + TStringStream newValue; + constexpr size_t maxPrintedLen = 32; + for (size_t i = 0; i < Min(value.size(), maxPrintedLen); ++i) { + if (i) { + newValue << ' '; + } + newValue << Sprintf("%02x", static_cast(value[i])); + } + if (value.size() > maxPrintedLen) { + newValue << " ... (total " << value.size() << " bytes)"; + } + TString& s = newValue.Str(); + generator->Print(s.data(), s.size()); + } + }; + + NProtoBuf::TextFormat::Printer p; + p.SetDefaultFieldValuePrinter(new TFieldPrinter); + + TString s; + p.PrintToString(message, &s); + EscapeHtmlString(out, s); +} -- cgit v1.3