Skip to content
This repository was archived by the owner on Apr 12, 2021. It is now read-only.
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-channels
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 6866a74a851a
Choose a base ref
...
head repository: NixOS/nixpkgs-channels
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 31b53e0f4b59
Choose a head ref
  • 14 commits
  • 5 files changed
  • 4 contributors

Commits on Apr 17, 2019

  1. prometheus: add tls_config

    (cherry picked from commit da7aeb1)
    elohmeier authored and basvandijk committed Apr 17, 2019

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Copy the full SHA
    4713945 View commit details
  2. nixos/prometheus: add ec2_sd_configs section to scrape_configs

    (cherry picked from commit ad7e232)
    thefloweringash authored and basvandijk committed Apr 17, 2019

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Copy the full SHA
    67d1bcb View commit details
  3. nixos/prometheus: add new ec2_sd_config options for prometheus2

    (cherry picked from commit a23db5d)
    basvandijk committed Apr 17, 2019

    Verified

    This commit was signed with the committer’s verified signature.
    eadwu Edmund Wu
    Copy the full SHA
    84414b3 View commit details
  4. nixos/prometheus: filter out empty srcape_configs attributes

    This results in a smaller prometheus.yml config file.
    
    It also allows us to use the same options for both prometheus-1 and
    prometheus-2 since the new options for prometheus-2 default to null
    and will be filtered out if they are not set.
    
    (cherry picked from commit a913d08)
    basvandijk committed Apr 17, 2019

    Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    2a0742b View commit details

Commits on Apr 18, 2019

  1. Merge pull request #59769 from basvandijk/prometheus-ec2-release-19.03

    Backport prometheus ec2_sd_config and tls_config options to release-19.03
    basvandijk authored Apr 18, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    bcd5fe6 View commit details
  2. nixos/prometheus: filter out the _module attr in a central place

    We previously filtered out the `_module` attribute in a NixOS
    configuration by filtering it using the option's `apply` function.
    
    This meant that every option that had a submodule type needed to have
    this apply function. Adding this function is easy to forget thus this
    mechanism is error prone.
    
    We now recursively filter out the `_module` attributes at the place we
    construct the Prometheus configuration file. Since we now do the filtering
    centrally we don't have to do it per option making it less prone to errors.
    
    (cherry picked from commit 57e5b75)
    basvandijk committed Apr 18, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    c8e2dc0 View commit details
  3. nixos/prometheus: set optional attributes to type types.nullOr

    This makes sure that when a user hasn't set a Prometheus option it
    won't show up in the prometheus.yml configuration file. This results
    in smaller and easier to understand configuration files.
    
    (cherry picked from commit 55ef5d4)
    basvandijk committed Apr 18, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    3a253af View commit details
  4. nixos/prometheus: abstract over optional option creation

    (cherry picked from commit 285fd3c)
    basvandijk committed Apr 18, 2019
    Copy the full SHA
    cf44453 View commit details
  5. nixos/prometheus: add more missing options

    (cherry picked from commit cdd8268)
    basvandijk committed Apr 18, 2019
    Copy the full SHA
    c99b5b4 View commit details
  6. Merge pull request #59831 from basvandijk/prometheus-refactoring-rele…

    …ase-19.03
    
    Backport "nixos/prometheus: refactored & added more missing options" to release 19.03
    basvandijk authored Apr 18, 2019
    Copy the full SHA
    1cbe0fe View commit details
  7. prometheus-pushgateway: 0.4.0 -> 0.7.0

    Add some tests to make sure the --version output includes the values
    passed in with -X.
    
    Add myself as a maintainer.
    
    (cherry picked from commit 8b4b12e)
    ivan authored and basvandijk committed Apr 18, 2019
    Copy the full SHA
    ae14052 View commit details
  8. prometheus-pushgateway: 0.7.0 -> 0.8.0

    (cherry picked from commit b0fbe1d)
    basvandijk committed Apr 18, 2019
    Copy the full SHA
    a3178b0 View commit details
  9. nixos/prometheus/pushgateway: add module and test

    (cherry picked from commit d1940be)
    basvandijk committed Apr 18, 2019
    Copy the full SHA
    5776161 View commit details
  10. Merge pull request #59832 from basvandijk/prometheus-pushgateway-modu…

    …le-release-19.03
    
    Backport "Prometheus pushgateway 0.4.0 -> 0.8.0 & module" to release 19.03
    basvandijk authored Apr 18, 2019
    Copy the full SHA
    31b53e0 View commit details
1 change: 1 addition & 0 deletions nixos/modules/module-list.nix
Original file line number Diff line number Diff line change
@@ -479,6 +479,7 @@
./services/monitoring/prometheus/default.nix
./services/monitoring/prometheus/alertmanager.nix
./services/monitoring/prometheus/exporters.nix
./services/monitoring/prometheus/pushgateway.nix
./services/monitoring/riemann.nix
./services/monitoring/riemann-dash.nix
./services/monitoring/riemann-tools.nix
600 changes: 341 additions & 259 deletions nixos/modules/services/monitoring/prometheus/default.nix

Large diffs are not rendered by default.

166 changes: 166 additions & 0 deletions nixos/modules/services/monitoring/prometheus/pushgateway.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
{ config, pkgs, lib, ... }:

with lib;

let
cfg = config.services.prometheus.pushgateway;

cmdlineArgs =
opt "web.listen-address" cfg.web.listen-address
++ opt "web.telemetry-path" cfg.web.telemetry-path
++ opt "web.external-url" cfg.web.external-url
++ opt "web.route-prefix" cfg.web.route-prefix
++ optional cfg.persistMetrics ''--persistence.file="/var/lib/${cfg.stateDir}/metrics"''
++ opt "persistence.interval" cfg.persistence.interval
++ opt "log.level" cfg.log.level
++ opt "log.format" cfg.log.format
++ cfg.extraFlags;

opt = k : v : optional (v != null) ''--${k}="${v}"'';

in {
options = {
services.prometheus.pushgateway = {
enable = mkEnableOption "Prometheus Pushgateway";

package = mkOption {
type = types.package;
default = pkgs.prometheus-pushgateway;
defaultText = "pkgs.prometheus-pushgateway";
description = ''
Package that should be used for the prometheus pushgateway.
'';
};

web.listen-address = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
Address to listen on for the web interface, API and telemetry.
<literal>null</literal> will default to <literal>:9091</literal>.
'';
};

web.telemetry-path = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
Path under which to expose metrics.
<literal>null</literal> will default to <literal>/metrics</literal>.
'';
};

web.external-url = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
The URL under which Pushgateway is externally reachable.
'';
};

web.route-prefix = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
Prefix for the internal routes of web endpoints.
Defaults to the path of
<option>services.prometheus.pushgateway.web.external-url</option>.
'';
};

persistence.interval = mkOption {
type = types.nullOr types.str;
default = null;
example = "10m";
description = ''
The minimum interval at which to write out the persistence file.
<literal>null</literal> will default to <literal>5m</literal>.
'';
};

log.level = mkOption {
type = types.nullOr (types.enum ["debug" "info" "warn" "error" "fatal"]);
default = null;
description = ''
Only log messages with the given severity or above.
<literal>null</literal> will default to <literal>info</literal>.
'';
};

log.format = mkOption {
type = types.nullOr types.str;
default = null;
example = "logger:syslog?appname=bob&local=7";
description = ''
Set the log target and format.
<literal>null</literal> will default to <literal>logger:stderr</literal>.
'';
};

extraFlags = mkOption {
type = types.listOf types.str;
default = [];
description = ''
Extra commandline options when launching the Pushgateway.
'';
};

persistMetrics = mkOption {
type = types.bool;
default = false;
description = ''
Whether to persist metrics to a file.
When enabled metrics will be saved to a file called
<literal>metrics</literal> in the directory
<literal>/var/lib/pushgateway</literal>. The directory below
<literal>/var/lib</literal> can be set using
<option>services.prometheus.pushgateway.stateDir</option>.
'';
};

stateDir = mkOption {
type = types.str;
default = "pushgateway";
description = ''
Directory below <literal>/var/lib</literal> to store metrics.
This directory will be created automatically using systemd's
StateDirectory mechanism when
<option>services.prometheus.pushgateway.persistMetrics</option>
is enabled.
'';
};
};
};

config = mkIf cfg.enable {
assertions = [
{
assertion = !hasPrefix "/" cfg.stateDir;
message =
"The option services.prometheus.pushgateway.stateDir" +
" shouldn't be an absolute directory." +
" It should be a directory relative to /var/lib.";
}
];
systemd.services.pushgateway = {
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig = {
Restart = "always";
DynamicUser = true;
ExecStart = "${cfg.package}/bin/pushgateway" +
optionalString (length cmdlineArgs != 0) (" \\\n " +
concatStringsSep " \\\n " cmdlineArgs);
StateDirectory = if cfg.persistMetrics then cfg.stateDir else null;
};
};
};
}
47 changes: 40 additions & 7 deletions nixos/tests/prometheus-2.nix
Original file line number Diff line number Diff line change
@@ -3,15 +3,29 @@ import ./make-test.nix {

nodes = {
one = { pkgs, ... }: {
environment.systemPackages = [ pkgs.jq ];
services.prometheus2 = {
enable = true;
scrapeConfigs = [{
job_name = "prometheus";
static_configs = [{
targets = [ "127.0.0.1:9090" ];
labels = { instance = "localhost"; };
}];
}];
scrapeConfigs = [
{
job_name = "prometheus";
static_configs = [
{
targets = [ "127.0.0.1:9090" ];
labels = { instance = "localhost"; };
}
];
}
{
job_name = "pushgateway";
scrape_interval = "1s";
static_configs = [
{
targets = [ "127.0.0.1:9091" ];
}
];
}
];
rules = [
''
groups:
@@ -22,6 +36,12 @@ import ./make-test.nix {
''
];
};
services.prometheus.pushgateway = {
enable = true;
persistMetrics = true;
persistence.interval = "1s";
stateDir = "prometheus-pushgateway";
};
};
};

@@ -30,5 +50,18 @@ import ./make-test.nix {
$one->waitForUnit("prometheus2.service");
$one->waitForOpenPort(9090);
$one->succeed("curl -s http://127.0.0.1:9090/metrics");
# Let's test if pushing a metric to the pushgateway succeeds
# and whether that metric gets ingested by prometheus.
$one->waitForUnit("pushgateway.service");
$one->succeed(
"echo 'some_metric 3.14' | " .
"curl --data-binary \@- http://127.0.0.1:9091/metrics/job/some_job");
$one->waitUntilSucceeds(
"curl -sf 'http://127.0.0.1:9090/api/v1/query?query=some_metric' " .
"| jq '.data.result[0].value[1]' | grep '\"3.14\"'");
# Let's test if the pushgateway persists metrics to the configured location.
$one->waitUntilSucceeds("test -e /var/lib/prometheus-pushgateway/metrics");
'';
}
40 changes: 23 additions & 17 deletions pkgs/servers/monitoring/prometheus/pushgateway.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{ stdenv, go, buildGoPackage, go-bindata, fetchFromGitHub }:
{ stdenv, go, buildGoPackage, fetchFromGitHub }:

buildGoPackage rec {
name = "pushgateway-${version}";
version = "0.4.0";
version = "0.8.0";
rev = "v${version}";

goPackagePath = "github.com/prometheus/pushgateway";
@@ -11,33 +11,39 @@ buildGoPackage rec {
inherit rev;
owner = "prometheus";
repo = "pushgateway";
sha256 = "19hsv42addcx4dsjdbh64y7ggjvaaay9gag0342gz7gyl9sr719f";
sha256 = "1mzwkxnznv6wzy7dc8rksa8gr7z92plrzls8gb8rk432zfqcbv6a";
};

buildInputs = [ go-bindata ];

preBuild = ''
(
cd "go/src/$goPackagePath"
go-bindata ./resources/
)
'';
buildUser = "nix@nixpkgs";
buildDate = "19700101-00:00:00";

buildFlagsArray = ''
-ldflags=
-X main.buildVersion=${version}
-X main.buildRev=${rev}
-X main.buildBranch=${rev}
-X main.buildUser=nix@nixpkgs
-X main.buildDate=19700101-00:00:00
-X github.com/prometheus/pushgateway/vendor/github.com/prometheus/common/version.Version=${version}
-X github.com/prometheus/pushgateway/vendor/github.com/prometheus/common/version.Revision=${rev}
-X github.com/prometheus/pushgateway/vendor/github.com/prometheus/common/version.Branch=${rev}
-X github.com/prometheus/pushgateway/vendor/github.com/prometheus/common/version.BuildUser=${buildUser}
-X github.com/prometheus/pushgateway/vendor/github.com/prometheus/common/version.BuildDate=${buildDate}
-X main.goVersion=${stdenv.lib.getVersion go}
'';

doInstallCheck = true;
installCheckPhase = ''
export PATH=$PATH:$bin/bin
pushgateway --help
# Make sure our -X options were included in the build
for s in ${version} ${rev} ${buildUser} ${buildDate}; do
pushgateway --version 2>&1 | fgrep -q -- "$s" || { echo "pushgateway --version output missing $s"; exit 1; }
done
'';

meta = with stdenv.lib; {
description = "Allows ephemeral and batch jobs to expose metrics to Prometheus";
homepage = https://github.com/prometheus/pushgateway;
license = licenses.asl20;
maintainers = with maintainers; [ benley fpletz ];
maintainers = with maintainers; [ benley fpletz ivan ];
platforms = platforms.unix;
};
}