Skip to content

Commit c67cbba

Browse files
committed
Add METRICS diagnostic type with InfluxDB backups
1 parent 31c687c commit c67cbba

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

pkgs/playos-diagnostics/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pkgs.writeShellApplication {
1515
rauc
1616
grub2_efi
1717
curl
18+
influxdb
1819
];
1920
text = builtins.readFile ./playos-diagnostics.sh;
2021
}

pkgs/playos-diagnostics/playos-diagnostics.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ declare -a DIAGNOSTIC_TYPES=(
88
"HARDWARE"
99
"LOGS"
1010
"NETWORK"
11+
"METRICS"
1112
"STATS"
1213
"SYSINFO"
1314
"UPDATE"
@@ -60,7 +61,7 @@ Limits:
6061
suffixes for seconds, minutes, hours, days.
6162
6263
Filters:
63-
-m, --minimal Produce a small archive. Alias for --exclude=LOGS
64+
-m, --minimal Produce a small archive. Alias for "--exclude=METRICS --exclude=LOGS"
6465
6566
-S, --since SINCE How much historical data (e.g. logs) to collect.
6667
Defaults to "${DEFAULT_SINCE}".
@@ -100,7 +101,7 @@ while [[ $# -gt 0 ]]; do
100101
-h|--help) usage ;;
101102
-o|--output) OUTPUT="$2"; shift 2 ;;
102103
--log-format) LOG_FORMAT="$2"; shift 2 ;;
103-
-m|--minimal) EXCLUDES+=("LOGS"); shift ;;
104+
-m|--minimal) EXCLUDES+=("LOGS" "METRICS"); shift ;;
104105
-S|--since) SINCE="$2"; shift 2 ;;
105106
--cmd-timeout) CMD_TIMEOUT="$2"; shift 2 ;;
106107
-e|--exclude) EXCLUDES+=("$2"); shift 2 ;;
@@ -240,6 +241,16 @@ collect_UPDATE() {
240241
run_cmd -o controller_system_status.html curl -L --fail --silent http://localhost:3333/status
241242
}
242243

244+
collect_METRICS() {
245+
# If influxdb is not running, the backup tool keeps retrying with back-off,
246+
# which will take forever, so to fail early we check if the service is active
247+
#
248+
# Expected uncompressed size is around 200-300 MB
249+
run_cmd -o /dev/null \
250+
"systemctl is-active -q influxdb.service && \
251+
influxd backup -portable -skip-errors ./influxdb-backup"
252+
}
253+
243254
workdir=$(mktemp -d)
244255
# shellcheck disable=SC2064
245256
trap "rm -rf '$workdir'" EXIT

testing/integration/playos-diagnostics.nix

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pkgs.testers.runNixOSTest {
1313
config = {
1414
environment.systemPackages = with pkgs; [ playos-diagnostics ];
1515
services.connman.enable = pkgs.lib.mkOverride 0 true; # disabled in runNixOSTest by default
16+
services.influxdb.enable = true; # for testing backups in METRICS
1617
};
1718
};
1819
};
@@ -169,11 +170,14 @@ with TestCase("proxy passwords are masked in connman output") as t:
169170
f"The expected masked string '{expected_mask}' was not found.")
170171
171172
172-
with TestCase("--minimal flag excludes logs") as t:
173+
with TestCase("--minimal flag excludes logs and metrics") as t:
173174
with diagnostic_output('--minimal') as (_, tmpdir):
174175
match = list(tmpdir.glob("playos-diagnostics-*/data/logs/"))
175176
t.assertEqual(match, [])
176177
178+
match = list(tmpdir.glob("playos-diagnostics-*/data/metrics/"))
179+
t.assertEqual(match, [])
180+
177181
178182
with TestCase("--exclude excludes custom types") as t:
179183
with diagnostic_output('--exclude NETWORK') as (_, tmpdir):

0 commit comments

Comments
 (0)