From 4e756c4a090aa9aa7ef9993820c2d4b5737ef774 Mon Sep 17 00:00:00 2001 From: Mateusz Date: Thu, 30 Jul 2026 14:41:55 +0100 Subject: [PATCH] PCBC-1071: Fix build break in meter wrapper after core metric_attributes API change --- src/deps/couchbase-cxx-client | 2 +- src/wrapper/connection_handle.cxx | 49 +++++++++++++++++++++++-------- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/src/deps/couchbase-cxx-client b/src/deps/couchbase-cxx-client index fb3f8608..488c7502 160000 --- a/src/deps/couchbase-cxx-client +++ b/src/deps/couchbase-cxx-client @@ -1 +1 @@ -Subproject commit fb3f860843c3ca594f2676225dcc95ed8d6c1375 +Subproject commit 488c75021059c4bbad9b8d9a0d47790dd1c41477 diff --git a/src/wrapper/connection_handle.cxx b/src/wrapper/connection_handle.cxx index d380d84a..f65843e2 100644 --- a/src/wrapper/connection_handle.cxx +++ b/src/wrapper/connection_handle.cxx @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -918,27 +919,50 @@ connection_handle::cluster_labels(zval* return_value) namespace { auto -zval_to_value_recorder_tags(const zval* tags) -> std::map +zval_to_metric_attributes(const zval* tags) -> core::metrics::metric_attributes { - std::map result{}; + namespace attributes = core::tracing::attributes; + + core::metrics::metric_attributes attrs{}; if (tags == nullptr || Z_TYPE_P(tags) != IS_ARRAY) { - return result; + return attrs; } const zend_string* key = nullptr; const zval* value = nullptr; ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(tags), key, value) { - if (Z_TYPE_P(value) == IS_STRING) { - result[cb_string_new(key)] = cb_string_new(Z_STR_P(value)); - } - // We ignore other types. We can't forward them to the C++ SDK's meter. - // This is not an issue at present, as this is only used for the LoggingMeter, which only needs - // the service and operation name tags, which are both strings. + if (key == nullptr || Z_TYPE_P(value) != IS_STRING) { + // We ignore other types. We can't forward them to the C++ SDK's meter. + // This is not an issue at present, as this is only used for the LoggingMeter, which only needs + // the service and operation name tags, which are both strings. + continue; + } + auto name = cb_string_new(key); + auto text = cb_string_new(Z_STR_P(value)); + if (name == attributes::op::service) { + attrs.service = std::move(text); + } else if (name == attributes::op::operation_name) { + attrs.operation = std::move(text); + } else if (name == attributes::op::bucket_name) { + attrs.bucket_name = std::move(text); + } else if (name == attributes::op::scope_name) { + attrs.scope_name = std::move(text); + } else if (name == attributes::op::collection_name) { + attrs.collection_name = std::move(text); + } else if (name == attributes::op::error_type) { + attrs.error_type = std::move(text); + } else if (name == attributes::common::cluster_name) { + attrs.internal.cluster_name = std::move(text); + } else if (name == attributes::common::cluster_uuid) { + attrs.internal.cluster_uuid = std::move(text); + } + // Other tags (e.g. the reserved unit and system name) are fixed by + // metric_attributes::encode() and don't need to be forwarded. } ZEND_HASH_FOREACH_END(); - return result; + return attrs; } } // namespace @@ -946,8 +970,9 @@ COUCHBASE_API void connection_handle::record_core_meter_operation_duration(std::int64_t duration_us, zval* tags) { - auto tag_map = zval_to_value_recorder_tags(tags); - impl_->core_api().meter()->record_value(tag_map, std::chrono::microseconds(duration_us)); + auto attrs = zval_to_metric_attributes(tags); + impl_->core_api().meter()->record_value( + std::move(attrs), std::chrono::steady_clock::now() - std::chrono::microseconds(duration_us)); } COUCHBASE_API