summaryrefslogtreecommitdiffstats
path: root/library/cpp/monlib/encode/prometheus/prometheus_decoder.cpp
diff options
context:
space:
mode:
authorvvminashkin <[email protected]>2026-03-02 12:13:39 +0300
committervvminashkin <[email protected]>2026-03-02 13:04:29 +0300
commitb065a51848d90f8131a4861ebd6ec4f4e79f548f (patch)
tree908bccce181c50611bf891daded56c1fbbd35b39 /library/cpp/monlib/encode/prometheus/prometheus_decoder.cpp
parent49c8ec452cfb6220fc817bbb4d4667e440060ce0 (diff)
[cpp/monlib] add ability to mangle name in prometheus decoder
commit_hash:ef6584bf0941f50d0833dacd3b5d14cfc1cd30a8
Diffstat (limited to 'library/cpp/monlib/encode/prometheus/prometheus_decoder.cpp')
-rw-r--r--library/cpp/monlib/encode/prometheus/prometheus_decoder.cpp23
1 files changed, 18 insertions, 5 deletions
diff --git a/library/cpp/monlib/encode/prometheus/prometheus_decoder.cpp b/library/cpp/monlib/encode/prometheus/prometheus_decoder.cpp
index 5ccc854cab2..c74fc9f4a82 100644
--- a/library/cpp/monlib/encode/prometheus/prometheus_decoder.cpp
+++ b/library/cpp/monlib/encode/prometheus/prometheus_decoder.cpp
@@ -525,14 +525,27 @@ namespace NMonitoring {
}
void ConsumeLabels(TStringBuf name, const TLabelsMap& labels) {
- Y_PARSER_ENSURE(labels.count(MetricNameLabel_) == 0,
- "label name '" << MetricNameLabel_ <<
- "' is reserved, but is used with metric: " << name << LabelsToStr(labels));
+ auto it = labels.find(MetricNameLabel_);
+ if(it != labels.end() && !Settings_.NameMangler) {
+ Y_PARSER_ENSURE(false,
+ "label name '" << MetricNameLabel_ <<
+ "' is reserved, but is used with metric: " << name << LabelsToStr(labels));
+ }
+ const bool labelClashPresent = it != labels.end();
Consumer_->OnLabelsBegin();
Consumer_->OnLabel(MetricNameLabel_, TString(name)); // TODO: remove this string allocation
- for (const auto& it: labels) {
- Consumer_->OnLabel(it.first, it.second);
+ for (const auto& [k, v]: labels) {
+ if(labelClashPresent && k == MetricNameLabel_) {
+ auto newKey = Settings_.NameMangler(k);
+ Y_PARSER_ENSURE(!labels.contains(newKey),
+ "after mangling label name: " << MetricNameLabel_ <<
+ " the resulting label is: " << newKey <<
+ "but it is already used in: " << LabelsToStr(labels));
+ Consumer_->OnLabel(newKey, v);
+ continue;
+ }
+ Consumer_->OnLabel(k, v);
}
Consumer_->OnLabelsEnd();
}