Skip to content

feat: add force refresh of license entitlements #9155

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

Merged
merged 10 commits into from
Aug 22, 2023

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented Aug 17, 2023

Closes #8665

What this does

  • When Coderd shuts down, it sends a message on the PubsubEventLicenses pubsub to force a new entitlement update on other Coderds. This should update the replica count and remove the warning. This should fix things without any intervention.
  • Added a force refresh entitlements api call. It is a solution to waiting 10 minutes, so should not be used very often.
    • I added this button because other entitlement type issues might exist, and waiting 10 minutes is kinda annoying. Especially in dev type environments. This refresh api call does not hurt anything, so I feel it is ok to have as a backup.

Abuse prevention

I prevent force refreshing more than once per minute

{
   "message":"Entitlements already recently refreshed, please wait 15 seconds to force a new refresh",
   "detail":"Last refresh at 2023-08-17 20:41:28.89935887 +0000 UTC"
}

Manual Refresh

@BrunoQuaresma thoughts?

Peek.2023-08-17.16-56.webm

@Emyrk Emyrk marked this pull request as ready for review August 18, 2023 14:58
Copy link
Member

@deansheather deansheather left a comment

Choose a reason for hiding this comment

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

BE LGTM 👍

err = api.Pubsub.Publish(PubsubEventLicenses, []byte("refresh"))
if err != nil {
api.Logger.Error(context.Background(), "failed to publish forced entitlement update", slog.Error(err))
// don't fail the HTTP request, since we did write it successfully to the database
Copy link
Member

Choose a reason for hiding this comment

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

I think you should still fail the request if it fails to notify other replicas to update

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok 👍

<Button
onClick={() => {
if (refreshEntitlements) {
if (refreshEntitlements()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this in an if?

Copy link
Member Author

Choose a reason for hiding this comment

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

If it isn't null, I do not want to call a null function.

Copy link
Member

Choose a reason for hiding this comment

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

Could you do if (!!refreshEntitlements && refreshEntitlements())

onClick={() => {
if (refreshEntitlements) {
if (refreshEntitlements()) {
displaySuccess("Successfully refreshed licenses")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sending an event is not a sync operation so does not make too much sense to display this message here. Since you are using XState for that, you could do:

  • Call the refreshEntitlements function
  • In the refresh button, add a prop loading={...}

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, ngl I was not sure exactly how to get this done

Copy link
Member Author

Choose a reason for hiding this comment

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

@BrunoQuaresma can I merge this and then we improve it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeap!

@Emyrk Emyrk merged commit 262d769 into main Aug 22, 2023
@Emyrk Emyrk deleted the stevenmasley/entitlement_refresh branch August 22, 2023 14:26
@github-actions github-actions bot locked and limited conversation to collaborators Aug 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

License Issue Banner Shows up in Error
3 participants