Watch
0
0
Fork
You've already forked hyperhive
0
hyperhive/nix/host-modules/lib/scrape-without-jobs.nix
atlas 480855dfaf swarm-otel: scrape the authenticated targets only once the collector has its client secret
An empty secret file made the prometheus receiver request a token for each published target every scrape; authelia's per-address limit then refused every client behind that address. Without a secret the collector starts on the config minus those jobs. full-setup asserts the limiter never fired.
2026-11-23 12:28:12 +01:00

33 lines
1.1 KiB
Nix

# 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 ];
};
}