Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
johnstcn merged 20 commits intomainfromcj/populate-provisionerdaemons
Dec 18, 2023

Conversation

johnstcn
Copy link
Member

@johnstcnjohnstcn commentedDec 14, 2023
edited
Loading

Relates to#10676

  • upsert provisioner daemons on connection
  • add heartbeats
  • update unit tests

@johnstcnjohnstcnforce-pushed thecj/populate-provisionerdaemons branch from876ee58 tob7bb176CompareDecember 15, 2023 10:02
@johnstcnjohnstcn marked this pull request as ready for reviewDecember 15, 2023 10:28
Copy link
Member

@mtojekmtojek left a 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.

q.provisionerDaemons[idx].LastSeenAt=arg.LastSeenAt
returnnil
}
returnsql.ErrNoRows
Copy link
Member

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 🤔

Copy link
MemberAuthor

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.

mtojek reacted with thumbs up emoji
Copy link
Member

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.

johnstcn reacted with thumbs up emoji
Copy link
MemberAuthor

@johnstcnjohnstcnDec 18, 2023
edited
Loading

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

mafredri reacted with heart emoji
Copy link
Member

@mtojekmtojek left a 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 👍

Comment on lines +17 to +37
// 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]=""
Copy link
MemberAuthor

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.

Copy link
MemberAuthor

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,
Copy link
MemberAuthor

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.

Copy link
Member

@mafredrimafredri left a 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
Copy link
Member

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.

johnstcn reacted with thumbs up emoji
USING btree (name,lower(coalesce(tags->>'owner','')::text));

COMMENTON INDEX idx_provisioner_daemons_name_owner_key
IS'Allow unique provisioner daemon names by user';
Copy link
Member

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 ❤️

@johnstcnjohnstcn merged commit213b768 intomainDec 18, 2023
@johnstcnjohnstcn deleted the cj/populate-provisionerdaemons branchDecember 18, 2023 16:44
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsDec 18, 2023
//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},
Copy link
Member

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?

Copy link
MemberAuthor

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

Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

@mafredrimafredrimafredri approved these changes

@mtojekmtojekmtojek approved these changes

@spikecurtisspikecurtisAwaiting requested review from spikecurtis

Assignees

@johnstcnjohnstcn

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@johnstcn@mafredri@mtojek

[8]ページ先頭

©2009-2025 Movatter.jp