Skip to content

MM-67505 Add AnalyticsQueryTimeout setting and use when refreshing materialized views#35906

Merged
hmhealey merged 7 commits intomasterfrom
MM-67505_analytics-timeout
Apr 13, 2026
Merged

MM-67505 Add AnalyticsQueryTimeout setting and use when refreshing materialized views#35906
hmhealey merged 7 commits intomasterfrom
MM-67505_analytics-timeout

Conversation

@hmhealey
Copy link
Copy Markdown
Member

@hmhealey hmhealey commented Apr 1, 2026

Summary

The queries to refresh the materialized views which are now used for calculating some of the contents of the statistics pages in the system console take longer than other queries, but that's fine because they should only be ran in the background periodically. This PR adds a new timeout for them which defaults to 5 minutes.

Note that this isn't used for other analytics queries like I originally thought based on the ticket's name and trying to understand the accompanying thread without context. After originally doing that, I realized this was meant more for those specific queries which didn't need as many changes, so I reverted that part because I didn't think it was a good idea to increase the timeout on the other queries which are called directly via the API. Let me know if I should add this timeout to more queries though.

Ticket Link

https://mattermost.atlassian.net/browse/MM-67505

Release Note

Added DatabaseSettings.AnalyticsQueryTimeout setting for use when running long analytics queries in the background

Change Impact: 🟡 Medium

Regression Risk: Modest — changes are limited to adding a new SqlSettings field and applying context-based timeouts only to background materialized-view refreshes; this may cause long-running refreshes to fail under high DB load but does not alter API call paths or core logic.
QA Recommendation: Manual verification recommended: exercise materialized-view refreshes on environments with varying DB performance (local, staging, cloud) and validate the admin UI, config persistence, and validation for the new AnalyticsQueryTimeout.


Release Notes

Added DatabaseSettings.AnalyticsQueryTimeout setting for use when running long analytics queries in the background.

Generated by CodeRabbitAI

@hmhealey hmhealey added this to the v11.7.0 milestone Apr 1, 2026
@hmhealey hmhealey added the 2: Dev Review Requires review by a developer label Apr 1, 2026
@mm-cloud-bot mm-cloud-bot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Apr 1, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 1, 2026

Documentation Impact Analysis — updates needed

Documentation Impact Analysis

Overall Assessment: Documentation Updates Required

Changes Summary

This PR introduces a new AnalyticsQueryTimeout configuration setting that controls database timeout behavior specifically for analytics queries used to populate Team and Site Statistics pages in the admin console. The setting defaults to 300 seconds and is separate from the existing general QueryTimeout setting.

Documentation Impact Details

Change Type Files Changed Affected Personas Documentation Action Docs Location
Configuration changes server/public/model/config.go System Administrator Add new setting documentation docs/source/administration-guide/configure/environment-configuration-settings.rst
UI changes webapp/channels/src/components/admin_console/database_settings.tsx System Administrator Already covered by config setting documentation N/A

Recommended Actions

  • Update docs/source/administration-guide/configure/environment-configuration-settings.rst to document new AnalyticsQueryTimeout setting in the database section, following the same format as the existing QueryTimeout setting (around line 830)
  • Document default value of 300 seconds and explain that it specifically affects analytics queries for Team and Site Statistics pages
  • Include the environment variable MM_SQLSETTINGS_ANALYTICSQUERYTIMEOUT and config.json path SqlSettings.AnalyticsQueryTimeout

Confidence

High — This is a straightforward new configuration setting with well-defined behavior and clear documentation requirements. The existing QueryTimeout setting in the same file provides an exact template for documenting this new setting.


@github-actions github-actions Bot added the Docs/Needed Requires documentation label Apr 1, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 1, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f2ca9239-8fd9-47ea-b639-5b365ebb548f

📥 Commits

Reviewing files that changed from the base of the PR and between 9a3133b and b88a6f6.

⛔ Files ignored due to path filters (1)
  • webapp/channels/src/components/admin_console/__snapshots__/database_settings.test.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (1)
  • server/i18n/en.json
✅ Files skipped from review due to trivial changes (1)
  • server/i18n/en.json

📝 Walkthrough

Walkthrough

Adds a configurable SQL analytics query timeout, introduces a SqlStore.analyticsContext helper used to run materialized-view refreshes with cancellable contexts, validates and defaults the new setting, and exposes it in admin UI, TypeScript types, translations, tests, and default configs.

Changes

Cohort / File(s) Summary
Backend: store context & view refreshes
server/channels/store/sqlstore/store.go, server/channels/store/sqlstore/file_info_store.go, server/channels/store/sqlstore/post_store.go, server/channels/store/sqlstore/user_store.go
Added analyticsContext() to produce a cancellable context with timeout from settings; switched materialized-view refresh Exec(...) calls to context-aware ExecContext(...) and deferred cancels.
Backend: store tests settings
server/channels/store/storetest/settings.go
Initialized AnalyticsQueryTimeout in test database settings to the default (300).
Backend: SQL config model
server/public/model/config.go
Added AnalyticsQueryTimeout *int to SqlSettings, defaulted to 300 in SetDefaults, and added validation requiring >0 with a new error key.
Backend: i18n
server/i18n/en.json
Added validation error translation key model.config.is_valid.sql_analytics_query_timeout.app_error.
Web Admin UI
webapp/channels/src/components/admin_console/database_settings.tsx, webapp/channels/src/components/admin_console/database_settings.test.tsx
Added analyticsQueryTimeout state, form field, i18n descriptors, hydration/serialization to config, env-override handling, and updated snapshot/test data.
Web i18n & types
webapp/channels/src/i18n/en.json, webapp/platform/types/src/config.ts
Added UI translations (admin.sql.analyticsQueryTimeoutTitle, ...Description, ...Example) and added required AnalyticsQueryTimeout: number to TypeScript SqlSettings type.
E2E & default configs
e2e-tests/cypress/tests/support/api/cloud_default_config.json, e2e-tests/cypress/tests/support/api/on_prem_default_config.json, e2e-tests/playwright/lib/src/server/default_config.ts
Added AnalyticsQueryTimeout = 300 to various default/test server configuration files.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and specifically summarizes the main change: adding a new AnalyticsQueryTimeout setting and applying it to materialized view refreshes.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch MM-67505_analytics-timeout

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

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@webapp/channels/src/components/admin_console/database_settings.tsx`:
- Line 125: Change the assignment to ensure AnalyticsQueryTimeout cannot be
zero: replace the use of parseIntNonNegative with parseIntNonZero when setting
config.SqlSettings.AnalyticsQueryTimeout in the component (so it matches backend
validation in SqlSettings.isValid()); update the statement that currently calls
parseIntNonNegative(this.state.analyticsQueryTimeout) to call
parseIntNonZero(this.state.analyticsQueryTimeout) instead.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 790ba636-8805-4bed-9772-8d9bee9a3e9d

📥 Commits

Reviewing files that changed from the base of the PR and between 9b01e40 and ed71c0a.

⛔ Files ignored due to path filters (1)
  • webapp/channels/src/components/admin_console/__snapshots__/database_settings.test.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (10)
  • server/channels/store/sqlstore/file_info_store.go
  • server/channels/store/sqlstore/post_store.go
  • server/channels/store/sqlstore/store.go
  • server/channels/store/sqlstore/user_store.go
  • server/i18n/en.json
  • server/public/model/config.go
  • webapp/channels/src/components/admin_console/database_settings.test.tsx
  • webapp/channels/src/components/admin_console/database_settings.tsx
  • webapp/channels/src/i18n/en.json
  • webapp/platform/types/src/config.ts

Comment thread webapp/channels/src/components/admin_console/database_settings.tsx Outdated
@hmhealey
Copy link
Copy Markdown
Member Author

hmhealey commented Apr 1, 2026

Docs PR: mattermost/docs#8846

@hmhealey hmhealey added Docs/Done Required documentation has been written and removed Docs/Needed Requires documentation labels Apr 2, 2026
@github-actions github-actions Bot added the Docs/Needed Requires documentation label Apr 2, 2026
@hmhealey
Copy link
Copy Markdown
Member Author

hmhealey commented Apr 6, 2026

The failing E2E test is unrelated to these changes

Copy link
Copy Markdown
Member

@lieut-data lieut-data left a comment

Choose a reason for hiding this comment

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

Nice!!

Copy link
Copy Markdown
Member

@agarciamontoro agarciamontoro left a comment

Choose a reason for hiding this comment

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

Looking good, thank you!

@amyblais amyblais removed the 2: Dev Review Requires review by a developer label Apr 10, 2026
@hmhealey hmhealey merged commit 8e14c8e into master Apr 13, 2026
127 of 128 checks passed
@hmhealey hmhealey deleted the MM-67505_analytics-timeout branch April 13, 2026 13:27
@amyblais amyblais added the Changelog/Done Required changelog entry has been written label Apr 13, 2026
esarafianou pushed a commit that referenced this pull request Apr 22, 2026
…terialized views (#35906)

* MM-67505 Add AnalyticsQueryTimeout setting and use when refreshing materialized views

* Fix last minute i18n change

* Disallow 0 values for AnalyticsQueryTimeout

* Fix E2E test config

* Fix post store tests crashing

* Update snapshot and revert accidental changes to it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Changelog/Done Required changelog entry has been written Docs/Done Required documentation has been written Docs/Needed Requires documentation release-note Denotes a PR that will be considered when it comes time to generate release notes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants