aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrobot-piglet <robot-piglet@yandex-team.com>2024-08-08 22:17:02 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2024-08-08 22:26:03 +0300
commit3feede1c65c327a3412d4e312ec30cd4bc961fb6 (patch)
tree63e9283a5d0c88b551846a540a0280fc8b4a8452
parentb3b92751c90449515e067ead980c8c719f060e72 (diff)
downloadydb-3feede1c65c327a3412d4e312ec30cd4bc961fb6.tar.gz
Intermediate changes
-rw-r--r--library/python/monlib/encoder.pxd6
-rw-r--r--library/python/monlib/encoder.pyx21
-rw-r--r--library/python/monlib/ya.make1
-rw-r--r--yt/yt/core/test_framework/framework.h2
4 files changed, 27 insertions, 3 deletions
diff --git a/library/python/monlib/encoder.pxd b/library/python/monlib/encoder.pxd
index f879b66b78..ac6ad4f904 100644
--- a/library/python/monlib/encoder.pxd
+++ b/library/python/monlib/encoder.pxd
@@ -40,6 +40,10 @@ cdef extern from "library/cpp/monlib/encode/json/json.h" namespace "NMonitoring"
cdef void DecodeJson(TStringBuf data, IMetricConsumer* c)
+cdef extern from "library/cpp/monlib/encode/prometheus/prometheus.h" namespace "NMonitoring" nogil:
+ cdef IMetricEncoderPtr EncoderPrometheus(IOutputStream* out, TStringBuf metricNameLabel)
+
+
cdef extern from "library/cpp/monlib/encode/spack/spack_v1.h" namespace "NMonitoring" nogil:
cdef IMetricEncoderPtr EncoderSpackV1(IOutputStream* out, ETimePrecision, ECompression)
@@ -77,3 +81,5 @@ cdef class Encoder:
cdef Encoder create_spack(object stream, ETimePrecision timePrecision, ECompression compression)
@staticmethod
cdef Encoder create_json(object stream, int indent)
+ @staticmethod
+ cdef Encoder create_prometheus(object stream, bytes metricNameLabel)
diff --git a/library/python/monlib/encoder.pyx b/library/python/monlib/encoder.pyx
index 5387d40a88..2e4f56e1d3 100644
--- a/library/python/monlib/encoder.pyx
+++ b/library/python/monlib/encoder.pyx
@@ -79,6 +79,15 @@ cdef class Encoder:
wrapper.__wrapped = EncoderJson(wrapper.__stream.Get(), indent)
return wrapper
+
+ @staticmethod
+ cdef Encoder create_prometheus(object stream, bytes metricNameLabel):
+ cdef Encoder wrapper = Encoder.__new__(Encoder)
+ wrapper._make_stream(stream)
+
+ wrapper.__wrapped = EncoderPrometheus(wrapper.__stream.Get(), TStringBuf(metricNameLabel))
+
+ return wrapper
cpdef Encoder create_json_encoder(object stream, int indent):
@@ -126,13 +135,14 @@ def dump(registry, fp, format='spack', **kwargs):
:param registry: Metric registry object
:param fp: File descriptor to serialize to
- :param format: Format to serialize to (allowed values: spack). Default: json
+ :param format: Format to serialize to (allowed values: spack, json, prometheus). Default: json
Keyword arguments:
:param time_precision: Time precision (spack)
:param compression: Compression codec (spack)
:param indent: Pretty-print indentation for object members and arrays (json)
:param timestamp: Metric timestamp datetime
+ :param metric_name_label: Name of the label used as the prometheus metric name
:returns: Nothing
"""
if not hasattr(fp, 'fileno'):
@@ -145,6 +155,9 @@ def dump(registry, fp, format='spack', **kwargs):
elif format == 'json':
indent = int(kwargs.get('indent', 0))
encoder = Encoder.create_json(fp, indent)
+ elif format == 'prometheus':
+ metric_name_label = kwargs.get('metric_name_label', 'sensor').encode()
+ encoder = Encoder.create_prometheus(fp, metric_name_label)
timestamp = kwargs.get('timestamp', EPOCH_NAIVE)
registry.accept(timestamp, encoder)
@@ -157,13 +170,14 @@ def dumps(registry, format='spack', **kwargs):
adjusted using kwargs, which may differ depending on the selected format.
:param registry: Metric registry object
- :param format: Format to serialize to (allowed values: spack). Default: json
+ :param format: Format to serialize to (allowed values: spack, json, prometheus). Default: json
Keyword arguments:
:param time_precision: Time precision (spack)
:param compression: Compression codec (spack)
:param indent: Pretty-print indentation for object members and arrays (json)
:param timestamp: Metric timestamp datetime
+ :param metric_name_label: Name of the label used as the prometheus metric name
:returns: A string of the specified format
"""
if format == 'spack':
@@ -173,6 +187,9 @@ def dumps(registry, format='spack', **kwargs):
elif format == 'json':
indent = int(kwargs.get('indent', 0))
encoder = Encoder.create_json(None, indent)
+ elif format == 'prometheus':
+ metric_name_label = kwargs.get('metric_name_label', 'sensor').encode()
+ encoder = Encoder.create_prometheus(None, metric_name_label)
timestamp = kwargs.get('timestamp', EPOCH_NAIVE)
registry.accept(timestamp, encoder)
diff --git a/library/python/monlib/ya.make b/library/python/monlib/ya.make
index 5c7de8de58..585078be64 100644
--- a/library/python/monlib/ya.make
+++ b/library/python/monlib/ya.make
@@ -11,6 +11,7 @@ PEERDIR(
library/cpp/monlib/encode/json
library/cpp/monlib/encode/spack
library/cpp/monlib/encode/unistat
+ library/cpp/monlib/encode/prometheus
)
END()
diff --git a/yt/yt/core/test_framework/framework.h b/yt/yt/core/test_framework/framework.h
index 4255a3eb44..30f11c1efa 100644
--- a/yt/yt/core/test_framework/framework.h
+++ b/yt/yt/core/test_framework/framework.h
@@ -197,7 +197,7 @@ public:\
private:\
virtual void TestBody();\
void TestInnerBody();\
- static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_;\
+ [[maybe_unused]] static ::testing::TestInfo* const test_info_;\
};\
\
::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_case_name, test_name)\