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

Clarify how often usage reports are sent #928

Merged
merged 1 commit into from
Jul 17, 2023
Merged

Conversation

matthew-white
Copy link
Member

@matthew-white matthew-white commented Jul 13, 2023

Closes #921. This PR doesn't change the current behavior, but it tries to make that behavior clear. For example, I used to think that usage reports were sent every 30 days. After this PR, usage reports will continue to be sent every 31 days — but I think that fact will be clearer.

What has been done to verify that this works as intended?

Updated and new tests.

Why is this the best possible solution? Were any other approaches considered?

I considered not making any changes at all. I realized that I could send daily usage reports by setting the default.taskSchedule.analytics config to 0 instead of 1. However, I think this PR makes things a little clearer.

I'll also leave a comment about an individual line.

How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?

The current behavior is intended to stay the same. I've updated tests to help verify that there hasn't been a change in behavior.

Does this change require updates to the API documentation? If so, please update docs/api.md as part of this PR.

I don't think so. We say in the API docs that usage data is sent monthly, which is consistent with the current interval of 31 days.

Before submitting this PR, please make sure you have:

  • run make test-full and confirmed all checks still pass OR confirm CircleCI build passes
  • verified that any code from external sources are properly credited in comments or that everything is internally sourced

const getLatestAudit = () => ({ maybeOne }) => maybeOne(sql`select * from audits
where action='analytics' and "loggedAt" >= current_date - cast(${AUDIT_SCHEDULE} as int)
where action='analytics' and current_date - "loggedAt"::date < ${ANALYTICS_SCHEDULE}
Copy link
Member Author

Choose a reason for hiding this comment

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

Instead of this change, I could have done:

"loggedAt" >= current_date - cast(${AUDIT_SCHEDULE} as int) + 1

However, I think that would have been less clear overall.

I was initially confused about dates vs. timestamps here. Previously, current_date - cast(${AUDIT_SCHEDULE} as int) was implicitly coerced to a timestamp with time part equal to midnight. I started wondering about the time part of loggedAt and whether it mattered that it was 3 a.m. instead of midnight. Now I'm converting loggedAt to a date and calculating the number of days between that date and current_date. That way, the time part of loggedAt doesn't figure into things: it doesn't matter when the usage report started or how long it took to complete.

This approach also lets us remove the cast of ANALYTICS_SCHEDULE.

Copy link
Member

Choose a reason for hiding this comment

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

I like this new approach a lot of making both values dates (without timestamps) and doing the subtraction there.

@matthew-white
Copy link
Member Author

@ktuite, I'm thinking this can be reviewed async.

@matthew-white matthew-white merged commit 34d2f32 into master Jul 17, 2023
1 check passed
@matthew-white matthew-white deleted the analytics-schedule branch July 17, 2023 16:36
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.

Usage data is sent a day later than expected
2 participants