Skip to content

Conversation

@ricardogarim
Copy link
Contributor

@ricardogarim ricardogarim commented Feb 9, 2026

The rocketchat_statistics collection grows indefinitely as statistics are collected daily but never cleaned up.

Customer reported: After running since 2017 (~7 years), their statistics collection reached 496MB - larger than their messages collection (454MB).

Proposed changes (including videos or screenshots)

This PR adds a MongoDB TTL index to automatically expire statistics documents after 1 year (365 days), capping storage to approximately ~70MB regardless of how long the server runs.

Why TTL index?

  • Already used across 10+ collections in the codebase (IntegrationHistory, Sessions, AppLogs, NotificationQueue, OAuth tokens, Trash, etc.)
  • Zero runtime code - MongoDB handles expiration automatically
  • No admin configuration needed - 1 year retention is sufficient for operational/debugging needs

Issue(s)

Steps to test or reproduce

  1. Start Rocket.Chat server
  2. Connect to MongoDB and verify the TTL index was created: db.rocketchat_statistics.getIndexes()
  3. Confirm the output includes an index with expireAfterSeconds: 31536000: { "key": { "createdAt": 1 }, "name": "createdAt_1", "expireAfterSeconds": 31536000 }

Further comments

Alternatives considered:

  • Configurable setting + cron job: Over-engineered for this use case; stats retention doesn't need runtime configuration
  • Keep last N documents (count-based): Requires cleanup job code; time-based is more intuitive
  • Size-based cap (e.g., 50MB): MongoDB doesn't support natively; would require complex implementation

Important: in the future, when we reach the next major, we should merge PR #38572. It contains the index consolidation and a migration that we can’t merge right now, since migrations are only included in major releases. The work there is ready to go.

Summary by CodeRabbit

Release Notes

  • New Features

    • Implemented automatic cleanup of historical statistics data, with documents retained for 1 year.
  • Chores

    • Patch release.

@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Feb 9, 2026

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is targeting the wrong base branch. It should target 8.2.0, but it targets 8.1.0

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link

changeset-bot bot commented Feb 9, 2026

🦋 Changeset detected

Latest commit: 073dfa8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 40 packages
Name Type
@rocket.chat/models Patch
@rocket.chat/meteor Patch
@rocket.chat/core-services Patch
@rocket.chat/cron Patch
@rocket.chat/instance-status Patch
@rocket.chat/omni-core Patch
@rocket.chat/ui-client Patch
@rocket.chat/account-service Patch
@rocket.chat/authorization-service Patch
@rocket.chat/ddp-streamer Patch
@rocket.chat/omnichannel-transcript Patch
@rocket.chat/presence-service Patch
@rocket.chat/queue-worker Patch
@rocket.chat/abac Patch
@rocket.chat/federation-matrix Patch
@rocket.chat/media-calls Patch
@rocket.chat/omni-core-ee Patch
@rocket.chat/omnichannel-services Patch
@rocket.chat/presence Patch
rocketchat-services Patch
@rocket.chat/network-broker Patch
@rocket.chat/core-typings Patch
@rocket.chat/rest-typings Patch
@rocket.chat/uikit-playground Patch
@rocket.chat/api-client Patch
@rocket.chat/apps Patch
@rocket.chat/ddp-client Patch
@rocket.chat/fuselage-ui-kit Patch
@rocket.chat/gazzodown Patch
@rocket.chat/http-router Patch
@rocket.chat/livechat Patch
@rocket.chat/model-typings Patch
@rocket.chat/ui-avatar Patch
@rocket.chat/ui-contexts Patch
@rocket.chat/ui-voip Patch
@rocket.chat/web-ui-registration Patch
@rocket.chat/license Patch
@rocket.chat/pdf-worker Patch
@rocket.chat/mock-providers Patch
@rocket.chat/ui-video-conf Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 9, 2026

Walkthrough

Implements automatic cleanup of the MongoDB statistics collection by adding a TTL (Time To Live) index that expires documents after 365 days, preventing indefinite growth of the statistics collection over time.

Changes

Cohort / File(s) Summary
Changelog
.changeset/young-humans-stare.md
Adds release notes documenting the automatic statistics collection cleanup feature with 1-year retention policy using TTL indexing.
Statistics Model
packages/models/src/models/Statistics.ts
Adds a new ascending TTL index on the createdAt field with expireAfterSeconds set to 31,536,000 (365 days), enabling automatic document expiration while preserving the existing descending index.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 Hop, hop, statistics grow,
But now they'll cleanup down below,
A TTL index, one year's grace,
Then off to digital rabbit space! 🌙✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding a TTL index to the statistics collection for automatic cleanup, which is the primary objective of this PR.
Linked Issues check ✅ Passed The PR implements TTL-based automatic cleanup of statistics collection (#36003, CORE-1785), adding a 1-year retention index to prevent unbounded growth without requiring manual configuration.
Out of Scope Changes check ✅ Passed All changes are scoped to adding a TTL index for statistics cleanup as specified in linked issues; changelog entry and index addition are directly related to the stated objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


No actionable comments were generated in the recent review. 🎉

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 13433b1 and 073dfa8.

📒 Files selected for processing (2)
  • .changeset/young-humans-stare.md
  • packages/models/src/models/Statistics.ts
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • packages/models/src/models/Statistics.ts
🔇 Additional comments (2)
.changeset/young-humans-stare.md (1)

1-5: LGTM!

Changeset correctly documents the patch-level change for @rocket.chat/models.

packages/models/src/models/Statistics.ts (1)

13-16: LGTM — TTL index is correctly defined.

The TTL index configuration is correct: ascending single-field key on createdAt with the right expiration value. The redundancy with the existing { createdAt: -1 } index is acknowledged per the PR description (consolidation deferred to PR #38572).

One minor note: the inline comment on line 15 should be removed per coding guidelines. As per coding guidelines, **/*.{ts,tsx,js}: "Avoid code comments in the implementation".

[approve_code_changes, suggest_optional_refactor]

Nitpick: remove inline comment
-			{ key: { createdAt: 1 }, expireAfterSeconds: 365 * 24 * 60 * 60 }, // expire after 1 year
+			{ key: { createdAt: 1 }, expireAfterSeconds: 365 * 24 * 60 * 60 },

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ricardogarim ricardogarim added this to the 8.2.0 milestone Feb 9, 2026
@codecov
Copy link

codecov bot commented Feb 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.41%. Comparing base (eb366e7) to head (073dfa8).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #38568      +/-   ##
===========================================
+ Coverage    70.39%   70.41%   +0.01%     
===========================================
  Files         3161     3162       +1     
  Lines       110654   110650       -4     
  Branches     19892    19859      -33     
===========================================
+ Hits         77895    77914      +19     
+ Misses       30731    30707      -24     
- Partials      2028     2029       +1     
Flag Coverage Δ
e2e 60.35% <ø> (-0.02%) ⬇️
e2e-api 48.76% <ø> (+1.00%) ⬆️
unit 71.40% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 9, 2026

📦 Docker Image Size Report

➡️ Changes

Service Current Baseline Change Percent
sum of all images 0B 0B 0B
account-service 0B 0B 0B
authorization-service 0B 0B 0B
ddp-streamer-service 0B 0B 0B
omnichannel-transcript-service 0B 0B 0B
presence-service 0B 0B 0B
queue-worker-service 0B 0B 0B
rocketchat 0B 0B 0B

📊 Historical Trend

---
config:
  theme: "dark"
  xyChart:
    width: 900
    height: 400
---
xychart
  title "Image Size Evolution by Service (Last 30 Days + This PR)"
  x-axis ["11/18 22:53", "11/19 23:02", "11/21 16:49", "11/24 17:34", "11/27 22:32", "11/28 19:05", "12/01 23:01", "12/02 21:57", "12/03 21:00", "12/04 18:17", "12/05 21:56", "12/08 20:15", "12/09 22:17", "12/10 23:26", "12/11 21:56", "12/12 22:45", "12/13 01:34", "12/15 22:31", "12/16 22:18", "12/17 21:04", "12/18 23:12", "12/19 23:27", "12/20 21:03", "12/22 18:54", "12/23 16:16", "12/24 19:38", "12/25 17:51", "12/26 13:18", "12/29 19:01", "12/30 20:52", "02/10 13:59 (PR)"]
  y-axis "Size (GB)" 0 --> 0.5
  line "account-service" [0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.00]
  line "authorization-service" [0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.00]
  line "ddp-streamer-service" [0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.00]
  line "omnichannel-transcript-service" [0.14, 0.14, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.00]
  line "presence-service" [0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.00]
  line "queue-worker-service" [0.14, 0.14, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.00]
  line "rocketchat" [0.35, 0.35, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.00]
Loading

Statistics (last 30 days):

  • 📊 Average: 1.5GiB
  • ⬇️ Minimum: 1.4GiB
  • ⬆️ Maximum: 1.6GiB
  • 🎯 Current PR: 0B
ℹ️ About this report

This report compares Docker image sizes from this build against the develop baseline.

  • Tag: pr-38568
  • Baseline: develop
  • Timestamp: 2026-02-10 13:59:47 UTC
  • Historical data points: 30

Updated: Tue, 10 Feb 2026 13:59:47 GMT

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Collected statistics are not automatically rotated / cleaned

1 participant