mirror of
https://github.com/emqx/neuron.git
synced 2026-10-27 04:19:50 +08:00
fix(metrics): correct registered rolling counter entry ref count
This commit is contained in:
+6
-4
@@ -263,8 +263,8 @@ int neu_metric_entries_add(neu_metric_entry_t **entries, const char *name,
|
||||
}
|
||||
|
||||
if (NEU_METRIC_TYPE_ROLLING_COUNTER == type) {
|
||||
entry->rcnt = neu_rolling_counter_new(init);
|
||||
if (NULL == entry->rcnt) {
|
||||
// only allocate rolling counter for nonzero time span
|
||||
if (init > 0 && NULL == (entry->rcnt = neu_rolling_counter_new(init))) {
|
||||
free(entry);
|
||||
return -1;
|
||||
}
|
||||
@@ -311,9 +311,11 @@ int neu_metrics_register_entry(const char *name, const char *help,
|
||||
neu_metric_entry_t *e = NULL;
|
||||
|
||||
pthread_rwlock_wrlock(&g_metrics_mtx_);
|
||||
// use `value` field as reference counter, initialize to zero
|
||||
// and we don't need to allocate rolling counter for register entries
|
||||
rv = neu_metric_entries_add(&g_metrics_.registered_metrics, name, help,
|
||||
type, 1);
|
||||
if (1 == rv) {
|
||||
type, 0);
|
||||
if (-1 != rv) {
|
||||
HASH_FIND_STR(g_metrics_.registered_metrics, name, e);
|
||||
++e->value;
|
||||
rv = 0;
|
||||
|
||||
Reference in New Issue
Block a user