Skip to content

Commit

Permalink
Improve NW and distconf HTML monitoring (#14854)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexvru authored Feb 20, 2025
1 parent 90a6e27 commit bd6334d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
4 changes: 1 addition & 3 deletions ydb/core/blobstorage/nodewarden/distconf_mon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,8 @@ namespace NKikimr::NStorage {
}
DIV_CLASS("panel-body") {
if (config) {
TString s;
NProtoBuf::TextFormat::PrintToString(*config, &s);
out << "<pre>";
EscapeHtmlString(out, s);
OutputPrettyMessage(out, *config);
out << "</pre>";
} else {
out << "not defined";
Expand Down
1 change: 1 addition & 0 deletions ydb/core/blobstorage/nodewarden/node_warden_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@ namespace NKikimr::NStorage {
TString *errorReason);

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

}

Expand Down
40 changes: 31 additions & 9 deletions ydb/core/blobstorage/nodewarden/node_warden_mon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,28 +106,22 @@ void TNodeWarden::RenderWholePage(IOutputStream& out) {
TAG(TH3) { out << "StorageConfig"; }
DIV() {
out << "<p>Self-management enabled: " << (SelfManagementEnabled ? "yes" : "no") << "</p>";
TString s;
NProtoBuf::TextFormat::PrintToString(StorageConfig, &s);
out << "<pre>";
EscapeHtmlString(out, s);
OutputPrettyMessage(out, StorageConfig);
out << "</pre>";
}

TAG(TH3) { out << "Static service set"; }
DIV() {
TString s;
NProtoBuf::TextFormat::PrintToString(StaticServices, &s);
out << "<pre>";
EscapeHtmlString(out, s);
OutputPrettyMessage(out, StaticServices);
out << "</pre>";
}

TAG(TH3) { out << "Dynamic service set"; }
DIV() {
TString s;
NProtoBuf::TextFormat::PrintToString(DynamicServices, &s);
out << "<pre>";
EscapeHtmlString(out, s);
OutputPrettyMessage(out, DynamicServices);
out << "</pre>";
}

Expand Down Expand Up @@ -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<size_t>(value.size(), maxPrintedLen); ++i) {
if (i) {
newValue << ' ';
}
newValue << Sprintf("%02x", static_cast<std::byte>(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);
}

0 comments on commit bd6334d

Please sign in to comment.