<p>George Joseph <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/16149">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Joshua Colp: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved; Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_statsd: handle non-standard meter type safely<br><br>Meter types are not well supported,<br>lacking support in telegraf, datadog and the official statsd servers.<br>We deprecate meters and provide a compliant fallback for any existing usages.<br><br>A flag has been introduced to allow meters to fallback to counters.<br><br><br>ASTERISK-29513<br><br>Change-Id: I5fcb385983a1b88f03696ff30a26b55c546a1dd7<br>---<br>M configs/samples/statsd.conf.sample<br>A doc/CHANGES-staging/res_statsd.txt<br>M include/asterisk/statsd.h<br>M res/res_statsd.c<br>4 files changed, 28 insertions(+), 2 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/configs/samples/statsd.conf.sample b/configs/samples/statsd.conf.sample</span><br><span>index 8060973..fd51cbd 100644</span><br><span>--- a/configs/samples/statsd.conf.sample</span><br><span>+++ b/configs/samples/statsd.conf.sample</span><br><span>@@ -6,3 +6,6 @@</span><br><span> ;add_newline = no ; Append a newline to every event. This is</span><br><span> ; useful if you want to run a fake statsd</span><br><span> ; server using netcat (nc -lu 8125)</span><br><span style="color: hsl(120, 100%, 40%);">+;meter_support = yes ; Enable/disable the non-standard StatsD Meter type</span><br><span style="color: hsl(120, 100%, 40%);">+ ; if disabled falls back to counter</span><br><span style="color: hsl(120, 100%, 40%);">+ ; and will append a "_meter" suffix to the metric name</span><br><span>\ No newline at end of file</span><br><span>diff --git a/doc/CHANGES-staging/res_statsd.txt b/doc/CHANGES-staging/res_statsd.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..317c65d</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/res_statsd.txt</span><br><span>@@ -0,0 +1,5 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: Handle non-standard Meter metric type safely</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+A meter_support flag has been introduced that defaults to true to maintain current behaviour.</span><br><span style="color: hsl(120, 100%, 40%);">+If disabled, a counter metric type will be used instead wherever a meter metric type was used,</span><br><span style="color: hsl(120, 100%, 40%);">+the counter will have a "_meter" suffix appended to the metric name.</span><br><span>\ No newline at end of file</span><br><span>diff --git a/include/asterisk/statsd.h b/include/asterisk/statsd.h</span><br><span>index 4dbfb77..1f8468e 100644</span><br><span>--- a/include/asterisk/statsd.h</span><br><span>+++ b/include/asterisk/statsd.h</span><br><span>@@ -41,9 +41,13 @@</span><br><span> #define AST_STATSD_TIMER "ms"</span><br><span> /*! Distribution of values over time. */</span><br><span> #define AST_STATSD_HISTOGRAM "h"</span><br><span style="color: hsl(0, 100%, 40%);">-/*! Events over time. Sorta like increment-only counters. */</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * Meters are non-standard and poorly supported by StatsD servers</span><br><span style="color: hsl(120, 100%, 40%);">+ * \deprecated You should switch to counter or stateful counters for a similar effect.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span> #define AST_STATSD_METER "m"</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*!</span><br><span> * \brief Send a stat to the configured statsd server.</span><br><span> *</span><br><span>diff --git a/res/res_statsd.c b/res/res_statsd.c</span><br><span>index bdb3d6f..e250857 100644</span><br><span>--- a/res/res_statsd.c</span><br><span>+++ b/res/res_statsd.c</span><br><span>@@ -58,6 +58,10 @@</span><br><span> you want to fake out a server using netcat</span><br><span> (nc -lu 8125)</synopsis></span><br><span> </configOption></span><br><span style="color: hsl(120, 100%, 40%);">+ <configOption name="meter_support"></span><br><span style="color: hsl(120, 100%, 40%);">+ <synopsis>Enable/disable the non-standard StatsD Meter type,</span><br><span style="color: hsl(120, 100%, 40%);">+ if disabled falls back to counter and will append a "_meter" suffix to the metric name</synopsis></span><br><span style="color: hsl(120, 100%, 40%);">+ </configOption></span><br><span> </configObject></span><br><span> </configFile></span><br><span> </configInfo></span><br><span>@@ -89,6 +93,8 @@</span><br><span> struct ast_sockaddr statsd_server;</span><br><span> /*! Prefix to put on every stat. */</span><br><span> char prefix[MAX_PREFIX + 1];</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! Enabled support for non-standard Meter type by default, falls back to counter if disabled */</span><br><span style="color: hsl(120, 100%, 40%);">+ int meter_support;</span><br><span> };</span><br><span> </span><br><span> /*! \brief All configuration options for statsd client. */</span><br><span>@@ -142,7 +148,11 @@</span><br><span> ast_str_append(&msg, 0, "%s.", cfg->global->prefix);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ast_str_append(&msg, 0, "%s:%s|%s", metric_name, value, metric_type);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!cfg->global->meter_support && strcmp(metric_type, AST_STATSD_METER)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_append(&msg, 0, "%s_meter:%s|%s", metric_name, value, AST_STATSD_COUNTER);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_append(&msg, 0, "%s:%s|%s", metric_name, value, metric_type);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span> if (sample_rate < 1.0) {</span><br><span> ast_str_append(&msg, 0, "|@%.2f", sample_rate);</span><br><span>@@ -360,6 +370,10 @@</span><br><span> "", OPT_CHAR_ARRAY_T, 0,</span><br><span> CHARFLDSET(struct conf_global_options, prefix));</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ aco_option_register(&cfg_info, "meter_support", ACO_EXACT, global_options,</span><br><span style="color: hsl(120, 100%, 40%);">+ "yes", OPT_BOOL_T, 1,</span><br><span style="color: hsl(120, 100%, 40%);">+ FLDSET(struct conf_global_options, meter_support));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> if (aco_process_config(&cfg_info, 0) == ACO_PROCESS_ERROR) {</span><br><span> struct conf *cfg;</span><br><span> </span><br><span></span><br></pre><div style="white-space:pre-wrap"></div><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/16149">change 16149</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/16149"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-Change-Id: I5fcb385983a1b88f03696ff30a26b55c546a1dd7 </div>
<div style="display:none"> Gerrit-Change-Number: 16149 </div>
<div style="display:none"> Gerrit-PatchSet: 9 </div>
<div style="display:none"> Gerrit-Owner: Rijnhard Hessel <rijnhard@teleforge.co.za> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>