Skip to content

Commit 0b32f29

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

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

monitor.py

Lines changed: 39 additions & 1 deletion
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

@@ -38,6 +38,39 @@ def fetch_release_date(release):
3838
return "Error while sending request to url"
3939
except json.JSONDecodeError as e:
4040
return "Failed to extract the spy-links"
41+
42+
def fetch_build_time(build):
43+
'''
44+
Returns the created time (HH:MM) and date (YYYY-MM-DD) of the release in IST
45+
'''
46+
url = constants.PROW_VIEW_URL + build[8:] + '/prowjob.json'
47+
48+
try:
49+
response = requests.get(url, verify=False, timeout=15)
50+
if response.status_code == 200:
51+
buildtime = json.loads(response.text)
52+
timestamp_str = buildtime["metadata"]["creationTimestamp"]
53+
54+
# Convert timestamp to datetime object (UTC)
55+
utc_time = datetime.strptime(timestamp_str, "%Y-%m-%dT%H:%M:%SZ")
56+
57+
# Convert UTC to IST (UTC +5:30)
58+
ist_time = utc_time + timedelta(hours=5, minutes=30)
59+
60+
# Extract date and time separately
61+
ist_date = ist_time.strftime("%Y-%m-%d") # YYYY-MM-DD
62+
ist_time_formatted = ist_time.strftime("%H:%M") # HH:MM (without seconds)
63+
64+
return ist_date, ist_time_formatted # Returning both date and time
65+
else:
66+
return f"ERROR: Received unexpected status code {response.status_code}"
67+
68+
except requests.Timeout:
69+
return "Request timed out", None
70+
except requests.RequestException:
71+
return "Error while sending request to URL", None
72+
except (json.JSONDecodeError, KeyError):
73+
return "Error while parsing prowjob.json", None
4174

4275
def set_prow_url(ci_job_type: str)->str:
4376
'''
@@ -1194,6 +1227,7 @@ def get_brief_job_info(build_list,prow_ci_name,zone=None):
11941227
for build in build_list:
11951228
match = re.search(pattern_build_id, build)
11961229
build_id = match.group(1)
1230+
_,time=fetch_build_time(build)
11971231
lease, _ = get_quota_and_nightly(build)
11981232
if zone is not None and lease not in zone :
11991233
continue
@@ -1204,6 +1238,7 @@ def get_brief_job_info(build_list,prow_ci_name,zone=None):
12041238
job_dict = {}
12051239
job_dict["Job"] = prow_ci_name
12061240
job_dict["Prow Build ID"] = build_id
1241+
job_dict["Time"]=time
12071242
job_dict["Install Status"] = cluster_status
12081243
if sensitive_info_expose_status == True:
12091244
job_dict["Lease"]="Build log removed"
@@ -1255,7 +1290,10 @@ def get_detailed_job_info(build_list,prow_ci_name,zone=None):
12551290
builds_to_deleted.append(build)
12561291
continue
12571292
i=i+1
1293+
date,time=fetch_build_time(build)
1294+
12581295
print(i,"Job link:"+constants.JOB_LINK_URL+build)
1296+
print("Build start time: "+time +" "+date)
12591297

12601298
build_status = check_job_status(build)
12611299
sensitive_info_expose_status=check_if_sensitive_info_exposed(build)

0 commit comments

Comments
 (0)