<p>osmith <strong>submitted</strong> this change.</p><p><a href="https://gerrit.osmocom.org/c/libosmocore/+/25206">View Change</a></p><div style="white-space:pre-wrap">Approvals:
neels: Looks good to me, approved
daniel: Looks good to me, but someone else must approve
Jenkins Builder: Verified
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">stats: send real last value if no new values come<br><br>Background:<br>* Individual values can be added to osmo_stat_item.values at any time.<br>* Stats are reported at a fixed interval (see vty 'stats interval'),<br> e.g. every 10 seconds.<br>* In order to report a new stat value, we use the maximum of all<br> osmo_stat_item.values added since the last report.<br>* By default, we do not send new stat values if they did not change<br> (see vty 'config-stats' -> 'flush-period' default of 0).<br><br>Fix the following bug:<br>* If 'flush-period' is 0, and no new osmo_stat_item.values are coming<br> in, the last value that gets reported is not necessarily the last<br> entry in osmo_stat_item.values.<br>* For attached reporters (statsd), it could then be that the given stat<br> stays at the wrong value for a long stretch of time (think of several<br> hours/days/forever).<br><br>Explanation of how the test shows that it is fixed:<br>* stats get reported (value is irrelevant)<br>* osmo_stat_item gets a new value: 20<br>* osmo_stat_item gets a new value: 10<br>* stats get reported (value: 20, the maximum of both new values)<br>* osmo_stat_item gets no new values<br>* stats get reported (value: 10, this is new because of the bug fix,<br> the real last value in osmo_stat_item, different from the 20 sent<br> earlier, without the fix it would not send anything here and the last<br> sent value would be 20)<br>* osmo_stat_item gets no new values<br>* stats get reported (nothing gets sent, since the real last value was<br> already sent and 'flush-period' is 0)<br><br>Fixes: OS#5215<br>Change-Id: Ibeefd0e3d1dbe4be454ff05a21df4848b2abfabe<br>---<br>M TODO-RELEASE<br>M include/osmocom/core/stat_item.h<br>M src/stats.c<br>M tests/stats/stats_test.c<br>M tests/stats/stats_test.err<br>5 files changed, 15 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/TODO-RELEASE b/TODO-RELEASE</span><br><span>index 260e1d4..c8966cd 100644</span><br><span>--- a/TODO-RELEASE</span><br><span>+++ b/TODO-RELEASE</span><br><span>@@ -15,3 +15,4 @@</span><br><span> libosmosim osim_card_{reset,close} New API</span><br><span> libosmocore struct rate_ctr_group, osmo_stat_item_group_desc ABI breakage due to new struct members</span><br><span> libosmgsm kdf functions New API</span><br><span style="color: hsl(120, 100%, 40%);">+libosmocore osmo_stat_item ABI + API breakage due to new struct members</span><br><span>diff --git a/include/osmocom/core/stat_item.h b/include/osmocom/core/stat_item.h</span><br><span>index fbe0433..332bbe9 100644</span><br><span>--- a/include/osmocom/core/stat_item.h</span><br><span>+++ b/include/osmocom/core/stat_item.h</span><br><span>@@ -28,6 +28,10 @@</span><br><span> * be read from the FIFO. If accessing osmo_stat_item directly, without</span><br><span> * the stats API, store this value elsewhere. */</span><br><span> int32_t stats_next_id;</span><br><span style="color: hsl(120, 100%, 40%);">+ /* internal use by stats API: indicate if the last value sent to</span><br><span style="color: hsl(120, 100%, 40%);">+ * reporters was actually the last value in the FIFO. This may not be</span><br><span style="color: hsl(120, 100%, 40%);">+ * the case, as always a max of 1 or more values gets sent (OS#5215) */</span><br><span style="color: hsl(120, 100%, 40%);">+ bool stats_last_sent_was_max;</span><br><span> /*! the index of the last value written to the FIFO */</span><br><span> int16_t last_offs;</span><br><span> /*! value FIFO */</span><br><span>diff --git a/src/stats.c b/src/stats.c</span><br><span>index 411ecff..f06515d 100644</span><br><span>--- a/src/stats.c</span><br><span>+++ b/src/stats.c</span><br><span>@@ -715,6 +715,11 @@</span><br><span> if (!have_value) {</span><br><span> /* Send the last value in case a flush is requested */</span><br><span> value = osmo_stat_item_get_last(item);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Also send it in case a different max value was sent</span><br><span style="color: hsl(120, 100%, 40%);">+ * previously (OS#5215) */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!item->stats_last_sent_was_max)</span><br><span style="color: hsl(120, 100%, 40%);">+ have_value = 1;</span><br><span> } else {</span><br><span> int32_t next_val;</span><br><span> /* If we have multiple values only send the max */</span><br><span>@@ -722,6 +727,8 @@</span><br><span> value = OSMO_MAX(value, next_val);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ item->stats_last_sent_was_max = (osmo_stat_item_get_last(item) == value);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> llist_for_each_entry(srep, &osmo_stats_reporter_list, list) {</span><br><span> if (!srep->running)</span><br><span> continue;</span><br><span>diff --git a/tests/stats/stats_test.c b/tests/stats/stats_test.c</span><br><span>index 6505e66..2f2c6ec 100644</span><br><span>--- a/tests/stats/stats_test.c</span><br><span>+++ b/tests/stats/stats_test.c</span><br><span>@@ -445,7 +445,7 @@</span><br><span> fprintf(stderr, "report (group 1, item 1 no update, send last item (!= last max), OS#5215):\n");</span><br><span> send_count = 0;</span><br><span> osmo_stats_report();</span><br><span style="color: hsl(0, 100%, 40%);">- OSMO_ASSERT(send_count == 0); /* BUG: should be 2! */</span><br><span style="color: hsl(120, 100%, 40%);">+ OSMO_ASSERT(send_count == 2);</span><br><span> </span><br><span> fprintf(stderr, "report (group 1, item 1 no update, nothing to send):\n");</span><br><span> send_count = 0;</span><br><span>diff --git a/tests/stats/stats_test.err b/tests/stats/stats_test.err</span><br><span>index 08c2cbc..daa3e5c 100644</span><br><span>--- a/tests/stats/stats_test.err</span><br><span>+++ b/tests/stats/stats_test.err</span><br><span>@@ -116,6 +116,8 @@</span><br><span> test2: item p= g=test.one i=1 n=item.a v=20 u=ma</span><br><span> test1: item p= g=test.one i=1 n=item.a v=20 u=ma</span><br><span> report (group 1, item 1 no update, send last item (!= last max), OS#5215):</span><br><span style="color: hsl(120, 100%, 40%);">+ test2: item p= g=test.one i=1 n=item.a v=10 u=ma</span><br><span style="color: hsl(120, 100%, 40%);">+ test1: item p= g=test.one i=1 n=item.a v=10 u=ma</span><br><span> report (group 1, item 1 no update, nothing to send):</span><br><span> report (remove statg1, ctrg1):</span><br><span> test2: counter p= g=ctr-test:one_dot i=3 n=ctr:a v=0 d=0</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/libosmocore/+/25206">change 25206</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.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.osmocom.org/c/libosmocore/+/25206"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: libosmocore </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: Ibeefd0e3d1dbe4be454ff05a21df4848b2abfabe </div>
<div style="display:none"> Gerrit-Change-Number: 25206 </div>
<div style="display:none"> Gerrit-PatchSet: 5 </div>
<div style="display:none"> Gerrit-Owner: osmith <osmith@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder </div>
<div style="display:none"> Gerrit-Reviewer: daniel <dwillmann@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: dexter <pmaier@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-Reviewer: neels <nhofmeyr@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: osmith <osmith@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>