Skip to content

Commit fc8b84f

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

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

monitor.py

Lines changed: 48 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,42 @@ 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(build):
51+
'''
52+
Returns the created time (HH:MM) and date (YYYY-MM-DD) of the release in IST
53+
'''
54+
url = constants.PROW_VIEW_URL + build[8:] + '/prowjob.json'
55+
56+
try:
57+
response = requests.get(url, verify=False, timeout=15)
58+
if response.status_code == 200:
59+
buildtime = json.loads(response.text)
60+
timestamp_str = buildtime["metadata"]["creationTimestamp"]
61+
62+
# Convert timestamp to datetime object (UTC)
63+
utc_time = datetime.strptime(timestamp_str, "%Y-%m-%dT%H:%M:%SZ")
64+
65+
# Convert UTC to IST (UTC +5:30)
66+
ist_time = utc_time + timedelta(hours=5, minutes=30)
67+
68+
# Extract date and time separately
69+
ist_date = ist_time.strftime("%Y-%m-%d") # YYYY-MM-DD
70+
ist_time_formatted = ist_time.strftime("%H:%M") # HH:MM (without seconds)
71+
72+
return ist_date, ist_time_formatted # Returning both date and time
73+
else:
74+
return "failed to get build time"
75+
76+
except requests.Timeout:
77+
print("Request timed out")
78+
return None,None
79+
except requests.RequestException:
80+
print("Error while sending request to URL")
81+
return None,None
82+
except (json.JSONDecodeError, KeyError):
83+
print("Error while parsing prowjob.json")
84+
return None,None
4985

5086
def set_prow_url(ci_job_type: str)->str:
5187
'''
@@ -1219,6 +1255,7 @@ def get_brief_job_info(build_list,prow_ci_name,zone=None):
12191255
for build in build_list:
12201256
match = re.search(pattern_build_id, build)
12211257
build_id = match.group(1)
1258+
_,time=fetch_build_time(build)
12221259
lease, _ = get_quota_and_nightly(build)
12231260
if zone is not None and lease not in zone :
12241261
continue
@@ -1229,6 +1266,10 @@ def get_brief_job_info(build_list,prow_ci_name,zone=None):
12291266
job_dict = {}
12301267
job_dict["Job"] = prow_ci_name
12311268
job_dict["Prow Build ID"] = build_id
1269+
if time is None:
1270+
job_dict["Time"]="unable to fetch time"
1271+
else:
1272+
job_dict["Time"]=time
12321273
job_dict["Install Status"] = cluster_status
12331274
if sensitive_info_expose_status == True:
12341275
job_dict["Lease"]="Build log removed"
@@ -1284,8 +1325,13 @@ def get_detailed_job_info(build_list,prow_ci_name,zone=None):
12841325
builds_to_deleted.append(build)
12851326
continue
12861327
i=i+1
1287-
print(i,"Job link:"+constants.JOB_LINK_URL+build)
1328+
date,time=fetch_build_time(build)
12881329

1330+
print(i,"Job link:"+constants.JOB_LINK_URL+build)
1331+
if date and time is None:
1332+
print("Build start time: Unable to fetch time")
1333+
else:
1334+
print("Build start time: "+date +" "+time)
12891335
build_status = check_job_status(build)
12901336
sensitive_info_expose_status=check_if_sensitive_info_exposed(build)
12911337

0 commit comments

Comments
 (0)