Skip to content

Commit

Permalink
Add KMT links
Browse files Browse the repository at this point in the history
  • Loading branch information
gjulianm committed Sep 20, 2024
1 parent 9a66a5e commit 05efcd9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tasks/gitlab_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from invoke import task

from tasks.kernel_matrix_testing.ci import get_kmt_dashboard_links
from tasks.libs.ciproviders.gitlab_api import (
get_all_gitlab_ci_configurations,
get_gitlab_ci_configuration,
Expand Down Expand Up @@ -62,7 +63,7 @@ def generate_ci_visibility_links(_ctx, output: str | None):


def create_gitlab_annotations_report(ci_job_id: str, ci_job_name: str):
return {
links = {
"CI Visibility": [
{
"external_link": {
Expand Down Expand Up @@ -91,6 +92,12 @@ def create_gitlab_annotations_report(ci_job_id: str, ci_job_name: str):
]
}

kmt_links = get_kmt_dashboard_links()
if kmt_links:
links["KMT Dashboard"] = kmt_links

return links


def print_gitlab_object(get_object, ctx, ids, repo='DataDog/datadog-agent', jq: str | None = None, jq_colors=True):
"""
Expand Down
46 changes: 46 additions & 0 deletions tasks/kernel_matrix_testing/ci.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from __future__ import annotations

import datetime
import io
import json
import os
import re
import tarfile
import urllib.parse
import xml.etree.ElementTree as ET
from typing import TYPE_CHECKING, overload

Expand Down Expand Up @@ -250,3 +252,47 @@ def get_all_jobs_for_pipeline(pipeline_id: int | str) -> tuple[list[KMTSetupEnvJ
break

return setup_jobs, test_jobs


def get_kmt_dashboard_links() -> None | list:
stage = os.environ.get("CI_JOB_STAGE")
pipeline = os.environ.get("CI_PIPELINE_ID")
branch = os.environ.get("CI_COMMIT_REF_NAME")
pipeline_start = os.environ.get("CI_PIPELINE_CREATED_AT")

# Check we're running in Gitlab CI
if pipeline_start is None or branch is None or pipeline is None or stage is None:
return None

# Check this is a KMT job
if "kernel_matrix_testing" not in stage:
return None

try:
pipeline_start_date = datetime.datetime.fromisoformat(pipeline_start)
except Exception:
print(f"Error: Could not parse pipeline start date {pipeline_start}")
return None

dashboard_end = pipeline_start_date + datetime.timedelta(hours=4)

query_args = {
"fromUser": "false",
"refresh_mode": "paused",
"tpl_var_ci.pipeline.id[0]": pipeline,
"tpl_var_git-branch[0]": branch,
"from_ts": int(pipeline_start_date.timestamp()) * 1000,
"to_ts": int(dashboard_end.timestamp()) * 1000,
"live": "false",
}

url = f"https://app.datadoghq.com/dashboard/zs9-uia-gsg?{urllib.parse.urlencode(query_args)}"

return [
{
"external_link": {
"label": "KMT: Pipeline dashboard",
"url": url,
}
}
]

0 comments on commit 05efcd9

Please sign in to comment.