anyproto / any-sync-dockercompose

docker-compose for testing any-sync
MIT License
234 stars 29 forks source link

fix mongo healthcheck command #47

Closed dyumin closed 2 months ago

dyumin commented 2 months ago

On some systems (using mongo 6.0, but I guess 7.0 will have the same behaviour) current healthcheck command output looks like this:

dyumin@nas:/volume1/anytype/any-sync-dockercompose$ sudo docker-compose exec -it mongo-1 mongosh --port 27001 --quiet --eval "try {rs.initiate({_id:'rs0',members:[{_id:0,host:\"mongo-1:27001\"}]})} catch(e) {rs.status().ok}"
{"t":{"$date":"2024-05-05T18:44:44.379Z"},"s":"I",  "c":"NETWORK",  "id":5693100, "ctx":"js","msg":"Asio socket.set_option failed with std::system_error","attr":{"note":"connect (sync) TCP fast open","option":{"level":6,"name":30,"data":"01 00 00 00"},"error":{"what":"set_option: Protocol not available","message":"Protocol not available","category":"asio.system","value":92}}}
{ "ok" : 1 }
dyumin@nas:/volume1/anytype/any-sync-dockercompose$ sudo docker-compose exec -it mongo-1 mongosh --port 27001 --quiet --eval "try {rs.initiate({_id:'rs0',members:[{_id:0,host:\"mongo-1:27001\"}]})} catch(e) {rs.status().ok}"
{"t":{"$date":"2024-05-05T18:44:51.099Z"},"s":"I",  "c":"NETWORK",  "id":5693100, "ctx":"js","msg":"Asio socket.set_option failed with std::system_error","attr":{"note":"connect (sync) TCP fast open","option":{"level":6,"name":30,"data":"01 00 00 00"},"error":{"what":"set_option: Protocol not available","message":"Protocol not available","category":"asio.system","value":92}}}
{
    "ok" : 0,
    "errmsg" : "already initialized",
    "code" : 23,
    "codeName" : "AlreadyInitialized",
    "$clusterTime" : {
        "clusterTime" : Timestamp(1714934691, 1),
        "signature" : {
            "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
            "keyId" : NumberLong(0)
        }
    },
    "operationTime" : Timestamp(1714934690, 3)
}

which leads to broken healthcheck

Proposed changes:

  1. filter out TCP fast open error (grep -v asio.system)
  2. check rs.status().ok first and only then try to run rs.initiate()
  3. use .ok field from rs.initiate() output json


Description

What type of PR is this? (check all applicable)

Related Tickets & Documents

Mobile & Desktop Screenshots/Recordings

Added tests?

Added to documentation?

[optional] Are there any post-deployment tasks we need to perform?

fb929 commented 2 months ago

@dyumin Thank You for your request, but unfortunately, your edits do not work :( If you clear the MongoDB data and try to run it, you get the following error:

docker inspect --format "{{json .State.Health }}" 6692638ed797 | python3 -m json.tool
{
    "Status": "starting",
    "FailingStreak": 1,
    "Log": [
        {
            "Start": "2024-05-05T19:02:51.31873601Z",
            "End": "2024-05-05T19:02:51.760723218Z",
            "ExitCode": 0,
            "Output": ""
        },
        {
            "Start": "2024-05-05T19:03:01.764394625Z",
            "End": "2024-05-05T19:03:02.224474584Z",
            "ExitCode": 0,
            "Output": ""
        },
        {
            "Start": "2024-05-05T19:03:45.099564715Z",
            "End": "2024-05-05T19:03:45.607875048Z",
            "ExitCode": 2,
            "Output": "MongoServerError: no replset config has been received\n/bin/sh: 1: test: -eq: unexpected operator\n"
        },
        {
            "Start": "2024-05-05T19:03:55.611954387Z",
            "End": "2024-05-05T19:03:56.060191137Z",
            "ExitCode": 2,
            "Output": "MongoServerError: no replset config has been received\n/bin/sh: 1: test: -eq: unexpected operator\n"
        },
        {
            "Start": "2024-05-05T19:04:06.066012919Z",
            "End": "2024-05-05T19:04:06.530823919Z",
            "ExitCode": 2,
            "Output": "MongoServerError: no replset config has been received\n/bin/sh: 1: test: -eq: unexpected operator\n"
        }
    ]
}

Apparently, the replica set is not initializing.

docker compose exec mongo-1 mongosh --port 27001 --eval 'rs.status()'
Current Mongosh Log ID: 6637d8dcc95d6018bad31619
Connecting to:      mongodb://127.0.0.1:27001/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.0.1
Using MongoDB:      7.0.2
Using Mongosh:      2.0.1

For mongosh info see: https://docs.mongodb.com/mongodb-shell/

------
   The server generated these startup warnings when booting
   2024-05-05T19:03:36.009+00:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
   2024-05-05T19:03:36.009+00:00: vm.max_map_count is too low
------

MongoServerError: no replset config has been received
dyumin commented 2 months ago

Thanks for testing! I will try to fix it and come back with the results