Version in base suite: 0.0~git20230203.6f710f8-1 Base version: prometheus-node-exporter-collectors_0.0~git20230203.6f710f8-1 Target version: prometheus-node-exporter-collectors_0.0~git20230203.6f710f8-1+deb12u1 Base file: /srv/ftp-master.debian.org/ftp/pool/main/p/prometheus-node-exporter-collectors/prometheus-node-exporter-collectors_0.0~git20230203.6f710f8-1.dsc Target file: /srv/ftp-master.debian.org/policy/pool/main/p/prometheus-node-exporter-collectors/prometheus-node-exporter-collectors_0.0~git20230203.6f710f8-1+deb12u1.dsc changelog | 7 + patches/0001-do-not-run-apt-update-or-simulate-apt-dist-upgrade.patch | 65 ++++++++++ patches/0001-report-the-apt-cache-timestamp.patch | 52 ++++++++ patches/0001-use-a-better-heuristic-for-the-apt-update-last-run-t.patch | 60 +++++++++ patches/series | 3 5 files changed, 187 insertions(+) diff -Nru prometheus-node-exporter-collectors-0.0~git20230203.6f710f8/debian/changelog prometheus-node-exporter-collectors-0.0~git20230203.6f710f8/debian/changelog --- prometheus-node-exporter-collectors-0.0~git20230203.6f710f8/debian/changelog 2023-02-03 04:57:45.000000000 +0000 +++ prometheus-node-exporter-collectors-0.0~git20230203.6f710f8/debian/changelog 2023-10-31 17:57:52.000000000 +0000 @@ -1,3 +1,10 @@ +prometheus-node-exporter-collectors (0.0~git20230203.6f710f8-1+deb12u1) bookworm; urgency=medium + + * Team upload + * Fix deadlock with other apt update runs (Closes: #1028212) + + -- Antoine Beaupré Tue, 31 Oct 2023 13:57:52 -0400 + prometheus-node-exporter-collectors (0.0~git20230203.6f710f8-1) unstable; urgency=medium * New upstream snapshot (Closes: #1030058) diff -Nru prometheus-node-exporter-collectors-0.0~git20230203.6f710f8/debian/patches/0001-do-not-run-apt-update-or-simulate-apt-dist-upgrade.patch prometheus-node-exporter-collectors-0.0~git20230203.6f710f8/debian/patches/0001-do-not-run-apt-update-or-simulate-apt-dist-upgrade.patch --- prometheus-node-exporter-collectors-0.0~git20230203.6f710f8/debian/patches/0001-do-not-run-apt-update-or-simulate-apt-dist-upgrade.patch 1970-01-01 00:00:00.000000000 +0000 +++ prometheus-node-exporter-collectors-0.0~git20230203.6f710f8/debian/patches/0001-do-not-run-apt-update-or-simulate-apt-dist-upgrade.patch 2023-10-31 17:57:52.000000000 +0000 @@ -0,0 +1,65 @@ +From 28c179ddfd3d7e0f5bc49b93f924f0dffba5b71d Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= +Date: Fri, 13 Oct 2023 12:29:48 -0400 +Subject: [PATCH] do not run apt update or simulate apt dist-upgrade +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +This is causing all sorts of problems. The first of which is that +we're hitting our poor mirrors every time the script is ran, which, in +the Debian package configuration, is *every 15 minutes* (!!). + +The second is that this locks the cache and makes this script +needlessly stumble upon a possible regression in APT from Debian +bookworm and Ubuntu 22.06: + +https://bugs.launchpad.net/ubuntu/+source/apt/+bug/2003851 + +That still has to be confirmed: it's possible that `apt update` can +hang for a long time, but that shouldn't concern us if we delegate +this work out of band. + +I also do not believe actually performing the `dist-upgrade` +calculations is necessary to compute the pending upgrades at all. I've +done work with python-apt for other projects and haven't found that to +be required: the cache has the necessary information about pending +upgrades. + +Closes: #179 + +Signed-off-by: Antoine Beaupré +--- + apt_info.py | 9 --------- + 1 file changed, 9 deletions(-) + +diff --git a/apt_info.py b/apt_info.py +index 59f3ad7..81a276b 100755 +--- a/apt_info.py ++++ b/apt_info.py +@@ -9,7 +9,6 @@ + + import apt + import collections +-import contextlib + import os + + _UpgradeInfo = collections.namedtuple("_UpgradeInfo", ["labels", "count"]) +@@ -90,14 +89,6 @@ def _write_reboot_required(): + def _main(): + cache = apt.cache.Cache() + +- # First of all, attempt to update the index. If we don't have permission +- # to do so (or it fails for some reason), it's not the end of the world, +- # we'll operate on the old index. +- with contextlib.suppress(apt.cache.LockFailedException, apt.cache.FetchFailedException): +- cache.update() +- +- cache.open() +- cache.upgrade(True) + _write_pending_upgrades(cache) + _write_held_upgrades(cache) + _write_autoremove_pending(cache) +-- +2.39.2 + diff -Nru prometheus-node-exporter-collectors-0.0~git20230203.6f710f8/debian/patches/0001-report-the-apt-cache-timestamp.patch prometheus-node-exporter-collectors-0.0~git20230203.6f710f8/debian/patches/0001-report-the-apt-cache-timestamp.patch --- prometheus-node-exporter-collectors-0.0~git20230203.6f710f8/debian/patches/0001-report-the-apt-cache-timestamp.patch 1970-01-01 00:00:00.000000000 +0000 +++ prometheus-node-exporter-collectors-0.0~git20230203.6f710f8/debian/patches/0001-report-the-apt-cache-timestamp.patch 2023-10-31 17:57:52.000000000 +0000 @@ -0,0 +1,52 @@ +From dc6568ef14f49bddef28befef6f5058d38535cbc Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= +Date: Fri, 13 Oct 2023 13:01:32 -0400 +Subject: [PATCH] report the apt cache timestamp +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +We use the `pkgcache.bin` modification time as a heuristic, but there +might be a better way to do this. + +We also silently ignore errors when pulling that file to avoid broken +systems from breaking the other metrics. I believe this will lead to a +null metric which is probably what we want anyway. + +A possible improvement to this would be to individually inspect the +`InRelease` files and report the mirror's timestamps as well, but +that's more involved. It's also not a priority compared to this fix, +because we want the update timestamp if we remove the `apt update` +run (in #181). + +Closes: #180 + +Signed-off-by: Antoine Beaupré +Co-authored-by: Ben Kochie +--- + apt_info.py | 9 +++++++++ + 1 file changed, 9 insertions(+) + +Index: b/apt_info.py +=================================================================== +--- a/apt_info.py 2023-10-23 14:58:09.558722141 -0400 ++++ b/apt_info.py 2023-10-23 15:00:07.250721050 -0400 +@@ -77,6 +77,18 @@ def _write_autoremove_pending(cache): + print(f"apt_autoremove_pending {len(autoremovable_packages)}") + + ++def _write_cache_timestamps(registry): ++ print('# HELP apt_package_cache_timestamp_seconds Apt update last run time.') ++ print('# TYPE apt_package_cache_timestamp_seconds gauge') ++ try: ++ print( ++ "apt_package_cache_timestamp_seconds %s" ++ % os.stat('/var/cache/apt/pkgcache.bin').st_mtime ++ ) ++ except OSError: ++ pass ++ ++ + def _write_reboot_required(): + print("# HELP node_reboot_required Node reboot is required for software updates.") + print("# TYPE node_reboot_required gauge") diff -Nru prometheus-node-exporter-collectors-0.0~git20230203.6f710f8/debian/patches/0001-use-a-better-heuristic-for-the-apt-update-last-run-t.patch prometheus-node-exporter-collectors-0.0~git20230203.6f710f8/debian/patches/0001-use-a-better-heuristic-for-the-apt-update-last-run-t.patch --- prometheus-node-exporter-collectors-0.0~git20230203.6f710f8/debian/patches/0001-use-a-better-heuristic-for-the-apt-update-last-run-t.patch 1970-01-01 00:00:00.000000000 +0000 +++ prometheus-node-exporter-collectors-0.0~git20230203.6f710f8/debian/patches/0001-use-a-better-heuristic-for-the-apt-update-last-run-t.patch 2023-10-31 17:57:52.000000000 +0000 @@ -0,0 +1,60 @@ +From feb943f6df8cbc536eaf7fca59a088d59bb39e82 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= +Date: Tue, 17 Oct 2023 10:27:30 -0400 +Subject: [PATCH] use a better heuristic for the apt update last run time +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +As reported in #182, `pkgcache.bin` gets updated on more than just +`apt update`. In particular, it gets modified when a package is +installed, upgraded or removed. + +So let's fallback on a better heuristic, which is the `APT::Periodic` +timestamp. This should give us a much more precise and deliberate +status. + +We also fallback to the `lists` directory, which gets updated when new +mirror lists gets moved into place. This does run the risk of staying +silently unchanged if there's no change on mirrors but (a) that's +rather infrequent and (b) we might actually want to warn on that +anyway. + +Signed-off-by: Antoine Beaupré +Closes: #183 +--- + apt_info.py | 11 ++++++++++- + 1 file changed, 10 insertions(+), 1 deletion(-) + +Index: b/apt_info.py +=================================================================== +--- a/apt_info.py 2023-10-23 15:01:19.018720385 -0400 ++++ b/apt_info.py 2023-10-23 15:01:46.930720116 -0400 +@@ -8,6 +8,7 @@ + # Author: Kyle Fazzari + + import apt ++import apt_pkg + import collections + import os + +@@ -80,10 +81,18 @@ def _write_autoremove_pending(cache): + def _write_cache_timestamps(registry): + print('# HELP apt_package_cache_timestamp_seconds Apt update last run time.') + print('# TYPE apt_package_cache_timestamp_seconds gauge') ++ apt_pkg.init_config() ++ if apt_pkg.config.find_b("APT::Periodic::Update-Package-Lists"): ++ # if we run updates automatically with APT::Periodic, we can ++ # check this timestamp file ++ stamp_file = "/var/lib/apt/periodic/update-success-stamp" ++ else: ++ # if not, let's just fallback on the lists directory ++ stamp_file = '/var/lib/apt/lists' + try: + print( + "apt_package_cache_timestamp_seconds %s" +- % os.stat('/var/cache/apt/pkgcache.bin').st_mtime ++ % os.stat(stamp_file).st_mtime + ) + except OSError: + pass diff -Nru prometheus-node-exporter-collectors-0.0~git20230203.6f710f8/debian/patches/series prometheus-node-exporter-collectors-0.0~git20230203.6f710f8/debian/patches/series --- prometheus-node-exporter-collectors-0.0~git20230203.6f710f8/debian/patches/series 1970-01-01 00:00:00.000000000 +0000 +++ prometheus-node-exporter-collectors-0.0~git20230203.6f710f8/debian/patches/series 2023-10-31 17:57:52.000000000 +0000 @@ -0,0 +1,3 @@ +0001-do-not-run-apt-update-or-simulate-apt-dist-upgrade.patch +0001-report-the-apt-cache-timestamp.patch +0001-use-a-better-heuristic-for-the-apt-update-last-run-t.patch