Skip to content

[CLIENT-3366] Add support for dynamic config #744

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 153 commits into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
153 commits
Select commit Hold shift + click to select a range
c34746a
try using libyaml from c client
juliannguyen4 Feb 24, 2025
1183962
install libyaml in centos
juliannguyen4 Feb 24, 2025
7dbf569
try out
juliannguyen4 Feb 28, 2025
b76bef0
update
juliannguyen4 Mar 7, 2025
e708856
update
juliannguyen4 Mar 17, 2025
e2a57b4
update
juliannguyen4 Mar 18, 2025
eca3168
Install libyaml so that delocate copies it into the wheel
juliannguyen4 Mar 18, 2025
dfc9235
Update c client
juliannguyen4 Mar 18, 2025
9ef11bd
libyaml must be linked with extension
juliannguyen4 Mar 18, 2025
f5be51e
b4 and after
juliannguyen4 Mar 18, 2025
ab28850
libyaml only built for macos 13 or higher
juliannguyen4 Mar 18, 2025
6da7f3f
add libyaml to lib search path
juliannguyen4 Mar 18, 2025
5392758
fix
juliannguyen4 Mar 18, 2025
2085167
Use macos 13 so we can target the min supported version
juliannguyen4 Mar 18, 2025
38d9fd1
use library_path env var to avoid compiler warnings
juliannguyen4 Mar 18, 2025
118b418
support windows
juliannguyen4 Mar 19, 2025
bad94a6
Merge remote-tracking branch 'origin/dev' into libyaml
juliannguyen4 Mar 20, 2025
f74359e
same step that set env var can't access new value
juliannguyen4 Mar 20, 2025
b8f733b
newest c client
juliannguyen4 Mar 24, 2025
0b59796
wip
juliannguyen4 Mar 24, 2025
b3b3357
this is fine
juliannguyen4 Mar 24, 2025
0b06419
finish
juliannguyen4 Mar 24, 2025
c4547b0
fix
juliannguyen4 Mar 24, 2025
e5aa288
fix
juliannguyen4 Mar 24, 2025
43b30a5
fix
juliannguyen4 Mar 24, 2025
6bd6313
need to include declaration with definition
juliannguyen4 Mar 24, 2025
d8ed9a7
forgot to compile new file
juliannguyen4 Mar 24, 2025
608f3df
add smoke test
juliannguyen4 Mar 25, 2025
e7cc6e6
make work for now.
juliannguyen4 Mar 25, 2025
802fe0e
fix
juliannguyen4 Mar 25, 2025
85ca602
dont wrap around as_config_provider
juliannguyen4 Mar 25, 2025
dbd7894
fix
juliannguyen4 Mar 25, 2025
d8176ea
fix
juliannguyen4 Mar 25, 2025
aba6098
e2e test
juliannguyen4 Mar 25, 2025
e22971e
Add negative test
juliannguyen4 Mar 25, 2025
94bef8f
fix test
juliannguyen4 Mar 25, 2025
f8e3d40
fix
juliannguyen4 Mar 25, 2025
a01dd98
stub
juliannguyen4 Mar 25, 2025
d6576da
show coverage of new file
juliannguyen4 Mar 25, 2025
5c8098f
set log lvl...
juliannguyen4 Mar 26, 2025
9a71355
fix
juliannguyen4 Mar 26, 2025
bcdcb0b
fix
juliannguyen4 Mar 26, 2025
1f45e83
fix config
juliannguyen4 Mar 27, 2025
5df69ca
f
juliannguyen4 Mar 27, 2025
a855557
comment
juliannguyen4 Mar 27, 2025
01d0a65
add api test
juliannguyen4 Mar 27, 2025
7844ecd
show both startup and asd logs
juliannguyen4 Mar 27, 2025
443ea83
wrong type....:
juliannguyen4 Apr 1, 2025
d67b8c4
fix
juliannguyen4 Apr 1, 2025
22a6e61
define getters
juliannguyen4 Apr 1, 2025
e1cde9c
missing
juliannguyen4 Apr 1, 2025
57e7f71
Fix test
juliannguyen4 Apr 2, 2025
824995f
Doc
juliannguyen4 Apr 2, 2025
ed80472
use default interval from c client
juliannguyen4 Apr 2, 2025
5753ff7
rm todos
juliannguyen4 Apr 2, 2025
44989ff
fix bad explanation
juliannguyen4 Apr 2, 2025
85afbe5
improve errors
juliannguyen4 Apr 2, 2025
5001a4c
improve errors
juliannguyen4 Apr 2, 2025
2906841
Object must be reinitializable, check that inteveral is 32-bit unsigned
juliannguyen4 Apr 2, 2025
f66e74c
Add reinit test
juliannguyen4 Apr 2, 2025
682ff07
set up properly
juliannguyen4 Apr 2, 2025
47ee067
fix
juliannguyen4 Apr 2, 2025
45b25d4
just comment out so it doesn't affect the rest of the tests
juliannguyen4 Apr 2, 2025
66c915e
improve commenting
juliannguyen4 Apr 3, 2025
a9c1116
proofread
juliannguyen4 Apr 3, 2025
47fa9c3
fix
juliannguyen4 Apr 3, 2025
c4ea6d8
fix bad spacing
juliannguyen4 Apr 3, 2025
d681f54
fix mem leak
juliannguyen4 Apr 3, 2025
684f290
future proof
juliannguyen4 Apr 3, 2025
90666ce
WIP
juliannguyen4 Apr 3, 2025
3dcc8e2
fix
juliannguyen4 Apr 3, 2025
bc0f392
oops
juliannguyen4 Apr 3, 2025
5c3f0c2
apply global metrics policy
juliannguyen4 Apr 3, 2025
f623d83
add regression test for global metrics policy
juliannguyen4 Apr 3, 2025
30d8577
fix
juliannguyen4 Apr 4, 2025
523efb0
fix
juliannguyen4 Apr 4, 2025
0a1b63c
fix
juliannguyen4 Apr 4, 2025
a93ff80
whoop
juliannguyen4 Apr 4, 2025
888cf69
fix
juliannguyen4 Apr 4, 2025
c32a1e8
rm comment
juliannguyen4 Apr 7, 2025
5f30c14
e2e test
juliannguyen4 Apr 7, 2025
4c61262
clean up
juliannguyen4 Apr 7, 2025
6540100
use fixture
juliannguyen4 Apr 7, 2025
10348f7
update c client
juliannguyen4 Apr 7, 2025
97bbf5b
fix
juliannguyen4 Apr 7, 2025
9a4c23f
interval too long
juliannguyen4 Apr 7, 2025
17272b1
dont make a tuple
juliannguyen4 Apr 7, 2025
20a2266
improve error msg
juliannguyen4 Apr 7, 2025
9f911b9
fix broken test
juliannguyen4 Apr 7, 2025
ea9e3cd
Remove todo
juliannguyen4 Apr 7, 2025
ec794f5
fix
juliannguyen4 Apr 8, 2025
aece879
Merge remote-tracking branch 'origin/dev' into CLIENT-3366-dyn-config
juliannguyen4 Apr 10, 2025
31d3e52
use neg test instead. easier to test
juliannguyen4 Apr 10, 2025
d4137d3
update c client
juliannguyen4 Apr 10, 2025
abda3e1
finish test
juliannguyen4 Apr 10, 2025
1b23e24
clean up test code
juliannguyen4 Apr 11, 2025
0a2b8f1
make immutable
juliannguyen4 Apr 11, 2025
6d9cc30
provide more helpful err msg. clean up comments
juliannguyen4 Apr 11, 2025
bed70aa
add stub
juliannguyen4 Apr 11, 2025
bac0239
code cov test
juliannguyen4 Apr 11, 2025
e01da48
oop:
juliannguyen4 Apr 11, 2025
85e450d
bad test
juliannguyen4 Apr 11, 2025
2631c0f
fix
juliannguyen4 Apr 11, 2025
79afd88
bad comment
juliannguyen4 Apr 11, 2025
28c5cb3
update docs
juliannguyen4 Apr 11, 2025
1762837
test that other fields than latency* should be ignored
juliannguyen4 Apr 11, 2025
987d94c
fix spellcheck
juliannguyen4 Apr 11, 2025
d7f6d91
update c cl
juliannguyen4 Apr 18, 2025
a672d98
Merge remote-tracking branch 'origin/dev' into CLIENT-3366-dyn-config
juliannguyen4 Apr 23, 2025
18c2c77
update c client
juliannguyen4 Apr 23, 2025
b791d2e
fix
juliannguyen4 Apr 23, 2025
d6295b1
update c client final time
juliannguyen4 Apr 28, 2025
6216074
Merge remote-tracking branch 'origin/dev' into CLIENT-3366-dyn-config
juliannguyen4 Apr 28, 2025
c01d1d5
Merge remote-tracking branch 'origin/dev' into CLIENT-3366-dyn-config
juliannguyen4 May 5, 2025
9ef8e5c
add env var test
juliannguyen4 May 5, 2025
fea6f85
make configprovider path optional since we can pass in an env var now
juliannguyen4 May 5, 2025
044155b
add default test
juliannguyen4 May 5, 2025
8289eae
c client's dyn config in stage already
juliannguyen4 May 5, 2025
3562405
use c client from stage branch
juliannguyen4 May 5, 2025
85b2805
proofread
juliannguyen4 May 7, 2025
236af30
make test more thorough
juliannguyen4 May 7, 2025
16a5204
fix
juliannguyen4 May 7, 2025
16c8876
wasnt being cleaned up entirely
juliannguyen4 May 7, 2025
7222591
Revert "make configprovider path optional since we can pass in an en…
juliannguyen4 May 7, 2025
567db56
update test for reversion
juliannguyen4 May 7, 2025
83a08ff
document the alternate way to enable dyn config
juliannguyen4 May 7, 2025
273eac8
this is duplicated above
juliannguyen4 May 7, 2025
37974a0
incorrect usage in test
juliannguyen4 May 7, 2025
3dbee32
spelling typo
juliannguyen4 May 7, 2025
841baeb
improve commenting
juliannguyen4 May 7, 2025
66d5e1a
add test for codecov
juliannguyen4 May 7, 2025
80e4901
fix test
juliannguyen4 May 8, 2025
4b19375
fix syntax
juliannguyen4 May 8, 2025
671b1b3
this is the right codepath
juliannguyen4 May 8, 2025
0baed06
properly destroy as_config
juliannguyen4 May 8, 2025
4f6b1d8
mark as dead
juliannguyen4 May 8, 2025
d9ebf43
if txn level metrics policy is not passed in python, pass in NULL to …
juliannguyen4 May 8, 2025
782ff3f
only set ptr if we need to
juliannguyen4 May 8, 2025
89e667b
only free if we used our own metrics listener in txn level policy
juliannguyen4 May 8, 2025
cb1aecd
even if report_size_limit is ignored, it will be validated?
juliannguyen4 May 8, 2025
26d4836
make cleaner
juliannguyen4 May 12, 2025
f2157dc
wrong
juliannguyen4 May 12, 2025
f78c1c9
fix comment
juliannguyen4 May 12, 2025
caf6e72
set
juliannguyen4 May 12, 2025
857ab86
debug on mac x86
juliannguyen4 May 12, 2025
144d4ed
try this
juliannguyen4 May 12, 2025
2ae7d6c
comment
juliannguyen4 May 12, 2025
0e8bd3d
c-api will truncate unsigned long on windows. do our own input valida…
juliannguyen4 May 12, 2025
1f652f9
fix regression
juliannguyen4 May 12, 2025
ffc3e21
comment until we need later
juliannguyen4 May 12, 2025
93dbafd
fix test
juliannguyen4 May 12, 2025
860d653
fix mem leak
juliannguyen4 May 12, 2025
3c2fa6f
clear up
juliannguyen4 May 12, 2025
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
30 changes: 24 additions & 6 deletions .github/workflows/build-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,11 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# It is not documented in Github that openssl 3 is installed in their macos images
# It is not documented in Github that openssl 3 / libyaml is installed in their macos images
# so we install it here to be safe
- if: ${{ startsWith(inputs.platform-tag, 'macosx') }}
name: Ensure openssl is installed on Github macOS runners.
run: brew install openssl@${{ env.MACOS_OPENSSL_VERSION }}
name: Ensure openssl and libyaml are installed on Github macOS runners.
run: brew install openssl@${{ env.MACOS_OPENSSL_VERSION }} libyaml

- if: ${{ startsWith(inputs.platform-tag, 'macosx') }}
name: Set minimum macos version required to install wheel
Expand All @@ -266,7 +266,16 @@ jobs:
name: Ensure that linker can find brew packages
# On mac m1, packages installed via brew are not in the linker's default library path
run: |
echo LIBRARY_PATH="${LIBRARY_PATH}:$(brew --prefix openssl)/lib" >> $GITHUB_ENV
libraries=('libyaml' 'openssl')
for library in "${libraries[@]}"; do
LIBRARY_PATH="${LIBRARY_PATH}:$(brew --prefix $library)/lib"
done
echo LIBRARY_PATH=$LIBRARY_PATH >> $GITHUB_ENV
shell: bash

- if: ${{ inputs.platform-tag == 'macosx_x86_64' && matrix.python-tag == 'cp313' }}
# This fixes an issue where there is not enough room in the wheel's shared library to replace the rpath
run: echo CIBW_ENVIRONMENT_MACOS="LDFLAGS='-headerpad_max_install_names'" >> $GITHUB_ENV

- name: Build wheel
uses: pypa/[email protected]
Expand All @@ -275,13 +284,14 @@ jobs:
CIBW_BUILD: ${{ env.BUILD_IDENTIFIER }}
CIBW_BUILD_FRONTEND: build
CIBW_BEFORE_ALL_LINUX: >
yum install python-setuptools -y
yum install python-setuptools libyaml-devel -y
# delvewheel is not enabled by default but we do need to repair the wheel
CIBW_BEFORE_BUILD_WINDOWS: "pip install delvewheel==1.*"
# We want to check that our wheel links to the new openssl 3 install, not the system default
# This assumes that ldd prints out the "soname" for the libraries
# We can also manually verify the repair worked by checking the repaired wheel's compatibility tag
CIBW_REPAIR_WHEEL_COMMAND_LINUX: >
auditwheel show {wheel} &&
WHEEL_DIR=wheel-contents &&
unzip {wheel} -d $WHEEL_DIR &&
ldd $WHEEL_DIR/*.so | awk '{print $1}' | grep libssl.so.3 &&
Expand All @@ -297,8 +307,16 @@ jobs:
delocate-listdeps {dest_dir}/*.whl | grep libssl.3.dylib
CIBW_TEST_COMMAND: ${{ env.TEST_COMMAND }}

# - name: Setup tmate session
# if: ${{ !cancelled() }}
# uses: mxschmitt/action-tmate@v3

# For debugging
- run: docker logs aerospike
- run: |
# Checks that server started up properly
docker logs aerospike
# Prints the actual logs from asd
docker exec aerospike cat /var/log/aerospike/aerospike.log
if: ${{ always() && env.RUN_INTEGRATION_TESTS_IN_CIBW == 'true' }}
shell: bash

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ jobs:
mkdir -p query/src/main/query
mkdir -p scan/src/main/scan
mkdir -p transaction/src/main/transaction
mkdir -p config_provider/src/main/config_provider

cd ../../../../
cp src/main/*.c build/temp*/src/main/src/main
Expand All @@ -154,6 +155,7 @@ jobs:
cp src/main/query/*.c build/temp*/src/main/query/src/main/query/
cp src/main/scan/*.c build/temp*/src/main/scan/src/main/scan/
cp src/main/transaction/*.c build/temp*/src/main/transaction/src/main/transaction/
cp src/main/config_provider/*.c build/temp*/src/main/config_provider/src/main/config_provider/

- name: Generate coverage report for all object files
if: ${{ !cancelled() }}
Expand Down
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
path = aerospike-client-c
# url = [email protected]:aerospike/aerospike-client-c.git
url = https://github.com/aerospike/aerospike-client-c.git
branch = stage
branch = CLIENT-3346
2 changes: 1 addition & 1 deletion aerospike-client-c
Submodule aerospike-client-c updated 50 files
+2 −0 .build.yml
+24 −57 LICENSE.md
+1 −0 Makefile
+5 −5 README.md
+5 −5 examples/basic_examples/transaction/src/main/example.c
+1 −1 examples/project/Makefile
+1 −1 project/test.mk
+128 −13 src/include/aerospike/aerospike.h
+38 −17 src/include/aerospike/as_cluster.h
+88 −4 src/include/aerospike/as_config.h
+144 −0 src/include/aerospike/as_config_file.h
+123 −0 src/include/aerospike/as_file.h
+95 −12 src/include/aerospike/as_metrics.h
+6 −0 src/include/aerospike/as_policy.h
+1 −1 src/include/aerospike/version.h
+69 −15 src/main/aerospike/aerospike.c
+582 −169 src/main/aerospike/aerospike_batch.c
+6 −5 src/main/aerospike/aerospike_index.c
+14 −9 src/main/aerospike/aerospike_info.c
+257 −57 src/main/aerospike/aerospike_key.c
+64 −25 src/main/aerospike/aerospike_query.c
+65 −30 src/main/aerospike/aerospike_scan.c
+14 −5 src/main/aerospike/aerospike_txn.c
+19 −13 src/main/aerospike/aerospike_udf.c
+28 −21 src/main/aerospike/as_admin.c
+53 −31 src/main/aerospike/as_cluster.c
+9 −3 src/main/aerospike/as_config.c
+1,959 −0 src/main/aerospike/as_config_file.c
+11 −9 src/main/aerospike/as_info.c
+9 −8 src/main/aerospike/as_job.c
+144 −2 src/main/aerospike/as_metrics.c
+1 −1 src/main/aerospike/as_metrics_writer.c
+5 −3 src/main/aerospike/as_partition.c
+3 −1 src/main/aerospike/as_policy.c
+5 −3 src/main/aerospike/as_shm_cluster.c
+1 −1 src/main/aerospike/version.c
+4 −3 src/test/aerospike_batch/batch.c
+15 −14 src/test/aerospike_udf/udf_record.c
+19 −19 src/test/transaction.c
+186 −17 src/test/transaction_async.c
+1 −1 vs/aerospike-client-c-libevent.nuspec
+1 −1 vs/aerospike-client-c-libuv.nuspec
+1 −1 vs/aerospike-client-c.nuspec
+12 −0 vs/aerospike/aerospike.vcxproj
+6 −0 vs/aerospike/aerospike.vcxproj.filters
+1 −0 vs/aerospike/packages.config
+6 −0 xcode/aerospike-test.xcodeproj/project.pbxproj
+14 −0 xcode/aerospike.xcodeproj/project.pbxproj
+6 −0 xcode/examples.xcodeproj/project.pbxproj
+1 −0 xcode/prepare_xcode
6 changes: 6 additions & 0 deletions aerospike-stubs/aerospike.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,12 @@ class Transaction:
state: int
timeout: int

@final
class ConfigProvider:
def __new__(cls, path: str, interval: int = 60) -> ConfigProvider: ...
path: str
interval: int

class Client:
def __init__(self, *args, **kwargs) -> None: ...
def admin_change_password(self, username: str, password: str, policy: dict = ...) -> None: ...
Expand Down
7 changes: 7 additions & 0 deletions doc/aerospike.rst
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,11 @@ Only the `hosts` key is required; the rest of the keys are optional.
(Optional) A defined user with roles in the cluster. See :meth:`admin_create_user`.
* **password** (:class:`str`)
(Optional) The password will be hashed by the client using bcrypt.
* **config_provider** (:class:`aerospike.ConfigProvider`)
(Optional) Dynamic configuration provider.

An alternate way to enable dynamic config is to set environment variable ``AEROSPIKE_CLIENT_CONFIG_URL``
to the path of the config file before running the application.
* **lua** (:class:`dict`)
(Optional) Contains the paths to two types of Lua modules

Expand Down Expand Up @@ -446,6 +451,8 @@ Only the `hosts` key is required; the rest of the keys are optional.
* **txn_roll** (:class:`dict`)
Default transaction policy when rolling the transaction records forward (commit) or back (abort) in a batch.
Contains :ref:`aerospike_batch_policies`.
* **metrics** (:class:`~aerospike_helpers.metrics.MetricsPolicy`)
Default metrics policy. Only :py:attr:`~aerospike_helpers.metrics.MetricsPolicy.latency_columns` and :py:attr:`~aerospike_helpers.metrics.MetricsPolicy.latency_shift` will override transaction-level metrics policies.
* **total_timeout** (:class:`int`)
**Deprecated**: set this individually in the :ref:`aerospike_policies` dictionaries.

Expand Down
35 changes: 35 additions & 0 deletions doc/config_provider.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.. _aerospike.ConfigProvider:

.. currentmodule:: aerospike

===================================================================
:class:`aerospike.ConfigProvider` --- Dynamic config provider class
===================================================================

Methods
=======

.. class:: ConfigProvider

Dynamic configuration provider. Determines how to retrieve cluster policies.

An instance of this class is immutable.

For the ``interval`` parameter, an unsigned 32-bit integer must be passed.

:param path: Dynamic configuration file path. Cluster policies will be read from the yaml file at cluster initialization and whenever the file changes. The policies fields in the file override all command policies.
:type path: str
:param interval: Check dynamic configuration file for changes after this number of cluster tend iterations. Defaults to ``60``.
:type interval: int, optional

.. py:attribute:: path

This attribute is read-only.

:type: str

.. py:attribute:: interval

This attribute is read-only.

:type: int
2 changes: 2 additions & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Class Description
:ref:`aerospike.geojson` Handles GeoJSON type data.
:ref:`aerospike.KeyOrderedDict` Key ordered dictionary
:ref:`aerospike.Transaction` Transaction
:ref:`aerospike.ConfigProvider` Dynamic config provider
================================= ===========

In addition, the :ref:`Data_Mapping` page explains how **Python** types map to **Aerospike Server** types.
Expand All @@ -81,6 +82,7 @@ Content
geojson
key_ordered_dict
transaction
config_provider
predicates
exception
aerospike_helpers
Expand Down
1 change: 1 addition & 0 deletions doc/spelling_wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,4 @@ msg
func
bcrypt
namespaces
yaml
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@
'crypto',
'pthread',
'm',
'z'
'z',
'yaml'
]

##########################
Expand Down
3 changes: 3 additions & 0 deletions src/include/config_provider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include <Python.h>

PyTypeObject *AerospikeConfigProvider_Ready();
6 changes: 6 additions & 0 deletions src/include/conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ PyObject *create_py_cluster_from_as_cluster(as_error *error_p,
PyObject *create_py_node_from_as_node(as_error *error_p,
struct as_node_s *node);

// obj must be non-NULL
// Checks if pyobject is an instance of a class type defined in aerospike_helpers or one of its submodules
// If expected_submodule_name is NULL, the type is expected to be defined directly in the aerospike_helpers package
// If is_subclass_instance is true, we expect the instance's type to directly inherit from aerospike_helpers.<expected_submodule_name>.<expected_type_name>
Expand All @@ -245,3 +246,8 @@ PyObject *create_class_instance_from_module(as_error *error_p,
const char *module_name,
const char *class_name,
PyObject *py_arg);

// Error indicator must always be checked after this call
// Constructor parameter name needed for constructing error message
uint32_t convert_pyobject_to_uint32_t(PyObject *pyobject,
const char *param_name_of_pyobj);
8 changes: 5 additions & 3 deletions src/include/policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,11 @@ as_status pyobject_to_batch_remove_policy(AerospikeClient *self, as_error *err,
as_exp *exp_list,
as_exp **exp_list_p);

as_status init_and_set_as_metrics_policy_using_pyobject(
as_error *err, PyObject *py_metrics_policy,
as_metrics_policy *metrics_policy);
// metrics_policy must be declared already
// py_metrics_policy must be non-NULL
as_status
set_as_metrics_policy_using_pyobject(as_error *err, PyObject *py_metrics_policy,
as_metrics_policy *metrics_policy);

typedef struct {
// Use listener name for error messages
Expand Down
9 changes: 9 additions & 0 deletions src/include/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include <aerospike/as_bin.h>
#include <aerospike/as_operations.h>
#include <aerospike/as_txn.h>
#include <aerospike/as_config.h>

#include "pool.h"

#define AEROSPIKE_MODULE_NAME "aerospike"
Expand Down Expand Up @@ -108,3 +110,10 @@ typedef struct {
} AerospikeTransaction;

extern PyTypeObject AerospikeTransaction_Type;

typedef struct {
PyObject_HEAD char *path;
uint32_t interval;
} AerospikeConfigProvider;

extern PyTypeObject AerospikeConfigProvider_Type;
2 changes: 2 additions & 0 deletions src/main/aerospike.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "nullobject.h"
#include "cdt_types.h"
#include "transaction.h"
#include "config_provider.h"

#include <aerospike/as_operations.h>
#include <aerospike/as_log_macros.h>
Expand Down Expand Up @@ -556,6 +557,7 @@ static struct type_name_to_creation_method py_module_types[] = {
{"CDTWildcard", AerospikeWildcardObject_Ready},
{"CDTInfinite", AerospikeInfiniteObject_Ready},
{"Transaction", AerospikeTransaction_Ready},
{"ConfigProvider", AerospikeConfigProvider_Ready},
};

PyMODINIT_FUNC PyInit_aerospike(void)
Expand Down
21 changes: 15 additions & 6 deletions src/main/client/metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,29 @@ PyObject *AerospikeClient_EnableMetrics(AerospikeClient *self, PyObject *args,
goto RAISE_EXCEPTION_WITHOUT_AS_ERROR;
}

as_status status = init_and_set_as_metrics_policy_using_pyobject(
&err, py_metrics_policy, &metrics_policy);
if (status != AEROSPIKE_OK) {
goto RAISE_EXCEPTION_USING_AS_ERROR;
as_metrics_policy *metrics_policy_ref;
if (py_metrics_policy == NULL || py_metrics_policy == Py_None) {
// Use C client's config metrics policy
metrics_policy_ref = NULL;
}
else {
as_metrics_policy_init(&metrics_policy);
as_status status = set_as_metrics_policy_using_pyobject(
&err, py_metrics_policy, &metrics_policy);
if (status != AEROSPIKE_OK) {
goto RAISE_EXCEPTION_USING_AS_ERROR;
}
metrics_policy_ref = &metrics_policy;
}

// 2 scenarios:
// 1. If the user does not pass their own MetricsListeners object to client.enable_metrics(), udata is NULL
// 2. Otherwise, udata is non-NULL and set to heap-allocated PyListenerData
bool free_udata_as_py_listener_data =
metrics_policy.metrics_listeners.udata != NULL;
metrics_policy_ref && metrics_policy.metrics_listeners.udata != NULL;

Py_BEGIN_ALLOW_THREADS
aerospike_enable_metrics(self->as, &err, &metrics_policy);
aerospike_enable_metrics(self->as, &err, metrics_policy_ref);
Py_END_ALLOW_THREADS

if (err.code != AEROSPIKE_OK) {
Expand Down
Loading
Loading