Commit cd274127 authored by Christophe Benz's avatar Christophe Benz

Add link to Grafana dashboard

parent 71d6d4d5
......@@ -4,6 +4,7 @@ GITLAB_BASE_URL=https://git.nomics.world
GITLAB_PRIVATE_TOKEN=
UI_BASE_URL=https://db.nomics.world
GRAFANA_DASHBOARD_URL=http://grafana.k8s.db.nomics.world/d/CjF6WPZMz/overview
SOLR_URL=https://solr.db.nomics.world/solr/dbnomics
NB_PIPELINES=5
......
......@@ -38,7 +38,7 @@ import zipfile
from dataclasses import dataclass, field
from datetime import datetime
from pathlib import Path
from typing import Dict, List, Optional
from typing import Dict, List, Optional, Tuple
from urllib.parse import urljoin
import daiquiri
......@@ -95,6 +95,11 @@ def main():
parser.add_argument(
"--ui-base-url", default=env.str("UI_BASE_URL"), help="base URL of DBnomics UI",
)
parser.add_argument(
"--grafana-dashboard-url",
default=env.str("GRAFANA_DASHBOARD_URL"),
help="URL of the dashboard in Grafana",
)
parser.add_argument(
"--solr-url", default=env.str("SOLR_URL"), help="base URL of Solr core",
)
......@@ -174,6 +179,7 @@ def main():
"schedule_url": schedule_url,
"source_data_url": source_data_url,
"str": str,
"to_grafana_timestamp_ms": to_grafana_timestamp_ms,
"urljoin": urljoin,
"validators": validators,
}
......@@ -323,6 +329,24 @@ class Fetcher:
validate_jobs: List[Job] = field(default_factory=list)
def normalize_iso_date(s: str):
if s.endswith("Z"):
s = s[:-1] + "+00:00"
return s
def to_grafana_timestamp_ms(pipeline: ProjectPipeline) -> Tuple[int, Optional[int]]:
created_at_s = normalize_iso_date(pipeline.created_at)
created_at_ts = datetime.fromisoformat(created_at_s).timestamp()
from_ts_ms = int(created_at_ts * 1000)
to_ts_ms = (
int((created_at_ts + pipeline.duration) * 1000)
if pipeline.duration is not None
else None
)
return (from_ts_ms, to_ts_ms)
def jobs_url(base_url: str, project: Project):
return urljoin(base_url, "{}/-/jobs".format(project.path_with_namespace))
......@@ -486,9 +510,10 @@ class DashboardGenerator:
args = self.args
def iter_project_pipelines(project):
for pipeline in take(
for pipeline_light in take(
args.max_nb_pipelines_fetched, project.pipelines.list(as_list=False)
):
pipeline = project.pipelines.get(pipeline_light.id)
pipeline_jobs = pipeline.jobs.list()
# Legacy pipelines have only one job named "job".
is_new_pipeline = len(pipeline_jobs) > 1
......
......@@ -52,6 +52,8 @@
created: {{ local_time(pipeline.created_at) if pipeline.created_at else "?" }}
<br>
updated: {{ local_time(pipeline.updated_at) if pipeline.updated_at else "?" }}
<br>
duration: {{ pipeline.duration if pipeline.duration is not none else "?" }}
{% endmacro %}
{% macro job_icon(job) %}
......@@ -83,5 +85,9 @@
{% endfor %}
</span>
{% endfor %}
{% set ts_ms_pair = to_grafana_timestamp_ms(pipeline) %}
<a href="{{ args.grafana_dashboard_url }}?from={{ ts_ms_pair[0] }}&to={{ ts_ms_pair[1] or "" }}" title="Open Grafana dashboard">
<i class="fas fa-chart-area"></i>
</a>
</div>
{% endmacro %}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment