Skip to content

Use Redis session instance

Nikola Milojevic requested to merge 1334-use-redis-sessions-store into master

What does this MR do and why?

Introduces ENV[GITLAB_USE_REDIS_SESSIONS_STORE] variable, which is enabled by default. This MR replaces usage of Gitlab::Redis::SharedSteate with the Gitlab::Redis::Sessions for sessions (ActiveSession and AnonymousSession).

Gitlab::Redis::Sessions will use our own implementation of a MultiStore, but the MultiStore will actually talk directly to SharedState by default. We can enable read-one-fallback and write-both with a feature flag.

How to set up and validate locally

Preparation:

  1. In case you are using GDK, check if gitlab/config/redis.sessions.yml file exists.
  2. If it doesn't, pull latest gdk and run gdk reconfigure This should generate gitlab/config/redis.sessions.yml

Steps:

  1. On master, run gdk redis-cli monitor | grep sessions | grep -v peek:request. Log in and click around.
  2. Do the same on this branch.

In both cases we should be issuing the same commands; here's a sample:

1636052900.230118 [0 unix:/home/smcgivern/gdk/redis/redis.socket] "get" "session:gitlab:2::86f3a0d6747e8b163b7b97653204d5cbfacb1c3953f43201cd3afb4614d0101b"
1636052900.340196 [0 unix:/home/smcgivern/gdk/redis/redis.socket] "setex" "session:user:gitlab:1:2::86f3a0d6747e8b163b7b97653204d5cbfacb1c3953f43201cd3afb4614d0101b" "604800" "\x04\bo:\x12ActiveSession\x0e:\x10@ip_address\"\r10.0.2.2:\r@browserI\"\x0cFirefox\x06:\x06ET:\b@osI\"\bMac\x06;\bT:\x11@device_name0:\x11@device_typeI\"\x0cdesktop\x06;\bT:\x10@created_atU: ActiveSupport::TimeWithZone[\bIu:\tTime\r\x92h\x1e\xc0\x00qH\xb1\x06:\tzone0I\"\bUTC\x06;\bTIu;\x0e\r\x92h\x1e\xc0\x00qH\xb1\x06;\x0f0:\x10@updated_atU;\r[\bIu;\x0e\r\x93h\x1e\xc0\xf7\x9bD!\t;\x0fI\"\bUTC\x06;\bF:\rnano_numi\x16:\rnano_deni\x06:\rsubmicro\"\a\x01p@\rIu;\x0e\r\x93h\x1e\xc0\xf7\x9bD!\t;\x0f@\x11;\x11i\x16;\x12i\x06;\x13\"\a\x01p:\x18@session_private_idI\"H2::86f3a0d6747e8b163b7b97653204d5cbfacb1c3953f43201cd3afb4614d0101b\x06;\bT:\x15@is_impersonatedF"
1636052900.340248 [0 unix:/home/smcgivern/gdk/redis/redis.socket] "sadd" "session:lookup:user:gitlab:1" "2::86f3a0d6747e8b163b7b97653204d5cbfacb1c3953f43201cd3afb4614d0101b"
1636052907.491846 [0 unix:/home/smcgivern/gdk/redis/redis.socket] "setex" "session:gitlab:2::86f3a0d6747e8b163b7b97653204d5cbfacb1c3953f43201cd3afb4614d0101b" "604800" "\x04\b{\bI\"\x19warden.user.user.key\x06:\x06ET[\a[\x06i\x06I\"\"$2a$10$rdaAuw6xP1xVNk0nXJrSB.\x06;\x00TI\" ask_for_usage_stats_consent\x06;\x00FFI\"\x10_csrf_token\x06;\x00FI\"1RoYdR+i/a475vViQqYvsAHTB0HPNQuctUWhSkKQ+krc=\x06;\x00F"
1636052907.914162 [0 unix:/home/smcgivern/gdk/redis/redis.socket] "get" "session:gitlab:2::86f3a0d6747e8b163b7b97653204d5cbfacb1c3953f43201cd3afb4614d0101b"

MultiStore testing:

  1. In rails console:
  Feature.enable(:use_multi_store)
  1. run gdk redis-cli monitor | grep sessions | grep -v peek:request.
  2. Log in and click around.

Now we should see that we run same write commands on both Redis dbs (0 and 5)

Note: We should stay logged in after switching branches and restarting Rails, so we won't log people out with this change.

Numbered steps to set up and validate the change are strongly suggested.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to gitlab-com/gl-infra/scalability#1334 (closed)

Edited by Nikola Milojevic

Merge request reports

Loading