canonical / jhack

Chock-full of Juju hackery.
Apache License 2.0
51 stars 24 forks source link

`jhack utils show-relation` shows an Exception #66

Closed Abuelodelanada closed 1 year ago

Abuelodelanada commented 1 year ago

In a lxd controller I have 2 charms running:

╭─ubuntu@charm-dev-juju-29 ~ 
╰─$ juju status --color --relations                           
Model         Controller  Cloud/Region         Version  SLA          Timestamp
applications  lxd         localhost/localhost  2.9.38   unsupported  18:43:17-03:00

SAAS                             Status  Store                URL
loki-logging                     active  charm-dev-batteries  admin/cos.loki-logging
prometheus-receive-remote-write  active  charm-dev-batteries  admin/cos.prometheus-receive-remote-write

App            Version  Status  Scale  Charm          Channel  Rev  Exposed  Message
grafana-agent           active      1  grafana-agent             0  no       
zookeeper               active      1  zookeeper                 0  no       

Unit                Workload  Agent  Machine  Public address  Ports  Message
zookeeper/0*        active    idle   0        10.77.61.148           
  grafana-agent/0*  active    idle            10.77.61.148           

Machine  State    Address       Inst id        Series  AZ  Message
0        started  10.77.61.148  juju-a8713e-0  jammy       Running

Offer          Application    Charm          Rev  Connected  Endpoint                     Interface          Role
grafana-agent  grafana-agent  grafana-agent  0    0/0        grafana-dashboards-provider  grafana_dashboard  provider

Relation provider                                     Requirer                         Interface                Type         Message
loki-logging:logging                                  grafana-agent:logging-consumer   loki_push_api            regular      
prometheus-receive-remote-write:receive-remote-write  grafana-agent:send-remote-write  prometheus_remote_write  regular      
zookeeper:cluster                                     zookeeper:cluster                cluster                  peer         
zookeeper:cos-agent                                   grafana-agent:cos-agent          cos_agent                subordinate  
zookeeper:restart                                     zookeeper:restart                rolling_op               peer  

grafana-agent charm is a subordinate charm.

And when I execute:

jhack utils show-relation zookeeper:cos-agent grafana-agent

I obtain this error:

╭─ubuntu@charm-dev-juju-29 ~/repos/zookeeper-operator ‹cos-machine●› 
╰─$ jhack utils show-relation zookeeper:cos-agent grafana-agent                                                                          1 ↵
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /snap/jhack/201/lib/python3.8/site-packages/jhack/utils/show_relation.py:249 in get_content      │
│                                                                                                  │
│   246 │   """Get the content of the databag of `obj`, as seen from `other_obj`."""               │
│   247 │   try:                                                                                   │
│   248 │   │   this_url, this_endpoint = obj.split(":")                                           │
│ ❱ 249 │   │   other_url, other_endpoint = other_obj.split(":")                                   │
│   250 │   except ValueError:                                                                     │
│   251 │   │   raise ValueError(                                                                  │
│   252 │   │   │   "Relation endpoints need to be formatted as 'app_name:endpoint_name', "        │
│                                                                                                  │
│ ╭─────────────────────────── locals ────────────────────────────╮                                │
│ │ include_default_juju_keys = False                             │                                │
│ │                     model = None                              │                                │
│ │                       obj = 'zookeeper:cos-agent'             │                                │
│ │                 other_obj = 'grafana-agent'                   │                                │
│ │             relation_type = <RelationType.regular: 'regular'> │                                │
│ │             this_endpoint = 'cos-agent'                       │                                │
│ │                  this_url = 'zookeeper'                       │                                │
│ ╰───────────────────────────────────────────────────────────────╯                                │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
ValueError: not enough values to unpack (expected 2, got 1)

During handling of the above exception, another exception occurred:

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /snap/jhack/201/lib/python3.8/site-packages/jhack/utils/show_relation.py:652 in                  │
│ sync_show_relation                                                                               │
│                                                                                                  │
│   649 │                                                                                          │
│   650 │   $ jhack utils show-relation my_app:relation_name other_app:other_name                  │
│   651 │   """                                                                                    │
│ ❱ 652 │   return _sync_show_relation(                                                            │
│   653 │   │   endpoint1=endpoint1,                                                               │
│   654 │   │   endpoint2=endpoint2,                                                               │
│   655 │   │   n=n,                                                                               │
│                                                                                                  │
│ ╭────────────────── locals ───────────────────╮                                                  │
│ │               color = 'auto'                │                                                  │
│ │           endpoint1 = 'zookeeper:cos-agent' │                                                  │
│ │           endpoint2 = 'grafana-agent'       │                                                  │
│ │ hide_empty_databags = False                 │                                                  │
│ │               model = None                  │                                                  │
│ │                   n = None                  │                                                  │
│ │      show_juju_keys = False                 │                                                  │
│ │               watch = False                 │                                                  │
│ ╰─────────────────────────────────────────────╯                                                  │
│                                                                                                  │
│ /snap/jhack/201/lib/python3.8/site-packages/jhack/utils/show_relation.py:689 in                  │
│ _sync_show_relation                                                                              │
│                                                                                                  │
│   686 │   while True:                                                                            │
│   687 │   │   start = time.time()                                                                │
│   688 │   │                                                                                      │
│ ❱ 689 │   │   table = asyncio.run(                                                               │
│   690 │   │   │   render_relation(                                                               │
│   691 │   │   │   │   endpoint1,                                                                 │
│   692 │   │   │   │   endpoint2,                                                                 │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │               color = 'auto'                                                                 │ │
│ │             Console = <class 'rich.console.Console'>                                         │ │
│ │             console = <console width=141 ColorSystem.EIGHT_BIT>                              │ │
│ │           endpoint1 = 'zookeeper:cos-agent'                                                  │ │
│ │           endpoint2 = 'grafana-agent'                                                        │ │
│ │ hide_empty_databags = False                                                                  │ │
│ │               model = None                                                                   │ │
│ │                   n = None                                                                   │ │
│ │                rich = <module 'rich' from                                                    │ │
│ │                       '/snap/jhack/201/lib/python3.8/site-packages/rich/__init__.py'>        │ │
│ │      show_juju_keys = False                                                                  │ │
│ │               start = 1678830314.8960829                                                     │ │
│ │               watch = False                                                                  │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                  │
│ /usr/lib/python3.8/asyncio/runners.py:44 in run                                                  │
│                                                                                                  │
│   41 │   │   events.set_event_loop(loop)                                                         │
│   42 │   │   if debug is not None:                                                               │
│   43 │   │   │   loop.set_debug(debug)                                                           │
│ ❱ 44 │   │   return loop.run_until_complete(main)                                                │
│   45 │   finally:                                                                                │
│   46 │   │   try:                                                                                │
│   47 │   │   │   _cancel_all_tasks(loop)                                                         │
│                                                                                                  │
│ ╭──────────────────────────────── locals ────────────────────────────────╮                       │
│ │ debug = None                                                           │                       │
│ │  loop = <_UnixSelectorEventLoop running=False closed=True debug=False> │                       │
│ │  main = <coroutine object render_relation at 0x7ff5cf652f40>           │                       │
│ ╰────────────────────────────────────────────────────────────────────────╯                       │
│                                                                                                  │
│ /usr/lib/python3.8/asyncio/base_events.py:616 in run_until_complete                              │
│                                                                                                  │
│    613 │   │   if not future.done():                                                             │
│    614 │   │   │   raise RuntimeError('Event loop stopped before Future completed.')             │
│    615 │   │                                                                                     │
│ ❱  616 │   │   return future.result()                                                            │
│    617 │                                                                                         │
│    618 │   def stop(self):                                                                       │
│    619 │   │   """Stop running the event loop.                                                   │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │   future = <Task finished name='Task-1' coro=<render_relation() done, defined at             │ │
│ │            /snap/jhack/201/lib/python3.8/site-packages/jhack/utils/show_relation.py:474>     │ │
│ │            exception=ValueError("Relation endpoints need to be formatted as                  │ │
│ │            'app_name:endpoint_name', e.g. 'traefik:ingress'. Not: 'zookeeper:cos-agent',     │ │
│ │            'grafana-agent'")>                                                                │ │
│ │ new_task = True                                                                              │ │
│ │     self = <_UnixSelectorEventLoop running=False closed=True debug=False>                    │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                  │
│ /snap/jhack/201/lib/python3.8/site-packages/jhack/utils/show_relation.py:534 in render_relation  │
│                                                                                                  │
│   531 │   │   if not (endpoint1 and endpoint2):                                                  │
│   532 │   │   │   raise RuntimeError("invalid usage: provide two endpoints.")                    │
│   533 │   │                                                                                      │
│ ❱ 534 │   │   data = get_relation_data(                                                          │
│   535 │   │   │   provider_endpoint=endpoint1,                                                   │
│   536 │   │   │   requirer_endpoint=endpoint2,                                                   │
│   537 │   │   │   include_default_juju_keys=include_default_juju_keys,                           │
│                                                                                                  │
│ ╭───────────────────── locals ──────────────────────╮                                            │
│ │                 endpoint1 = 'zookeeper:cos-agent' │                                            │
│ │                 endpoint2 = 'grafana-agent'       │                                            │
│ │       hide_empty_databags = False                 │                                            │
│ │ include_default_juju_keys = False                 │                                            │
│ │                     model = None                  │                                            │
│ │                         n = None                  │                                            │
│ │             relation_type = None                  │                                            │
│ ╰───────────────────────────────────────────────────╯                                            │
│                                                                                                  │
│ /snap/jhack/201/lib/python3.8/site-packages/jhack/utils/show_relation.py:399 in                  │
│ get_relation_data                                                                                │
│                                                                                                  │
│   396 │                                                                                          │
│   397 │   >>> get_relation_data('prometheus/0:ingress', 'traefik/1:ingress-per-unit')            │
│   398 │   """                                                                                    │
│ ❱ 399 │   provider_data = get_content(                                                           │
│   400 │   │   provider_endpoint, requirer_endpoint, include_default_juju_keys, model=model       │
│   401 │   )                                                                                      │
│   402 │   requirer_data = get_content(                                                           │
│                                                                                                  │
│ ╭───────────────────── locals ──────────────────────╮                                            │
│ │ include_default_juju_keys = False                 │                                            │
│ │                     model = None                  │                                            │
│ │         provider_endpoint = 'zookeeper:cos-agent' │                                            │
│ │         requirer_endpoint = 'grafana-agent'       │                                            │
│ ╰───────────────────────────────────────────────────╯                                            │
│                                                                                                  │
│ /snap/jhack/201/lib/python3.8/site-packages/jhack/utils/show_relation.py:251 in get_content      │
│                                                                                                  │
│   248 │   │   this_url, this_endpoint = obj.split(":")                                           │
│   249 │   │   other_url, other_endpoint = other_obj.split(":")                                   │
│   250 │   except ValueError:                                                                     │
│ ❱ 251 │   │   raise ValueError(                                                                  │
│   252 │   │   │   "Relation endpoints need to be formatted as 'app_name:endpoint_name', "        │
│   253 │   │   │   f"e.g. 'traefik:ingress'. Not: {obj!r}, {other_obj!r}"                         │
│   254 │   │   )                                                                                  │
│                                                                                                  │
│ ╭─────────────────────────── locals ────────────────────────────╮                                │
│ │ include_default_juju_keys = False                             │                                │
│ │                     model = None                              │                                │
│ │                       obj = 'zookeeper:cos-agent'             │                                │
│ │                 other_obj = 'grafana-agent'                   │                                │
│ │             relation_type = <RelationType.regular: 'regular'> │                                │
│ │             this_endpoint = 'cos-agent'                       │                                │
│ │                  this_url = 'zookeeper'                       │                                │
│ ╰───────────────────────────────────────────────────────────────╯                                │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
ValueError: Relation endpoints need to be formatted as 'app_name:endpoint_name', e.g. 'traefik:ingress'. Not: 'zookeeper:cos-agent', 
'grafana-agent'

I'm using 0.3.14

PietroPasotti commented 1 year ago

The traceback says it all: show-relation can't determine based on the first endpoint alone that the second endpoint is the same. You should do:

jhack utils show-relation zookeeper:cos-agent grafana-agent:cos-agent

PietroPasotti commented 1 year ago

arguably jhack show-relation could be made smarter and infer that given that there's only one endpoint on grafana-agent related to zookeeper:cos-agent, that's the one you mean. That's a good feature request :)

Abuelodelanada commented 1 year ago

Yes, I opened this issue because a command with wrong arguments shows an exception instead of an error message