aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/messagebus/message_status_counter.cpp
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/messagebus/message_status_counter.cpp
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/messagebus/message_status_counter.cpp')
-rw-r--r--library/cpp/messagebus/message_status_counter.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/library/cpp/messagebus/message_status_counter.cpp b/library/cpp/messagebus/message_status_counter.cpp
new file mode 100644
index 0000000000..891c8f5bb2
--- /dev/null
+++ b/library/cpp/messagebus/message_status_counter.cpp
@@ -0,0 +1,71 @@
+#include "message_status_counter.h"
+
+#include "key_value_printer.h"
+#include "text_utils.h"
+
+#include <library/cpp/messagebus/monitoring/mon_proto.pb.h>
+
+#include <util/stream/str.h>
+
+using namespace NBus;
+using namespace NBus::NPrivate;
+
+TMessageStatusCounter::TMessageStatusCounter() {
+ Zero(Counts);
+}
+
+TMessageStatusCounter& TMessageStatusCounter::operator+=(const TMessageStatusCounter& that) {
+ for (size_t i = 0; i < MESSAGE_STATUS_COUNT; ++i) {
+ Counts[i] += that.Counts[i];
+ }
+ return *this;
+}
+
+TString TMessageStatusCounter::PrintToString() const {
+ TStringStream ss;
+ TKeyValuePrinter p;
+ bool hasNonZeros = false;
+ bool hasZeros = false;
+ for (size_t i = 0; i < MESSAGE_STATUS_COUNT; ++i) {
+ if (i == MESSAGE_OK) {
+ Y_VERIFY(Counts[i] == 0);
+ continue;
+ }
+ if (Counts[i] != 0) {
+ p.AddRow(EMessageStatus(i), Counts[i]);
+ const char* description = MessageStatusDescription(EMessageStatus(i));
+ // TODO: add third column
+ Y_UNUSED(description);
+
+ hasNonZeros = true;
+ } else {
+ hasZeros = true;
+ }
+ }
+ if (!hasNonZeros) {
+ ss << "message status counts are zeros\n";
+ } else {
+ if (hasZeros) {
+ ss << "message status counts are zeros, except:\n";
+ } else {
+ ss << "message status counts:\n";
+ }
+ ss << IndentText(p.PrintToString());
+ }
+ return ss.Str();
+}
+
+void TMessageStatusCounter::FillErrorsProtobuf(TConnectionStatusMonRecord* status) const {
+ status->clear_errorcountbystatus();
+ for (size_t i = 0; i < MESSAGE_STATUS_COUNT; ++i) {
+ if (i == MESSAGE_OK) {
+ Y_VERIFY(Counts[i] == 0);
+ continue;
+ }
+ if (Counts[i] != 0) {
+ TMessageStatusRecord* description = status->add_errorcountbystatus();
+ description->SetStatus(TMessageStatusCounter::MessageStatusToProtobuf((EMessageStatus)i));
+ description->SetCount(Counts[i]);
+ }
+ }
+}