From 8b41fa2cc093d26ddee8a90164793ab61012f62d Mon Sep 17 00:00:00 2001 From: Jan Hrnko Date: Fri, 1 Nov 2019 10:56:59 +0100 Subject: [PATCH 1/3] trickster: init at 0.1.10 --- pkgs/servers/trickster/trickster.nix | 27 +++ pkgs/servers/trickster/trickster_deps.nix | 237 ++++++++++++++++++++++ pkgs/top-level/all-packages.nix | 2 + 3 files changed, 266 insertions(+) create mode 100644 pkgs/servers/trickster/trickster.nix create mode 100644 pkgs/servers/trickster/trickster_deps.nix diff --git a/pkgs/servers/trickster/trickster.nix b/pkgs/servers/trickster/trickster.nix new file mode 100644 index 00000000000..c219300ca21 --- /dev/null +++ b/pkgs/servers/trickster/trickster.nix @@ -0,0 +1,27 @@ +{ stdenv, buildGoPackage, fetchFromGitHub }: + +buildGoPackage rec { + pname = "trickster"; + version = "0.1.10"; + + goPackagePath = "github.com/Comcast/trickster"; + + goDeps = ./trickster_deps.nix; + + src = fetchFromGitHub { + owner = "Comcast"; + repo = pname; + rev = "v${version}"; + sha256 = "12z71rf03g2x8r7cgns0n4n46r0gjsfyig6z9r5xrn9kfghabfi8"; + }; + + doCheck = true; + + meta = with stdenv.lib; { + description = "Reverse proxy cache for the Prometheus HTTP APIv1"; + homepage = "https://github.com/Comcast/trickster"; + license = licenses.asl20; + maintainers = with maintainers; [ maintainers."1000101" ]; + platforms = platforms.linux; + }; +} \ No newline at end of file diff --git a/pkgs/servers/trickster/trickster_deps.nix b/pkgs/servers/trickster/trickster_deps.nix new file mode 100644 index 00000000000..ab100bed760 --- /dev/null +++ b/pkgs/servers/trickster/trickster_deps.nix @@ -0,0 +1,237 @@ +# file generated from go.mod using vgo2nix (https://github.com/adisbladis/vgo2nix) +[ + { + goPackagePath = "github.com/BurntSushi/toml"; + fetch = { + type = "git"; + url = "https://github.com/BurntSushi/toml"; + rev = "v0.3.1"; + sha256 = "1fjdwwfzyzllgiwydknf1pwjvy49qxfsczqx5gz3y0izs7as99j6"; + }; + } + { + goPackagePath = "github.com/alicebob/gopher-json"; + fetch = { + type = "git"; + url = "https://github.com/alicebob/gopher-json"; + rev = "5a6b3ba71ee6"; + sha256 = "0hx6n722zq51p852lv56k39yjy09lw6mnr2c3x0p23rfyyrakj2p"; + }; + } + { + goPackagePath = "github.com/alicebob/miniredis"; + fetch = { + type = "git"; + url = "https://github.com/alicebob/miniredis"; + rev = "cfad8aca71cc"; + sha256 = "0x2401nxyhdz037lj98c0sa77d8k49jfcq7is3ddiyim3csg5a0w"; + }; + } + { + goPackagePath = "github.com/beorn7/perks"; + fetch = { + type = "git"; + url = "https://github.com/beorn7/perks"; + rev = "3a771d992973"; + sha256 = "1l2lns4f5jabp61201sh88zf3b0q793w4zdgp9nll7mmfcxxjif3"; + }; + } + { + goPackagePath = "github.com/chzyer/readline"; + fetch = { + type = "git"; + url = "https://github.com/chzyer/readline"; + rev = "2972be24d48e"; + sha256 = "104q8dazj8yf6b089jjr82fy9h1g80zyyzvp3g8b44a7d8ngjj6r"; + }; + } + { + goPackagePath = "github.com/coreos/bbolt"; + fetch = { + type = "git"; + url = "https://github.com/coreos/bbolt"; + rev = "v1.3.0"; + sha256 = "0cp5v9iypg9ysiq40k3h3lg7aisxplnmxshha7nama6b170izyay"; + }; + } + { + goPackagePath = "github.com/go-kit/kit"; + fetch = { + type = "git"; + url = "https://github.com/go-kit/kit"; + rev = "v0.8.0"; + sha256 = "1rcywbc2pvab06qyf8pc2rdfjv7r6kxdv2v4wnpqnjhz225wqvc0"; + }; + } + { + goPackagePath = "github.com/go-logfmt/logfmt"; + fetch = { + type = "git"; + url = "https://github.com/go-logfmt/logfmt"; + rev = "v0.4.0"; + sha256 = "06smxc112xmixz78nyvk3b2hmc7wasf2sl5vxj1xz62kqcq9lzm9"; + }; + } + { + goPackagePath = "github.com/go-redis/redis"; + fetch = { + type = "git"; + url = "https://github.com/go-redis/redis"; + rev = "v6.14.2"; + sha256 = "0s1if96r8xnadan7pz1j8hvzk9g4fm3phwmwzadwpq21pgni66d7"; + }; + } + { + goPackagePath = "github.com/go-stack/stack"; + fetch = { + type = "git"; + url = "https://github.com/go-stack/stack"; + rev = "v1.8.0"; + sha256 = "0wk25751ryyvxclyp8jdk5c3ar0cmfr8lrjb66qbg4808x66b96v"; + }; + } + { + goPackagePath = "github.com/golang/protobuf"; + fetch = { + type = "git"; + url = "https://github.com/golang/protobuf"; + rev = "v1.2.0"; + sha256 = "0kf4b59rcbb1cchfny2dm9jyznp8ri2hsb14n8iak1q8986xa0ab"; + }; + } + { + goPackagePath = "github.com/golang/snappy"; + fetch = { + type = "git"; + url = "https://github.com/golang/snappy"; + rev = "2e65f85255db"; + sha256 = "05w6mpc4qcy0pv8a2bzng8nf4s5rf5phfang4jwy9rgf808q0nxf"; + }; + } + { + goPackagePath = "github.com/gomodule/redigo"; + fetch = { + type = "git"; + url = "https://github.com/gomodule/redigo"; + rev = "v2.0.0"; + sha256 = "1kg7s8027b4g1sfw0v3nh30c15j407kv684s53gg281r807dnfpk"; + }; + } + { + goPackagePath = "github.com/gorilla/context"; + fetch = { + type = "git"; + url = "https://github.com/gorilla/context"; + rev = "v1.1.1"; + sha256 = "03p4hn87vcmfih0p9w663qbx9lpsf7i7j3lc7yl7n84la3yz63m4"; + }; + } + { + goPackagePath = "github.com/gorilla/handlers"; + fetch = { + type = "git"; + url = "https://github.com/gorilla/handlers"; + rev = "v1.4.0"; + sha256 = "0mnw81ayjm4d8462qg8spmcwxmchn24158bf93zxjab51pg8n9gm"; + }; + } + { + goPackagePath = "github.com/gorilla/mux"; + fetch = { + type = "git"; + url = "https://github.com/gorilla/mux"; + rev = "v1.6.2"; + sha256 = "0pvzm23hklxysspnz52mih6h1q74vfrdhjfm1l3sa9r8hhqmmld2"; + }; + } + { + goPackagePath = "github.com/kr/logfmt"; + fetch = { + type = "git"; + url = "https://github.com/kr/logfmt"; + rev = "b84e30acd515"; + sha256 = "02ldzxgznrfdzvghfraslhgp19la1fczcbzh7wm2zdc6lmpd1qq9"; + }; + } + { + goPackagePath = "github.com/matttproud/golang_protobuf_extensions"; + fetch = { + type = "git"; + url = "https://github.com/matttproud/golang_protobuf_extensions"; + rev = "v1.0.1"; + sha256 = "1d0c1isd2lk9pnfq2nk0aih356j30k3h1gi2w0ixsivi5csl7jya"; + }; + } + { + goPackagePath = "github.com/pkg/errors"; + fetch = { + type = "git"; + url = "https://github.com/pkg/errors"; + rev = "v0.8.0"; + sha256 = "001i6n71ghp2l6kdl3qq1v2vmghcz3kicv9a5wgcihrzigm75pp5"; + }; + } + { + goPackagePath = "github.com/prometheus/client_golang"; + fetch = { + type = "git"; + url = "https://github.com/prometheus/client_golang"; + rev = "v0.9.1"; + sha256 = "01gnylazia30pcp069xcng482gwmm3xcx5zgrlwdkhic1lyb6i9l"; + }; + } + { + goPackagePath = "github.com/prometheus/client_model"; + fetch = { + type = "git"; + url = "https://github.com/prometheus/client_model"; + rev = "5c3871d89910"; + sha256 = "04psf81l9fjcwascsys428v03fx4fi894h7fhrj2vvcz723q57k0"; + }; + } + { + goPackagePath = "github.com/prometheus/common"; + fetch = { + type = "git"; + url = "https://github.com/prometheus/common"; + rev = "4724e9255275"; + sha256 = "0pcx8hlnrxx5nnmpk786cn99rsgqk1jrd3c9f6fsx8qd8y5iwjy6"; + }; + } + { + goPackagePath = "github.com/prometheus/procfs"; + fetch = { + type = "git"; + url = "https://github.com/prometheus/procfs"; + rev = "1dc9a6cbc91a"; + sha256 = "1zlv1x30xp7z5c3vn5vp870v4bjim0zcidzc3mr2l3xhazc0svab"; + }; + } + { + goPackagePath = "github.com/yuin/gopher-lua"; + fetch = { + type = "git"; + url = "https://github.com/yuin/gopher-lua"; + rev = "a0dfe84f6227"; + sha256 = "13k2dphx4zv6fwgqsydsc0g0b0pf7qx3yb6i7hai6nnkh0db91nn"; + }; + } + { + goPackagePath = "golang.org/x/sys"; + fetch = { + type = "git"; + url = "https://go.googlesource.com/sys"; + rev = "a5c9d58dba9a"; + sha256 = "02qv5i7yps35p7fa81345qz7k8i73gkigj69anwmpw9rhpmzayf9"; + }; + } + { + goPackagePath = "gopkg.in/natefinch/lumberjack.v2"; + fetch = { + type = "git"; + url = "https://gopkg.in/natefinch/lumberjack.v2"; + rev = "a96e63847dc3"; + sha256 = "1l3vlv72b7rfkpy1164kwd3qzrqmmjnb67akzxqp2mlvc66k6p3d"; + }; + } +] diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index b23103f5b68..f29fc065831 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -16679,6 +16679,8 @@ in tpacpi-bat = callPackage ../os-specific/linux/tpacpi-bat { }; + trickster = callPackage ../servers/trickster/trickster.nix {}; + trinity = callPackage ../os-specific/linux/trinity { }; tunctl = callPackage ../os-specific/linux/tunctl { }; From 9b0aefac86e743bded74688773e15744f761678c Mon Sep 17 00:00:00 2001 From: Jan Hrnko Date: Fri, 1 Nov 2019 10:57:29 +0100 Subject: [PATCH 2/3] nixos/trickster: init --- nixos/modules/module-list.nix | 1 + .../modules/services/networking/trickster.nix | 112 ++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 nixos/modules/services/networking/trickster.nix diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 13a7867b772..e71d7374f7a 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -713,6 +713,7 @@ ./services/networking/tinc.nix ./services/networking/tinydns.nix ./services/networking/tftpd.nix + ./services/networking/trickster.nix ./services/networking/tox-bootstrapd.nix ./services/networking/tox-node.nix ./services/networking/toxvpn.nix diff --git a/nixos/modules/services/networking/trickster.nix b/nixos/modules/services/networking/trickster.nix new file mode 100644 index 00000000000..8760dd5a938 --- /dev/null +++ b/nixos/modules/services/networking/trickster.nix @@ -0,0 +1,112 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.services.trickster; +in +{ + + options = { + services.trickster = { + enable = mkOption { + type = types.bool; + default = false; + description = '' + Enable Trickster. + ''; + }; + + package = mkOption { + type = types.package; + default = pkgs.trickster; + defaultText = "pkgs.trickster"; + description = '' + Package that should be used for trickster. + ''; + }; + + configFile = mkOption { + type = types.nullOr types.path; + default = null; + description = '' + Path to configuration file. + ''; + }; + + instance-id = mkOption { + type = types.nullOr types.int; + default = null; + description = '' + Instance ID for when running multiple processes (default null). + ''; + }; + + log-level = mkOption { + type = types.str; + default = "info"; + description = '' + Level of Logging to use (debug, info, warn, error) (default "info"). + ''; + }; + + metrics-port = mkOption { + type = types.port; + default = 8082; + description = '' + Port that the /metrics endpoint will listen on. + ''; + }; + + origin = mkOption { + type = types.str; + default = "http://prometheus:9090"; + description = '' + URL to the Prometheus Origin. Enter it like you would in grafana, e.g., http://prometheus:9090 (default http://prometheus:9090). + ''; + }; + + profiler-port = mkOption { + type = types.nullOr types.port; + default = null; + description = '' + Port that the /debug/pprof endpoint will listen on. + ''; + }; + + proxy-port = mkOption { + type = types.port; + default = 9090; + description = '' + Port that the Proxy server will listen on. + ''; + }; + + }; + }; + + config = mkIf cfg.enable { + systemd.services.trickster = { + description = "Dashboard Accelerator for Prometheus"; + after = [ "network.target" ]; + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + DynamicUser = true; + ExecStart = '' + ${cfg.package}/bin/trickster \ + -log-level ${cfg.log-level} \ + -metrics-port ${toString cfg.metrics-port} \ + -origin ${cfg.origin} \ + -proxy-port ${toString cfg.proxy-port} \ + ${optionalString (cfg.configFile != null) "-config ${cfg.configFile}"} \ + ${optionalString (cfg.profiler-port != null) "-profiler-port ${cfg.profiler-port}"} \ + ${optionalString (cfg.instance-id != null) "-instance-id ${cfg.instance-id}"} + ''; + ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID"; + Restart = "always"; + }; + }; + + }; +} + From 4adb3dd7decf722c69792c92a425c796328a7da0 Mon Sep 17 00:00:00 2001 From: Jan Hrnko Date: Fri, 1 Nov 2019 11:03:23 +0100 Subject: [PATCH 3/3] nixos/trickster: add test --- nixos/tests/all-tests.nix | 1 + nixos/tests/trickster.nix | 29 ++++++++++++++++++++++++++++ pkgs/servers/trickster/trickster.nix | 2 +- 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 nixos/tests/trickster.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 694376b9d36..a407ec1ac22 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -276,6 +276,7 @@ in tor = handleTest ./tor.nix {}; transmission = handleTest ./transmission.nix {}; trezord = handleTest ./trezord.nix {}; + trickster = handleTest ./trickster.nix {}; udisks2 = handleTest ./udisks2.nix {}; upnp = handleTest ./upnp.nix {}; uwsgi = handleTest ./uwsgi.nix {}; diff --git a/nixos/tests/trickster.nix b/nixos/tests/trickster.nix new file mode 100644 index 00000000000..1461a32bb07 --- /dev/null +++ b/nixos/tests/trickster.nix @@ -0,0 +1,29 @@ +import ./make-test.nix ({ pkgs, ... }: { + name = "trickster"; + meta = with pkgs.stdenv.lib.maintainers; { + maintainers = [ "1000101" ]; + }; + + nodes = { + prometheus = { ... }: { + services.prometheus.enable = true; + networking.firewall.allowedTCPPorts = [ 9090 ]; + }; + trickster = { ... }: { + services.trickster.enable = true; + }; + }; + + testScript = '' + startAll; + $prometheus->waitForUnit("prometheus.service"); + $prometheus->waitForOpenPort(9090); + $prometheus->waitUntilSucceeds("curl -L http://localhost:9090/metrics | grep 'promhttp_metric_handler_requests_total{code=\"500\"} 0'"); + $trickster->waitForUnit("trickster.service"); + $trickster->waitForOpenPort(8082); + $trickster->waitForOpenPort(9090); + $trickster->waitUntilSucceeds("curl -L http://localhost:8082/metrics | grep 'promhttp_metric_handler_requests_total{code=\"500\"} 0'"); + $trickster->waitUntilSucceeds("curl -L http://prometheus:9090/metrics | grep 'promhttp_metric_handler_requests_total{code=\"500\"} 0'"); + $trickster->waitUntilSucceeds("curl -L http://localhost:9090/metrics | grep 'promhttp_metric_handler_requests_total{code=\"500\"} 0'"); + ''; +}) \ No newline at end of file diff --git a/pkgs/servers/trickster/trickster.nix b/pkgs/servers/trickster/trickster.nix index c219300ca21..3c03193e770 100644 --- a/pkgs/servers/trickster/trickster.nix +++ b/pkgs/servers/trickster/trickster.nix @@ -22,6 +22,6 @@ buildGoPackage rec { homepage = "https://github.com/Comcast/trickster"; license = licenses.asl20; maintainers = with maintainers; [ maintainers."1000101" ]; - platforms = platforms.linux; + platforms = platforms.all; }; } \ No newline at end of file