-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Fixed issue with duration strings used in yaml config file #20360
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
base: main
Are you sure you want to change the base?
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: BBQing The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Hi @BBQing. Thanks for your PR. I'm waiting for a etcd-io member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
86887a2
to
46a9ba2
Compare
@ivanvc could you check it? |
Please refer to my comment in #20342 (comment). |
/ok-to-test |
46a9ba2
to
b0edd91
Compare
server/embed/config.go
Outdated
@@ -156,6 +156,46 @@ func init() { | |||
defaultHostname, defaultHostStatus = netutil.GetDefaultHost() | |||
} | |||
|
|||
type Duration struct { | |||
Duration time.Duration |
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 left a comment here before, but I don't know what happened as it seems like GitHub dropped it 🤔.
I suggested changing this to an anonymous field. I believe it would be transparent in cases like:
WatchProgressNotifyInterval: cfg.WatchProgressNotifyInterval.Duration,
We could revert this change.
Duration time.Duration | |
time.Duration |
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 initially had it anonymous, but then I have decided to be more explicit - I have reverted the change
Updated tests to work with wrapped duration Signed-off-by: sprochazka <[email protected]>
b0edd91
to
519616b
Compare
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 the changes, @BBQing. I must have been more explicit before with my suggestion. Apologies, again, I'm not sure why GitHub sent my comment to the void 😅
server/embed/etcd.go
Outdated
@@ -224,7 +224,7 @@ func StartEtcd(inCfg *Config) (e *Etcd, err error) { | |||
UnsafeNoFsync: cfg.UnsafeNoFsync, | |||
CompactionBatchLimit: cfg.CompactionBatchLimit, | |||
CompactionSleepInterval: cfg.CompactionSleepInterval, | |||
WatchProgressNotifyInterval: cfg.WatchProgressNotifyInterval, | |||
WatchProgressNotifyInterval: cfg.WatchProgressNotifyInterval.Duration, |
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.
With the anonymous time.Duration
field, I believe this change is no longer necessary.
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 have tried to use embed.Duration(current location) instead of time.Duration in the ServerConfig and it failed on the circular imports - I am thinking if the Duration should be placed in the pkg directory in its own package (or in some already existing package).
I'll continue with changes tomorrow. But thank you for the feedback - I am learning a lot.
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, @BBQing. I'll keep an eye on this pull request.
server/embed/config.go
Outdated
func (d Duration) String() string { | ||
return d.Duration.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.
And this is not required, either. As it would call String()
from d.Duration
.
Codecov Report❌ Patch coverage is
Additional details and impacted files
... and 163 files with indirect coverage changes @@ Coverage Diff @@
## main #20360 +/- ##
==========================================
+ Coverage 62.94% 69.20% +6.26%
==========================================
Files 386 417 +31
Lines 32989 34724 +1735
==========================================
+ Hits 20765 24031 +3266
+ Misses 10667 9300 -1367
+ Partials 1557 1393 -164 Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
Signed-off-by: sprochazka <[email protected]>
867e141
to
2bcd25a
Compare
…sing Signed-off-by: sprochazka <[email protected]>
2bcd25a
to
d7ec16e
Compare
Signed-off-by: sprochazka <[email protected]>
c83387a
to
a635dc9
Compare
Signed-off-by: sprochazka <[email protected]>
1c07ac7
to
2e78494
Compare
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 the updates, @BBQing. Please take a look at my comments :)
server/embed/config.go
Outdated
if cfg.WatchProgressNotifyIntervalJSON.Duration != 0 { | ||
cfg.WatchProgressNotifyInterval = cfg.WatchProgressNotifyIntervalJSON.Duration | ||
} |
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.
Suggestion to drop the .Duration
if cfg.WatchProgressNotifyIntervalJSON.Duration != 0 { | |
cfg.WatchProgressNotifyInterval = cfg.WatchProgressNotifyIntervalJSON.Duration | |
} | |
if cfg.WatchProgressNotifyIntervalJSON != 0 { | |
cfg.WatchProgressNotifyInterval = cfg.WatchProgressNotifyIntervalJSON | |
} |
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, I missed the casting. Thanks for adding that.
tests/framework/e2e/cluster.go
Outdated
return func(c *EtcdProcessClusterConfig) { c.ServerConfig.WatchProgressNotifyInterval = interval } | ||
return func(c *EtcdProcessClusterConfig) { | ||
c.ServerConfig.WatchProgressNotifyInterval = interval | ||
} |
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.
Could you please revert this change?
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.
fixed
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 :)
server/embed/config_duration.go
Outdated
"time" | ||
) | ||
|
||
type Duration struct { |
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 should be named ConfigDuration
if the filename is config_duration.go
.
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 change that
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!
server/embed/config.go
Outdated
WatchProgressNotifyInterval time.Duration | ||
WatchProgressNotifyIntervalJSON Duration `json:"watch-progress-notify-interval"` |
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 was the issue of keeping a single field?
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.
The problem for me was, that in the downstream the value is compared to some time.Duration constant (minimal watch progress interval - I could have retyped the constant into the new Duration type, but I think since the functionality of the wrapper type is related to configuration, it should remain there and not leak outside. So I have decided to follow approach used for different configuration fields, that also require some special treatment. beyond the standard unmarshalling
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.
Makes sense, thanks for the clarification. Let's see what other contributors think :)
…d Duration to ConfigDuration Signed-off-by: sprochazka <[email protected]>
Thanks for the contribution, but please see my comment #20342 (comment) |
Relates: #20342
Please read https://github.com/etcd-io/etcd/blob/main/CONTRIBUTING.md#contribution-flow.
This is a proposal on how to fix the issue. the problem is, that for the parameter --watch-progress-notify-interval, there is a difference in the behavior. While it is accepted as duration string from CLI, when provided in config_file, it has to be a number, that then gets converted into nanoseconds so for example for 1s you have to use 1000000000. Although it works well for machines it's bad for humans.
I have wrapped the time.duration, so that I can implement the UnmarshalJSON interface and also I have implemented flag.Value interface. And applied it where necessary.
I have also fixed some tests.
The fix supports both numbers and duration string from config file and in the future there can be issued warning, in case it will be decided to abandon the possibility to use numbers in the configuration.
It might be necessary to do this for every duration parameter in the future.
I guess this concerns etcdserver.