Skip to content

Conversation

@ivandevp
Copy link
Collaborator

Description

Add timeseries collection stats in a tooltip for the timeseries property badge.
Screenshot 2025-11-19 at 15 47 23

Checklist

  • New tests and/or benchmarks are included
  • Documentation is changed or added
  • If this change updates the UI, screenshots/videos are added and a design review is requested
  • If this change could impact the load on the MongoDB cluster, please describe the expected and worst case impact
  • I have signed the MongoDB Contributor License Agreement (https://www.mongodb.com/legal/contributor-agreement)

Motivation and Context

  • Bugfix
  • New feature
  • Dependency update
  • Misc

Open Questions

Dependents

Types of changes

  • Backport Needed
  • Patch (non-breaking change which fixes an issue)
  • Minor (non-breaking change which adds functionality)
  • Major (fix or feature that would cause existing functionality to change)

@ivandevp ivandevp requested a review from a team as a code owner November 19, 2025 14:47
@ivandevp ivandevp requested review from Copilot and mabaasit November 19, 2025 14:47
@github-actions github-actions bot added the feat label Nov 19, 2025
Copilot finished reviewing on behalf of ivandevp November 19, 2025 14:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds timeseries collection statistics (bucket count and average bucket size) to the collections list UI. The stats are displayed in a tooltip when hovering over the timeseries badge.

Key Changes:

  • Added bucket_count and avg_bucket_size fields to collection types and models
  • Implemented aggregation pipeline logic to calculate bucket statistics from MongoDB storage stats
  • Created tooltip with formatted bucket statistics for timeseries collections

Reviewed Changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/data-service/src/types.ts Added optional bucket_count and avg_bucket_size fields to CollectionStats interface
packages/data-service/src/data-service.ts Implemented aggregation pipeline stages to extract and calculate timeseries bucket statistics
packages/collection-model/lib/model.js Added bucket_count and avg_bucket_size as number properties
packages/collection-model/index.d.ts Added optional bucket_count and avg_bucket_size to CollectionProps interface
packages/databases-collections-list/src/collections.tsx Updated timeseries badge to display tooltip with bucket stats; removed timeseries from view-only conditions for indexes and index size columns
packages/databases-collections-list/src/collections.spec.tsx Updated test data and added test coverage for timeseries badge tooltip

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

case 'timeseries':
return { id, name: id, variant: 'darkgray', icon: 'TimeSeries' };
case 'timeseries': {
let hint: React.ReactNode = undefined;
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

[nitpick] Redundant initialization. In TypeScript/JavaScript, variables without explicit initialization are already undefined. Remove = undefined for cleaner code.

Suggested change
let hint: React.ReactNode = undefined;
let hint: React.ReactNode;

Copilot uses AI. Check for mistakes.
Comment on lines +1227 to +1239
totalBucketSize: {
$first: {
$ifNull: [
{
$multiply: [
'$storageStats.timeseries.avgBucketSize',
'$storageStats.timeseries.bucketCount',
],
},
'$storageStats.totalBucketSize',
],
},
},
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

This calculation multiplies avgBucketSize by bucketCount to derive totalBucketSize, but the logic and rationale are unclear. Add a comment explaining why this multiplication is necessary and when each field in the $ifNull array is expected to be available versus null.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think the logic needs to be explained, but given that we're clearly trying to support different setups (or server versions), a short note or link to docs could be useful. Especially if part of this is older sever versions, which is something we might be able to clean up once those versions are EOL.

Copy link
Contributor

@lerouxb lerouxb Nov 21, 2025

Choose a reason for hiding this comment

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

Do we already know what type of collection it is? This is run per collectionName so I'm wondering if we can just run different queries depending on the type of collection and if that won't be safer and easier to read.

(This is just me wondering, I don't know if that would necessarily be better.)

Comment on lines +1258 to +1280
avgBucketSize: {
$cond: {
if: { $ne: ['$avgBucketSizeFromStats', null] },
then: '$avgBucketSizeFromStats',
else: {
$cond: {
if: {
$and: [
{ $ne: ['$numBuckets', null] },
{ $ne: ['$numBuckets', 0] },
],
},
then: {
$divide: [
{ $toDouble: '$totalBucketSize' },
{ $toDouble: '$numBuckets' },
],
},
else: null,
},
},
},
},
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

This nested conditional logic for calculating avgBucketSize has multiple fallback paths but lacks explanation. Add a comment describing the calculation strategy: when avgBucketSize is directly available from stats vs. when it needs to be calculated from totalBucketSize/numBuckets, and what MongoDB versions or configurations affect this.

Copilot uses AI. Check for mistakes.
Comment on lines +567 to +568
const result = inspectTable(screen, 'collections-list');
const badge = result.trs[3].querySelector(
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

Using a hardcoded array index (result.trs[3]) makes this test brittle. If the order of collections changes or collections are added/removed, this test will break. Consider selecting the timeseries collection by name or filtering for the collection with timeseries properties instead.

Suggested change
const result = inspectTable(screen, 'collections-list');
const badge = result.trs[3].querySelector(
const timeseriesRow = screen.getByTestId('collections-list-row-timeseries');
const badge = timeseriesRow.querySelector(

Copilot uses AI. Check for mistakes.
@ivandevp ivandevp self-assigned this Nov 19, 2025
@ivandevp ivandevp added the no release notes Fix or feature not for release notes label Nov 19, 2025
@codeowners-service-app
Copy link

Assigned paula-stacho for team compass-developers because mabaasit is out of office.

Copy link
Collaborator

@paula-stacho paula-stacho left a comment

Choose a reason for hiding this comment

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

Left a small suggestion, otherwise looks good!

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

Labels

feat no release notes Fix or feature not for release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants