aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/monlib/dynamic_counters
diff options
context:
space:
mode:
authornga <nga@yandex-team.ru>2022-02-10 16:48:09 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:48:09 +0300
commit1f553f46fb4f3c5eec631352cdd900a0709016af (patch)
treea231fba2c03b440becaea6c86a2702d0bfb0336e /library/cpp/monlib/dynamic_counters
parentc4de7efdedc25b49cbea74bd589eecb61b55b60a (diff)
downloadydb-1f553f46fb4f3c5eec631352cdd900a0709016af.tar.gz
Restoring authorship annotation for <nga@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/monlib/dynamic_counters')
-rw-r--r--library/cpp/monlib/dynamic_counters/counters.cpp36
-rw-r--r--library/cpp/monlib/dynamic_counters/counters.h72
-rw-r--r--library/cpp/monlib/dynamic_counters/page.cpp20
-rw-r--r--library/cpp/monlib/dynamic_counters/page.h26
4 files changed, 77 insertions, 77 deletions
diff --git a/library/cpp/monlib/dynamic_counters/counters.cpp b/library/cpp/monlib/dynamic_counters/counters.cpp
index 3635d87d0d..8a73c388eb 100644
--- a/library/cpp/monlib/dynamic_counters/counters.cpp
+++ b/library/cpp/monlib/dynamic_counters/counters.cpp
@@ -2,10 +2,10 @@
#include <library/cpp/monlib/service/pages/templates.h>
-#include <util/generic/cast.h>
-
-using namespace NMonitoring;
-
+#include <util/generic/cast.h>
+
+using namespace NMonitoring;
+
namespace {
TDynamicCounters* AsDynamicCounters(const TIntrusivePtr<TCountableBase>& ptr) {
return dynamic_cast<TDynamicCounters*>(ptr.Get());
@@ -53,7 +53,7 @@ TDynamicCounters::TDynamicCounters(EVisibility vis)
TDynamicCounters::~TDynamicCounters() {
}
-
+
TDynamicCounters::TCounterPtr TDynamicCounters::GetExpiringCounter(const TString& value, bool derivative, EVisibility vis) {
return GetExpiringNamedCounter("sensor", value, derivative, vis);
}
@@ -68,8 +68,8 @@ TDynamicCounters::TCounterPtr TDynamicCounters::GetCounter(const TString& value,
TDynamicCounters::TCounterPtr TDynamicCounters::GetNamedCounter(const TString& name, const TString& value, bool derivative, EVisibility vis) {
return AsCounterRef(GetNamedCounterImpl<false, TCounterForPtr>(name, value, derivative, vis));
-}
-
+}
+
THistogramPtr TDynamicCounters::GetHistogram(const TString& value, IHistogramCollectorPtr collector, bool derivative, EVisibility vis) {
return GetNamedHistogram("sensor", value, std::move(collector), derivative, vis);
}
@@ -126,7 +126,7 @@ TIntrusivePtr<TDynamicCounters> TDynamicCounters::GetSubgroup(const TString& nam
}
}
return res;
-}
+}
TIntrusivePtr<TDynamicCounters> TDynamicCounters::FindSubgroup(const TString& name, const TString& value) const {
TReadGuard g(Lock);
@@ -186,7 +186,7 @@ void TDynamicCounters::RegisterSubgroup(const TString& name, const TString& valu
void TDynamicCounters::OutputHtml(IOutputStream& os) const {
HTML(os) {
PRE() {
- OutputPlainText(os);
+ OutputPlainText(os);
}
}
}
@@ -199,7 +199,7 @@ void TDynamicCounters::EnumerateSubgroups(const std::function<void(const TString
}
}
}
-
+
void TDynamicCounters::OutputPlainText(IOutputStream& os, const TString& indent) const {
auto snap = ReadSnapshot();
// mark private records in plain text output
@@ -232,18 +232,18 @@ void TDynamicCounters::OutputPlainText(IOutputStream& os, const TString& indent)
}
os << ": " << snapshot->Value(i) << '\n';
}
- }
- }
-
+ }
+ }
+
for (const auto& [key, value] : snap) {
if (const auto subgroup = AsDynamicCounters(value)) {
- os << "\n";
+ os << "\n";
os << indent << key.LabelName << "=" << key.LabelValue << ":\n";
subgroup->OutputPlainText(os, indent + INDENT);
- }
- }
-}
-
+ }
+ }
+}
+
void TDynamicCounters::Accept(const TString& labelName, const TString& labelValue, ICountableConsumer& consumer) const {
if (!IsVisible(Visibility(), consumer.Visibility())) {
return;
diff --git a/library/cpp/monlib/dynamic_counters/counters.h b/library/cpp/monlib/dynamic_counters/counters.h
index dc178cfbe0..548e92ef39 100644
--- a/library/cpp/monlib/dynamic_counters/counters.h
+++ b/library/cpp/monlib/dynamic_counters/counters.h
@@ -1,5 +1,5 @@
-#pragma once
-
+#pragma once
+
#include <library/cpp/monlib/counters/counters.h>
#include <library/cpp/monlib/metrics/histogram_collector.h>
@@ -7,14 +7,14 @@
#include <library/cpp/containers/stack_vector/stack_vec.h>
#include <util/generic/cast.h>
-#include <util/generic/map.h>
-#include <util/generic/ptr.h>
+#include <util/generic/map.h>
+#include <util/generic/ptr.h>
#include <util/string/cast.h>
#include <util/system/rwlock.h>
#include <functional>
-
-namespace NMonitoring {
+
+namespace NMonitoring {
struct TCounterForPtr;
struct TDynamicCounters;
struct ICountableConsumer;
@@ -44,8 +44,8 @@ namespace NMonitoring {
protected:
EVisibility Visibility_{EVisibility::Unspecified};
- };
-
+ };
+
inline bool IsVisible(TCountableBase::EVisibility myLevel, TCountableBase::EVisibility consumerLevel) {
if (myLevel == TCountableBase::EVisibility::Private
&& consumerLevel != TCountableBase::EVisibility::Private) {
@@ -114,8 +114,8 @@ namespace NMonitoring {
using TDeprecatedCounter::operator-=;
using TDeprecatedCounter::operator=;
using TDeprecatedCounter::operator!;
- };
-
+ };
+
struct TExpiringCounter: public TCounterForPtr {
explicit TExpiringCounter(bool derivative = false, EVisibility vis = EVisibility::Public)
: TCounterForPtr{derivative}
@@ -185,34 +185,34 @@ namespace NMonitoring {
#pragma warning(pop)
#endif
- struct TDynamicCounters;
-
- typedef TIntrusivePtr<TDynamicCounters> TDynamicCounterPtr;
- struct TDynamicCounters: public TCountableBase {
- public:
+ struct TDynamicCounters;
+
+ typedef TIntrusivePtr<TDynamicCounters> TDynamicCounterPtr;
+ struct TDynamicCounters: public TCountableBase {
+ public:
using TCounterPtr = TIntrusivePtr<TCounterForPtr>;
using TOnLookupPtr = void (*)(const char *methodName, const TString &name, const TString &value);
-
- private:
+
+ private:
TRWMutex Lock;
TCounterPtr LookupCounter; // Counts lookups by name
TOnLookupPtr OnLookup = nullptr; // Called on each lookup if not nullptr, intended for lightweight tracing.
-
- typedef TIntrusivePtr<TCountableBase> TCountablePtr;
-
- struct TChildId {
+
+ typedef TIntrusivePtr<TCountableBase> TCountablePtr;
+
+ struct TChildId {
TString LabelName;
TString LabelValue;
TChildId() {
}
TChildId(const TString& labelName, const TString& labelValue)
- : LabelName(labelName)
- , LabelValue(labelValue)
- {
- }
+ : LabelName(labelName)
+ , LabelValue(labelValue)
+ {
+ }
auto AsTuple() const {
return std::make_tuple(std::cref(LabelName), std::cref(LabelValue));
- }
+ }
friend bool operator <(const TChildId& x, const TChildId& y) {
return x.AsTuple() < y.AsTuple();
}
@@ -222,8 +222,8 @@ namespace NMonitoring {
friend bool operator !=(const TChildId& x, const TChildId& y) {
return x.AsTuple() != y.AsTuple();
}
- };
-
+ };
+
using TCounters = TMap<TChildId, TCountablePtr>;
using TLabels = TVector<TChildId>;
@@ -231,7 +231,7 @@ namespace NMonitoring {
mutable TCounters Counters;
mutable TAtomic ExpiringCount = 0;
- public:
+ public:
TDynamicCounters(TCountableBase::EVisibility visibility = TCountableBase::EVisibility::Public);
TDynamicCounters(const TDynamicCounters *origin)
@@ -240,7 +240,7 @@ namespace NMonitoring {
{}
~TDynamicCounters() override;
-
+
// This counter allows to track lookups by name within the whole subtree
void SetLookupCounter(TCounterPtr lookupCounter) {
TWriteGuard g(Lock);
@@ -328,7 +328,7 @@ namespace NMonitoring {
void RemoveCounter(const TString &value);
void RemoveNamedCounter(const TString& name, const TString &value);
-
+
TIntrusivePtr<TDynamicCounters> GetSubgroup(const TString& name, const TString& value);
TIntrusivePtr<TDynamicCounters> FindSubgroup(const TString& name, const TString& value) const;
void RemoveSubgroup(const TString& name, const TString& value);
@@ -348,12 +348,12 @@ namespace NMonitoring {
// mostly for debugging purposes -- use accept with encoder instead
void OutputPlainText(IOutputStream& os, const TString& indent = "") const;
-
+
void Accept(
const TString& labelName, const TString& labelValue,
ICountableConsumer& consumer) const override;
- private:
+ private:
TCounters Resign() {
TCounters counters;
TWriteGuard g(Lock);
@@ -369,6 +369,6 @@ namespace NMonitoring {
template <class TCounterType>
TCountablePtr FindNamedCounterImpl(const TString& name, const TString& value) const;
- };
-
-}
+ };
+
+}
diff --git a/library/cpp/monlib/dynamic_counters/page.cpp b/library/cpp/monlib/dynamic_counters/page.cpp
index 5124a47bb3..2ddc74bd88 100644
--- a/library/cpp/monlib/dynamic_counters/page.cpp
+++ b/library/cpp/monlib/dynamic_counters/page.cpp
@@ -1,14 +1,14 @@
#include "page.h"
#include "encode.h"
-
+
#include <library/cpp/monlib/service/pages/templates.h>
#include <library/cpp/string_utils/quote/quote.h>
#include <util/string/split.h>
#include <util/system/tls.h>
-
-using namespace NMonitoring;
-
+
+using namespace NMonitoring;
+
namespace {
Y_POD_STATIC_THREAD(TDynamicCounters*)
currentCounters(nullptr);
@@ -74,10 +74,10 @@ void TDynamicCountersPage::Output(NMonitoring::IMonHttpRequest& request) {
if (!format) {
currentCounters = counters.Get();
- THtmlMonPage::Output(request);
+ THtmlMonPage::Output(request);
currentCounters = nullptr;
return;
- }
+ }
IOutputStream& out = request.Output();
if (*format == EFormat::JSON) {
@@ -93,7 +93,7 @@ void TDynamicCountersPage::Output(NMonitoring::IMonHttpRequest& request) {
auto encoder = CreateEncoder(&out, *format, visibility);
counters->Accept(TString(), TString(), *encoder);
out.Flush();
-}
+}
void TDynamicCountersPage::HandleAbsentSubgroup(IMonHttpRequest& request) {
if (UnknownGroupPolicy == EUnknownGroupPolicy::Error) {
@@ -110,7 +110,7 @@ void TDynamicCountersPage::BeforePre(IMonHttpRequest& request) {
HTML(out) {
DIV() {
out << "<a href='" << request.GetPath() << "/json'>Counters as JSON</a>";
- out << " for <a href='https://wiki.yandex-team.ru/solomon/'>Solomon</a>";
+ out << " for <a href='https://wiki.yandex-team.ru/solomon/'>Solomon</a>";
}
H5() {
@@ -131,10 +131,10 @@ void TDynamicCountersPage::BeforePre(IMonHttpRequest& request) {
}
}
}
-
+
void TDynamicCountersPage::OutputText(IOutputStream& out, IMonHttpRequest&) {
currentCounters->OutputPlainText(out);
-}
+}
void TDynamicCountersPage::SetUnknownGroupPolicy(EUnknownGroupPolicy value) {
UnknownGroupPolicy = value;
diff --git a/library/cpp/monlib/dynamic_counters/page.h b/library/cpp/monlib/dynamic_counters/page.h
index 1f0ef6a5ea..c318ded739 100644
--- a/library/cpp/monlib/dynamic_counters/page.h
+++ b/library/cpp/monlib/dynamic_counters/page.h
@@ -1,24 +1,24 @@
-#pragma once
-
+#pragma once
+
#include "counters.h"
#include <library/cpp/monlib/service/pages/pre_mon_page.h>
-#include <util/generic/ptr.h>
-
+#include <util/generic/ptr.h>
+
#include <functional>
-
-namespace NMonitoring {
+
+namespace NMonitoring {
enum class EUnknownGroupPolicy {
Error, // send 404
Ignore, // send 204
};
- struct TDynamicCountersPage: public TPreMonPage {
+ struct TDynamicCountersPage: public TPreMonPage {
public:
using TOutputCallback = std::function<void()>;
- private:
+ private:
const TIntrusivePtr<TDynamicCounters> Counters;
TOutputCallback OutputCallback;
EUnknownGroupPolicy UnknownGroupPolicy {EUnknownGroupPolicy::Error};
@@ -26,19 +26,19 @@ namespace NMonitoring {
private:
void HandleAbsentSubgroup(IMonHttpRequest& request);
- public:
+ public:
TDynamicCountersPage(const TString& path,
const TString& title,
TIntrusivePtr<TDynamicCounters> counters,
TOutputCallback outputCallback = nullptr)
: TPreMonPage(path, title)
- , Counters(counters)
+ , Counters(counters)
, OutputCallback(outputCallback)
{
}
-
+
void Output(NMonitoring::IMonHttpRequest& request) override;
-
+
void BeforePre(NMonitoring::IMonHttpRequest& request) override;
void OutputText(IOutputStream& out, NMonitoring::IMonHttpRequest&) override;
@@ -47,4 +47,4 @@ namespace NMonitoring {
/// If set to Ignore, responds with 204 if the requested subgroup is not found
void SetUnknownGroupPolicy(EUnknownGroupPolicy value);
};
-}
+}