Skip to content

Commit 51969fb

Browse files
authored
Merge pull request #832 from cncf/update-keggs
Update metadata gathering functions
2 parents 2d76e2c + 685e639 commit 51969fb

File tree

1 file changed

+36
-32
lines changed

1 file changed

+36
-32
lines changed

apps/snoopdb/postgres/snoopUtils.py

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
AKC_BUCKET="ci-audit-kind-conformance"
2121
KGCL_BUCKET="ci-kubernetes-gce-conformance-latest"
2222
KEGG_BUCKET="ci-kubernetes-e2e-gci-gce"
23+
CONFORMANCE_RUNS="https://prow.k8s.io/job-history/kubernetes-jenkins/logs/"
2324

24-
AUDIT_KIND_CONFORMANCE_RUNS="https://prow.k8s.io/job-history/kubernetes-jenkins/logs/ci-audit-kind-conformance"
2525
AUDIT_KIND_CONFORMANCE_LOGS="https://storage.googleapis.com/kubernetes-jenkins/logs/ci-audit-kind-conformance"
2626
GCS_LOGS="https://storage.googleapis.com/kubernetes-jenkins/logs/"
2727

@@ -295,11 +295,12 @@ def find_operation_id(openapi_spec, event):
295295
openapi_spec['hit_cache'][url.path][method]=op_id
296296
return op_id, None
297297

298-
def akc_latest_success():
298+
def bucket_latest_success(bucket):
299299
"""
300300
determines latest successful run for ci-audit-kind-conformance and returns its ID as a string.
301301
"""
302-
soup = get_html(AUDIT_KIND_CONFORMANCE_RUNS)
302+
test_runs = CONFORMANCE_RUNS + bucket
303+
soup = get_html(test_runs)
303304
scripts = soup.find(is_spyglass_script)
304305
if scripts is None :
305306
raise ValueError("No spyglass script found in akc page")
@@ -345,34 +346,42 @@ def akc_timestamp(job):
345346
started = json.loads(urlopen(started_url).read().decode('utf-8'))
346347
return started["timestamp"]
347348

348-
def akc_meta(custom_job=None):
349+
def akc_meta(bucket, custom_job=None):
349350
"""
350351
Compose a Meta object for job of given AKC bucket.
351352
Meta object contains the job, the k8s version, the k8s commit, the audit log links for the test run, and thed timestamp of the testrun
352353
"""
353-
job = akc_latest_success() if custom_job is None else custom_job
354+
job = bucket_latest_success(bucket) if custom_job is None else custom_job
354355
return Meta(job,
355356
akc_version(job),
356357
akc_commit(job),
357358
akc_loglinks(job),
358359
akc_timestamp(job))
359360

360-
def kgcl_version(job_version):
361+
def kgcl_version(job):
361362
"""
362363
return k8s semver for version of k8s run in given job's test run
363364
"""
365+
finished_url = GCS_LOGS + KGCL_BUCKET + '/' + job + '/finished.json'
366+
finished = get_json(finished_url)
367+
job_version = finished["metadata"]["job-version"]
368+
364369
match = re.match("^v([0-9.]+)-",job_version)
365370
if match is None:
366371
raise ValueError("Could not find version in given job_version.", job_version)
367372
else:
368373
version = match.group(1)
369374
return version
370375

371-
def kgcl_commit(job_version):
376+
def kgcl_commit(job):
372377
"""
373378
return k8s/k8s commit for k8s used in given job's test run
374379
"""
375380
# we want the end of the string, after the '+'. A commit should only be numbers and letters
381+
finished_url = GCS_LOGS + KGCL_BUCKET + '/' + job + '/finished.json'
382+
finished = get_json(finished_url)
383+
job_version = finished["metadata"]["job-version"]
384+
376385
match = re.match(".+\+([0-9a-zA-Z]+)$",job_version)
377386
if match is None:
378387
raise ValueError("Could not find commit in given job_version", job_version)
@@ -396,40 +405,41 @@ def kgcl_timestamp(job):
396405
finished = get_json(finished_url)
397406
return finished["timestamp"]
398407

399-
def kgcl_meta(custom_job=None):
408+
def kgcl_meta(bucket, custom_job=None):
400409
"""
401410
Compose a Meta object for job of given KGCL bucket.
402411
Meta object contains the job, the k8s version, the k8s commit, the audit log links for the test run, and thed timestamp of the testrun
403412
"""
404-
testgrid_history = get_json(GCS_LOGS + KGCL_BUCKET + "/jobResultsCache.json")
405-
if custom_job is not None:
406-
build = [x for x in testgrid_history if x['buildnumber'] == custom_job][0]
407-
else:
408-
build = [x for x in testgrid_history if x['result'] == 'SUCCESS'][-1]
409-
job = build["buildnumber"]
410-
job_version = build["job-version"]
413+
job = bucket_latest_success(bucket) if custom_job is None else custom_job
411414
return Meta(job,
412-
kgcl_version(job_version),
413-
kgcl_commit(job_version),
415+
kgcl_version(job),
416+
kgcl_commit(job),
414417
kgcl_loglinks(job),
415418
kgcl_timestamp(job))
416419

417-
def kegg_version(job_version):
420+
def kegg_version(job):
418421
"""
419422
return k8s semver for version of k8s run in given job's test run
420423
"""
424+
finished_url = GCS_LOGS + KEGG_BUCKET + '/' + job + '/finished.json'
425+
finished = get_json(finished_url)
426+
job_version = finished["metadata"]["job-version"]
427+
421428
match = re.match("^v([0-9.]+)-",job_version)
422429
if match is None:
423430
raise ValueError("Could not find version in given job_version.", job_version)
424431
else:
425432
version = match.group(1)
426433
return version
427434

428-
def kegg_commit(job_version):
435+
def kegg_commit(job):
429436
"""
430437
return k8s/k8s commit for k8s used in given job's test run
431438
"""
432439
# we want the end of the string, after the '+'. A commit should only be numbers and letters
440+
finished_url = GCS_LOGS + KEGG_BUCKET + '/' + job + '/finished.json'
441+
finished = get_json(finished_url)
442+
job_version = finished["metadata"]["job-version"]
433443
match = re.match(".+\+([0-9a-zA-Z]+)$",job_version)
434444
if match is None:
435445
raise ValueError("Could not find commit in given job_version.", job_version)
@@ -453,33 +463,27 @@ def kegg_timestamp(job):
453463
finished = get_json(finished_url)
454464
return finished["timestamp"]
455465

456-
def kegg_meta(custom_job=None):
466+
def kegg_meta(bucket, custom_job=None):
457467
"""
458468
Compose a Meta object for job of given KEGG bucket.
459469
Meta object contains the job, the k8s version, the k8s commit, the audit log links for the test run, and thed timestamp of the testrun
460470
"""
461-
testgrid_history = get_json(GCS_LOGS + KEGG_BUCKET + "/jobResultsCache.json")
462-
if custom_job is not None:
463-
build = [x for x in testgrid_history if x['buildnumber'] == custom_job][0]
464-
else:
465-
build = [x for x in testgrid_history if x['result'] == 'SUCCESS'][-1]
466-
job = build["buildnumber"]
467-
job_version = build["job-version"]
471+
job = bucket_latest_success(bucket) if custom_job is None else custom_job
468472
return Meta(job,
469-
kegg_version(job_version),
470-
kegg_commit(job_version),
473+
kegg_version(job),
474+
kegg_commit(job),
471475
kegg_loglinks(job),
472476
kegg_timestamp(job))
473477

474478
def get_meta(bucket,job=None):
475479
"""Returns meta object for given bucket.
476480
Meta includes job, k8s version, k8s commit, all auditlog links, and timestamp of the test run"""
477481
if(bucket == AKC_BUCKET):
478-
return akc_meta(job)
482+
return akc_meta(bucket,job)
479483
elif(bucket == KGCL_BUCKET):
480-
return kgcl_meta(job)
484+
return kgcl_meta(bucket,job)
481485
elif(bucket == KEGG_BUCKET):
482-
return kegg_meta(job)
486+
return kegg_meta(bucket, job)
483487

484488
def download_and_process_auditlogs(bucket,job):
485489
"""

0 commit comments

Comments
 (0)