-
Notifications
You must be signed in to change notification settings - Fork 875
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…sing its id fix: change from database.StringMap to codersdk.ProvisionerKeyTags in endpoint response improve annotations for endpoint move logic to enterprise part generate new doc move logic to enterprise part generate doc
Take a look at the existing tests in |
I assume that #15505 covers part of this PR? |
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. |
for k, v := range pkDetails.Tags { | ||
displayedTags[k] = v | ||
} |
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 think we can overwrite displayedTags
here entirely. If using a provisioner key, none of the tags specified via tags
will be used to match jobs to the provisioner. (In fact, I don't think you're even allowed specify both --key
and --tag
)
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 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 ?
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.
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) |
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: This displayedTags
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) { |
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.
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?
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.
We could add a test to validate what happen in case of the client.GetProvisionerKey
failing - I've just done it.
Otherwise the logic should not be impacted and the endpoint itself seems pretty much well tested.
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'm not really understanding the point of NoProvisionerKeyFound
. 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?
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.
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)
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.
Cool, no need to change the behaviour - I was just confirming what the intent was for this test.
return xerrors.New("unable to get provisioner key details") | ||
} | ||
|
||
displayedTags = make(map[string]string, len(pkDetails.Tags)) |
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.
What is your intention here? To clear out the map if the provisioner key is set?
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.
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 in pkDetails
.
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.
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.
Seems like you should add an else
block which populates displayedTags
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 the make
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.
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.
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) { |
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'm not really understanding the point of NoProvisionerKeyFound
. 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?
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
return xerrors.New("unable to get provisioner key details") | ||
} | ||
|
||
displayedTags = make(map[string]string, len(pkDetails.Tags)) |
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.
Seems like you should add an else
block which populates displayedTags
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 the make
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.
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.