Skip to content

feat: add separate Sensitivity Labels and Encrypted Sensitivity Labels stat cards for Emails and Files - #190

Open
rishiksingh11 wants to merge 8 commits into
google:files-shallow-scanfrom
rishiksingh11:feat/sensitivity-labels-count-emails-and-files
Open

rishiksingh11 wants to merge 8 commits into
google:files-shallow-scanfrom
rishiksingh11:feat/sensitivity-labels-count-emails-and-files

Conversation

@rishiksingh11

@rishiksingh11 rishiksingh11 commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds Sensitivity Labels and Sensitivity Labeled Items metrics for Exchange Online and SharePoint & OneDrive Files (Deep Scan), addressing all feedback from #190 (comment):

  1. Deep Scan Only (Zero Shallow Scan Changes):
    • Scoped Scan for Encrypted Files (RMS/MIP) strictly to Deep Scan (FileEstimator).
    • Reverted all modifications to estimators/files_shallow/shallow_file_estimator.py, util/files_shallow/sp_rest_connector.py, and tests/files/shallow_estimator_test.py (0 diff against files-shallow-scan).
    • Added unit tests for Deep Scan encrypted files & sensitivity labels in tests/files/load_tests.py (TestDeepScanEncryptedFilesAndSensitivityLabels).
  2. Modular Encrypted Files Search Utility (util/encrypted_files_utils.py):
    • Extracted SharePoint REST Search (POST /_api/search/postquery) pagination and sensitivity label classification into util/encrypted_files_utils.py.
  3. Sequential Execution After Deep Scan (_scan_encrypted_files):
    • Executed _scan_encrypted_files sequentially after drive_parsing (_create_in_memory_tree) completes so it never runs concurrently with the Deep Scan.
    • Configured Document Library search concurrency to 3 (ENCRYPTED_FILES_CONCURRENCY = 3).
  4. Scoped to Subsite / Document Library URLs:
    • Removed the base_url fallback (1 <= len(target_urls) <= 10) and strictly scoped every search query to the specific Document Library / Subsite URL (Path:"{library_url}").
  5. O(1) Memory Streaming & Ascending Size Cursor Pagination:
    • Removed seen_files and all_rows accumulation in memory.
    • Ordered search queries in ascending order of file size ({"Property": "Size", "Direction": 0}, tie-broken by {"Property": "DocId", "Direction": 0}) with cursor pagination AND (Size>{last_size} OR (Size={last_size} AND IndexDocId>{last_doc_id})).
    • Aggregated metrics immediately per page via on_page_metrics and explicitly freed page rows (del rows, del resp_data) after each batch.
  6. Resolved Merge Conflicts in ui/files_ui.py & Inline Review Feedback:
    • Merged latest files-shallow-scan (f66811c) cleanly into ui/files_ui.py (shallow_scan default True + shallow_ui_helpers.on_shallow_scan_toggle(self)).
    • Restored ?$select=id,isPersonalSite and response_data.get("isPersonalSite", False) in estimators/file_estimator.py.

Local Screencast & Screenshots

🎥 Local Execution Screencast

Local Screencast

1. Exchange Online — Configuration & Sensitivity Labels Report

Configuration Data Corpus Report
Exchange Online Config Exchange Online Report

2. SharePoint & OneDrive Files (Deep Scan) — Configuration & Sensitivity Labels Report

Configuration (Deep Scan) Data Corpus Report
Files Config Files Report

3. googlellc914 Load-Test Tenant (16,285 Sites) — Scan All Sites + Encrypted Files Memory Usage Proof

  • Tenant ID: 8c838f69-e747-41fa-a86d-e63d579f59cb (googlellc914 / deal_assistant_test_app)
  • Mode: Scan All Sites (Deep Scan, Personal Sites (OneDrive) + SharePoint Sites, Scan for Encrypted Files (RMS/MIP) enabled)
  • Discovered Corpus: 16,285 Sites (15,268 SharePoint Team Sites + 1,017 OneDrive Personal Sites) | 3,013,673 Files (4.21 TB)
  • Memory Usage (psutil Process RSS): Avg 157.6 MB / Peak 227.7 MB (0.22% System RAM) — bounded O(1) worker pool (max_workers=3) with immediate per-page del rows cleanup and per-batch tree cleanup (del batch_adj_list, batch_parent_refs, batch_folder_nodes).
googlellc914 Configuration (Scan All Sites) googlellc914 Data Corpus Report (16,285 Sites)
googlellc914 Config googlellc914 Results

Live Process RSS Memory Profile (googlellc914 — 16,285 Sites)

googlellc914 Memory Profile

…ails and Files

- Replace combined X (Y Encrypted) bracketed counts with separate, standalone stat cards:
  - Exchange Online: Sensitivity Labels, Encrypted Sensitivity Labels, Sensitivity Labeled Emails, and Encrypted Emails in a dedicated row
  - SharePoint & OneDrive Files: Sensitivity Labels, Encrypted Sensitivity Labels, Sensitivity Labeled Files, Total Encrypted File Count, and Total Encrypted File Size in a dedicated row
- Store plain integer counts in Sensitivity Labeled Email Count and Sensitivity Labeled File Count CSV columns
- Refresh screenshots and local GUI screencast against live Microsoft 365 tenant
@rishiksingh11 rishiksingh11 changed the title feat: add Sensitivity Labels & Labeled Items counts (with Encrypted counts in brackets) for Emails & Files Sep 23, 2026
@NityamPareek

Copy link
Copy Markdown
Collaborator

Please fix the following:

  1. Encrypted files option should only be present for deep scan not shallow scan, so please do not modify shallow estimator or its unit tests. Separate unit tests should be written in the load_tests.py file for deep scan.
  2. Feel free to define a separate encrypted_files_utils.py if required for better readability (optional)
  3. Please fix the merge conflicts in files_ui.py
  4. It seems to me that all rows returned from the search are first stored in memory then aggregated. This can cause significant memory usage, please update metrics as soon as the page arrives and then delete them from memory.
  5. Similarly, instead of keeping track of seen_files the query itself can be tailored to fetch files in ascending order of memory so that it is not a random ordering.
  6. You can try adding some concurrency here (3 should be fine for all tenants) to speed up computation. Make sure that this phase runs either before or after the deep scan and should not run together with it to avoid being throttled.
  7. See this piece of code path_prefixes = sorted(target_urls) if 1 <= len(target_urls) <= 10 else [base_url] . Why are we falling back to base url? let's narrow the scope of the search to subsite/DL level and not tenant level to avoid running into issues
Comment thread estimators/file_estimator.py Resolved
@rishiksingh11

Copy link
Copy Markdown
Contributor Author

@NityamPareek Thanks for the thorough review! Addressed all points from your comment and inline review in 8676864:

  1. Scoped Encrypted Files to Deep Scan Only (Reverted Shallow Scan Changes):
    • Reverted all changes to estimators/files_shallow/shallow_file_estimator.py, util/files_shallow/sp_rest_connector.py, and tests/files/shallow_estimator_test.py (0 diff against files-shallow-scan).
    • Added unit tests for Deep Scan encrypted files & sensitivity labels in tests/files/load_tests.py (TestDeepScanEncryptedFilesAndSensitivityLabels).
  2. Extracted Separate util/encrypted_files_utils.py:
    • Moved EncryptedFilesSearchRunner and scan_libraries_for_encrypted_files into a dedicated util/encrypted_files_utils.py module.
  3. Resolved Merge Conflicts in ui/files_ui.py:
    • Merged latest files-shallow-scan (f66811c) cleanly and kept shallow_scan = ctk.BooleanVar(value=True) with shallow_ui_helpers.on_shallow_scan_toggle(self) so Scan for Encrypted Files (RMS/MIP) is only enabled during Deep Scan.
  4. Streaming Per-Page Metrics Aggregation & Immediate Cleanup (del rows):
    • Updated metrics immediately as each page of search results arrives via on_page_metrics and explicitly freed del rows and del resp_data on every page instead of storing rows in memory.
  5. Ordered by Ascending File Size (Removed seen_files):
    • Removed the in-memory seen_files set and ordered SharePoint Search results in ascending order of file size (SortList: [{"Property": "Size", "Direction": 0}, {"Property": "DocId", "Direction": 0}]) with cursor pagination AND (Size>{last_size} OR (Size={last_size} AND IndexDocId>{last_doc_id})).
  6. Sequential Execution After Deep Scan + Concurrency = 3:
    • Moved _scan_encrypted_files to run only after drive_parsing (_create_in_memory_tree) finishes, with ThreadPoolExecutor(max_workers=3) (ENCRYPTED_FILES_CONCURRENCY = 3).
  7. Strictly Scoped to Subsite / Document Library URLs:
    • Removed path_prefixes = sorted(target_urls) if 1 <= len(target_urls) <= 10 else [base_url] and scoped every query strictly to each Document Library URL (Path:\"{library_url}\"").
  8. Inline Comment on estimators/file_estimator.py:
    • Restored ?$select=id,isPersonalSite and response_data.get("isPersonalSite", False) in _parse_sites_data.
@rishiksingh11

Copy link
Copy Markdown
Contributor Author

@NityamPareek Ran Scan All Sites with Scan for Encrypted Files (RMS/MIP) enabled on the googlellc914 tenant (8c838f69-e747-41fa-a86d-e63d579f59cb / deal_assistant_test_app, 16,285 total sites: 15,268 SharePoint + 1,017 OneDrive) and added the proof screenshots & memory profile to the PR:

  • Process RSS Memory Usage: Avg 157.6 MB / Peak 227.7 MB (0.22% System RAM) across all 16,285 sites (3,013,673 files).
  • Memory Optimizations Verified:
    1. Bounded iterator worker pool (max_workers=3) in scan_libraries_for_encrypted_files so we never allocate thousands of Future objects in memory at once.
    2. Immediate per-page del rows / del resp_data cleanup in EncryptedFilesSearchRunner + per-batch del batch_adj_list, batch_parent_refs, batch_folder_nodes cleanup in FileEstimator.
    3. Automatic skip of empty Document Libraries (fileCount == 0).
googlellc914 Configuration (Scan All Sites) googlellc914 Data Corpus Report (16,285 Sites)
googlellc914 Config googlellc914 Results

googlellc914 Memory Profile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants