Skip to content

Commit bd6334d

Browse files
authored
Improve NW and distconf HTML monitoring (#14854)
1 parent 90a6e27 commit bd6334d

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

ydb/core/blobstorage/nodewarden/distconf_mon.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,8 @@ namespace NKikimr::NStorage {
170170
}
171171
DIV_CLASS("panel-body") {
172172
if (config) {
173-
TString s;
174-
NProtoBuf::TextFormat::PrintToString(*config, &s);
175173
out << "<pre>";
176-
EscapeHtmlString(out, s);
174+
OutputPrettyMessage(out, *config);
177175
out << "</pre>";
178176
} else {
179177
out << "not defined";

ydb/core/blobstorage/nodewarden/node_warden_impl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,7 @@ namespace NKikimr::NStorage {
685685
TString *errorReason);
686686

687687
void EscapeHtmlString(IOutputStream& out, const TString& s);
688+
void OutputPrettyMessage(IOutputStream& out, const NProtoBuf::Message& message);
688689

689690
}
690691

ydb/core/blobstorage/nodewarden/node_warden_mon.cpp

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,28 +106,22 @@ void TNodeWarden::RenderWholePage(IOutputStream& out) {
106106
TAG(TH3) { out << "StorageConfig"; }
107107
DIV() {
108108
out << "<p>Self-management enabled: " << (SelfManagementEnabled ? "yes" : "no") << "</p>";
109-
TString s;
110-
NProtoBuf::TextFormat::PrintToString(StorageConfig, &s);
111109
out << "<pre>";
112-
EscapeHtmlString(out, s);
110+
OutputPrettyMessage(out, StorageConfig);
113111
out << "</pre>";
114112
}
115113

116114
TAG(TH3) { out << "Static service set"; }
117115
DIV() {
118-
TString s;
119-
NProtoBuf::TextFormat::PrintToString(StaticServices, &s);
120116
out << "<pre>";
121-
EscapeHtmlString(out, s);
117+
OutputPrettyMessage(out, StaticServices);
122118
out << "</pre>";
123119
}
124120

125121
TAG(TH3) { out << "Dynamic service set"; }
126122
DIV() {
127-
TString s;
128-
NProtoBuf::TextFormat::PrintToString(DynamicServices, &s);
129123
out << "<pre>";
130-
EscapeHtmlString(out, s);
124+
OutputPrettyMessage(out, DynamicServices);
131125
out << "</pre>";
132126
}
133127

@@ -406,3 +400,31 @@ void NKikimr::NStorage::EscapeHtmlString(IOutputStream& out, const TString& s) {
406400
}
407401
dump(s.size());
408402
}
403+
404+
void NKikimr::NStorage::OutputPrettyMessage(IOutputStream& out, const NProtoBuf::Message& message) {
405+
class TFieldPrinter : public NProtoBuf::TextFormat::FastFieldValuePrinter {
406+
public:
407+
void PrintBytes(const TProtoStringType& value, NProtoBuf::TextFormat::BaseTextGenerator *generator) const override {
408+
TStringStream newValue;
409+
constexpr size_t maxPrintedLen = 32;
410+
for (size_t i = 0; i < Min<size_t>(value.size(), maxPrintedLen); ++i) {
411+
if (i) {
412+
newValue << ' ';
413+
}
414+
newValue << Sprintf("%02x", static_cast<std::byte>(value[i]));
415+
}
416+
if (value.size() > maxPrintedLen) {
417+
newValue << " ... (total " << value.size() << " bytes)";
418+
}
419+
TString& s = newValue.Str();
420+
generator->Print(s.data(), s.size());
421+
}
422+
};
423+
424+
NProtoBuf::TextFormat::Printer p;
425+
p.SetDefaultFieldValuePrinter(new TFieldPrinter);
426+
427+
TString s;
428+
p.PrintToString(message, &s);
429+
EscapeHtmlString(out, s);
430+
}

0 commit comments

Comments
 (0)