Commit 590cfbf0 authored by Pavel Shutsin's avatar Pavel Shutsin

Change Analytics unique visits key naming

parent 48b1f532
...@@ -50,7 +50,6 @@ project:{1}:set_b ...@@ -50,7 +50,6 @@ project:{1}:set_b
project:{2}:set_c project:{2}:set_c
``` ```
`set_a` and `set_b` are guaranteed to be held on the same Redis server, while `set_c` is not. `set_a` and `set_b` are guaranteed to be held on the same Redis server, while `set_c` is not.
Currently, we validate this in the development and test environments Currently, we validate this in the development and test environments
......
...@@ -52,8 +52,10 @@ module Gitlab ...@@ -52,8 +52,10 @@ module Gitlab
def key(target_id, time) def key(target_id, time)
raise "Invalid target id #{target_id}" unless TARGET_IDS.include?(target_id.to_s) raise "Invalid target id #{target_id}" unless TARGET_IDS.include?(target_id.to_s)
target_key = target_id.to_s.gsub('analytics', '{analytics}')
year_week = time.strftime('%G-%V') year_week = time.strftime('%G-%V')
"#{target_id}-{#{year_week}}"
"#{target_key}-#{year_week}"
end end
def keys(targets:, timeframe_start:, weeks:) def keys(targets:, timeframe_start:, weeks:)
......
...@@ -47,7 +47,7 @@ RSpec.describe Gitlab::Analytics::UniqueVisits, :clean_gitlab_redis_shared_state ...@@ -47,7 +47,7 @@ RSpec.describe Gitlab::Analytics::UniqueVisits, :clean_gitlab_redis_shared_state
unique_visits.track_visit(visitor1_id, target1_id) unique_visits.track_visit(visitor1_id, target1_id)
Gitlab::Redis::SharedState.with do |redis| Gitlab::Redis::SharedState.with do |redis|
redis.scan_each(match: "#{target1_id}-*").each do |key| redis.scan_each(match: "{#{target1_id}}-*").each do |key|
expect(redis.ttl(key)).to be_within(5.seconds).of(12.weeks) expect(redis.ttl(key)).to be_within(5.seconds).of(12.weeks)
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment