summaryrefslogtreecommitdiffstats
path: root/library/cpp/monlib/encode/prometheus/prometheus_decoder.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'library/cpp/monlib/encode/prometheus/prometheus_decoder.cpp')
-rw-r--r--library/cpp/monlib/encode/prometheus/prometheus_decoder.cpp28
1 files changed, 18 insertions, 10 deletions
diff --git a/library/cpp/monlib/encode/prometheus/prometheus_decoder.cpp b/library/cpp/monlib/encode/prometheus/prometheus_decoder.cpp
index d1d0d9e0f22..313651ba8fa 100644
--- a/library/cpp/monlib/encode/prometheus/prometheus_decoder.cpp
+++ b/library/cpp/monlib/encode/prometheus/prometheus_decoder.cpp
@@ -71,6 +71,9 @@ namespace NMonitoring {
using TBucketData = std::pair<TBucketBound, TBucketValue>;
constexpr static TBucketData ZERO_BUCKET = { -std::numeric_limits<TBucketBound>::max(), 0 };
public:
+ THistogramBuilder(TPrometheusDecodeSettings settings)
+ : Settings_(settings) {
+ }
TStringBuf GetName() const noexcept {
return Name_;
}
@@ -125,7 +128,6 @@ namespace NMonitoring {
Bounds_.push_back(bound);
Values_.push_back(value - PrevBucket_.second); // keep only delta between buckets
-
PrevBucket_ = { bound, value };
}
@@ -150,6 +152,7 @@ namespace NMonitoring {
TBucketBounds Bounds_;
TBucketValues Values_;
TBucketData PrevBucket_ = ZERO_BUCKET;
+ TPrometheusDecodeSettings Settings_;
};
///////////////////////////////////////////////////////////////////////
@@ -168,10 +171,12 @@ namespace NMonitoring {
///////////////////////////////////////////////////////////////////////
class TPrometheusReader {
public:
- TPrometheusReader(TStringBuf data, IMetricConsumer* c, TStringBuf metricNameLabel)
+ TPrometheusReader(TStringBuf data, IMetricConsumer* c, TStringBuf metricNameLabel, const TPrometheusDecodeSettings& settings = TPrometheusDecodeSettings{})
: Data_(data)
, Consumer_(c)
, MetricNameLabel_(metricNameLabel)
+ , Settings_(settings)
+ , HistogramBuilder_(settings)
{
}
@@ -272,12 +277,14 @@ namespace NMonitoring {
TStringBuf baseName = name;
EPrometheusMetricType type = EPrometheusMetricType::UNTYPED;
- if (auto* seenType = SeenTypes_.FindPtr(name)) {
- type = *seenType;
- } else {
- baseName = NPrometheus::ToBaseName(name);
- if (auto* baseType = SeenTypes_.FindPtr(baseName)) {
- type = *baseType;
+ if (Settings_.Mode != EPrometheusDecodeMode::RAW) {
+ if (auto* seenType = SeenTypes_.FindPtr(name)) {
+ type = *seenType;
+ } else {
+ baseName = NPrometheus::ToBaseName(name);
+ if (auto* baseType = SeenTypes_.FindPtr(baseName)) {
+ type = *baseType;
+ }
}
}
@@ -584,6 +591,7 @@ namespace NMonitoring {
TStringBuf Data_;
IMetricConsumer* Consumer_;
TStringBuf MetricNameLabel_;
+ TPrometheusDecodeSettings Settings_;
THashMap<TString, EPrometheusMetricType> SeenTypes_;
THistogramBuilder HistogramBuilder_;
@@ -593,8 +601,8 @@ namespace NMonitoring {
};
} // namespace
-void DecodePrometheus(TStringBuf data, IMetricConsumer* c, TStringBuf metricNameLabel) {
- TPrometheusReader reader(data, c, metricNameLabel);
+void DecodePrometheus(TStringBuf data, IMetricConsumer* c, TStringBuf metricNameLabel, const TPrometheusDecodeSettings& settings) {
+ TPrometheusReader reader(data, c, metricNameLabel, settings);
reader.Read();
}