Scope and reactive interface relations

Hello,

I get a hook error from the grafana charm when trying to create a relation from an operator charm.

nit-grafana-4: 18:04:03 ERROR unit.grafana/4.juju-log grafana-source:233: Hook error:
Traceback (most recent call last):
  File "/var/lib/juju/agents/unit-grafana-4/.venv/lib/python3.6/site-packages/charms/reactive/__init__.py", line 74, in main
    bus.dispatch(restricted=restricted_mode)
  File "/var/lib/juju/agents/unit-grafana-4/.venv/lib/python3.6/site-packages/charms/reactive/bus.py", line 379, in dispatch
    _invoke(hook_handlers)
  File "/var/lib/juju/agents/unit-grafana-4/.venv/lib/python3.6/site-packages/charms/reactive/bus.py", line 359, in _invoke
    handler.invoke()
  File "/var/lib/juju/agents/unit-grafana-4/.venv/lib/python3.6/site-packages/charms/reactive/bus.py", line 181, in invoke
    self._action(*args)
  File "/var/lib/juju/agents/unit-grafana-4/charm/hooks/relations/grafana-source/requires.py", line 11, in changed
    conv = self.conversation()
  File "/var/lib/juju/agents/unit-grafana-4/.venv/lib/python3.6/site-packages/charms/reactive/relations.py", line 431, in conversation
    raise ValueError('Unable to determine default scope: no current hook or global scope')
ValueError: Unable to determine default scope: no current hook or global scope

The grafana charm (a reactive charm) defines the requiring side of the grafana-source relation, while my charm (an operator charm) defines the provides side.

The requires side of the relation looks into the conversation to get and split the scope.

        for conv in self.conversations():
            ds = {'service_name': conv.scope.split('/')[0],

I think there is an issue somewhere in that the relating charm is not using the reactive framework and won’t have a conversation or conversation scope. I think there may be an issue with the reactive/conversation expecting the scope to be there when it isn’t available via the operator charm side of the relation.

Possibly I have this all mixed up and its something entirely different.

I’m wondering if there is a way to set the scope from an operator charm interface in a way that will be compatible with what reactive charms and/or what conversations expect to be available?

Thanks

The scope for old (pre-Endpoint) style reactive interface layers should be handled entirely on the local charm side, so it shouldn’t matter what you’re relating it to. Specifically, the scope value for that interface (which is scopes.SERVICE) should be translated to the remote application name.

Since that traceback says it’s in the changed handler, which should only be called during a relation hook, I would definitely expect for JUJU_REMOTE_UNIT to be set. The only thing I can think of is that at some other point, hookenv.remote_service_name() was called without a relation ID outside of a relation hook and cached a None value. TBH, I don’t think that function should be cached at all, but either way, a better fix would be refactoring that interface layer to use Endpoint instead.

1 Like

I would tend to agree with @cory_fu that this is likely a bug on the grafana charm side related to that cached remote_service_name function. Everything else about the code looks as if it’s executing in the proper relation context.

I’d like to get a bug filed against lp:interface-grafana-source related to the deprecated status of RelationBase and scopes. To that end, @jamesbeedy, would you be able to provide more context around that Traceback log you’ve provided and, if public, a link to your operator charm provides code and related bits of your deployed bundle for reproduction purposes?

Were you deploying a second grafana-source relation or a multi-unit application to grafana? There’s an open bug that grafana-source only supports a single unit relation that could be causing contention.

I have had success with making operator ‘provides’ relations with reactive ‘requires’ relations based on Endpoint, so I believe the interface rewrite on top of the Endpoint base is the right long-term solution.

1 Like

Hey @cory_fu, @afreiberger thanks for the responses here.

100%

Me too! I can’t for the life of me figure out how to file a bug against it though …

The operator charm code that I am trying to get to work with the grafana charm (grafana-source provides)

You can find the bundle here.

git clone https://github.com/omnivector-solutions/rev2 -b bdx_next && cd rev2

make charms

juju deploy ./bundles/slurm-core-focal-aws-influxdb-grafana/bundle-no-spaces.yaml

no

:+1:

The result, after deploying the bundle, should look like:

Model     Controller  Cloud/Region   Version  SLA          Timestamp
bdx-rats  osl-aws     aws/us-west-2  2.8.1    unsupported  02:56:05Z

App                 Version  Status  Scale  Charm               Store       Rev  OS      Notes
grafana                      error       1  grafana             jujucharms   37  ubuntu
influxdb                     active      1  influxdb            jujucharms   23  ubuntu
percona-cluster     5.7.20   active      1  percona-cluster     jujucharms  291  ubuntu
slurm-configurator           active      1  slurm-configurator  local        54  ubuntu
slurmctld           20.02.1  active      1  slurmctld           local        41  ubuntu
slurmd              20.02.1  active      1  slurmd              local        23  ubuntu
slurmdbd            20.02.1  active      1  slurmdbd            local        30  ubuntu

Unit                    Workload  Agent  Machine  Public address  Ports              Message
grafana/5*              error     idle   168      172.31.82.15    3000/tcp           hook failed: "grafana-source-relation-changed"
influxdb/5*             active    idle   169      172.31.80.152   8083/tcp,8086/tcp
percona-cluster/16*     active    idle   170      172.31.81.42    3306/tcp           Unit is ready
slurm-configurator/34*  active    idle   171      172.31.82.254
slurmctld/32*           active    idle   172      172.31.83.216                      Slurmctld Available
slurmd/24*              active    idle   173      172.31.80.234                      Slurmd Available
slurmdbd/32*            active    idle   174      172.31.81.174                      Slurmdbd Available

Machine  State    DNS            Inst id              Series  AZ          Message
168      started  172.31.82.15   i-0cca521d3976d562b  focal   us-west-2c  running
169      started  172.31.80.152  i-0edb6b7b89a041821  focal   us-west-2a  running
170      started  172.31.81.42   i-012b7d4eea1f9385b  bionic  us-west-2b  running
171      started  172.31.82.254  i-075a6707fb3f50068  focal   us-west-2c  running
172      started  172.31.83.216  i-0a5d9a1f510569570  focal   us-west-2d  running
173      started  172.31.80.234  i-0923d1c53a9611b93  focal   us-west-2a  running
174      started  172.31.81.174  i-0af7db23bea934c11  focal   us-west-2b  running

The grafana unit errors with:

juju debug-log --include grafana

unit-grafana-5: 02:56:34 ERROR unit.grafana/5.juju-log grafana-source:239: Hook error:
Traceback (most recent call last):
  File "/var/lib/juju/agents/unit-grafana-5/.venv/lib/python3.8/site-packages/charms/reactive/__init__.py", line 74, in main
    bus.dispatch(restricted=restricted_mode)
  File "/var/lib/juju/agents/unit-grafana-5/.venv/lib/python3.8/site-packages/charms/reactive/bus.py", line 379, in dispatch
    _invoke(hook_handlers)
  File "/var/lib/juju/agents/unit-grafana-5/.venv/lib/python3.8/site-packages/charms/reactive/bus.py", line 359, in _invoke
    handler.invoke()
  File "/var/lib/juju/agents/unit-grafana-5/.venv/lib/python3.8/site-packages/charms/reactive/bus.py", line 181, in invoke
    self._action(*args)
  File "/var/lib/juju/agents/unit-grafana-5/charm/hooks/relations/grafana-source/requires.py", line 11, in changed
    conv = self.conversation()
  File "/var/lib/juju/agents/unit-grafana-5/.venv/lib/python3.8/site-packages/charms/reactive/relations.py", line 431, in conversation
    raise ValueError('Unable to determine default scope: no current hook or global scope')
ValueError: Unable to determine default scope: no current hook or global scope

Thanks for the details. I’ll follow up on this after the holiday on Tuesday.

It appears my URL had a / instead of a -.


I’d also link it against the grafana charm itself so we ensure the team sees it in triage for the charm itself.

1 Like

@afreiberger done

@afreiberger I made a pr against each of interface-grafana-source and charm-grafana that fix the issue for me. If you want to implement it differently, feel free to discard my changes. I thought I would propose them none the less.

Thanks

2 Likes