Skip to content

Commit fe9debd

Browse files
committed
WIP new charm
1 parent 2e0529e commit fe9debd

File tree

16 files changed

+747
-52
lines changed

16 files changed

+747
-52
lines changed
Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build and test charms
1+
name: Build and test charm
22

33
on:
44
push:
@@ -12,34 +12,11 @@ env:
1212
DEBIAN_FRONTEND: noninteractive
1313

1414
jobs:
15-
define-charm-list:
16-
name: Define charm list to build
17-
runs-on: ubuntu-24.04
18-
outputs:
19-
charms: ${{ steps.charms.outputs.charms }}
20-
steps:
21-
- name: Checkout
22-
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0
23-
with:
24-
persist-credentials: false
25-
26-
- name: Generate list
27-
id: charms
28-
run: |
29-
list="$(find . -mindepth 1 -maxdepth 1 -type d -printf '"%P", ')"
30-
echo "charms=[$list]"
31-
echo "charms=[$list]" >> $GITHUB_OUTPUT
32-
working-directory: charms
33-
3415
lint:
35-
name: Lint - (${{ matrix.charm }})
16+
name: Lint
3617
runs-on: ubuntu-24.04
37-
needs:
38-
- define-charm-list
3918
strategy:
4019
fail-fast: false
41-
matrix:
42-
charm: ${{ fromJSON(needs.define-charm-list.outputs.charms) }}
4320
steps:
4421
- name: Checkout
4522
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0
@@ -49,16 +26,11 @@ jobs:
4926
run: sudo snap install ruff --classic
5027
- name: Run linters
5128
run: ruff check --preview .
52-
working-directory: charms/${{ matrix.charm }}
29+
working-directory: charm
5330

5431
lib-check:
55-
name: Check libraries - (${{ matrix.charm }})
32+
name: Check libraries
5633
runs-on: ubuntu-24.04
57-
needs:
58-
- define-charm-list
59-
strategy:
60-
matrix:
61-
charm: ${{ fromJSON(needs.define-charm-list.outputs.charms) }}
6234
permissions:
6335
contents: write
6436
pull-requests: write
@@ -72,16 +44,11 @@ jobs:
7244
uses: canonical/charming-actions/check-libraries@1753e0803f70445132e92acd45c905aba6473225 # 2.7.0
7345
with:
7446
github-token: "${{ secrets.GITHUB_TOKEN }}"
75-
charm-path: charms/${{ matrix.charm }}
47+
charm-path: .
7648

7749
pack-charm:
78-
name: Build charm - (${{ matrix.charm }})
50+
name: Build charm
7951
runs-on: ubuntu-24.04
80-
needs:
81-
- define-charm-list
82-
strategy:
83-
matrix:
84-
charm: ${{ fromJSON(needs.define-charm-list.outputs.charms) }}
8552
steps:
8653
- name: Checkout
8754
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0
@@ -102,24 +69,22 @@ jobs:
10269
10370
- name: Pack charm
10471
run: charmcraft pack -v
105-
working-directory: charms/${{ matrix.charm }}
10672

10773
- name: Test charm
108-
run: uv run --all-extras pytest tests/ -vv --log-level=INFO
109-
working-directory: charms/${{ matrix.charm }}
74+
run: uv run --all-extras pytest -vv --log-level=INFO .
75+
working-directory: charm/tests
11076

11177
- name: Upload charm artifact
11278
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
11379
with:
114-
name: ${{ matrix.charm }}.charm
115-
path: charms/${{ matrix.charm }}/*.charm
80+
name: error-tracker.charm
81+
path: "*.charm"
11682

11783
- name: Upload charm to charmhub
11884
uses: canonical/charming-actions/upload-charm@1753e0803f70445132e92acd45c905aba6473225 # 2.7.0
11985
with:
12086
credentials: '${{ secrets.CHARMHUB_TOKEN }}'
12187
github-token: '${{ secrets.GITHUB_TOKEN }}'
122-
charm-path: charms/${{ matrix.charm }}
12388
tag-prefix: ${{ matrix.charm }}
124-
built-charm-path: error-tracker-${{ matrix.charm }}_ubuntu@24.04-amd64.charm
89+
built-charm-path: error-tracker_ubuntu@24.04-amd64.charm
12590
if: github.ref == 'refs/heads/main'

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
run: sudo snap install charmcraft --classic
4444
- name: Run Error Tracker tests
4545
run: |
46-
charmcraft.spread -v
46+
charmcraft.spread -v tests/errortracker/
4747
# spread artifacts need to work to re-enable this
4848
# - name: Upload coverage
4949
# uses: actions/upload-artifact@v4

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
# Charm
2+
*.charm
3+
14
# Spread
25
.spread*
6+
37
# Byte-compiled / optimized / DLL files
48
__pycache__/
59
*.py[cod]

charm/charm.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env python3
2+
# Copyright 2025 Skia
3+
# See LICENSE file for licensing details.
4+
5+
"""Charm the Error Tracker."""
6+
7+
import logging
8+
9+
import ops
10+
11+
from errortracker import ErrorTracker
12+
13+
logger = logging.getLogger(__name__)
14+
15+
16+
class ErrorTrackerCharm(ops.CharmBase):
17+
"""Charm the application."""
18+
19+
def __init__(self, *args):
20+
super().__init__(*args)
21+
self._error_tracker = ErrorTracker()
22+
23+
self.framework.observe(self.on.start, self._on_start)
24+
self.framework.observe(self.on.install, self._on_install)
25+
self.framework.observe(self.on.config_changed, self._on_config_changed)
26+
27+
def _on_start(self, event: ops.StartEvent):
28+
"""Handle start event."""
29+
self.unit.status = ops.ActiveStatus()
30+
31+
def _on_install(self, event: ops.InstallEvent):
32+
"""Handle install event."""
33+
self.unit.status = ops.MaintenanceStatus("Installing the error tracker")
34+
try:
35+
self._error_tracker.install()
36+
except Exception as e:
37+
logger.error("Failed to install the Error Tracker: %s", str(e))
38+
self.unit.status = ops.BlockedStatus("Failed installing the Error Tracker")
39+
return
40+
41+
self.unit.status = ops.ActiveStatus("Ready")
42+
43+
def _on_config_changed(self, event: ops.ConfigChangedEvent):
44+
enable_daisy = self.config.get("enable_daisy")
45+
enable_retracer = self.config.get("enable_retracer")
46+
enable_timers = self.config.get("enable_timers")
47+
enable_web = self.config.get("enable_web")
48+
49+
config = self.config.get("configuration")
50+
51+
self._error_tracker.configure(config)
52+
53+
# TODO: the charms know how to enable components, but not disable them.
54+
# This is a bit annoying, but also doesn't have a very big impact in
55+
# practice. This charm has no configuration where it's supposed to store
56+
# data, so it's always very easy to remove a unit and recreate.
57+
if enable_daisy:
58+
self._error_tracker.configure_daisy()
59+
self.unit.set_ports(self._error_tracker.daisy_port)
60+
if enable_retracer:
61+
self._error_tracker.configure_retracer(self.config.get("retracer_failed_queue"))
62+
if enable_timers:
63+
self._error_tracker.configure_timers()
64+
if enable_web:
65+
self._error_tracker.configure_web()
66+
67+
self.unit.set_workload_version(self._error_tracker.get_version())
68+
self.unit.status = ops.ActiveStatus("Ready")
69+
70+
71+
if __name__ == "__main__": # pragma: nocover
72+
ops.main(ErrorTrackerCharm) # type: ignore

0 commit comments

Comments
 (0)