Skip to content

fix - entity too big error for stats#363

Merged
frikky merged 2 commits intoShuffle:mainfrom
LalitDeore:fix-stats
Mar 31, 2026
Merged

fix - entity too big error for stats#363
frikky merged 2 commits intoShuffle:mainfrom
LalitDeore:fix-stats

Conversation

@LalitDeore
Copy link
Copy Markdown
Collaborator

Copy link
Copy Markdown
Member

@frikky frikky left a comment

Choose a reason for hiding this comment

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

Just minor stuff to consider. Fine to merge if you're ok

log.Printf("[WARNING] SetOrgStatistics: GCS archive failed for org %s: %s – trimming anyway", id, archiveErr)
}

if len(stats.DailyStatistics) > 60 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there any chance at all that 60 can be too big as well? Have you checked the average size per day?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This should not happen. GCP allows a maximum entity size of 1 MB, and storing 60 days of data should not cause any issues.

}
dateMap := make(map[string]DailyStatistics, dateMapCap)
for _, d := range existingStats {
dateMap[d.Date.UTC().Format("2006-01-02")] = d
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This feels weird mapping-wise, but with the small scale should be fine


gcsWriter := obj.NewWriter(ctx)
if _, writeErr := gcsWriter.Write(mergedBytes); writeErr != nil {
_ = gcsWriter.Close()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this actually return a value?

Can't you just defer gcsWriter.Close()?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Okay, changing this :)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@frikky I looked into this and found that using defer gcsWriter.Close() can cause the error from Close() to be missed.

I’ve used the following code instead, which checks and returns the error properly. This makes it easier to debug issues in case of GCS write failure:

if closeErr := gcsWriter.Close(); closeErr != nil { return fmt.Errorf("archiveOldStatsToGCSBucket: failed to close GCS writer for org %s: %w", orgId, closeErr) }

}

// Sideload GCS overflow stats (entries >60 days old archived from Datastore), cached 30 min.
if project.Environment == "cloud" && len(orgFileBucket) > 0 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

"Max size" is also a problem onprem tho

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Let's make this available on Cloud first. In case we should prioritize onprem as well let me know :)

@LalitDeore
Copy link
Copy Markdown
Collaborator Author

@frikky We can merge this PR :)

@frikky frikky merged commit 38ef776 into Shuffle:main Mar 31, 2026
15 of 17 checks passed
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.

3 participants