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

feat: Improve config generation #318

Closed
wants to merge 1 commit into from

Conversation

fmoura
Copy link
Contributor

@fmoura fmoura commented Feb 9, 2024

closes #309

@fmoura fmoura linked an issue Feb 9, 2024 that may be closed by this pull request
@fmoura fmoura requested a review from renan061 February 9, 2024 18:17
@fmoura fmoura self-assigned this Feb 9, 2024
@fmoura fmoura added the no changelog PRs that don't require changes in changelog label Feb 9, 2024
@fmoura fmoura force-pushed the feature/imporve-config-code-generation branch from d5da941 to a78d9e0 Compare February 9, 2024 18:38
@fmoura fmoura marked this pull request as ready for review February 11, 2024 13:16
Copy link
Contributor

@torives torives left a comment

Choose a reason for hiding this comment

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

This is looking great! It'll help me log the node's configs easily now in #319.

Since I had the time, I've taken the liberty to propose a few changes in #323. I suggest checking the commit messages for extra context. I'd also suggest changing the final commit message to something more descriptive, like: feat: aggregate node config in a single struct.

After the PR is merged, I'd argue we would need a follow-up issue to refactor config package into something more cohesive. The cache feature is mostly useless as it is now, for example. But that's a discussion for later 😉

@fmoura fmoura force-pushed the feature/imporve-config-code-generation branch 3 times, most recently from 0b23315 to 77d3e37 Compare February 15, 2024 05:23
This was referenced Feb 15, 2024

addLine(&doc, "<!-- markdownlint-disable MD012 -->")
//Validate envs
for i := range envs {
Copy link
Contributor

Choose a reason for hiding this comment

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

for _, env := range envs {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

as Validate sets the default value, if we use _,env we get a copy of the "Env" and the value is not correctly set. Unless we do .validate() on every loop and use this Env instance to generate that code snippet.

Copy link
Contributor

@renan061 renan061 left a comment

Choose a reason for hiding this comment

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

It seems strange to me that NodeConfig gets initialized from the environment with all its fields set. Are there no optional fields? I think this has to do with my prior comment on the RedisEndpoint.

Before, the program would explode if we required an env that was not set and had no default. But that was ok because we only called Get when the program had to explode if an env was not set and had no default.

But now we always call all gets. Won't that fail in production?

I think some fields should be *type and the constructor for NodeConfig should call
getOptional. Then we can have a (not generated) function Validate() that checks whether we have a valid node config instance.

Make sense?

@renan061
Copy link
Contributor

renan061 commented Feb 15, 2024

After the PR is merged, I'd argue we would need a follow-up issue to refactor config package into something more cohesive. The cache feature is mostly useless as it is now, for example. But that's a discussion for later 😉

I agree that we should refactor config. Not sure if we should do some of that here (like i proposed).

@fmoura fmoura marked this pull request as draft February 15, 2024 17:58
@fmoura fmoura marked this pull request as ready for review February 20, 2024 14:24
@fmoura
Copy link
Contributor Author

fmoura commented Feb 20, 2024

After some discussions we are going to merge this PR as is . The problems mentioned by @renan061 will be resolved right after on top of the issue #325

@fmoura fmoura force-pushed the feature/imporve-config-code-generation branch from 77d3e37 to 9d00b7f Compare February 20, 2024 14:30
@fmoura fmoura requested a review from renan061 February 20, 2024 14:31
@fmoura fmoura force-pushed the feature/imporve-config-code-generation branch from 9d00b7f to 311d8fa Compare February 20, 2024 19:04
@renan061
Copy link
Contributor

renan061 commented Feb 21, 2024

After some discussions we are going to merge this PR as is . The problems mentioned by @renan061 will be resolved right after on top of the issue #325

Since this PR will break the main branch*, I think it is best to merge the other config PRs on top of this branch.

And then we continue with the proposed changes.

(It breaks the main because in reader mode, the auth variables do not need to bet set. Thus, the struct initializer would panic.)

@fmoura fmoura force-pushed the feature/imporve-config-code-generation branch from 058b500 to b9a3169 Compare February 27, 2024 19:09
@fmoura fmoura requested a review from gligneul February 27, 2024 19:12
@fmoura fmoura force-pushed the feature/imporve-config-code-generation branch 4 times, most recently from 189fe65 to d862fdd Compare March 4, 2024 17:35
internal/config/config.go Show resolved Hide resolved
internal/config/config.go Show resolved Hide resolved
internal/config/validate.go Show resolved Hide resolved
internal/config/custom_get.go Outdated Show resolved Hide resolved
internal/config/config_test.go Outdated Show resolved Hide resolved
internal/config/config.go Show resolved Hide resolved
internal/config/generate/main.go Outdated Show resolved Hide resolved
internal/config/log.go Outdated Show resolved Hide resolved
@fmoura fmoura force-pushed the feature/imporve-config-code-generation branch from 35b2c80 to c19ca1b Compare March 7, 2024 04:22
@fmoura fmoura force-pushed the feature/imporve-config-code-generation branch from c19ca1b to 2c11f31 Compare March 7, 2024 04:33
@fmoura fmoura requested a review from torives March 7, 2024 05:15
Copy link
Contributor

@torives torives left a comment

Choose a reason for hiding this comment

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

After some consideration, I changed my mind about merging this PR and dealing with its implications in a follow-up issue (#325).

As we've noticed multiple times, the old design of the config package doesn't fit our current needs, and adapting it will inevitably create technical debt, something we should avoid.

Even though we've already spent a great amount of time and effort with this, I'm convinced that going back to the drawing board and creating a design from scratch that better accounts for the new requirements is a better approach.

@renan061 @gligneul

@gligneul gligneul closed this Mar 11, 2024
@fmoura fmoura deleted the feature/imporve-config-code-generation branch July 8, 2024 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no changelog PRs that don't require changes in changelog
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Improve Node Services' configuration generation
4 participants