refactor(observability): extract common logging options to shared pac…#2395
Conversation
|
@yehudit1987: The label(s) DetailsIn response to this:
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. |
✅ Deploy Preview for gateway-api-inference-extension ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Hi @yehudit1987. Thanks for your PR. I'm waiting for a kubernetes-sigs 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. DetailsInstructions 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. |
|
/ok-to-test |
a3074ea to
ba66186
Compare
|
@elevran any chance you have capacity to review this one? |
| GRPCHealthPort: DefaultGrpcHealthPort, | ||
| LogVerbosity: logging.DEFAULT, | ||
| ZapOptions: zap.Options{Development: true}, | ||
| Options: *logging.NewOptions(), |
There was a problem hiding this comment.
can we name this LoggingOptions?
Options is pretty confusing here.
| Options: *logging.NewOptions(), | |
| LoggingOptions: *logging.NewOptions(), |
| EnablePprof bool // Enables pprof handlers. | ||
| SecureServing bool // Enables secure serving. | ||
| MetricsEndpointAuth bool // Enables authentication and authorization of the metrics endpoint. | ||
| logging.Options // Embedded logging configuration. |
There was a problem hiding this comment.
| logging.Options // Embedded logging configuration. | |
| LoggingOptions logging.Options // Embedded logging configuration. |
There was a problem hiding this comment.
@nirrozenbaum what's the benefit of not embedding? Won't this require a larger refactor of the options.go in EPP and BBR since would need to indirect via LoggingOptions.field vs just field?
There was a problem hiding this comment.
I'm ok with embedding, no benefit of not embedding.
just wanted to highlight that when embedding, the way to use it is by opts.Options, and that's very unclear that it actually holds the logging options.
if we name the struct in logging package as logging.LoggingOptions that would solve the issue (can embed without it being confusing)
There was a problem hiding this comment.
if we name the struct in logging package as logging.LoggingOptions
that would create struttering in the full type name and is often discouraged. logging.Options seems fine to me.
| var ( | ||
| // ErrInvalidLogVerbosity is returned when log verbosity is negative. | ||
| ErrInvalidLogVerbosity = errors.New("log verbosity must be >= 0") | ||
| ) |
There was a problem hiding this comment.
can we move this var to logging/options.go?
it's strongly related to logging options and doesn't seem to worth a separated file for it.
| ) | ||
|
|
||
| // Options contains logging configuration for command-line flags. | ||
| type Options struct { |
There was a problem hiding this comment.
here it can remain Options
| EnableCertReload bool // Enables certificate reloading of the certificates specified in --cert-path. | ||
| SecureServing bool // Enables secure serving. | ||
| MetricsEndpointAuth bool // Enables authentication and authorization of the metrics endpoint. | ||
| logging.Options // Embedded logging configuration. |
| EnablePprof bool // Enables pprof handlers. | ||
| SecureServing bool // Enables secure serving. | ||
| MetricsEndpointAuth bool // Enables authentication and authorization of the metrics endpoint. | ||
| logging.Options // Embedded logging configuration. |
There was a problem hiding this comment.
@nirrozenbaum what's the benefit of not embedding? Won't this require a larger refactor of the options.go in EPP and BBR since would need to indirect via LoggingOptions.field vs just field?
| PluginSpecs config.BBRPluginSpecs // Repeatable --plugin <type>:<name>[:<json>] flag values. | ||
|
|
||
| // internal | ||
| fs *pflag.FlagSet // FlagSet used in AddFlags() and consulted in Complete() |
There was a problem hiding this comment.
IIRC, the FlagSet is saved once and then used in other functions. Perhaps to facilitate testing which can use multiple sets to options and not use the "global" commandline set.
I did not implement the BBR options so I might be confusing with the EPP options.
Regardless, it should continue to work as long as we use embedding for logging.Options.
There was a problem hiding this comment.
The current implementation works correctly, but for pattern consistency with EPP I added an fs field to BBR's Options struct as well.
| func (opts *Options) Validate() error { | ||
| // Log verbosity must be non-negative. | ||
| if opts.LogVerbosity < 0 { | ||
| return ErrInvalidLogVerbosity |
There was a problem hiding this comment.
or set to some default instead?
| } | ||
| } | ||
|
|
||
| func TestComplete_ExplicitZapLevel(t *testing.T) { |
There was a problem hiding this comment.
nits:
- consider moving this into the previous function so it can share the setup. Seems like could benefit from table-driven tests as in
TestValidate()below. - is use of
_in test name a common practice? Curiosity, not change request (unless it is non-standard...)
There was a problem hiding this comment.
Good observation on the naming. Coming from Python, the underscore convention didn't flag for me. I've changed it to the CamelCase standard.
|
|
||
| // internal | ||
| fs *pflag.FlagSet // FlagSet used in AddFlags() and consulted in Complete() | ||
| fs *pflag.FlagSet // FlagSet used in AddFlags() and consulted in Validate() |
There was a problem hiding this comment.
Q: is there shadowing of fs here since logging.Options is embedded and has the same field name/type?
There was a problem hiding this comment.
Yes, there was shadowing. I renamed the field in LoggingOptions from fs to loggingFS to avoid confusion.
|
|
||
| // Add logging flags. | ||
| opts.Options.AddFlags(fs) | ||
|
|
There was a problem hiding this comment.
Be consistent in use of comments and empty whitespace.
| // Add logging flags. | |
| opts.Options.AddFlags(fs) | |
| opts.Options.AddFlags(fs) // add logging flags. |
question/observation: part of the reuse implies that EPP and BBR must use the same logging options and deprecate atthe same time? I don't see a case where this is not happening, but something to be aware of.
Can we independently deprecate in EPP or in BBR?
There was a problem hiding this comment.
You're right - independent deprecation would need extra handling. But I think the trade-off is worth it. We're avoiding significant duplication (~90 lines) for functionality that should be consistent across components. If we ever need component-specific logging changes, we can handle them after calling AddFlags().
…kage EPP and BBR duplicated logging configuration code. Extract to pkg/common/observability/logging for reusability and consistent behavior across components. Signed-off-by: Yehudit Kerido <[email protected]>
ba66186 to
94092b0
Compare
|
/lgtm |
nirrozenbaum
left a comment
There was a problem hiding this comment.
/lgtm
/approve
Thanks!
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: nirrozenbaum, yehuditkerido The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
…kage (kubernetes-sigs#2395) EPP and BBR duplicated logging configuration code. Extract to pkg/common/observability/logging for reusability and consistent behavior across components. Signed-off-by: Yehudit Kerido <[email protected]>
…kage (kubernetes-sigs#2395) EPP and BBR duplicated logging configuration code. Extract to pkg/common/observability/logging for reusability and consistent behavior across components. Signed-off-by: Yehudit Kerido <[email protected]>
…kage (kubernetes-sigs/gateway-api-inference-extension#2395) EPP and BBR duplicated logging configuration code. Extract to pkg/common/observability/logging for reusability and consistent behavior across components. Signed-off-by: Yehudit Kerido <[email protected]>
…kage (kubernetes-sigs/gateway-api-inference-extension#2395) EPP and BBR duplicated logging configuration code. Extract to pkg/common/observability/logging for reusability and consistent behavior across components. Signed-off-by: Yehudit Kerido <[email protected]>
What type of PR is this?
/kind cleanup
/kind refactor
What this PR does / why we need it:
Extracts duplicated logging configuration code from BBR and EPP into a shared package at
pkg/common/observability/logging/, eliminating ~90 lines of code duplication.Both components had identical implementations for managing logging options (verbosity, zap configuration, validation). The new shared
logging.Optionsstruct is embedded into BBR and EPP using Go's struct embedding, preserving backward compatibility while centralizing the logic.Changes:
pkg/common/observability/logging/withoptions.go,errors.go, and comprehensive tests (159 lines)logging.Optionslogging.OptionsAll existing functionality preserved (default verbosity, flag behavior, validation). All tests pass including BBR/EPP integration tests.
Which issue(s) this PR fixes:
Fixes #2378
Does this PR introduce a user-facing change?:
None