From f8e829619907b2ea57c942d2f681b55fcbcb41f7 Mon Sep 17 00:00:00 2001 From: Cameron Savage Date: Fri, 26 Apr 2024 11:38:32 -0700 Subject: [PATCH] fix: #5787 Support uppercased version of "COLLECT_ANALYTICS" env var (#5788) - [x] Commit message(s) and PR title follows the format `[fix|feat|ci|chore|doc]: TICKET-ID: Short description of change made` ex. `fix: DEV-XXXX: Removed inconsistent code usage causing intermittent errors` - [x] Tests for the changes have been added/updated (for bug fixes/features) - [x] Docs have been added/updated (for bug fixes/features) - [x] Best efforts were made to ensure docs/code are concise and coherent (checked for spelling/grammatical errors, commented out code, debug logs etc.) - [x] Self-reviewed and ran all changes on a local instance (for bug fixes/features) _(check all that apply)_ - [ ] Product design - [ ] Backend (Database) - [x] Backend (API) - [ ] Frontend _(link to issue, supportive screenshots etc.)_ https://github.com/HumanSignal/label-studio/issues/5787 _(if this is a bug fix)_ Updates `base.py` to search for `COLLECT_ANALYTICS` environment variable instead of `collect_analytics` _(if this is a breaking or feature change)_ _(if this is a breaking or feature change)_ _(list all with version changes)_ _(if so describe the impacts positive or negative)_ _(if so describe the impacts positive or negative)_ Positive: backend analytics are properly disabled when deploying with Helm. _(briefly list any if applicable)_ _(briefly list any if applicable)_ _(check only one)_ - [ ] Yes, and covered entirely by feature flag(s) - [ ] Yes, and covered partially by feature flag(s) - [ ] No - [x] Not sure (briefly explain the situation below) The environment variable name is changing to all upper-case - no impact if using Helm, as it enforces all caps. Other users who pass variables in with Docker Compose or other setup methods may already be using lower case, and their setup methods may not enforce all-caps. _(check all that apply)_ - [ ] e2e - [ ] integration - [x] unit _(for bug fixes/features, be as precise as possible. ex. Authentication, Annotation History, Review Stream etc.)_ Analytics / logging --------- Co-authored-by: Jo Booth --- .github/workflows/test_migrations.yml | 2 +- .github/workflows/tests.yml | 8 ++++---- docs/source/guide/security.md | 2 +- label_studio/core/settings/base.py | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test_migrations.yml b/.github/workflows/test_migrations.yml index 3e4d7fab0b48..200bc735c9c8 100644 --- a/.github/workflows/test_migrations.yml +++ b/.github/workflows/test_migrations.yml @@ -16,7 +16,7 @@ jobs: DJANGO_SETTINGS_MODULE: core.settings.label_studio COVERAGE_PROCESS_START: 1 LOG_DIR: pytest_logs - collect_analytics: true + COLLECT_ANALYTICS: true DEBUG_CONTEXTLOG: true LABEL_STUDIO_TEST_ENVIRONMENT: false SENTRY_ENVIRONMENT: tests-ubuntu-sqlite diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 20852cde34d9..ab9ca6a055e8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -28,7 +28,7 @@ jobs: DJANGO_SETTINGS_MODULE: core.settings.label_studio COVERAGE_PROCESS_START: 1 LOG_DIR: pytest_logs - collect_analytics: true + COLLECT_ANALYTICS: true DEBUG_CONTEXTLOG: true LABEL_STUDIO_TEST_ENVIRONMENT: false SENTRY_ENVIRONMENT: tests-ubuntu-sqlite @@ -116,7 +116,7 @@ jobs: PYTHONPATH: . LOG_LEVEL: ERROR LOG_DIR: pytest_logs - collect_analytics: true + COLLECT_ANALYTICS: true DEBUG_CONTEXTLOG: true LABEL_STUDIO_TEST_ENVIRONMENT: false SENTRY_ENVIRONMENT: tests-ubuntu-postgresql @@ -244,7 +244,7 @@ jobs: DJANGO_SETTINGS_MODULE: core.settings.label_studio COVERAGE_PROCESS_START: 1 LOG_DIR: pytest_logs - collect_analytics: true + COLLECT_ANALYTICS: true DEBUG_CONTEXTLOG: true LABEL_STUDIO_TEST_ENVIRONMENT: false SENTRY_ENVIRONMENT: tests-windows-sqlite @@ -292,7 +292,7 @@ jobs: - name: Test with pytest env: - collect_analytics: 0 + COLLECT_ANALYTICS: 0 run: | cd label_studio/ poetry run python -m pytest -vv -n auto diff --git a/docs/source/guide/security.md b/docs/source/guide/security.md index 5ac73f709db9..a3fbc3956fd6 100644 --- a/docs/source/guide/security.md +++ b/docs/source/guide/security.md @@ -122,7 +122,7 @@ Label Studio collects usage statistics including the number of page visits, numb
-You can disable data collection by setting the environment variable `collect_analytics` to `False`. +You can disable data collection by setting the environment variable `COLLECT_ANALYTICS` to `False`.
diff --git a/label_studio/core/settings/base.py b/label_studio/core/settings/base.py index 49b2bfe8dd54..f56c1a4ff59b 100644 --- a/label_studio/core/settings/base.py +++ b/label_studio/core/settings/base.py @@ -609,8 +609,8 @@ def collect_versions_dummy(**kwargs): # default value for feature flags (if not overridden by environment or client) FEATURE_FLAGS_DEFAULT_VALUE = False -# Whether to send analytics telemetry data -COLLECT_ANALYTICS = get_bool_env('collect_analytics', True) +# Whether to send analytics telemetry data. Fall back to old lowercase name for legacy compatibility. +COLLECT_ANALYTICS = get_bool_env('COLLECT_ANALYTICS', get_bool_env('collect_analytics', True)) # Strip harmful content from SVG files by default SVG_SECURITY_CLEANUP = get_bool_env('SVG_SECURITY_CLEANUP', False)