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

Add support for 'canceling' status for variant analysis #3405

Merged
merged 10 commits into from
Feb 27, 2024

Conversation

charisk
Copy link
Contributor

@charisk charisk commented Feb 26, 2024

Introduces a new 'canceling' status for variant analyses which is used to show whether we're in the middle of stoping the analysis.

Checklist

  • CHANGELOG.md has been updated to incorporate all user visible changes made by this pull request.
  • Issues have been created for any UI or other user-facing changes made by this pull request.
  • [Maintainers only] If this pull request makes user-facing changes that require documentation changes, open a corresponding docs pull request in the github/codeql repo and add the ready-for-doc-review label there.

@charisk charisk requested review from a team as code owners February 26, 2024 10:59
Copy link
Contributor

@shati-patel shati-patel left a comment

Choose a reason for hiding this comment

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

I had one question inline, but looks good otherwise! 🖼️

Is it worth adding a storybook example for the "canceling" status? 📖

Copy link
Contributor

@shati-patel shati-patel left a comment

Choose a reason for hiding this comment

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

🚢

@shati-patel
Copy link
Contributor

Oh wait, a CHANGELOG entry would indeed be helpful!

@charisk
Copy link
Contributor Author

charisk commented Feb 26, 2024

Oh wait, a CHANGELOG entry would indeed be helpful!

Cool, I'll update. BTW I won't merge until we hear back from Product. Also I'll wait in case there are more reviews.

Copy link
Contributor

@robertbrignull robertbrignull left a comment

Choose a reason for hiding this comment

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

I like the approach, but I've seen a few things in the code that don't look quite right to me. Although I haven't tried manually running the code to verify things. Have you manually tested this?

return;
}

// Maintain the canceling status if we are still canceling.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure adding this code to onVariantAnalysisUpdated is going to do what we want.

As far as I can tell this method is only called from within cancelVariantAnalysis. Once when we set the status to Canceling and once more if we want to set it back to InProgress.

So it won't help when we get updates from the monitoring job which will try to set the status to InProgress. It will also hinder us because it'll undo the change we're trying to make in the catch block of cancelVariantAnalysis.

I think instead we might want to add this logic to mapUpdatedVariantAnalysis?

What do you think? Have I understood things correctly?

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 think you're right. I did a last minute refactor here and didn't think through all the cases I had in mind on Friday.

I'm also having some trouble with testing manually atm - I seem to be testing against older versions of the code somehow. I'm either being forgetful with builds or the watcher/build is a bit off.

I'll move some logic to mapUpdatedVariantAnalysis.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops, I missed originally that we pass onVariantAnalysisUpdated into variantAnalysisMonitor.onVariantAnalysisChange, so it was called in other places. But the point still stands about when we want to set that status back when cancelation fails, so the other changes you made are still the right thing.

@charisk
Copy link
Contributor Author

charisk commented Feb 27, 2024

@shati-patel @robertbrignull this is now ready to review again. While testing I noticed a small bug around the "stats" area so I fixed that (see f0ea640).

I've also done the following manual tests:

  • Run a normal variant analysis
  • Run a variant analysis and press "Stop query"
  • Change the gh-actions-api-client.ts to always throw an error so I can simulate error when canceling, run a variant analysis and press "Stop query".

@@ -49,6 +50,7 @@ export function mapUpdatedVariantAnalysis(
VariantAnalysis,
"language" | "query" | "queries" | "databases" | "executionStartTime"
>,
currentStatus: VariantAnalysisStatus | undefined,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that I had to pass this as a separate arg instead of adding more items to Pick because we want to allow for it to be undefined for the case where we map a variant analysis submission to a variant analysis entity (L30).

I don't love how this function is shaping up in terms of args (specially with the Pick<>) but we could tidy that up a bit separately.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should rewrite the exposed interface of this file. Right now we have

mapVariantAnalysis(VariantAnalysisSubmission, ApiVariantAnalysis): VariantAnalysis
mapUpdatedVariantAnalysis(Pick<...>, ApiVariantAnalysis): VariantAnalysis

where mapVariantAnalysis depends on mapUpdatedVariantAnalysis. We could rewrite mapUpdatedVariantAnalysis to be

mapUpdatedVariantAnalysis(VariantAnalysis, ApiVariantAnalysis): VariantAnalysis

and then have a third un-exported method that can have Pick or other ugly things for its args, but it'll be an internal function and not exposed outside the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that's the sort of thing I had in mind (although I'm still not into using Pick and would rather avoid it). Let's play around that in a separate PR.

@@ -121,6 +125,7 @@ export class VariantAnalysisMonitor extends DisposableObject {

variantAnalysis = mapUpdatedVariantAnalysis(
variantAnalysis,
this.getVariantAnalysisStatus(variantAnalysis.id),
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you explain why we call getVariantAnalysisStatus(variantAnalysis.id) to fetch the status from the variant analysis manager instead of using the variantAnalysis.status value we already have?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the variantAnalysis.status we already have is one we got from the API so it won't necessarily have the "true" status (which is "canceling"). I should probably at least add a code comment to explain this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, I agree this is necessary for now, but I think it's not ideal. I'd like to look at changing it in a followup tech-debt issue.

In the code here, variantAnalysisSummary comes from the API, but the variantAnalysis variable we have here is of the internal type and has gone through mapping / processing. The problem is that it's a variable we keep within this _monitorVariantAnalysis function so it doesn't see any changes that come from outside the monitor. Previously this was fine because the monitor was the only thing that changed the variant analysis state and then it just fed data back to the manager. But now changes can come from other places and the monitor doesn't see these changes and tries to overwrite them.

Adding in getVariantAnalysisStatus works right now, but only because the status field is the only bit that's changing. It could cause problems if any other fields change in other places.

We could make it more general and fetch the whole variant analysis from the manager. We could also rewrite the monitor so it can track any changes by listening to the onVariantAnalysisStatusUpdated event from the manager.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah agree it's an area that could do with improvement. IMO it goes hand in hand with #3405 (comment).

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've added a comment. I would like to make some incremental improvements around this and the mapping functions in separate PRs, if that's okay.

@robertbrignull
Copy link
Contributor

I've also done the following manual tests:

  • Run a normal variant analysis
  • Run a variant analysis and press "Stop query"
  • Change the gh-actions-api-client.ts to always throw an error so I can simulate error when canceling, run a variant analysis and press "Stop query".

Thanks. I've done some manual testing and it's working correctly in all the cases I tried.

Copy link
Contributor

@shati-patel shati-patel left a comment

Choose a reason for hiding this comment

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

Poked it again, and things still work for me! Thanks for fixing the bug in the "Stats" header too ⚡

I'll leave @robertbrignull to re-review + approve, since he had more comments than I did 😛

Copy link
Contributor

@robertbrignull robertbrignull left a comment

Choose a reason for hiding this comment

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

I've left one optional comment on the comment, but I think the code looks fine. I had no other comments other than what I said earlier and we've decided to defer any changes there to followup issues.

@charisk charisk enabled auto-merge (squash) February 27, 2024 16:10
@charisk charisk merged commit 040c7fc into main Feb 27, 2024
15 checks passed
@charisk charisk deleted the charisk/variant-analysis-canceling-status branch February 27, 2024 16:32
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