generated from rochacbruno/python-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from ubuntu-robotics/feat/grafana_dashboards_w…
…ith_charm Feat/grafana dashboards with charm
- Loading branch information
Showing
13 changed files
with
260 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# The workflow canonical/observability/.github/workflows/rock-release-dev.yaml@main | ||
# https://github.com/canonical/observability/blob/34b7edb56094e8e3f01200ce49e01bf9dd6688ac/.github/workflows/rock-release-dev.yaml | ||
# does not allow setting a GHCR repo where to publish at the moment. | ||
# We thus copy it below and adapt it. | ||
|
||
name: Build ROCK and release pr tag to GHCR | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
main: | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Find the *latest* rockcraft.yaml | ||
id: find-latest | ||
run: | | ||
latest_rockcraft_file=$(find $GITHUB_WORKSPACE -name "rockcraft.yaml" | sort -V | tail -n1) | ||
rockcraft_dir=$(dirname ${latest_rockcraft_file#\./}) | ||
echo "latest-dir=$rockcraft_dir" >> $GITHUB_OUTPUT | ||
- name: Build ROCK | ||
uses: canonical/craft-actions/rockcraft-pack@main | ||
with: | ||
path: "${{ steps.find-latest.outputs.latest-dir }}" | ||
verbosity: verbose | ||
id: rockcraft | ||
|
||
- name: Upload locally built ROCK artifact | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: cos-registration-agent-rock | ||
path: ${{ steps.rockcraft.outputs.rock }} | ||
|
||
- name: Upload ROCK to ghcr.io | ||
run: | | ||
sudo skopeo --insecure-policy copy oci-archive:$(realpath ${{ steps.rockcraft.outputs.rock }}) docker://ghcr.io/ubuntu-robotics/cos-registration-server:pr --dest-creds "${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}" | ||
- name: Generate digest | ||
run: | | ||
digest=$(skopeo inspect oci-archive:$(realpath ${{ steps.rockcraft.outputs.rock }}) --format '{{.Digest}}') | ||
echo "digest=${digest#*:}" >> "$GITHUB_OUTPUT" | ||
- name: Install Syft | ||
run: | | ||
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin | ||
- name: Create SBOM | ||
run: syft $(realpath ${{ steps.rockcraft.outputs.rock }}) -o spdx-json=cos-registration-server.sbom.json | ||
|
||
- name: Upload SBOM | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: cos-registration-server-sbom | ||
path: "cos-registration-server.sbom.json" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import json | ||
from os import mkdir, remove | ||
from pathlib import Path | ||
from shutil import rmtree | ||
|
||
from devices.models import Device | ||
from django.conf import settings | ||
|
||
|
||
def add_grafana_dashboards(device): | ||
dashboard_path = Path(settings.GRAFANA_DASHBOARD_PATH) | ||
for dashboard in device.grafana_dashboards: | ||
dashboard_title = dashboard["title"].replace(" ", "_") | ||
dashboard["title"] = f'{device.uid}-{dashboard["title"]}' | ||
dashboard_file = f"{device.uid}-{dashboard_title}.json" | ||
with open(dashboard_path / dashboard_file, "w") as file: | ||
json.dump(dashboard, file) | ||
|
||
|
||
def delete_grafana_dashboards(device): | ||
dashboard_path = Path(settings.GRAFANA_DASHBOARD_PATH) | ||
|
||
def _is_device_dashboard(p: Path) -> bool: | ||
return p.is_file() and p.name.startswith(device.uid) | ||
|
||
for dashboard in filter( | ||
_is_device_dashboard, Path(dashboard_path).glob("*") | ||
): | ||
remove(dashboard) | ||
|
||
|
||
def update_all_grafana_dashboards(): | ||
dashboard_path = Path(settings.GRAFANA_DASHBOARD_PATH) | ||
rmtree(dashboard_path, ignore_errors=True) | ||
mkdir(dashboard_path) | ||
for device in Device.objects.all(): | ||
add_grafana_dashboards(device) |
Empty file.
Empty file.
9 changes: 9 additions & 0 deletions
9
cos_registration_server/api/management/commands/update_all_grafana_dashboards.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from api.grafana_dashboards import update_all_grafana_dashboards | ||
from django.core.management.base import BaseCommand | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Update all the grafana dashboards in the folder" | ||
|
||
def handle(self, *args, **options): | ||
update_all_grafana_dashboards() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.