Skip to content

Library import 250304-1619 #15324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions library/python/monlib/metric_registry.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ from library.python.monlib.metric cimport (


cdef extern from "library/cpp/monlib/metrics/metric_registry.h" namespace "NMonitoring" nogil:
cdef struct TMetricOpts:
bint MemOnly

cdef cppclass TMetricRegistry:
TMetricRegistry() except +
TMetricRegistry(const TLabels&) except +
Expand All @@ -19,6 +22,23 @@ cdef extern from "library/cpp/monlib/metrics/metric_registry.h" namespace "NMoni
THistogram* HistogramCounter(const TLabels&, IHistogramCollectorPtr collector) except +
THistogram* HistogramRate(const TLabels&, IHistogramCollectorPtr collector) except +

TGauge* GaugeWithOpts(const TLabels&, TMetricOpts) except +
TIntGauge* IntGaugeWithOpts(const TLabels&, TMetricOpts) except +
TCounter* CounterWithOpts(const TLabels&, TMetricOpts) except +
TRate* RateWithOpts(const TLabels&, TMetricOpts) except +

THistogram* HistogramCounterWithOpts(
const TLabels&,
IHistogramCollectorPtr collector,
TMetricOpts opts
) except +

THistogram* HistogramRateWithOpts(
const TLabels&,
IHistogramCollectorPtr collector,
TMetricOpts opts
) except +

void Reset() except +
void Clear() except +

Expand Down
51 changes: 40 additions & 11 deletions library/python/monlib/metric_registry.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ cdef class MetricRegistry:

return native_labels

@staticmethod
cdef TMetricOpts _py_to_native_opts(dict kwargs) except *:
cdef TMetricOpts native_opts = TMetricOpts()
native_opts.MemOnly = kwargs.get('mem_only', False)
return native_opts

@staticmethod
cdef _native_to_py_labels(const TLabels& native_labels):
result = dict()
Expand All @@ -94,6 +100,7 @@ cdef class MetricRegistry:

def _histogram(self, labels, is_rate, hist_type, **kwargs):
cdef TLabels native_labels = MetricRegistry._py_to_native_labels(labels)
cdef TMetricOpts native_opts = MetricRegistry._py_to_native_opts(kwargs)
cdef IHistogramCollectorPtr collector
cdef TVector[double] native_buckets

Expand All @@ -117,9 +124,9 @@ cdef class MetricRegistry:

cdef THistogram* native_hist
if is_rate:
native_hist = self.__wrapped.Get().HistogramRate(native_labels, move(collector))
native_hist = self.__wrapped.Get().HistogramRateWithOpts(native_labels, move(collector), native_opts)
else:
native_hist = self.__wrapped.Get().HistogramCounter(native_labels, move(collector))
native_hist = self.__wrapped.Get().HistogramCounterWithOpts(native_labels, move(collector), native_opts)

return Histogram.from_ptr(native_hist)

Expand All @@ -135,52 +142,72 @@ cdef class MetricRegistry:

return labels

def gauge(self, labels):
def gauge(self, labels, **kwargs):
"""
Gets a gauge counter or creates a new one in case counter with the specified labels
does not exist

:param labels: A dict of labels which identifies counter

Keyword arguments:
:param mem_only: flag for memOnly metric (see: https://m.yandex-team.ru/docs/concepts/glossary#memonly)

:returns: Gauge counter
"""
cdef TLabels native_labels = MetricRegistry._py_to_native_labels(labels)
native_gauge = self.__wrapped.Get().Gauge(native_labels)
cdef TMetricOpts native_opts = MetricRegistry._py_to_native_opts(kwargs)
native_gauge = self.__wrapped.Get().GaugeWithOpts(native_labels, native_opts)
return Gauge.from_ptr(native_gauge)

def int_gauge(self, labels):
def int_gauge(self, labels, **kwargs):
"""
Gets a gauge counter or creates a new one in case counter with the specified labels
does not exist

:param labels: A dict of labels which identifies counter

Keyword arguments:
:param mem_only: flag for memOnly metric (see: https://m.yandex-team.ru/docs/concepts/glossary#memonly)

:returns: IntGauge counter
"""
cdef TLabels native_labels = MetricRegistry._py_to_native_labels(labels)
native_gauge = self.__wrapped.Get().IntGauge(native_labels)
cdef TMetricOpts native_opts = MetricRegistry._py_to_native_opts(kwargs)
native_gauge = self.__wrapped.Get().IntGaugeWithOpts(native_labels, native_opts)
return IntGauge.from_ptr(native_gauge)

def counter(self, labels):
def counter(self, labels, **kwargs):
"""
Gets a counter or creates a new one in case counter with the specified labels
does not exist

:param labels: A dict of labels which identifies counter

Keyword arguments:
:param mem_only: flag for memOnly metric (see: https://m.yandex-team.ru/docs/concepts/glossary#memonly)

:returns: Counter counter
"""
cdef TLabels native_labels = MetricRegistry._py_to_native_labels(labels)
native_counter = self.__wrapped.Get().Counter(native_labels)
cdef TMetricOpts native_opts = MetricRegistry._py_to_native_opts(kwargs)
native_counter = self.__wrapped.Get().CounterWithOpts(native_labels, native_opts)
return Counter.from_ptr(native_counter)

def rate(self, labels):
def rate(self, labels, **kwargs):
"""
Gets a rate counter or creates a new one in case counter with the specified labels
does not exist

:param labels: A dict of labels which identifies counter

Keyword arguments:
:param mem_only: flag for memOnly metric (see: https://m.yandex-team.ru/docs/concepts/glossary#memonly)

:returns: Rate counter
"""
cdef TLabels native_labels = MetricRegistry._py_to_native_labels(labels)
native_rate = self.__wrapped.Get().Rate(native_labels)
cdef TMetricOpts native_opts = MetricRegistry._py_to_native_opts(kwargs)
native_rate = self.__wrapped.Get().RateWithOpts(native_labels, native_opts)
return Rate.from_ptr(native_rate)

def histogram_counter(self, labels, hist_type, **kwargs):
Expand All @@ -197,6 +224,7 @@ cdef class MetricRegistry:
:param base: the exponential growth factor for buckets' width (exponential)
:param scale: linear scale for the buckets. Must be >= 1.0 (exponential)
:param start_value: the upper bound of the first bucket (linear)
:param mem_only: flag for memOnly metric (see: https://m.yandex-team.ru/docs/concepts/glossary#memonly)

:returns: Histogram counter

Expand Down Expand Up @@ -236,6 +264,7 @@ cdef class MetricRegistry:
:param base: the exponential growth factor for buckets' width (exponential)
:param scale: linear scale for the buckets. Must be >= 1.0 (exponential)
:param start_value: the upper bound of the first bucket (linear)
:param mem_only: flag for memOnly metric (see: https://m.yandex-team.ru/docs/concepts/glossary#memonly)

:returns: Histogram counter

Expand Down Expand Up @@ -274,4 +303,4 @@ cdef class MetricRegistry:

def remove_metric(self, labels):
cdef TLabels native_labels = MetricRegistry._py_to_native_labels(labels)
self.__wrapped.Get().RemoveMetric(native_labels)
self.__wrapped.Get().RemoveMetric(native_labels)
48 changes: 48 additions & 0 deletions library/python/monlib/ut/py2/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,3 +412,51 @@ def test_reset_and_clear_registry():
out = dumps(registry, format="json")
j = json.loads(out)
assert j == {}


def test_mem_only_metrics():
registry = MetricRegistry()

registry.gauge({"some": "gauge"}, mem_only=True)
with pytest.raises(Exception):
registry.gauge({"some": "gauge"})

registry.int_gauge({"some": "int_gauge"}, mem_only=True)
with pytest.raises(Exception):
registry.int_gauge({"some": "int_gauge"})

registry.counter({"some": "counter"}, mem_only=True)
with pytest.raises(Exception):
registry.counter({"some": "counter"})

registry.rate({"some": "rate"}, mem_only=True)
with pytest.raises(Exception):
registry.rate({"some": "rate"})

registry.histogram_counter(
{"some": "histogram_counter"},
HistogramType.Explicit,
mem_only=True,
buckets=[1, 5, 15, 20, 25]
)
with pytest.raises(Exception):
registry.histogram_counter(
{"some": "histogram_counter"},
HistogramType.Explicit,
buckets=[1, 5, 15, 20, 25],
)

registry.histogram_rate(
{"some": "histogram_rate"},
HistogramType.Exponential,
mem_only=True,
bucket_count=5,
base=2
)
with pytest.raises(Exception):
registry.histogram_rate(
{"some": "histogram_rate"},
HistogramType.Exponential,
bucket_count=5,
base=2
)
48 changes: 48 additions & 0 deletions library/python/monlib/ut/py3/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,3 +410,51 @@ def test_reset_and_clear_registry():
out = dumps(registry, format="json")
j = json.loads(out)
assert j == {}


def test_mem_only_metrics():
registry = MetricRegistry()

registry.gauge({"some": "gauge"}, mem_only=True)
with pytest.raises(Exception):
registry.gauge({"some": "gauge"})

registry.int_gauge({"some": "int_gauge"}, mem_only=True)
with pytest.raises(Exception):
registry.int_gauge({"some": "int_gauge"})

registry.counter({"some": "counter"}, mem_only=True)
with pytest.raises(Exception):
registry.counter({"some": "counter"})

registry.rate({"some": "rate"}, mem_only=True)
with pytest.raises(Exception):
registry.rate({"some": "rate"})

registry.histogram_counter(
{"some": "histogram_counter"},
HistogramType.Explicit,
mem_only=True,
buckets=[1, 5, 15, 20, 25]
)
with pytest.raises(Exception):
registry.histogram_counter(
{"some": "histogram_counter"},
HistogramType.Explicit,
buckets=[1, 5, 15, 20, 25],
)

registry.histogram_rate(
{"some": "histogram_rate"},
HistogramType.Exponential,
mem_only=True,
bucket_count=5,
base=2
)
with pytest.raises(Exception):
registry.histogram_rate(
{"some": "histogram_rate"},
HistogramType.Exponential,
bucket_count=5,
base=2
)
2 changes: 1 addition & 1 deletion ydb/ci/rightlib.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0ae3f82349eeb4f353c62dd726e4ba06bbc837f9
e34965b5e8228c70bfde422fbe03b40e462530c3
4 changes: 2 additions & 2 deletions ydb/library/yql/dq/transform/yql_common_dq_transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class TCommonDqTaskTransform {
};

TTaskTransformFactory CreateCommonDqTaskTransformFactory() {
return [] (const THashMap<TString, TString>& taskParams, const IFunctionRegistry* funcRegistry) -> TCallableVisitFuncProvider {
Y_UNUSED(taskParams);
return [] (const TTaskTransformArguments& args, const IFunctionRegistry* funcRegistry) -> TCallableVisitFuncProvider {
Y_UNUSED(args);
return TCommonDqTaskTransform(*funcRegistry);
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ class TTaskCommandExecutor {
}
settings.OptLLVM = DqConfiguration->OptLLVM.Get().GetOrElse("");

Ctx.FuncProvider = TaskTransformFactory(taskParams, Ctx.FuncRegistry);
Ctx.FuncProvider = TaskTransformFactory({taskParams, settings.ReadRanges}, Ctx.FuncRegistry);

Y_ABORT_UNLESS(!Alloc);
Y_ABORT_UNLESS(FunctionRegistry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ class TLocalFactory: public IProxyFactory {
YQL_CLOG(DEBUG, ProviderDq) << message;
};
}
ctx.FuncProvider = TaskTransformFactory(settings.TaskParams, ctx.FuncRegistry);
ctx.FuncProvider = TaskTransformFactory({settings.TaskParams, settings.ReadRanges}, ctx.FuncRegistry);
return MakeDqTaskRunner(alloc, ctx, settings, logger);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class TYdbDqTaskTransform {
};

TTaskTransformFactory CreateYdbDqTaskTransformFactory() {
return [] (const THashMap<TString, TString>& taskParams, const IFunctionRegistry* funcRegistry) -> TCallableVisitFuncProvider {
return TYdbDqTaskTransform(taskParams, *funcRegistry);
return [] (const TTaskTransformArguments& args, const IFunctionRegistry* funcRegistry) -> TCallableVisitFuncProvider {
return TYdbDqTaskTransform(args.TaskParams, *funcRegistry);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
namespace NYql {

TTaskTransformFactory CreateCompositeTaskTransformFactory(TVector<TTaskTransformFactory> factories) {
return [factories = std::move(factories)] (const THashMap<TString, TString>& taskParams, const NKikimr::NMiniKQL::IFunctionRegistry* funcRegistry) -> NKikimr::NMiniKQL::TCallableVisitFuncProvider {
return [factories = std::move(factories)] (const TTaskTransformArguments& args, const NKikimr::NMiniKQL::IFunctionRegistry* funcRegistry) -> NKikimr::NMiniKQL::TCallableVisitFuncProvider {
TVector<NKikimr::NMiniKQL::TCallableVisitFuncProvider> funcProviders;
for (auto& factory: factories) {
funcProviders.push_back(factory(taskParams, funcRegistry));
funcProviders.push_back(factory(args, funcRegistry));
}
return [funcProviders = std::move(funcProviders)] (const NKikimr::NMiniKQL::TInternName& name) -> NKikimr::NMiniKQL::TCallableVisitFunc {
for (auto& provider: funcProviders) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@

namespace NYql {

using TTaskTransformFactory = std::function<NKikimr::NMiniKQL::TCallableVisitFuncProvider(const THashMap<TString, TString>&, const NKikimr::NMiniKQL::IFunctionRegistry*)>;
struct TTaskTransformArguments {
THashMap<TString, TString> TaskParams;
TVector<TString> ReadRanges;
};

using TTaskTransformFactory = std::function<NKikimr::NMiniKQL::TCallableVisitFuncProvider(const TTaskTransformArguments&, const NKikimr::NMiniKQL::IFunctionRegistry*)>;

TTaskTransformFactory CreateCompositeTaskTransformFactory(TVector<TTaskTransformFactory> factories);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,9 +578,9 @@
],
"test.test[Udf-PythonAvg--Debug]": [
{
"checksum": "3c48becb08f825e3f64de7f909c3d4a7",
"checksum": "d90368f50cd675a0868fa9090bca1a54",
"size": 989,
"uri": "https://{canondata_backend}/1600758/4167b447d68450d04af3e055febcc3a8168a477c/resource.tar.gz#test.test_Udf-PythonAvg--Debug_/opt.yql"
"uri": "https://{canondata_backend}/1936947/488d1ce7f16cf486fb2c04ce444c576f60aa7157/resource.tar.gz#test.test_Udf-PythonAvg--Debug_/opt.yql"
}
],
"test.test[Udf-PythonAvg--Results]": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# prepare python udf
(let ui32 (DataType 'Uint32))
(let dbl (DataType 'Double))
(let rt (ResourceType 'Python2))
(let rt (ResourceType 'Python3))

(let udfScript (String '@@
class AvgCalc:
Expand Down
8 changes: 4 additions & 4 deletions yql/essentials/udfs/common/python/bindings/py_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ TPyObjectPtr ToPyResource(
const NUdf::TType* type,
const NUdf::TUnboxedValuePod& value)
{
// TODO NILE-43
#if false && UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 15)

#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 15)
NUdf::TResourceTypeInspector inpector(*ctx->PyCtx->TypeInfoHelper, type);
auto tag = inpector.GetTag();
if (tag == ctx->PyCtx->ResourceTag) {
Expand All @@ -80,8 +80,8 @@ NUdf::TUnboxedValue FromPyResource(
const TPyCastContext::TPtr& ctx,
const NUdf::TType* type, PyObject* value)
{
// TODO NILE-43
#if false && UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 15)

#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 15)
NUdf::TResourceTypeInspector inpector(*ctx->PyCtx->TypeInfoHelper, type);
auto tag = inpector.GetTag();
if (tag == ctx->PyCtx->ResourceTag) {
Expand Down
Loading
Loading