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

fix: improve log on provisioner daemon started with pk#15588

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
defelmnq merged 19 commits intomainfromclient-provisioners-tags
Nov 25, 2024

Conversation

defelmnq
Copy link
Contributor

@defelmnqdefelmnq commentedNov 19, 2024
edited
Loading

Resolve#15126

This PR aims to fetch the provisioned key details when starting a provisioned daemon - for now in order to access the tags associated to the provisioned key and display them accordingly in the starting logs.

We do not want to change any other logic inside this PR as it was already working as expected.

@defelmnqdefelmnq changed the titlefix(cli): improve log on provisioner daemon started with pkfix: improve log on provisioner daemon started with pkNov 19, 2024
@johnstcn
Copy link
Member

cc@johnstcn I tried to think about how to test this one but am not sure to find something that makes sense.

Take a look at the existing tests inenterprise/cli/provisionerdaemonstart_test.go: in particular, tests that leverageptytest.New(inv) to assert the stdin/stdout of the command that's being invoked.

@johnstcn
Copy link
Member

I assume that#15505 covers part of this PR?

@defelmnq
Copy link
ContributorAuthor

Yeah indeed@johnstcn that's why I kept it as a draft until the other one is merged - was more to be able to validate CI & ensure its all ready.

About the tests tips thanks, currently checking.

@defelmnqdefelmnq marked this pull request as ready for reviewNovember 21, 2024 15:52
Comment on lines +118 to +120
for k, v := range pkDetails.Tags {
displayedTags[k] = v
}
Copy link
Member

@johnstcnjohnstcnNov 21, 2024
edited
Loading

Choose a reason for hiding this comment

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

I think we can overwritedisplayedTags here entirely. If using a provisioner key, none of the tags specified viatags will be used to match jobs to the provisioner. (In fact, I don't think you're evenallowed specify both--key and--tag)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I preferred to keep two different variables as otherwise it would require some other logic changes.

The tag variable is used to call the/provisionerdaemon/serve endpoint below, and using the same variable would mean changes here too, which I feel like we dont want.

wdyt ?

Copy link
Member

Choose a reason for hiding this comment

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

For the sake of correctness, I'd like to make this change.
Otherwise this may confuse future readers of the code.
However, let's do it as a separate follow-up PR.

@@ -104,6 +104,22 @@ func (r *RootCmd) provisionerDaemonStart() *serpent.Command {
return err
}

displayedTags := make(map[string]string)
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

review: ThisdisplayedTags var is merging both tags provided in the CLI and tags fetched from the provisionerKey.

@@ -294,6 +294,51 @@ func TestProvisionerDaemon_ProvisionerKey(t *testing.T) {
require.Equal(t, proto.CurrentVersion.String(), daemons[0].APIVersion)
})

t.Run("OKWithTags", func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there any sad-cases that we could be testing here?
Is there a test already (sorry, being lazy) which already checks that if a provisioner key is not defined then it will not display the tags?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

We could add a test to validate what happen in case of theclient.GetProvisionerKey failing - I've just done it.

Otherwise the logic should not be impacted and the endpoint itself seems pretty much well tested.

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 really understanding the point ofNoProvisionerKeyFound. The purpose of this PR is to add changes to tags which are logged, but AFAICS you're not looking at the outputted logs? Does the provisioner fail to start in this case?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Yeah that's exactly it - I am open to the behavior we want to apply here but globally if we can not contact the backend / retrieve the key , I returned and error and did not continued to start the provisioner.

We can instead just output an error and continue as if nothing happened - but the log will be the same as of now (without the tags)

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool, no need to change the behaviour - I was just confirming what the intent was for this test.

defelmnq reacted with thumbs up emoji
return xerrors.New("unable to get provisioner key details")
}

displayedTags = make(map[string]string, len(pkDetails.Tags))
Copy link
Contributor

Choose a reason for hiding this comment

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

What is your intention here? To clear out the map if the provisioner key is set?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

So globally, either we have no key and some tags (line 107 to 110) - either we have no key (line 112) and want to fill the displayedTags with the ones fetched inpkDetails.

That's why at first I was using the same map without allocating it , as we can't really be sure about the size before knowing in which case we'll enter
anyway, we want the map to be declared in the whole function to be used below.

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like you should add anelse block which populatesdisplayedTags if the provision key is nil?

I don't think what you have is a big deal performance-wise since maps can never shrink, so if themake call on L107 has a length of 4 and the call on L118 has a length of 2, it'll keep the originally-allocated memory.
Preallocation is not strictly necessary but it's a good practice. In this case if there's a chance we'll allocate twice then there's not much of a saving since that's what preallocation is trying to prevent.

Copy link
ContributorAuthor

@defelmnqdefelmnqNov 25, 2024
edited
Loading

Choose a reason for hiding this comment

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

tried to improve it from your feedback, was it what you had in mind ? 🙏

I basically allocate before the logic, then fill it with the tags i want based on the case - worst situation, it will reallocate with more space for the tags fetched if required.

@@ -294,6 +294,51 @@ func TestProvisionerDaemon_ProvisionerKey(t *testing.T) {
require.Equal(t, proto.CurrentVersion.String(), daemons[0].APIVersion)
})

t.Run("OKWithTags", func(t *testing.T) {
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 really understanding the point ofNoProvisionerKeyFound. The purpose of this PR is to add changes to tags which are logged, but AFAICS you're not looking at the outputted logs? Does the provisioner fail to start in this case?

Copy link
Contributor

@dannykoppingdannykopping left a comment

Choose a reason for hiding this comment

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

LGTM

return xerrors.New("unable to get provisioner key details")
}

displayedTags = make(map[string]string, len(pkDetails.Tags))
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like you should add anelse block which populatesdisplayedTags if the provision key is nil?

I don't think what you have is a big deal performance-wise since maps can never shrink, so if themake call on L107 has a length of 4 and the call on L118 has a length of 2, it'll keep the originally-allocated memory.
Preallocation is not strictly necessary but it's a good practice. In this case if there's a chance we'll allocate twice then there's not much of a saving since that's what preallocation is trying to prevent.

@defelmnqdefelmnq merged commita8becfb intomainNov 25, 2024
27 checks passed
@defelmnqdefelmnq deleted the client-provisioners-tags branchNovember 25, 2024 09:11
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@dannykoppingdannykoppingdannykopping approved these changes

@johnstcnjohnstcnjohnstcn approved these changes

Assignees

@defelmnqdefelmnq

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Correct log line when using tagged --key provisioner
3 participants
@defelmnq@johnstcn@dannykopping

[8]ページ先頭

©2009-2025 Movatter.jp