-
Notifications
You must be signed in to change notification settings - Fork 24
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
Some issues with enums management in API #608
Comments
Congratulations for contributing your first flowlogs-pipeline issue |
First step / PoC for fixing netobserv#608 Starting with metrics filters only; other enums should follow
First step / PoC for fixing netobserv#608 Starting with metrics filters only; other enums should follow
First step / PoC for fixing netobserv#608 Starting with metrics filters only; other enums should follow
Hey @KalmanMeth @OlivierCazade @jpinsonneau , any thoughts to share on this? Personally I'd like to go forward for the gains it would provide (better type safety / less duplication etc.) and do the changes but I recognize there's a drawback especially wrt. the You can check this PR to see how it'd look like |
@eranra Your input would also be appreciated. |
I'm fine going that direction as soon as the doc is kept 👍 |
I agree that some of the enums are not really used in the coding and it is confusing and error-prone for the programmer. At the same time we need to clearly define the legal values used for the various parameters. I think we should strive to make the use of the enums uniform across the various stages, and at the same time include (one way or another) the possible values in the documentation. If we have a decent solution on how to document the parameter values directly from the code, then I am OK with the proposed changes. |
First step / PoC for fixing netobserv#608 Starting with metrics filters only; other enums should follow
thanks @KalmanMeth @jpinsonneau |
First step / PoC for fixing netobserv#608 Starting with metrics filters only; other enums should follow
* Enum replacement in API First step / PoC for fixing #608 Starting with metrics filters only; other enums should follow * simplify sed for docgen * Complete using new enum types * Generic transform: use same pattern as network transform
Problem description
I'm seeing several issues with the current way enums are managed in the api, making them unpractical to work with:
api.go
const), developers need to make sure these defs are always sync'ed; plus, they are sometimes referred to as CamelCase strings equivalent.enum.go
Example of usage that I find confusing:
What doc says:
How enum is defined:
This structure is sort of a hack to allow documentation and also to perform conversions via reflection. It isn't used to carry data.
Usage in yaml:
Usage in go code:
It's the usage in go code that I find very confusing: it doesn't use the documented format in strings, but uses upper camel-case instead. Moreover, it lacks of type enforcement, as it accepts any string in the switch statement, making it more bug-prone if a wrong value is provided, or in case of typo, etc.
Proposal
Instead of all of this, I wish we had just one reference point to declare enums, and make it as a type alias for better type enforcement:
We would remove:
api.go
enum.go
The downside is that we'd loose the enum values documentation. We cannot have
doc
markers on constants.An option could be to use go documentation, and add some logic to the docgen scripts to use
go doc
to extract this documentation and inject it in the api doc file:The go constants would be documented as such:
Then with
go doc -all -short -C pkg/api MetricFilterEnum
and somesed
magic, this could be reinjected intodocs/api.md
.This is not as pretty as the current implementation in terms of doc generation, but IMO we should favor code quality over this.
The text was updated successfully, but these errors were encountered: