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

chore: Rebase avahi_name_conflict commits onto edge #10706

Merged
merged 3 commits into from
Jun 9, 2022

Conversation

SyntaxColoring
Copy link
Contributor

@SyntaxColoring SyntaxColoring commented Jun 9, 2022

Overview

This PR is to rebase two commits atop edge:

  1. One commit for the entirety of refactor(update-server): Split name_management into submodules #10523.
  2. One commit for the entirety of fix(update-server): Keep name deconflicted with other devices on the network #10559.
  3. One fixup commit to change sleep(3600) to sleep(10). See discussion below in this PR.

Fixes bug #10126.

Review requests

  • We agree with the plan to click the GitHub "rebase and merge" button.
  • We agree with merging this into edge (as opposed to an alpha or beta branch or something).
  • No unexpected commits are in here.

Risk analysis

This should be safe at this point because:

@SyntaxColoring SyntaxColoring added chore update server robot-svcs Falls under the purview of the Robot Services squad (formerly CPX, Core Platform Experience). labels Jun 9, 2022
@codecov
Copy link

codecov bot commented Jun 9, 2022

Codecov Report

Merging #10706 (0d73aba) into edge (3dffaef) will increase coverage by 0.00%.
The diff coverage is 49.46%.

Impacted file tree graph

@@           Coverage Diff            @@
##             edge   #10706    +/-   ##
========================================
  Coverage   73.81%   73.81%            
========================================
  Files        2139     2144     +5     
  Lines       57526    57629   +103     
  Branches     5807     5807            
========================================
+ Hits        42460    42541    +81     
- Misses      13846    13868    +22     
  Partials     1220     1220            
Flag Coverage Δ
update-server 73.04% <49.46%> (+0.53%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
update-server/otupdate/buildroot/__main__.py 0.00% <0.00%> (ø)
update-server/otupdate/buildroot/constants.py 0.00% <ø> (ø)
update-server/otupdate/common/constants.py 100.00% <ø> (ø)
update-server/otupdate/common/run_application.py 0.00% <0.00%> (ø)
update-server/otupdate/openembedded/__main__.py 0.00% <0.00%> (ø)
...otupdate/common/name_management/static_hostname.py 23.52% <23.52%> (ø)
...otupdate/common/name_management/pretty_hostname.py 28.94% <28.94%> (ø)
...te-server/otupdate/common/name_management/avahi.py 49.48% <49.48%> (ø)
...update/common/name_management/name_synchronizer.py 97.50% <97.50%> (ø)
update-server/otupdate/buildroot/__init__.py 88.88% <100.00%> (+1.70%) ⬆️
... and 3 more

Copy link
Contributor

@mcous mcous left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's get a 👍 from the embedded team, too

Copy link
Member

@sfoster1 sfoster1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The truncation stuff I think can have some slightly surprising outcomes. A better way to do this might be to limit the length of the names you can set low enough to give enough space for, say, 4 or 5 or 6 digits of service name deconfliction, and wrap the sequence numbers at that limit. Then there's no dynamic truncation stuff required. It also solves the problem with losing the original basename so that you might end up with just "Num0" as your name after a while.

(If we care to fix this, we should look into preserving grapheme clusters:
https://unicode.org/reports/tr29/)
"""
encoded = s.encode("utf-8")[:maximum_utf8_octets]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this won't be as much of an issue because our name acceptability regex may prevent characters like this, depending on how the engine is implemented. it really is pretty gross though, and I think there are better ways to do it - see top level review

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only name acceptability regex that I know of today is client-side. Is that the one that you mean?

If so, yes, it'll prevent non-ASCII. But we intend to loosen that eventually. I figured we may as well try to handle things nicely now in case a client that's looser with names ever talks to this server version.

Agreed with your top-level review about this being gross and there being better ways.


# "3" comes from AVAHI_ENTRY_GROUP_COLLISION being index 3 in this enum:
# https://github.com/lathiat/avahi/blob/v0.8/avahi-common/defs.h#L234
avahi_entry_group_collision = dbus.Int32(3)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] love the comment with the source, but maybe also make this a class constant so you can see it from the code alone?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, @X-sam suggested this in #10559 (comment) too. Two people independently suggesting this probably means it's a good idea, so I will.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, it turns out that this is hard because dev machines don't have the dbus module.

This syntax:

class _SyncClient:
    _AVAHI_ENTRY_GROUP_COLLISION = dbus.Int32(3)
    ...

Will evaluate dbus.Int32(3) at class definition time, and run into a NameError because dbus isn't defined.

I don't see an easy way of resolving this without doing something like guarding the whole class definition, which, anecdotally, I've seen mypy have trouble with.

Leaving this alone for now.

# It seems like there should be a better way of doing this,
# but this is what the docs recommend.
# https://docs.aiohttp.org/en/stable/web_advanced.html#application-runners
await asyncio.sleep(3600)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make this like await asyncio.sleep(10)? i get why you would want to do this, but either

  • it doesn't matter how long you sleep as long as it's "a while" (and ten seconds counts)
  • something weird happens when this task wakes and it'll be easier to notice if it's every ten seconds instead of every hour

even better honestly would be establishing some dummy quitflag, setting it, and then await on it dropping. will never wake accidentally and provides a pretty clear path to adding graceful quitting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good thoughts.

Going with await asyncio.sleep(10) for now because it's a more minimal change and it keeps us mirroring the aiohttp docs. But the dummy quitflag is a clever solution, I think I agree that it's better, and I'll make a note to do that in another PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you're gonna make a note for that - maybe note to go ahead and implement actual quitting by handling sigterm (default for systemd process killing, could change to basically anything else if you wanted to in the unit file) and raising the flag,

@SyntaxColoring
Copy link
Contributor Author

The truncation stuff I think can have some slightly surprising outcomes. A better way to do this might be to limit the length of the names you can set low enough to give enough space for, say, 4 or 5 or 6 digits of service name deconfliction, and wrap the sequence numbers at that limit. Then there's no dynamic truncation stuff required. It also solves the problem with losing the original basename so that you might end up with just "Num0" as your name after a while.

Yeah, that definitely would have been better.

I think I'd like to stick with the logic as written for now, because:

Copy link
Member

@sfoster1 sfoster1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on discussion here, sounds good to me!

Will say though, I'm not an expert, but if splitting grapheme clusters is a concern I don't know how much I want to leave that to avahi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore robot-svcs Falls under the purview of the Robot Services squad (formerly CPX, Core Platform Experience). update server
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants