[sr-dev] Re: [kamailio/kamailio] modules/statsd: ensure statsd failures do not stop execution (PR #3819)

2024-04-26 Thread Ostap via sr-dev
@ostap0207 commented on this pull request.



>  }
 
 static int ki_statsd_decr_with_labels(sip_msg_t *msg, str *key, str *labels)
 {
-   return statsd_count(key->s, "-1", labels->s);
+   return convert_result(statsd_count(key->s, "-1", labels->s));
+}
+
+static int convert_result(bool result)
+{
+   if(result == false) {
+   return -1;
+   }
+
+   return 0;

Updated 
https://github.com/kamailio/kamailio/compare/3bbed6d62a2ef3a3fbcbf4d8ba125ab95aec28dd..ee772af9e7acbdac14247010e1e7ecf539d759ba

-- 
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/pull/3819#discussion_r1580680113
You are receiving this because you are subscribed to this thread.

Message ID: ___
Kamailio (SER) - Development Mailing List
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org


[sr-dev] Re: [kamailio/kamailio] modules/statsd: ensure statsd failures do not stop execution (PR #3819)

2024-04-25 Thread Ostap via sr-dev
@ostap0207 commented on this pull request.



>  }
 
 static int ki_statsd_decr_with_labels(sip_msg_t *msg, str *key, str *labels)
 {
-   return statsd_count(key->s, "-1", labels->s);
+   return convert_result(statsd_count(key->s, "-1", labels->s));
+}
+
+static int convert_result(bool result)
+{
+   if(result == false) {
+   return -1;
+   }
+
+   return 0;

Yes, correct, we noticed this in our local build but haven't updated here yet, 
will fix

-- 
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/pull/3819#discussion_r1580110145
You are receiving this because you are subscribed to this thread.

Message ID: ___
Kamailio (SER) - Development Mailing List
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org


[sr-dev] [kamailio/kamailio] modules/statsd: ensure statsd failures do not stop execution (PR #3819)

2024-04-23 Thread Ostap via sr-dev
 Pre-Submission Checklist



- [x] Commit message has the format required by CONTRIBUTING guide
- [x] Commits are split per component (core, individual modules, libs, utils, 
...)
- [x] Each component has a single commit (if not, squash them into one commit)
- [x] No commits to README files for modules (changes must be done to docbook 
files
in `doc/` subfolder, the README file is autogenerated)

 Type Of Change
- [x] Small bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds new functionality)
- [ ] Breaking change (fix or feature that would change existing functionality)

 Checklist:

- [ ] PR should be backported to stable branches
- [ ] Tested changes locally
- [ ] Related to issue # (replace  with an open issue number)

 Description


2 issues:

**Issue 1:**
Currently statsd functions return bool: `true` or `false` depending when
the function succeeds or fails respectively.

This value gets implicitly converted to `int`: `true` -> `1`, `false` ->
`0`.

For Kamailio `1` means succesfull execution, but `0` means to stop
processing messages, which is not what we want as statsd should not impact
flow execution. Instead we want to return `-1` which signifies error,
but the flow continues.


**Issue 2:**
statsd_init executes `statsd_connect` which tries to connect to statd
server.

If connection fails then kamailio fails to start.
This is not the desired behaviour as:
1. Kamailio should continue working even if statsd server is down,
   metrics should not impact runtime.
2. `statsd_connect` is also re-executed each time we try to send the metric 
https://github.com/salemove/kamailio/blame/master/src/modules/statsd/lib_statsd.c#L76,
so it's initial result is not essential.

Note, that before 5.8 the result of init was already ignored due to
implicit conversion of `false` to `0`
until after
https://github.com/kamailio/kamailio/commit/0186246fce8f0e4bb46b30c05174983cd957a3ba
was introduced (which could be considered a breaking change even if it
seemingly fixes a bug in conversion).

You can view, comment on, or merge this pull request online at:

  https://github.com/kamailio/kamailio/pull/3819

-- Commit Summary --

  * modules/statsd: avoid stopping flow when sending statsd metric fails
  * modules/statsd: do not fail module initilization when statsd init fails

-- File Changes --

M src/modules/statsd/statsd.c (51)

-- Patch Links --

https://github.com/kamailio/kamailio/pull/3819.patch
https://github.com/kamailio/kamailio/pull/3819.diff

-- 
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/pull/3819
You are receiving this because you are subscribed to this thread.

Message ID: 
___
Kamailio (SER) - Development Mailing List
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org