Skip to content

Commit cec570f

Browse files
committed
address comments
1 parent 6375e91 commit cec570f

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/modules/keydb_modstatsd/modmain.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ class StatsdClientWrapper
6767

6868
/* constants */
6969
static time_t c_infoUpdateSeconds = 10;
70+
// the current Redis Cluster setup we configure replication factor as 2, each non-empty master node should have 2 replicas, given that there are 3 zones in each regions
71+
static const int EXPECTED_NUMBER_OF_REPLICAS = 2;
7072

7173
StatsdClientWrapper *g_stats = nullptr;
7274
std::string m_strPrefix { "keydb" };
@@ -544,17 +546,19 @@ void emit_system_free_memory() {
544546
}
545547
}
546548

547-
void emit_non_empty_primary_with_less_than_2_connected_replicas_error_metrics(struct RedisModuleCtx *ctx, long long keys) {
549+
void emit_metrics_for_insufficient_replicas(struct RedisModuleCtx *ctx, long long keys) {
548550
// non-empty
549551
if (keys <= 0) {
550552
return;
551553
}
552554
RedisModuleCallReply *reply = RedisModule_Call(ctx, "ROLE", "");
553555
if (RedisModule_CallReplyType(reply) != REDISMODULE_REPLY_ARRAY) {
556+
RedisModule_FreeCallReply(reply);
554557
return;
555558
}
556559
RedisModuleCallReply *roleReply = RedisModule_CallReplyArrayElement(reply, 0);
557560
if (RedisModule_CallReplyType(roleReply) != REDISMODULE_REPLY_STRING) {
561+
RedisModule_FreeCallReply(reply);
558562
return;
559563
}
560564
size_t len;
@@ -563,10 +567,11 @@ void emit_non_empty_primary_with_less_than_2_connected_replicas_error_metrics(st
563567
if (strncmp(role, "master", len) == 0) {
564568
RedisModuleCallReply *replicasReply = RedisModule_CallReplyArrayElement(reply, 2);
565569
// check if there are less than 2 connected replicas
566-
if (RedisModule_CallReplyLength(replicasReply) < 2) {
567-
g_stats->increment("hasLessThan2ConnectedReplicas_error", 1);
570+
if (RedisModule_CallReplyLength(replicasReply) < EXPECTED_NUMBER_OF_REPLICAS) {
571+
g_stats->increment("lessThanExpectedReplicas_error", 1);
568572
}
569573
}
574+
RedisModule_FreeCallReply(reply);
570575
}
571576

572577
void event_cron_handler(struct RedisModuleCtx *ctx, RedisModuleEvent eid, uint64_t subevent, void *data) {
@@ -652,7 +657,7 @@ void event_cron_handler(struct RedisModuleCtx *ctx, RedisModuleEvent eid, uint64
652657
RedisModule_Log(ctx, REDISMODULE_LOGLEVEL_DEBUG, "Emitting metric \"keys\": %llu", keys);
653658
g_stats->timing("emit_keys_metric_time_taken_us", ustime() - commandStartTime);
654659

655-
emit_non_empty_primary_with_less_than_2_connected_replicas_error_metrics(ctx, keys);
660+
emit_metrics_for_insufficient_replicas(ctx, keys);
656661

657662
g_stats->timing("metrics_time_taken_us", ustime() - startTime);
658663

0 commit comments

Comments
 (0)