Skip to content

Added Time in both brief and detailed output #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from bs4 import BeautifulSoup
import urllib3
import requests
from datetime import datetime
from datetime import datetime , timedelta
import xml.etree.ElementTree as ET
import constants

Expand Down Expand Up @@ -46,6 +46,23 @@ def fetch_release_date(release):
return "Error while sending request to url"
except json.JSONDecodeError as e:
return "Failed to extract the spy-links"

def fetch_build_time(url):
'''
Returns the created time (HH:MM) and date (YYYY-MM-DD) of the release in IST
'''
response = requests.get(url, verify=False, timeout=15)
response.raise_for_status()
buildtime = json.loads(response.text)
timestamp_str = buildtime["metadata"]["creationTimestamp"]
# Convert timestamp to datetime object (UTC)
utc_time = datetime.strptime(timestamp_str, "%Y-%m-%dT%H:%M:%SZ")
# Convert UTC to IST (UTC +5:30)
ist_time = utc_time + timedelta(hours=5, minutes=30)
ist_date = ist_time.strftime("%Y-%m-%d") # YYYY-MM-DD
ist_time_formatted = ist_time.strftime("%H:%M") # HH:MM (without seconds)
timestamp=ist_date+" "+ist_time_formatted
return timestamp

def set_prow_url(ci_job_type: str)->str:
'''
Expand Down Expand Up @@ -1219,6 +1236,11 @@ def get_brief_job_info(build_list,prow_ci_name,zone=None):
for build in build_list:
match = re.search(pattern_build_id, build)
build_id = match.group(1)
try:
url = constants.PROW_VIEW_URL + build[8:] + '/prowjob.json'
time=fetch_build_time(url)
except:
time=None
lease, _ = get_quota_and_nightly(build)
if zone is not None and lease not in zone :
continue
Expand All @@ -1229,6 +1251,10 @@ def get_brief_job_info(build_list,prow_ci_name,zone=None):
job_dict = {}
job_dict["Job"] = prow_ci_name
job_dict["Prow Build ID"] = build_id
if time:
job_dict["Time"]=time[11:]
else:
job_dict["Time"]="Failed to fetch time"
job_dict["Install Status"] = cluster_status
if sensitive_info_expose_status == True:
job_dict["Lease"]="Build log removed"
Expand Down Expand Up @@ -1285,7 +1311,12 @@ def get_detailed_job_info(build_list,prow_ci_name,zone=None):
continue
i=i+1
print(i,"Job link:"+constants.JOB_LINK_URL+build)

try:
url = constants.PROW_VIEW_URL + build[8:] + '/prowjob.json'
time=fetch_build_time(url)
print("Build start time:", time)
except (requests.exceptions.RequestException, KeyError, ValueError) as e:
print("Error fetching build time:", e)
build_status = check_job_status(build)
sensitive_info_expose_status=check_if_sensitive_info_exposed(build)

Expand Down