aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormonster <monster@yandex-team.ru>2022-04-18 18:40:01 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-04-18 18:40:01 +0300
commita29b2dd13e50bb8157853eabc42eaf54ca6a6b6a (patch)
tree4b62aa73bfc21269884f61a6984d037cece58bca
parenta082789ff18782ef5eaefb1d973289bf4e4b93d8 (diff)
downloadydb-a29b2dd13e50bb8157853eabc42eaf54ca6a6b6a.tar.gz
add name_label page parameter for prometheus format KIKIMR-14564
REVIEW: 2409698 REVIEW: 2411265 x-ydb-stable-ref: d99e0a3a39cc18795ae54e62bddde7afe498eed2
-rw-r--r--library/cpp/monlib/dynamic_counters/encode.cpp6
-rw-r--r--library/cpp/monlib/dynamic_counters/encode.h1
-rw-r--r--library/cpp/monlib/dynamic_counters/page.cpp12
3 files changed, 16 insertions, 3 deletions
diff --git a/library/cpp/monlib/dynamic_counters/encode.cpp b/library/cpp/monlib/dynamic_counters/encode.cpp
index ffa48d276e..26328a44ee 100644
--- a/library/cpp/monlib/dynamic_counters/encode.cpp
+++ b/library/cpp/monlib/dynamic_counters/encode.cpp
@@ -95,7 +95,9 @@ namespace NMonitoring {
}
- THolder<ICountableConsumer> CreateEncoder(IOutputStream* out, EFormat format, TCountableBase::EVisibility vis) {
+ THolder<ICountableConsumer> CreateEncoder(IOutputStream* out, EFormat format,
+ TStringBuf nameLabel, TCountableBase::EVisibility vis)
+ {
switch (format) {
case EFormat::JSON:
return MakeHolder<TConsumer>(NMonitoring::EncoderJson(out), vis);
@@ -106,7 +108,7 @@ namespace NMonitoring {
NMonitoring::ECompression::ZSTD), vis);
case EFormat::PROMETHEUS:
return MakeHolder<TConsumer>(NMonitoring::EncoderPrometheus(
- out), vis);
+ out, nameLabel), vis);
default:
ythrow yexception() << "unsupported metric encoding format: " << format;
break;
diff --git a/library/cpp/monlib/dynamic_counters/encode.h b/library/cpp/monlib/dynamic_counters/encode.h
index c79964d7cb..bc39fc0029 100644
--- a/library/cpp/monlib/dynamic_counters/encode.h
+++ b/library/cpp/monlib/dynamic_counters/encode.h
@@ -10,6 +10,7 @@ namespace NMonitoring {
THolder<ICountableConsumer> CreateEncoder(
IOutputStream* out,
EFormat format,
+ TStringBuf nameLabel = "sensor",
TCountableBase::EVisibility visibility = TCountableBase::EVisibility::Public
);
diff --git a/library/cpp/monlib/dynamic_counters/page.cpp b/library/cpp/monlib/dynamic_counters/page.cpp
index 5124a47bb3..b116adfdef 100644
--- a/library/cpp/monlib/dynamic_counters/page.cpp
+++ b/library/cpp/monlib/dynamic_counters/page.cpp
@@ -31,6 +31,7 @@ void TDynamicCountersPage::Output(NMonitoring::IMonHttpRequest& request) {
OutputCallback();
}
+ TString nameLabel("sensor");
TCountableBase::EVisibility visibility{
TCountableBase::EVisibility::Public
};
@@ -46,6 +47,15 @@ void TDynamicCountersPage::Output(NMonitoring::IMonHttpRequest& request) {
parts.pop_back();
}
+ if (!parts.empty() && parts.back().StartsWith(TStringBuf("name_label="))) {
+ TVector<TString> labels;
+ StringSplitter(parts.back()).Split('=').SkipEmpty().Collect(&labels);
+ if (labels.size() == 2U) {
+ nameLabel = labels.back();
+ }
+ parts.pop_back();
+ }
+
if (!parts.empty() && parts.back() == TStringBuf("private")) {
visibility = TCountableBase::EVisibility::Private;
parts.pop_back();
@@ -90,7 +100,7 @@ void TDynamicCountersPage::Output(NMonitoring::IMonHttpRequest& request) {
ythrow yexception() << "unsupported metric encoding format: " << *format;
}
- auto encoder = CreateEncoder(&out, *format, visibility);
+ auto encoder = CreateEncoder(&out, *format, nameLabel, visibility);
counters->Accept(TString(), TString(), *encoder);
out.Flush();
}