canonical / grafana-agent-k8s-operator

https://charmhub.io/grafana-agent-k8s
Apache License 2.0
8 stars 18 forks source link

Hook "juju-info-relation-joined" crashes on "ValueError: invalid literal for int() with base 10: 'x1'" #233

Closed przemeklal closed 1 year ago

przemeklal commented 1 year ago

Bug Description

Hook "juju-info-relation-joined" crashes on "ValueError: invalid literal for int() with base 10: 'x1'".

Such snap versions may show up on the system if they were installed from local versions, e.g. snaps attached as juju resources. In my case it happened with openstack-service-checks:

$ juju resources openstack-service-checks
Resource  Supplied by  Revision
core18    charmstore   1
fcbtest   charmstore   0
snapd     charmstore   0

Which on the unit results in:

# snap list
Name     Version        Rev    Tracking       Publisher   Notes
core18   20211215       x2     latest/stable  -           base
core20   20230622       1974   latest/stable  canonical✓  base
core22   20230725       858    latest/stable  canonical✓  base
fcbtest  2              x1     latest/stable  -           -
lxd      4.0.9-a29c6f1  24061  4.0/stable/…   canonical✓  -
snapd    2.51.1         x2     latest/stable  -           snapd

This eventually breaks the grafana-agent charm (logs below). I believe the fact that such versions show up in the snap list should not cause grafana-agent charm to crash.

To Reproduce

  1. On any unit install any snap that has x1/x2 version from this list:
    root@juju-0fc37b-20-lxd-14:~# snap list
    Name     Version        Rev    Tracking       Publisher   Notes
    core18   20211215       x2     latest/stable  -           base
    core20   20230622       1974   latest/stable  canonical✓  base
    core22   20230725       858    latest/stable  canonical✓  base
    fcbtest  2              x1     latest/stable  -           -
    lxd      4.0.9-a29c6f1  24061  4.0/stable/…   canonical✓  -
    snapd    2.51.1         x2     latest/stable  -           snapd
  2. Deploy grafana-agent to the same unit.

Environment

grafana-agent: candidate, rev 9 snap list posted above OS: focal

Relevant log output

unit-grafana-agent-84: 10:15:22 ERROR unit.grafana-agent/84.juju-log juju-info:604: Uncaught exception while in charm code:
Traceback (most recent call last):
  File "./src/charm.py", line 495, in <module>
    main(GrafanaAgentMachineCharm)
  File "/var/lib/juju/agents/unit-grafana-agent-84/charm/venv/ops/main.py", line 429, in main
    charm = charm_class(framework)
  File "./src/charm.py", line 166, in __init__
    self.snap = snap.SnapCache()["grafana-agent"]
  File "/var/lib/juju/agents/unit-grafana-agent-84/charm/lib/charms/operator_libs_linux/v1/snap.py", line 774, in __init__
    self._load_installed_snaps()
  File "/var/lib/juju/agents/unit-grafana-agent-84/charm/lib/charms/operator_libs_linux/v1/snap.py", line 831, in _load_installed_snaps
    revision=int(i["revision"]),
ValueError: invalid literal for int() with base 10: 'x2'


### Additional context

_No response_
lucabello commented 1 year ago

This bug seems to be fixed already, but it looks like the changes are only in edge :)

Could you try deploying from edge and see if the error's still there?

przemeklal commented 1 year ago

I can confirm that upgrading the charm to the edge channel resolved the issue (rev 12). I believe this one can be closed. Thanks for the support!