Skip to content

feat(profile): wire COS observability into kubernetes and machine scaffolds - #5

Open
tonyandrewmeyer wants to merge 65 commits into
mainfrom
claude/profile-observability
Open

feat(profile): wire COS observability into kubernetes and machine scaffolds#5
tonyandrewmeyer wants to merge 65 commits into
mainfrom
claude/profile-observability

Conversation

@tonyandrewmeyer

Copy link
Copy Markdown
Owner

What this does

Extends both the kubernetes and machine profiles so that charmcraft init
produces a charm pre-wired for Canonical Observability Stack (COS) integration.
Each profile is independent; six logical commits cover the work.


Kubernetes profile (--profile=kubernetes)

Charm-libs declared in charmcraft.yaml (run charmcraft fetch-libs after init):

  • prometheus_k8s.prometheus_scrape v0
  • loki_k8s.loki_push v1
  • grafana_k8s.grafana_dashboard v0

Relations added to charmcraft.yaml:

provides:
  metrics-endpoint:
    interface: prometheus_scrape
  grafana-dashboard:
    interface: grafana_dashboard
requires:
  logging:
    interface: loki_push

src/charm.py — three providers instantiated in __init__:

self._metrics_endpoint = MetricsEndpointProvider(
    self, jobs=[{"static_configs": [{"targets": ["*:8080"]}]}]
)
self._log_forwarder = LogForwarder(self)
self._grafana_dashboard = GrafanaDashboardProvider(self)

src/grafana_dashboards/overview.json — starter dashboard with:

  • up stat panel (prometheus scrape health) driven by $juju_application
  • markdown panel with getting-started guidance

Unit tests (ops.testing.Context):

  • test_metrics_endpoint_relation_joined — verifies scrape_jobs with port 8080 is written to app data
  • test_grafana_dashboard_relation_joined — verifies dashboards key is populated in app data
  • test_logging_relation_joined — verifies LogForwarder handles the requirer-side event without error

Integration tests: skipped stubs showing the jubilant + COS pattern for each relation.


Machine profile (--profile=machine)

Charm-lib declared in charmcraft.yaml:

  • cos_agent.cos_agent v0

Relation added:

provides:
  cos-agent:
    interface: cos_agent

src/charm.py — single provider that bundles metrics, logs, and dashboards:

self._cos_agent = COSAgentProvider(
    self,
    metrics_endpoints=[{"path": "/metrics", "port": 8080}],
    dashboard_dirs=["./src/grafana_dashboards"],
)

src/grafana_dashboards/overview.json — identical structure to the kubernetes starter dashboard (grafana-agent picks this up via the cos-agent relation and ships it to Grafana).

Unit tests (ops.testing.Context):

  • test_cos_agent_relation_joined — verifies config key with metrics_scrape_jobs is written to unit data
  • test_cos_agent_relation_joined_dashboard_registered — verifies dashboards are included in config

Integration tests: skipped stubs covering the grafana-agent co-deployment pattern.


How to activate (post-init)

charmcraft init --profile=kubernetes  # or --profile=machine
charmcraft fetch-libs                  # downloads the charm-libs into lib/
# inspect PYDEPS in each fetched lib, add any extras to pyproject.toml dependencies
tox -e unit                            # unit tests pass once libs are fetched

To activate COS monitoring after deploying:

Kubernetes:

juju integrate <app>:metrics-endpoint prometheus-k8s:metrics-endpoint
juju integrate <app>:grafana-dashboard grafana-k8s:grafana-dashboard
juju integrate <app>:logging loki-k8s:logging

Machine:

juju deploy grafana-agent
juju integrate <app>:cos-agent grafana-agent:cos-agent
# then cross-model relations to COS lite

COS integration test limitation

Full COS integration tests (marked @pytest.mark.skip) require a live COS lite
stack and (for machine) the grafana-agent machine charm. These are documented
in-template with setup instructions. The skipped stubs show the expected jubilant
pattern; developers can enable them once their environment has COS deployed.

Out of scope

  • Tracing (separate routine; quick to add via opentelemetry_sdk lib but not included here)
  • Alert rules directories (prometheus_alert_rules/, loki_alert_rules/) — developers add these as needed
  • 12-factor profiles and test-* overlays

Generated by Claude Code

bepri and others added 3 commits May 7, 2026 11:02
Add the common remote build how-to and reference pages.

---------

Signed-off-by: JJ Coldiron <jj.coldiron@canonical.com>
…l#2705)

The `pack --help` overview instructed users to ensure a valid
`metadata.yaml` exists. That is the legacy split-file format; modern
(4.x) charms put metadata inline in `charmcraft.yaml`, so the stale
guidance sent readers looking for a file that should not exist.

---------

Signed-off-by: Tony Meyer <tony.meyer@gmail.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
lengau and others added 26 commits June 22, 2026 09:58
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
This adds release notes for Charmcraft 4.3 so we can tag 4.3.0.

This also creates (and excludes) blank release notes for Charmcraft 4.4.

Requires canonical#2727
…ical#2691)

Warns about the deprecation of charmhub-hosted charmlibs in all charmlibs-related commands.

---------

Signed-off-by: Alex Lowe <alex.lowe@canonical.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: James Garner <james.garner@canonical.com>
Co-authored-by: Imani Pelton <imani.pelton@canonical.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
…cal#2743)

* docs: add Canonical K8s instructions to web app charm how-tos

Migrate the MicroK8s-only steps in the manage-web-app-charms how-to guides
to also cover Canonical K8s, matching the tabbed pattern used in the
"Use a database with your 12-factor app charm" guide.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix link

* Update docs/howto/manage-web-app-charms/use-web-app-charm.rst

Co-authored-by: Ali UĞUR <39213991+alithethird@users.noreply.github.com>
Signed-off-by: florentianayuwono <76247368+florentianayuwono@users.noreply.github.com>

---------

Signed-off-by: florentianayuwono <76247368+florentianayuwono@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Ali UĞUR <39213991+alithethird@users.noreply.github.com>
…ical#2721)

* build(deps): update dependency django to v5.2.15

* docs: update django tutorial with version

* docs: one way to sync the docs and code

* fix: trailing whitespace

* docs: script in conf.py to extract django version

* docs: make linter happy

* fix(docs): revert phrasing change in tutorial

* fix: update install spread step of spread-docs.yaml

* chore(copilot): add 24.04 base support to Django framework

* fix: workflow path in spread-docs.yaml

* chore(copilot): add 24.04 base support to Flask framework

* fix: name of charms in task.yaml

* fix: CHARMCRAFTCRAFT

* fix: name of charms in task.yaml

* chore: revert all spread test changes

* chore: reorder the imports in conf.py

* docs: update name of django version global var

* chore: incorporate feedback from @medubelko

* chore: update placeholder to something less concerning

* chore: convert code snippet to function

* chore(docs): update spread test and docs for updatelogfile action howto

* fix(docs): revert spread test changes

* chore(docs): update flask and fastapi versions

* docs: small refactoring

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Michael DuBelko <michael.dubelko@canonical.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
The 12-factor tooling accepts a configuration file `paas-config.yaml` that is read by the
`paas-charm` library. See https://canonical-12-factor-app-support.readthedocs-hosted.com/latest/reference/paas-config/

This file is written in `yaml` format, and currently it contains functionality about Prometheus scraping configuration and [logging formatting in the frameworks](https://canonical-12-factor-app-support.readthedocs-hosted.com/latest/reference/paas-config-structured-logging/).

If the file is not correct, because it is not valid `yaml` or because the keys/values are wrong, the application will get into error state, as it is invalid and the file has to be fixed and the charm packed again.

To improve the feedback loop, this PR will make the `charmcraft pack` fail if the `paas-config.yaml` is not correct `yaml`. It will also fail if the `framework_logging_format` is set to `json` for any of the frameworks where it is not supported (only Gunicorn and Uvicorn based frameworks support this option, as the other frameworks can be easily configured in the charmed application).
* build(deps): update dependency django to v5.2.15

* docs: update django tutorial with version

* docs: one way to sync the docs and code

* fix: trailing whitespace

* docs: script in conf.py to extract django version

* docs: make linter happy

* fix(docs): revert phrasing change in tutorial

* fix: update install spread step of spread-docs.yaml

* chore(copilot): add 24.04 base support to Django framework

* fix: workflow path in spread-docs.yaml

* chore(copilot): add 24.04 base support to Flask framework

* fix: name of charms in task.yaml

* fix: CHARMCRAFTCRAFT

* fix: name of charms in task.yaml

* chore(docs): remove auto-sync aspects

* chore: revert auto-sync feature

* fix: charm name in custom-action-updatelogfile/task.yaml

* chore(docs): update spread test for updatelogfile action

* chore(docs): update spread test and howto for updatelogfile

* chore(docs): update spread test and howto for updatelogfile

* fix: name of charm in updatelogfile test

* chore: revert changes to charmcraft/extensions/app.py

* chore: revert the newline change too

---------

Signed-off-by: Alex Lowe <alex.lowe@canonical.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Alex Lowe <alex.lowe@canonical.com>
canonical#2712)

---------

Signed-off-by: Tony Meyer <tony.meyer@gmail.com>
Co-authored-by: Michael DuBelko <michael.dubelko@canonical.com>
Co-authored-by: Michael DuBelko <michael.dubelko@gmail.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
…onical#2748)

---------

Signed-off-by: Michael DuBelko <michael.dubelko@gmail.com>
Co-authored-by: Michael DuBelko <michael.dubelko@gmail.com>
…nical#2764)

Updates craft-providers to >=3.7.1 to resolve Ubuntu 25.10 spread test failures.

Signed-off-by: Alex Lowe <alex.lowe@canonical.com>
The bug was in craft-parts so I've updated the patch release in uv.lock.

---------

Signed-off-by: Alex Lowe <alex.lowe@canonical.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
javierdelapuente and others added 29 commits July 14, 2026 11:45
Use microk8s 1.34-strict/stable instead 1.31-strict/stable.

Microk8s 1.31 is EOL, and it does not work correctly in Ubuntu 26.04.
…al#2718)

Promotes Python warnings to errors in `tox -e unit` for both the
machine and kubernetes init profiles so charmers catch deprecated-API
and resource-cleanup bugs before they bite in production.

Validated by an internal Charm Tech baseline (clean after
operator#2506/canonical#2507/canonical#2509 land) and a 145-charm downstream baseline
(~40% projected pass rate post-operator-fix; residual clusters are all
filterable per-repo). Gate PRs merged 2026-06-02; see
canonical-work-queue roadmap/26.10/w-error/DECISION.md.

* docs: add 4.3 release notes entry for unit-profile warnings-as-errors

* docs: Apply suggestion from @tonyandrewmeyer

Signed-off-by: Tony Meyer <tony.meyer@gmail.com>

* docs: Update docs/release-notes/charmcraft-4.3.rst

Co-authored-by: JJ Coldiron <jj.coldiron@canonical.com>
Signed-off-by: Tony Meyer <tony.meyer@gmail.com>

* docs: Update docs/release-notes/charmcraft-4.3.rst

Co-authored-by: JJ Coldiron <jj.coldiron@canonical.com>
Signed-off-by: Tony Meyer <tony.meyer@gmail.com>

---------

Signed-off-by: Tony Meyer <tony.meyer@gmail.com>
Co-authored-by: JJ Coldiron <jj.coldiron@canonical.com>
Co-authored-by: Michael DuBelko <michael.dubelko@canonical.com>
Replaces canonical#2765 with the same fix pattern as starbase canonical#573.

---------

Signed-off-by: Alex Lowe <alex.lowe@canonical.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Set Renovate ignorePaths to docs/** so dependency updates under docs are not proposed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…2769)

Co-authored-by: Alex Lowe <alex.lowe@canonical.com>
Replicate canonical/snapcraft#6352.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Switches from candid to Ubuntu One for authentication.

(CHARMCRAFT-667)
Signed-off-by: JJ Coldiron <jj.coldiron@canonical.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
…nical#2786)

The README's "Weekly Spread" badge and link pointed to .github/workflows/spread-large.yaml, which no longer exists in the repository.

Fixes canonical#2755

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
---------

Signed-off-by: Alex Lowe <alex.lowe@canonical.com>
Co-authored-by: Sam Kosh <samkosh@Sams-MacBook-Pro.local>
Co-authored-by: Alex Lowe <alex.lowe@canonical.com>
Co-authored-by: Michael DuBelko <michael.dubelko@gmail.com>
* Feat: extension dispatch for 12-factor extensions.

* chore: cleanup

* chore: addback the resolute invalid

* chore: revert fmt

* chore: create get_project_bases back

* chore: cleanup

* chore: Bring back old init templates and version the new ones

* chore: set 26.04 and 26.10 as experimental for charm plugin

* chore: apply comments

* chore: use pascalcase for class

* chore: doc links

* chore: apply comments

* fix: experimental

* fix: default to v2 and rename v1 frameworks

* docs: Update docs for v2 12-factor extensions.

* docs: add linting and testing dependencies to project templates

* fix(templates): organize imports in new templates

* fix(tox): enable tests path in tox.ini templates for various frameworks

* fix(docs): standardize tab indentation for Kubernetes log commands in use-web-app-charm.rst

* fix(docs): correct indentation and formatting in manage-extensions.rst

* fix(docs): update paas-charm library version information and standardize container names in logs

* Apply suggestions from code review

Co-authored-by: Erin Conley <erin.conley@canonical.com>
Signed-off-by: Ali UĞUR <39213991+alithethird@users.noreply.github.com>

* docs: update extension management guidance for Ubuntu versions

* docs: remove outdated extension behavior notes for Ubuntu versions

* docs: improve formatting and consistency in manage-extensions guide

* retrigger CI

---------

Signed-off-by: Ali UĞUR <39213991+alithethird@users.noreply.github.com>
Co-authored-by: David Wilding <david.wilding@canonical.com>
Co-authored-by: Erin Conley <erin.conley@canonical.com>
Co-authored-by: Michael DuBelko <michael.dubelko@canonical.com>
Switches spread backend from google to openstack
The captions for settings.py and the project urls.py were missing the
inner django_hello_world package directory that django-admin
startproject creates. Correct them to match the actual layout used by
the tutorial's task.yaml spread test.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…boards

Add MetricsEndpointProvider, LogForwarder, and GrafanaDashboardProvider to
the kubernetes profile scaffold so that `charmcraft init --profile=kubernetes`
produces a charm pre-wired for Canonical Observability Stack integration.

- charmcraft.yaml: declare charm-libs (prometheus_scrape v0, loki_push v1,
  grafana_dashboard v0), provides: metrics-endpoint + grafana-dashboard,
  requires: logging
- src/charm.py: import and instantiate all three providers in __init__
  with comments pointing developers to the scrape port and fetch-libs step
Add src/grafana_dashboards/overview.json.j2 to the kubernetes profile.
GrafanaDashboardProvider discovers and ships JSON files from this
directory automatically via the grafana-dashboard relation.

The starter dashboard includes an 'up' stat panel (Prometheus scrape
health) and a markdown panel with getting-started guidance.
Unit tests (ops.testing.Context):
- test_metrics_endpoint_relation_joined: verifies MetricsEndpointProvider
  writes scrape_jobs (port 8080) into app relation data on relation-joined
- test_grafana_dashboard_relation_joined: verifies GrafanaDashboardProvider
  writes dashboard data into app relation data
- test_logging_relation_joined: verifies LogForwarder handles relation-joined
  without error on the requirer side

Integration tests (jubilant, @pytest.mark.skip):
- Skipped stubs for metrics collection, dashboard registration, and log
  forwarding that show the jubilant + COS integration pattern; include
  instructions for enabling against a real COS lite stack.
Add COSAgentProvider to the machine profile scaffold so that
`charmcraft init --profile=machine` produces a charm pre-wired for
Canonical Observability Stack integration via the grafana-agent machine charm.

COSAgentProvider bundles metrics scraping, log forwarding, and dashboard
distribution through a single 'cos-agent' relation to grafana-agent.

- charmcraft.yaml: declare cos_agent charm-lib v0, provides: cos-agent
- src/charm.py: import and instantiate COSAgentProvider with a configured
  metrics endpoint (port 8080) and dashboard directory
Add src/grafana_dashboards/overview.json.j2 to the machine profile.
COSAgentProvider reads JSON files from this directory and ships them
to Grafana via grafana-agent and the COS stack.

Mirrors the kubernetes profile dashboard structure and guidance.
Unit tests (ops.testing.Context):
- test_cos_agent_relation_joined: verifies COSAgentProvider writes 'config'
  into unit relation data, and that metrics_scrape_jobs contains the
  port-8080 endpoint declared in charm.__init__
- test_cos_agent_relation_joined_dashboard_registered: verifies the
  dashboard directory is included in the COS agent config

Integration tests (jubilant, @pytest.mark.skip):
- Skipped stubs for cos-agent relation and metrics scraping; include
  comments explaining how to enable against a real grafana-agent + COS stack.
The observability profile adds src/grafana_dashboards/overview.json to both
the kubernetes and machine scaffolds, so BASIC_INIT_FILES has to list it.
@tonyandrewmeyer
tonyandrewmeyer force-pushed the claude/profile-observability branch from 8da1e5c to abeb07a Compare July 27, 2026 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.