diff --git a/lib/charms/grafana_agent/v0/cos_agent.py b/lib/charms/grafana_agent/v0/cos_agent.py index cc4da25..3aed66a 100644 --- a/lib/charms/grafana_agent/v0/cos_agent.py +++ b/lib/charms/grafana_agent/v0/cos_agent.py @@ -64,7 +64,8 @@ def __init__( - `dashboard_dirs`: List of directories where the dashboards are stored in the Charmed Operator. -- `refresh_events`: List of events on which to refresh relation data. +- `refresh_events`: List of events on which to refresh relation data. If no events is passed, the + relation data will be refreshed on config-changed and charm upgrade. - `tracing_protocols`: List of requested tracing protocols that the charm requires to send traces. @@ -175,7 +176,8 @@ def __init__(self, *args): `cos_agent` interface. The default value of this argument is "cos-agent". -- `refresh_events`: List of events on which to refresh relation data. +- `refresh_events`: List of events on which to refresh relation data. If no events is passed, the + relation data will be refreshed on config-changed and charm upgrade. ### Example 1 - Minimal instrumentation: @@ -653,7 +655,10 @@ def __init__( self._recursive = recurse_rules_dirs self._log_slots = log_slots or [] self._dashboard_dirs = dashboard_dirs - self._refresh_events = refresh_events or [self._charm.on.config_changed] + self._refresh_events = refresh_events or [ + self._charm.on.config_changed, + self._charm.on.upgrade_charm, + ] self._tracing_protocols = tracing_protocols self._is_single_endpoint = charm.meta.relations[relation_name].limit == 1 @@ -895,7 +900,10 @@ def __init__( self._charm = charm self._relation_name = relation_name self._peer_relation_name = peer_relation_name - self._refresh_events = refresh_events or [self._charm.on.config_changed] + self._refresh_events = refresh_events or [ + self._charm.on.config_changed, + self._charm.on.upgrade_charm, + ] events = self._charm.on[relation_name] self.framework.observe( diff --git a/tests/scenario/test_machine_charm/test_cos_agent_e2e.py b/tests/scenario/test_machine_charm/test_cos_agent_e2e.py index abf53fc..5dba3c2 100644 --- a/tests/scenario/test_machine_charm/test_cos_agent_e2e.py +++ b/tests/scenario/test_machine_charm/test_cos_agent_e2e.py @@ -53,9 +53,11 @@ def placeholder_cfg_path(tmp_path): @pytest.fixture(autouse=True) def patch_all(placeholder_cfg_path): - with patch("subprocess.run", MagicMock()), patch( - "grafana_agent.CONFIG_PATH", placeholder_cfg_path - ), patch("socket.getfqdn", return_value="localhost"): + with ( + patch("subprocess.run", MagicMock()), + patch("grafana_agent.CONFIG_PATH", placeholder_cfg_path), + patch("socket.getfqdn", return_value="localhost"), + ): yield diff --git a/tests/scenario/test_machine_charm/test_scrape_configs.py b/tests/scenario/test_machine_charm/test_scrape_configs.py index 075ab64..6529224 100644 --- a/tests/scenario/test_machine_charm/test_scrape_configs.py +++ b/tests/scenario/test_machine_charm/test_scrape_configs.py @@ -65,9 +65,11 @@ def mock_write(_, path, text): my_uuid = str(uuid.uuid4()) - with patch("charms.operator_libs_linux.v2.snap.SnapCache"), patch( - "charm.GrafanaAgentMachineCharm.write_file", new=mock_write - ), patch("charm.GrafanaAgentMachineCharm.is_ready", return_value=True): + with ( + patch("charms.operator_libs_linux.v2.snap.SnapCache"), + patch("charm.GrafanaAgentMachineCharm.write_file", new=mock_write), + patch("charm.GrafanaAgentMachineCharm.is_ready", return_value=True), + ): state = State( relations=[cos_relation, loki_relation, PeerRelation("peers")], model=Model(name="my-model", uuid=my_uuid), diff --git a/tests/scenario/test_start_statuses.py b/tests/scenario/test_start_statuses.py index c3235aa..f7fdc66 100644 --- a/tests/scenario/test_start_statuses.py +++ b/tests/scenario/test_start_statuses.py @@ -31,8 +31,9 @@ def _subp_run_mock(*a, **kw): @pytest.fixture(autouse=True) def patch_all(placeholder_cfg_path): - with patch("subprocess.run", _subp_run_mock), patch( - "grafana_agent.CONFIG_PATH", placeholder_cfg_path + with ( + patch("subprocess.run", _subp_run_mock), + patch("grafana_agent.CONFIG_PATH", placeholder_cfg_path), ): yield