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

server/embed: address golangci var-naming issues #17674

Merged

Conversation

ivanvc
Copy link
Member

@ivanvc ivanvc commented Mar 30, 2024

Addresses issues with config.{TLSMinVersion,TLSMaxVersion,WALDir,MaxWALFiles}.

This is part 1 of 2 from server/embed, as it's the package with the most changes.

Part of #17578.

Please read https://github.com/etcd-io/etcd/blob/main/CONTRIBUTING.md#contribution-flow.

@ivanvc ivanvc mentioned this pull request Mar 30, 2024
20 tasks
server/embed/config.go Outdated Show resolved Hide resolved
@ivanvc ivanvc force-pushed the address-server-embed-var-naming-lint-rule branch 4 times, most recently from 4bd3d28 to 9ff9462 Compare April 2, 2024 00:30
@ivanvc
Copy link
Member Author

ivanvc commented Apr 2, 2024

/retest

@ivanvc ivanvc force-pushed the address-server-embed-var-naming-lint-rule branch 3 times, most recently from 448f511 to 87bea43 Compare April 4, 2024 17:51
Copy link
Member

@ahrtr ahrtr left a comment

Choose a reason for hiding this comment

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

LGTM

Thanks @ivanvc

@ahrtr
Copy link
Member

ahrtr commented Apr 5, 2024

cc @fuweid @jmhbnz @serathius

Copy link
Member

@jmhbnz jmhbnz left a comment

Choose a reason for hiding this comment

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

LGTM - Thanks @ivanvc

@serathius
Copy link
Member

I don't think it's worth to be pedantic to complicate the config struct so much. If this is a blocker for enabling var-naming on whole repo, we should just exclude this file.

@ahrtr
Copy link
Member

ahrtr commented Apr 6, 2024

I don't think it's worth to be pedantic to complicate the config struct so much. If this is a blocker for enabling var-naming on whole repo, we should just exclude this file.

  • Overall it isn't that complicated; this PR follows the same pattern to handle the 4 fields in Config struct. It is super clear and easy to understand.
  • It's also backward compatible change.
  • I won't insist on merging this PR if majority maintainers &members are against it, but I still think we should welcome & open to such change which improves readability, although it's minor.

@serathius
Copy link
Member

but I still think we should welcome & open to such change which improves readability, although it's minor.

For me using linters like var-naming is not about readability, it's about code style consistency. Don't have strong preference about WALDir vs WalDir. However, duplicating fields definitely reduces readability.

@ahrtr
Copy link
Member

ahrtr commented Apr 6, 2024

For me using linters like var-naming is not about readability, it's about code style consistency.

Making code style consistent is part of readability.

However, duplicating fields definitely reduces readability.

It's a temporary solution to make the change backward compatible. We will remove one of them in 3.7. Also @ivanvc has been already following the same pattern in previous PRs.

Again, overall not a big problem, doesn't worth too much getting stuck on this. defer to majority maintainers & member's opinions.

@ivanvc ivanvc force-pushed the address-server-embed-var-naming-lint-rule branch from 87bea43 to 3631f3e Compare April 6, 2024 15:27
@ivanvc
Copy link
Member Author

ivanvc commented Apr 6, 2024

As the author of these Pull Requests, I left these changes as the last ones, as I felt they were the most controversial (and the decision agreed in this PR will impact follow-up PRs on other config fields with inconsistent naming). This time, getting to a position in which the change is backward compatibility was the most intricate. I initially suggested doing a linter ignore for these. Still, I think that if we don't deprecate the variable names now, it's improbable that we'll rename them later in another release without prior deprecation.

I think applying the linter rule helps with code style consistency and gives internal (and external) developers a better experience. For example, with the current state of the code (and inconsistencies with naming Wal and WAL), this could be potentially an end-user code that has an embedded etcd:

if cfg.MaxWalFiles != embed.DefaultMaxWALFiles {
  ...
}

Developers with an IDE may not have an issue with the naming, but it may not be very pleasant in other scenarios.

I'm advocating for enabling var-naming to have a more mature and formal naming for internal and external developers. It'd be good to hear from others and @fuweid, who worked to enable linter rules in the past.

Copy link
Member

@fuweid fuweid left a comment

Choose a reason for hiding this comment

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

+1 for this change. We don't break command line interface and I believe it's good timing to do clean up. Yes, it needs some effort to maintain two fields. We can consider to add UT to cover that.

NOTE: When I re-enable lint, I just want to focus on existing lint and keep the change in small.

server/embed/config.go Outdated Show resolved Hide resolved
@ivanvc ivanvc force-pushed the address-server-embed-var-naming-lint-rule branch from 3631f3e to 786023b Compare April 9, 2024 19:13
@ivanvc
Copy link
Member Author

ivanvc commented Apr 9, 2024

@ahrtr, do we want any other team members to chime on this? Please cc who you think should have an opinion on this. Thanks.

@ahrtr
Copy link
Member

ahrtr commented Apr 13, 2024

@serathius can we merge this PR?

@serathius
Copy link
Member

serathius commented Apr 14, 2024

I don't like the change as it's the most controversial from all static analysis changes. It duplicates fields on user facing config which complicates the code and user interface. I wanted to discuss it further make sure we are not overzealous and just apply linters blindly. Making change now means we are committing to a new API, that we won't be able to clean up anytime soon. And for what benefit? Just because we didn't want to put //nolint:var-naming comment before a variable name. v3.7 will not come anytime soon.

Nonetheless, the change is don't I will block the change if community supports it. @ahrtr feel free to merge if you think it's benefitial.

@ahrtr
Copy link
Member

ahrtr commented Apr 15, 2024

v3.7 will not come anytime soon.

Actually I am not insist on merging this PR. Due to bad maintenance history, each etcd minor release is actually a LTS version. If we have the same release cadence as K8s, e.g. a minor release each 3 ~ 4 months, then I will merge this PR. But the reality is we may release 3.7 at least 3+ years later based on the etcd release history.

@ivanvc So let's disable the linter for the fields in Config. Thanks for your work and sorry for the confusion.

Addresses issues in TLSMinVersion, TLSMaxVersion, WALDir, and
MaxWALFiles.

Signed-off-by: Ivan Valdes <[email protected]>
@ivanvc ivanvc force-pushed the address-server-embed-var-naming-lint-rule branch from 786023b to 0a1bc12 Compare April 17, 2024 22:34
@@ -57,7 +57,7 @@ func TestConfigFileMemberFields(t *testing.T) {
yc := struct {
Dir string `json:"data-dir"`
MaxSnapFiles uint `json:"max-snapshots"`
MaxWalFiles uint `json:"max-wals"`
MaxWALFiles uint `json:"max-wals"`
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a struct exclusively used in this test case. It tests that marshaling the JSON fields works as expected, feeding it as a YAML config file. So, it should be fine to rename this field

Copy link
Member

Choose a reason for hiding this comment

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

Right

@ivanvc ivanvc requested a review from ahrtr April 17, 2024 23:06
@ivanvc
Copy link
Member Author

ivanvc commented Apr 17, 2024

@serathius, @ahrtr PTAL 🙏

Copy link
Member

@ahrtr ahrtr left a comment

Choose a reason for hiding this comment

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

LGTM

Thank you !

@serathius serathius merged commit d492b41 into etcd-io:main Apr 18, 2024
44 checks passed
@ivanvc ivanvc deleted the address-server-embed-var-naming-lint-rule branch April 18, 2024 07:10
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.

5 participants