git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #108179 from WilliButz/update/prometheus-json-exporter/0.2.0

prometheus-json-exporter: unstable-2017-10-06 -> 0.2.0

commit3b57908018dfb72fbacd60b25d5fd326f02087d5 authorMaximilian Bosch <maximilian@mbosch.me> dateSun 3 Jan 2021, 19:28 (6 years ago) parenta6e50716e43cc7
7 files changed+126−203
nixos/doc/manual/release-notes/rl-2103.xml+26 nixos/modules/services/monitoring/prometheus/exporters.nix−2 nixos/modules/services/monitoring/prometheus/exporters/json.nix+18−10 nixos/modules/services/monitoring/prometheus/exporters/rspamd.nix+64−57 nixos/tests/prometheus-exporters.nix+9−6 pkgs/servers/monitoring/prometheus/json-exporter.nix+9−17 pkgs/servers/monitoring/prometheus/json-exporter_deps.nix−111
nixos/doc/manual/release-notes/rl-2103.xml+26
@@ -309,6 +309,32 @@
309309 Based on <xref linkend="opt-system.stateVersion" />, existing installations will continue to work.
310310 </para>
311311 </listitem>
312+ <listitem>
313+ <para>
314+ The prometheus json exporter is now managed by the prometheus community. Together with additional features
315+ some backwards incompatibilities were introduced.
316+ Most importantly the exporter no longer accepts a fixed command-line parameter to specify the URL of the
317+ endpoint serving JSON. It now expects this URL to be passed as an URL parameter, when scraping the exporter's
318+ <literal>/probe</literal> endpoint.
319+ In the prometheus scrape configuration the scrape target might look like this:
320+ <programlisting>
321+http://some.json-exporter.host:7979/probe?target=https://example.com/some/json/endpoint
322+ </programlisting>
323+ </para>
324+ <para>
325+ Existing configuration for the exporter needs to be updated, but can partially be re-used.
326+ Documentation is available in the upstream repository and a small example for NixOS is available
327+ in the corresponding NixOS test.
328+ </para>
329+ <para>
330+ These changes also affect <xref linkend="opt-services.prometheus.exporters.rspamd.enable" />, which is
331+ just a preconfigured instance of the json exporter.
332+ </para>
333+ <para>
334+ For more information, take a look at the <link xlink:href="https://github.com/prometheus-community/json_exporter">
335+ official documentation</link> of the json_exporter.
336+ </para>
337+ </listitem>
312338 </itemizedlist>
313339 </section>
314340
nixos/modules/services/monitoring/prometheus/exporters.nix−2
@@ -236,8 +236,6 @@ in
236236 services.prometheus.exporters.minio.minioAddress = mkDefault "http://localhost:9000";
237237 services.prometheus.exporters.minio.minioAccessKey = mkDefault config.services.minio.accessKey;
238238 services.prometheus.exporters.minio.minioAccessSecret = mkDefault config.services.minio.secretKey;
239− })] ++ [(mkIf config.services.rspamd.enable {
240− services.prometheus.exporters.rspamd.url = mkDefault "http://localhost:11334/stat";
241239 })] ++ [(mkIf config.services.prometheus.exporters.rtl_433.enable {
242240 hardware.rtl-sdr.enable = mkDefault true;
243241 })] ++ [(mkIf config.services.nginx.enable {
nixos/modules/services/monitoring/prometheus/exporters/json.nix+18−10
@@ -8,28 +8,36 @@ in
88{
99 port = 7979;
1010 extraOpts = {
11− url = mkOption {
12− type = types.str;
13− description = ''
14− URL to scrape JSON from.
15− '';
16− };
1711 configFile = mkOption {
1812 type = types.path;
1913 description = ''
2014 Path to configuration file.
2115 '';
2216 };
23− listenAddress = {}; # not used
2417 };
2518 serviceOpts = {
2619 serviceConfig = {
2720 ExecStart = ''
28− ${pkgs.prometheus-json-exporter}/bin/prometheus-json-exporter \
29− --port ${toString cfg.port} \
30− ${cfg.url} ${escapeShellArg cfg.configFile} \
21+ ${pkgs.prometheus-json-exporter}/bin/json_exporter \
22+ --config.file ${escapeShellArg cfg.configFile} \
23+ --web.listen-address="${cfg.listenAddress}:${toString cfg.port}" \
3124 ${concatStringsSep " \\\n " cfg.extraFlags}
3225 '';
3326 };
3427 };
28+ imports = [
29+ (mkRemovedOptionModule [ "url" ] ''
30+ This option was removed. The URL of the endpoint serving JSON
31+ must now be provided to the exporter by prometheus via the url
32+ parameter `target'.
33+
34+ In prometheus a scrape URL would look like this:
35+
36+ http://some.json-exporter.host:7979/probe?target=https://example.com/some/json/endpoint
37+
38+ For more information, take a look at the official documentation
39+ (https://github.com/prometheus-community/json_exporter) of the json_exporter.
40+ '')
41+ ({ options.warnings = options.warnings; options.assertions = options.assertions; })
42+ ];
3543}
nixos/modules/services/monitoring/prometheus/exporters/rspamd.nix+64−57
@@ -10,64 +10,55 @@ let
1010 echo '${builtins.toJSON conf}' | ${pkgs.buildPackages.jq}/bin/jq '.' > $out
1111 '';
1212
13− generateConfig = extraLabels: (map (path: {
14− name = "rspamd_${replaceStrings [ "." " " ] [ "_" "_" ] path}";
15− path = "$.${path}";
16− labels = extraLabels;
17− }) [
18− "actions.'add header'"
19− "actions.'no action'"
20− "actions.'rewrite subject'"
21− "actions.'soft reject'"
22− "actions.greylist"
23− "actions.reject"
24− "bytes_allocated"
25− "chunks_allocated"
26− "chunks_freed"
27− "chunks_oversized"
28− "connections"
29− "control_connections"
30− "ham_count"
31− "learned"
32− "pools_allocated"
33− "pools_freed"
34− "read_only"
35− "scanned"
36− "shared_chunks_allocated"
37− "spam_count"
38− "total_learns"
39− ]) ++ [{
40− name = "rspamd_statfiles";
41− type = "object";
42− path = "$.statfiles[*]";
43− labels = recursiveUpdate {
44− symbol = "$.symbol";
45− type = "$.type";
46− } extraLabels;
47− values = {
48− revision = "$.revision";
49− size = "$.size";
50− total = "$.total";
51− used = "$.used";
52− languages = "$.languages";
53− users = "$.users";
54− };
55− }];
13+ generateConfig = extraLabels: {
14+ metrics = (map (path: {
15+ name = "rspamd_${replaceStrings [ "." " " ] [ "_" "_" ] path}";
16+ path = "$.${path}";
17+ labels = extraLabels;
18+ }) [
19+ "actions.'add header'"
20+ "actions.'no action'"
21+ "actions.'rewrite subject'"
22+ "actions.'soft reject'"
23+ "actions.greylist"
24+ "actions.reject"
25+ "bytes_allocated"
26+ "chunks_allocated"
27+ "chunks_freed"
28+ "chunks_oversized"
29+ "connections"
30+ "control_connections"
31+ "ham_count"
32+ "learned"
33+ "pools_allocated"
34+ "pools_freed"
35+ "read_only"
36+ "scanned"
37+ "shared_chunks_allocated"
38+ "spam_count"
39+ "total_learns"
40+ ]) ++ [{
41+ name = "rspamd_statfiles";
42+ type = "object";
43+ path = "$.statfiles[*]";
44+ labels = recursiveUpdate {
45+ symbol = "$.symbol";
46+ type = "$.type";
47+ } extraLabels;
48+ values = {
49+ revision = "$.revision";
50+ size = "$.size";
51+ total = "$.total";
52+ used = "$.used";
53+ languages = "$.languages";
54+ users = "$.users";
55+ };
56+ }];
57+ };
5658in
5759{
5860 port = 7980;
5961 extraOpts = {
60− listenAddress = {}; # not used
61−
62− url = mkOption {
63− type = types.str;
64− description = ''
65− URL to the rspamd metrics endpoint.
66− Defaults to http://localhost:11334/stat when
67− <option>services.rspamd.enable</option> is true.
68− '';
69− };
70−
7162 extraLabels = mkOption {
7263 type = types.attrsOf types.str;
7364 default = {
@@ -84,9 +75,25 @@ in
8475 };
8576 };
8677 serviceOpts.serviceConfig.ExecStart = ''
87− ${pkgs.prometheus-json-exporter}/bin/prometheus-json-exporter \
88− --port ${toString cfg.port} \
89− ${cfg.url} ${prettyJSON (generateConfig cfg.extraLabels)} \
78+ ${pkgs.prometheus-json-exporter}/bin/json_exporter \
79+ --config.file ${prettyJSON (generateConfig cfg.extraLabels)} \
80+ --web.listen-address "${cfg.listenAddress}:${toString cfg.port}" \
9081 ${concatStringsSep " \\\n " cfg.extraFlags}
9182 '';
83+
84+ imports = [
85+ (mkRemovedOptionModule [ "url" ] ''
86+ This option was removed. The URL of the rspamd metrics endpoint
87+ must now be provided to the exporter by prometheus via the url
88+ parameter `target'.
89+
90+ In prometheus a scrape URL would look like this:
91+
92+ http://some.rspamd-exporter.host:7980/probe?target=http://some.rspamd.host:11334/stat
93+
94+ For more information, take a look at the official documentation
95+ (https://github.com/prometheus-community/json_exporter) of the json_exporter.
96+ '')
97+ ({ options.warnings = options.warnings; options.assertions = options.assertions; })
98+ ];
9299}
nixos/tests/prometheus-exporters.nix+9−6
@@ -222,10 +222,11 @@ let
222222 exporterConfig = {
223223 enable = true;
224224 url = "http://localhost";
225− configFile = pkgs.writeText "json-exporter-conf.json" (builtins.toJSON [{
226− name = "json_test_metric";
227− path = "$.test";
228− }]);
225+ configFile = pkgs.writeText "json-exporter-conf.json" (builtins.toJSON {
226+ metrics = [
227+ { name = "json_test_metric"; path = "$.test"; }
228+ ];
229+ });
229230 };
230231 metricProvider = {
231232 systemd.services.prometheus-json-exporter.after = [ "nginx.service" ];
@@ -241,7 +242,9 @@ let
241242 wait_for_open_port(80)
242243 wait_for_unit("prometheus-json-exporter.service")
243244 wait_for_open_port(7979)
244− succeed("curl -sSf localhost:7979/metrics | grep -q 'json_test_metric 1'")
245+ succeed(
246+ "curl -sSf 'localhost:7979/probe?target=http://localhost' | grep -q 'json_test_metric 1'"
247+ )
245248 '';
246249 };
247250
@@ -659,7 +662,7 @@ let
659662 wait_for_open_port(11334)
660663 wait_for_open_port(7980)
661664 wait_until_succeeds(
662− "curl -sSf localhost:7980/metrics | grep -q 'rspamd_scanned{host=\"rspamd\"} 0'"
665+ "curl -sSf 'localhost:7980/probe?target=http://localhost:11334/stat' | grep -q 'rspamd_scanned{host=\"rspamd\"} 0'"
663666 )
664667 '';
665668 };
pkgs/servers/monitoring/prometheus/json-exporter.nix+9−17
@@ -1,31 +1,23 @@
1−# This file was generated by go2nix.
2−{ buildGoPackage, fetchFromGitHub, fetchpatch, lib, nixosTests }:
1+{ lib, buildGoModule, fetchFromGitHub, nixosTests }:
32
4−buildGoPackage {
3+buildGoModule rec {
54 pname = "prometheus-json-exporter";
6− version = "unstable-2017-10-06";
7−
8− goPackagePath = "github.com/kawamuray/prometheus-json-exporter";
5+ version = "0.2.0";
96
107 src = fetchFromGitHub {
11− owner = "kawamuray";
12− repo = "prometheus-json-exporter";
13− rev = "51e3dc02a30ab818bb73e5c98c3853231c2dbb5f";
14− sha256 = "1v1p4zcqnb3d3rm55r695ydn61h6gz95f55cpa22hzw18dasahdh";
8+ owner = "prometheus-community";
9+ repo = "json_exporter";
10+ rev = "v${version}";
11+ sha256 = "1aabvd75a2223x5wnbyryigj7grw6l05jhr3g3s97b1f1hfigz6d";
1512 };
1613
17− goDeps = ./json-exporter_deps.nix;
18−
19− patches = [(fetchpatch { # adds bool support
20− url = "https://patch-diff.githubusercontent.com/raw/kawamuray/prometheus-json-exporter/pull/17.patch";
21− sha256 = "0mc5axhd2bykci41dgswl4r1552d70jsmb17lbih7czhsy6rgmrm";
22− })];
14+ vendorSha256 = "03kb0gklq08krl7qnvs7267siw1pkyy346b42dsk1d9gr5302wsw";
2315
2416 passthru.tests = { inherit (nixosTests.prometheus-exporters) json; };
2517
2618 meta = with lib; {
2719 description = "A prometheus exporter which scrapes remote JSON by JSONPath";
28− homepage = "https://github.com/kawamuray/prometheus-json-exporter";
20+ homepage = "https://github.com/prometheus-community/json_exporter";
2921 license = licenses.asl20;
3022 maintainers = with maintainers; [ willibutz ];
3123 };
pkgs/servers/monitoring/prometheus/json-exporter_deps.nixdeleted−111
@@ -1,111 +0,0 @@
1−# This file was generated by go2nix.
2−[
3− {
4− goPackagePath = "github.com/Sirupsen/logrus";
5− fetch = {
6− type = "git";
7− url = "https://github.com/Sirupsen/logrus";
8− rev = "a437dfd2463eaedbec3dfe443e477d3b0a810b3f";
9− sha256 = "1904s2bbc7p88anzjp6fyj3jrbm5p6wbb8j4490674dq10kkcfbj";
10− };
11− }
12− {
13− goPackagePath = "github.com/beorn7/perks";
14− fetch = {
15− type = "git";
16− url = "https://github.com/beorn7/perks";
17− rev = "4c0e84591b9aa9e6dcfdf3e020114cd81f89d5f9";
18− sha256 = "1hrybsql68xw57brzj805xx2mghydpdiysv3gbhr7f5wlxj2514y";
19− };
20− }
21− {
22− goPackagePath = "github.com/golang/protobuf";
23− fetch = {
24− type = "git";
25− url = "https://github.com/golang/protobuf";
26− rev = "8ee79997227bf9b34611aee7946ae64735e6fd93";
27− sha256 = "0qm1lpdhf97k2hxgivq2cpjgawhlmmz39y230kgxijhm96xijxb8";
28− };
29− }
30− {
31− goPackagePath = "github.com/kawamuray/jsonpath";
32− fetch = {
33− type = "git";
34− url = "https://github.com/kawamuray/jsonpath";
35− rev = "5c448ebf973557834ef870e788b0b2d95ac68d12";
36− sha256 = "1i1id1i85rf09rldp03h0ibyi6zg0fz9p9l5qj7i8dfs6h6y8f0a";
37− };
38− }
39− {
40− goPackagePath = "github.com/kawamuray/prometheus-exporter-harness";
41− fetch = {
42− type = "git";
43− url = "https://github.com/kawamuray/prometheus-exporter-harness";
44− rev = "97eeea7b8b0619ea2a065d75c0f0f5909327afa6";
45− sha256 = "12al8irf8jb6p2xmm4wbh0wjqsyrdywynr4w122wxxnsx2n56xyv";
46− };
47− }
48− {
49− goPackagePath = "github.com/matttproud/golang_protobuf_extensions";
50− fetch = {
51− type = "git";
52− url = "https://github.com/matttproud/golang_protobuf_extensions";
53− rev = "c12348ce28de40eed0136aa2b644d0ee0650e56c";
54− sha256 = "1d0c1isd2lk9pnfq2nk0aih356j30k3h1gi2w0ixsivi5csl7jya";
55− };
56− }
57− {
58− goPackagePath = "github.com/prometheus/client_golang";
59− fetch = {
60− type = "git";
61− url = "https://github.com/prometheus/client_golang";
62− rev = "575f371f7862609249a1be4c9145f429fe065e32";
63− sha256 = "0hyvszjv5m6i40k2fn21c3bjr8jhlfdqavk1r6g2v5dybyj47vps";
64− };
65− }
66− {
67− goPackagePath = "github.com/prometheus/client_model";
68− fetch = {
69− type = "git";
70− url = "https://github.com/prometheus/client_model";
71− rev = "fa8ad6fec33561be4280a8f0514318c79d7f6cb6";
72− sha256 = "11a7v1fjzhhwsl128znjcf5v7v6129xjgkdpym2lial4lac1dhm9";
73− };
74− }
75− {
76− goPackagePath = "github.com/prometheus/common";
77− fetch = {
78− type = "git";
79− url = "https://github.com/prometheus/common";
80− rev = "0d5de9d6d8629cb8bee6d4674da4127cd8b615a3";
81− sha256 = "1zlvvgw67p66fz9nswkydq15j4a5z5kkiskl0jxps8i27ya1baq0";
82− };
83− }
84− {
85− goPackagePath = "github.com/prometheus/procfs";
86− fetch = {
87− type = "git";
88− url = "https://github.com/prometheus/procfs";
89− rev = "abf152e5f3e97f2fafac028d2cc06c1feb87ffa5";
90− sha256 = "0cp8lznv1b4zhi3wnbjkfxwzhkqd3wbmiy6mwgjanip8l9l3ykws";
91− };
92− }
93− {
94− goPackagePath = "github.com/urfave/cli";
95− fetch = {
96− type = "git";
97− url = "https://github.com/urfave/cli";
98− rev = "0bdeddeeb0f650497d603c4ad7b20cfe685682f6";
99− sha256 = "1ny63c7bfwfrsp7vfkvb4i0xhq4v7yxqnwxa52y4xlfxs4r6v6fg";
100− };
101− }
102− {
103− goPackagePath = "gopkg.in/yaml.v2";
104− fetch = {
105− type = "git";
106− url = "https://gopkg.in/yaml.v2";
107− rev = "a5b47d31c556af34a302ce5d659e6fea44d90de0";
108− sha256 = "0v6l48fshdjrqzyq1kwn22gy7vy434xdr1i0lm3prsf6jbln9fam";
109− };
110− }
111−]