Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Add test for MongoDB ping with extended details #34

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

lucafaggianelli
Copy link

Some MongoDB clusters return advanced details like cluster time and signature with object types that are not JSON-serializable.

You're probably going to manipulate the response object here:

def _check(base: pymongo.database.Database) -> (str, dict):
    try:
        response = base.command("ping")
        return (
            "pass",
            {
                f"{base.name}:ping": {
                    "componentType": "datastore",
                    "observedValue": response,
                    "status": "pass",
                    "time": datetime.datetime.utcnow().isoformat(),
                }
            },
        )

but please notice that the response object is used internally by pymongo for its internal health check, so changing that object will break pymongo, to solve that I needed to copy the response object before modyfing it:

# this will break pymongo:
response["$clusterTime"]["clusterTime"] = response["$clusterTime"]["clusterTime"].as_datetime().isoformat()

Some MongoDB clusters return advanced details like cluster time and
signature with object types that are not JSON-serializable
@sonarcloud
Copy link

sonarcloud bot commented Feb 17, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant