-
Notifications
You must be signed in to change notification settings - Fork 160
Consolidate bindings for Enterprise ABI compatibility #2821
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
be18e9b
dc8a9c7
9f92afd
6251ddd
fd875bb
3dccc3c
3cc34ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /* Copyright 2023 Man Group Operations Limited | ||
| * | ||
| * Use of this software is governed by the Business Source License 1.1 included in the file licenses/BSL.txt. | ||
| * | ||
| * As of the Change Date specified in that file, in accordance with the Business Source License, use of this software | ||
| * will be governed by the Apache License, version 2.0. | ||
| */ | ||
|
|
||
| #include <arcticdb/entity/python_bindings_common.hpp> | ||
| #include <arcticdb/entity/atom_key.hpp> | ||
| #include <arcticdb/entity/versioned_item.hpp> | ||
| #include <arcticdb/entity/types.hpp> | ||
|
|
||
| #include <pybind11/pybind11.h> | ||
| #include <pybind11/operators.h> | ||
| #include <pybind11/stl.h> | ||
|
|
||
| namespace py = pybind11; | ||
|
|
||
| namespace arcticdb::entity::apy { | ||
|
|
||
| void register_common_entity_bindings(py::module& m, bool local_bindings) { | ||
| py::class_<AtomKey, std::shared_ptr<AtomKey>>(m, "AtomKey", py::module_local(local_bindings)) | ||
| .def(py::init()) | ||
| .def(py::init<StreamId, VersionId, timestamp, ContentHash, IndexValue, IndexValue, KeyType>()) | ||
| .def("change_id", &AtomKey::change_id) | ||
| .def_property_readonly("id", &AtomKey::id) | ||
| .def_property_readonly("version_id", &AtomKey::version_id) | ||
| .def_property_readonly("creation_ts", &AtomKey::creation_ts) | ||
| .def_property_readonly("content_hash", &AtomKey::content_hash) | ||
| .def_property_readonly("start_index", &AtomKey::start_index) | ||
| .def_property_readonly("end_index", &AtomKey::end_index) | ||
| .def_property_readonly("type", [](const AtomKey& self) { return self.type(); }) | ||
| .def(pybind11::self == pybind11::self) | ||
| .def(pybind11::self != pybind11::self) | ||
| .def("__repr__", &AtomKey::view_human) | ||
| .def(py::self < py::self) | ||
| .def(py::pickle( | ||
| [](const AtomKey& key) { | ||
| constexpr int serialization_version = 0; | ||
| return py::make_tuple( | ||
| serialization_version, | ||
| key.id(), | ||
| key.version_id(), | ||
| key.creation_ts(), | ||
| key.content_hash(), | ||
| key.start_index(), | ||
| key.end_index(), | ||
| key.type() | ||
| ); | ||
| }, | ||
| [](py::tuple t) { | ||
| util::check(t.size() >= 7, "Invalid AtomKey pickle object!"); | ||
|
|
||
| [[maybe_unused]] const int serialization_version = t[0].cast<int>(); | ||
|
||
| AtomKey key( | ||
| t[1].cast<StreamId>(), | ||
| t[2].cast<VersionId>(), | ||
| t[3].cast<timestamp>(), | ||
| t[4].cast<ContentHash>(), | ||
| t[5].cast<IndexValue>(), | ||
| t[6].cast<IndexValue>(), | ||
| t[7].cast<KeyType>() | ||
| ); | ||
| return key; | ||
| } | ||
| )); | ||
|
|
||
| py::class_<VersionedItem>(m, "VersionedItem", py::module_local(local_bindings)) | ||
| .def_property_readonly("symbol", &VersionedItem::symbol) | ||
| .def_property_readonly("timestamp", &VersionedItem::timestamp) | ||
| .def_property_readonly("version", &VersionedItem::version); | ||
| } | ||
|
|
||
| } // namespace arcticdb::entity::apy | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| /* Copyright 2023 Man Group Operations Limited | ||
| * | ||
| * Use of this software is governed by the Business Source License 1.1 included in the file licenses/BSL.txt. | ||
| * | ||
| * As of the Change Date specified in that file, in accordance with the Business Source License, use of this software | ||
| * will be governed by the Apache License, version 2.0. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <pybind11/pybind11.h> | ||
|
||
|
|
||
| namespace arcticdb::entity::apy { | ||
|
|
||
| void register_common_entity_bindings(pybind11::module& m, bool local_bindings); | ||
|
||
|
|
||
| } // namespace arcticdb::entity::apy | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need to make the metrics config pickleable? This relates to this comment on the enterprise PR https://github.com/man-group/arcticdb-enterprise/pull/281#discussion_r2650734598 . All we need is to add accessors to the fields in hte metrics config? It's confusing to use the pickling APIs for this purpose. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| #include <arcticdb/python/python_bindings_common.hpp> | ||
| #include <arcticdb/entity/metrics.hpp> | ||
| #include <arcticdb/util/preconditions.hpp> | ||
|
|
||
| namespace py = pybind11; | ||
|
|
||
| namespace arcticdb::apy { | ||
|
|
||
| py::tuple to_tuple(const MetricsConfig& config) { | ||
| return py::make_tuple( | ||
| config.host, config.port, config.job_name, config.instance, config.prometheus_env, config.model_ | ||
| ); | ||
| } | ||
|
|
||
| MetricsConfig metrics_config_from_tuple(const py::tuple& t) { | ||
| util::check(t.size() == 6, "Invalid MetricsConfig pickle object, expected 6 attributes but was {}", t.size()); | ||
| return MetricsConfig{ | ||
| t[static_cast<uint32_t>(MetricsConfigPickleOrder::HOST)].cast<std::string>(), | ||
| t[static_cast<uint32_t>(MetricsConfigPickleOrder::PORT)].cast<std::string>(), | ||
| t[static_cast<uint32_t>(MetricsConfigPickleOrder::JOB_NAME)].cast<std::string>(), | ||
| t[static_cast<uint32_t>(MetricsConfigPickleOrder::INSTANCE)].cast<std::string>(), | ||
| t[static_cast<uint32_t>(MetricsConfigPickleOrder::PROMETHEUS_ENV)].cast<std::string>(), | ||
| t[static_cast<uint32_t>(MetricsConfigPickleOrder::MODEL)].cast<MetricsConfig::Model>() | ||
| }; | ||
| } | ||
|
|
||
| } // namespace arcticdb::apy | ||
|
|
||
| void register_metrics(py::module&& m, bool local_bindings) { | ||
|
|
||
| auto prometheus = m.def_submodule("prometheus"); | ||
| py::class_<arcticdb::PrometheusInstance, std::shared_ptr<arcticdb::PrometheusInstance>>( | ||
| prometheus, "Instance", py::module_local(local_bindings) | ||
| ); | ||
|
|
||
| py::class_<arcticdb::MetricsConfig, std::shared_ptr<arcticdb::MetricsConfig>>( | ||
| prometheus, "MetricsConfig", py::module_local(local_bindings) | ||
| ) | ||
| .def(py::init< | ||
| const std::string&, | ||
| const std::string&, | ||
| const std::string&, | ||
| const std::string&, | ||
| const std::string&, | ||
| const arcticdb::MetricsConfig::Model>()) | ||
| .def(py::pickle( | ||
| [](const arcticdb::MetricsConfig& config) { return arcticdb::apy::to_tuple(config); }, | ||
| [](py::tuple t) { return arcticdb::apy::metrics_config_from_tuple(t); } | ||
| )); | ||
|
|
||
| py::enum_<arcticdb::MetricsConfig::Model>(prometheus, "MetricsConfigModel", py::module_local(local_bindings)) | ||
| .value("NO_INIT", arcticdb::MetricsConfig::Model::NO_INIT) | ||
| .value("PUSH", arcticdb::MetricsConfig::Model::PUSH) | ||
| .value("PULL", arcticdb::MetricsConfig::Model::PULL) | ||
| .export_values(); | ||
|
|
||
| prometheus.def("metrics_config_from_tuple", &arcticdb::apy::metrics_config_from_tuple); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| #pragma once | ||
| #include <pybind11/pybind11.h> | ||
|
||
| #include <arcticdb/entity/metrics.hpp> | ||
|
|
||
| namespace arcticdb::apy { | ||
|
|
||
| enum class MetricsConfigPickleOrder : uint32_t { | ||
| HOST = 0, | ||
| PORT = 1, | ||
| JOB_NAME = 2, | ||
| INSTANCE = 3, | ||
| PROMETHEUS_ENV = 4, | ||
| MODEL = 5 | ||
| }; | ||
|
|
||
| pybind11::tuple to_tuple(const MetricsConfig& config); | ||
| MetricsConfig metrics_config_from_tuple(const pybind11::tuple& t); | ||
|
|
||
| } // namespace arcticdb::apy | ||
|
|
||
| void register_metrics(pybind11::module&& m, bool local_bindings); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not check for
t.size() == 7There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's for some sort of future proof, if new setting is added to the class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's for the staged data tokens API, which makes the staged data tokens (which wrap atom keys) pickleable. This helps to use the staged data API across processes which may have different ArcticDB versions.