Unverified Commit 1a9bb3aa authored by Sandro Jäckel's avatar Sandro Jäckel Committed by GitHub
Browse files

nixos/opentelemetry-collector: validate config (#392701)

parents 5e93de35 0a5bba0f
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -435,3 +435,5 @@
- The `open-webui` package's postgres support have been moved to optional dependencies to comply with upstream changes in 0.6.26.

- `prl-tools` has been moved out of `linuxPackages` because Parallels Guest Tools become driverless since 26.1.0.

- `services.opentelemetry-collector` has a new option `validateConfigFile` option that checks the configuration file during build. It is enabled by default if the configuration file is in the Nix store.
+34 −22
Original line number Diff line number Diff line
@@ -13,12 +13,27 @@ let
    mkOption
    types
    getExe
    isStorePath
    literalMD
    ;

  cfg = config.services.opentelemetry-collector;
  opentelemetry-collector = cfg.package;

  settingsFormat = pkgs.formats.yaml { };
  generatedConf =
    if cfg.configFile == null then
      settingsFormat.generate "config.yaml" cfg.settings
    else
      cfg.configFile;
  conf =
    if cfg.validateConfigFile then
      pkgs.runCommandLocal "config.yaml" { inherit generatedConf; } ''
        cp $generatedConf $out
        ${getExe opentelemetry-collector} validate --config=file:$out
      ''
    else
      generatedConf;
in
{
  options.services.opentelemetry-collector = {
@@ -43,6 +58,11 @@ in
        Specify a path to a configuration file that Opentelemetry Collector should use.
      '';
    };

    validateConfigFile = lib.mkEnableOption "Validate configuration file" // {
      defaultText = literalMD "`true` if `configFile` is a store path";
      default = isStorePath cfg.configFile;
    };
  };

  config = mkIf cfg.enable {
@@ -61,15 +81,7 @@ in
      description = "Opentelemetry Collector Service Daemon";
      wantedBy = [ "multi-user.target" ];

      serviceConfig =
        let
          conf =
            if cfg.configFile == null then
              settingsFormat.generate "config.yaml" cfg.settings
            else
              cfg.configFile;
        in
        {
      serviceConfig = {
        ExecStart = "${getExe opentelemetry-collector} --config=file:${conf}";
        DynamicUser = true;
        Restart = "always";