- Notifications
You must be signed in to change notification settings - Fork1k
feat(coderd): insert provisioner daemons#11207
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
ee108ad
to02b6743
Compare876ee58
tob7bb176
CompareThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I haven't looked intoprovisionerdserver_test.go
yet, but I can submit some feedback now.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
q.provisionerDaemons[idx].LastSeenAt=arg.LastSeenAt | ||
returnnil | ||
} | ||
returnsql.ErrNoRows |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Is this really the same return signature the DB gives? I believe you have to check the affected rows of theExec
as it will not return an error, just zero affected rows.
I wonder if we rely on similar assumptions elsewhere in the code, seeing as the generated code doesn't check affected rows 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Other dbmem queries have very similar logic; I just copied it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Ideally we should change it so that our dbmem logic matches reality. Otherwise a developer may rely on this behavior and wonder why it doesn't work in the real world.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I'll file a follow-up issue 👍
EDIT:#11263
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Thanks for addressing my comments 👍
// Otherwise, the "owner" tag is always an empty string. | ||
// NOTE: "owner" must NEVER be nil. Otherwise it will end up being | ||
// duplicated in the database, as idx_provisioner_daemons_name_owner_key | ||
// is a partial unique index that includes a JSON field. | ||
funcMutateTags(userID uuid.UUID,tagsmap[string]string)map[string]string { | ||
iftags==nil { | ||
tags=map[string]string{} | ||
} | ||
_,ok:=tags[TagScope] | ||
if!ok { | ||
tags[TagScope]=ScopeOrganization | ||
delete(tags,TagOwner) | ||
tags[TagOwner]="" | ||
} | ||
switchtags[TagScope] { | ||
caseScopeUser: | ||
tags[TagOwner]=userID.String() | ||
caseScopeOrganization: | ||
delete(tags,TagOwner) | ||
tags[TagOwner]="" | ||
default: | ||
tags[TagScope]=ScopeOrganization | ||
tags[TagOwner]="" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
review: calling this out here -- I had assumed that the index over(name, tags["owner"])
would disallow multiple rows with("foo", NULL)
but this is apparently not the case. However, it does disallow multiple rows with("foo", "")
.
I updated to useMutateProvisionerTags
wherever possible when inserting a provisioner daemon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@mafredri helpfully pointed out that we can useCOALESCE
in the index to ensure that an absent value is treated the same as an empty string. 🎉 Adding a migration for this now.
srvCtx, | ||
api.AccessURL, | ||
id, | ||
daemon.ID, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
review: another call-out: I am now setting the ID of the provisionerd server to be the same as the provisioner daemon that was inserted into the database, instead of a random UUID as it was before.
Ibelieve this should be OK, but deferring to better judgement here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
LGTM
q.provisionerDaemons[idx].LastSeenAt=arg.LastSeenAt | ||
returnnil | ||
} | ||
returnsql.ErrNoRows |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Ideally we should change it so that our dbmem logic matches reality. Otherwise a developer may rely on this behavior and wonder why it doesn't work in the real world.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
USING btree (name,lower(coalesce(tags->>'owner','')::text)); | ||
COMMENTON INDEX idx_provisioner_daemons_name_owner_key | ||
IS'Allow unique provisioner daemon names by user'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This makes it much more clear what it's purpose is ❤️
//nolint:gocritic // This is specifically for updating the last seen at timestamp. | ||
returndb.UpdateProvisionerDaemonLastSeenAt(dbauthz.AsSystemRestricted(hbCtx), database.UpdateProvisionerDaemonLastSeenAtParams{ | ||
ID:id, | ||
LastSeenAt: sql.NullTime{Time:time.Now(),Valid:true}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Noticed this wass.timeNow()
, but turned intotime.Now()
. I suppose that's OK? Should it bedbtime.Now()
, though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Should be s.timeNow, will hotfix 👍 Thanks for the catch
Uh oh!
There was an error while loading.Please reload this page.
Relates to#10676