-
Notifications
You must be signed in to change notification settings - Fork 41
[feature][MSD-318] implement store annotated data framework #3444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1f2c680
[feature] implement store annotated data framework
K4rishma 4138bef
consent none value error fixed, time accepts utc iso form
K4rishma 73b6023
stop pagination when next token is absent by braking it rather than s…
K4rishma 73fb358
formattin
K4rishma 84ee1ff
resolve pr comments
K4rishma 478bf9a
format docstings from markdown
K4rishma 7da7a8b
remove consent pop up
K4rishma 3315e67
resolve pr comments
K4rishma 39f8e72
fix rst formatting
K4rishma 1f7d617
fix datetime to date
K4rishma 7e919be
add datacollector key check while packaging Odemis
K4rishma 79d8943
add ini file for using the cli retrieval tool
K4rishma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
K4rishma marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,362 @@ | ||
| Odemis Data Collection Framework — Setup Guide | ||
| =============================================== | ||
|
|
||
| **Audience:** Software and support engineers setting up data collection on an | ||
| Odemis installation or on a developer workstation. | ||
|
|
||
| .. note:: | ||
| All commands are Bash. Enter them line by line unless stated otherwise. | ||
|
|
||
| This guide covers: | ||
|
|
||
| - Prerequisites | ||
| - Installing the boto3 package | ||
| - Creating and installing the credentials key file | ||
| - Setting up the local queue directory (``dc_queue``) | ||
| - Verifying the configuration file | ||
| - Test-bucket vs production-bucket mode | ||
| - Running the unit tests | ||
| - Quick smoke-test with ``odemis-dc-fetch`` | ||
| - Troubleshooting | ||
|
|
||
|
|
||
| Prerequisites | ||
| ------------- | ||
|
|
||
| - Ubuntu 22.04 LTS or later | ||
| - Odemis installed from the Debian package or a source checkout | ||
| - AWS S3 credentials (``access_key`` + ``secret_key``) for the target bucket | ||
| (typically upload-only IAM keys). | ||
| Obtain these from a Delmic software engineer; they are **not** stored in this | ||
| repository. | ||
| - Write access to ``/usr/share/odemis/`` (for the key file) | ||
|
|
||
|
|
||
| Installing the boto3 Package | ||
| ----------------------------- | ||
|
|
||
| ``boto3`` is the AWS SDK for Python used to upload data to S3. | ||
|
|
||
| When installed via the Odemis Debian package it is listed as a dependency and | ||
| will be pulled in automatically: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| sudo apt update | ||
| sudo apt install python3-boto3 | ||
|
|
||
| To verify the installation: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| python3 -c "import boto3; print(boto3.__version__)" | ||
|
|
||
| If the command prints a version string (e.g. ``1.28.0``) the package is ready. | ||
| If it raises ``ImportError``, re-run the ``apt install`` command above. | ||
|
|
||
|
|
||
| Installing the Credentials Key File | ||
| ------------------------------------- | ||
|
|
||
| The framework reads S3 credentials from a single JSON file at: /usr/share/odemis/datacollector.key | ||
|
K4rishma marked this conversation as resolved.
|
||
|
|
||
| The file must contain exactly the following two keys: | ||
|
|
||
|
K4rishma marked this conversation as resolved.
|
||
| .. code-block:: json | ||
|
|
||
| { "access_key": "<AWS_ACCESS_KEY_ID>", "secret_key": "<AWS_SECRET_ACCESS_KEY>" } | ||
|
|
||
| Obtain the actual key values from a Delmic software engineer. These keys are | ||
| typically scoped to upload-only access (no read/retrieve), so internal sharing | ||
| over standard channels is lower risk than full-access AWS credentials. | ||
|
|
||
| Do **not** commit these keys to git repositories (especially public remotes). | ||
| Public repository scrapers continuously harvest AWS key patterns, and committing | ||
| keys can also trigger GitHub secret-scanning/security warnings. | ||
|
|
||
|
|
||
| Production Setup | ||
| ~~~~~~~~~~~~~~~~ | ||
|
|
||
| Contact a software engineer who has access to the AWS IAM console to get the | ||
| key pair, then run the following commands line by line: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| # Create the file — replace placeholder values with the real keys | ||
| sudo tee /usr/share/odemis/datacollector.key > /dev/null << 'EOF' | ||
| { "access_key": "<PRODUCTION_ACCESS_KEY_ID>", "secret_key": "<PRODUCTION_SECRET_ACCESS_KEY>" } | ||
| EOF | ||
|
K4rishma marked this conversation as resolved.
|
||
|
|
||
|
|
||
| Setting up the Local Queue Directory (dc_queue) | ||
| ------------------------------------------------- | ||
|
|
||
| .. note:: | ||
| This section applies to the **test / developer setup** only. Skip it for a | ||
| production installation. | ||
|
|
||
| The framework stages serialised ZIP archives in a local directory before | ||
| uploading them. The default path is: | ||
|
|
||
| .. code-block:: text | ||
|
|
||
| ~/.local/share/odemis/dc_queue | ||
|
|
||
| This directory is created automatically by the framework at runtime if it does | ||
| not exist, as long as the parent ``~/.local/share/odemis/`` is writable by the | ||
| process. | ||
|
|
||
| For a standard Odemis installation ``~/.local/share/odemis/`` is already | ||
| created by the package post-install script. If that is not the case, create it | ||
| manually: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| sudo mkdir -p ~/.local/share/odemis/dc_queue | ||
| sudo chown $USER:$USER ~/.local/share/odemis/dc_queue | ||
| sudo chmod 750 ~/.local/share/odemis/dc_queue | ||
|
|
||
|
|
||
| Queue Disk Limit | ||
| ~~~~~~~~~~~~~~~~ | ||
|
|
||
| The framework automatically enforces a soft limit of 10 % of the partition's | ||
| total disk space on ``~/.local/share/odemis/dc_queue``. When the limit is | ||
| exceeded, the oldest ZIP files are deleted with a ``WARNING`` log entry. | ||
|
|
||
| - **Production:** ``~/.local/share/odemis/`` is normally on the main OS | ||
| partition. No special configuration is required. | ||
| - **Test / developer workstation:** the queue directory may be redirected to a | ||
| temporary location by instantiating ``_BackgroundWorker`` with a custom | ||
| ``queue_dir`` argument (used in unit tests). For manual testing with the real | ||
| Odemis GUI, the default path is always used. | ||
|
|
||
|
|
||
| Inspecting Queued Files | ||
| ~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| ls -lh ~/.local/share/odemis/dc_queue/ | ||
|
|
||
| Files follow the naming convention:: | ||
|
|
||
| <event_name>-<YYYYMMDDTHHmmss>-<uuid8>.zip | ||
|
|
||
| Any file ending in ``.tmp`` is an incomplete write left over from a crash; the | ||
| framework removes such files on startup. You can delete them manually if Odemis | ||
| is not running: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| rm -f ~/.local/share/odemis/dc_queue/*.tmp | ||
|
|
||
|
|
||
| Verifying the Configuration File | ||
| ---------------------------------- | ||
|
|
||
| The per-user consent state is stored in: | ||
|
|
||
| .. code-block:: text | ||
|
|
||
| ~/.config/odemis/datacollector.config | ||
|
|
||
| This file is created automatically the first time the user interacts with the | ||
| consent dialog from the menu. Its permissions are always set to ``0600`` | ||
| (owner read/write only) by the framework. | ||
|
|
||
| A typical file after opt-in looks like: | ||
|
|
||
| .. code-block:: ini | ||
|
|
||
| [general] | ||
| # Data sharing consent (true / false). | ||
| consent = true | ||
|
|
||
|
|
||
| .. _test-bucket-mode: | ||
|
|
||
| Test-Bucket vs Production-Bucket Mode | ||
| --------------------------------------- | ||
|
|
||
| Production (Default) | ||
| ~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| - **Bucket:** ``delmic-odemis-collect`` | ||
| - **Region:** ``eu-west-1`` | ||
|
|
||
| This is the default when the framework starts normally. No environment variable | ||
| needs to be set. Use the production IAM credentials in the key file | ||
| (see `Installing the Credentials Key File`_). | ||
|
|
||
|
|
||
| Test / Developer Mode | ||
| ~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| - **Bucket:** ``delmic-odemis-collect-test`` | ||
| - **Region:** ``eu-west-1`` | ||
|
|
||
| Set the following environment variable before starting Odemis (or any script | ||
| that calls ``record()``): | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| export TEST_DATACOLLECTION=1 | ||
|
|
||
| The framework logs the following ``INFO`` message when test mode is active:: | ||
|
|
||
| DataCollector: TEST_DATACOLLECTION=1 — using test bucket 'delmic-odemis-collect-test' | ||
|
|
||
| .. important:: | ||
| The test bucket credentials (``access_key`` / ``secret_key`` in the key | ||
| file) must be scoped to the **test** bucket by the Delmic AWS admin. If you | ||
| install production credentials and set ``TEST_DATACOLLECTION=1``, uploads | ||
| will fail with an ``AccessDenied`` error because the IAM policy only permits | ||
| writes to the production prefix. | ||
|
|
||
|
|
||
| Managing Consent | ||
| ---------------- | ||
|
|
||
| The data collection consent dialog is accessed via the Odemis menu. Users have | ||
| three options: | ||
|
|
||
| - **Opt In:** Enable data collection permanently. | ||
| - **Opt Out:** Disable data collection permanently. | ||
| - **Consent for One Day:** Enable data collection temporarily for one day only. | ||
| After the specified day, consent automatically expires to disabled. | ||
|
|
||
| When temporary consent is active and less than one day remains, the collection | ||
| sampling rate increases to 100% to prioritize data collection. Otherwise, a | ||
| default 10% sampling rate applies. | ||
|
|
||
| When consent is active, collected data is staged in the queue directory and | ||
| uploaded to S3 in the background. When consent is disabled, no data is collected | ||
| or uploaded. | ||
|
|
||
|
|
||
| Running the Unit Tests | ||
| ----------------------- | ||
|
|
||
| Unit tests run without any hardware and without a real S3 connection. All | ||
| upload calls are mocked. | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| # From the repository root | ||
| env TEST_NOHW=1 python3 src/odemis/util/test/datacollector_test.py | ||
|
|
||
| To run a specific test class or method: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| env TEST_NOHW=1 python3 src/odemis/util/test/datacollector_test.py \ | ||
| DataCollectorTest.test_record_returns_fast | ||
|
|
||
| env TEST_NOHW=1 python3 src/odemis/util/test/datacollector_test.py \ | ||
| TestSerialize.test_metadata_json_envelope_fields | ||
|
|
||
|
|
||
| Real S3 Integration Tests | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| The class ``TestRealS3Integration`` uploads to the test bucket and cleans up | ||
| after itself. It requires: | ||
|
|
||
| - ``boto3`` installed | ||
| - ``/usr/share/odemis/datacollector.key`` present with test bucket credentials | ||
| - ``TEST_DATACOLLECTION=1`` is **not** needed here — the test class hard-codes | ||
| the test bucket directly | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| env TEST_NOHW=1 python3 src/odemis/util/test/datacollector_test.py \ | ||
| TestRealS3Integration | ||
|
|
||
| If the key file is absent, this class is skipped automatically. | ||
|
|
||
|
|
||
| Quick Smoke-Test with odemis-dc-fetch | ||
| --------------------------------------- | ||
|
|
||
| After a successful upload (production or test), use the retrieval script to | ||
| confirm objects landed in S3. The retrieval script can only be used with an AWS | ||
| profile that has data-analyst read access; the upload key in | ||
| ``/usr/share/odemis/datacollector.key`` is typically write-only and usually | ||
| does not grant retrieval rights. | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| odemis-dc-fetch \ | ||
| --bucket delmic-odemis-collect \ | ||
| --region eu-west-1 \ | ||
| --output ./dc_samples_test | ||
|
|
||
| Filter by event name and date: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| odemis-dc-fetch \ | ||
| --bucket delmic-odemis-collect-test \ | ||
| --region eu-west-1 \ | ||
| --event feature_collected \ | ||
| --since 2026-04-01 \ | ||
| --output ./dc_samples_test | ||
|
|
||
| The script prints a one-line summary:: | ||
|
|
||
| listed=N matched=N downloaded=N skipped_existing=N failed=0 | ||
|
|
||
| If ``failed`` is non-zero, check the log output for ``AccessDenied`` or network | ||
| errors and verify the key file credentials. | ||
|
|
||
|
|
||
| Troubleshooting | ||
| ---------------- | ||
|
|
||
| **Problem:** ``LookupError: S3 credentials key file not found at /usr/share/odemis/datacollector.key`` | ||
|
|
||
| **Solution:** Create the key file as described in | ||
| `Installing the Credentials Key File`_. | ||
|
|
||
| ---- | ||
|
|
||
| **Problem:** ``botocore.exceptions.ClientError: AccessDenied`` | ||
|
|
||
| **Cause:** The IAM key in the key file does not have permission to write to the | ||
| bucket being targeted. | ||
|
|
||
| **Solution:** Ensure the key file contains credentials matching the target | ||
| bucket (production key → production bucket, test key → test bucket). Check | ||
| whether ``TEST_DATACOLLECTION=1`` is set unexpectedly. | ||
|
|
||
| ---- | ||
|
|
||
| **Problem:** Uploads never happen; queue fills up. | ||
|
|
||
| **Cause:** Network is unavailable or credentials are wrong. | ||
|
|
||
| **Solution:** Check the Odemis log for ``DataCollector upload failed`` entries. | ||
| The framework retries with exponential back-off (30 s → 60 s → ... up to 1 h). | ||
| Pending ZIPs remain in ``~/.local/share/odemis/dc_queue/`` and are flushed | ||
| oldest-first once connectivity is restored. | ||
|
|
||
| ---- | ||
|
|
||
| **Problem:** ``Queue limit exceeded: removed oldest sample`` appears in the log. | ||
|
|
||
| **Cause:** The queue directory has grown beyond 10 % of the partition. | ||
|
|
||
| **Solution:** Check disk space with ``df -h ~/.local/share/odemis/dc_queue``. | ||
| Investigate why uploads are not succeeding (credentials, network). | ||
|
|
||
| ---- | ||
|
|
||
| **Problem:** ``TEST_DATACOLLECTION=1`` is set but uploads still go to | ||
| production. | ||
|
|
||
| **Solution:** The environment variable is read at the | ||
| moment ``get_upload_backend()`` is called, which is lazy (first upload attempt). | ||
| Verify the variable is exported in the same shell/environment that runs the | ||
| Odemis process. | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: delmic/odemis
Length of output: 600
🏁 Script executed:
Repository: delmic/odemis
Length of output: 2102
Update
debian/controlto reflect Python 3.9+ requirement.This PR introduces builtin generic annotations (
list[str],tuple[Any, str]) which require Python 3.9+, butdebian/controlstill declaresX-Python3-Version: >= 3.6. The package will fail to import on Python 3.6–3.8. Update line 18 frompython3-all-dev (>= 3.6.1)to at least>= 3.9.🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how to handle it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Let me check the codebase for the minimum Python version already in use and the exact annotations in the new files.
🏁 Script executed:
Length of output: 544
🏁 Script executed:
Length of output: 1480
@K4rishma, no worries — here's a clear explanation of the issue and the easiest fix.What's the problem?
Your new files use lowercase builtin generics like
list[Path]andtuple[Any, str]directly in type annotations. This syntax (PEP 585) was only introduced in Python 3.9+. However,debian/controldeclares the package requires Python ≥ 3.6, so it would fail to import on older Python versions.The easiest fix (minimal change)
dc_fetch.pyalready importsList,Tuple, etc. fromtypingat the top — you just need to use them consistently in the two function signatures where lowercase was slipped in:In
src/odemis/util/dc_fetch.py(lines 169 and 193), change:(
Tupleis already imported fromtypingin that file — no new imports needed.)In
src/odemis/util/datacollector.py(line 527), change:And add
Listto thetypingimport in that file:Alternative: bump the minimum Python version
If the project is already targeting a modern OS (e.g., Ubuntu 22.04 which ships Python 3.10, or Debian Bookworm which ships Python 3.11), you could instead bump the declared minimum in
debian/control:But this is a wider project-level decision — I'd recommend going with the typing-based fix above as it's the smallest and safest change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@K4rishma the code should stay Python 3.8 compatible. You should change the type annotation to be
Listinstead oflistandDictinstead ofdict.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.