feat(prow): auto-inject metadata labels to kubevirt prowjobs#4841
feat(prow): auto-inject metadata labels to kubevirt prowjobs#4841Aneesh-Hegde wants to merge 1 commit into
Conversation
Signed-off-by: Aneesh Hegde <aneeshhegde7110@gmail.com>
There was a problem hiding this comment.
Sorry @Aneesh-Hegde, your pull request is larger than the review limit of 150000 diff characters
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @Aneesh-Hegde. Thanks for your PR. PRs from untrusted users cannot be marked as trusted with I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
/cc @dhiller |
|
PR needs rebase. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
Hey @dhiller ! Since this PR modifies over 2,000 lines, I want to make reviewing it as painless as possible. I did not hand edit these files. To prevent human error and perfectly preserve your existing YAML formatting and comments, I wrote a Python script using the Instead of reading the massive diff, you only need to review the regex logic in this script. Detailsimport os
import re
from ruamel.yaml import YAML
def process_yaml(filepath):
yaml = YAML()
yaml.allow_duplicate_keys = True
yaml.preserve_quotes = True
yaml.indent(mapping=2, sequence=2, offset=0)
yaml.width = 4096
try:
with open(filepath, 'r') as f:
data = yaml.load(f)
except Exception as e:
return
if not data or not isinstance(data, dict):
return
modified = False
job_types = ['presubmits', 'postsubmits', 'periodics']
for j_type in job_types:
if j_type in data and isinstance(data[j_type], dict):
for repo, jobs in data[j_type].items():
if not jobs or not isinstance(jobs, list):
continue
for job in jobs:
if not isinstance(job, dict) or 'name' not in job:
continue
job_name = job['name']
new_labels = {}
# 1. Extract Version
k8s_match = re.search(r'(?:k8s|kind)-(\d+\.\d+)', job_name)
if k8s_match:
new_labels['ci.kubevirt.io/k8s-version'] = k8s_match.group(1)
# 2. Extract SIG
sig_match = re.search(r'sig-([a-zA-Z0-9]+)', job_name)
if sig_match:
new_labels['ci.kubevirt.io/sig'] = sig_match.group(1)
# 3. Extract Category
if '-e2e-' in job_name:
new_labels['ci.kubevirt.io/category'] = 'e2e'
elif '-unit-' in job_name:
new_labels['ci.kubevirt.io/category'] = 'unit'
elif '-build-' in job_name:
new_labels['ci.kubevirt.io/category'] = 'build'
elif '-lint' in job_name:
new_labels['ci.kubevirt.io/category'] = 'lint'
if new_labels:
if 'labels' not in job:
job['labels'] = {}
for key, val in new_labels.items():
if key not in job['labels']:
job['labels'][key] = val
modified = True
if modified:
with open(filepath, 'w') as f:
yaml.dump(data, f)
def main():
for filename in os.listdir('.'):
if filename.endswith('.yaml'):
process_yaml(filename)
if __name__ == '__main__':
main() |
What this PR does / why we need it:
Injects explicit metadata labels (
ci.kubevirt.io/k8s-version,ci.kubevirt.io/sig, andci.kubevirt.io/category) into KubeVirt ProwJobs. This allows the prow-exporter to scrape these dimensions, enabling Grafana admins to filter metrics using clean Prometheus label queries instead of relying on fragile regex matching against the job_name.Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)format, will close the issue(s) when PR gets merged):Fixes #4733
Special notes for your reviewer:
To avoid human error and preserve existing YAML formatting/comments, I used an automated ruamel.yaml Python script to parse the name strings and inject the labels across the jobs/kubevirt/kubevirt/ directory.
Questions for Maintainers:
I currently extracted Version, SIG, and Category based on the issue description. Looking at the job names, I could also extract architecture (arm64/s390x) and provider/hardware (kind/vgpu/sriov). Would you like those added to this PR, or should we keep the scope narrow for now?
Checklist
This checklist is not enforcing, but it's a reminder of items that could be relevant to every PR.
Approvers are expected to review this list.
Release note: