Skip to content

CXX-2284 Append platform data to handshake #915

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
merged 4 commits into from
Jan 3, 2023

Conversation

kevinAlbs
Copy link
Collaborator

@kevinAlbs kevinAlbs commented Jan 3, 2023

Summary

Background & Motivation

The Handshake is the first command performed upon establishing the connection to MongoDB.
The Handshake includes metadata in the client field, so a client can identify itself. The Handshake metadata appears in mongod logs.

Here is a formatted log from mongod from a C++ driver connection before this change:

{
    "t": {
        "$date": "2022-12-21T12:02:28.088-05:00"
    },
    "s": "I",
    "c": "NETWORK",
    "id": 51800,
    "ctx": "conn11",
    "msg": "client metadata",
    "attr": {
        "remote": "127.0.0.1:59363",
        "client": "conn11",
        "doc": {
            "driver": {
                "name": "mongoc / mongocxx",
                "version": "1.23.1 / 3.7.1-pre"
            },
            "os": {
                "type": "Darwin",
                "name": "macOS",
                "version": "20.6.0",
                "architecture": "x86_64"
            },
            "platform": "cfg=0x0200d68a65 posix=200112 stdc=201710 CC=clang 13.0.0 (clang-1300.0.29.30) CFLAGS=\"\" LDFLAGS=\"\""
        }
    }
}

The platform only includes information from the C driver. After this change, the platform field includes the C++ compiler ID and version in the prefix:

{
    "t": {
        "$date": "2023-01-03T09:15:05.013-05:00"
    },
    "s": "I",
    "c": "NETWORK",
    "id": 51800,
    "ctx": "conn12",
    "msg": "client metadata",
    "attr": {
        "remote": "127.0.0.1:59806",
        "client": "conn12",
        "doc": {
            "driver": {
                "name": "mongoc / mongocxx",
                "version": "1.23.1 / 3.7.1-pre"
            },
            "os": {
                "type": "Darwin",
                "name": "macOS",
                "version": "20.6.0",
                "architecture": "x86_64"
            },
            "platform": "CXX=AppleClang 13.0.0.13000029 stdcxx=201703 / cfg=0x0200d68a65 posix=200112 stdc=201710 CC=clang 13.0.0 (clang-1300.0.29.30) CFLAGS=\"\" LDFLAGS=\"\""
        }
    }
}

cmake is used to determine the compiler ID and version. The C driver uses macros to determine the compiler ID and version, and falls back to values set by cmake. I see no reason to use macros instead of cmake to determine the compiler type and version for the C++ driver. The C driver may have preferred macros for consistent values between cmake and the now removed autotools build. But I am not sure.

A patch build was run to determine all MONGOCXX_COMPILER_ID and MONGOCXX_COMPILER_VERSION for tested variants. The following table is the unique values:

MONGOCXX_COMPILER_ID MONGOCXX_COMPILER_VERSION
GNU 8.3.1
AppleClang 11.0.0.11000033
GNU 8.3.0
GNU 9.4.0
GNU 7.5.0
GNU 10.2.1
Clang 6.0.0
GNU 5.4.0
MSVC 19.16.27043.0
MSVC 19.0.24223.0

@kevinAlbs kevinAlbs changed the title CXX-2284 add compiler ID and version to platform CXX-2284 Append platform data to handshake Jan 3, 2023
@kevinAlbs kevinAlbs marked this pull request as ready for review January 3, 2023 14:23
@codecov-commenter
Copy link

codecov-commenter commented Jan 3, 2023

Codecov Report

Merging #915 (927ebd3) into master (4b7add4) will decrease coverage by 0.05%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #915      +/-   ##
==========================================
- Coverage   91.34%   91.28%   -0.06%     
==========================================
  Files         384      384              
  Lines       23463    23312     -151     
==========================================
- Hits        21432    21281     -151     
  Misses       2031     2031              
Impacted Files Coverage Δ
src/mongocxx/instance.cpp 77.77% <100.00%> (-7.75%) ⬇️
src/mongocxx/test/client.cpp 99.64% <0.00%> (+0.13%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Contributor

@vector-of-bool vector-of-bool left a comment

Choose a reason for hiding this comment

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

LGTM, but with one possible improvement for handling MSVC.

// argument for consistency with the driver_name, and driver_version.
std::stringstream platform;
platform << "CXX=" << MONGOCXX_COMPILER_ID << " " << MONGOCXX_COMPILER_VERSION << " "
<< "stdcxx=" << __cplusplus << " / ";
Copy link
Contributor

Choose a reason for hiding this comment

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

Possible tweak: The __cplusplus macro is a lie for MSVC (by default). It would be useful to add a field for _MSVC_LANG, which tells the true value of /std: regardless of the compiler conformance options.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point. The installation documentation suggests compiling with /Zc:__cplusplus for C++17. But users may be building with older versions.

Updated to prefer _MSVC_LANG. Filed CXX-2629 to consider setting /Zc:__cplusplus as the default when building with MSVC.

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.

4 participants