diff options
author | thiagoftsm <thiagoftsm@gmail.com> | 2020-05-25 14:27:27 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-25 14:27:27 +0000 |
commit | 4fb41597da6961813679c1b795793600ddc0a402 (patch) | |
tree | 4b00b831bd6fd48a1fdd069fb4f86ee29ea4a18f /exporting/prometheus | |
parent | 6c4da08ece22cc6233ad01a9e899f13b1477055c (diff) |
Exporting cleanup (#9098)
Cleanup allocated variables for the majority of the databases.
Diffstat (limited to 'exporting/prometheus')
-rw-r--r-- | exporting/prometheus/prometheus.c | 26 | ||||
-rw-r--r-- | exporting/prometheus/prometheus.h | 2 | ||||
-rw-r--r-- | exporting/prometheus/remote_write/remote_write.c | 16 | ||||
-rw-r--r-- | exporting/prometheus/remote_write/remote_write.h | 1 |
4 files changed, 43 insertions, 2 deletions
diff --git a/exporting/prometheus/prometheus.c b/exporting/prometheus/prometheus.c index 6cfe279013..17cf902ebb 100644 --- a/exporting/prometheus/prometheus.c +++ b/exporting/prometheus/prometheus.c @@ -69,6 +69,30 @@ static struct prometheus_server { struct prometheus_server *next; } *prometheus_server_root = NULL; +static netdata_mutex_t prometheus_server_root_mutex = NETDATA_MUTEX_INITIALIZER; + +/** + * Clean server root local structure + */ +void prometheus_clean_server_root() +{ + if (prometheus_server_root) { + netdata_mutex_lock(&prometheus_server_root_mutex); + + struct prometheus_server *ps; + for (ps = prometheus_server_root; ps; ) { + struct prometheus_server *current = ps; + ps = ps->next; + if(current->server) + freez((void *)current->server); + + freez(current); + } + prometheus_server_root = NULL; + netdata_mutex_unlock(&prometheus_server_root_mutex); + } +} + /** * Get the last time when a Prometheus server scraped the Netdata Prometheus exporter. * @@ -82,8 +106,6 @@ static inline time_t prometheus_server_last_access(const char *server, RRDHOST * #ifdef UNIT_TESTING return 0; #endif - static netdata_mutex_t prometheus_server_root_mutex = NETDATA_MUTEX_INITIALIZER; - uint32_t hash = simple_hash(server); netdata_mutex_lock(&prometheus_server_root_mutex); diff --git a/exporting/prometheus/prometheus.h b/exporting/prometheus/prometheus.h index 85bcc7a7f8..2f0845ce98 100644 --- a/exporting/prometheus/prometheus.h +++ b/exporting/prometheus/prometheus.h @@ -36,4 +36,6 @@ char *prometheus_units_copy(char *d, const char *s, size_t usable, int showoldun void format_host_labels_prometheus(struct instance *instance, RRDHOST *host); +extern void prometheus_clean_server_root(); + #endif //NETDATA_EXPORTING_PROMETHEUS_H diff --git a/exporting/prometheus/remote_write/remote_write.c b/exporting/prometheus/remote_write/remote_write.c index 939b98fb73..2a94fc44e7 100644 --- a/exporting/prometheus/remote_write/remote_write.c +++ b/exporting/prometheus/remote_write/remote_write.c @@ -83,6 +83,20 @@ int process_prometheus_remote_write_response(BUFFER *buffer, struct instance *in } /** + * Release specific data allocated. + * + * @param instance an instance data structure. + */ +void clean_prometheus_remote_write(struct instance *instance) +{ + freez(instance->connector_specific_data); + + struct prometheus_remote_write_specific_config *connector_specific_config = + instance->config.connector_specific_config; + freez(connector_specific_config->remote_write_path); +} + +/** * Initialize Prometheus Remote Write connector instance * * @param instance an instance data structure. @@ -117,6 +131,8 @@ int init_prometheus_remote_write_instance(struct instance *instance) connector_specific_data->write_request = init_write_request(); + instance->engine->protocol_buffers_initialized = 1; + return 0; } diff --git a/exporting/prometheus/remote_write/remote_write.h b/exporting/prometheus/remote_write/remote_write.h index 050eb0c1a8..3bd212414a 100644 --- a/exporting/prometheus/remote_write/remote_write.h +++ b/exporting/prometheus/remote_write/remote_write.h @@ -8,6 +8,7 @@ #include "remote_write_request.h" int init_prometheus_remote_write_instance(struct instance *instance); +extern void clean_prometheus_remote_write(struct instance *instance); int format_host_prometheus_remote_write(struct instance *instance, RRDHOST *host); int format_chart_prometheus_remote_write(struct instance *instance, RRDSET *st); |