]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_statsd: handle non-standard meter type safely
authorRijnhard Hessel <rijnhard@teleforge.co.za>
Thu, 8 Jul 2021 12:34:27 +0000 (14:34 +0200)
committerGeorge Joseph <gjoseph@digium.com>
Tue, 3 Aug 2021 13:44:45 +0000 (08:44 -0500)
Meter types are not well supported,
lacking support in telegraf, datadog and the official statsd servers.
We deprecate meters and provide a compliant fallback for any existing usages.

A flag has been introduced to allow meters to fallback to counters.

ASTERISK-29513

Change-Id: I5fcb385983a1b88f03696ff30a26b55c546a1dd7

configs/samples/statsd.conf.sample
doc/CHANGES-staging/res_statsd.txt [new file with mode: 0644]
include/asterisk/statsd.h
res/res_statsd.c

index 806097300d38432883abf5d9ca8ede08239cb07d..fd51cbd21398ed0c878bd329502941d3de3e8f3f 100644 (file)
@@ -6,3 +6,6 @@
 ;add_newline = no              ; Append a newline to every event. This is
                                ; useful if you want to run a fake statsd
                                ; server using netcat (nc -lu 8125)
+;meter_support = yes   ; Enable/disable the non-standard StatsD Meter type
+                               ; if disabled falls back to counter
+                               ; and will append a "_meter" suffix to the metric name
\ No newline at end of file
diff --git a/doc/CHANGES-staging/res_statsd.txt b/doc/CHANGES-staging/res_statsd.txt
new file mode 100644 (file)
index 0000000..317c65d
--- /dev/null
@@ -0,0 +1,5 @@
+Subject: Handle non-standard Meter metric type safely
+
+A meter_support flag has been introduced that defaults to true to maintain current behaviour.
+If disabled, a counter metric type will be used instead wherever a meter metric type was used,
+the counter will have a "_meter" suffix appended to the metric name.
\ No newline at end of file
index 4dbfb77ebb86b58516beba39ff555f3421f770be..1f8468e4c2068327b5c25241280322c747dd7009 100644 (file)
 #define AST_STATSD_TIMER "ms"
 /*! Distribution of values over time. */
 #define AST_STATSD_HISTOGRAM "h"
-/*! Events over time. Sorta like increment-only counters. */
+/*!
+ * Meters are non-standard and poorly supported by StatsD servers
+ * \deprecated You should switch to counter or stateful counters for a similar effect.
+ */
 #define AST_STATSD_METER "m"
 
+
 /*!
  * \brief Send a stat to the configured statsd server.
  *
index bdb3d6fd97f838ea668d9a09e5e8465bcedbb9b4..e250857b3f35084af3d288a40ab81a11993440c7 100644 (file)
                                        you want to fake out a server using netcat
                                        (nc -lu 8125)</synopsis>
                                </configOption>
+                               <configOption name="meter_support">
+                                       <synopsis>Enable/disable the non-standard StatsD Meter type,
+                                       if disabled falls back to counter and will append a "_meter" suffix to the metric name</synopsis>
+                               </configOption>
                        </configObject>
                </configFile>
        </configInfo>
@@ -89,6 +93,8 @@ struct conf_global_options {
        struct ast_sockaddr statsd_server;
        /*! Prefix to put on every stat. */
        char prefix[MAX_PREFIX + 1];
+       /*! Enabled support for non-standard Meter type by default, falls back to counter if disabled */
+       int meter_support;
 };
 
 /*! \brief All configuration options for statsd client. */
@@ -142,7 +148,11 @@ void AST_OPTIONAL_API_NAME(ast_statsd_log_string)(const char *metric_name,
                ast_str_append(&msg, 0, "%s.", cfg->global->prefix);
        }
 
-       ast_str_append(&msg, 0, "%s:%s|%s", metric_name, value, metric_type);
+       if (!cfg->global->meter_support && strcmp(metric_type, AST_STATSD_METER)) {
+               ast_str_append(&msg, 0, "%s_meter:%s|%s", metric_name, value, AST_STATSD_COUNTER);
+       } else {
+               ast_str_append(&msg, 0, "%s:%s|%s", metric_name, value, metric_type);
+       }
 
        if (sample_rate < 1.0) {
                ast_str_append(&msg, 0, "|@%.2f", sample_rate);
@@ -360,6 +370,10 @@ static int load_module(void)
                "", OPT_CHAR_ARRAY_T, 0,
                CHARFLDSET(struct conf_global_options, prefix));
 
+       aco_option_register(&cfg_info, "meter_support", ACO_EXACT, global_options,
+               "yes", OPT_BOOL_T, 1,
+               FLDSET(struct conf_global_options, meter_support));
+
        if (aco_process_config(&cfg_info, 0) == ACO_PROCESS_ERROR) {
                struct conf *cfg;