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

[BACK-2866] Fix Dexcom task failing for newly created Dexcom connections #697

Merged
merged 2 commits into from
Feb 12, 2024

Conversation

darinkrauss
Copy link
Contributor

@darinkrauss darinkrauss commented Feb 7, 2024

  • Fix Dexcom task failing for newly created Dexcom connections
  • Only set CreatedUserID in UsersDataSetsCreate if user AuthDetails
  • Always add error to Dexcom tasks whether or not task should fail
  • Doubled average period between Dexcom task executions from 60 minutes to 120 minutes.
  • Doubled task duration to account for a couple of long running errors observed in logs.
  • Update tests
  • Update .gitignore and .dockerignore
  • https://tidepool.atlassian.net/browse/BACK-2866

- Fix Dexcom task failing for newly created Dexcom connections
- Only set CreatedUserID in UsersDataSetsCreate if user AuthDetails
- Always add error to Dexcom tasks whether or not task should fail
- Update tests
- Update .gitignore and .dockerignore
- https://tidepool.atlassian.net/browse/BACK-2866
Copy link
Contributor

@toddkazakov toddkazakov left a comment

Choose a reason for hiding this comment

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

I think there's one edge case that should be fixed

@@ -51,7 +51,7 @@ func FailTask(l log.Logger, t *task.Task, err error) error {
return err
}

func shouldTaskError(t *task.Task) bool {
func shouldTaskFail(t *task.Task) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this function handles correctly the case where the t.Data[dexcomTaskRetryField] is not set. When t.Data[dexcomTaskRetryField] is nil, this function should return false instead of true, so the retry counter can be set to 1.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that is correct and I intentionally did not fix that yet.

If we make that fix right now, then every Dexcom task that hits a 429 will start down the "retry path" and, after retrying 3 times, will be marked as failed. I really don't want that to happen quite yet. I need to first straighten out what errors cause a formal retry (where the retry counter is incremented; e.g. Dexcom auth errors), what errors retry for "free" (no increment; e.g. Dexcom 429s), and what errors fail immediately (e.g bad data). Furthermore, I need to add code that resets the retry counter on success (as there is no code to do that currently).

jh-bate
jh-bate previously approved these changes Feb 7, 2024
Copy link
Contributor

@jh-bate jh-bate left a comment

Choose a reason for hiding this comment

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

nothing else that I can see - will approve on the understanding that Todd's comment needs to be addressed first

@@ -69,7 +69,9 @@ func UsersDataSetsCreate(dataServiceContext dataService.Context) {
}

dataSet.SetUserID(&targetUserID)
dataSet.SetCreatedUserID(pointer.FromString(details.UserID()))
if details.IsUser() {
dataSet.SetCreatedUserID(pointer.FromString(details.UserID()))
Copy link
Contributor

@toddkazakov toddkazakov Feb 7, 2024

Choose a reason for hiding this comment

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

FYI, details.UserID will be set to the id of the backend client service account, which is a real user in Keycloak.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, that's not what I'm seeing. I'm getting an empty string which causes a failure during later validation (CreatedUserID of nil is fine, but an empty string is not).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll double check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

While the service session token does include the UserID of the backend client service account, it is not being used because the session token is marked as IsServer. Find the relevant code that ignores the UserID for a server session token at

result.UserID = ""
.

Comment on lines +72 to +74
if details.IsUser() {
dataSet.SetCreatedUserID(pointer.FromString(details.UserID()))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be simpler, given the validation failure, to do:

Suggested change
if details.IsUser() {
dataSet.SetCreatedUserID(pointer.FromString(details.UserID()))
}
if userID := details.UserID(); userID != "" {
dataSet.SetCreatedUserID(pointer.FromString(userID))
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Per discussions in Slack, will leave as-is. Using the system-generated user ID for service session tokens will cause downstream issues. Plus, existing platform code that references the UserID from AuthDetails checks IsUser beforehand.

- Doubled average period between Dexcom task executions from 60 minutes to 120 minutes
- Doubled task duration to account for a couple of long running errors observed in logs
- Minor changes for local debugging
@darinkrauss darinkrauss force-pushed the BACK-2866-fix-dexcom-task-issues.1 branch from 9f67aa8 to 2a425fc Compare February 7, 2024 22:45
Copy link
Contributor

@toddkazakov toddkazakov left a comment

Choose a reason for hiding this comment

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

Should .vscode/launch.json be added to gitignore? Other than that, it looks ok.

@ewollesen
Copy link
Contributor

Merging this on behalf of Darin, since this is a critical update, and Darin is OOO. Squashing as I believe that's what Darin said he normally does. Will combine commit messages in a way that makes as much sense as possible.

@ewollesen ewollesen merged commit 05c2492 into master Feb 12, 2024
2 checks passed
@darinkrauss darinkrauss deleted the BACK-2866-fix-dexcom-task-issues.1 branch June 13, 2024 04:13
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.

4 participants