diff --git a/PKG-INFO b/PKG-INFO index ee6daf2..645aca5 100644 --- a/PKG-INFO +++ b/PKG-INFO @@ -1,39 +1,39 @@ Metadata-Version: 2.1 Name: swh.core -Version: 2.17.0 +Version: 2.18.0 Summary: Software Heritage core utilities Home-page: https://forge.softwareheritage.org/diffusion/DCORE/ Author: Software Heritage developers Author-email: swh-devel@inria.fr Project-URL: Bug Reports, https://forge.softwareheritage.org/maniphest Project-URL: Funding, https://www.softwareheritage.org/donate Project-URL: Source, https://forge.softwareheritage.org/source/swh-core Project-URL: Documentation, https://docs.softwareheritage.org/devel/swh-core/ Classifier: Programming Language :: Python :: 3 Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3) Classifier: Operating System :: OS Independent Classifier: Development Status :: 5 - Production/Stable Requires-Python: >=3.7 Description-Content-Type: text/x-rst Provides-Extra: testing-core Provides-Extra: logging Provides-Extra: db Provides-Extra: http Provides-Extra: github Provides-Extra: testing License-File: LICENSE License-File: AUTHORS Software Heritage - Core foundations ==================================== Low-level utilities and helpers used by almost all other modules in the stack. core library for swh's modules: - config parser - serialization - logging mechanism - database connection - http-based RPC client/server diff --git a/debian/changelog b/debian/changelog index 9c73273..c28864c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,1493 +1,1497 @@ -swh-core (2.17.0-1~swh1~bpo10+1) buster-swh; urgency=medium +swh-core (2.18.0-1~swh1) unstable-swh; urgency=medium - * Rebuild for buster-swh + * New upstream release 2.18.0 - (tagged by Valentin Lorentz + on 2022-12-21 15:05:04 +0100) + * Upstream changes: - v2.18.0 - * docs: Include module indices + only when building standalone package doc - * github: Export + statsd metrics about API requests and token usage - -- Software Heritage autobuilder (on jenkins-debian1) Wed, 26 Oct 2022 12:47:34 +0000 + -- Software Heritage autobuilder (on jenkins-debian1) Wed, 21 Dec 2022 14:08:16 +0000 swh-core (2.17.0-1~swh1) unstable-swh; urgency=medium * New upstream release 2.17.0 - (tagged by Antoine R. Dumont (@ardumont) on 2022-10-26 14:42:33 +0200) * Upstream changes: - v2.17.0 - swh.core.tarball: Add support for war files as well - pre-commit, tox: Bump pre-commit, codespell, black and flake8 -- Software Heritage autobuilder (on jenkins-debian1) Wed, 26 Oct 2022 12:45:55 +0000 swh-core (2.16.1-1~swh1) unstable-swh; urgency=medium * New upstream release 2.16.1 - (tagged by Valentin Lorentz on 2022-10-13 16:41:59 +0200) * Upstream changes: - v2.16.1 - * Fix _sanitize_github_url removing suffixes too greedily -- Software Heritage autobuilder (on jenkins-debian1) Thu, 13 Oct 2022 14:48:15 +0000 swh-core (2.16.0-1~swh1) unstable-swh; urgency=medium * New upstream release 2.16.0 - (tagged by Antoine Lambert on 2022-10-12 11:34:18 +0200) * Upstream changes: - version 2.16.0 -- Software Heritage autobuilder (on jenkins-debian1) Wed, 12 Oct 2022 09:37:28 +0000 swh-core (2.15.0-1~swh1) unstable-swh; urgency=medium * New upstream release 2.15.0 - (tagged by Antoine R. Dumont (@ardumont) on 2022-10-03 17:04:49 +0200) * Upstream changes: - v2.15.0 - Make mimetype to archive format dictionary public - api/asynchronous: Do not log/report client exception -- Software Heritage autobuilder (on jenkins-debian1) Mon, 03 Oct 2022 15:07:52 +0000 swh-core (2.14.1-1~swh1) unstable-swh; urgency=medium * New upstream release 2.14.1 - (tagged by Antoine Lambert on 2022-09-12 11:46:16 +0200) * Upstream changes: - version 2.14.1 -- Software Heritage autobuilder (on jenkins-debian1) Mon, 12 Sep 2022 09:51:15 +0000 swh-core (2.14.0-1~swh1) unstable-swh; urgency=medium * New upstream release 2.14.0 - (tagged by Valentin Lorentz on 2022-08-16 13:49:11 +0200) * Upstream changes: - v2.14.0 - * RPC server: Do not log exceptions with 4xx HTTP status codes - * Remove support for deprecated exception format - * Make the RPC client raise a specific exception class on 503 -- Software Heritage autobuilder (on jenkins-debian1) Tue, 16 Aug 2022 11:52:17 +0000 swh-core (2.13.1-1~swh1) unstable-swh; urgency=medium * New upstream release 2.13.1 - (tagged by Valentin Lorentz on 2022-08-04 10:42:39 +0200) * Upstream changes: - v2.13.1 - * Remove use of app.test_client() as a ctx-manager, to fix support - for Flask 2.2.0 -- Software Heritage autobuilder (on jenkins-debian1) Thu, 04 Aug 2022 08:45:44 +0000 swh-core (2.13-1~swh1) unstable-swh; urgency=medium * New upstream release 2.13 - (tagged by David Douard on 2022-07-05 14:22:04 +0200) * Upstream changes: - v2.13 -- Software Heritage autobuilder (on jenkins-debian1) Tue, 05 Jul 2022 12:38:24 +0000 swh-core (2.12-1~swh2) unstable-swh; urgency=medium * Bump new release with correct deps. -- Antoine R. Dumont (@ardumont) Mon, 20 Jun 2022 10:13:14 +0200 swh-core (2.12-1~swh1) unstable-swh; urgency=medium * New upstream release 2.12 - (tagged by Nicolas Dandrimont on 2022-06-16 13:38:52 +0200) * Upstream changes: - Release swh.core v2.12 - Add support for zstandard compressed tarballs -- Software Heritage autobuilder (on jenkins-debian1) Thu, 16 Jun 2022 11:42:04 +0000 swh-core (2.11-1~swh1) unstable-swh; urgency=medium * New upstream release 2.11 - (tagged by Antoine R. Dumont (@ardumont) on 2022-06-10 10:20:37 +0200) * Upstream changes: - v2.11 - tarball: Use standard Python module zipfile to extract jar archive - Add missing coverage on `swh db version` cli - db: Grant read access to guest user on all schema tables -- Software Heritage autobuilder (on jenkins-debian1) Fri, 10 Jun 2022 08:24:24 +0000 swh-core (2.10-1~swh1) unstable-swh; urgency=medium * New upstream release 2.10 - (tagged by Antoine R. Dumont (@ardumont) on 2022-06-02 16:03:41 +0200) * Upstream changes: - v2.10 - github/utils: Deal with exotic urls to canonicalize - deprecate the db/pytest_plugin.py module - move initialize_database_for_module in db_utils - mark postgresql_fact fixture factory function as deprecated - tests: use stock pytest_postgresql factory function - docs/db: Update datastore requirement -- Software Heritage autobuilder (on jenkins-debian1) Thu, 02 Jun 2022 14:39:11 +0000 swh-core (2.9.0-1~swh1) unstable-swh; urgency=medium * New upstream release 2.9.0 - (tagged by Antoine R. Dumont (@ardumont) on 2022-05-30 17:36:23 +0200) * Upstream changes: - v2.9.0 - Allow module to specify another config key than their module name - cli.db: Reword ignore sentence -- Software Heritage autobuilder (on jenkins-debian1) Mon, 30 May 2022 15:41:42 +0000 swh-core (2.8.1-1~swh1) unstable-swh; urgency=medium * New upstream release 2.8.1 - (tagged by Antoine R. Dumont (@ardumont) on 2022-05-30 17:06:11 +0200) * Upstream changes: - v2.8.1 - cli.db: Use attribute current_version instead of undeclared getter - cli.db: Fix help message typo -- Software Heritage autobuilder (on jenkins-debian1) Mon, 30 May 2022 15:10:17 +0000 swh-core (2.8.0-1~swh1) unstable-swh; urgency=medium * New upstream release 2.8.0 - (tagged by Antoine R. Dumont (@ardumont) on 2022-05-20 18:17:20 +0200) * Upstream changes: - v2.8.0 - Deal with git protocol url to canonicalize to https -- Software Heritage autobuilder (on jenkins-debian1) Fri, 20 May 2022 16:21:13 +0000 swh-core (2.7.0-1~swh1) unstable-swh; urgency=medium * New upstream release 2.7.0 - (tagged by Antoine R. Dumont (@ardumont) on 2022-05-20 15:26:30 +0200) * Upstream changes: - v2.7.0 - Use GitHubSession to make canonical computation deal with rate limit -- Software Heritage autobuilder (on jenkins-debian1) Fri, 20 May 2022 13:30:15 +0000 swh-core (2.6.0-1~swh2) unstable-swh; urgency=medium * Bump new release -- Antoine R. Dumont (@ardumont) Fri, 20 May 2022 10:26:03 +0200 swh-core (2.6.0-1~swh1) unstable-swh; urgency=medium * New upstream release 2.6.0 - (tagged by Antoine R. Dumont (@ardumont) on 2022-05-20 08:54:46 +0200) * Upstream changes: - v2.6.0 - Extract reusable github tests fixtures into its own pytest_plugin - test_db/test_db_copy_to: Fix hypothesis FailedHealthCheck error - Refactor swh.lister.github.utils to swh.core.github.utils - Add utility function to retrieve canonical github urls - Make 'python -m swh' work as cli entry point - db_utils: Make connect_to_conninfo use through contextmanager - Upgrade mypy to 0.942 to fix support of types-psycopg2 >= 2.9.12 -- Software Heritage autobuilder (on jenkins-debian1) Fri, 20 May 2022 06:58:23 +0000 swh-core (2.5.0-1~swh1) unstable-swh; urgency=medium * New upstream release 2.5.0 - (tagged by Valentin Lorentz on 2022-04-25 13:51:26 +0200) * Upstream changes: - v2.5.0 - * Make db_transaction's client_options configurable at run time - * sentry: always override init settings with the environment variables - * Add support for disabling logging-based events in sentry - * RPC server: explicitly handle sentry exception capture (instead of gunicorn) - * statsd: add an error_type tag to @timed error counters - * cli: Ensure tests don't mess with the global logging setup - * mypy/pre-commit/pytest maintenance -- Software Heritage autobuilder (on jenkins-debian1) Mon, 25 Apr 2022 11:56:02 +0000 swh-core (2.4.0-1~swh1) unstable-swh; urgency=medium * New upstream release 2.4.0 - (tagged by Valentin Lorentz on 2022-03-29 14:39:15 +0200) * Upstream changes: - v2.4.0 - * Fix support of Werkzeug 2.1.0 -- Software Heritage autobuilder (on jenkins-debian1) Tue, 29 Mar 2022 12:42:28 +0000 swh-core (2.3.0-1~swh1) unstable-swh; urgency=medium * New upstream release 2.3.0 - (tagged by David Douard on 2022-03-14 17:19:37 +0100) * Upstream changes: - v2.3.0 -- Software Heritage autobuilder (on jenkins-debian1) Mon, 14 Mar 2022 16:23:52 +0000 swh-core (2.2.2-1~swh1) unstable-swh; urgency=medium * New upstream release 2.2.2 - (tagged by David Douard on 2022-03-09 17:44:25 +0100) * Upstream changes: - v2.2.2 - small fixes in the `swh db upgrade` command -- Software Heritage autobuilder (on jenkins-debian1) Wed, 09 Mar 2022 16:48:21 +0000 swh-core (2.2.1-1~swh1) unstable-swh; urgency=medium * New upstream release 2.2.1 - (tagged by Nicolas Dandrimont on 2022-03-03 20:20:11 +0100) * Upstream changes: - Release swh.core v2.2.1 - quiesce deprecation warnings for autogenerated RPC clients - fix typing for a few methods in db_utils -- Software Heritage autobuilder (on jenkins-debian1) Thu, 03 Mar 2022 19:24:59 +0000 swh-core (2.2.0-1~swh1) unstable-swh; urgency=medium * New upstream release 2.2.0 - (tagged by Valentin Lorentz on 2022-03-02 11:45:18 +0100) * Upstream changes: - v2.2.0 - * utils: Add a new 'iter_chunks' function -- Software Heritage autobuilder (on jenkins-debian1) Wed, 02 Mar 2022 10:47:47 +0000 swh-core (2.1.1-1~swh1) unstable-swh; urgency=medium * New upstream release 2.1.1 - (tagged by Valentin Lorentz on 2022-03-01 17:00:36 +0100) * Upstream changes: - v2.1.1 - * Fix wrong version numbers in deprecation message. -- Software Heritage autobuilder (on jenkins-debian1) Tue, 01 Mar 2022 16:03:05 +0000 swh-core (2.1.0-1~swh1) unstable-swh; urgency=medium * New upstream release 2.1.0 - (tagged by Valentin Lorentz on 2022-03-01 16:58:02 +0100) * Upstream changes: - v2.1.0 - * RPCClient: Make methods {get,post}{,_stream} protected - * RPCServerApp: Add hooks to add behaviors to generated methods -- Software Heritage autobuilder (on jenkins-debian1) Tue, 01 Mar 2022 16:00:51 +0000 swh-core (2.0.0-2~swh1) unstable-swh; urgency=medium * Bump dependency constranints for pytest and pytest-postgresql. -- David Douard Wed, 23 Feb 2022 10:56:37 +0100 swh-core (2.0.0-1~swh1) unstable-swh; urgency=medium * New upstream release 2.0.0 - (tagged by David Douard on 2022-02-17 15:26:59 +0100) * Upstream changes: - v2.0.0 - add support for generic db version handling for postgresql backends, - add support for generic db upgrade (for postgresql backends), - upgrade pytest- postgresql based tests scaffolding to use the - template-based db creation (instead of the truncate-based db reset). -- Software Heritage autobuilder (on jenkins-debian1) Wed, 23 Feb 2022 09:34:41 +0000 swh-core (1.1.1-1~swh1) unstable-swh; urgency=medium * New upstream release 1.1.1 - (tagged by Valentin Lorentz on 2022-02-04 12:52:06 +0100) * Upstream changes: - v1.1.1 - * Require pytest to be <7.0.0 -- Software Heritage autobuilder (on jenkins-debian1) Fri, 04 Feb 2022 11:54:45 +0000 swh-core (1.1.0-1~swh1) unstable-swh; urgency=medium * New upstream release 1.1.0 - (tagged by David Douard on 2022-01-20 15:39:02 +0100) * Upstream changes: - v1.1.0 - add a Statsd.status_gauge() context manager - add support for env var substitution in STATS_TAGS - pin mypy version and clean reauirements a bit -- Software Heritage autobuilder (on jenkins-debian1) Thu, 20 Jan 2022 14:44:14 +0000 swh-core (1.0.0-2~swh1) unstable-swh; urgency=medium * Add missing B-D on python3-blinker for sentry-sdk -- Nicolas Dandrimont Thu, 02 Dec 2021 12:34:50 +0100 swh-core (1.0.0-1~swh1) unstable-swh; urgency=medium * New upstream release 1.0.0 - (tagged by David Douard on 2021-12-02 10:51:10 +0100) * Upstream changes: - v1.0.0 -- Software Heritage autobuilder (on jenkins-debian1) Thu, 02 Dec 2021 10:00:19 +0000 swh-core (0.15.1-1~swh1) unstable-swh; urgency=medium * New upstream release 0.15.1 - (tagged by Valentin Lorentz on 2021-11-08 14:10:08 +0100) * Upstream changes: - v0.15.1 - * Require pytest-postgresql < 4.0 -- Software Heritage autobuilder (on jenkins-debian1) Mon, 08 Nov 2021 13:12:36 +0000 swh-core (0.15.0-1~swh1) unstable-swh; urgency=medium * New upstream release 0.15.0 - (tagged by Antoine R. Dumont (@ardumont) on 2021-09-20 11:45:26 +0200) * Upstream changes: - v0.15.0 - tarball: Fallback to guess archive format from mimetype when no format detected -- Software Heritage autobuilder (on jenkins-debian1) Mon, 20 Sep 2021 09:48:28 +0000 swh-core (0.14.6-1~swh1) unstable-swh; urgency=medium * New upstream release 0.14.6 - (tagged by Antoine Lambert on 2021-09-16 10:48:35 +0200) * Upstream changes: - version 0.14.6 -- Software Heritage autobuilder (on jenkins-debian1) Thu, 16 Sep 2021 08:51:58 +0000 swh-core (0.14.5-1~swh1) unstable-swh; urgency=medium * New upstream release 0.14.5 - (tagged by Valentin Lorentz on 2021-08-30 10:31:47 +0200) * Upstream changes: - v0.14.5 - * tarball: Add support for .tbz, .tbz2, and .jar -- Software Heritage autobuilder (on jenkins-debian1) Mon, 30 Aug 2021 08:34:03 +0000 swh-core (0.14.4-1~swh1) unstable-swh; urgency=medium * New upstream release 0.14.4 - (tagged by Valentin Lorentz on 2021-07-30 16:44:26 +0200) * Upstream changes: - v0.14.4 - * add stream_results_optional -- Software Heritage autobuilder (on jenkins-debian1) Fri, 30 Jul 2021 14:47:25 +0000 swh-core (0.14.3-1~swh1) unstable-swh; urgency=medium * New upstream release 0.14.3 - (tagged by Antoine Lambert on 2021-06-11 15:41:38 +0200) * Upstream changes: - version 0.14.3 -- Software Heritage autobuilder (on jenkins-debian1) Fri, 11 Jun 2021 13:47:13 +0000 swh-core (0.14.2-2~swh1) unstable-swh; urgency=medium * Rebuild v0.14.2 after missing unzip dependency -- Antoine Lambert Thu, 10 Jun 2021 16:24:09 +0200 swh-core (0.14.2-1~swh1) unstable-swh; urgency=medium * New upstream release 0.14.2 - (tagged by Antoine Lambert on 2021-06-10 16:09:06 +0200) * Upstream changes: - version 0.14.2 -- Software Heritage autobuilder (on jenkins-debian1) Thu, 10 Jun 2021 14:13:25 +0000 swh-core (0.14.1-1~swh1) unstable-swh; urgency=medium * New upstream release 0.14.1 - (tagged by Valentin Lorentz on 2021-05-06 15:33:56 +0200) * Upstream changes: - v0.14.1 - * Fix reserved name being used in pytest plugin -- Software Heritage autobuilder (on jenkins-debian1) Thu, 06 May 2021 13:38:24 +0000 swh-core (0.14.0-1~swh1) unstable-swh; urgency=medium * New upstream release 0.14.0 - (tagged by Valentin Lorentz on 2021-05-06 14:14:10 +0200) * Upstream changes: - v0.14.0 - Add support for pytest- postgresql 3.0.0 - For consistency, I renamed db_name to dbname everywhere, so this will - affect other SWH packages. -- Software Heritage autobuilder (on jenkins-debian1) Thu, 06 May 2021 12:17:31 +0000 swh-core (0.13.3-1~swh1) unstable-swh; urgency=medium * New upstream release 0.13.3 - (tagged by Antoine Lambert on 2021-05-06 13:54:51 +0200) * Upstream changes: - version 0.13.3 -- Software Heritage autobuilder (on jenkins-debian1) Thu, 06 May 2021 11:59:49 +0000 swh-core (0.13.2-1~swh1) unstable-swh; urgency=medium * New upstream release 0.13.2 - (tagged by Valentin Lorentz on 2021-05-06 10:40:51 +0200) * Upstream changes: - v0.13.2 - * tarball: properly normalize perms for all extracted files - * requirements-db-pytestplugin: Don't install pytest-postgresql 3.0+ -- Software Heritage autobuilder (on jenkins-debian1) Thu, 06 May 2021 08:44:45 +0000 swh-core (0.13.1-1~swh1) unstable-swh; urgency=medium * New upstream release 0.13.1 - (tagged by Antoine Lambert on 2021-04-29 14:21:29 +0200) * Upstream changes: - version 0.13.1 -- Software Heritage autobuilder (on jenkins-debian1) Thu, 29 Apr 2021 12:25:15 +0000 swh-core (0.13.0-1~swh1) unstable-swh; urgency=medium * New upstream release 0.13.0 - (tagged by Vincent SELLIER on 2021-04-06 19:01:37 +0200) * Upstream changes: - v0.13.0 - Support several backends on RPCServerApp -- Software Heritage autobuilder (on jenkins-debian1) Tue, 06 Apr 2021 17:07:10 +0000 swh-core (0.12.1-1~swh1) unstable-swh; urgency=medium * New upstream release 0.12.1 - (tagged by Valentin Lorentz on 2021-04-06 12:34:34 +0200) * Upstream changes: - v0.12.1 - * tests: Drop hypothesis < 6 requirement - * README.rst: Remove getting-started instructions, they are duplicates - * Improve/fix documentation of requests_mock_datadir - * Remove dependency on 'decorator' (fixes a regression in decorator 5.0.5) -- Software Heritage autobuilder (on jenkins-debian1) Tue, 06 Apr 2021 10:37:17 +0000 swh-core (0.12.0-1~swh1) unstable-swh; urgency=medium * New upstream release 0.12.0 - (tagged by David Douard on 2021-02-16 11:48:58 +0100) * Upstream changes: - v0.12.0 -- Software Heritage autobuilder (on jenkins-debian1) Tue, 16 Feb 2021 10:52:14 +0000 swh-core (0.11.0-1~swh1) unstable-swh; urgency=medium * New upstream release 0.11.0 - (tagged by David Douard on 2020-12-08 15:35:05 +0100) * Upstream changes: - v0.11.0 -- Software Heritage autobuilder (on jenkins-debian1) Tue, 08 Dec 2020 14:38:23 +0000 swh-core (0.10.0-1~swh1) unstable-swh; urgency=medium * New upstream release 0.10.0 - (tagged by Nicolas Dandrimont on 2020-12-02 11:46:38 +0100) * Upstream changes: - Release swh.core 0.10.0 - db.tests.db_testing: Drop unused database test utilities. - api.serializers: Add support for serializing large negative integers with - msgpack. - Do not mutate api.serializers.ENCODERS or DECODERS. - swh cli: Add support for setting up the log level of multiple loggers. -- Software Heritage autobuilder (on jenkins-debian1) Wed, 02 Dec 2020 10:50:35 +0000 swh-core (0.9.1-1~swh1) unstable-swh; urgency=medium * New upstream release 0.9.1 - (tagged by Antoine Lambert on 2020-11-23 11:24:50 +0100) * Upstream changes: - version 0.9.1 -- Software Heritage autobuilder (on jenkins-debian1) Mon, 23 Nov 2020 10:29:15 +0000 swh-core (0.9.0-1~swh2) unstable-swh; urgency=medium * Split packages python3-swh.core and python3-swh.core.db.pytestplugin -- Antoine R. Dumont (@ardumont) Fri, 20 Nov 2020 16:37:00 +0000 swh-core (0.9.0-1~swh1) unstable-swh; urgency=medium * New upstream release 0.9.0 - (tagged by Antoine R. Dumont (@ardumont) on 2020-11-20 15:35:53 +0100) * Upstream changes: - v0.9.0 - Clarify names around the swh.core.db.pytest_plugin tests - setup: Separate pytest- postgresql dependency and declare it when needed - RPCClient: Fix reraise_exceptions regression - api/serializers: Add Exception type encoder and decoder - Makefile.local: Ensure all tests are executed when invoking make test - core.db.cli: Add coverage and ensure `swh db *` works as expected - core tests: disambiguate arg 'request' through typing -- Software Heritage autobuilder (on jenkins-debian1) Fri, 20 Nov 2020 14:37:00 +0000 swh-core (0.8.0-1~swh1) unstable-swh; urgency=medium * New upstream release 0.8.0 - (tagged by Antoine R. Dumont (@ardumont) on 2020-10-30 09:12:17 +0100) * Upstream changes: - v0.8.0 - cli.db: Open init-admin subcmd to initialize superuser-level scripts -- Software Heritage autobuilder (on jenkins-debian1) Fri, 30 Oct 2020 08:13:02 +0000 swh-core (0.7.1-1~swh1) unstable-swh; urgency=medium * New upstream release 0.7.1 - (tagged by Antoine R. Dumont (@ardumont) on 2020-10-22 18:51:16 +0200) * Upstream changes: - v0.7.1 - Move SWHDatabaseJanitor to db.pytest_plugin module -- Software Heritage autobuilder (on jenkins-debian1) Thu, 22 Oct 2020 16:51:59 +0000 swh-core (0.7.0-1~swh1) unstable-swh; urgency=medium * New upstream release 0.7.0 - (tagged by Antoine R. Dumont (@ardumont) on 2020-10-22 18:31:18 +0200) * Upstream changes: - v0.7.0 - remote_api_endpoint: Allow to declare what http method to use - api.RPCServerApp: Adapt sync rpc server with async rpc server -- Software Heritage autobuilder (on jenkins-debian1) Thu, 22 Oct 2020 16:32:04 +0000 swh-core (0.6.1-1~swh1) unstable-swh; urgency=medium * New upstream release 0.6.1 - (tagged by Antoine R. Dumont (@ardumont) on 2020-10-22 13:53:41 +0200) * Upstream changes: - v0.6.1 - Move pytest_plugin declaration to top-level conftest -- Software Heritage autobuilder (on jenkins-debian1) Thu, 22 Oct 2020 11:54:49 +0000 swh-core (0.6.0-1~swh1) unstable-swh; urgency=medium * New upstream release 0.6.0 - (tagged by Antoine R. Dumont (@ardumont) on 2020-10-22 13:24:55 +0200) * Upstream changes: - v0.6.0 - asynchronous.RPCServerApp: Align implementation with api.RPCServerApp -- Software Heritage autobuilder (on jenkins-debian1) Thu, 22 Oct 2020 11:25:29 +0000 swh-core (0.5.0-1~swh2) unstable-swh; urgency=medium * Bump new release with dependency updated -- Antoine R. Dumont thu, 22 Oct 2020 11:21:04 +0200 swh-core (0.5.0-1~swh1) unstable-swh; urgency=medium * New upstream release 0.5.0 - (tagged by Antoine R. Dumont (@ardumont) on 2020-10-22 11:11:29 +0200) * Upstream changes: - v0.5.0 - Install postgresql_fact fixture for faster postgres tests - api.tests.test_async: Simplify fixture setup - core.config: Drop no longer used SWHConfig -- Software Heritage autobuilder (on jenkins-debian1) Thu, 22 Oct 2020 09:12:14 +0000 swh-core (0.4.0-1~swh1) unstable-swh; urgency=medium * New upstream release 0.4.0 - (tagged by Antoine R. Dumont (@ardumont) on 2020-10-02 11:44:10 +0200) * Upstream changes: - v0.4.0 - config: Deprecate SWHConfig in favor of load_from_envvar function -- Software Heritage autobuilder (on jenkins-debian1) Fri, 02 Oct 2020 09:44:53 +0000 swh-core (0.3.1-1~swh1) unstable-swh; urgency=medium * New upstream release 0.3.1 - (tagged by Valentin Lorentz on 2020-10-01 12:38:08 +0200) * Upstream changes: - v0.3.1 - * Add specific celery task arguments to metadata sent to systemd-journald - * SortedList: Don't inherit from UserList. -- Software Heritage autobuilder (on jenkins-debian1) Thu, 01 Oct 2020 10:40:27 +0000 swh-core (0.3.0-1~swh1) unstable-swh; urgency=medium * New upstream release 0.3.0 - (tagged by David Douard on 2020-09-23 16:24:40 +0200) * Upstream changes: - v0.3.0 -- Software Heritage autobuilder (on jenkins-debian1) Wed, 23 Sep 2020 14:27:08 +0000 swh-core (0.2.3-1~swh1) unstable-swh; urgency=medium * New upstream release 0.2.3 - (tagged by Valentin Lorentz on 2020-08-17 13:55:41 +0200) * Upstream changes: - v0.2.3 - * tarball: add test for permissions. - * Move SortedList from swh-storage. -- Software Heritage autobuilder (on jenkins-debian1) Mon, 17 Aug 2020 11:57:43 +0000 swh-core (0.2.2-1~swh1) unstable-swh; urgency=medium * New upstream release 0.2.2 - (tagged by Antoine R. Dumont (@ardumont) on 2020-07-31 13:41:19 +0200) * Upstream changes: - v0.2.2 - api.classes: Open swh.core.api.classes.stream_results -- Software Heritage autobuilder (on jenkins-debian1) Fri, 31 Jul 2020 11:44:33 +0000 swh-core (0.2.1-1~swh1) unstable-swh; urgency=medium * New upstream release 0.2.1 - (tagged by Valentin Lorentz on 2020-07-30 19:16:57 +0200) * Upstream changes: - v0.2.1 - Make @remote_api_endpoint preserve typing information for mypy. -- Software Heritage autobuilder (on jenkins-debian1) Thu, 30 Jul 2020 17:20:05 +0000 swh-core (0.2.0-1~swh1) unstable-swh; urgency=medium * New upstream release 0.2.0 - (tagged by Antoine R. Dumont (@ardumont) on 2020-07-29 11:18:37 +0200) * Upstream changes: - v0.2.0 - core.api: Expose serializable PagedResult object for pagination api - test_serializers: Refactor using pytest - Migrate from vcversioner to setuptools- scm -- Software Heritage autobuilder (on jenkins-debian1) Wed, 29 Jul 2020 09:20:56 +0000 swh-core (0.1.2-1~swh1) unstable-swh; urgency=medium * New upstream release 0.1.2 - (tagged by Antoine R. Dumont (@ardumont) on 2020-07-08 13:41:51 +0200) * Upstream changes: - v0.1.2 - test_serializers: Move to pytest for that specific erratic assertion -- Software Heritage autobuilder (on jenkins-debian1) Wed, 08 Jul 2020 11:43:25 +0000 swh-core (0.1.1-1~swh1) unstable-swh; urgency=medium * New upstream release 0.1.1 - (tagged by Antoine R. Dumont (@ardumont) on 2020-07-08 13:03:52 +0200) * Upstream changes: - v0.1.1 - api.tests: Fix unsupported matches keyword to match - requirements-db: Move typing- extension from test to runtime deps -- Software Heritage autobuilder (on jenkins-debian1) Wed, 08 Jul 2020 11:07:55 +0000 swh-core (0.1.0-1~swh1) unstable-swh; urgency=medium * New upstream release 0.1.0 - (tagged by David Douard on 2020-07-06 14:33:28 +0200) * Upstream changes: - v0.1.0 -- Software Heritage autobuilder (on jenkins-debian1) Mon, 06 Jul 2020 12:36:15 +0000 swh-core (0.0.95-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.95 - (tagged by Nicolas Dandrimont on 2020-04-17 17:20:35 +0200) * Upstream changes: - Release swh.core v0.0.95 - support serializing large integers in msgpack - add documentation for CLI - move formatting to black -- Software Heritage autobuilder (on jenkins-debian1) Fri, 17 Apr 2020 16:05:01 +0000 swh-core (0.0.94-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.94 - (tagged by Valentin Lorentz on 2020-02-28 14:28:11 +0100) * Upstream changes: - v0.0.94 - Allow subclasses of RPCClient to override methods. -- Software Heritage autobuilder (on jenkins-debian1) Fri, 28 Feb 2020 13:32:41 +0000 swh-core (0.0.93-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.93 - (tagged by Valentin Lorentz on 2020-02-26 15:26:29 +0100) * Upstream changes: - v0.0.93 - Reintroduce support for decoding legacy msgpack encoding -- Software Heritage autobuilder (on jenkins-debian1) Wed, 26 Feb 2020 14:29:46 +0000 swh-core (0.0.92-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.92 - (tagged by Valentin Lorentz on 2020-02-19 15:40:57 +0100) * Upstream changes: - v0.0.92 - Add support for msgpack 1.0.0 -- Software Heritage autobuilder (on jenkins-debian1) Wed, 19 Feb 2020 14:45:27 +0000 swh-core (0.0.91-1~swh2) unstable-swh; urgency=medium * Add missing python3-iso8601 build dependency -- Antoine Lambert Wed, 19 Feb 2020 11:18:34 +0100 swh-core (0.0.91-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.91 - (tagged by Antoine Lambert on 2020-02-18 16:43:59 +0100) * Upstream changes: - version 0.0.91 -- Software Heritage autobuilder (on jenkins-debian1) Tue, 18 Feb 2020 15:51:39 +0000 swh-core (0.0.90-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.90 - (tagged by Valentin Lorentz on 2020-02-18 13:54:30 +0100) * Upstream changes: - v0.0.90 - Remove exception pickling from the async server, as in the sync server. -- Software Heritage autobuilder (on jenkins-debian1) Tue, 18 Feb 2020 12:59:38 +0000 swh-core (0.0.89-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.89 - (tagged by Valentin Lorentz on 2020-02-18 11:35:01 +0100) * Upstream changes: - v0.0.89 - * Change msgpack serialization to be closer to the JSON one. - * Add support for extra {de,en}coders. - * Add extra_type_encoders and extra_type_decoders attributes to RPC clients and servers. - * Use iso8601.parse_date instead of dateutil.parser.parse. -- Software Heritage autobuilder (on jenkins-debian1) Tue, 18 Feb 2020 10:43:34 +0000 swh-core (0.0.88-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.88 - (tagged by Valentin Lorentz on 2020-02-14 12:22:23 +0100) * Upstream changes: - v0.0.88 - In case of errors, return a simple dictionary instead of pickled exception. -- Software Heritage autobuilder (on jenkins-debian1) Fri, 14 Feb 2020 11:27:02 +0000 swh-core (0.0.87-1~swh2) unstable-swh; urgency=medium * Fix package build -- Antoine R. Dumont (@ardumont) Thu, 30 Jan 2020 14:06:54 +0100 swh-core (0.0.87-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.87 - (tagged by Valentin Lorentz on 2020-01-29 12:21:48 +0100) * Upstream changes: - v0.0.87 - Make db_transaction* remove db/cur from the signature. -- Software Heritage autobuilder (on jenkins-debian1) Wed, 29 Jan 2020 11:28:23 +0000 swh-core (0.0.86-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.86 - (tagged by Antoine R. Dumont (@ardumont) on 2020-01-23 09:08:56 +0100) * Upstream changes: - v0.0.86 - sentry: Add environment variable $SWH_SENTRY_ENVIRONMENT - pytest_plugin: Fix sphinx warnings -- Software Heritage autobuilder (on jenkins-debian1) Thu, 23 Jan 2020 08:12:40 +0000 swh-core (0.0.85-1~swh2) unstable-swh; urgency=medium * Fix package build on buster -- Antoine Lambert Thu, 16 Jan 2020 11:00:00 +0000 swh-core (0.0.85-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.85 - (tagged by Valentin Lorentz on 2020-01-15 13:07:36 +0100) * Upstream changes: - v0.0.85 - Add env var SWH_MAIN_PACKAGE -- Software Heritage autobuilder (on jenkins-debian1) Wed, 15 Jan 2020 12:11:49 +0000 swh-core (0.0.84-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.84 - (tagged by Antoine R. Dumont (@ardumont) on 2019-12-13 09:08:00 +0100) * Upstream changes: - v0.0.84 - Improve tarball support for tar.lz, tar.x, tar.Z files -- Software Heritage autobuilder (on jenkins-debian1) Fri, 13 Dec 2019 08:14:23 +0000 swh-core (0.0.83-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.83 - (tagged by Antoine R. Dumont (@ardumont) on 2019-12-12 16:03:25 +0100) * Upstream changes: - v0.0.83 - core.config: Rename configuration key -- Software Heritage autobuilder (on jenkins-debian1) Thu, 12 Dec 2019 15:06:28 +0000 swh-core (0.0.82-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.82 - (tagged by Nicolas Dandrimont on 2019-12-11 15:04:09 +0100) * Upstream changes: - Release swh.core 0.0.82 - Add missing conftest.py to MANIFEST.in -- Software Heritage autobuilder (on jenkins-debian1) Wed, 11 Dec 2019 14:09:00 +0000 swh-core (0.0.81-1~swh2) unstable-swh; urgency=medium * Add dependency to python3-sentry-sdk -- Nicolas Dandrimont Wed, 11 Dec 2019 14:58:54 +0100 swh-core (0.0.81-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.81 - (tagged by Valentin Lorentz on 2019-12-10 13:59:17 +0100) * Upstream changes: - v0.0.81 - * Include all requirements in MANIFEST.in - * Split test requirements to try and properly minimize dependencies - * Make the CLI initialize sentry-sdk based on CLI options/envvars. - * Add gunicorn config script to initialize sentry-sdk based on envvars. -- Software Heritage autobuilder (on jenkins-debian1) Tue, 10 Dec 2019 13:03:13 +0000 swh-core (0.0.80-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.80 - (tagged by Nicolas Dandrimont on 2019-11-19 16:36:35 +0100) * Upstream changes: - Release swh.core v0.0.80 - Let TypeErrors pass through the RPC layer - Register SIGINT/SIGTERM handlers for the CLI -- Software Heritage autobuilder (on jenkins-debian1) Tue, 19 Nov 2019 15:41:09 +0000 swh-core (0.0.79-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.79 - (tagged by Stefano Zacchiroli on 2019-11-18 13:35:19 +0100) * Upstream changes: - v0.0.79 ======= - * RPCClient: add response attribute to RemoteException - * RPCClent: rename and refactor check_status (now raise_for_status) - * RPCClient: check HTTP status code for errors also when streaming - * cli: Add support for loading a logging configuration file - * cli: Allow adding a Notes section between Options and Commands - * Add trailing dot to help texts for consistency - * logger: only flatten dicts if all keys are strings - * Move to @pytest.fixture from yield_fixture - * test_rpc_client_server.py: fix typo in docstring -- Software Heritage autobuilder (on jenkins-debian1) Mon, 18 Nov 2019 12:42:12 +0000 swh-core (0.0.78-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.78 - (tagged by Nicolas Dandrimont on 2019-11-06 18:01:56 +0100) * Upstream changes: - Release swh.core 0.0.78 - allow the swh command to work even when a plugin fails - hardcode bytea and bytea[] type oids in BaseDb -- Software Heritage autobuilder (on jenkins-debian1) Wed, 06 Nov 2019 17:05:38 +0000 swh-core (0.0.77-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.77 - (tagged by Antoine R. Dumont (@ardumont) on 2019-11-06 14:10:58 +0100) * Upstream changes: - v0.0.77 - pytest_plugin: Decode url to resolve filename - api/serializers: Force json module use to decode requests text response -- Software Heritage autobuilder (on jenkins-debian1) Wed, 06 Nov 2019 13:15:03 +0000 swh-core (0.0.76-1~swh2) unstable-swh; urgency=medium * Force using the swh.core pytest plugin -- Nicolas Dandrimont Wed, 23 Oct 2019 14:50:04 +0200 swh-core (0.0.76-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.76 - (tagged by Nicolas Dandrimont on 2019-10-18 10:16:20 +0200) * Upstream changes: - Release swh.core v0.0.76 - Make the systemd dependency optional -- Software Heritage autobuilder (on jenkins-debian1) Fri, 18 Oct 2019 08:25:15 +0000 swh-core (0.0.75-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.75 - (tagged by Antoine R. Dumont (@ardumont) on 2019-10-14 17:51:58 +0200) * Upstream changes: - v0.0.75 - pytest_plugin: Add support for http requests -- Software Heritage autobuilder (on jenkins-debian1) Mon, 14 Oct 2019 15:57:05 +0000 swh-core (0.0.74-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.74 - (tagged by David Douard on 2019-10-11 15:30:51 +0200) * Upstream changes: - v0.0.74 -- Software Heritage autobuilder (on jenkins-debian1) Fri, 11 Oct 2019 13:35:17 +0000 swh-core (0.0.73-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.73 - (tagged by Antoine R. Dumont (@ardumont) on 2019-10-09 14:16:04 +0200) * Upstream changes: - v0.0.73 - Improve pytest-plugin fixture to ease testing with pagination -- Software Heritage autobuilder (on jenkins-debian1) Wed, 09 Oct 2019 12:20:36 +0000 swh-core (0.0.72-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.72 - (tagged by Antoine R. Dumont (@ardumont) on 2019-10-09 10:59:28 +0200) * Upstream changes: - v0.0.72 - Fix tox.ini's py3 environment -- Software Heritage autobuilder (on jenkins-debian1) Wed, 09 Oct 2019 09:02:51 +0000 swh-core (0.0.70-1~swh2) unstable-swh; urgency=medium * Add new dependency on python3-tz -- Nicolas Dandrimont Tue, 01 Oct 2019 15:07:09 +0200 swh-core (0.0.70-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.70 - (tagged by Stefano Zacchiroli on 2019-09-27 10:16:41 +0200) * Upstream changes: - v0.0.70 - init.py: switch to documented way of extending path -- Software Heritage autobuilder (on jenkins-debian1) Fri, 27 Sep 2019 08:21:29 +0000 swh-core (0.0.69-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.69 - (tagged by Stefano Zacchiroli on 2019-09-20 15:50:52 +0200) * Upstream changes: - v0.0.69 - MANIFEST.in: ship py.typed -- Software Heritage autobuilder (on jenkins-debian1) Fri, 20 Sep 2019 13:54:15 +0000 swh-core (0.0.68-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.68 - (tagged by Stefano Zacchiroli on 2019-09-20 15:05:29 +0200) * Upstream changes: - v0.0.68 - * mypy: ignore django-stubs, needed only by hypothesis - * mypy: use conffile to ignore requests_mock - * typing: minimal changes to make a no-op mypy run pass - * db_testing.py: do not explode when TEST_DB_DUMP = None - * swh.core.config.parse_config_file: fix sphinx markup in docstring - * statsd: protect access to the statsd's socket - * tests: add tests for swh.logger and swh.tarball modules - * Remove fallback when aiohttp_utils is not installed. -- Software Heritage autobuilder (on jenkins-debian1) Fri, 20 Sep 2019 13:09:50 +0000 swh-core (0.0.67-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.67 - (tagged by Valentin Lorentz on 2019-08-22 13:56:36 +0200) * Upstream changes: - v0.0.67 - Improve error handling in Db.copy_to -- Software Heritage autobuilder (on jenkins-debian1) Thu, 22 Aug 2019 12:02:14 +0000 swh-core (0.0.66-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.66 - (tagged by David Douard on 2019-07-30 13:55:16 +0200) * Upstream changes: - v0.0.66 -- Software Heritage autobuilder (on jenkins-debian1) Tue, 30 Jul 2019 11:58:47 +0000 swh-core (0.0.65-1~swh2) unstable-swh; urgency=medium * debian/control: add missing dependencies. -- David Douard Tue, 16 Jul 2019 14:46:43 +0200 swh-core (0.0.65-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.65 - (tagged by David Douard on 2019-07-15 16:49:47 +0200) * Upstream changes: - v0.0.65 - needed to fix my mess with 0.0.64 tag, since the wrong 0.0.64 version has - already been pushed to pypi. -- Software Heritage autobuilder (on jenkins-debian1) Mon, 15 Jul 2019 14:53:29 +0000 swh-core (0.0.64-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.64 - (tagged by David Douard on 2019-07-15 16:33:32 +0200) * Upstream changes: - v0.0.64 -- Software Heritage autobuilder (on jenkins-debian1) Mon, 15 Jul 2019 14:37:04 +0000 swh-core (0.0.63-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.63 - (tagged by Antoine Lambert on 2019-05-21 13:12:11 +0200) * Upstream changes: - version 0.0.63 -- Software Heritage autobuilder (on jenkins-debian1) Tue, 21 May 2019 11:15:45 +0000 swh-core (0.0.62-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.62 - (tagged by Antoine Lambert on 2019-05-20 14:56:05 +0200) * Upstream changes: - version 0.0.62 -- Software Heritage autobuilder (on jenkins-debian1) Mon, 20 May 2019 13:01:38 +0000 swh-core (0.0.61-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.61 - (tagged by David Douard on 2019-05-17 10:32:07 +0200) * Upstream changes: - v0.0.61 -- Software Heritage autobuilder (on jenkins-debian1) Fri, 17 May 2019 08:38:08 +0000 swh-core (0.0.60-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.60 - (tagged by David Douard on 2019-05-06 15:27:44 +0200) * Upstream changes: - v0.0.60 -- Software Heritage autobuilder (on jenkins-debian1) Mon, 06 May 2019 13:32:48 +0000 swh-core (0.0.59-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.59 - (tagged by Valentin Lorentz on 2019-04-09 16:55:41 +0200) * Upstream changes: - Explicitly give Db connections back to the pool. - So they gracefully release the connection on error instead - of relying on reference-counting to call the Db's `__del__` - (which does not happen in Hypothesis tests) because a ref - to it is kept via the traceback object. -- Software Heritage autobuilder (on jenkins-debian1) Tue, 09 Apr 2019 16:12:32 +0000 swh-core (0.0.58-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.58 - (tagged by Antoine Lambert on 2019-04-02 17:19:05 +0200) * Upstream changes: - version 0.0.58 -- Software Heritage autobuilder (on jenkins-debian1) Tue, 02 Apr 2019 15:24:34 +0000 swh-core (0.0.57-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.57 - (tagged by Nicolas Dandrimont on 2019-03-28 15:51:27 +0100) * Upstream changes: - Release swh.core v0.0.57 - Move to native async primitives - Fix statsd.timed exceptional behavior bug/misfeature - Fix SWHRemoteAPI post_stream method -- Software Heritage autobuilder (on jenkins-debian1) Thu, 28 Mar 2019 14:55:58 +0000 swh-core (0.0.56-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.56 - (tagged by David Douard on 2019-03-19 10:17:06 +0100) * Upstream changes: - v0.0.56 -- Software Heritage autobuilder (on jenkins-debian1) Tue, 19 Mar 2019 09:27:18 +0000 swh-core (0.0.55-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.55 - (tagged by Antoine R. Dumont (@ardumont) on 2019-02-19 12:28:26 +0100) * Upstream changes: - v0.0.55 - Fix runtime dependencies -- Software Heritage autobuilder (on jenkins-debian1) Tue, 19 Feb 2019 11:32:28 +0000 swh-core (0.0.54-1~swh2) unstable-swh; urgency=medium * New upstream release 0.0.54 * Upstream changes: - Add missing build dependencies -- Antoine R. Dumont (@ardumont) Tue, 12 Feb 2019 16:25:34 +0000 swh-core (0.0.54-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.54 - (tagged by Valentin Lorentz on 2019-02-11 16:47:18 +0100) * Upstream changes: - Add test for BaseDb.connect. -- Software Heritage autobuilder (on jenkins-debian1) Tue, 12 Feb 2019 12:37:43 +0000 swh-core (0.0.53-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.53 - (tagged by Antoine R. Dumont (@ardumont) on 2019-02-08 09:09:30 +0100) * Upstream changes: - v0.0.53 - Fix debian build -- Software Heritage autobuilder (on jenkins-debian1) Fri, 08 Feb 2019 08:12:31 +0000 swh-core (0.0.52-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.52 - (tagged by David Douard on 2019-02-06 15:24:04 +0100) * Upstream changes: - v0.0.52 -- Software Heritage autobuilder (on jenkins-debian1) Wed, 06 Feb 2019 14:27:14 +0000 swh-core (0.0.51-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.51 - (tagged by David Douard on 2019-02-01 14:28:27 +0100) * Upstream changes: - v0.0.51 -- Software Heritage autobuilder (on jenkins-debian1) Fri, 01 Feb 2019 13:31:45 +0000 swh-core (0.0.50-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.50 - (tagged by Nicolas Dandrimont on 2019-01-09 15:50:58 +0100) * Upstream changes: - Release swh.core v0.0.50 - Add statsd client module - Log used config files -- Software Heritage autobuilder (on jenkins-debian1) Wed, 09 Jan 2019 14:54:37 +0000 swh-core (0.0.49-1~swh1) unstable-swh; urgency=medium * Make DbTestFixture.setUp() accept and pass *args and **kwargs. -- Software Heritage autobuilder (on jenkins-debian1) Tue, 08 Jan 2019 16:38:02 +0000 swh-core (0.0.48-1~swh1) unstable-swh; urgency=medium * v0.0.48 * swh.core.cli: Update swh-db-init to make it idemtpotent -- Antoine R. Dumont (@ardumont) Tue, 08 Jan 2019 15:33:15 +0000 swh-core (0.0.47-1~swh1) unstable-swh; urgency=medium * v0.0.47 * swh.core.cli: Fix flag -- Antoine R. Dumont (@ardumont) Tue, 08 Jan 2019 15:16:09 +0000 swh-core (0.0.46-1~swh1) unstable-swh; urgency=medium * v0.0.46 * utils.grouper: Improve implementation * Remove now-obsolete information about swh.core.worker -- Antoine R. Dumont (@ardumont) Tue, 08 Jan 2019 14:37:34 +0000 swh-core (0.0.45-1~swh1) unstable-swh; urgency=medium * Release swh.core v0.0.45 * Compatibility with recent msgpack * Debian packaging-related cleanups -- Nicolas Dandrimont Thu, 22 Nov 2018 21:09:53 +0100 swh-core (0.0.44-1~swh1) unstable-swh; urgency=medium * Release swh.core v0.0.44 * Refactor the database testing fixtures * Stop unsafe serialization/deserialization constructs * Update tests to use nose -- Nicolas Dandrimont Thu, 18 Oct 2018 18:20:12 +0200 swh-core (0.0.43-1~swh1) unstable-swh; urgency=medium * v0.0.43 * Fix missing dependency declaration -- Antoine R. Dumont (@ardumont) Thu, 11 Oct 2018 15:47:06 +0200 swh-core (0.0.42-1~swh1) unstable-swh; urgency=medium * v0.0.42 * Fix missing dependency declaration -- Antoine R. Dumont (@ardumont) Thu, 11 Oct 2018 15:45:25 +0200 swh-core (0.0.41-1~swh1) unstable-swh; urgency=medium * Add functions to generate HTTP API clients and servers from databases. * Summary: This moves the interesting parts of D505 into the core, so other components can use them as well. * Test Plan: `make test` * Reviewers: ardumont, seirl, #reviewers * Reviewed By: ardumont, #reviewers * Subscribers: douardda * Differential Revision: https://forge.softwareheritage.org/D507 -- Valentin Lorentz Thu, 11 Oct 2018 10:57:27 +0200 swh-core (0.0.40-1~swh1) unstable-swh; urgency=medium * v0.0.40 * swh.core.api.SWHRemoteAPI: Permit to set a query timeout option -- Antoine R. Dumont (@ardumont) Thu, 24 May 2018 12:10:03 +0200 swh-core (0.0.39-1~swh1) unstable-swh; urgency=medium * v0.0.39 * package: Add missing runtime dependency -- Antoine R. Dumont (@ardumont) Thu, 26 Apr 2018 15:24:22 +0200 swh-core (0.0.38-1~swh1) unstable-swh; urgency=medium * v0.0.38 * tests: Use more reasonable psql options for db restores * swh.core.serializers: Add custom types serialization -- Antoine R. Dumont (@ardumont) Thu, 26 Apr 2018 15:15:27 +0200 swh-core (0.0.37-1~swh1) unstable-swh; urgency=medium * v0.0.37 * Move test fixture in swh.core.tests.server_testing module -- Antoine R. Dumont (@ardumont) Wed, 25 Apr 2018 15:00:02 +0200 swh-core (0.0.36-1~swh1) unstable-swh; urgency=medium * v0.0.36 * Migrate swh.loader.tar.tarball module in swh.core -- Antoine R. Dumont (@ardumont) Wed, 06 Dec 2017 12:03:29 +0100 swh-core (0.0.35-1~swh1) unstable-swh; urgency=medium * Release swh.core version 0.0.35 * Update packaging runes -- Nicolas Dandrimont Thu, 12 Oct 2017 18:07:50 +0200 swh-core (0.0.34-1~swh1) unstable-swh; urgency=medium * Release swh.core v0.0.34 * New modular database test fixture -- Nicolas Dandrimont Mon, 07 Aug 2017 18:29:48 +0200 swh-core (0.0.33-1~swh1) unstable-swh; urgency=medium * Release swh.core v0.0.33 * Be more conservative with remote API responses -- Nicolas Dandrimont Mon, 19 Jun 2017 19:01:38 +0200 swh-core (0.0.32-1~swh1) unstable-swh; urgency=medium * Release swh-core v0.0.32 * Add asynchronous streaming methods for internal APIs * Remove task arguments from systemd-journal loggers -- Nicolas Dandrimont Tue, 09 May 2017 14:04:22 +0200 swh-core (0.0.31-1~swh1) unstable-swh; urgency=medium * Release swh.core v0.0.31 * Add explicit dependency on python3-systemd -- Nicolas Dandrimont Fri, 07 Apr 2017 15:11:26 +0200 swh-core (0.0.30-1~swh1) unstable-swh; urgency=medium * Release swh.core v0.0.30 * drop swh.core.hashutil (moved to swh.model.hashutil) * add a systemd logger -- Nicolas Dandrimont Fri, 07 Apr 2017 11:49:15 +0200 swh-core (0.0.29-1~swh1) unstable-swh; urgency=medium * Release swh.core v0.0.29 * Catch proper exception in the base API client -- Nicolas Dandrimont Thu, 02 Feb 2017 00:19:25 +0100 swh-core (0.0.28-1~swh1) unstable-swh; urgency=medium * v0.0.28 * Refactoring some common code into swh.core -- Antoine R. Dumont (@ardumont) Thu, 26 Jan 2017 14:54:22 +0100 swh-core (0.0.27-1~swh1) unstable-swh; urgency=medium * v0.0.27 * Fix issue with default boolean value -- Antoine R. Dumont (@ardumont) Thu, 20 Oct 2016 16:15:20 +0200 swh-core (0.0.26-1~swh1) unstable-swh; urgency=medium * Release swh.core v0.0.26 * Raise an exception when a configuration file exists and is unreadable -- Nicolas Dandrimont Wed, 12 Oct 2016 10:16:09 +0200 swh-core (0.0.25-1~swh1) unstable-swh; urgency=medium * v0.0.25 * Add new function utils.cwd -- Antoine R. Dumont (@ardumont) Thu, 29 Sep 2016 21:29:37 +0200 swh-core (0.0.24-1~swh1) unstable-swh; urgency=medium * v0.0.24 * Deal with edge case in logger regarding json -- Antoine R. Dumont (@ardumont) Thu, 22 Sep 2016 12:21:09 +0200 swh-core (0.0.23-1~swh1) unstable-swh; urgency=medium * Release swh.core v0.0.23 * Properly fix the PyYAML dependency -- Nicolas Dandrimont Tue, 23 Aug 2016 16:20:29 +0200 swh-core (0.0.22-1~swh1) unstable-swh; urgency=medium * Release swh.core v0.0.22 * Proper loading of yaml and ini files in all paths -- Nicolas Dandrimont Fri, 19 Aug 2016 15:45:55 +0200 swh-core (0.0.21-1~swh1) unstable-swh; urgency=medium * v0.0.21 * Update test tools -- Antoine R. Dumont (@ardumont) Tue, 19 Jul 2016 14:47:01 +0200 swh-core (0.0.20-1~swh1) unstable-swh; urgency=medium * Release swh.core v0.0.20 * Add some generic bytes <-> escaped unicode methods -- Nicolas Dandrimont Tue, 14 Jun 2016 16:54:41 +0200 swh-core (0.0.19-1~swh1) unstable-swh; urgency=medium * v0.0.19 * Resurrect swh.core.utils -- Antoine R. Dumont (@ardumont) Fri, 15 Apr 2016 12:40:43 +0200 swh-core (0.0.18-1~swh1) unstable-swh; urgency=medium * v0.0.18 * Add swh.core.utils * serializers: support UUIDs all around -- Antoine R. Dumont (@ardumont) Sat, 26 Mar 2016 11:16:33 +0100 swh-core (0.0.17-1~swh1) unstable-swh; urgency=medium * Release swh.core v0.0.17 * Allow serialization of UUIDs -- Nicolas Dandrimont Fri, 04 Mar 2016 11:40:56 +0100 swh-core (0.0.16-1~swh1) unstable-swh; urgency=medium * Release swh.core version 0.0.16 * add bytehex_to_hash and hash_to_bytehex in hashutil * move scheduling utilities to swh.scheduler -- Nicolas Dandrimont Fri, 19 Feb 2016 18:12:10 +0100 swh-core (0.0.15-1~swh1) unstable-swh; urgency=medium * Release v0.0.15 * Add hashutil.hash_git_object -- Nicolas Dandrimont Wed, 16 Dec 2015 16:31:26 +0100 swh-core (0.0.14-1~swh1) unstable-swh; urgency=medium * v0.0.14 * Add simple README * Update license * swh.core.hashutil.hashfile can now deal with filepath as bytes -- Antoine R. Dumont (@ardumont) Fri, 23 Oct 2015 11:13:14 +0200 swh-core (0.0.13-1~swh1) unstable-swh; urgency=medium * Prepare deployment of swh.core v0.0.13 -- Nicolas Dandrimont Fri, 09 Oct 2015 17:32:49 +0200 swh-core (0.0.12-1~swh1) unstable-swh; urgency=medium * Prepare deployment of swh.core v0.0.12 -- Nicolas Dandrimont Tue, 06 Oct 2015 17:34:34 +0200 swh-core (0.0.11-1~swh1) unstable-swh; urgency=medium * Prepare deployment of swh.core v0.0.11 -- Nicolas Dandrimont Sat, 03 Oct 2015 15:57:03 +0200 swh-core (0.0.10-1~swh1) unstable-swh; urgency=medium * Prepare deploying swh.core v0.0.10 -- Nicolas Dandrimont Sat, 03 Oct 2015 12:28:52 +0200 swh-core (0.0.9-1~swh1) unstable-swh; urgency=medium * Prepare deploying swh.core v0.0.9 -- Nicolas Dandrimont Sat, 03 Oct 2015 11:36:55 +0200 swh-core (0.0.8-1~swh1) unstable-swh; urgency=medium * Prepare deployment of swh.core v0.0.8 -- Nicolas Dandrimont Thu, 01 Oct 2015 12:31:44 +0200 swh-core (0.0.7-1~swh1) unstable-swh; urgency=medium * Prepare deployment of swh.core v0.0.7 -- Nicolas Dandrimont Thu, 01 Oct 2015 11:29:04 +0200 swh-core (0.0.6-1~swh1) unstable-swh; urgency=medium * Prepare deployment of swh.core v0.0.6 -- Nicolas Dandrimont Tue, 29 Sep 2015 16:48:44 +0200 swh-core (0.0.5-1~swh1) unstable-swh; urgency=medium * Prepare v0.0.5 deployment -- Nicolas Dandrimont Tue, 29 Sep 2015 16:08:32 +0200 swh-core (0.0.4-1~swh1) unstable-swh; urgency=medium * Tagging swh.core 0.0.4 -- Nicolas Dandrimont Fri, 25 Sep 2015 15:41:26 +0200 swh-core (0.0.3-1~swh1) unstable-swh; urgency=medium * Tag swh.core v0.0.3 -- Nicolas Dandrimont Fri, 25 Sep 2015 11:07:10 +0200 swh-core (0.0.2-1~swh1) unstable-swh; urgency=medium * Deploy v0.0.2 -- Nicolas Dandrimont Wed, 23 Sep 2015 12:08:50 +0200 swh-core (0.0.1-1~swh1) unstable-swh; urgency=medium * Initial release * Tag v0.0.1 for deployment -- Nicolas Dandrimont Tue, 22 Sep 2015 14:52:26 +0200 diff --git a/docs/index.rst b/docs/index.rst index e48fb07..0873240 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,13 +1,21 @@ .. _swh-core: .. include:: README.rst Reference Documentation ----------------------- .. toctree:: :maxdepth: 2 cli db - /apidoc/swh.core + +.. only:: standalone_package_doc + + Indices and tables + ------------------ + + * :ref:`genindex` + * :ref:`modindex` + * :ref:`search` diff --git a/swh.core.egg-info/PKG-INFO b/swh.core.egg-info/PKG-INFO index ee6daf2..645aca5 100644 --- a/swh.core.egg-info/PKG-INFO +++ b/swh.core.egg-info/PKG-INFO @@ -1,39 +1,39 @@ Metadata-Version: 2.1 Name: swh.core -Version: 2.17.0 +Version: 2.18.0 Summary: Software Heritage core utilities Home-page: https://forge.softwareheritage.org/diffusion/DCORE/ Author: Software Heritage developers Author-email: swh-devel@inria.fr Project-URL: Bug Reports, https://forge.softwareheritage.org/maniphest Project-URL: Funding, https://www.softwareheritage.org/donate Project-URL: Source, https://forge.softwareheritage.org/source/swh-core Project-URL: Documentation, https://docs.softwareheritage.org/devel/swh-core/ Classifier: Programming Language :: Python :: 3 Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3) Classifier: Operating System :: OS Independent Classifier: Development Status :: 5 - Production/Stable Requires-Python: >=3.7 Description-Content-Type: text/x-rst Provides-Extra: testing-core Provides-Extra: logging Provides-Extra: db Provides-Extra: http Provides-Extra: github Provides-Extra: testing License-File: LICENSE License-File: AUTHORS Software Heritage - Core foundations ==================================== Low-level utilities and helpers used by almost all other modules in the stack. core library for swh's modules: - config parser - serialization - logging mechanism - database connection - http-based RPC client/server diff --git a/swh/core/github/pytest_plugin.py b/swh/core/github/pytest_plugin.py index 20c5e80..a38160a 100644 --- a/swh/core/github/pytest_plugin.py +++ b/swh/core/github/pytest_plugin.py @@ -1,184 +1,202 @@ # Copyright (C) 2020-2022 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information import time from typing import Dict, Iterator, List, Optional, Union import pytest import requests_mock HTTP_GITHUB_API_URL = "https://api.github.com/repositories" def fake_time_sleep(duration: float, sleep_calls: Optional[List[float]] = None): """Record calls to time.sleep in the sleep_calls list.""" if duration < 0: raise ValueError("Can't sleep for a negative amount of time!") if sleep_calls is not None: sleep_calls.append(duration) def fake_time_time(): """Return 0 when running time.time()""" return 0 @pytest.fixture def monkeypatch_sleep_calls(monkeypatch) -> Iterator[List[float]]: """Monkeypatch `time.time` and `time.sleep`. Returns a list cumulating the arguments passed to time.sleep().""" sleeps: List[float] = [] monkeypatch.setattr(time, "sleep", lambda d: fake_time_sleep(d, sleeps)) monkeypatch.setattr(time, "time", fake_time_time) yield sleeps @pytest.fixture() def num_before_ratelimit() -> int: """Number of successful requests before the ratelimit hits""" return 0 @pytest.fixture() def num_ratelimit() -> Optional[int]: """Number of rate-limited requests; None means infinity""" return None @pytest.fixture() def ratelimit_reset() -> Optional[int]: """Value of the X-Ratelimit-Reset header on ratelimited responses""" return None def github_ratelimit_callback( request: requests_mock.request._RequestObjectProxy, context: requests_mock.response._Context, + remaining_requests: int, ratelimit_reset: Optional[int], ) -> Dict[str, str]: """Return a rate-limited GitHub API response.""" # Check request headers assert request.headers["Accept"] == "application/vnd.github.v3+json" assert request.headers["User-Agent"] is not None if "Authorization" in request.headers: context.status_code = 429 else: context.status_code = 403 if ratelimit_reset is not None: context.headers["X-Ratelimit-Reset"] = str(ratelimit_reset) + context.headers["X-Ratelimit-Remaining"] = str(remaining_requests) return { "message": "API rate limit exceeded for .", "documentation_url": "https://developer.github.com/v3/#rate-limiting", } def github_repo(i: int) -> Dict[str, Union[int, str]]: """Basic repository information returned by the GitHub API""" repo: Dict[str, Union[int, str]] = { "id": i, "html_url": f"https://github.com/origin/{i}", } # Set the pushed_at date on one of the origins if i == 4321: repo["pushed_at"] = "2018-11-08T13:16:24Z" return repo def github_response_callback( request: requests_mock.request._RequestObjectProxy, context: requests_mock.response._Context, + remaining_requests: int, page_size: int = 1000, origin_count: int = 10000, ) -> List[Dict[str, Union[str, int]]]: """Return minimal GitHub API responses for the common case where the loader hasn't been rate-limited""" # Check request headers assert request.headers["Accept"] == "application/vnd.github.v3+json" assert request.headers["User-Agent"] is not None # Check request parameters: per_page == 1000, since = last_repo_id assert "per_page" in request.qs assert request.qs["per_page"] == [str(page_size)] assert "since" in request.qs since = int(request.qs["since"][0]) next_page = since + page_size if next_page < origin_count: # the first id for the next page is within our origin count; add a Link # header to the response next_url = f"{HTTP_GITHUB_API_URL}?per_page={page_size}&since={next_page}" context.headers["Link"] = f"<{next_url}>; rel=next" + context.headers["X-Ratelimit-Remaining"] = str(remaining_requests) return [github_repo(i) for i in range(since + 1, min(next_page, origin_count) + 1)] @pytest.fixture() -def requests_ratelimited( +def github_requests_ratelimited( num_before_ratelimit: int, num_ratelimit: Optional[int], ratelimit_reset: Optional[int], ) -> Iterator[requests_mock.Mocker]: """Mock requests to the GitHub API, returning a rate-limiting status code after `num_before_ratelimit` requests. GitHub does inconsistent rate-limiting: - Anonymous requests return a 403 status code - Authenticated requests return a 429 status code, with an X-Ratelimit-Reset header. This fixture takes multiple arguments (which can be overridden with a :func:`pytest.mark.parametrize` parameter): - num_before_ratelimit: the global number of requests until the ratelimit triggers - num_ratelimit: the number of requests that return a rate-limited response. - ratelimit_reset: the timestamp returned in X-Ratelimit-Reset if the request is authenticated. The default values set in the previous fixtures make all requests return a rate limit response. """ current_request = 0 def response_callback(request, context): nonlocal current_request current_request += 1 - if num_before_ratelimit < current_request and ( - num_ratelimit is None - or current_request < num_before_ratelimit + num_ratelimit + 1 + if num_before_ratelimit >= current_request: + # case 1: not yet rate-limited + return github_response_callback( + request, context, (num_before_ratelimit or 1000) - current_request + ) + elif ( + num_ratelimit is not None + and current_request >= num_before_ratelimit + num_ratelimit + 1 ): - return github_ratelimit_callback(request, context, ratelimit_reset) + # case 3: no longer rate-limited + return github_response_callback( + request, context, (num_before_ratelimit + 1000) - current_request + ) else: - return github_response_callback(request, context) + # case 2: being rate-limited + return github_ratelimit_callback( + request, + context, + max(0, (num_before_ratelimit or 1000) - current_request), + ratelimit_reset, + ) with requests_mock.Mocker() as mock: mock.get(HTTP_GITHUB_API_URL, json=response_callback) yield mock @pytest.fixture def github_credentials() -> List[Dict[str, str]]: """Return a static list of GitHub credentials""" return sorted( [{"username": f"swh{i:d}", "token": f"token-{i:d}"} for i in range(3)] + [ {"username": f"swh-legacy{i:d}", "password": f"token-legacy-{i:d}"} for i in range(3) ], key=lambda c: c["username"], ) @pytest.fixture def all_tokens(github_credentials) -> List[str]: """Return the list of tokens matching the static credential""" return [t.get("token", t.get("password")) for t in github_credentials] diff --git a/swh/core/github/tests/test_github_utils.py b/swh/core/github/tests/test_github_utils.py index d3978f7..2db2de3 100644 --- a/swh/core/github/tests/test_github_utils.py +++ b/swh/core/github/tests/test_github_utils.py @@ -1,211 +1,361 @@ # Copyright (C) 2022 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information +import itertools import logging +from unittest.mock import call import pytest from swh.core.github.pytest_plugin import HTTP_GITHUB_API_URL from swh.core.github.utils import ( GitHubSession, _sanitize_github_url, _url_github_api, get_canonical_github_origin_url, ) KNOWN_GH_REPO = "https://github.com/user/repo" KNOWN_GH_REPO2 = "https://github.com/user/reposit" @pytest.mark.parametrize( "user_repo, expected_url", [ ("user/repo.git", KNOWN_GH_REPO), ("user/repo.git/", KNOWN_GH_REPO), ("user/repo/", KNOWN_GH_REPO), ("user/repo", KNOWN_GH_REPO), ("user/repo/.git", KNOWN_GH_REPO), ("user/reposit.git", KNOWN_GH_REPO2), ("user/reposit.git/", KNOWN_GH_REPO2), ("user/reposit/", KNOWN_GH_REPO2), ("user/reposit", KNOWN_GH_REPO2), ("user/reposit/.git", KNOWN_GH_REPO2), ("unknown/page", None), # unknown gh origin returns None ("user/with/deps", None), # url kind is not dealt with ], ) def test_get_canonical_github_origin_url( user_repo, expected_url, requests_mock, github_credentials ): """It should return a canonical github origin when it exists, None otherwise""" for separator in ["/", ":"]: for prefix in [ "http://", "https://", "git://", "ssh://", "//", "git@", "ssh://git@", "https://${env.GITHUB_TOKEN_USR}:${env.GITHUB_TOKEN_PSW}@", "[fetch=]git@", ]: html_input_url = f"{prefix}github.com{separator}{user_repo}" html_url = f"https://github.com/{user_repo}" api_url = _url_github_api(_sanitize_github_url(user_repo)) if expected_url is not None: status_code = 200 response = {"html_url": _sanitize_github_url(html_url)} else: status_code = 404 response = {} requests_mock.get(api_url, [{"status_code": status_code, "json": response}]) # anonymous assert get_canonical_github_origin_url(html_input_url) == expected_url # with credentials assert ( get_canonical_github_origin_url( html_input_url, credentials=github_credentials ) == expected_url ) # anonymous assert ( GitHubSession( user_agent="GitHub Session Test", ).get_canonical_url(html_input_url) == expected_url ) # with credentials assert ( GitHubSession( user_agent="GitHub Session Test", credentials=github_credentials ).get_canonical_url(html_input_url) == expected_url ) def test_get_canonical_github_origin_url_not_gh_origin(): """It should return the input url when that origin is not a github one""" url = "https://example.org" assert get_canonical_github_origin_url(url) == url assert ( GitHubSession( user_agent="GitHub Session Test", ).get_canonical_url(url) == url ) def test_github_session_anonymous_session(): user_agent = ("GitHub Session Test",) github_session = GitHubSession( user_agent=user_agent, ) assert github_session.anonymous is True actual_headers = github_session.session.headers assert actual_headers["Accept"] == "application/vnd.github.v3+json" assert actual_headers["User-Agent"] == user_agent @pytest.mark.parametrize( "num_ratelimit", [1] # return a single rate-limit response, then continue ) def test_github_session_ratelimit_once_recovery( caplog, - requests_ratelimited, + mocker, + github_requests_ratelimited, num_ratelimit, monkeypatch_sleep_calls, github_credentials, ): """GitHubSession should recover from hitting the rate-limit once""" caplog.set_level(logging.DEBUG, "swh.core.github.utils") github_session = GitHubSession( user_agent="GitHub Session Test", credentials=github_credentials ) + statsd_report = mocker.patch.object(github_session.statsd, "_report") + res = github_session.request(f"{HTTP_GITHUB_API_URL}?per_page=1000&since=10") assert res.status_code == 200 token_users = [] for record in caplog.records: if "Using authentication token" in record.message: token_users.append(record.args[0]) # check that we used one more token than we saw rate limited requests assert len(token_users) == 1 + num_ratelimit # check that we slept for one second between our token uses assert monkeypatch_sleep_calls == [1] + username0 = github_session.credentials[0]["username"] + username1 = github_session.credentials[1]["username"] + tags0 = {"username": username0, "http_status": 429} + tags1 = {"username": username1, "http_status": 200} + assert [c for c in statsd_report.mock_calls] == [ + call("requests_total", "c", 1, {"username": username0}, 1), + call("responses_total", "c", 1, tags0, 1), + call("remaining_requests", "g", 999, {"username": username0}, 1), + call("rate_limited_responses_total", "c", 1, {"username": username0}, 1), + call("sleep", "c", 1, None, 1), + call("requests_total", "c", 1, {"username": username1}, 1), + call("responses_total", "c", 1, tags1, 1), + call("remaining_requests", "g", 998, {"username": username1}, 1), + ] + assert github_session.statsd.constant_tags == { + "api_type": "github", + "api_instance": "github", + } + def test_github_session_authenticated_credentials( caplog, github_credentials, all_tokens ): """GitHubSession should have Authorization headers set in authenticated mode""" caplog.set_level(logging.DEBUG, "swh.core.github.utils") github_session = GitHubSession( "GitHub Session Test", credentials=github_credentials ) assert github_session.anonymous is False assert github_session.token_index == 0 assert ( sorted(github_session.credentials, key=lambda t: t["username"]) == github_credentials ) assert github_session.session.headers["Authorization"] in [ f"token {t}" for t in all_tokens ] @pytest.mark.parametrize( # Do 5 successful requests, return 6 ratelimits (to exhaust the credentials) with a # set value for X-Ratelimit-Reset, then resume listing successfully. "num_before_ratelimit, num_ratelimit, ratelimit_reset", [(5, 6, 123456)], ) def test_github_session_ratelimit_reset_sleep( caplog, - requests_ratelimited, + mocker, + github_requests_ratelimited, monkeypatch_sleep_calls, num_before_ratelimit, num_ratelimit, ratelimit_reset, github_credentials, ): """GitHubSession should handle rate-limit with authentication tokens.""" caplog.set_level(logging.DEBUG, "swh.core.github.utils") github_session = GitHubSession( user_agent="GitHub Session Test", credentials=github_credentials ) + statsd_report = mocker.patch.object(github_session.statsd, "_report") + for _ in range(num_ratelimit): github_session.request(f"{HTTP_GITHUB_API_URL}?per_page=1000&since=10") # We sleep 1 second every time we change credentials, then we sleep until # ratelimit_reset + 1 expected_sleep_calls = len(github_credentials) * [1] + [ratelimit_reset + 1] assert monkeypatch_sleep_calls == expected_sleep_calls found_exhaustion_message = False for record in caplog.records: if record.levelname == "INFO": if "Rate limits exhausted for all tokens" in record.message: found_exhaustion_message = True break assert found_exhaustion_message is True + + username0 = github_session.credentials[0]["username"] + + def ok_request_calls(user, remaining): + return [ + call("requests_total", "c", 1, {"username": user}, 1), + call("responses_total", "c", 1, {"username": user, "http_status": 200}, 1), + call("remaining_requests", "g", remaining, {"username": user}, 1), + ] + + def ratelimited_request_calls(user): + return [ + call("requests_total", "c", 1, {"username": user}, 1), + call("responses_total", "c", 1, {"username": user, "http_status": 429}, 1), + call("remaining_requests", "g", 0, {"username": user}, 1), + call("reset_seconds", "g", ratelimit_reset, {"username": user}, 1), + call("rate_limited_responses_total", "c", 1, {"username": user}, 1), + call("sleep", "c", 1, None, 1), + ] + + expected_calls_groups = ( + # Successful requests + [ok_request_calls(username0, n - 1) for n in range(num_before_ratelimit, 0, -1)] + # Then rate-limited failures, cycling through tokens + + [ + ratelimited_request_calls( + github_session.credentials[n % len(github_credentials)]["username"] + ) + for n in range(num_ratelimit) + ] + # And finally, a long sleep and the successful request + + [ + [call("sleep", "c", ratelimit_reset + 1, None, 1)], + ok_request_calls( + github_session.credentials[num_ratelimit % len(github_credentials)][ + "username" + ], + 1000 - num_ratelimit - 1, + ), + ] + ) + expected_calls = list(itertools.chain.from_iterable(expected_calls_groups)) + assert [c for c in statsd_report.mock_calls] == expected_calls + assert github_session.statsd.constant_tags == { + "api_type": "github", + "api_instance": "github", + } + + +# Same as before, but with no credentials +@pytest.mark.parametrize( + "num_before_ratelimit, num_ratelimit, ratelimit_reset", + [(5, 6, 123456)], +) +def test_github_session_ratelimit_reset_sleep_anonymous( + caplog, + mocker, + github_requests_ratelimited, + monkeypatch_sleep_calls, + num_before_ratelimit, + num_ratelimit, + ratelimit_reset, +): + """GitHubSession should handle rate-limit with authentication tokens.""" + caplog.set_level(logging.DEBUG, "swh.core.github.utils") + + github_session = GitHubSession(user_agent="GitHub Session Test") + + statsd_report = mocker.patch.object(github_session.statsd, "_report") + + for _ in range(num_ratelimit): + github_session.request(f"{HTTP_GITHUB_API_URL}?per_page=1000&since=10") + + # No credentials, so we immediately sleep for a long time + expected_sleep_calls = [ratelimit_reset + 1] * num_ratelimit + assert monkeypatch_sleep_calls == expected_sleep_calls + + found_exhaustion_message = False + for record in caplog.records: + if record.levelname == "INFO": + if "Rate limits exhausted for all tokens" in record.message: + found_exhaustion_message = True + break + + assert found_exhaustion_message is True + + user = "anonymous" + + def ok_request_calls(remaining): + return [ + call("requests_total", "c", 1, {"username": user}, 1), + call("responses_total", "c", 1, {"username": user, "http_status": 200}, 1), + call("remaining_requests", "g", remaining, {"username": user}, 1), + ] + + def ratelimited_request_calls(): + return [ + call("requests_total", "c", 1, {"username": user}, 1), + call("responses_total", "c", 1, {"username": user, "http_status": 403}, 1), + call("remaining_requests", "g", 0, {"username": user}, 1), + call("reset_seconds", "g", ratelimit_reset, {"username": user}, 1), + call("rate_limited_responses_total", "c", 1, {"username": user}, 1), + call("sleep", "c", ratelimit_reset + 1, None, 1), + ] + + expected_calls_groups = ( + # Successful requests + [ok_request_calls(n - 1) for n in range(num_before_ratelimit, 0, -1)] + # Then rate-limited failures, each with a long sleep + + [ratelimited_request_calls() for n in range(num_ratelimit)] + # And finally, the successful request + + [ + ok_request_calls( + 1000 - num_ratelimit - 1, + ), + ] + ) + expected_calls = list(itertools.chain.from_iterable(expected_calls_groups)) + assert [c for c in statsd_report.mock_calls] == expected_calls + assert github_session.statsd.constant_tags == { + "api_type": "github", + "api_instance": "github", + } diff --git a/swh/core/github/utils.py b/swh/core/github/utils.py index f10ed34..5f99b29 100644 --- a/swh/core/github/utils.py +++ b/swh/core/github/utils.py @@ -1,232 +1,275 @@ # Copyright (C) 2020-2022 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information import logging import random import re import time from typing import Dict, List, Optional import requests from tenacity import ( retry, retry_any, retry_if_exception_type, retry_if_result, wait_exponential, ) +from ..statsd import Statsd + GITHUB_PATTERN = re.compile( r"(//|git://|git@|git//|https?://|ssh://|.*@)github.com[/:](?P.*)" ) logger = logging.getLogger(__name__) def _url_github_api(user_repo: str) -> str: """Given the user_repo, returns the expected github api url.""" return f"https://api.github.com/repos/{user_repo}" _SANITIZATION_RE = re.compile(r"^(.*?)/?(\.git)?/?$") def _sanitize_github_url(url: str) -> str: """Sanitize github url.""" m = _SANITIZATION_RE.match(url.lower()) assert m is not None, url # impossible, but mypy doesn't know it return m.group(1) def get_canonical_github_origin_url( url: str, credentials: Optional[List[Dict[str, str]]] = None ) -> Optional[str]: """Retrieve canonical github url out of an url if any or None otherwise. This triggers an http request to the github api url to determine the canonical repository url (if no credentials is provided, the http request is anonymous. Either way that request can be rate-limited by github.) """ return GitHubSession( user_agent="SWH core library", credentials=credentials ).get_canonical_url(url) class RateLimited(Exception): def __init__(self, response): self.reset_time: Optional[int] # Figure out how long we need to sleep because of that rate limit ratelimit_reset = response.headers.get("X-Ratelimit-Reset") retry_after = response.headers.get("Retry-After") if ratelimit_reset is not None: self.reset_time = int(ratelimit_reset) elif retry_after is not None: self.reset_time = int(time.time()) + int(retry_after) + 1 else: logger.warning( "Received a rate-limit-like status code %s, but no rate-limit " "headers set. Response content: %s", response.status_code, response.content, ) self.reset_time = None self.response = response class MissingRateLimitReset(Exception): pass class GitHubSession: """Manages a :class:`requests.Session` with (optionally) multiple credentials, and cycles through them when reaching rate-limits.""" credentials: Optional[List[Dict[str, str]]] = None def __init__( self, user_agent: str, credentials: Optional[List[Dict[str, str]]] = None ) -> None: """Initialize a requests session with the proper headers for requests to GitHub.""" if credentials: creds = credentials.copy() random.shuffle(creds) self.credentials = creds + self.statsd = Statsd( + namespace="swh_outbound_api", + constant_tags={"api_type": "github", "api_instance": "github"}, + ) + self.session = requests.Session() self.session.headers.update( {"Accept": "application/vnd.github.v3+json", "User-Agent": user_agent} ) self.anonymous = not self.credentials if self.anonymous: logger.warning("No tokens set in configuration, using anonymous mode") self.token_index = -1 self.current_user: Optional[str] = None if not self.anonymous: # Initialize the first token value in the session headers self.set_next_session_token() def set_next_session_token(self) -> None: """Update the current authentication token with the next one in line.""" assert self.credentials self.token_index = (self.token_index + 1) % len(self.credentials) auth = self.credentials[self.token_index] self.current_user = auth["username"] logger.debug("Using authentication token for user %s", self.current_user) if "password" in auth: token = auth["password"] else: token = auth["token"] self.session.headers.update({"Authorization": f"token {token}"}) @retry( wait=wait_exponential(multiplier=1, min=4, max=10), retry=retry_any( # ChunkedEncodingErrors happen when the TLS connection gets reset, e.g. # when running the lister on a connection with high latency retry_if_exception_type(requests.exceptions.ChunkedEncodingError), # 502 status codes happen for a Server Error, sometimes retry_if_result(lambda r: r.status_code == 502), ), ) def _request(self, url: str) -> requests.Response: + # When anonymous, rate-limits are per-IP; but we cannot necessarily + # get the IP/hostname here as we may be containerized. Instead, we rely on + # statsd-exporter adding the hostname in the 'instance' tag. + tags = {"username": self.current_user or "anonymous"} + + self.statsd.increment("requests_total", tags=tags) + response = self.session.get(url) + # self.session.get(url) raises in case of non-HTTP error (DNS, TCP, TLS, ...), + # so responses_total may differ from requests_total. + self.statsd.increment( + "responses_total", tags={**tags, "http_status": response.status_code} + ) + + try: + ratelimit_remaining = int(response.headers["x-ratelimit-remaining"]) + except (KeyError, ValueError): + logger.warning( + "Invalid x-ratelimit-remaining header from GitHub: %r", + response.headers.get("x-ratelimit-remaining"), + ) + else: + self.statsd.gauge("remaining_requests", ratelimit_remaining, tags=tags) + + try: + reset_seconds = int(response.headers["x-ratelimit-reset"]) - time.time() + except (KeyError, ValueError): + logger.warning( + "Invalid x-ratelimit-reset header from GitHub: %r", + response.headers.get("x-ratelimit-reset"), + ) + else: + self.statsd.gauge("reset_seconds", reset_seconds, tags=tags) + if ( # GitHub returns inconsistent status codes between unauthenticated # rate limit and authenticated rate limits. Handle both. response.status_code == 429 or (self.anonymous and response.status_code == 403) ): + self.statsd.increment("rate_limited_responses_total", tags=tags) raise RateLimited(response) return response def request(self, url) -> requests.Response: """Repeatedly requests the given URL, cycling through credentials and sleeping if necessary; until either a successful response or :exc:`MissingRateLimitReset` """ # The following for/else loop handles rate limiting; if successful, # it provides the rest of the function with a `response` object. # # If all tokens are rate-limited, we sleep until the reset time, # then `continue` into another iteration of the outer while loop, # attempting to get data from the same URL again. while True: max_attempts = len(self.credentials) if self.credentials else 1 reset_times: Dict[int, int] = {} # token index -> time for attempt in range(max_attempts): try: return self._request(url) except RateLimited as e: reset_info = "(unknown reset)" if e.reset_time is not None: reset_times[self.token_index] = e.reset_time reset_info = "(resetting in %ss)" % (e.reset_time - time.time()) if not self.anonymous: logger.info( "Rate limit exhausted for current user %s %s", self.current_user, reset_info, ) # Use next token in line self.set_next_session_token() # Wait one second to avoid triggering GitHub's abuse rate limits + self.statsd.increment("sleep", 1) time.sleep(1) # All tokens have been rate-limited. What do we do? if not reset_times: logger.warning( "No X-Ratelimit-Reset value found in responses for any token; " "Giving up." ) raise MissingRateLimitReset() sleep_time = max(reset_times.values()) - time.time() + 1 logger.info( "Rate limits exhausted for all tokens. Sleeping for %f seconds.", sleep_time, ) + self.statsd.increment("sleep", sleep_time) time.sleep(sleep_time) def get_canonical_url(self, url: str) -> Optional[str]: """Retrieve canonical github url out of an url if any or None otherwise. This triggers an http request to the github api url to determine the canonical repository url. Returns The canonical url if any, None otherwise. """ url_ = url.lower() match = GITHUB_PATTERN.match(url_) if not match: return url user_repo = _sanitize_github_url(match.groupdict()["user_repo"]) response = self.request(_url_github_api(user_repo)) if response.status_code != 200: return None data = response.json() return data["html_url"] diff --git a/swh/core/statsd.py b/swh/core/statsd.py index b366d59..e841b7e 100644 --- a/swh/core/statsd.py +++ b/swh/core/statsd.py @@ -1,500 +1,500 @@ # Copyright (C) 2018 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information # Initially imported from https://github.com/DataDog/datadogpy/ # at revision 62b3a3e89988dc18d78c282fe3ff5d1813917436 # # Copyright (c) 2015, Datadog # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # * Neither the name of Datadog nor the names of its contributors may be # used to endorse or promote products derived from this software without # specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # # Vastly adapted for integration in swh.core: # # - Removed python < 3.5 compat code # - trimmed the imports down to be a single module # - adjust some options: # - drop unix socket connection option # - add environment variable support for setting the statsd host and # port (pulled the idea from the main python statsd module) # - only send timer metrics in milliseconds (that's what # prometheus-statsd-exporter expects) # - drop DataDog-specific metric types (that are unsupported in # prometheus-statsd-exporter) # - made the tags a dict instead of a list (prometheus-statsd-exporter only # supports tags with a value, mirroring prometheus) # - switch from time.time to time.monotonic # - improve unit test coverage # - documentation cleanup from asyncio import iscoroutinefunction from contextlib import contextmanager from functools import wraps import itertools import logging import os from random import random import re import socket import threading from time import monotonic from typing import Collection, Dict, Optional import warnings log = logging.getLogger("swh.core.statsd") class TimedContextManagerDecorator(object): """ A context manager and a decorator which will report the elapsed time in the context OR in a function call. Attributes: elapsed (float): the elapsed time at the point of completion """ def __init__( self, statsd, metric=None, error_metric=None, tags=None, sample_rate=1 ): self.statsd = statsd self.metric = metric self.error_metric = error_metric self.tags = tags or {} self.sample_rate = sample_rate self.elapsed = None # this is for testing purpose def __call__(self, func): """ Decorator which returns the elapsed time of the function call. Default to the function name if metric was not provided. """ if not self.metric: self.metric = "%s.%s" % (func.__module__, func.__name__) # Coroutines if iscoroutinefunction(func): @wraps(func) async def wrapped_co(*args, **kwargs): start = monotonic() try: result = await func(*args, **kwargs) except BaseException as e: self._send_error(error_type=type(e).__name__) raise self._send(start) return result return wrapped_co # Others @wraps(func) def wrapped(*args, **kwargs): start = monotonic() try: result = func(*args, **kwargs) except BaseException as e: self._send_error(error_type=type(e).__name__) raise self._send(start) return result return wrapped def __enter__(self): if not self.metric: raise TypeError("Cannot used timed without a metric!") self._start = monotonic() return self def __exit__(self, type, value, traceback): # Report the elapsed time of the context manager if no error. if type is None: self._send(self._start) else: self._send_error(error_type=type.__name__) def _send(self, start): elapsed = (monotonic() - start) * 1000 self.statsd.timing( self.metric, elapsed, tags=self.tags, sample_rate=self.sample_rate ) self.elapsed = elapsed def _send_error(self, error_type=None): if self.error_metric is None: self.error_metric = self.metric + "_error_count" if error_type is not None: tags = {**self.tags, "error_type": error_type} else: tags = self.tags self.statsd.increment(self.error_metric, tags=tags) def start(self): """Start the timer""" self.__enter__() def stop(self): """Stop the timer, send the metric value""" self.__exit__(None, None, None) class Statsd(object): """Initialize a client to send metrics to a StatsD server. Arguments: host (str): the host of the StatsD server. Defaults to localhost. port (int): the port of the StatsD server. Defaults to 8125. max_buffer_size (int): Maximum number of metrics to buffer before sending to the server if sending metrics in batch namespace (str): Namespace to prefix all metric names constant_tags (Dict[str, str]): Tags to attach to all metrics Note: This class also supports the following environment variables: STATSD_HOST Override the default host of the statsd server STATSD_PORT Override the default port of the statsd server STATSD_TAGS Tags to attach to every metric reported. Example value: "label:value,other_label:other_value" """ def __init__( self, host=None, port=None, max_buffer_size=50, namespace=None, constant_tags=None, ): # Connection if host is None: host = os.environ.get("STATSD_HOST") or "localhost" self.host = host if port is None: port = os.environ.get("STATSD_PORT") or 8125 self.port = int(port) # Socket self._socket = None self.lock = threading.Lock() self.max_buffer_size = max_buffer_size self._send = self._send_to_server self.encoding = "utf-8" # Tags self.constant_tags = {} tags_envvar = os.environ.get("STATSD_TAGS", "") for tag in tags_envvar.split(","): if not tag: continue if ":" not in tag: warnings.warn( - "STATSD_TAGS needs to be in key:value format, " "%s invalid" % tag, + f"STATSD_TAGS needs to be in 'key:value' format, not {tag!r}", UserWarning, ) continue k, v = tag.split(":", 1) # look for a possible env var substitution, using $NAME or ${NAME} format m = re.match(r"^[$]([{])?(?P\w+)(?(1)[}]|)$", v) if m: envvar = m.group("envvar") if envvar in os.environ: v = os.environ[envvar] self.constant_tags[k] = v if constant_tags: self.constant_tags.update( {str(k): str(v) for k, v in constant_tags.items()} ) # Namespace if namespace is not None: namespace = str(namespace) self.namespace = namespace def __enter__(self): self.open_buffer(self.max_buffer_size) return self def __exit__(self, type, value, traceback): self.close_buffer() def gauge(self, metric, value, tags=None, sample_rate=1): """ Record the value of a gauge, optionally setting a list of tags and a sample rate. >>> statsd.gauge('users.online', 123) >>> statsd.gauge('active.connections', 1001, tags={"protocol": "http"}) """ return self._report(metric, "g", value, tags, sample_rate) def increment(self, metric, value=1, tags=None, sample_rate=1): """ Increment a counter, optionally setting a value, tags and a sample rate. >>> statsd.increment('page.views') >>> statsd.increment('files.transferred', 124) """ self._report(metric, "c", value, tags, sample_rate) def decrement(self, metric, value=1, tags=None, sample_rate=1): """ Decrement a counter, optionally setting a value, tags and a sample rate. >>> statsd.decrement('files.remaining') >>> statsd.decrement('active.connections', 2) """ metric_value = -value if value else value self._report(metric, "c", metric_value, tags, sample_rate) def histogram(self, metric, value, tags=None, sample_rate=1): """ Sample a histogram value, optionally setting tags and a sample rate. >>> statsd.histogram('uploaded.file.size', 1445) >>> statsd.histogram('file.count', 26, tags={"filetype": "python"}) """ self._report(metric, "h", value, tags, sample_rate) def timing(self, metric, value, tags=None, sample_rate=1): """ Record a timing, optionally setting tags and a sample rate. >>> statsd.timing("query.response.time", 1234) """ self._report(metric, "ms", value, tags, sample_rate) def timed(self, metric=None, error_metric=None, tags=None, sample_rate=1): """ A decorator or context manager that will measure the distribution of a function's/context's run time. Optionally specify a list of tags or a sample rate. If the metric is not defined as a decorator, the module name and function name will be used. The metric is required as a context manager. :: @statsd.timed('user.query.time', sample_rate=0.5) def get_user(user_id): # Do what you need to ... pass # Is equivalent to ... with statsd.timed('user.query.time', sample_rate=0.5): # Do what you need to ... pass # Is equivalent to ... start = time.monotonic() try: get_user(user_id) finally: statsd.timing('user.query.time', time.monotonic() - start) """ return TimedContextManagerDecorator( statsd=self, metric=metric, error_metric=error_metric, tags=tags, sample_rate=sample_rate, ) def set(self, metric, value, tags=None, sample_rate=1): """ Sample a set value. >>> statsd.set('visitors.uniques', 999) """ self._report(metric, "s", value, tags, sample_rate) @property def socket(self): """ Return a connected socket. Note: connect the socket before assigning it to the class instance to avoid bad thread race conditions. """ with self.lock: if not self._socket: sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.connect((self.host, self.port)) self._socket = sock return self._socket def open_buffer(self, max_buffer_size=50): """ Open a buffer to send a batch of metrics in one packet. You can also use this as a context manager. >>> with Statsd() as batch: ... batch.gauge('users.online', 123) ... batch.gauge('active.connections', 1001) """ self.max_buffer_size = max_buffer_size self.buffer = [] self._send = self._send_to_buffer def close_buffer(self): """ Flush the buffer and switch back to single metric packets. """ self._send = self._send_to_server if self.buffer: # Only send packets if there are packets to send self._flush_buffer() def close_socket(self): """ Closes connected socket if connected. """ with self.lock: if self._socket: self._socket.close() self._socket = None def _report(self, metric, metric_type, value, tags, sample_rate): """ Create a metric packet and send it. """ if value is None: return if sample_rate != 1 and random() > sample_rate: return # Resolve the full tag list tags = self._add_constant_tags(tags) # Create/format the metric packet payload = "%s%s:%s|%s%s%s" % ( (self.namespace + ".") if self.namespace else "", metric, value, metric_type, ("|@" + str(sample_rate)) if sample_rate != 1 else "", ("|#" + ",".join("%s:%s" % (k, v) for (k, v) in sorted(tags.items()))) if tags else "", ) # Send it self._send(payload) def _send_to_server(self, packet): try: # If set, use socket directly self.socket.send(packet.encode("utf-8")) except socket.timeout: return except socket.error: log.debug( "Error submitting statsd packet." " Dropping the packet and closing the socket." ) self.close_socket() def _send_to_buffer(self, packet): self.buffer.append(packet) if len(self.buffer) >= self.max_buffer_size: self._flush_buffer() def _flush_buffer(self): self._send_to_server("\n".join(self.buffer)) self.buffer = [] def _add_constant_tags(self, tags): return { str(k): str(v) for k, v in itertools.chain( self.constant_tags.items(), (tags if tags else {}).items(), ) } @contextmanager def status_gauge( self, metric_name: str, statuses: Collection[str], tags: Optional[Dict[str, str]] = None, ): """Context manager to keep track of status changes as a gauge In addition to the `metric_name` and `tags` arguments, it expects a list of `statuses` to declare which statuses are possible, and returns a callable as context manager. This callable takes ones of the possible statuses as argument. Typical usage would be: >>> with statsd.status_gauge( "metric_name", ["starting", "processing", "waiting"]) as set_status: set_status("starting") # ... set_status("waiting") # ... """ if tags is None: tags = {} current_status: Optional[str] = None # reset status gauges to make sure they do not "leak" for status in statuses: self.gauge(metric_name, 0, {**tags, "status": status}) def set_status(new_status: str): nonlocal current_status assert isinstance(tags, dict) if new_status not in statuses: raise ValueError(f"{new_status} not in {statuses}") if current_status and new_status != current_status: self.gauge(metric_name, 0, {**tags, "status": current_status}) current_status = new_status self.gauge(metric_name, 1, {**tags, "status": current_status}) yield set_status # reset gauges on exit for status in statuses: self.gauge(metric_name, 0, {**tags, "status": status}) statsd = Statsd()