diff options
author | thiagoftsm <thiagoftsm@gmail.com> | 2020-01-14 10:27:22 +0000 |
---|---|---|
committer | Timo <timotej@netdata.cloud> | 2020-01-14 11:27:22 +0100 |
commit | ef2b11fcb4d56ec946f6dc24929ba6ec0b54d0f2 (patch) | |
tree | 5ac5e89b35404bdabc08162505f9ad02c86df7c3 /database | |
parent | bb51e824f97cd135674e2940bdbd5458fbfba15f (diff) |
Stream with labels (#7549)
This commit enables streaming host labels
Diffstat (limited to 'database')
-rw-r--r-- | database/rrd.h | 6 | ||||
-rw-r--r-- | database/rrdhost.c | 33 |
2 files changed, 30 insertions, 9 deletions
diff --git a/database/rrd.h b/database/rrd.h index 0702fc1710..40efd60e92 100644 --- a/database/rrd.h +++ b/database/rrd.h @@ -156,6 +156,9 @@ typedef enum label_source { LABEL_SOURCE_KUBERNETES = 4 } LABEL_SOURCE; +#define LABEL_FLAG_UPDATE_STREAM 1 +#define LABEL_FLAG_STOP_STREAM 2 + struct label { char *key, *value; uint32_t key_hash; @@ -166,6 +169,8 @@ struct label { char *translate_label_source(LABEL_SOURCE l); struct label *create_label(char *key, char *value, LABEL_SOURCE label_source); struct label *add_label_to_list(struct label *l, char *key, char *value, LABEL_SOURCE label_source); +extern void replace_label_list(RRDHOST *host, struct label *new_labels); +extern void free_host_labels(struct label *labels); void reload_host_labels(); // ---------------------------------------------------------------------------- @@ -749,6 +754,7 @@ struct rrdhost { // Support for host-level labels struct label *labels; netdata_rwlock_t labels_rwlock; // lock for the label list + uint32_t labels_flag; //Flags for labels // ------------------------------------------------------------------------ // indexes diff --git a/database/rrdhost.c b/database/rrdhost.c index df4e364d9b..a7fac8569b 100644 --- a/database/rrdhost.c +++ b/database/rrdhost.c @@ -890,6 +890,26 @@ struct label *create_label(char *key, char *value, LABEL_SOURCE label_source) return result; } +void free_host_labels(struct label *labels) +{ + while (labels != NULL) + { + struct label *current = labels; + labels = labels->next; + freez(current); + } +} + +void replace_label_list(RRDHOST *host, struct label *new_labels) +{ + netdata_rwlock_wrlock(&host->labels_rwlock); + struct label *old_labels = host->labels; + host->labels = new_labels; + netdata_rwlock_unlock(&host->labels_rwlock); + + free_host_labels(old_labels); +} + struct label *add_label_to_list(struct label *l, char *key, char *value, LABEL_SOURCE label_source) { struct label *lab = create_label(key, value, label_source); @@ -937,16 +957,11 @@ void reload_host_labels() struct label *new_labels = merge_label_lists(from_auto, from_k8s); new_labels = merge_label_lists(new_labels, from_config); - netdata_rwlock_wrlock(&localhost->labels_rwlock); - struct label *old_labels = localhost->labels; - localhost->labels = new_labels; - netdata_rwlock_unlock(&localhost->labels_rwlock); + replace_label_list(localhost, new_labels); - while (old_labels != NULL) - { - struct label *current = old_labels; - old_labels = old_labels->next; - freez(current); + if(localhost->rrdpush_send_enabled && localhost->rrdpush_sender_buffer){ + localhost->labels_flag |= LABEL_FLAG_UPDATE_STREAM; + rrdpush_send_labels(localhost); } health_reload(); |