From: Pavel Rochnyack Date: Fri, 20 Jul 2018 15:06:36 +0000 (+0700) Subject: utils_latency: Use plugin name from context to do error reporting X-Git-Url: https://git.octo.it/?p=collectd.git;a=commitdiff_plain;h=c19e4772d542383a17d174301cee635e9fdf6565 utils_latency: Use plugin name from context to do error reporting --- diff --git a/src/tail.c b/src/tail.c index 841b3312..df94580c 100644 --- a/src/tail.c +++ b/src/tail.c @@ -95,7 +95,7 @@ static int ctail_config_add_match_dstype(ctail_config_match_t *cm, } else if (strcasecmp("Distribution", ds_type) == 0) { cm->flags = UTILS_MATCH_DS_TYPE_GAUGE | UTILS_MATCH_CF_GAUGE_DIST; - int status = latency_config(&cm->latency, ci, "tail"); + int status = latency_config(&cm->latency, ci); if (status != 0) return status; } else if (strncasecmp("Counter", ds_type, strlen("Counter")) == 0) { diff --git a/src/utils_latency.c b/src/utils_latency.c index 1d3bf2e9..6e4f8732 100644 --- a/src/utils_latency.c +++ b/src/utils_latency.c @@ -156,7 +156,7 @@ void latency_counter_add(latency_counter_t *lc, cdtime_t latency) /* {{{ */ change_bin_width(lc, latency); bin = (latency - 1) / lc->bin_width; if (bin >= HISTOGRAM_NUM_BINS) { - ERROR("utils_latency: latency_counter_add: Invalid bin: %" PRIu64, bin); + P_ERROR("latency_counter_add: Invalid bin: %" PRIu64, bin); return; } } diff --git a/src/utils_latency_config.c b/src/utils_latency_config.c index 5eb5b6d9..9a91f113 100644 --- a/src/utils_latency_config.c +++ b/src/utils_latency_config.c @@ -25,29 +25,28 @@ * Pavel Rochnyack */ -#include "utils_latency_config.h" -#include "common.h" #include "collectd.h" +#include "common.h" +#include "utils_latency_config.h" static int latency_config_add_percentile(latency_config_t *conf, - oconfig_item_t *ci, - const char *plugin) { + oconfig_item_t *ci) { double percent; int status = cf_util_get_double(ci, &percent); if (status != 0) return status; if ((percent <= 0.0) || (percent >= 100)) { - ERROR("%s plugin: The value for \"%s\" must be between 0 and 100, " - "exclusively.", - plugin, ci->key); + P_ERROR("The value for \"%s\" must be between 0 and 100, " + "exclusively.", + ci->key); return ERANGE; } double *tmp = realloc(conf->percentile, sizeof(*conf->percentile) * (conf->percentile_num + 1)); if (tmp == NULL) { - ERROR("%s plugin: realloc failed.", plugin); + P_ERROR("realloc failed."); return ENOMEM; } conf->percentile = tmp; @@ -57,31 +56,29 @@ static int latency_config_add_percentile(latency_config_t *conf, return 0; } /* int latency_config_add_percentile */ -static int latency_config_add_bucket(latency_config_t *conf, oconfig_item_t *ci, - const char *plugin) { +static int latency_config_add_bucket(latency_config_t *conf, + oconfig_item_t *ci) { if ((ci->values_num != 2) || (ci->values[0].type != OCONFIG_TYPE_NUMBER) || (ci->values[1].type != OCONFIG_TYPE_NUMBER)) { - ERROR("%s plugin: \"%s\" requires exactly two numeric arguments.", plugin, - ci->key); + P_ERROR("\"%s\" requires exactly two numeric arguments.", ci->key); return EINVAL; } if (ci->values[1].value.number && ci->values[1].value.number <= ci->values[0].value.number) { - ERROR("%s plugin: MIN must be less than MAX in \"%s\".", plugin, ci->key); + P_ERROR("MIN must be less than MAX in \"%s\".", ci->key); return ERANGE; } if (ci->values[0].value.number < 0) { - ERROR("%s plugin: MIN must be greater then or equal to zero in \"%s\".", - plugin, ci->key); + P_ERROR("MIN must be greater then or equal to zero in \"%s\".", ci->key); return ERANGE; } latency_bucket_t *tmp = realloc(conf->buckets, sizeof(*conf->buckets) * (conf->buckets_num + 1)); if (tmp == NULL) { - ERROR("%s plugin: realloc failed.", plugin); + P_ERROR("realloc failed."); return ENOMEM; } conf->buckets = tmp; @@ -94,22 +91,21 @@ static int latency_config_add_bucket(latency_config_t *conf, oconfig_item_t *ci, return 0; } /* int latency_config_add_bucket */ -int latency_config(latency_config_t *conf, oconfig_item_t *ci, - char const *plugin) { +int latency_config(latency_config_t *conf, oconfig_item_t *ci) { int status = 0; for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp("Percentile", child->key) == 0) - status = latency_config_add_percentile(conf, child, plugin); + status = latency_config_add_percentile(conf, child); else if (strcasecmp("Bucket", child->key) == 0) - status = latency_config_add_bucket(conf, child, plugin); + status = latency_config_add_bucket(conf, child); else if (strcasecmp("BucketType", child->key) == 0) status = cf_util_get_string(child, &conf->bucket_type); else - WARNING("%s plugin: \"%s\" is not a valid option within a \"%s\" block.", - plugin, child->key, ci->key); + P_WARNING("\"%s\" is not a valid option within a \"%s\" block.", + child->key, ci->key); if (status != 0) return status; @@ -117,9 +113,9 @@ int latency_config(latency_config_t *conf, oconfig_item_t *ci, if ((status == 0) && (conf->percentile_num == 0) && (conf->buckets_num == 0)) { - ERROR("%s plugin: The \"%s\" block must contain at least one " - "\"Percentile\" or \"Bucket\" option.", - plugin, ci->key); + P_ERROR("The \"%s\" block must contain at least one " + "\"Percentile\" or \"Bucket\" option.", + ci->key); return EINVAL; } diff --git a/src/utils_latency_config.h b/src/utils_latency_config.h index 2572fa0d..3d2691a6 100644 --- a/src/utils_latency_config.h +++ b/src/utils_latency_config.h @@ -53,8 +53,7 @@ typedef struct { */ } latency_config_t; -int latency_config(latency_config_t *conf, oconfig_item_t *ci, - char const *plugin); +int latency_config(latency_config_t *conf, oconfig_item_t *ci); int latency_config_copy(latency_config_t *dst, const latency_config_t src);