Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NixOS/nixpkgs
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: a6e50716bd5d
Choose a base ref
...
head repository: NixOS/nixpkgs
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 3b57908018df
Choose a head ref
  • 4 commits
  • 7 files changed
  • 2 contributors

Commits on Jan 2, 2021

  1. Copy the full SHA
    d539517 View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    3f94c66 View commit details

Commits on Jan 3, 2021

  1. nixos/prometheus-exporters: minor doc improvements

    * Content of `programlisting` shouldn't be indented, otherwise it's
      weirdly indented in the output.
    * Use `<xref linkend=.../>` in the release notes: then users can
      directly go to the option documentation when reading release notes.
    * Don't use docbook tags in `mkRemovedOptionModule`: it's only used
      during evaluation where docbook isn't rendered.
    Ma27 committed Jan 3, 2021
    Copy the full SHA
    6e43cc7 View commit details
  2. Merge pull request #108179 from WilliButz/update/prometheus-json-expo…

    …rter/0.2.0
    
    prometheus-json-exporter: unstable-2017-10-06 -> 0.2.0
    Ma27 authored Jan 3, 2021
    Copy the full SHA
    3b57908 View commit details
26 changes: 26 additions & 0 deletions nixos/doc/manual/release-notes/rl-2103.xml
Original file line number Diff line number Diff line change
@@ -309,6 +309,32 @@
Based on <xref linkend="opt-system.stateVersion" />, existing installations will continue to work.
</para>
</listitem>
<listitem>
<para>
The prometheus json exporter is now managed by the prometheus community. Together with additional features
some backwards incompatibilities were introduced.
Most importantly the exporter no longer accepts a fixed command-line parameter to specify the URL of the
endpoint serving JSON. It now expects this URL to be passed as an URL parameter, when scraping the exporter's
<literal>/probe</literal> endpoint.
In the prometheus scrape configuration the scrape target might look like this:
<programlisting>
http://some.json-exporter.host:7979/probe?target=https://example.com/some/json/endpoint
</programlisting>
</para>
<para>
Existing configuration for the exporter needs to be updated, but can partially be re-used.
Documentation is available in the upstream repository and a small example for NixOS is available
in the corresponding NixOS test.
</para>
<para>
These changes also affect <xref linkend="opt-services.prometheus.exporters.rspamd.enable" />, which is
just a preconfigured instance of the json exporter.
</para>
<para>
For more information, take a look at the <link xlink:href="https://github.com/prometheus-community/json_exporter">
official documentation</link> of the json_exporter.
</para>
</listitem>
</itemizedlist>
</section>

2 changes: 0 additions & 2 deletions nixos/modules/services/monitoring/prometheus/exporters.nix
Original file line number Diff line number Diff line change
@@ -236,8 +236,6 @@ in
services.prometheus.exporters.minio.minioAddress = mkDefault "http://localhost:9000";
services.prometheus.exporters.minio.minioAccessKey = mkDefault config.services.minio.accessKey;
services.prometheus.exporters.minio.minioAccessSecret = mkDefault config.services.minio.secretKey;
})] ++ [(mkIf config.services.rspamd.enable {
services.prometheus.exporters.rspamd.url = mkDefault "http://localhost:11334/stat";
})] ++ [(mkIf config.services.prometheus.exporters.rtl_433.enable {
hardware.rtl-sdr.enable = mkDefault true;
})] ++ [(mkIf config.services.nginx.enable {
28 changes: 18 additions & 10 deletions nixos/modules/services/monitoring/prometheus/exporters/json.nix
Original file line number Diff line number Diff line change
@@ -8,28 +8,36 @@ in
{
port = 7979;
extraOpts = {
url = mkOption {
type = types.str;
description = ''
URL to scrape JSON from.
'';
};
configFile = mkOption {
type = types.path;
description = ''
Path to configuration file.
'';
};
listenAddress = {}; # not used
};
serviceOpts = {
serviceConfig = {
ExecStart = ''
${pkgs.prometheus-json-exporter}/bin/prometheus-json-exporter \
--port ${toString cfg.port} \
${cfg.url} ${escapeShellArg cfg.configFile} \
${pkgs.prometheus-json-exporter}/bin/json_exporter \
--config.file ${escapeShellArg cfg.configFile} \
--web.listen-address="${cfg.listenAddress}:${toString cfg.port}" \
${concatStringsSep " \\\n " cfg.extraFlags}
'';
};
};
imports = [
(mkRemovedOptionModule [ "url" ] ''
This option was removed. The URL of the endpoint serving JSON
must now be provided to the exporter by prometheus via the url
parameter `target'.
In prometheus a scrape URL would look like this:
http://some.json-exporter.host:7979/probe?target=https://example.com/some/json/endpoint
For more information, take a look at the official documentation
(https://github.com/prometheus-community/json_exporter) of the json_exporter.
'')
({ options.warnings = options.warnings; options.assertions = options.assertions; })
];
}
121 changes: 64 additions & 57 deletions nixos/modules/services/monitoring/prometheus/exporters/rspamd.nix
Original file line number Diff line number Diff line change
@@ -10,64 +10,55 @@ let
echo '${builtins.toJSON conf}' | ${pkgs.buildPackages.jq}/bin/jq '.' > $out
'';

generateConfig = extraLabels: (map (path: {
name = "rspamd_${replaceStrings [ "." " " ] [ "_" "_" ] path}";
path = "$.${path}";
labels = extraLabels;
}) [
"actions.'add header'"
"actions.'no action'"
"actions.'rewrite subject'"
"actions.'soft reject'"
"actions.greylist"
"actions.reject"
"bytes_allocated"
"chunks_allocated"
"chunks_freed"
"chunks_oversized"
"connections"
"control_connections"
"ham_count"
"learned"
"pools_allocated"
"pools_freed"
"read_only"
"scanned"
"shared_chunks_allocated"
"spam_count"
"total_learns"
]) ++ [{
name = "rspamd_statfiles";
type = "object";
path = "$.statfiles[*]";
labels = recursiveUpdate {
symbol = "$.symbol";
type = "$.type";
} extraLabels;
values = {
revision = "$.revision";
size = "$.size";
total = "$.total";
used = "$.used";
languages = "$.languages";
users = "$.users";
};
}];
generateConfig = extraLabels: {
metrics = (map (path: {
name = "rspamd_${replaceStrings [ "." " " ] [ "_" "_" ] path}";
path = "$.${path}";
labels = extraLabels;
}) [
"actions.'add header'"
"actions.'no action'"
"actions.'rewrite subject'"
"actions.'soft reject'"
"actions.greylist"
"actions.reject"
"bytes_allocated"
"chunks_allocated"
"chunks_freed"
"chunks_oversized"
"connections"
"control_connections"
"ham_count"
"learned"
"pools_allocated"
"pools_freed"
"read_only"
"scanned"
"shared_chunks_allocated"
"spam_count"
"total_learns"
]) ++ [{
name = "rspamd_statfiles";
type = "object";
path = "$.statfiles[*]";
labels = recursiveUpdate {
symbol = "$.symbol";
type = "$.type";
} extraLabels;
values = {
revision = "$.revision";
size = "$.size";
total = "$.total";
used = "$.used";
languages = "$.languages";
users = "$.users";
};
}];
};
in
{
port = 7980;
extraOpts = {
listenAddress = {}; # not used

url = mkOption {
type = types.str;
description = ''
URL to the rspamd metrics endpoint.
Defaults to http://localhost:11334/stat when
<option>services.rspamd.enable</option> is true.
'';
};

extraLabels = mkOption {
type = types.attrsOf types.str;
default = {
@@ -84,9 +75,25 @@ in
};
};
serviceOpts.serviceConfig.ExecStart = ''
${pkgs.prometheus-json-exporter}/bin/prometheus-json-exporter \
--port ${toString cfg.port} \
${cfg.url} ${prettyJSON (generateConfig cfg.extraLabels)} \
${pkgs.prometheus-json-exporter}/bin/json_exporter \
--config.file ${prettyJSON (generateConfig cfg.extraLabels)} \
--web.listen-address "${cfg.listenAddress}:${toString cfg.port}" \
${concatStringsSep " \\\n " cfg.extraFlags}
'';

imports = [
(mkRemovedOptionModule [ "url" ] ''
This option was removed. The URL of the rspamd metrics endpoint
must now be provided to the exporter by prometheus via the url
parameter `target'.
In prometheus a scrape URL would look like this:
http://some.rspamd-exporter.host:7980/probe?target=http://some.rspamd.host:11334/stat
For more information, take a look at the official documentation
(https://github.com/prometheus-community/json_exporter) of the json_exporter.
'')
({ options.warnings = options.warnings; options.assertions = options.assertions; })
];
}
15 changes: 9 additions & 6 deletions nixos/tests/prometheus-exporters.nix
Original file line number Diff line number Diff line change
@@ -222,10 +222,11 @@ let
exporterConfig = {
enable = true;
url = "http://localhost";
configFile = pkgs.writeText "json-exporter-conf.json" (builtins.toJSON [{
name = "json_test_metric";
path = "$.test";
}]);
configFile = pkgs.writeText "json-exporter-conf.json" (builtins.toJSON {
metrics = [
{ name = "json_test_metric"; path = "$.test"; }
];
});
};
metricProvider = {
systemd.services.prometheus-json-exporter.after = [ "nginx.service" ];
@@ -241,7 +242,9 @@ let
wait_for_open_port(80)
wait_for_unit("prometheus-json-exporter.service")
wait_for_open_port(7979)
succeed("curl -sSf localhost:7979/metrics | grep -q 'json_test_metric 1'")
succeed(
"curl -sSf 'localhost:7979/probe?target=http://localhost' | grep -q 'json_test_metric 1'"
)
'';
};

@@ -659,7 +662,7 @@ let
wait_for_open_port(11334)
wait_for_open_port(7980)
wait_until_succeeds(
"curl -sSf localhost:7980/metrics | grep -q 'rspamd_scanned{host=\"rspamd\"} 0'"
"curl -sSf 'localhost:7980/probe?target=http://localhost:11334/stat' | grep -q 'rspamd_scanned{host=\"rspamd\"} 0'"
)
'';
};
26 changes: 9 additions & 17 deletions pkgs/servers/monitoring/prometheus/json-exporter.nix
Original file line number Diff line number Diff line change
@@ -1,31 +1,23 @@
# This file was generated by go2nix.
{ buildGoPackage, fetchFromGitHub, fetchpatch, lib, nixosTests }:
{ lib, buildGoModule, fetchFromGitHub, nixosTests }:

buildGoPackage {
buildGoModule rec {
pname = "prometheus-json-exporter";
version = "unstable-2017-10-06";

goPackagePath = "github.com/kawamuray/prometheus-json-exporter";
version = "0.2.0";

src = fetchFromGitHub {
owner = "kawamuray";
repo = "prometheus-json-exporter";
rev = "51e3dc02a30ab818bb73e5c98c3853231c2dbb5f";
sha256 = "1v1p4zcqnb3d3rm55r695ydn61h6gz95f55cpa22hzw18dasahdh";
owner = "prometheus-community";
repo = "json_exporter";
rev = "v${version}";
sha256 = "1aabvd75a2223x5wnbyryigj7grw6l05jhr3g3s97b1f1hfigz6d";
};

goDeps = ./json-exporter_deps.nix;

patches = [(fetchpatch { # adds bool support
url = "https://patch-diff.githubusercontent.com/raw/kawamuray/prometheus-json-exporter/pull/17.patch";
sha256 = "0mc5axhd2bykci41dgswl4r1552d70jsmb17lbih7czhsy6rgmrm";
})];
vendorSha256 = "03kb0gklq08krl7qnvs7267siw1pkyy346b42dsk1d9gr5302wsw";

passthru.tests = { inherit (nixosTests.prometheus-exporters) json; };

meta = with lib; {
description = "A prometheus exporter which scrapes remote JSON by JSONPath";
homepage = "https://github.com/kawamuray/prometheus-json-exporter";
homepage = "https://github.com/prometheus-community/json_exporter";
license = licenses.asl20;
maintainers = with maintainers; [ willibutz ];
};
111 changes: 0 additions & 111 deletions pkgs/servers/monitoring/prometheus/json-exporter_deps.nix

This file was deleted.