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

pykms: fix/enhance logging #81366

Merged
merged 2 commits into from Apr 29, 2020
Merged

pykms: fix/enhance logging #81366

merged 2 commits into from Apr 29, 2020

Conversation

pvgoran
Copy link
Contributor

@pvgoran pvgoran commented Feb 29, 2020

Motivation for this change

The current pykms package (version 20190611, introduced at bf9cecf) does logging in a problematic way: it is sed-patched to log to the systemd journal, but at the same time it still creates a log file inside Nix store by default (if the --logfile option is not specified). This prevents this package's binaries from being used without specifying the --logfile option. Also, the journal logs are prefixed with a long full path to the python file in Nix store, which make it quite inconvenient to look at them.

So I replaced the current "sed-patch" with another patch which changes the default location of the log file to be in the current directory, and doesn't involve the systemd journal. This way, the binaries can be used without the --logfile option.

Also, I added the SyslogIdentifier systemd unit option for better identification of pykms' logs.

The result is tested and works as intended.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@@ -48,5 +48,5 @@
'choi' : ["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG", "MINI"]},
'lfile' : {'help' : 'Use this option to set an output log file. The default is \"pykms_logclient.log\" or type \"STDOUT\" to view log info on stdout.',
- 'def' : os.path.dirname(os.path.abspath( __file__ )) + "/pykms_logclient.log", 'des' : "logfile"},
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you approach upstream on that? The help text reads like it should log to pykms_logclient.log in the current working directory, not relative to the location on where pykms is installed.

This should cause problems in other distros as well, if pykms is installed by the distros package manager, and not world-writeable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, creating the log file in the executable's directory seems to be a deliberate decision made upstream. I don't think I'm willing to debate it with them.

Copy link
Contributor

Choose a reason for hiding this comment

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

I opened SystemRage/py-kms#64 to discuss this upstream.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@flokli Thank you.

Copy link
Member

@peterhoeg peterhoeg Apr 24, 2020

Choose a reason for hiding this comment

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

Do we really care about this? pykms can be given an absolute path to log to (or STDOUT which is what the the module currently is doing).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@peterhoeg I think this is worth caring for. It's better if the program works out-of-the-box, without requiring to specify this kind of parameters.

At the very least, I firmly disagree with the way the logging behaviour is tuned by the nixpkgs package right now.

@@ -29,6 +29,29 @@ let
fi
'');

loggingPatch =
Copy link
Contributor

Choose a reason for hiding this comment

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

We usually don't inline patches inside nix.

We prefer to fetch them from a PR to upstream, or if that's not feasible, ship them as a patchfile next to the default.nix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fetching patches from a PR seems fragile. If I make a PR upstream and reference it in .nix, what happens if this PR is deleted for some reason?

I can extract the patch into a separate file, though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Usually, referring to the patch via something like https://github.com/$upstreamOwner/$upstreamRepo/pull/$pr/commits/$commitID.patch should be stable, at least as long as the fork still has this commit on some branch. But I agree, moving to a separate file might also be okay.

Copy link
Member

Choose a reason for hiding this comment

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

You can reference the commit instead of the PR. The commit should be immutable even if you delete the PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Mic92 And if I delete the branch?

Copy link
Member

Choose a reason for hiding this comment

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

@Mic92 And if I delete the branch?

Also in that case. This commit is no longer accessible by any branch but the link still works: Mic92/dotfiles@18869fa

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Mic92 Thanks.

@peterhoeg
Copy link
Member

👍 on the changes. The easiest is just to stick the patch into a separate file and be done with it if upstream doesn't want to take your patch.

@peterhoeg
Copy link
Member

peterhoeg commented Apr 29, 2020 via email

@pvgoran
Copy link
Contributor Author

pvgoran commented Apr 29, 2020

I force-pushed another version, with the patch separated into a file. Also, I made a PR upstream: SystemRage/py-kms#66 . I couldn't use this PR here, though, because the patch is different (the affected lines changed in upstream's master).

@peterhoeg What you write makes perfect sense. However, what is the rationale for not inlining patches? (Just curious.)

I don't mind maintaining the change/the package, although I'm not familiar with the maintenance processes.

@peterhoeg
Copy link
Member

peterhoeg commented Apr 29, 2020 via email

The logging "sed-patch" that was introduced for version 20190611 worked poorly:
it was too intrusive (breaking the --logfile option), and it didn't prevent
using in-store file for logging by default. The new logging patch (an actual
"diff-patch") is less intrusive: it just changes the default log file's
location to be the current directory instead of the executable's directory.
@pvgoran
Copy link
Contributor Author

pvgoran commented Apr 29, 2020

Please add a comment to default.nix above the patch where you reference the upstream issue. It makes it nicer for the next person who looks at this.

@peterhoeg Done, and thanks for explaining.

@peterhoeg peterhoeg merged commit 83a57cf into NixOS:master Apr 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants