grafana-cloud-integrator

Grafana Cloud Integrator

Channel Revision Published Runs on
2/candidate 55 08 Oct 2025
Ubuntu 24.04 Ubuntu 22.04
2/candidate 56 08 Oct 2025
Ubuntu 24.04 Ubuntu 22.04
2/edge 56 11 Jun 2025
Ubuntu 24.04 Ubuntu 22.04
2/edge 55 11 Jun 2025
Ubuntu 24.04 Ubuntu 22.04
1/stable 52 11 Jun 2025
Ubuntu 22.04 Ubuntu 20.04
1/stable 53 11 Jun 2025
Ubuntu 22.04 Ubuntu 20.04
1/candidate 53 11 Jun 2025
Ubuntu 22.04 Ubuntu 20.04
1/candidate 52 11 Jun 2025
Ubuntu 22.04 Ubuntu 20.04
1/beta 52 11 Jun 2025
Ubuntu 22.04 Ubuntu 20.04
1/beta 53 11 Jun 2025
Ubuntu 22.04 Ubuntu 20.04
1/edge 53 07 May 2025
Ubuntu 22.04 Ubuntu 20.04
1/edge 52 07 May 2025
Ubuntu 22.04 Ubuntu 20.04
juju deploy grafana-cloud-integrator --channel 1/stable
Show information

Platform:

Ubuntu
24.04 22.04 20.04

"""Grafana Cloud Integrator Configuration Requirer."""

from ops.framework import Object

LIBID = "2a48eccc49a346f08879b11ecab4465a"
LIBAPI = 0
LIBPATCH = 5

DEFAULT_RELATION_NAME = "grafana-cloud-config"


class Credentials:
    """Credentials for the remote endpoints."""

    def __init__(self, username, password):
        self.username = username
        self.password = password


class GrafanaCloudConfigProvider(Object):
    """Provider side of the Grafana Cloud Config relation."""

    def __init__(
        self,
        charm,
        credentials: Credentials,
        prometheus_url: str,
        loki_url: str,
        tempo_url: str,
        relation_name: str = DEFAULT_RELATION_NAME,
    ):
        super().__init__(charm, relation_name)
        self._charm = charm
        self._credentials = credentials
        self._prometheus_url = prometheus_url
        self._loki_url = loki_url
        self._tempo_url = tempo_url
        self._relation_name = relation_name

        relation_events = self._charm.on[relation_name]

        for event in [
            relation_events.relation_joined,
            relation_events.relation_created,
            relation_events.relation_changed,
            self._charm.on.config_changed,
        ]:
            self.framework.observe(
                event,
                self._on_relation_changed,
            )

    def _on_relation_changed(self, event):
        if not self._charm.unit.is_leader():
            return

        for relation in self._charm.model.relations[self._relation_name]:
            databag = relation.data[self._charm.app]

            # FIXME: this is always true
            if self._credentials:
                databag["username"] = self._credentials.username
                databag["password"] = self._credentials.password
            if self._loki_url:
                databag["loki_url"] = self._loki_url
            if self._tempo_url:
                databag["tempo_url"] = self._tempo_url
            if self._prometheus_url:
                databag["prometheus_url"] = self._prometheus_url
            databag["tls-ca"] = self._charm.config.get("tls-ca", "")