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

prometheus-collectd-exporter service: init module #29212

Merged
merged 2 commits into from Sep 11, 2017

Conversation

bachp
Copy link
Member

@bachp bachp commented Sep 10, 2017

Motivation for this change

Allow easy configuration of the collectd exporter

Supports JSON and binary (optional) protocol
of collectd.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option build-use-sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • Linux
  • 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 nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

@mention-bot
Copy link

@bachp, thanks for your PR! By analyzing the history of the files in this pull request, we identified @edolstra, @bjornfor and @offlinehacker to be potential reviewers.

};

config = mkIf cfg.enable {
networking.firewall.allowedTCPPorts = [ (optional cfg.openFirewall cfg.port) (optional (cfg.openFirewall && cfg.collectdBinary.enable) cfg.collectdBinary.port) ];
Copy link
Member

@Mic92 Mic92 Sep 11, 2017

Choose a reason for hiding this comment

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

Throws an error if openFirewall is false (default):

error: The option value `networking.firewall.allowedTCPPorts.[definition 1-entry 1]' in `/home/joerg/git/nixpkgs/nixos/modules/services/monitoring/prometheus/collectd-exporter.nix' is not a integer

Copy link
Member Author

Choose a reason for hiding this comment

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

@Mic92 Do you know the correct way to enable the second port based on two conditions? I couldn't find any example.

Copy link
Member

Choose a reason for hiding this comment

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

untested:

networking.firewall.allowedTCPPorts = (optional cfg.openFirewall cfg.port)  ++ 
  (optional (cfg.openFirewall && cfg.collectdBinary.enable) cfg.collectdBinary.port);

Copy link
Member Author

Choose a reason for hiding this comment

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

I will give it a try. I now also figured out why I didn't catch the issue. I have the firewall disabled on my dev machine.

Copy link
Member Author

Choose a reason for hiding this comment

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

@Mic92 Your suggestions works. But I was wondering if it would make more sense to have two firewall open rules one for the binary and one for the scrape/json. Maybe people only want to open one.

Copy link
Member

Choose a reason for hiding this comment

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

I would keep it simple, you can always use networking.firewall.allowedTCPPorts = [ ] yourself, if you want it more granular.

@bachp
Copy link
Member Author

bachp commented Sep 11, 2017

Firewall handling fixed

unitConfig.Documentation = "https://github.com/prometheus/collectd_exporter";
wantedBy = [ "multi-user.target" ];
serviceConfig = {
User = "nobody";
Copy link
Member

Choose a reason for hiding this comment

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

How about using DynamicUser , which we have in systemd since some versions?

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't know about that. I just copied it from the other collectors. A quick tests shows it seems to work. I updated the PR accordingly.

Copy link
Member Author

Choose a reason for hiding this comment

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

Seems like this would be the first module in nixpkgs using DynamicUser.

Copy link
Member

Choose a reason for hiding this comment

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

Many services have persistent data, so that DynamicUser is not applicable. Also DynamicUser is still not well known and new.

Supports JSON and binary (optional) protocol
of collectd.
@Mic92 Mic92 merged commit 334e23d into NixOS:master Sep 11, 2017
@bachp
Copy link
Member Author

bachp commented Sep 11, 2017

@Mic92 What's the difference between submodule and just a new attrSet as you used?

@Mic92
Copy link
Member

Mic92 commented Sep 11, 2017

The submodule version did not evaluate on my system

fpletz pushed a commit that referenced this pull request Sep 17, 2017
* prometheus-collectd-exporter service: init module

Supports JSON and binary (optional) protocol
of collectd.

* nixos/prometheus-collectd-exporter: submodule is not needed for collectdBinary

(cherry picked from commit 334e23d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants