Skip to content

feat: dump user's session data in json file during shutdown to restore active sessions

Description

We need to keep active user sessions alive after restart (e.g. to upgrade Joe bot) Currently Joe keeps all session data in-memory so every restart wipes all active sessions

Proposal is to save all sessions in config/sessions.json file and read it during startup, write during shutdown

Limitations:

  • current tutor mounts one config file to docker container --volume ~/.dblab/joe.yml:/home/config/config.yml. You have to take care of sessions.json to run new Joe image version
  • json is readable format, some people could try to modify it. Joe won't start with incorrect sessions.json file
  • it updated sessions.json only during normal shutdown. Any bug with panic could wipe active sessions
  • currently it does not check clone param changes. e.g. you can change database user / dbname. Does it make sense to connect with old credentials to the new db?
  • any errors during user's session restore will wipe it!

Related issue

Closes #107 (closed)

Examples

sessions.json

{
  "slackrtm-C025B0LLJ3B": {
    "U021Y51C94P": {
      "UserInfo": {
        "ID": "U021Y51C94P",
        "Name": "viktor",
        "RealName": "Viktor Grigorev"
      },
      "Session": {
        "PlatformSessionID": "5072",
        "ChannelID": "C025B0LLJ3B",
        "Direct": false,
        "Quota": {},
        "LastActionTs": "2021-07-08T09:27:40.1627296Z",
        "IdleInterval": 0,
        "Clone": {
          "id": "joe-c3jc8adsc1vli5nkt8mg",
          "snapshot": {
            "id": "dblab_pool@snapshot_20210707191856",
            "createdAt": "2021-07-07 19:18:56 UTC",
            "dataStateAt": "2021-07-07 19:18:56 UTC"
          },
          "protected": false,
          "deleteAt": "",
          "createdAt": "2021-07-08 09:23:54 UTC",
          "status": {
            "code": "OK",
            "message": "Clone is ready to accept Postgres connections."
          },
          "db": {
            "connStr": "host=localhost port=6000 user=joe_viktor dbname=test",
            "host": "localhost",
            "port": "6000",
            "username": "joe_viktor",
            "password": "",
            "db_name": "test"
          },
          "metadata": {
            "cloneDiffSize": 692224,
            "cloneDiffSizeHR": "676 KiB",
            "cloningTime": 2.180451938,
            "maxIdleMinutes": 120
          }
        },
        "ConnParams": {
          "Name": "test",
          "Host": "localhost",
          "Port": "6000",
          "Username": "joe_viktor",
          "Password": "GyRIO2ub4ZC4g5hU",
          "SSLMode": "prefer"
        }
      }
    }
  },
  "webui-ProductionDB": {
  }
}

Screenshot_2021-07-08_at_16.44.22 Screenshot_2021-07-26_at_18.15.15

Checklist

  • the MR description has been reviewed
  • this MR contains text changes and they have been reviewed OR there are no texts changes
  • this MR contains GUI/CLI changes and they have been reviewed OR there are no GUI/CLI changes
  • this MR contains API changes and they have been reviewed OR there are no API changes
Edited by Viktor Grigorev

Merge request reports

Loading