Merge pull request #287348 from mweinelt/fastly-exporter-module
nixos/prometheus-fastly-exporter: fix runtime environment, refactor, make things prettier
This commit is contained in:
commit
878609256b
2 changed files with 46 additions and 24 deletions
|
@ -1,41 +1,54 @@
|
|||
{ config, lib, pkgs, options }:
|
||||
{ config
|
||||
, lib
|
||||
, pkgs
|
||||
, options
|
||||
}:
|
||||
|
||||
with lib;
|
||||
let
|
||||
inherit (lib)
|
||||
escapeShellArgs
|
||||
mkOption
|
||||
optionals
|
||||
types
|
||||
;
|
||||
|
||||
let cfg = config.services.prometheus.exporters.fastly;
|
||||
cfg = config.services.prometheus.exporters.fastly;
|
||||
in
|
||||
{
|
||||
port = 9118;
|
||||
extraOpts = {
|
||||
debug = mkEnableOption (lib.mdDoc "Debug logging mode for fastly-exporter");
|
||||
|
||||
extraOpts = with types; {
|
||||
configFile = mkOption {
|
||||
type = types.nullOr types.path;
|
||||
type = nullOr path;
|
||||
default = null;
|
||||
description = lib.mdDoc ''
|
||||
example = "./fastly-exporter-config.txt";
|
||||
description = ''
|
||||
Path to a fastly-exporter configuration file.
|
||||
Example one can be generated with `fastly-exporter --config-file-example`.
|
||||
'';
|
||||
example = "./fastly-exporter-config.txt";
|
||||
};
|
||||
|
||||
tokenPath = mkOption {
|
||||
type = types.nullOr types.path;
|
||||
apply = final: if final == null then null else toString final;
|
||||
description = lib.mdDoc ''
|
||||
type = path;
|
||||
description = ''
|
||||
A run-time path to the token file, which is supposed to be provisioned
|
||||
outside of Nix store.
|
||||
'';
|
||||
};
|
||||
};
|
||||
serviceOpts = {
|
||||
script = ''
|
||||
${optionalString (cfg.tokenPath != null)
|
||||
"export FASTLY_API_TOKEN=$(cat ${toString cfg.tokenPath})"}
|
||||
${pkgs.prometheus-fastly-exporter}/bin/fastly-exporter \
|
||||
-listen http://${cfg.listenAddress}:${toString cfg.port}
|
||||
${optionalString cfg.debug "-debug true"} \
|
||||
${optionalString (cfg.configFile != null) "-config-file ${cfg.configFile}"}
|
||||
serviceConfig = {
|
||||
LoadCredential = "fastly-api-token:${cfg.tokenPath}";
|
||||
};
|
||||
script = let
|
||||
call = escapeShellArgs ([
|
||||
"${pkgs.prometheus-fastly-exporter}/bin/fastly-exporter"
|
||||
"-listen" "${cfg.listenAddress}:${toString cfg.port}"
|
||||
] ++ optionals (cfg.configFile != null) [
|
||||
"--config-file" cfg.configFile
|
||||
] ++ cfg.extraFlags);
|
||||
in ''
|
||||
export FASTLY_API_TOKEN="$(cat $CREDENTIALS_DIRECTORY/fastly-api-token)"
|
||||
${call}
|
||||
'';
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,22 +1,31 @@
|
|||
{ lib, buildGoModule, fetchFromGitHub }:
|
||||
{ lib
|
||||
, buildGoModule
|
||||
, fetchFromGitHub
|
||||
, nixosTests
|
||||
}:
|
||||
|
||||
buildGoModule rec {
|
||||
pname = "fastly-exporter";
|
||||
version = "7.6.1";
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "peterbourgon";
|
||||
repo = pname;
|
||||
owner = "fastly";
|
||||
repo = "fastly-exporter";
|
||||
rev = "v${version}";
|
||||
sha256 = "sha256-JUbjWAJ70iq0RCr6U2thbtZ3nmCic9wGtSf2ArRy4uA=";
|
||||
hash = "sha256-JUbjWAJ70iq0RCr6U2thbtZ3nmCic9wGtSf2ArRy4uA=";
|
||||
};
|
||||
|
||||
vendorHash = "sha256-lEaMhJL/sKNOXx0W+QHMG4QUUE6Pc4AqulhgyCMQQNY=";
|
||||
|
||||
passthru.tests = {
|
||||
inherit (nixosTests.prometheus-exporters) fastly;
|
||||
};
|
||||
|
||||
meta = with lib; {
|
||||
description = "Prometheus exporter for the Fastly Real-time Analytics API";
|
||||
homepage = "https://github.com/peterbourgon/fastly-exporter";
|
||||
homepage = "https://github.com/fastly/fastly-exporter";
|
||||
license = licenses.asl20;
|
||||
maintainers = teams.deshaw.members;
|
||||
mainProgram = "fastly-exporter";
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue