Skip to content

CDRIVER-4485 string append and truncation fixes for structured logging #1826

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

Merged
24 commits merged into from
Jan 22, 2025

Conversation

ghost
Copy link

@ghost ghost commented Jan 15, 2025

This PR is a follow-up for #1795 which depends on the new internal string append and json building API from #1816. (Update: Now addresses compatibility with #1821 also.)

  • Refines the concept of "maximum max document length" internally as a specific value near INT_MAX, to account for both ellipsis and bson overhead. Currently we choose not to expose the specific value of this constant publicly.
  • Adds public APIs for the max_document_length within a mongoc_structured_log_opts_t.
  • Addresses the remainder of CDRIVER-4485: JSON documents within structured log messages are truncated correctly according to the rules set out in the Logging specification.
  • Addresses the remainder of CDRIVER-4486 by implementing prose tests.
  • Addresses CDRIVER-4814. Command or payload data beyond the truncation limit no longer degrades logging performance.

@ghost ghost requested review from adriandole and eramongodb January 15, 2025 19:53
Micah Scott added 7 commits January 15, 2025 12:18
PR #1821, merged as commit d08d455, included a TODO for this truncation refactor.
Updated to use the new internal function _mongoc_structured_log_document_as_truncated_json, and to ASSERT that the length is now guaranteed not to overflow on cast.
return an error in the event the sequence has < 4 bytes of unexpected data at the end.
previously, this extra data was silently ignored.
mdbmes and others added 8 commits January 16, 2025 11:29
…length.rst

Co-authored-by: Ezra Chung <88335979+eramongodb@users.noreply.github.com>
…length.rst

Co-authored-by: Ezra Chung <88335979+eramongodb@users.noreply.github.com>
Co-authored-by: Ezra Chung <88335979+eramongodb@users.noreply.github.com>
Expect a very slight microarchitectural speed boost if this path is ever hot.
@ghost ghost requested a review from eramongodb January 16, 2025 21:29
Copy link
Contributor

@eramongodb eramongodb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple more suggestions; otherwise, LGTM.

mdbmes and others added 2 commits January 16, 2025 13:39
@ghost ghost requested a review from eramongodb January 17, 2025 19:01
Copy link
Contributor

@eramongodb eramongodb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last suggestion; otherwise, LGTM. 👍

@@ -142,6 +143,7 @@ test_structured_log_plain (void)

mongoc_structured_log_opts_t *opts = mongoc_structured_log_opts_new ();
mongoc_structured_log_opts_set_handler (opts, structured_log_func, &assumption);
ASSERT (mongoc_structured_log_opts_set_max_document_length (opts, 10000));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ASSERT (mongoc_structured_log_opts_set_max_document_length (opts, 10000));
ASSERT (
mongoc_structured_log_opts_set_max_document_length (opts, MONGOC_STRUCTURED_LOG_DEFAULT_MAX_DOCUMENT_LENGTH));

Should these values of 10000 be MONGOC_STRUCTURED_LOG_DEFAULT_MAX_DOCUMENT_LENGTH (1000) instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The specific value doesn't really matter as long as it's more than the small lengths used in the test, but my intent was to follow the advice from the CLAM spec:

"Drivers MUST run the logging tests with their max document
length setting (as described in the logging specification)
set to a large value e.g. 10,000; this is necessary in order for the driver to emit the full server reply (and to allow
matching against that reply) on certain MongoDB versions and topologies."

It's mostly arbitrary but I'll add a comment explaining the choice just so it doesn't seem out of place.

@ghost ghost merged commit ee16861 into mongodb:master Jan 22, 2025
45 checks passed
@ghost ghost deleted the CDRIVER-4485-b branch January 23, 2025 01:49
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants