Change in libosmocore[master]: rate_ctr: Improve logging

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/.

Pau Espin Pedrol gerrit-no-reply at lists.osmocom.org
Wed Jun 27 14:54:21 UTC 2018


Pau Espin Pedrol has uploaded this change for review. ( https://gerrit.osmocom.org/9753


Change subject: rate_ctr: Improve logging
......................................................................

rate_ctr: Improve logging

Previous logic regarding logging of verification and mangling of
rate_ctr groups made it difficult to debug when an issue occurrs.

Change-Id: I992d165cab5ee6ca9b5b7e4a2210a0951954bd34
---
M src/rate_ctr.c
1 file changed, 20 insertions(+), 15 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/53/9753/1

diff --git a/src/rate_ctr.c b/src/rate_ctr.c
index 777a42a..75302da 100644
--- a/src/rate_ctr.c
+++ b/src/rate_ctr.c
@@ -73,7 +73,7 @@
 static void *tall_rate_ctr_ctx;
 
 
-static bool rate_ctrl_group_desc_validate(const struct rate_ctr_group_desc *desc, bool quiet)
+static bool rate_ctrl_group_desc_validate(const struct rate_ctr_group_desc *desc)
 {
 	unsigned int i;
 	const struct rate_ctr_desc *ctr_desc;
@@ -88,17 +88,15 @@
 		desc->group_name_prefix, desc->num_ctr);
 
 	if (!osmo_identifier_valid(desc->group_name_prefix)) {
-		if (!quiet)
-			LOGP(DLGLOBAL, LOGL_ERROR, "'%s' is not a valid counter group identifier\n",
-				desc->group_name_prefix);
+		LOGP(DLGLOBAL, LOGL_ERROR, "'%s' is not a valid counter group identifier\n",
+			desc->group_name_prefix);
 		return false;
 	}
 
 	for (i = 0; i < desc->num_ctr; i++) {
 		if (!osmo_identifier_valid(ctr_desc[i].name)) {
-			if (!quiet)
-				LOGP(DLGLOBAL, LOGL_ERROR, "'%s' is not a valid counter identifier\n",
-					ctr_desc[i].name);
+			LOGP(DLGLOBAL, LOGL_ERROR, "'%s' is not a valid counter identifier\n",
+				ctr_desc[i].name);
 			return false;
 		}
 	}
@@ -106,12 +104,13 @@
 	return true;
 }
 
-/* return 'in' if it doesn't contaon any '.'; otherwise allocate a copy and
+/* return 'in' if it doesn't contain any '.'; otherwise allocate a copy and
  * replace all '.' with ':' */
 static char *mangle_identifier_ifneeded(const void *ctx, const char *in)
 {
 	char *out;
 	unsigned int i;
+	bool modified = false;
 
 	if (!in)
 		return NULL;
@@ -123,10 +122,16 @@
 	OSMO_ASSERT(out);
 
 	for (i = 0; i < strlen(out); i++) {
-		if (out[i] == '.')
+		if (out[i] == '.') {
 			out[i] = ':';
+			modified = true;
+		}
 	}
 
+	if (modified)
+		LOGP(DLGLOBAL, LOGL_NOTICE, "counter group name mangled: '%s' -> '%s'\n",
+			in, out);
+
 	return out;
 }
 
@@ -139,6 +144,10 @@
 
 	OSMO_ASSERT(desc_new);
 
+	LOGP(DLGLOBAL, LOGL_INFO, "Needed to mangle counter group '%s' names: it is still using '.' as "
+		"separator, which is not allowed. please consider updating the application\n",
+		desc->group_name_prefix);
+
 	/* mangle the name_prefix but copy/keep the rest */
 	desc_new->group_name_prefix = mangle_identifier_ifneeded(desc_new, desc->group_name_prefix);
 	desc_new->group_description = desc->group_description;
@@ -161,7 +170,7 @@
 		ctrd_new[i].description = ctrd[i].description;
 	}
 
-	if (!rate_ctrl_group_desc_validate(desc_new, false)) {
+	if (!rate_ctrl_group_desc_validate(desc_new)) {
 		/* simple mangling of identifiers ('.' -> ':') was not sufficient to render a valid
 		 * descriptor, we have to bail out */
 		LOGP(DLGLOBAL, LOGL_ERROR, "counter group '%s' still invalid after mangling\n",
@@ -169,10 +178,6 @@
 		goto err_free;
 	}
 
-	LOGP(DLGLOBAL, LOGL_INFO, "Needed to mangle counter group '%s' names: it is still using '.' as "
-		"separator, which is not allowed. please consider updating the application\n",
-		desc->group_name_prefix);
-
 	return desc_new;
 err_free:
 	talloc_free(desc_new);
@@ -231,7 +236,7 @@
 		return NULL;
 
 	/* attempt to mangle all '.' in identifiers to ':' for backwards compat */
-	if (!rate_ctrl_group_desc_validate(desc, true)) {
+	if (!rate_ctrl_group_desc_validate(desc)) {
 		desc = rate_ctr_group_desc_mangle(group, desc);
 		if (!desc) {
 			talloc_free(group);

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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I992d165cab5ee6ca9b5b7e4a2210a0951954bd34
Gerrit-Change-Number: 9753
Gerrit-PatchSet: 1
Gerrit-Owner: Pau Espin Pedrol <pespin at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20180627/391e5a60/attachment.htm>


More information about the gerrit-log mailing list