Charm lifecycle
This guide outlines how the Generic Exporter operator responds to core Juju events and manages the exporter snap throughout its lifecycle.
Install
On install:
- Validate that a usable configuration is present:
- A
snap-nameis provided, and - Either
snap-channelorsnap-revisionis set (but not both).
- A
- Initialize the snap manager using
SnapCache. - Install the exporter snap:
- Using the requested channel or revision.
- Respecting
snap-classicwhen classic confinement is required.
- Apply any JSON snap configuration from
snap-configusingsnap.set().
If configuration is missing or invalid (for example, snap-name not set), the charm sets:
BlockedStatus("Missing required configuration fields: snap-name")
and does not proceed with installation.
Config-changed
On config-changed:
- Re-validate the charm configuration:
- Reject cases where both
snap-channelandsnap-revisionare set simultaneously. - Parse
snap-configas JSON; if parsing fails, block with an appropriate message.
- Reject cases where both
- Reapply snap configuration:
- Call
snap.set()with the parsed configuration. - Call
snap.unset()if any configuration was unset. - On failure, stop the snap and set a
Blockedstatus.
- Call
- Reapply
snap-plugsby connecting the requested interfaces. - Detect a change in the exporter identity:
- If the configured exporter changes (for example,
snap-namechanged), uninstall the previous snap and clean up its alerts directory.
- If the configured exporter changes (for example,
- Reconcile alert rules:
- If an
alertsresource is present, re-read and rewrite rules to/run/<app-name>-<unit-id>/alerts.yaml.
- If an
- Notify COS integration:
- Update scrape configuration and alert rules via
COSAgentProvider, usingconfig-changedas a refresh event.
- Update scrape configuration and alert rules via
Update-status
On update-status, the charm performs a simple health check against the exporter’s HTTP endpoint:
- Issue a GET request to
http://localhost:<port>/<metrics-path>.- If the request fails or the endpoint is unreachable, set:
BlockedStatus("Metrics endpoint not reachable") - Ensure that the snap services are active.
- Check that the charm is related to Grafana Agent
- If the check fails, the charm sets:
BlockedStatus("Missing relation: [cos-agent]")
If every check passes, the charm enters Active state. This checks ensure that both the snap and its configuration are functioning as expected.
Remove
On remove:
- Stop and remove the exporter snap from the unit.
- Remove the alerts directory and any associated files.
- Allow Grafana Agent to reconcile the disappearance of the metrics endpoint and alerts via
metrics-endpointrelation updates.