99import pytablewriter
1010from pytablewriter import MarkdownTableWriter
1111
12- # 7 days expire
13- STALL_INFO_DAYS = 7
12+ # 30 days expire
13+ STALL_INFO_DAYS = 30
1414EXPIRE_TIME_SECS_PROFILE_KEYS = 60 * 60 * 24 * STALL_INFO_DAYS
1515EXPIRE_TIME_MSECS_PROFILE_KEYS = EXPIRE_TIME_SECS_PROFILE_KEYS * 1000
1616
@@ -65,33 +65,21 @@ def generate_artifacts_table_grafana_redis(
6565 profile_markdown_str = profile_markdown_str .replace ("\n " , "" )
6666 profile_id = "{}_{}_hash_{}" .format (start_time_str , setup_name , tf_github_sha )
6767 profile_string_testcase_markdown_key = "profile:{}:{}" .format (profile_id , test_name )
68- zset_profiles = "profiles:{}_{}_{}" .format (
69- tf_github_org , tf_github_repo , setup_name
70- )
71- zset_profiles_setup = "profiles:setups:{}_{}" .format (
72- tf_github_org ,
73- tf_github_repo ,
74- )
75- profile_set_redis_key = "profile:{}:testcases" .format (profile_id )
76- zset_profiles_setups_testcases = "profiles:testcases:{}_{}_{}" .format (
77- tf_github_org ,
78- tf_github_repo ,
79- setup_name ,
80- )
81- zset_profiles_setups_testcases_profileid = "profiles:ids:{}_{}_{}_{}_{}" .format (
82- tf_github_org ,
83- tf_github_repo ,
68+ (
69+ profile_set_redis_key ,
70+ zset_profiles ,
71+ zset_profiles_setup ,
72+ zset_profiles_setups_testcases ,
73+ zset_profiles_setups_testcases_branches ,
74+ zset_profiles_setups_testcases_branches_latest_link ,
75+ zset_profiles_setups_testcases_profileid ,
76+ ) = get_profile_zset_names (
77+ profile_id ,
8478 setup_name ,
8579 test_name ,
8680 tf_github_branch ,
87- )
88- zset_profiles_setups_testcases_branches = "profiles:branches:{}_{}_{}_{}" .format (
89- tf_github_org , tf_github_repo , setup_name , test_name
90- )
91- zset_profiles_setups_testcases_branches_latest_link = (
92- "latest_profiles:by.branch:{}_{}_{}_{}" .format (
93- tf_github_org , tf_github_repo , setup_name , test_name
94- )
81+ tf_github_org ,
82+ tf_github_repo ,
9583 )
9684 https_link = "{}?var-org={}&var-repo={}&var-setup={}&var-branch={}" .format (
9785 grafana_profile_dashboard ,
@@ -103,13 +91,31 @@ def generate_artifacts_table_grafana_redis(
10391 test_name ,
10492 profile_id ,
10593 )
106- if push_results_redistimeseries :
94+ if push_results_redistimeseries is True :
95+ sorted_set_keys = [
96+ zset_profiles ,
97+ zset_profiles_setups_testcases_profileid ,
98+ zset_profiles_setups_testcases ,
99+ zset_profiles_setup ,
100+ zset_profiles_setups_testcases_branches_latest_link ,
101+ ]
102+ logging .info (
103+ "Propulating the profile helper ZSETs: {}" .format (" " .join (sorted_set_keys ))
104+ )
107105 current_time = time .time () * 1000
108106 timeframe_by_branch = current_time - EXPIRE_TIME_MSECS_PROFILE_KEYS
109- redis_conn .zadd (
107+ res = redis_conn .zadd (
110108 zset_profiles_setups_testcases_branches ,
111109 {tf_github_branch : start_time_ms },
112110 )
111+ logging .info (
112+ "Result of ZADD {} {} {} = {}" .format (
113+ zset_profiles_setups_testcases_branches ,
114+ start_time_ms ,
115+ tf_github_branch ,
116+ res ,
117+ )
118+ )
113119 redis_conn .zadd (
114120 zset_profiles_setups_testcases_branches_latest_link ,
115121 {https_link : start_time_ms },
@@ -130,14 +136,13 @@ def generate_artifacts_table_grafana_redis(
130136 zset_profiles ,
131137 {profile_id : start_time_ms },
132138 )
133- sorted_set_keys = [
134- zset_profiles ,
135- zset_profiles_setups_testcases_profileid ,
136- zset_profiles_setups_testcases ,
137- zset_profiles_setup ,
138- zset_profiles_setups_testcases_branches_latest_link ,
139- ]
139+
140140 for keyname in sorted_set_keys :
141+ logging .info (
142+ "Expiring all elements with score between 0 and {}" .format (
143+ int (timeframe_by_branch )
144+ )
145+ )
141146 redis_conn .zremrangebyscore (keyname , 0 , int (timeframe_by_branch ))
142147
143148 redis_conn .sadd (profile_set_redis_key , test_name )
@@ -153,3 +158,45 @@ def generate_artifacts_table_grafana_redis(
153158 )
154159 )
155160 return https_link
161+
162+
163+ def get_profile_zset_names (
164+ profile_id , setup_name , test_name , tf_github_branch , tf_github_org , tf_github_repo
165+ ):
166+ profile_set_redis_key = "profile:{}:testcases" .format (profile_id )
167+ zset_profiles = "profiles:{}_{}_{}" .format (
168+ tf_github_org , tf_github_repo , setup_name
169+ )
170+ zset_profiles_setup = "profiles:setups:{}_{}" .format (
171+ tf_github_org ,
172+ tf_github_repo ,
173+ )
174+ zset_profiles_setups_testcases = "profiles:testcases:{}_{}_{}" .format (
175+ tf_github_org ,
176+ tf_github_repo ,
177+ setup_name ,
178+ )
179+ zset_profiles_setups_testcases_profileid = "profiles:ids:{}_{}_{}_{}_{}" .format (
180+ tf_github_org ,
181+ tf_github_repo ,
182+ setup_name ,
183+ test_name ,
184+ tf_github_branch ,
185+ )
186+ zset_profiles_setups_testcases_branches = "profiles:branches:{}_{}_{}_{}" .format (
187+ tf_github_org , tf_github_repo , setup_name , test_name
188+ )
189+ zset_profiles_setups_testcases_branches_latest_link = (
190+ "latest_profiles:by.branch:{}_{}_{}_{}" .format (
191+ tf_github_org , tf_github_repo , setup_name , test_name
192+ )
193+ )
194+ return (
195+ profile_set_redis_key ,
196+ zset_profiles ,
197+ zset_profiles_setup ,
198+ zset_profiles_setups_testcases ,
199+ zset_profiles_setups_testcases_branches ,
200+ zset_profiles_setups_testcases_branches_latest_link ,
201+ zset_profiles_setups_testcases_profileid ,
202+ )
0 commit comments