Skip to content

Per-listener connection sets to track dropped connections

Mikhail Mazurskiy requested to merge ash2k/track-connections into master
  • Per-listener connection sets to track dropped connections
  • Preallocate counter add options

Relates to Track open connections in a Redis hash (#625).

Testing. I decided to not invest time into proper unit tests as I may further significantly change this code. Instead I tested manually. Started GDK+kas+agentk. Connected to Redis.

Below is the list of all matching keys that are in the Redis DB. We see that at this stage we only have one hash. This is as expected because we have an agent connected but didn't make any requests to it.

$ redis-cli -s /Users/mike/src/gdk/redis/redis.socket
> KEYS *:listener_conns:*
1) "gitlab-kas:listener_conns:agent_api"

Let's look at the hash. ok, below we have a single key-value mapping in that hash. This is as expected because there is only a single agentk connected via a single gRPC connection. Note that this mapping is \x01\x00\x00\x00\x00\x00\x00\x00 i.e. 1 in little-endian.

> HGETALL "gitlab-kas:listener_conns:agent_api"
1) "\xe3\xf2\xdb\xfa\aLlS\x01\x00\x00\x00\x00\x00\x00\x00"
2) "\b\xe9\xae\xff\xb7\x06"

Now, if we disconnect the agent, we see that kas removed the mapping:

> HGETALL "gitlab-kas:listener_conns:agent_api"
(empty array)

If we start agentk again, kas will create a new mapping for it. Note that this mapping is 2 (\x02\x00\x00\x00\x00\x00\x00\x00):

> HGETALL "gitlab-kas:listener_conns:agent_api"
1) "\xe3\xf2\xdb\xfa\aLlS\x02\x00\x00\x00\x00\x00\x00\x00"
2) "\b\x80\xb2\xff\xb7\x06"

If we kill kas and start it again, wait for agentk to reconnect, we'll see that the old mapping is still there but there is also a new mapping. It started counting from 1 again and it uses a different prefix (instance id) of \x1a\xd3g\xd7\xda\x98.l:

> HGETALL "gitlab-kas:listener_conns:agent_api"
1) "\xe3\xf2\xdb\xfa\aLlS\x02\x00\x00\x00\x00\x00\x00\x00"
2) "\b\x80\xb2\xff\xb7\x06"
3) "\x1a\xd3g\xd7\xda\x98.l\x01\x00\x00\x00\x00\x00\x00\x00"
4) "\b\x99\xb2\xff\xb7\x06"

The actual metrics will come from expiring hash's GC counter.

Merge request reports

Loading