-
Notifications
You must be signed in to change notification settings - Fork 119
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
Should relation data be visible to charm code from within a relation-broken
hook?
#888
Comments
Juju actually allows the charm to access (stale?) relation data in I've just tested this using two charms related to one another, each having a relation-broken hook and accessing relation data (from "this" or the "remote" app). The Harness actually gets this fairly different from real Juju in a number of cases. Below are the results. The "setter" charm is the charm in the relation that's setting relation data via
Show raw data from testTo test this (unit tests and real Juju), I hacked my database and webapp charms that I've been using for secrets to add logging into the relation-broken hooks. The database charm is the "setter" and it sets relation data, and the webapp charm is the "getter" as it reads relation data.
It seems odd that the Harness deviates so much from real Juju, which just allows reads in each case, even if the data is not useful/stale. I presume we intentionally raise more errors than Juju in tests to try to catch problems early -- for example, the charm probably shouldn't be accessing remote relation data during As to the original issue, it seems like the data is unable to be accessed (in 3 out of 4 cases!). @sed-i, can you post the actual code you were working with when you ran into this? Were you fetching relation data? Was it in the "getter" or "setter" charm? And was it via In any case, we should decide whether we want to mimic real Juju more closely. Or we should raise an error consistently if you access relation data in |
Here's the utest that expects the charmlib/juju to take care of cleaning up relation data.
The pattern we were taking in o11y charms more often than not, is that rel data represents the most up to date state. |
I'm probably missing something obvious, but I don't quite understand -- doesn't the above table show that relation-broken on real Juju still includes the previous data? So wouldn't expecting the Harness to do something different mean the unit test will behave differently in unit tests compared to under real Juju? |
I'm not sure I understand the table correctly: |
Yeah, that's right -- that's the last row in the table. It shows the "getter" app (i.e., the other charm from the one that set the data) being able to read data that the remote app (the "setter") set. Under real Juju it can read this data, under the Harness you currently get a You can see this from the following log line:
The webapp charm is the "getter" in this case, and it was able to read that data -- during relation-broken -- that the database charm had set. |
During relation-broken you should be able to read the data from the unit
that was on the other end, if we aren't doing that in Harness, we should
allow it. (my only caveat is that really relation-departing is where you
should be handling the information, by the time you get to
'relation-broken' its because the relation really is gone and you're
supposed to be finalizing things, not doing more configuration based on the
last thing that the remote unit shared with you.)
Note while you can read, you *shouldn't* be allowed to set data at that
point.
I also feel that 'relation-broken' really shouldn't be "just another
relation event like all the other ones". Deleting a file on disk is
completely different to modifying it, or creating it. So the original
argument that "I want a catch all behavior" doesn't really fit for me.
John
=:->
…On Tue, Jan 17, 2023 at 8:58 PM Ben Hoyt ***@***.***> wrote:
Yeah, that's right -- that's the last row in the table. It shows the
"getter" app (i.e., the other charm from the one that set the data) being
able to read data that the remote app (the "setter") set. Under real Juju
it can read this data, under the Harness you currently get a RuntimeError("remote-side
relation data cannot be accessed during a relation-broken event"), which
doesn't seem to match reality. ***@***.*** <https://github.com/jameinel>
any idea why the Harness tries to be different/stricter than reality here?)
You can see this from the following log line:
unit-webapp-0: 15:25:26 INFO unit.webapp/0.juju-log db:0: webapp _on_db_relation_broken: <ops.model.Relation db:0> event_data={'db_password_id': 'secret:cf0c1lrs26oc7aah2260'}
The webapp charm is the "getter" in this case, and it was able to read
that data -- during relation-broken -- that the database charm had set.
—
Reply to this email directly, view it on GitHub
<#888 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABRQ7IB6DJU7POVV7INTODWS5E5NANCNFSM6AAAAAATZLT5HE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Iiuc, this means that the following pattern is wrong: def _on_relation_departed(self, _): # or broken
self._update_config() # regenerate everything from current rel data and instead we should do something like: def _on_relation_departed(self, event): # or broken
self._update_config(excluding=event.relation.data) Is that correct? In other words, from within relation-departed/broken:
|
Hi everyone, chiming in on this; is what @sed-i proposed the pattern we're supposed to follow? |
@PietroPasotti just gave me an idea: This is not a great pattern, but it conveys well our dissonance about relation-broken. |
FYI in some cases (but not all) accessing the remote application data in a relation broken event causes an error See: Lines 1341 to 1349 in 734e12d
canonical/mysql-router-k8s-operator#73 |
What the Kubeflow team has seen with istio-pilot is like what @carlcsaposs-canonical reports. In live Juju when handling a relation-broken event:
Up until today, we had only seen case (1) and whenever we saw it, we also knew that the departing application's data is still in the relation data bag. We handled this by popping the departing data before using the data bag. # (simplified version - differs slightly from the link)
if isinstance(event, RelationBrokenEvent):
relation_data.pop((event.relation, event.app)) Now that sometimes we see if isinstance(event, RelationBrokenEvent):
try:
relation_data.pop((event.relation, event.app))
except KeyError:
log_and_pass # ? The one question I have is whether, when |
@jameinel Per the above and per https://bugs.launchpad.net/juju/+bug/1960934, it seems Juju is sometimes setting |
Also, I think we usually don't want to see the stale data even on relation-departed:
Real world example:
|
This issue is related to a frequent point of friction in charming: reconciling holistic vs deltas approaches.
|
Need to consider further what to do here. Possibly related to #940 work. |
Related: #940 (comment) (difference in usage between local and remote app data during |
This is fixed in ops 2.10, isn't it? |
I believe the relation data is still accessible—and I think it should be, for the local app/unit databags |
@tonyandrewmeyer is going to investigate this further and then we'll make a decision here. |
Currently, harness first emits
relation-broken
and only then invalidates the data.This means that relation data is still accessible by charm code while inside the
relation-broken
hook. Is that intentional?Based on the event page it sounds like charm code shouldn't be able to see any data when inside the
broken
hook.operator/ops/testing.py
Lines 697 to 702 in 4d38ef7
The text was updated successfully, but these errors were encountered: