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

LogEvent.client_metadata: Cannot parse certain log lines #871

Closed
akung0324 opened this issue May 25, 2022 · 0 comments
Closed

LogEvent.client_metadata: Cannot parse certain log lines #871

akung0324 opened this issue May 25, 2022 · 0 comments
Assignees
Milestone

Comments

@akung0324
Copy link
Contributor

There are certain client metadata log lines (4.2 and earlier) for which logevent.clientmetadata returns nothing.

Expected behavior

Example Log Line:

2020-02-07T12:01:39.677+1100 I NETWORK [conn10] received client metadata from 127.0.0.1:65199 conn: { driver: { name: "mongo-go-driver", version: "v1.1.2" }, os: { type: "darwin", architecture: "amd64" }, platform: "go1.12.9" }

Result of logevent.clientmetadata:

{'driver': {'name': 'mongo-go-driver', 'version': 'v1.1.2'}, 'os': {'type': 'darwin', 'architecture': 'amd64'}, 'platform': 'go1.12.9'}

Actual/current behavior

Example Log Line (impacted by this bug):

2020-02-07T11:59:14.109+1100 I NETWORK [conn1] received client metadata from 127.0.0.1:64766 conn: { driver: { name: "PyMongo", version: "3.10.1" }, os: { type: "Darwin", name: "Darwin", architecture: "x86_64", version: "10.14.6" }, platform: "CPython 3.8.1.final.0", application: { name: "mlaunch v1.6.2-dev" } }

Result of logevent.clientmetadata: None

Steps to reproduce the actual/current behavior

  1. Add an option --test to mloginfo for the purpose of this reproduction:

    • Add the attached test_section.py file to the mtools/loginfo/sections folder.
    • Insert a line into the top of mtools/mloginfo/sections/__init__.py that looks like from .test_section import TestSection.
  2. Run mloginfo --test on mtools/test/logfiles/sharding_360_mongos.log as an example. All the client metadata log lines that result in logevent.clientmetadata returning nothing are prefixed with "ERROR".

  3. Run mloginfo --test on another sample log file (attached) called mongod_4.2.11_clients.log. All the client metadata log lines parse successfully.

Issue

It seems like there's a bug in mtools/util/logevent.py in this part of the code:

    def client_metadata(self):
        """Return client metadata."""
...
                        # Replace double-quoted platform values with single quote
                        platform = re.search(r'"platform"\s+:\s+"(.*)"', metadata)
                        if (platform):
	                    platform = platform.group(1)
                            platform_esc, _ = re.subn(r'"', r"'", platform)
                            metadata, _ = re.subn(platform, platform_esc, metadata)
...

Environment

Software Version
mtools 1.7.0
Python 3.7.10
Operating system Amazon Linux 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants