-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a message-id parameter for messages #433
Conversation
Can one of the admins verify this patch? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm conflicted about the idea. The capability is nice but the code gets messy. I'm hesitant about adding target-specific arguments to otherwise generic logging functions (I'm sure there's extra info we could add to syslog or other targets).
lib/log_dcs.c
Outdated
cs = csl->cs; | ||
break; | ||
strcmp(safe_filename, csl->cs->filename) == 0 && | ||
strcmp(safe_message_id, csl->cs->message_id) == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not clear on how this code works -- is checking message ID necessary here? Maybe only if we allow filtering by ID?
I'm not against the idea in principle (I've worked in mainframe environments where Message-IDs have been very useful to me), but we need to be sure that a) people using libqb do actually want this and will use it and b) it is 100% backwards compatible. |
c775613
to
48b9bcf
Compare
I thought I was smart to simply use the conditional compilation, but unfortunately, it's not a solution. I will just do as #433 (comment) here (assuming |
Sadly ABI backward compatibility is very unforgiving. In Pacemaker we have tons of APIs I would love to change ... The basic idea is that an application linked against a shared library with a particular version can continue to be used without requiring code changes, recompilation, or relinking if the library is upgraded to a newer version that is ABI compatible. New APIs can be added, new members can be added to the end of structs (if the struct can only be allocated by library functions), new enum values can be added to the end, etc., without breaking compatibility. But anything that changes a function signature, or changes an existing struct member type or order, etc., requires a shared object version bump to force applications to at least be re-linked (otherwise they could have undefined behavior if used with the newer library). |
I really missed the point that the structure is only allocated in the library. It should be backward compatible then=) |
Also, it would be nice if we could just bump the shared object version anytime we wanted, so we could change the APIs, but that requires all clients to be rebuilt and possibly even require code changes, which is a burden to their developers and packagers. Many OSes/distributions avoid breaking ABI compatibility within a major release, so it also delays when they can adopt the new version. For Pacemaker I'm aiming for roughly at least 6 years between ABI breaks (the last one was 2.0.0 in 2018). Of course APIs that aren't exposed in installed headers, and any that are but are explicitly documented as internal, aren't subject to any limitations and can be changed however needed. |
48b9bcf
to
b76721f
Compare
@kgaillot @chrissie-c please have a loot at the latest change. I've made it backward compatible. It's only left to add new tests. |
This is starting to look good now, thanks! |
test this please |
b76721f
to
df4236d
Compare
Fixed.
I added a tiny change to the |
test this please |
@aleksei-burlakov sorry, when I say "test this please" it's an instruction to the CI to test the new code - not to you :) |
So it's a magic spell). Could you please give your feedback about the latest changes? |
I've sent a message to users@clusterlabs.org asking for user feedback on the idea. |
Thanks Ken |
The latest patch looks good to me, thanks. One tiny thing: I think it would be good to test the message ID that comes back in the check_log.c:1049 matches the one we sent at line 1029:
|
df4236d
to
94f352e
Compare
Thanks! I have amended the PR. |
94f352e
to
44cc52f
Compare
@chrissie-c @kgaillot do you think it's mergeable? |
I'm happy to merge it, but I would like Ken's approval too as pacemaker is the major user of the logging subsystem. |
44cc52f
to
bf7e87f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I had started a review and got distracted and forgot to send it. It looks good to me, just some minor comments.
I'm still not too sure how well this will work in practice, but we won't know until we try ...
include/qb/qblog.h
Outdated
@@ -258,6 +259,10 @@ struct qb_log_callsite { | |||
uint32_t lineno; | |||
uint32_t targets; | |||
uint32_t tags; | |||
/* message_id must be the last argument to | |||
* make it compatible with the external | |||
* programs that don't use it */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would drop this comment, since any new members in the future must be added after this one. It's always true that once a member is added, its order cannot be changed without breaking compatibility, so no special comment is needed. (If we did want to make that more explicit, it could be added to any developer documentation libqb has or should have, or as a comment at the top of each public header.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
include/qb/qblog.h
Outdated
@@ -319,6 +324,39 @@ struct qb_log_callsite* qb_log_callsite_get(const char *function, | |||
uint32_t lineno, | |||
uint32_t tags); | |||
|
|||
/** | |||
* Get or create a callsite at the given position. | |||
* The same that qb_log_callsite_ge but with the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing a "t"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Fixed.
lib/log_dcs.c
Outdated
{ | ||
return qb_log_dcs_get2(newly_created, NULL, function, | ||
filename, format, priority, lineno, tags); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
qb_log_dcs_get() is an internal function and was only used in the one spot, so we can just drop it now (or use its name for the new function)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. I have added the message-id
to the qb_log_dcs_get
and removed the qb_log_dcs_get2
.
Note that this is just a stranded instance of generalized structured I don't see much sense in bloating API piece-wise whenever new field Btw. this is the origin of the process that added structured logging https://lwn.net/Articles/492125/ Last I had a look, this provision appeared to be utilized heavily, (Of course, another inspiration can be In addition, there needs to be some set of rules that the keys need to Also, Another remark: (EDIT: it is not as I thought, i.e., that There is also a possibility to provide some postprocessing fix-ups Yet another remark: if nobody is to bite the structured logging bullet [*] I can see catalogs only from 2 packages/0.05% of all packages here:
|
That's good! Now we start implementing it.
Are you sure this is a good idea? The string could be greped and they are easier to read. |
@aleksei-burlakov Don't worry about poki's comment. |
The message-id parameter will enable systemd catalogs. To enable message-id's the libqb should be configured with the --enable-systemd-journal option.
bf7e87f
to
a407a31
Compare
You can grep it in the accompanying catalog files, that should Do you have any more concerns? Please assume good intentions, toxicity doesn't help. |
I don't think it would bring any space efficiency. Those |
test this please |
The coverity scan doesn't seem to find new vulnerabilities. |
It's finding old one because covscan was updated last week I think :) |
Merged thanks. I'll do a release a little later this week to get the other new stuff out to people |
Thanks to everyone who participated! |
I believe a wider context is owed since otherwise it may look like just I admit being too terse about my main concern of a premature single-use It is specifically this striking disproportion between the gain with Why? Simply because it seems (to me) that [*] EDIT: Also note how the current support of Such a disaster, you may cynically say, but the problem will get real This adds into the future burden that may be ahead, and could be I think that libqb is already systemic and internally structured well /* -1 denotes error, -2 and less denotes the fetcher asks libqb's
runtime to extend the buffer resulting in 2+ cell pairs available,
and subsequently to call it again; positive denotes how many cell
pairs have actually been used out of it; libqb's runtime will always
call it with at least one cell pair available */
typedef size_t (qb_log_tag_struct_fetcher*)(struct qb_log_callsite *cs, va_list msg_interpolation_vars,
void *passaround_data,
char *inprep_structured_log_buf[], size_t cell_pairs_available);
/* also return previously registered fetcher */
qb_log_tag_struct_fetcher * qb_log_tag_struct_fetcher_register(unsigned char which_tag_bit,
qb_log_tag_struct_fetcher *fn,
void *passaround_data); User would then dedicate a particular bit in Yes, I don't like this design too much either :-) It'd be preferred if a wider design sweep was made, considering Anyway, if you want to add a special treatment for #define MY_DEDICATED_MSGID_BIT 1 << 4;
static const char my_msgid_field = "MESSAGE_ID";
size_t my_msgid_fetcher(struct qb_log_callsite *cs, va_list msg_interpolation_vars,
void *passaround_data,
char *inprep_structured_log_buf[], size_t cell_pairs_available)
{
/* msg_interpolation_vars can inform further metadata assignments */
size_t consumed = 0;
const char *msgid = get_msgid_for_cs(passaround_data, cs);
if (msgid) {
assert(cell_pairs_available >= 2);
inprep_structured_log_buf[consumed++] = my_msgid_field;
inprep_structured_log_buf[consumed++] = msgid;
} else {
fprintf(stderr, "MY_DEDICATED_MSGID_BIT tag contract violated/n");
}
return consumed;
}
qb_log_tag_struct_fetcher_register(MY_DEDICATED_MSGID_BIT, my_msgid_fetcher, msgid_table); Finally, I hope to cast another perspective into richer logging It leaves a lot to be expected/makes for an inferior user experience This was (and perhaps still is) a topic for pacemaker, e.g. Now, with, e.g., a qualified help of proper metadata annotations There is a standard for such marking being considered in systemd: (Of course, there could also be a more dynamic behaviour of marking The point is, the sensitive lines will be marked as such on the go, Try to think about opportunities like this. Sincerely hope we are on the same page on my best wishes to the project. |
Literally speaking (but my intention was to rather touch efficiency But has practical aspects as well. You need to realize that while So if you start with Hence, the conclusion here shall be that the It looks to me that dev's convenience aspect is at least mildly One needs to properly weigh in all aspects of data handling ergonomics. Moreover, you can be reasonably sure that you won't introduce such Hopefully it clarifies why I think it'd be optimal to select |
Please consider this.
|
Nonetheless, I see no point in following up on this conversation. |
https://build.opensuse.org/request/show/924180 by user yan_gao + dimstar_suse - Update to version 2.0.3+20210303.404adbc (v2.0.3): - syslog: Add a message-id parameter for messages (gh#ClusterLabs/libqb#433) - timers: Add some locking (gh#ClusterLabs/libqb#436) - ipcc: Have a few goes at tidying up after a dead server (gh#ClusterLabs/libqb#434) - strlcpy: Check for maxlen underflow (gh#ClusterLabs/libqb#432) - doxygen2man: fix printing of lines starting with '.' (gh#ClusterLabs/libqb#431) - doxygen2man: ignore all-whitespace brief descriptions (gh#ClusterLabs/libqb#430) (forwarded request 924179 from yan_gao)
DON'T MERGE
The message-ids are used by systemd catalogs. (see ClusterLabs/sbd#117)
To enable this feature the libqb should be configured with the
--enable-systemd-journal
option.IMPORTANT:
The libqb exposes the
To make it completely backward compatible, they all three should come with
and without the
message_id
parameter. This would however require repeating agood half of the libqb. We did only a half-measure: we provided the
qb_log_from_external_source_va2
to make it working with the corosync. It's not however backward compatible with the pacemaker.
@beekhof , @jfriesse , @jnpkrn , please give your feedback. (The PR done in the continuation of the conversation started here ClusterLabs/sbd#117 thought a bit later than planned). It's mostly interesting if it should be backward compatible and if so, then how to make it.