Change in libosmocore[master]: stats: send real last value if no new values come

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

osmith gerrit-no-reply at lists.osmocom.org
Thu Aug 19 10:25:36 UTC 2021


osmith has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/25206 )


Change subject: stats: send real last value if no new values come
......................................................................

stats: send real last value if no new values come

Fixes: OS#5215
Change-Id: Ibeefd0e3d1dbe4be454ff05a21df4848b2abfabe
---
M include/osmocom/core/stat_item.h
M src/stats.c
M tests/stats/stats_test.c
M tests/stats/stats_test.err
4 files changed, 14 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/06/25206/1

diff --git a/include/osmocom/core/stat_item.h b/include/osmocom/core/stat_item.h
index fbe0433..f4f85cf 100644
--- a/include/osmocom/core/stat_item.h
+++ b/include/osmocom/core/stat_item.h
@@ -32,6 +32,10 @@
 	int16_t last_offs;
 	/*! value FIFO */
 	struct osmo_stat_item_value values[0];
+	/* internal use by stats API: indicate if the last value sent to
+	 * reporters was actually the last value in the FIFO. This may not be
+	 * the case, as always a max of 1 or more values gets sent (OS#5215) */
+	bool stats_last_sent_was_max;
 };
 
 /*! Statistics item description */
diff --git a/src/stats.c b/src/stats.c
index 411ecff..f06515d 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -715,6 +715,11 @@
 	if (!have_value) {
 		/* Send the last value in case a flush is requested */
 		value = osmo_stat_item_get_last(item);
+
+		/* Also send it in case a different max value was sent
+		 * previously (OS#5215) */
+		if (!item->stats_last_sent_was_max)
+			have_value = 1;
 	} else {
 		int32_t next_val;
 		/* If we have multiple values only send the max */
@@ -722,6 +727,8 @@
 			value = OSMO_MAX(value, next_val);
 	}
 
+	item->stats_last_sent_was_max = (osmo_stat_item_get_last(item) == value);
+
 	llist_for_each_entry(srep, &osmo_stats_reporter_list, list) {
 		if (!srep->running)
 			continue;
diff --git a/tests/stats/stats_test.c b/tests/stats/stats_test.c
index 6702131..168b8ad 100644
--- a/tests/stats/stats_test.c
+++ b/tests/stats/stats_test.c
@@ -445,7 +445,7 @@
 	fprintf(stderr, "report (group 1, no update, send last item (!= last max), OS#5215):\n");
 	send_count = 0;
 	osmo_stats_report();
-	OSMO_ASSERT(send_count == 0); /* BUG: should be 2! */
+	OSMO_ASSERT(send_count == 2);
 
 	fprintf(stderr, "report (group 1, no update, nothing to send):\n");
 	send_count = 0;
diff --git a/tests/stats/stats_test.err b/tests/stats/stats_test.err
index f76783c..6590c8b 100644
--- a/tests/stats/stats_test.err
+++ b/tests/stats/stats_test.err
@@ -116,6 +116,8 @@
   test2: item p= g=test.one i=1 n=item.a v=20 u=ma
   test1: item p= g=test.one i=1 n=item.a v=20 u=ma
 report (group 1, no update, send last item (!= last max), OS#5215):
+  test2: item p= g=test.one i=1 n=item.a v=10 u=ma
+  test1: item p= g=test.one i=1 n=item.a v=10 u=ma
 report (group 1, no update, nothing to send):
 report (remove statg1, ctrg1):
   test2: counter p= g=ctr-test:one_dot i=3 n=ctr:a v=0 d=0

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/25206
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Ibeefd0e3d1dbe4be454ff05a21df4848b2abfabe
Gerrit-Change-Number: 25206
Gerrit-PatchSet: 1
Gerrit-Owner: osmith <osmith at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210819/4b335d9f/attachment.htm>


More information about the gerrit-log mailing list