-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #243 from MrAnno/fix-metrics-probe-cntr-lifetime
Fix disappearing `metrics-probe()` counters
- Loading branch information
Showing
24 changed files
with
291 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/* | ||
* Copyright (c) 2023-2024 Attila Szakacs <[email protected]> | ||
* Copyright (c) 2024 Balazs Scheidler <[email protected]> | ||
* Copyright (c) 2024 László Várady | ||
* Copyright (c) 2024 Axoflow | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
|
@@ -23,49 +24,79 @@ | |
* | ||
*/ | ||
|
||
#include "metrics-tls-cache.h" | ||
#include "dyn-metrics-cache.h" | ||
#include "syslog-ng.h" | ||
#include "apphook.h" | ||
#include "tls-support.h" | ||
|
||
TLS_BLOCK_START | ||
{ | ||
MetricsCache *metrics_cache; | ||
DynMetricsStore *metrics_cache; | ||
} | ||
TLS_BLOCK_END; | ||
|
||
#define metrics_cache __tls_deref(metrics_cache) | ||
|
||
static DynMetricsStore *global_metrics_cache; | ||
static GMutex global_metrics_cache_lock; | ||
|
||
static void | ||
_sync_with_global_cache(DynMetricsStore *store) | ||
{ | ||
g_mutex_lock(&global_metrics_cache_lock); | ||
dyn_metrics_store_merge(global_metrics_cache, store); | ||
g_mutex_unlock(&global_metrics_cache_lock); | ||
} | ||
|
||
static void | ||
_purge_global_cache(gint type, gpointer c) | ||
{ | ||
g_mutex_lock(&global_metrics_cache_lock); | ||
dyn_metrics_store_reset(global_metrics_cache); | ||
g_mutex_unlock(&global_metrics_cache_lock); | ||
} | ||
|
||
static void | ||
_init_tls_cache(gpointer user_data) | ||
{ | ||
g_assert(!metrics_cache); | ||
|
||
metrics_cache = metrics_cache_new(); | ||
metrics_cache = dyn_metrics_store_new(); | ||
} | ||
|
||
static void | ||
_deinit_tls_cache(gpointer user_data) | ||
{ | ||
metrics_cache_free(metrics_cache); | ||
_sync_with_global_cache(metrics_cache); | ||
dyn_metrics_store_free(metrics_cache); | ||
} | ||
|
||
MetricsCache * | ||
metrics_tls_cache(void) | ||
DynMetricsStore * | ||
dyn_metrics_cache(void) | ||
{ | ||
return metrics_cache; | ||
} | ||
|
||
void | ||
metrics_tls_cache_global_init(void) | ||
dyn_metrics_cache_global_init(void) | ||
{ | ||
g_assert(!global_metrics_cache); | ||
g_mutex_init(&global_metrics_cache_lock); | ||
global_metrics_cache = dyn_metrics_store_new(); | ||
|
||
register_application_thread_init_hook(_init_tls_cache, NULL); | ||
register_application_thread_deinit_hook(_deinit_tls_cache, NULL); | ||
|
||
register_application_hook(AH_CONFIG_CHANGED, _purge_global_cache, NULL, AHM_RUN_REPEAT); | ||
|
||
_init_tls_cache(NULL); | ||
} | ||
|
||
void | ||
metrics_tls_cache_global_deinit(void) | ||
dyn_metrics_cache_global_deinit(void) | ||
{ | ||
_deinit_tls_cache(NULL); | ||
|
||
dyn_metrics_store_free(global_metrics_cache); | ||
g_mutex_clear(&global_metrics_cache_lock); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/* | ||
* Copyright (c) 2023-2024 Attila Szakacs <[email protected]> | ||
* Copyright (c) 2024 Balazs Scheidler <[email protected]> | ||
* Copyright (c) 2024 László Várady | ||
* Copyright (c) 2024 Axoflow | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
|
@@ -23,15 +24,15 @@ | |
* | ||
*/ | ||
|
||
#ifndef METRICS_TLS_CACHE_H_INCLUDED | ||
#define METRICS_TLS_CACHE_H_INCLUDED | ||
#ifndef DYN_METRICS_CACHE_H_INCLUDED | ||
#define DYN_METRICS_CACHE_H_INCLUDED | ||
|
||
#include "stats/stats-registry.h" | ||
#include "metrics-cache.h" | ||
#include "dyn-metrics-store.h" | ||
|
||
MetricsCache *metrics_tls_cache(void); | ||
DynMetricsStore *dyn_metrics_cache(void); | ||
|
||
void metrics_tls_cache_global_init(void); | ||
void metrics_tls_cache_global_deinit(void); | ||
void dyn_metrics_cache_global_init(void); | ||
void dyn_metrics_cache_global_deinit(void); | ||
|
||
#endif |
Oops, something went wrong.