Skip to content

CDRIVER-4487 server selection logging #1821

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
21 commits merged into from
Jan 15, 2025
Merged

CDRIVER-4487 server selection logging #1821

21 commits merged into from
Jan 15, 2025

Conversation

ghost
Copy link

@ghost ghost commented Jan 9, 2025

This patch addresses CDRIVER-4487: structured log messages for server selection.

Note:

  • src/libmongoc/tests/json/server_selection/* were synchronized from the specifications repo
  • src/libmongoc/tests/mock_server/future* were auto-generated by build/generate-future-functions.py

Contents:

  • server_selection/logging tests added to framework
  • New log messages reporting server selection progress
  • New mongoc_ss_log_context_t provided to server selection with additional operation context needed by log messages.

Much of the noise in here is related to that new mongoc_ss_log_context_t, required because the logs need information about both low-level server selection progress and high-level operation context. I considered alternatives, including a thread-local stack allowing functions to append log items to logs issued by a callee. This explicit context structure was chosen in order to optimize for clarity at the expense of some verbosity.

The mongoc_ss_log_context_t provides the "operation" name, defined in the spec as "The name of the operation for which a server is being selected. When server selection is being performed to select a server for a command, this MUST be the command name." In case operations are never expected to generate user-visible logs, like tests, the operation name is still required but it may be arbitrary. I considered making the entire mongoc_ss_log_context_t optional, but retained it as a required parameter to reduce the potential for omissions in non-testing paths. Some operations are not commands but nevertheless will be user-visible (mongoc_client_session_start_transaction) and in this case I chose the libmongoc API name as the "operation".

We might consider C99 compound literals for the mongoc_ss_log_context_t instances. So far I've opted not to, for simplicity and in order to keep the parameter list lengths under control.

@ghost ghost requested review from adriandole and eramongodb January 9, 2025 16:54
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.

[...] the logs need information about both low-level server selection progress and high-level operation context. I considered alternatives, including a thread-local stack allowing functions to append log items to logs issued by a callee. This explicit context structure was chosen in order to optimize for clarity at the expense of some verbosity.

I support this design decision.

@ghost ghost requested a review from eramongodb January 10, 2025 15:28
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 minor non-blocking suggestion; otherwise, LGTM! 👍

mdbmes and others added 2 commits January 10, 2025 07:41
Co-authored-by: Ezra Chung <88335979+eramongodb@users.noreply.github.com>
@ghost
Copy link
Author

ghost commented Jan 15, 2025

Thanks for the reviews!

@ghost ghost merged commit d08d455 into mongodb:master Jan 15, 2025
45 checks passed
ghost pushed a commit that referenced this pull request Jan 22, 2025
#1826)

This PR is a follow-up for #1795, #1821, and #1816. The new internal string and json APIs are used to implement missing functionality and tests for the structured logging subsystem.

* 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. (New serializer for command-with-payload)
* Unified tests use the suggested max document length of 10000 from the spec
* Replace atomic counter with atomic flag for environment error guards
* Tests for environment defaults now skip if relevant variables are set externally
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