Skip to content

Commit

Permalink
feat(telemetry): Introduce DO_NO_TRACK and KEDRO_DISABLE_TELEMETRY (
Browse files Browse the repository at this point in the history
kedro-org#762)

* add env var to skip telemetry

Signed-off-by: Nok Lam Chan <[email protected]>

* release note

Signed-off-by: Nok Lam Chan <[email protected]>

* update README

Signed-off-by: Nok Lam Chan <[email protected]>

* fix test

Signed-off-by: Nok Lam Chan <[email protected]>

* Change constant to tuple to avoid random test error

Signed-off-by: Nok Lam Chan <[email protected]>

* linting

Signed-off-by: Nok Lam Chan <[email protected]>

* fix typo

Signed-off-by: Nok <[email protected]>

---------

Signed-off-by: Nok Lam Chan <[email protected]>
Signed-off-by: Nok <[email protected]>
Co-authored-by: Dmitry Sorokin <[email protected]>
Signed-off-by: Merel Theisen <[email protected]>
  • Loading branch information
2 people authored and merelcht committed Aug 27, 2024
1 parent 021cb73 commit ca652c9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions kedro-telemetry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ To withdraw consent, you can change the `consent` variable to `false` in `.telem
```yaml
consent: false
```
You can also set `DO_NOT_TRACK` or `KEDRO_DISABLE_TELEMETRY` environment variable to `True`.

Or you can uninstall the plugin:

Expand Down
1 change: 1 addition & 0 deletions kedro-telemetry/RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Upcoming release
* Added `DO_NOT_TRACK` and `KEDRO_DISABLE_TELEMETRY` environment variables to skip telemetry.

# Release 0.5.0
* Updated the plugin to generate a unique project UUID for kedro project and store it in `pyproject.toml`.
Expand Down
8 changes: 8 additions & 0 deletions kedro-telemetry/kedro_telemetry/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
"TRAVIS", # https://docs.travis-ci.com/user/environment-variables/#default-environment-variables
"BUILDKITE", # https://buildkite.com/docs/pipelines/environment-variables
}
_SKIP_TELEMETRY_ENV_VAR_KEYS = (
"DO_NOT_TRACK",
"KEDRO_DISABLE_TELEMETRY",
)
TIMESTAMP_FORMAT = "%Y-%m-%dT%H:%M:%S.%fZ"
CONFIG_FILENAME = "telemetry.toml"
PYPROJECT_CONFIG_NAME = "pyproject.toml"
Expand Down Expand Up @@ -353,6 +357,10 @@ def _check_for_telemetry_consent(project_path: Path) -> bool:
Telemetry is considered as opt-in otherwise.
"""
telemetry_file_path = project_path / ".telemetry"

for env_var in _SKIP_TELEMETRY_ENV_VAR_KEYS:
if os.environ.get(env_var):
return False
if telemetry_file_path.exists():
with open(telemetry_file_path, encoding="utf-8") as telemetry_file:
telemetry = yaml.safe_load(telemetry_file)
Expand Down
13 changes: 13 additions & 0 deletions kedro-telemetry/tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from kedro_telemetry import __version__ as TELEMETRY_VERSION
from kedro_telemetry.plugin import (
_SKIP_TELEMETRY_ENV_VAR_KEYS,
KNOWN_CI_ENV_VAR_KEYS,
KedroTelemetryCLIHooks,
KedroTelemetryProjectHooks,
Expand Down Expand Up @@ -411,6 +412,18 @@ def test_check_for_telemetry_consent_not_given(self, mocker, fake_metadata):

assert not _check_for_telemetry_consent(fake_metadata.project_path)

@mark.parametrize("env_var", _SKIP_TELEMETRY_ENV_VAR_KEYS)
def test_check_for_telemetry_consent_skip_telemetry_with_env_var(
self, monkeypatch, fake_metadata, env_var
):
monkeypatch.setenv(env_var, "True")
Path(fake_metadata.project_path, "conf").mkdir(parents=True)
telemetry_file_path = fake_metadata.project_path / ".telemetry"
with open(telemetry_file_path, "w", encoding="utf-8") as telemetry_file:
yaml.dump({"consent": True}, telemetry_file)

assert not _check_for_telemetry_consent(fake_metadata.project_path)

def test_check_for_telemetry_consent_empty_file(self, mocker, fake_metadata):
Path(fake_metadata.project_path, "conf").mkdir(parents=True)
telemetry_file_path = fake_metadata.project_path / ".telemetry"
Expand Down

0 comments on commit ca652c9

Please sign in to comment.