From 8657f3160d8f1f9c0527b5cef076d78b43cd66a4 Mon Sep 17 00:00:00 2001 From: Shannon Klaus Date: Tue, 27 Feb 2024 19:10:33 -0500 Subject: [PATCH] CLIENT-2699 Support client metrics. Co-authored-by: Brian Nichols --- Makefile | 3 + src/include/aerospike/aerospike_stats.h | 30 +- src/include/aerospike/as_async.h | 13 +- src/include/aerospike/as_cdt_ctx.h | 2 +- src/include/aerospike/as_cluster.h | 184 +++++- src/include/aerospike/as_command.h | 3 +- src/include/aerospike/as_event_internal.h | 11 +- src/include/aerospike/as_latency.h | 66 +++ src/include/aerospike/as_metrics.h | 191 ++++++ src/include/aerospike/as_metrics_writer.h | 81 +++ src/include/aerospike/as_node.h | 92 ++- src/main/aerospike/aerospike.c | 11 +- src/main/aerospike/aerospike_batch.c | 16 +- src/main/aerospike/aerospike_key.c | 23 +- src/main/aerospike/aerospike_query.c | 14 +- src/main/aerospike/aerospike_scan.c | 12 +- src/main/aerospike/aerospike_stats.c | 78 ++- src/main/aerospike/as_cluster.c | 156 ++++- src/main/aerospike/as_command.c | 33 +- src/main/aerospike/as_event.c | 62 +- src/main/aerospike/as_event_ev.c | 38 +- src/main/aerospike/as_event_event.c | 38 +- src/main/aerospike/as_event_uv.c | 6 +- src/main/aerospike/as_latency.c | 42 ++ src/main/aerospike/as_metrics.c | 52 ++ src/main/aerospike/as_metrics_writer.c | 688 ++++++++++++++++++++++ src/main/aerospike/as_node.c | 113 +++- src/main/aerospike/as_pipe.c | 6 +- src/test/aerospike_test.c | 17 +- vs/aerospike/aerospike.vcxproj | 6 + vs/aerospike/aerospike.vcxproj.filters | 18 + vs/props/base.props | 2 +- xcode/aerospike.xcodeproj/project.pbxproj | 24 + 33 files changed, 1995 insertions(+), 136 deletions(-) create mode 100644 src/include/aerospike/as_latency.h create mode 100644 src/include/aerospike/as_metrics.h create mode 100644 src/include/aerospike/as_metrics_writer.h create mode 100644 src/main/aerospike/as_latency.c create mode 100644 src/main/aerospike/as_metrics.c create mode 100644 src/main/aerospike/as_metrics_writer.c diff --git a/Makefile b/Makefile index da78c30a6a..49b21ef60b 100644 --- a/Makefile +++ b/Makefile @@ -133,9 +133,12 @@ AEROSPIKE += as_host.o AEROSPIKE += as_info.o AEROSPIKE += as_job.o AEROSPIKE += as_key.o +AEROSPIKE += as_latency.o AEROSPIKE += as_list_operations.o AEROSPIKE += as_lookup.o AEROSPIKE += as_map_operations.o +AEROSPIKE += as_metrics.o +AEROSPIKE += as_metrics_writer.o AEROSPIKE += as_node.o AEROSPIKE += as_operations.o AEROSPIKE += as_partition.o diff --git a/src/include/aerospike/aerospike_stats.h b/src/include/aerospike/aerospike_stats.h index 431f12266e..cfb3e81114 100644 --- a/src/include/aerospike/aerospike_stats.h +++ b/src/include/aerospike/aerospike_stats.h @@ -1,5 +1,5 @@ /* - * Copyright 2008-2021 Aerospike, Inc. + * Copyright 2008-2024 Aerospike, Inc. * * Portions may be licensed to Aerospike, Inc. under one or more contributor * license agreements. @@ -88,9 +88,16 @@ typedef struct as_node_stats_s { as_conn_stats pipeline; /** - * Node error count within current window. + * Transaction error count since node was initialized. If the error is retryable, multiple errors per + * transaction may occur. */ - uint32_t error_count; + uint64_t error_count; + + /** + * Transaction timeout count since node was initialized. If the timeout is retryable (ie socket timeout), + * multiple timeouts per transaction may occur. + */ + uint64_t timeout_count; } as_node_stats; @@ -128,6 +135,11 @@ typedef struct as_cluster_stats_s { */ as_event_loop_stats* event_loops; + /** + * Count of transaction retries since cluster was started. + */ + uint64_t retry_count; + /** * Node count. */ @@ -242,6 +254,18 @@ aerospike_event_loop_stats(as_event_loop* event_loop, as_event_loop_stats* stats AS_EXTERN char* aerospike_stats_to_string(as_cluster_stats* stats); +static inline void +as_conn_stats_init(as_conn_stats* stats) +{ + stats->in_pool = 0; + stats->in_use = 0; + stats->opened = 0; + stats->closed = 0; +} + +void +as_conn_stats_sum(as_conn_stats* stats, as_async_conn_pool* pool); + #ifdef __cplusplus } // end extern "C" #endif diff --git a/src/include/aerospike/as_async.h b/src/include/aerospike/as_async.h index e4ca1f5551..2a1e2699c9 100644 --- a/src/include/aerospike/as_async.h +++ b/src/include/aerospike/as_async.h @@ -1,5 +1,5 @@ /* - * Copyright 2008-2023 Aerospike, Inc. + * Copyright 2008-2024 Aerospike, Inc. * * Portions may be licensed to Aerospike, Inc. under one or more contributor * license agreements. @@ -110,7 +110,9 @@ as_async_write_command_create( cmd->flags = 0; cmd->replica_size = pi->replica_size; cmd->replica_index = 0; + cmd->latency_type = AS_LATENCY_TYPE_WRITE; wcmd->listener = listener; + as_cluster_add_tran(cluster); return cmd; } @@ -119,7 +121,8 @@ as_async_record_command_create( as_cluster* cluster, const as_policy_base* policy, as_partition_info* pi, as_policy_replica replica, uint8_t replica_index, bool deserialize, bool heap_rec, uint8_t flags, as_async_record_listener listener, void* udata, as_event_loop* event_loop, - as_pipe_listener pipe_listener, size_t size, as_event_parse_results_fn parse_results + as_pipe_listener pipe_listener, size_t size, as_event_parse_results_fn parse_results, + as_latency_type latency_type ) { // Allocate enough memory to cover: struct size + write buffer size + auth max buffer size @@ -158,7 +161,9 @@ as_async_record_command_create( cmd->replica_size = pi->replica_size; cmd->replica_index = replica_index; + cmd->latency_type = latency_type; rcmd->listener = listener; + as_cluster_add_tran(cluster); return cmd; } @@ -197,7 +202,9 @@ as_async_value_command_create( cmd->flags = 0; cmd->replica_size = pi->replica_size; cmd->replica_index = 0; + cmd->latency_type = AS_LATENCY_TYPE_WRITE; vcmd->listener = listener; + as_cluster_add_tran(cluster); return cmd; } @@ -233,7 +240,9 @@ as_async_info_command_create( cmd->flags = 0; cmd->replica_size = 1; cmd->replica_index = 0; + cmd->latency_type = AS_LATENCY_TYPE_NONE; icmd->listener = listener; + as_cluster_add_tran(node->cluster); return cmd; } diff --git a/src/include/aerospike/as_cdt_ctx.h b/src/include/aerospike/as_cdt_ctx.h index 9e5104b78d..8317a1cc76 100644 --- a/src/include/aerospike/as_cdt_ctx.h +++ b/src/include/aerospike/as_cdt_ctx.h @@ -211,7 +211,7 @@ as_cdt_ctx_add_list_value(as_cdt_ctx* ctx, as_val* val) /** * Lookup map by index offset. - *

+ * * If the index is negative, the resolved index starts backwards from end of list. * If an index is out of bounds, a parameter error will be returned. Examples: *