From f3c67103cf625d1a99f4d995a31707b1f1eaa82f Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Tue, 16 Jul 2024 13:33:59 -0700 Subject: [PATCH] memcached_exporter: Explicitly close memcached connection. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes warnings like “ResourceWarning: unclosed ” with warnings enabled. Signed-off-by: Anders Kaseorg --- puppet/kandra/files/memcached_exporter | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/puppet/kandra/files/memcached_exporter b/puppet/kandra/files/memcached_exporter index 43eb3ddc88..d39c1ece53 100755 --- a/puppet/kandra/files/memcached_exporter +++ b/puppet/kandra/files/memcached_exporter @@ -382,12 +382,13 @@ class MemcachedCollector(Collector): raw_stats = client.stats("sizes") sizes_stats = next(iter(raw_stats.values())) - if sizes_stats.get("sizes_status") == b"disabled" or sizes_stats == {}: - return - sizes = sorted([int(x) for x in sizes_stats]) - yield gauge( - "item_max_bytes", "Largest item (rounded to 32 bytes) in bytes.", value=sizes[-1] - ) + if sizes_stats.get("sizes_status") != b"disabled" and sizes_stats != {}: + sizes = sorted([int(x) for x in sizes_stats]) + yield gauge( + "item_max_bytes", "Largest item (rounded to 32 bytes) in bytes.", value=sizes[-1] + ) + + client.disconnect_all() if __name__ == "__main__":