diff --git a/aerospike_helpers/metrics/__init__.py b/aerospike_helpers/metrics/__init__.py index 133e189aba..c9fa406c2a 100644 --- a/aerospike_helpers/metrics/__init__.py +++ b/aerospike_helpers/metrics/__init__.py @@ -105,6 +105,7 @@ class Cluster: Attributes: cluster_name (Optional[str]): Expected cluster name for all nodes. May be :py:obj:`None`. + app_id (Optional[str]): Application identifier. May be :py:obj:`None`. invalid_node_count (int): Count of add node failures in the most recent cluster tend iteration. command_count (int): Command count. The value is cumulative and not reset per metrics interval. retry_count (int): Command retry count. There can be multiple retries for a single command. diff --git a/src/main/conversions.c b/src/main/conversions.c index 0360b70994..c3c70fa88a 100644 --- a/src/main/conversions.c +++ b/src/main/conversions.c @@ -1052,6 +1052,16 @@ PyObject *create_py_cluster_from_as_cluster(as_error *error_p, PyObject_SetAttrString(py_cluster, "cluster_name", Py_None); } + // App Id is optional (declared in client config) + if (cluster->app_id) { + PyObject *py_app_id = PyUnicode_FromString(cluster->app_id); + PyObject_SetAttrString(py_cluster, "app_id", py_app_id); + Py_DECREF(py_app_id); + } + else { + PyObject_SetAttrString(py_cluster, "app_id", Py_None); + } + PyObject *py_invalid_node_count = PyLong_FromUnsignedLong(cluster->invalid_node_count); PyObject_SetAttrString(py_cluster, "invalid_node_count", diff --git a/test/new_tests/test_metrics.py b/test/new_tests/test_metrics.py index 8af2775e55..91b13559fb 100644 --- a/test/new_tests/test_metrics.py +++ b/test/new_tests/test_metrics.py @@ -194,6 +194,7 @@ def test_setting_metrics_policy_custom_settings(self): assert type(cluster.command_count) == int assert type(cluster.retry_count) == int assert type(cluster.nodes) == list + assert cluster.app_id is None or type(cluster.app_id) == str # Also check the Node and ConnectionStats objects in the Cluster object were populated for node in cluster.nodes: assert type(node) == Node diff --git a/test/standalone/test_ext_metrics_cluster_name.py b/test/standalone/test_ext_metrics_cluster_name.py index b95af360b0..d7cc3abec1 100644 --- a/test/standalone/test_ext_metrics_cluster_name.py +++ b/test/standalone/test_ext_metrics_cluster_name.py @@ -18,7 +18,8 @@ "hosts": [ ("127.0.0.1", 3000) ], - "cluster_name": "docker" + "cluster_name": "docker", + "app_id": "PythonClientTest" } print("Connecting to server...") as_client = aerospike.client(config) @@ -35,12 +36,14 @@ def snapshot(cluster: Cluster): global snapshot_triggered snapshot_triggered = True assert cluster.cluster_name == "docker" + assert cluster.app_id == "PythonClientTest" def disable(cluster: Cluster): print(f"Disable listener run. Cluster name: {cluster.cluster_name}") global disable_triggered disable_triggered = True assert cluster.cluster_name == "docker" + assert cluster.app_id == "PythonClientTest" def node_close(_: Node): pass