# Pure function — NOT a NixOS module. An OpenTelemetry collector config minus # the named prometheus scrape jobs. # # scrapeWithoutJobs = import ./lib/scrape-without-jobs.nix { inherit lib; }; # scrapeWithoutJobs { inherit settings jobs; pipeline = "metrics/swarm"; } # # `jobs` are `job_name`s of the `prometheus` receiver. When none is left the # receiver goes, and `pipeline` with it: a prometheus receiver without scrape # configs fails the collector's validation, and a pipeline naming an absent # receiver does too. { lib }: { settings, jobs, pipeline, }: let kept = lib.filter (job: !(lib.elem job.job_name jobs)) ( settings.receivers.prometheus.config.scrape_configs or [ ] ); in if !(settings.receivers ? prometheus) then settings else if kept != [ ] then lib.recursiveUpdate settings { receivers.prometheus.config.scrape_configs = kept; } else settings // { receivers = removeAttrs settings.receivers [ "prometheus" ]; service = settings.service // { pipelines = removeAttrs settings.service.pipelines [ pipeline ]; }; }