@cryptotaxi247 / netdata-1 / commits / e447276bc

code cleanup

Costa Tsaousis (ktsaou) committed Apr 17, 2018 at 02:24 UTC e447276bccf331aa09677706af23d64374b4c82d
1 file changed +14 -7
src/statsd.c
+14 -7
@@ -89,6 +89,8 @@ typedef enum statsd_metric_options {
89 STATSD_METRIC_OPTION_CHART_DIMENSION_COUNT = 0x00000008, // show the count of events for this private chart
90 STATSD_METRIC_OPTION_CHECKED_IN_APPS = 0x00000010, // set when this metric has been checked against apps
91 STATSD_METRIC_OPTION_USED_IN_APPS = 0x00000020, // set when this metric is used in apps
92 + STATSD_METRIC_OPTION_CHECKED = 0x00000040, // set when the charting thread checks this metric for use in charts (its usefulness)
93 + STATSD_METRIC_OPTION_USEFUL = 0x00000080, // set when the charting thread finds the metric useful (i.e. used in a chart)
94 } STATS_METRIC_OPTIONS;
95
96 typedef enum statsd_metric_type {
@@ -459,11 +461,11 @@ static inline int value_is_zinit(const char *value) {
461 return (value && *value == 'z' && *++value == 'i' && *++value == 'n' && *++value == 'i' && *++value == 't' && *++value == '\0');
462 }
463
462 -#define is_metric_checked(m) (((m)->options & (STATSD_METRIC_OPTION_PRIVATE_CHART_CHECKED|STATSD_METRIC_OPTION_CHECKED_IN_APPS)) == (STATSD_METRIC_OPTION_PRIVATE_CHART_CHECKED|STATSD_METRIC_OPTION_CHECKED_IN_APPS))
463 -#define is_metric_useful(m) (!is_metric_checked(m) || ((m)->options & (STATSD_METRIC_OPTION_PRIVATE_CHART_ENABLED|STATSD_METRIC_OPTION_USED_IN_APPS)) != 0)
464 +#define is_metric_checked(m) ((m)->options & STATSD_METRIC_OPTION_CHECKED)
465 +#define is_metric_useful_for_collection(m) (!is_metric_checked(m) || ((m)->options & STATSD_METRIC_OPTION_USEFUL))
466
467 static inline void statsd_process_gauge(STATSD_METRIC *m, const char *value, const char *sampling) {
466 - if(!is_metric_useful(m)) return;
468 + if(!is_metric_useful_for_collection(m)) return;
469
470 if(unlikely(!value || !*value)) {
471 error("STATSD: metric '%s' of type gauge, with empty value is ignored.", m->name);
@@ -490,7 +492,7 @@ static inline void statsd_process_gauge(STATSD_METRIC *m, const char *value, con
492 }
493
494 static inline void statsd_process_counter_or_meter(STATSD_METRIC *m, const char *value, const char *sampling) {
493 - if(!is_metric_useful(m)) return;
495 + if(!is_metric_useful_for_collection(m)) return;
496
497 // we accept empty values for counters
498
@@ -511,7 +513,7 @@ static inline void statsd_process_counter_or_meter(STATSD_METRIC *m, const char
513 #define statsd_process_meter(m, value, sampling) statsd_process_counter_or_meter(m, value, sampling)
514
515 static inline void statsd_process_histogram_or_timer(STATSD_METRIC *m, const char *value, const char *sampling, const char *type) {
514 - if(!is_metric_useful(m)) return;
516 + if(!is_metric_useful_for_collection(m)) return;
517
518 if(unlikely(!value || !*value)) {
519 error("STATSD: metric of type %s, with empty value is ignored.", type);
@@ -545,7 +547,7 @@ static inline void statsd_process_histogram_or_timer(STATSD_METRIC *m, const cha
547 #define statsd_process_histogram(m, value, sampling) statsd_process_histogram_or_timer(m, value, sampling, "histogram")
548
549 static inline void statsd_process_set(STATSD_METRIC *m, const char *value) {
548 - if(!is_metric_useful(m)) return;
550 + if(!is_metric_useful_for_collection(m)) return;
551
552 if(unlikely(!value || !*value)) {
553 error("STATSD: metric of type set, with empty value is ignored.");
@@ -2084,7 +2086,12 @@ static inline void statsd_flush_index_metrics(STATSD_INDEX *index, void (*flush_
2086 m->options |= STATSD_METRIC_OPTION_PRIVATE_CHART_CHECKED;
2087 }
2088
2087 - if(is_metric_useful(m)) {
2089 + // mark it as checked
2090 + m->options |= STATSD_METRIC_OPTION_CHECKED;
2091 +
2092 + // check if it is used in charts
2093 + if((m->options & (STATSD_METRIC_OPTION_PRIVATE_CHART_ENABLED|STATSD_METRIC_OPTION_USED_IN_APPS)) && !(m->options & STATSD_METRIC_OPTION_USEFUL)) {
2094 + m->options |= STATSD_METRIC_OPTION_USEFUL;
2095 index->useful++;
2096 m->next_useful = index->first_useful;
2097 index->first_useful = m;