From 0f96aa4590ccc496acd3bb39a1e1b1dc53400037 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hendrik=20S=C3=B6bbing?= Date: Fri, 15 Dec 2023 16:06:23 +0100 Subject: [PATCH 1/4] Add influxdb module --- examples/influxdb/.test.sh | 22 ++++++++++++++++++++++ examples/influxdb/devenv.nix | 9 +++++++++ examples/influxdb/devenv.yaml | 3 +++ src/modules/services/influxdb.nix | 22 ++++++++++++++++++++++ 4 files changed, 56 insertions(+) create mode 100755 examples/influxdb/.test.sh create mode 100644 examples/influxdb/devenv.nix create mode 100644 examples/influxdb/devenv.yaml create mode 100644 src/modules/services/influxdb.nix diff --git a/examples/influxdb/.test.sh b/examples/influxdb/.test.sh new file mode 100755 index 000000000..2b345dba0 --- /dev/null +++ b/examples/influxdb/.test.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +set -ex + +devenv up & +DEVENV_PID=$! +export DEVENV_PID + +function stop() { + pkill -P "$DEVENV_PID" +} + +trap stop EXIT + +timeout 10 bash -c 'until echo > /dev/tcp/localhost/8086; do sleep 0.5; done' + +influx --execute "CREATE DATABASE devenv" +DATABASES=$(influx --execute "SHOW DATABASES" | grep devenv) + +if [[ "$DATABASES" != "devenv" ]]; then + echo "The influxdb database was not created" + exit 1 +fi \ No newline at end of file diff --git a/examples/influxdb/devenv.nix b/examples/influxdb/devenv.nix new file mode 100644 index 000000000..7d6234f21 --- /dev/null +++ b/examples/influxdb/devenv.nix @@ -0,0 +1,9 @@ +{ pkgs, ... }: + +{ + packages = [ + pkgs.influxdb + ]; + + services.influxdb.enable = true; +} diff --git a/examples/influxdb/devenv.yaml b/examples/influxdb/devenv.yaml new file mode 100644 index 000000000..c7cb5ceda --- /dev/null +++ b/examples/influxdb/devenv.yaml @@ -0,0 +1,3 @@ +inputs: + nixpkgs: + url: github:NixOS/nixpkgs/nixpkgs-unstable diff --git a/src/modules/services/influxdb.nix b/src/modules/services/influxdb.nix new file mode 100644 index 000000000..5ce946d95 --- /dev/null +++ b/src/modules/services/influxdb.nix @@ -0,0 +1,22 @@ +{ pkgs, lib, config, ... }: + +let + cfg = config.services.influxdb; + types = lib.types; +in +{ + options.services.influxdb = { + enable = lib.mkEnableOption "influxdb"; + + package = lib.mkOption { + type = types.package; + description = "An open-source distributed time series database"; + default = pkgs.influxdb; + defaultText = lib.literalExpression "pkgs.influxdb"; + }; + }; + + config = lib.mkIf cfg.enable { + processes.influxdb-server.exec = "${cfg.package}/bin/influxd"; + }; +} From dad24416b1ca61a5551db0de863b047765ac0454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hendrik=20S=C3=B6bbing?= Date: Mon, 18 Dec 2023 08:24:24 +0100 Subject: [PATCH 2/4] Add settings for InfluxDB --- examples/influxdb/.test.sh | 3 +- examples/influxdb/devenv.lock | 150 ++++++++++++++++++++++++++++++ examples/influxdb/devenv.nix | 67 ++++++++++++- src/modules/services/influxdb.nix | 8 +- 4 files changed, 225 insertions(+), 3 deletions(-) create mode 100644 examples/influxdb/devenv.lock diff --git a/examples/influxdb/.test.sh b/examples/influxdb/.test.sh index 2b345dba0..9b79b708f 100755 --- a/examples/influxdb/.test.sh +++ b/examples/influxdb/.test.sh @@ -11,7 +11,8 @@ function stop() { trap stop EXIT -timeout 10 bash -c 'until echo > /dev/tcp/localhost/8086; do sleep 0.5; done' +# We test for the none-default port, configured in the nix file +timeout 10 bash -c 'until echo > /dev/tcp/localhost/8087; do sleep 0.5; done' influx --execute "CREATE DATABASE devenv" DATABASES=$(influx --execute "SHOW DATABASES" | grep devenv) diff --git a/examples/influxdb/devenv.lock b/examples/influxdb/devenv.lock new file mode 100644 index 000000000..8d6215a6c --- /dev/null +++ b/examples/influxdb/devenv.lock @@ -0,0 +1,150 @@ +{ + "nodes": { + "devenv": { + "locked": { + "path": "../../src/modules", + "type": "path" + }, + "original": { + "path": "../../src/modules", + "type": "path" + }, + "parent": [] + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1685518550, + "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1660459072, + "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1702539185, + "narHash": "sha256-KnIRG5NMdLIpEkZTnN5zovNYc0hhXjAgv6pfd5Z4c7U=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "aa9d4729cbc99dabacb50e3994dcefb3ea0f7447", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1685801374, + "narHash": "sha256-otaSUoFEMM+LjBI1XL/xGB5ao6IwnZOXc47qhIgJe8U=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c37ca420157f4abc31e26f436c1145f8951ff373", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "gitignore": "gitignore", + "nixpkgs": [ + "nixpkgs" + ], + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1702456155, + "narHash": "sha256-I2XhXGAecdGlqi6hPWYT83AQtMgL+aa3ulA85RAEgOk=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "007a45d064c1c32d04e1b8a0de5ef00984c419bc", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "devenv": "devenv", + "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/examples/influxdb/devenv.nix b/examples/influxdb/devenv.nix index 7d6234f21..9b30de689 100644 --- a/examples/influxdb/devenv.nix +++ b/examples/influxdb/devenv.nix @@ -1,9 +1,74 @@ -{ pkgs, ... }: +{ pkgs, config, ... }: +let + cfg = config.services.influxdb; +in { packages = [ pkgs.influxdb ]; services.influxdb.enable = true; + services.influxdb.settings = '' + [meta] + dir = "/tmp/influxdb/meta" + + [data] + dir = "/tmp/influxdb/data" + wal-dir = "/tmp/influxdb/wal" + query-log-enabled = true + cache-max-memory-size = 1048576000 + cache-snapshot-memory-size = 26214400 + cache-snapshot-write-cold-duration = "10m" + compact-full-write-cold-duration = "4h" + + [coordinator] + write-timeout = "10s" + max-concurrent-queries = 0 + query-timeout = "0s" + log-queries-after = "0s" + max-select-point = 0 + max-select-series = 0 + max-select-buckets = 0 + + [retention] + enabled = true + check-interval = "30m" + + [shard-precreation] + enabled = true + check-interval = "10m" + advance-period = "30m" + + [monitor] + store-enabled = true + store-database = "_internal" + store-interval = "10s" + + [http] + enabled = true + bind-address = ":8087" + auth-enabled = false + log-enabled = true + write-tracing = false + pprof-enabled = true + https-enabled = false + + [logging] + format = "auto" + level = "info" + suppress-logo = false + + [[graphite]] + enabled = false + + [[collectd]] + enabled = false + + [[opentsdb]] + enabled = false + + [[udp]] + enabled = false + ''; } diff --git a/src/modules/services/influxdb.nix b/src/modules/services/influxdb.nix index 5ce946d95..9fe1e09be 100644 --- a/src/modules/services/influxdb.nix +++ b/src/modules/services/influxdb.nix @@ -14,9 +14,15 @@ in default = pkgs.influxdb; defaultText = lib.literalExpression "pkgs.influxdb"; }; + + settings = lib.mkOption { + type = types.lines; + default = ""; + description = "Configuration for InfluxDB-server"; + }; }; config = lib.mkIf cfg.enable { - processes.influxdb-server.exec = "${cfg.package}/bin/influxd"; + processes.influxdb-server.exec = "${cfg.package}/bin/influxd -config ${pkgs.writeText "influxdb.conf" cfg.settings}"; }; } From a3770ae3e111eac4252f941078fa1eb549ccf8ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hendrik=20S=C3=B6bbing?= Date: Mon, 18 Dec 2023 11:41:15 +0100 Subject: [PATCH 3/4] Remove lock, rename settings to config --- examples/influxdb/devenv.lock | 150 ------------------------------ examples/influxdb/devenv.nix | 2 +- src/modules/services/influxdb.nix | 4 +- 3 files changed, 3 insertions(+), 153 deletions(-) delete mode 100644 examples/influxdb/devenv.lock diff --git a/examples/influxdb/devenv.lock b/examples/influxdb/devenv.lock deleted file mode 100644 index 8d6215a6c..000000000 --- a/examples/influxdb/devenv.lock +++ /dev/null @@ -1,150 +0,0 @@ -{ - "nodes": { - "devenv": { - "locked": { - "path": "../../src/modules", - "type": "path" - }, - "original": { - "path": "../../src/modules", - "type": "path" - }, - "parent": [] - }, - "flake-compat": { - "flake": false, - "locked": { - "lastModified": 1673956053, - "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", - "owner": "edolstra", - "repo": "flake-compat", - "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", - "type": "github" - }, - "original": { - "owner": "edolstra", - "repo": "flake-compat", - "type": "github" - } - }, - "flake-utils": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1685518550, - "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "gitignore": { - "inputs": { - "nixpkgs": [ - "pre-commit-hooks", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1660459072, - "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", - "owner": "hercules-ci", - "repo": "gitignore.nix", - "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", - "type": "github" - }, - "original": { - "owner": "hercules-ci", - "repo": "gitignore.nix", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1702539185, - "narHash": "sha256-KnIRG5NMdLIpEkZTnN5zovNYc0hhXjAgv6pfd5Z4c7U=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "aa9d4729cbc99dabacb50e3994dcefb3ea0f7447", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs-stable": { - "locked": { - "lastModified": 1685801374, - "narHash": "sha256-otaSUoFEMM+LjBI1XL/xGB5ao6IwnZOXc47qhIgJe8U=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "c37ca420157f4abc31e26f436c1145f8951ff373", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixos-23.05", - "repo": "nixpkgs", - "type": "github" - } - }, - "pre-commit-hooks": { - "inputs": { - "flake-compat": "flake-compat", - "flake-utils": "flake-utils", - "gitignore": "gitignore", - "nixpkgs": [ - "nixpkgs" - ], - "nixpkgs-stable": "nixpkgs-stable" - }, - "locked": { - "lastModified": 1702456155, - "narHash": "sha256-I2XhXGAecdGlqi6hPWYT83AQtMgL+aa3ulA85RAEgOk=", - "owner": "cachix", - "repo": "pre-commit-hooks.nix", - "rev": "007a45d064c1c32d04e1b8a0de5ef00984c419bc", - "type": "github" - }, - "original": { - "owner": "cachix", - "repo": "pre-commit-hooks.nix", - "type": "github" - } - }, - "root": { - "inputs": { - "devenv": "devenv", - "nixpkgs": "nixpkgs", - "pre-commit-hooks": "pre-commit-hooks" - } - }, - "systems": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/examples/influxdb/devenv.nix b/examples/influxdb/devenv.nix index 9b30de689..da1ea7081 100644 --- a/examples/influxdb/devenv.nix +++ b/examples/influxdb/devenv.nix @@ -9,7 +9,7 @@ in ]; services.influxdb.enable = true; - services.influxdb.settings = '' + services.influxdb.config = '' [meta] dir = "/tmp/influxdb/meta" diff --git a/src/modules/services/influxdb.nix b/src/modules/services/influxdb.nix index 9fe1e09be..2b42358d8 100644 --- a/src/modules/services/influxdb.nix +++ b/src/modules/services/influxdb.nix @@ -15,7 +15,7 @@ in defaultText = lib.literalExpression "pkgs.influxdb"; }; - settings = lib.mkOption { + config = lib.mkOption { type = types.lines; default = ""; description = "Configuration for InfluxDB-server"; @@ -23,6 +23,6 @@ in }; config = lib.mkIf cfg.enable { - processes.influxdb-server.exec = "${cfg.package}/bin/influxd -config ${pkgs.writeText "influxdb.conf" cfg.settings}"; + processes.influxdb-server.exec = "${cfg.package}/bin/influxd -config ${pkgs.writeText "influxdb.conf" cfg.config}"; }; } From d4b9af65992f802023a623c9bfabc6f528304080 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hendrik=20S=C3=B6bbing?= Date: Mon, 18 Dec 2023 14:00:01 +0100 Subject: [PATCH 4/4] Increase wait time for instance start --- examples/influxdb/.test.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/influxdb/.test.sh b/examples/influxdb/.test.sh index 9b79b708f..ce2c18335 100755 --- a/examples/influxdb/.test.sh +++ b/examples/influxdb/.test.sh @@ -12,10 +12,10 @@ function stop() { trap stop EXIT # We test for the none-default port, configured in the nix file -timeout 10 bash -c 'until echo > /dev/tcp/localhost/8087; do sleep 0.5; done' +timeout 60 bash -c 'until echo > /dev/tcp/localhost/8087; do sleep 0.5; done' -influx --execute "CREATE DATABASE devenv" -DATABASES=$(influx --execute "SHOW DATABASES" | grep devenv) +influx --port 8087 --execute "CREATE DATABASE devenv" +DATABASES=$(influx --port 8087 --execute "SHOW DATABASES" | grep devenv) if [[ "$DATABASES" != "devenv" ]]; then echo "The influxdb database was not created"