@cryptotaxi247 / netdata-1 / commits / c6e9d3e14

fix ignored multiplier, divisor, algorithm when adding dimensions to statsd synthetic chart, after the chart has been created; fixes #2253

Costa Tsaousis (ktsaou) committed May 31, 2017 at 00:03 UTC c6e9d3e14179b77563a4028e99daa016a8fca5de
1 file changed +19 -14
src/statsd.c
+19 -14
@@ -30,7 +30,7 @@
30 #define STATSD_DICTIONARY_OPTIONS DICTIONARY_FLAG_SINGLE_THREADED
31 #endif
32
33 -#define STATSD_DECIMAL_DETAIL 1000 // floating point values get multiplied by this, with the same divider
33 +#define STATSD_DECIMAL_DETAIL 1000 // floating point values get multiplied by this, with the same divisor
34
35 // --------------------------------------------------------------------------------------------------------------------
36 // data specific to each metric type
@@ -169,7 +169,7 @@ typedef struct statsd_app_chart_dimension {
169 const char *metric;
170 uint32_t metric_hash;
171 collected_number multiplier;
172 - collected_number divider;
172 + collected_number divisor;
173 STATSD_APP_CHART_DIM_VALUE_TYPE value_type;
174
175 RRDDIM *rd;
@@ -1072,7 +1072,7 @@ int statsd_readfile(const char *path, const char *filename) {
1072 chart->chart_type = rrdset_type_id(value);
1073 }
1074 else if (!strcmp(name, "dimension")) {
1075 - // metric [name [type [multiplier [divider]]]]
1075 + // metric [name [type [multiplier [divisor]]]]
1076 char *words[5];
1077 pluginsd_split_words(value, words, 5);
1078
@@ -1080,7 +1080,7 @@ int statsd_readfile(const char *path, const char *filename) {
1080 char *dim_name = words[1];
1081 char *type = words[2];
1082 char *multipler = words[3];
1083 - char *divider = words[4];
1083 + char *divisor = words[4];
1084
1085 STATSD_APP_CHART_DIM *dim = callocz(sizeof(STATSD_APP_CHART_DIM), 1);
1086
@@ -1089,7 +1089,7 @@ int statsd_readfile(const char *path, const char *filename) {
1089
1090 dim->name = strdupz((dim_name && *dim_name)?dim_name:metric_name);
1091 dim->multiplier = (multipler && *multipler)?str2l(multipler):1;
1092 - dim->divider = (divider && *divider)?str2l(divider):1;
1092 + dim->divisor = (divisor && *divisor)?str2l(divisor):1;
1093
1094 if(!type || !*type) type = "last";
1095 if(!strcmp(type, "events")) dim->value_type = STATSD_APP_CHART_DIM_VALUE_TYPE_EVENTS;
@@ -1110,9 +1110,9 @@ int statsd_readfile(const char *path, const char *filename) {
1110 error("STATSD: invalid multiplier value '%s' at line %zu of file '%s/%s'. Using 1.", multipler, line, path, filename);
1111 dim->multiplier = 1;
1112 }
1113 - if(!dim->divider) {
1114 - error("STATSD: invalid divider value '%s' at line %zu of file '%s/%s'. Using 1.", divider, line, path, filename);
1115 - dim->divider = 1;
1113 + if(!dim->divisor) {
1114 + error("STATSD: invalid divisor value '%s' at line %zu of file '%s/%s'. Using 1.", divisor, line, path, filename);
1115 + dim->divisor = 1;
1116 }
1117
1118 // append it to the list of dimension
@@ -1128,8 +1128,8 @@ int statsd_readfile(const char *path, const char *filename) {
1128 }
1129 chart->dimensions_count++;
1130
1131 - debug(D_STATSD, "Added dimension '%s' to chart '%s' of app '%s', for metric '%s', with type %u, multiplier " COLLECTED_NUMBER_FORMAT ", divider " COLLECTED_NUMBER_FORMAT,
1132 - dim->name, chart->name, app->name, dim->metric, dim->value_type, dim->multiplier, dim->divider);
1131 + debug(D_STATSD, "Added dimension '%s' to chart '%s' of app '%s', for metric '%s', with type %u, multiplier " COLLECTED_NUMBER_FORMAT ", divisor " COLLECTED_NUMBER_FORMAT,
1132 + dim->name, chart->name, app->name, dim->metric, dim->value_type, dim->multiplier, dim->divisor);
1133 }
1134 else {
1135 error("STATSD: ignoring line %zu ('%s') of file '%s/%s'. Unknown keyword for the [%s] section.", line, name, path, filename, chart->id);
@@ -1553,7 +1553,6 @@ static inline void check_if_metric_is_for_app(STATSD_INDEX *index, STATSD_METRIC
1553 for(dim = chart->dimensions; dim ; dim = dim->next) {
1554 if(!dim->value_ptr && dim->metric_hash == m->hash && !strcmp(dim->metric, m->name)) {
1555 // we have a match - this metric should be linked to this dimension
1556 - debug(D_STATSD, "metric '%s' linked with app '%s', chart '%s', dimension '%s'", m->name, app->name, chart->id, dim->name);
1556
1557 if(dim->value_type == STATSD_APP_CHART_DIM_VALUE_TYPE_EVENTS) {
1558 dim->value_ptr = &m->events;
@@ -1561,7 +1560,7 @@ static inline void check_if_metric_is_for_app(STATSD_INDEX *index, STATSD_METRIC
1560 }
1561 else if(m->type == STATSD_METRIC_TYPE_HISTOGRAM || m->type == STATSD_METRIC_TYPE_TIMER) {
1562 dim->algorithm = RRD_ALGORITHM_ABSOLUTE;
1564 - dim->divider *= STATSD_DECIMAL_DETAIL;
1563 + dim->divisor *= STATSD_DECIMAL_DETAIL;
1564
1565 switch(dim->value_type) {
1566 case STATSD_APP_CHART_DIM_VALUE_TYPE_EVENTS:
@@ -1606,10 +1605,11 @@ static inline void check_if_metric_is_for_app(STATSD_INDEX *index, STATSD_METRIC
1605 dim->algorithm = statsd_algorithm_for_metric(m);
1606
1607 if(m->type == STATSD_METRIC_TYPE_GAUGE)
1609 - dim->divider *= STATSD_DECIMAL_DETAIL;
1608 + dim->divisor *= STATSD_DECIMAL_DETAIL;
1609 }
1610
1611 chart->dimensions_linked_count++;
1612 + debug(D_STATSD, "metric '%s' of type %u linked with app '%s', chart '%s', dimension '%s', algorithm '%s'", m->name, m->type, app->name, chart->id, dim->name, rrd_algorithm_name(dim->algorithm));
1613 }
1614 }
1615 }
@@ -1642,9 +1642,14 @@ static inline void statsd_update_app_chart(STATSD_APP *app, STATSD_APP_CHART *ch
1642 STATSD_APP_CHART_DIM *dim;
1643 for(dim = chart->dimensions; dim ;dim = dim->next) {
1644 if(unlikely(!dim->rd))
1645 - dim->rd = rrddim_add(chart->st, dim->name, NULL, dim->multiplier, dim->divider, dim->algorithm);
1645 + dim->rd = rrddim_add(chart->st, dim->name, NULL, dim->multiplier, dim->divisor, dim->algorithm);
1646
1647 if(unlikely(dim->value_ptr)) {
1648 + // FIXME: this is anorthodox, we should an API call at RRDDIM to overwrite these settings
1649 + dim->rd->algorithm = dim->algorithm;
1650 + dim->rd->multiplier = dim->multiplier;
1651 + dim->rd->divisor = dim->divisor;
1652 +
1653 debug(D_STATSD, "updating dimension '%s' (%s) of chart '%s' (%s) for app '%s' with value " COLLECTED_NUMBER_FORMAT, dim->name, dim->rd->id, chart->id, chart->st->id, app->name, *dim->value_ptr);
1654 rrddim_set_by_pointer(chart->st, dim->rd, *dim->value_ptr);
1655 }