Skip to content
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

Move the newClientCfg into clientv3 package so as to be reused by both etcdctl and v3discovery #13821

Merged
merged 2 commits into from
Mar 24, 2022

Conversation

ahrtr
Copy link
Member

@ahrtr ahrtr commented Mar 18, 2022

Part of issues/13624, and it might be the last PR for this feature.

@ahrtr ahrtr force-pushed the configspec_config branch from 54dd8cd to 0419586 Compare March 18, 2022 06:18
@codecov-commenter
Copy link

codecov-commenter commented Mar 18, 2022

Codecov Report

Merging #13821 (b8104e0) into main (1b208aa) will decrease coverage by 0.22%.
The diff coverage is 65.57%.

@@            Coverage Diff             @@
##             main   #13821      +/-   ##
==========================================
- Coverage   72.63%   72.41%   -0.23%     
==========================================
  Files         467      468       +1     
  Lines       38280    38273       -7     
==========================================
- Hits        27806    27715      -91     
- Misses       8686     8752      +66     
- Partials     1788     1806      +18     
Flag Coverage Δ
all 72.41% <65.57%> (-0.23%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
etcdctl/ctlv3/command/ep_command.go 45.97% <55.00%> (+0.35%) ⬆️
client/v3/config.go 66.66% <66.66%> (ø)
etcdctl/ctlv3/command/global.go 54.40% <100.00%> (-4.27%) ⬇️
server/etcdserver/api/v3discovery/discovery.go 79.16% <100.00%> (-1.12%) ⬇️
client/v3/txn.go 73.33% <0.00%> (-26.67%) ⬇️
server/auth/simple_token.go 80.00% <0.00%> (-8.47%) ⬇️
client/v3/leasing/util.go 91.66% <0.00%> (-6.67%) ⬇️
client/v3/concurrency/mutex.go 61.64% <0.00%> (-5.48%) ⬇️
raft/rafttest/node.go 95.00% <0.00%> (-5.00%) ⬇️
server/storage/mvcc/watchable_store.go 85.50% <0.00%> (-4.35%) ⬇️
... and 13 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1b208aa...b8104e0. Read the comment docs.

@ahrtr
Copy link
Member Author

ahrtr commented Mar 18, 2022

cc @serathius @ptabor @spzala

@ahrtr ahrtr added this to the etcd-v3.6 milestone Mar 18, 2022
client/v3/config.go Outdated Show resolved Hide resolved
Copy link
Member

@serathius serathius left a comment

Choose a reason for hiding this comment

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

Love the changes and I think we should go even further with them, however we need some tests.
This code seems simple at the first glance, however it's very fragile due to complicated dependencies.

Can you add a simple set of tests for newClientCfg that guarantees we don't make unintentional changes during refactor?

@ahrtr ahrtr force-pushed the configspec_config branch from 0419586 to 48a0c8d Compare March 18, 2022 10:22
client/v3/config.go Outdated Show resolved Hide resolved
@ahrtr ahrtr force-pushed the configspec_config branch 7 times, most recently from 8e9d0ac to 42d31d8 Compare March 19, 2022 06:00
@ahrtr
Copy link
Member Author

ahrtr commented Mar 19, 2022

Added a unit test file, and all tests passed. PTAL, thanks. @serathius @spzala @ptabor

client/v3/config_test.go Outdated Show resolved Hide resolved
@serathius
Copy link
Member

Added a unit test file, and all tests passed. PTAL, thanks. @serathius @spzala @ptabor

Just to confirm, have you run the tests without the refactor to confirm that it change output?

@ahrtr ahrtr force-pushed the configspec_config branch 2 times, most recently from 97a8462 to bc91bbf Compare March 19, 2022 23:44
@ahrtr
Copy link
Member Author

ahrtr commented Mar 20, 2022

Just to confirm, have you run the tests without the refactor to confirm that it change output?

No. The function NewClientConfig has different signature as previous one newClientCfg. But both of them have the same logic, they only resolve the TLS, and all other fields should keep unchanged.

func NewClientConfig(confSpec *ConfigSpec, lg *zap.Logger) (*Config, error)
func newClientCfg(endpoints []string, dialTimeout, keepAliveTime, keepAliveTimeout time.Duration, scfg *clientv3.SecureConfig, acfg *clientv3.AuthConfig) (*clientv3.Config, error)

@ahrtr ahrtr force-pushed the configspec_config branch 3 times, most recently from d595f9b to b8104e0 Compare March 20, 2022 05:48
@ahrtr
Copy link
Member Author

ahrtr commented Mar 20, 2022

After second thought, I decided to completely remove the original newClientCfg function, because it doesn't make much sense to maintain a thin adapter.

PTAL, thanks. @serathius @spzala @ptabor

@serathius
Copy link
Member

Just to confirm, have you run the tests without the refactor to confirm that it change output?

No. The function NewClientConfig has different signature as previous one newClientCfg. But both of them have the same logic, they only resolve the TLS, and all other fields should keep unchanged.

func NewClientConfig(confSpec *ConfigSpec, lg *zap.Logger) (*Config, error)
func newClientCfg(endpoints []string, dialTimeout, keepAliveTime, keepAliveTimeout time.Duration, scfg *clientv3.SecureConfig, acfg *clientv3.AuthConfig) (*clientv3.Config, error)

Just to clarify. A good rule about refactoring code is: don't refactor code that doesn't have tests. Add a test first, refactor, update test to new code. Problem with this PR is that it combines both adding test and refactor. This means that we are loosing the benefit of testing as we cannot verify if the refactor didn't change results. Refactor still needs to be human validated.

If we are not adding the tests for the original code, I would double check the refactored code it to make sure there is no weird edge case.

@ahrtr
Copy link
Member Author

ahrtr commented Mar 21, 2022

Thanks for the comment. I agree with you in principle.

To eliminate your concern, I just added a unit test for the original newClientCfg in another PR pull/13830. Note that the unit test in both PRs are almost identical, the only difference is as below.

// in the refactor PR
cfg, err := NewClientConfig(&tc.spec, lg)

// in this PR
cfg, err := newClientCfg(tc.spec.Endpoints, tc.spec.DialTimeout, tc.spec.KeepAliveTime, tc.spec.KeepAliveTimeout, tc.spec.Secure, tc.spec.Auth)

Note that the original newClientCfg implementation is indeed fragile, so I made minor change as well. The input parameter scfg *clientv3.SecureConfig is always a non-nil value for all use cases in the code base, so we do not see any issue so far. But when I intentionally pass a nil value in the unit test, then we will see issue.

Once the PR pull/13830 is merged, I will rebase this one.

@ahrtr ahrtr force-pushed the configspec_config branch from fa7db24 to 57d82c0 Compare March 23, 2022 10:51
client/v3/config_test.go Outdated Show resolved Hide resolved
@ahrtr ahrtr force-pushed the configspec_config branch from 57d82c0 to 8089113 Compare March 23, 2022 10:53
@ahrtr
Copy link
Member Author

ahrtr commented Mar 23, 2022

Just rebased this PR. PTAL, thanks. @serathius @spzala @ptabor

client/v3/config.go Outdated Show resolved Hide resolved
@ahrtr ahrtr force-pushed the configspec_config branch from 8089113 to a1935ac Compare March 23, 2022 11:02
client/v3/config_test.go Outdated Show resolved Hide resolved
Copy link
Member

@serathius serathius left a comment

Choose a reason for hiding this comment

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

@ahrtr ahrtr force-pushed the configspec_config branch 3 times, most recently from d5c6f00 to bf6c69c Compare March 23, 2022 22:41
@ahrtr ahrtr force-pushed the configspec_config branch from bf6c69c to 49e9a14 Compare March 23, 2022 23:24
@serathius serathius merged commit 0d55a1c into etcd-io:main Mar 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants