Skip to content

Commit ea3c2d5

Browse files
Added Time in both brief and detailed output
Signed-off-by: alokgoswami-ag <[email protected]>
1 parent 25b5cf4 commit ea3c2d5

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

monitor.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from bs4 import BeautifulSoup
55
import urllib3
66
import requests
7-
from datetime import datetime
7+
from datetime import datetime , timedelta
88
import xml.etree.ElementTree as ET
99
import constants
1010

@@ -46,6 +46,23 @@ def fetch_release_date(release):
4646
return "Error while sending request to url"
4747
except json.JSONDecodeError as e:
4848
return "Failed to extract the spy-links"
49+
50+
def fetch_build_time(url):
51+
'''
52+
Returns the created time (HH:MM) and date (YYYY-MM-DD) of the release in IST
53+
'''
54+
response = requests.get(url, verify=False, timeout=15)
55+
response.raise_for_status()
56+
buildtime = json.loads(response.text)
57+
timestamp_str = buildtime["metadata"]["creationTimestamp"]
58+
# Convert timestamp to datetime object (UTC)
59+
utc_time = datetime.strptime(timestamp_str, "%Y-%m-%dT%H:%M:%SZ")
60+
# Convert UTC to IST (UTC +5:30)
61+
ist_time = utc_time + timedelta(hours=5, minutes=30)
62+
ist_date = ist_time.strftime("%Y-%m-%d") # YYYY-MM-DD
63+
ist_time_formatted = ist_time.strftime("%H:%M") # HH:MM (without seconds)
64+
timestamp=ist_date+" "+ist_time_formatted
65+
return timestamp
4966

5067
def set_prow_url(ci_job_type: str)->str:
5168
'''
@@ -1219,6 +1236,11 @@ def get_brief_job_info(build_list,prow_ci_name,zone=None):
12191236
for build in build_list:
12201237
match = re.search(pattern_build_id, build)
12211238
build_id = match.group(1)
1239+
try:
1240+
url = constants.PROW_VIEW_URL + build[8:] + '/prowjob.json'
1241+
time=fetch_build_time(url)
1242+
except:
1243+
time=None
12221244
lease, _ = get_quota_and_nightly(build)
12231245
if zone is not None and lease not in zone :
12241246
continue
@@ -1229,6 +1251,10 @@ def get_brief_job_info(build_list,prow_ci_name,zone=None):
12291251
job_dict = {}
12301252
job_dict["Job"] = prow_ci_name
12311253
job_dict["Prow Build ID"] = build_id
1254+
if time:
1255+
job_dict["Time"]=time[11:]
1256+
else:
1257+
job_dict["Time"]="Failed to fetch time"
12321258
job_dict["Install Status"] = cluster_status
12331259
if sensitive_info_expose_status == True:
12341260
job_dict["Lease"]="Build log removed"
@@ -1285,7 +1311,12 @@ def get_detailed_job_info(build_list,prow_ci_name,zone=None):
12851311
continue
12861312
i=i+1
12871313
print(i,"Job link:"+constants.JOB_LINK_URL+build)
1288-
1314+
try:
1315+
url = constants.PROW_VIEW_URL + build[8:] + '/prowjob.json'
1316+
time=fetch_build_time(url)
1317+
print("Build start time:", time)
1318+
except (requests.exceptions.RequestException, KeyError, ValueError) as e:
1319+
print("Error fetching build time:", e)
12891320
build_status = check_job_status(build)
12901321
sensitive_info_expose_status=check_if_sensitive_info_exposed(build)
12911322

0 commit comments

Comments
 (0)