-
Notifications
You must be signed in to change notification settings - Fork 155
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
Fix (*artifact.Config).Unpack not preserving not overridden values #3930
Fix (*artifact.Config).Unpack not preserving not overridden values #3930
Conversation
(*artifact.Config).Unpack was creating a new instance of Config and manually coping all values from the original to the new one. New values added to config, RetrySleepInitDuration in this case, were neither maintaining its default value nor being updated with the new value. Now it uses reflection to ensure all values are correctly copied.
Pinging @elastic/elastic-agent (Team:Elastic-Agent) |
Do we know why it was doing this? Are there any hints in the commit history? This seems intentional so I am wondering if this was because of a bug or something from the past. |
Ah the answer is the comment, thanks! |
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 is just nasty. Really sucks that this needs to be done this way. I think the way you handled it is the best way to go currently.
Really glad you added a test to ensure those structures stay inline.
Since we need to special case the transport, which includes the proxy configuration, I wonder if we should implement #3820 as part of this PR to ensure we didn't break it. It's already in the current sprint and assigned to Anderson anyway. |
This pull request is now in conflicts. Could you fix it? 🙏
|
…-artifact-config-unpack-main
buildkite test this |
Could it be something coming from your change? |
if tmpField.IsValid() && tmpField.CanSet() { | ||
tmpField.Set(cValue.Field(i)) | ||
} |
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.
You cannot be certain that tmpType.Filed(i)
and cValue.Field(i)return the equivalent fields, it is safer to use
https://pkg.go.dev/reflect#Value.FieldByName`
if tmpField.IsValid() && tmpField.CanSet() { | |
tmpField.Set(cValue.Field(i)) | |
} | |
if tmpField.IsValid() && tmpField.CanSet() { | |
tmpField.Set(cValue.FieldByName(name)) | |
} |
If you change the field ordering from configWithoutHTTPTransportSettings
and Config
, then run the test TestConfig_Unpack
it will fail.
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 catching this, this suggests there is a test case missing to catch this.
DropPath: tmp.DropPath, | ||
HTTPTransportSettings: transport, | ||
if cField.IsValid() && cField.CanSet() { | ||
cField.Set(tmpValue.Field(i)) |
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.
Same thing here
cField.Set(tmpValue.Field(i)) | |
cField.Set(tmpValue.FieldByName(name)) |
@AndersonQ will you also tackle #3820 as suggested by Craig abovE? |
Not in this PR |
buildkite test this |
|
…3930) (*artifact.Config).Unpack was creating a new instance of Config and manually coping all values from the original to the new one. New values added to config, RetrySleepInitDuration in this case, were neither maintaining its default value nor being updated with the new value. Now it uses reflection to ensure all values are correctly copied. --------- Co-authored-by: Pierre HILBERT <pierre.hilbert@elastic.co> (cherry picked from commit 1ee9cc7) # Conflicts: # NOTICE.txt # go.mod
…ot overridden values (#3979) (*artifact.Config).Unpack was creating a new instance of Config and manually coping all values from the original to the new one. New values added to config, RetrySleepInitDuration in this case, were neither maintaining its default value nor being updated with the new value. Now it uses reflection to ensure all values are correctly copied. --------- Co-authored-by: Pierre HILBERT <pierre.hilbert@elastic.co> (cherry picked from commit 1ee9cc7) --------- Co-authored-by: Anderson Queiroz <anderson.queiroz@elastic.co>
…lastic#3930) (*artifact.Config).Unpack was creating a new instance of Config and manually coping all values from the original to the new one. New values added to config, RetrySleepInitDuration in this case, were neither maintaining its default value nor being updated with the new value. Now it uses reflection to ensure all values are correctly copied. --------- Co-authored-by: Pierre HILBERT <pierre.hilbert@elastic.co>
…ot overridden values (#3979) (*artifact.Config).Unpack was creating a new instance of Config and manually coping all values from the original to the new one. New values added to config, RetrySleepInitDuration in this case, were neither maintaining its default value nor being updated with the new value. Now it uses reflection to ensure all values are correctly copied. --------- Co-authored-by: Pierre HILBERT <pierre.hilbert@elastic.co> (cherry picked from commit 1ee9cc7) --------- Co-authored-by: Anderson Queiroz <anderson.queiroz@elastic.co>
What does this PR do?
(*artifact.Config).Unpack was creating a new instance of Config and manually coping all values from the original to the new one. New values added to config, RetrySleepInitDuration in this case, were neither maintaining its default value nor being updated with the new value. Now it uses reflection to ensure all values are correctly copied.
Why is it important?
When applying a new
agent.download
config some of the default values were set to the zero value and even if they'd come on the new fleet config, they'd be ignored.Checklist
[ ] I have made corresponding changes to the documentation[ ] I have made corresponding change to the default configuration files[ ] I have added an entry in./changelog/fragments
using the changelog tool[ ] I have added an integration test or an E2E testHow to test this PR locally
Try any of the following:
TestConfig_Unpack
to main and see it failing.retry_sleep_init_duration
in the agent's policy, enrol it to fleet and check it's not set.Related issues
Questions to ask yourself