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

nixos/prometheus: abbility to add downstream exporters #298171

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mkg20001
Copy link
Member

@mkg20001 mkg20001 commented Mar 22, 2024

Description of changes

This adds the abbility to add downstream exporters while profiting from upstream's exporter config generator

Documentation of the new method: https://github.com/mgit-at/nixpkgs/blob/downstream-exporter/nixos/modules/services/monitoring/prometheus/exporters.md#adding-a-downstream-exporter-module-services-prometheus-exporters-downstream-exporter

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.05 Release Notes (or backporting 23.05 and 23.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@mkg20001 mkg20001 force-pushed the downstream-exporter branch from 38393f8 to b2a6008 Compare March 22, 2024 21:23
@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Mar 22, 2024
@mkg20001 mkg20001 force-pushed the downstream-exporter branch 4 times, most recently from fa4e0bd to 8b85385 Compare March 22, 2024 21:56
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 labels Mar 22, 2024
@mkg20001 mkg20001 requested a review from WilliButz March 22, 2024 22:44
@mkg20001 mkg20001 force-pushed the downstream-exporter branch from 8b85385 to aa09415 Compare April 2, 2024 23:36
@mkg20001 mkg20001 force-pushed the downstream-exporter branch from aa09415 to 8deb9e4 Compare April 24, 2024 15:06
imports = [
(import "${modulesPath}/services/monitoring/prometheus/mk-downstream-exporter.nix" {
name = "EXPORTER";
file = ./EXPORTER-exporter.nix;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this need to be passed via a file? Being able to pass that inline seems useful, at least for exporters with little-to-no configurability; it seems better from a readability standpoint, than having to jump files (and mental contexts) to get potentially-little information.

Copy link
Member Author

Choose a reason for hiding this comment

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

Current exporters are also files, this fits the pattern.

I could extend it to take a function too and call the option "module" therefore keeping it similar to how "imports" works right now

Copy link
Contributor

Choose a reason for hiding this comment

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

Current exporters are also files, this fits the pattern.

I'm not saying it's necessarily wrong to put it in a separate file, especially in the current case: folder full of exporters, which the module automatically maps through mkExporter. However, I think it would be pretty natural to either take in an already-resolved attrset, or a function (taking pkgs, lib, etc.)

Importing the file can be the responsibility of the caller then, which leaves them the ability to implement whatever conventions they use; for instance, if something ships a bunch of exporters which use a common configuration format (incl. cmdline parameters) the drv's author may want to automate the option and service definitions, which seems simpler to do if they can programatically generate that part before passing it to mkExporter.
(In principle it's entirely possible to do the same thing with pass-by-file, using IFD, but that gets kind of gnarly.)

```nix
{ modulesPath, ... }: {
imports = [
(import "${modulesPath}/services/monitoring/prometheus/mk-downstream-exporter.nix" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be exposed under utils or such, instead of hardcoding that path in every caller?

Copy link
Member Author

Choose a reason for hiding this comment

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

Does it fit there? Certainly could be done

Copy link
Contributor

@nbraud nbraud left a comment

Choose a reason for hiding this comment

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

Seems useful, but I had a couple questions about the proposed implementation.

@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Sep 10, 2024
@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Sep 15, 2024
@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Sep 27, 2024
@mkg20001 mkg20001 force-pushed the downstream-exporter branch 2 times, most recently from 9da240c to d8f28e9 Compare September 28, 2024 12:20
@fpletz fpletz self-requested a review September 28, 2024 12:21
@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Sep 28, 2024
@FliegendeWurst FliegendeWurst added the awaiting_changes (old Marvin label, do not use) label Dec 4, 2024
@mkg20001 mkg20001 force-pushed the downstream-exporter branch from d8f28e9 to 9b47fa1 Compare December 26, 2024 17:15
@mkg20001 mkg20001 force-pushed the downstream-exporter branch from 9b47fa1 to 0f6aaad Compare December 26, 2024 18:04
@github-actions github-actions bot added the 8.has: documentation This PR adds or changes documentation label Dec 26, 2024
@nix-owners nix-owners bot requested review from GetPsyched and hsjobeki December 26, 2024 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: documentation This PR adds or changes documentation 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 awaiting_changes (old Marvin label, do not use)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants