Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add upgrade charm on refresh_events to COSAgent #151

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions lib/charms/grafana_agent/v0/cos_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand Down
8 changes: 5 additions & 3 deletions tests/scenario/test_machine_charm/test_cos_agent_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
8 changes: 5 additions & 3 deletions tests/scenario/test_machine_charm/test_scrape_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
5 changes: 3 additions & 2 deletions tests/scenario/test_start_statuses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading