From ea11342ba59cad42ba29a889b34849dae40845a2 Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Mon, 12 Jul 2021 15:15:41 +1000 Subject: [PATCH] refactor: give all executors a meaningful name Naming these is a good idea because: - the name will be reused in any created threads, so we can figure out which code created which thread - the name will appear in prometheus metrics --- CHANGELOG.md | 4 +++- requirements.txt | 2 +- src/pushsource/_impl/backend/errata_source/errata_client.py | 2 +- src/pushsource/_impl/backend/errata_source/errata_source.py | 4 ++-- src/pushsource/_impl/backend/koji_source.py | 2 +- src/pushsource/_impl/backend/staged/staged_source.py | 2 +- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 521c893d..710e4c46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -- n/a +### Changed + +- Internally created executors are now named for improved metrics and debuggability. ## [2.9.0] - 2021-07-05 diff --git a/requirements.txt b/requirements.txt index e28f73d4..d36700a5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ attrs -more-executors +more-executors>=2.7.0 koji>=1.18 six pushcollector diff --git a/src/pushsource/_impl/backend/errata_source/errata_client.py b/src/pushsource/_impl/backend/errata_source/errata_client.py index 5b17910a..216b26a0 100644 --- a/src/pushsource/_impl/backend/errata_source/errata_client.py +++ b/src/pushsource/_impl/backend/errata_source/errata_client.py @@ -23,7 +23,7 @@ class ErrataRaw(object): class ErrataClient(object): def __init__(self, threads, url, **retry_args): self._executor = ( - Executors.thread_pool(max_workers=threads) + Executors.thread_pool(name="pushsource-errata-client", max_workers=threads) .with_retry(**retry_args) .with_cancel_on_shutdown() ) diff --git a/src/pushsource/_impl/backend/errata_source/errata_source.py b/src/pushsource/_impl/backend/errata_source/errata_source.py index 4e4cbae7..738c9f52 100644 --- a/src/pushsource/_impl/backend/errata_source/errata_source.py +++ b/src/pushsource/_impl/backend/errata_source/errata_source.py @@ -80,14 +80,14 @@ def __init__( # This executor doesn't use retry because koji & ET executors already do that. self._executor = Executors.thread_pool( - max_workers=threads + name="pushsource-errata", max_workers=threads ).with_cancel_on_shutdown() # We set aside a separate thread pool for koji so that there are separate # queues for ET and koji calls, yet we avoid creating a new thread pool for # each koji source. self._koji_executor = ( - Executors.thread_pool(max_workers=threads) + Executors.thread_pool(name="pushsource-errata-koji", max_workers=threads) .with_retry() .with_cancel_on_shutdown() ) diff --git a/src/pushsource/_impl/backend/koji_source.py b/src/pushsource/_impl/backend/koji_source.py index a545f155..abe48ac1 100644 --- a/src/pushsource/_impl/backend/koji_source.py +++ b/src/pushsource/_impl/backend/koji_source.py @@ -204,7 +204,7 @@ def __init__( self._threads = threads self._executor = ( executor - or Executors.thread_pool(max_workers=threads) + or Executors.thread_pool(name="pushsource-koji", max_workers=threads) .with_retry() .with_cancel_on_shutdown() ) diff --git a/src/pushsource/_impl/backend/staged/staged_source.py b/src/pushsource/_impl/backend/staged/staged_source.py index f88d4746..173ec059 100644 --- a/src/pushsource/_impl/backend/staged/staged_source.py +++ b/src/pushsource/_impl/backend/staged/staged_source.py @@ -76,7 +76,7 @@ def __init__(self, url, threads=4, timeout=60 * 60): # Note: this executor does not have a retry. # NFS already does a lot of its own retries. self._executor = ( - Executors.thread_pool(max_workers=threads) + Executors.thread_pool(name="pushsource-staged", max_workers=threads) .with_timeout(timeout) .with_cancel_on_shutdown() )