Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
run: make import

- name: Generate newer usage graphs
continue-on-error: true
run: |
pip3 install click requests pygal
python3 files/generate_usage.py
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ jobs:
- name: Import the nested docs
run: make import

- name: Generate newer usage graphs
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or if we want to use it for testing the script, we can make it react only for changes on files/generate_usage.py path, wdyt?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

React to changes in the path can be helpful to catch errors earlier. But I am also fine with it like this. I expect we would catch the errors in the action were we really need this.

run: |
pip3 install click requests pygal
python3 files/generate_usage.py

- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Test build website
Expand Down
79 changes: 50 additions & 29 deletions files/generate_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Copyright Contributors to the Packit project.
# SPDX-License-Identifier: MIT

import sys
import click
import requests
import json
Expand Down Expand Up @@ -38,39 +39,59 @@ def generate_usage_treemap():
Generate usage heatmaps
"""
click.echo("Loading new data")
response = requests.request(
method="GET", url="https://prod.packit.dev/api/usage?top=1000&from=1994-01-01"
)
result = json.loads(response.content)

for job_name, job_data in result["jobs"].items():
job_name_human_readable = (
job_name.replace("_", " ")
.capitalize()
.replace(" Groups", "s")
.replace(" Targets", "s")
.replace("Vm", "VM")
.replace("Tft", "TFT")
.replace("Srpm", "SRPM")
try:
response = requests.request(
method="GET", url="https://prod.packit.dev/api/usage?top=1000&from=1994-01-01"
)
response.raise_for_status()
result = json.loads(response.content)
except requests.exceptions.RequestException as e:
click.echo(f"Error fetching usage data: {e}", err=True)
sys.exit(1)
except json.JSONDecodeError as e:
click.echo(f"Error parsing JSON response: {e}", err=True)
sys.exit(1)

data_namespaces = defaultdict(int)
for p, c in job_data["top_projects_by_job_runs"].items():
data_namespaces[
p.removeprefix("https://github.com/").rsplit("/", maxsplit=1)[0]
] += c

sorted_data = sorted(data_namespaces.items(), key=lambda x: -x[1]) # [:3]

for style, style_class in (("light", DefaultStyle), ("dark", DarkStyle)):
generate_graph(
f"Packit: {job_name_human_readable}",
data=sorted_data,
path=f"./static/img/usage/{job_name}_{style}.svg",
value_text=("builds" if "build" in job_name else "runs"),
style=style_class,
failed_jobs = []

for job_name, job_data in result["jobs"].items():
try:
job_name_human_readable = (
job_name.replace("_", " ")
.capitalize()
.replace(" Groups", "s")
.replace(" Targets", "s")
.replace("Vm", "VM")
.replace("Tft", "TFT")
.replace("Srpm", "SRPM")
)

data_namespaces = defaultdict(int)
for p, c in job_data["top_projects_by_job_runs"].items():
data_namespaces[
p.removeprefix("https://github.com/").rsplit("/", maxsplit=1)[0]
] += c

sorted_data = sorted(data_namespaces.items(), key=lambda x: -x[1]) # [:3]

for style, style_class in (("light", DefaultStyle), ("dark", DarkStyle)):
generate_graph(
f"Packit: {job_name_human_readable}",
data=sorted_data,
path=f"./static/img/usage/{job_name}_{style}.svg",
value_text=("builds" if "build" in job_name else "runs"),
style=style_class,
)
except Exception as e:
click.echo(f"Error generating graph for {job_name}: {e}", err=True)
failed_jobs.append(job_name)

if failed_jobs:
click.echo(f"Failed: {', '.join(failed_jobs)}", err=True)
sys.exit(1)

click.echo("Successfully generated all usage graphs")


if __name__ == "__main__":
generate_usage_treemap()
Loading