Skip to content
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

DRIVERS-1677, DRIVERS-1673: Add general logging specification and command logging #1303

Merged
merged 45 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
195f581
DRIVERS-1204 add general spec, unified format changes, and command lo…
kmahar Sep 1, 2022
2359fbc
use $$matchAsDocument for matching empty documents
kmahar Sep 9, 2022
8bea9ab
fix link
kmahar Sep 9, 2022
5484c94
Apply suggestions from code review
kmahar Sep 14, 2022
998adcb
Apply suggestions from code review
kmahar Sep 14, 2022
2d406d7
make driverConnectionId optional and split out testing for it
kmahar Sep 13, 2022
3027e01
move tests up out of /unified subdirectories
kmahar Sep 13, 2022
4114394
clarify length in prose tests
kmahar Sep 13, 2022
6e0356a
add type assertions to tests
kmahar Sep 13, 2022
a628829
drivers must omit null values from messages
kmahar Sep 14, 2022
968d937
unstuctured -> unstructured
kmahar Sep 14, 2022
60ec05e
MUST -> SHOULD for unstructured message forms; pull out common values…
kmahar Sep 14, 2022
09e0316
address comments on unified test format
kmahar Sep 14, 2022
68f1dd0
address comments on general spec
kmahar Sep 15, 2022
b8d48eb
fix rst
kmahar Sep 15, 2022
be019e5
fix operationId test
kmahar Sep 15, 2022
001e6d2
fix object in operationId test
kmahar Sep 15, 2022
08275c7
add tests for no handshake and no heartbeat messages being emitted
kmahar Sep 16, 2022
cf77d2c
only run heartbeat test on non-LB topology; reorder ops
kmahar Sep 16, 2022
dc15477
update rationale for not requiring structured logging
kmahar Sep 16, 2022
e8b39be
update prose test to reflect it applies to any driver with a max leng…
kmahar Sep 16, 2022
b161034
fix emphasis
kmahar Sep 16, 2022
1afc10f
schema version should be 1.12
kmahar Sep 27, 2022
b441824
Merge branch 'master' into DRIVERS-1204/logging-spec
kmahar Sep 27, 2022
e998fed
bump test file schema versions
kmahar Sep 27, 2022
45b9d8b
add interruptInUseConnections to schema v1.12
kmahar Sep 27, 2022
8c01044
update command logging tests README
kmahar Oct 5, 2022
4a94ad0
reword
kmahar Oct 5, 2022
2f41ac7
make clear that drivers should do "naive" truncation of JSON, and add…
kmahar Oct 7, 2022
830c568
drivers must match exact names/casing for structured log messages
kmahar Oct 10, 2022
5bacb00
events -> messages, clarify that messages MUST be an exact match
kmahar Oct 11, 2022
3a22c27
bump schema versions in invalid tests
kmahar Oct 11, 2022
5b0224b
update redacton rules and unifited format support for testing for red…
kmahar Oct 11, 2022
e2c7209
update failureIsRedacted language slightly
kmahar Oct 11, 2022
0434dd8
Merge branch 'master' into DRIVERS-1204/logging-spec
kmahar Oct 11, 2022
2f5256e
back to a single boolean; fix typos
kmahar Oct 12, 2022
73a0b3c
Merge remote-tracking branch 'origin' into DRIVERS-1204/logging-spec
kmahar Oct 12, 2022
7174ad7
address jmikola comments
kmahar Oct 13, 2022
bc6cdf6
schema version 1.12 -> 1.13
kmahar Oct 14, 2022
13e9593
Merge remote-tracking branch 'origin' into DRIVERS-1204/logging-spec
kmahar Oct 14, 2022
cfd852a
fix changelog date
kmahar Oct 14, 2022
042f20c
bump schema version in unified tests makefile
kmahar Oct 14, 2022
7a63673
update CLAM spec name in makefile
kmahar Oct 14, 2022
9358d08
consistent driver connection ID type in events
kmahar Oct 14, 2022
91464fa
address @BorisDog comments
kmahar Oct 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view

Large diffs are not rendered by default.

60 changes: 60 additions & 0 deletions source/command-logging-and-monitoring/tests/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
.. role:: javascript(code)
:language: javascript

==============================
Command Logging and Monitoring
==============================

.. contents::

--------

Testing
=======

Automated Tests
^^^^^^^^^^^^^^^
There are tests in the `Unified Test Format <../../unified-test-format/unified-test-format.rst>`__ for both logging and
monitoring in `/logging </logging>`_ and `/monitoring </monitoring>`_, respectively. Drivers MUST run the logging
kmahar marked this conversation as resolved.
Show resolved Hide resolved
tests with their max document length setting (as described in the
`logging specification <../../logging/logging.rst#truncation-of-large-documents>`__) 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.

Prose Tests
^^^^^^^^^^^
Drivers MUST implement the following logging prose tests. These tests require the ability to capture log message data in a
structured form as described in the
`Unified Test Format specification <../../unified-test-format/unified-test-format.rst#expectedLogMessage>`__.

Note: the following tests mention string "length"; this refers to length in terms of whatever unit the driver has chosen
to support for specifying max document length as discussed in the
`logging specification <../../logging/logging.rst#truncation-of-large-documents>`__.

*Test 1: Default truncation limit*

1. Configure logging with a minimum severity level of "debug" for the "command" component. Do not explicitly configure the max document length.
2. Construct an array ``docs`` containing the document ``{"x" : "y"}`` repeated 100 times.
3. Insert ``docs`` to a collection via ``insertMany``.
4. Inspect the resulting "command started" log message and assert that the "command" value is a string of length 1000 + (length of trailing ellipsis).
5. Inspect the resulting "command succeeded" log message and assert that the "reply" value is a string of length <= 1000 + (length of trailing ellipsis).
6. Run ``find()`` on the collection where the document was inserted.
7. Inspect the resulting "command succeeded" log message and assert that the reply is a string of length 1000 + (length of trailing ellipsis).
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: Is there a value in having the second test, as opposed to a parameterizing the first one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the differences in terms of the commands and assertions run are significant enough that it would not save us much text to try to combine them.


*Test 2: Explicitly configured truncation limit*

1. Configure logging with a minimum severity level of "debug" for the "command" component. Set the max document length to 5.
2. Run the command ``{"hello": true}``.
3. Inspect the resulting "command started" log message and assert that the "command" value is a string of length 5 + (length of trailing ellipsis).
4. Inspect the resulting "command succeeded" log message and assert that the "reply" value is a string of length 5 + (length of trailing ellipsis).
5. If the driver attaches raw server responses to failures and can access these via log messages to assert on, run the command
``{"notARealCommand": true}``. Inspect the resulting "command failed" log message and confirm that the server error is
a string of length 5 + (length of trailing ellipsis).

*Test 3: Truncation with multi-byte codepoints*
kmahar marked this conversation as resolved.
Show resolved Hide resolved

A specific test case is not provided here due to the allowed variations in truncation logic as well as varying extended JSON whitespace usage.
Drivers MUST write language-specific tests that confirm truncation of commands, replies, and (if applicable) server responses included in error
messages work as expected when the data being truncated includes multi-byte Unicode codepoints.
If the driver uses anything other than Unicode codepoints as the unit for max document length, there also MUST be tests confirming that cases
where the max length falls in the middle of a multi-byte codepoint are handled gracefully.
213 changes: 213 additions & 0 deletions source/command-logging-and-monitoring/tests/logging/command.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
{
"description": "command-logging",
"schemaVersion": "1.12",
"createEntities": [
{
"client": {
"id": "client",
"observeLogMessages": {
"command": "debug"
}
}
},
{
"database": {
"id": "database",
"client": "client",
"databaseName": "logging-tests"
}
},
{
"collection": {
"id": "collection",
"database": "database",
"collectionName": "logging-tests-collection"
}
}
],
"initialData": [
{
"collectionName": "logging-tests-collection",
"databaseName": "logging-tests",
"documents": [
{
"_id": 1,
"x": 11
}
]
}
],
"tests": [
{
"description": "A successful command",
"operations": [
{
"name": "runCommand",
"object": "database",
"arguments": {
"command": {
"ping": 1
},
"commandName": "ping"
}
}
],
"expectLogMessages": [
{
"client": "client",
"messages": [
{
"level": "debug",
"component": "command",
"data": {
"message": "Command started",
"databaseName": "logging-tests",
"commandName": "ping",
"command": {
"$$matchAsDocument": {
"$$matchAsRoot": {
"ping": 1,
"$db": "logging-tests"
}
}
},
"requestId": {
"$$type": [
"int",
"long"
]
},
"serverHost": {
"$$type": "string"
},
"serverPort": {
"$$type": [
"int",
"long"
]
}
}
},
{
"level": "debug",
"component": "command",
"data": {
"message": "Command succeeded",
"commandName": "ping",
"reply": {
"$$type": "string"
},
"requestId": {
"$$type": [
"int",
"long"
]
},
"serverHost": {
"$$type": "string"
},
"serverPort": {
"$$type": [
"int",
"long"
]
},
"durationMS": {
"$$type": [
"double",
"int",
"long"
]
}
}
}
]
}
]
},
{
"description": "A failed command",
"operations": [
{
"name": "find",
"object": "collection",
"arguments": {
"filter": {
"$or": true
}
},
"expectError": {
"isClientError": false
}
}
],
"expectLogMessages": [
{
"client": "client",
"messages": [
{
"level": "debug",
"component": "command",
"data": {
"message": "Command started",
"databaseName": "logging-tests",
"commandName": "find",
"command": {
"$$type": "string"
},
"requestId": {
"$$type": [
"int",
"long"
]
},
"serverHost": {
"$$type": "string"
},
"serverPort": {
"$$type": [
"int",
"long"
]
}
}
},
{
"level": "debug",
"component": "command",
"data": {
"message": "Command failed",
"commandName": "find",
"failure": {
"$$exists": true
},
"requestId": {
"$$type": [
"int",
"long"
]
},
"serverHost": {
"$$type": "string"
},
"serverPort": {
"$$type": [
"int",
"long"
]
},
"durationMS": {
"$$type": [
"double",
"int",
"long"
]
}
}
}
]
}
]
}
]
}
94 changes: 94 additions & 0 deletions source/command-logging-and-monitoring/tests/logging/command.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
description: "command-logging"

schemaVersion: "1.12"

createEntities:
- client:
id: &client client
observeLogMessages:
command: debug
- database:
id: &database database
client: *client
databaseName: &databaseName logging-tests
- collection:
id: &collection collection
database: *database
collectionName: &collectionName logging-tests-collection

initialData:
- collectionName: *collectionName
databaseName: *databaseName
documents:
- { _id: 1, x: 11 }

tests:
- description: "A successful command"
operations:
- name: runCommand
object: *database
arguments:
command: { ping: 1 }
commandName: &commandName ping
expectLogMessages:
- client: *client
messages:
- level: debug
component: command
data:
message: "Command started"
databaseName: *databaseName
commandName: *commandName
command:
$$matchAsDocument:
$$matchAsRoot:
ping: 1
$db: *databaseName
requestId: { $$type: [int, long] }
serverHost: { $$type: string }
serverPort: { $$type: [int, long] }

- level: debug
component: command
data:
message: "Command succeeded"
commandName: *commandName
reply: { $$type: string }
requestId: { $$type: [int, long] }
serverHost: { $$type: string }
serverPort: { $$type: [int, long] }
durationMS: { $$type: [double, int, long] }

- description: "A failed command"
operations:
- name: &commandName find
object: *collection
arguments:
filter: { $or: true }
expectError:
isClientError: false
expectLogMessages:
- client: *client
messages:
- level: debug
component: command
data:
message: "Command started"
databaseName: *databaseName
commandName: *commandName
command: { $$type: string }
requestId: { $$type: [int, long] }
serverHost: { $$type: string }
serverPort: { $$type: [int, long] }

- level: debug
component: command
data:
message: "Command failed"
commandName: *commandName
failure: { $$exists: true }
requestId: { $$type: [int, long] }
serverHost: { $$type: string }
serverPort: { $$type: [int, long] }
durationMS: { $$type: [double, int, long] }