Skip to content
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

[usage] Round workspace runtime #10591

Merged
merged 1 commit into from
Jun 13, 2022
Merged

[usage] Round workspace runtime #10591

merged 1 commit into from
Jun 13, 2022

Conversation

easyCZ
Copy link
Member

@easyCZ easyCZ commented Jun 10, 2022

Description

As requested in #10583 (review).

Related Issue(s)

Fixes #

How to test

Unit tests

Release Notes

NONE

Documentation

NONE

@easyCZ easyCZ requested a review from a team June 10, 2022 14:31
@github-actions github-actions bot added the team: webapp Issue belongs to the WebApp team label Jun 10, 2022
@easyCZ
Copy link
Member Author

easyCZ commented Jun 10, 2022

I personally think that rounding at this layer is losing precision for no good reason. The rounding can always happen before it's inserted into the DB, or before it's synced into stripe but the report should remain as accurate as possible. It is an intermediate representation.

@@ -131,7 +131,7 @@ func (u *UsageReconciler) ReconcileTimeRange(ctx context.Context, from, to time.
func generateUsageReport(teams []teamWithWorkspaces, maxStopTime time.Time) ([]TeamUsage, error) {
var report []TeamUsage
for _, team := range teams {
var teamTotalRuntime float64
var teamTotalRuntime int64
Copy link
Contributor

Choose a reason for hiding this comment

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

Thought: This could even be uint64 right? (I don't think we want to support "negative usage time", so we can double our max representable value 🙌)

Copy link
Member

Choose a reason for hiding this comment

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

If this really is only about "usage"/"runtime", I agree. If we want to represent "credits" here (which I'm not sure we want/should..?) then int64 it is.
Another thought: Not sure how (type) safe uint64/int64 interactions are in Go: Is it easy to mess it up? If yes, that might be a good argument too keep one type everywhere (most likely in64 if we need the "positive" side)

Copy link
Contributor

@jankeromnes jankeromnes left a comment

Choose a reason for hiding this comment

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

Thanks again!

I personally think that rounding at this layer is losing precision for no good reason. The rounding can always happen before it's inserted into the DB, or before it's synced into stripe but the report should remain as accurate as possible. It is an intermediate representation.

Thanks for voicing these concerns. I do understand your point, however I still believe that the extra readability and sanity of integer values for seconds outweighs any benefits given by sub-second precision. Still, if we really do want sub-second precision one day, I think it will be easy to adjust. 😊

Approving, but holding due to one optional suggestion.

/hold

@geropl
Copy link
Member

geropl commented Jun 13, 2022

I do understand your point, however I still believe that the extra readability and sanity of integer values for seconds outweighs any benefits given by sub-second precision

My 2 cents:

  • we should definitely store time durations in integer values (upvoting the uint64 comment above!)
  • whether we want to store ms vs s:
    • for precisions/consistencies sake it's sometimes beneficial to keep whatever we get as input (ms here), e.g. if we need to be able to exactly identify time-range in the opposite direction (usage -> workspace instance)
    • but as all clients are not interested in anything below s precision, I think it's a great way to keep things simple, and use the same datatype everywhere 🧘

@jankeromnes
Copy link
Contributor

Since Milan is on holidays, let's merge this as is and address the review comments in follow-up PRs.

/unhold

@roboquat roboquat merged commit ae50163 into main Jun 13, 2022
@roboquat roboquat deleted the mp/usage-round branch June 13, 2022 14:20
@roboquat roboquat added deployed: webapp Meta team change is running in production deployed Change is completely running in production labels Jun 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deployed: webapp Meta team change is running in production deployed Change is completely running in production release-note-none size/S team: webapp Issue belongs to the WebApp team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants