-
Notifications
You must be signed in to change notification settings - Fork 2
Fix the analytics issue and update the README file #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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 pull request fixes analytics functionality by correcting cost calculation formulas and replaces dummy data with actual database queries. The PR also adds a comprehensive README file to improve project documentation.
- Fixed cost calculation formulas in the analytics utils by removing incorrect scaling factors
- Updated analytics handlers to use actual database queries instead of returning hardcoded dummy data
- Added comprehensive README documentation covering architecture, API endpoints, and setup instructions
Reviewed Changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| analytics/utils.go | Fixed cost calculation formulas by removing scaling factors and updating rate constants |
| analytics/models.go | Removed extensive dummy data variables that were previously used for testing |
| analytics/handlers.go | Updated handlers to use actual database queries and improved error handling for NULL values |
| README.md | Added comprehensive project documentation including setup, API endpoints, and architecture |
| // CalculateCosts calculates the costs associated with database usage based on read/write queries and CPU time. | ||
| func (d *DatabaseUsageStats) CalculateCosts() DatabaseUsageCost { | ||
| Cost := DatabaseUsageCost{ | ||
| ReadWriteCost: float64(d.ReadQueries)/1_000_000*1.00 + float64(d.WriteQueries)/1_000_000*1.50, | ||
| CPUCost: (d.TotalCPUTimeMs / 1000 / 3600) * 0.000463, | ||
| ReadWriteCost: float64(d.ReadQueries)*1.00 + float64(d.WriteQueries)*1.50, | ||
| CPUCost: d.TotalCPUTimeMs * 1.50, |
Copilot
AI
Jul 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cost calculation uses magic numbers (1.00, 1.50) without explanation. Consider defining these as named constants with clear documentation about the pricing model.
| // CalculateCosts calculates the costs associated with database usage based on read/write queries and CPU time. | ||
| func (d *DatabaseUsageStats) CalculateCosts() DatabaseUsageCost { | ||
| Cost := DatabaseUsageCost{ | ||
| ReadWriteCost: float64(d.ReadQueries)/1_000_000*1.00 + float64(d.WriteQueries)/1_000_000*1.50, | ||
| CPUCost: (d.TotalCPUTimeMs / 1000 / 3600) * 0.000463, | ||
| ReadWriteCost: float64(d.ReadQueries)*1.00 + float64(d.WriteQueries)*1.50, | ||
| CPUCost: d.TotalCPUTimeMs * 1.50, |
Copilot
AI
Jul 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CPU cost calculation uses a magic number (1.50) and appears to have incorrect units. CPU time in milliseconds multiplied by a rate should likely be converted to appropriate time units (seconds/hours) for meaningful cost calculation.
|
|
||
| _, apiErr := GetALLExecutionTimeStats(r.Context(), config.DB, projectOid) | ||
| stats, apiErr := GetALLExecutionTimeStats(r.Context(), config.DB, projectOid) | ||
| if len(stats) == 0 || (apiErr.Error() != nil && strings.Contains(apiErr.Error().Error(), "cannot scan NULL into")) { |
Copilot
AI
Jul 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation uses spaces instead of tabs, which is inconsistent with Go formatting standards. Run 'go fmt' to fix formatting.
| if len(stats) == 0 || (apiErr.Error() != nil && strings.Contains(apiErr.Error().Error(), "cannot scan NULL into")) { | |
| if len(stats) == 0 || (apiErr.Error() != nil && strings.Contains(apiErr.Error().Error(), "cannot scan NULL into")) { |
| storage, apiErr := GetALLDatabaseStorage(r.Context(), config.DB, projectOid) | ||
| if apiErr.Error() != nil { | ||
| utils.ResponseHandler(w, r, apiErr) | ||
| if len(storage) == 0 || (apiErr.Error() != nil && strings.Contains(apiErr.Error().Error(), "cannot scan NULL into")) { |
Copilot
AI
Jul 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error handling logic is duplicated across multiple handlers. Consider extracting this into a shared utility function to reduce code duplication.
| storage, apiErr := GetALLDatabaseStorage(r.Context(), config.DB, projectOid) | ||
| if apiErr.Error() != nil { | ||
| utils.ResponseHandler(w, r, apiErr) | ||
| if len(storage) == 0 || (apiErr.Error() != nil && strings.Contains(apiErr.Error().Error(), "cannot scan NULL into")) { |
Copilot
AI
Jul 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String matching on error messages ("cannot scan NULL into") is fragile and can break if the underlying library changes error messages. Consider using error type checking or defining custom error types for more robust error handling.
No description provided.