Skip to content

refactor(observability): extract common logging options to shared pac…#2395

Merged
k8s-ci-robot merged 1 commit intokubernetes-sigs:mainfrom
yehuditkerido:refactor/extract-logging-options
Mar 6, 2026
Merged

refactor(observability): extract common logging options to shared pac…#2395
k8s-ci-robot merged 1 commit intokubernetes-sigs:mainfrom
yehuditkerido:refactor/extract-logging-options

Conversation

@yehuditkerido
Copy link
Copy Markdown
Contributor

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.Options struct is embedded into BBR and EPP using Go's struct embedding, preserving backward compatibility while centralizing the logic.

Changes:

  • New: pkg/common/observability/logging/ with options.go, errors.go, and comprehensive tests (159 lines)
  • BBR: Removed ~45 lines of duplicated code, now embeds logging.Options
  • EPP: Removed ~43 lines of duplicated code, now embeds logging.Options

All 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

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

@yehudit1987: The label(s) kind/refactor cannot be applied, because the repository doesn't have them.

Details

In response to this:

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.Options struct is embedded into BBR and EPP using Go's struct embedding, preserving backward compatibility while centralizing the logic.

Changes:

  • New: pkg/common/observability/logging/ with options.go, errors.go, and comprehensive tests (159 lines)
  • BBR: Removed ~45 lines of duplicated code, now embeds logging.Options
  • EPP: Removed ~43 lines of duplicated code, now embeds logging.Options

All 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

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.

@k8s-ci-robot k8s-ci-robot added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Feb 23, 2026
@netlify
Copy link
Copy Markdown

netlify Bot commented Feb 23, 2026

Deploy Preview for gateway-api-inference-extension ready!

Name Link
🔨 Latest commit 94092b0
🔍 Latest deploy log https://app.netlify.com/projects/gateway-api-inference-extension/deploys/69a800755491c20008766a3a
😎 Deploy Preview https://deploy-preview-2395--gateway-api-inference-extension.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Feb 23, 2026
@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Feb 23, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

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.

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Feb 23, 2026
@nirrozenbaum
Copy link
Copy Markdown
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 23, 2026
@yehuditkerido yehuditkerido force-pushed the refactor/extract-logging-options branch 2 times, most recently from a3074ea to ba66186 Compare February 23, 2026 12:07
@nirrozenbaum
Copy link
Copy Markdown
Contributor

@elevran any chance you have capacity to review this one?
as a side note, it would probably be useful to use the same common logging options in llm-d scheduler sidecar.

Comment thread pkg/bbr/server/options.go Outdated
GRPCHealthPort: DefaultGrpcHealthPort,
LogVerbosity: logging.DEFAULT,
ZapOptions: zap.Options{Development: true},
Options: *logging.NewOptions(),
Copy link
Copy Markdown
Contributor

@nirrozenbaum nirrozenbaum Mar 3, 2026

Choose a reason for hiding this comment

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

can we name this LoggingOptions?
Options is pretty confusing here.

Suggested change
Options: *logging.NewOptions(),
LoggingOptions: *logging.NewOptions(),

Comment thread pkg/bbr/server/options.go Outdated
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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
logging.Options // Embedded logging configuration.
LoggingOptions logging.Options // Embedded logging configuration.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@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?

Copy link
Copy Markdown
Contributor

@nirrozenbaum nirrozenbaum Mar 3, 2026

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment on lines +21 to +24
var (
// ErrInvalidLogVerbosity is returned when log verbosity is negative.
ErrInvalidLogVerbosity = errors.New("log verbosity must be >= 0")
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

here it can remain Options

Comment thread pkg/common/observability/logging/options.go Outdated
Comment thread pkg/epp/server/options.go Outdated
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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ditto

Comment thread pkg/bbr/server/options.go Outdated
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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@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?

Comment thread pkg/bbr/server/options.go
PluginSpecs config.BBRPluginSpecs // Repeatable --plugin <type>:<name>[:<json>] flag values.

// internal
fs *pflag.FlagSet // FlagSet used in AddFlags() and consulted in Complete()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The current implementation works correctly, but for pattern consistency with EPP I added an fs field to BBR's Options struct as well.

Comment thread pkg/common/observability/logging/options.go Outdated
func (opts *Options) Validate() error {
// Log verbosity must be non-negative.
if opts.LogVerbosity < 0 {
return ErrInvalidLogVerbosity
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

or set to some default instead?

}
}

func TestComplete_ExplicitZapLevel(t *testing.T) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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...)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good observation on the naming. Coming from Python, the underscore convention didn't flag for me. I've changed it to the CamelCase standard.

Comment thread pkg/epp/server/options.go

// internal
fs *pflag.FlagSet // FlagSet used in AddFlags() and consulted in Complete()
fs *pflag.FlagSet // FlagSet used in AddFlags() and consulted in Validate()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Q: is there shadowing of fs here since logging.Options is embedded and has the same field name/type?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, there was shadowing. I renamed the field in LoggingOptions from fs to loggingFS to avoid confusion.

Comment thread pkg/epp/server/options.go
Comment on lines +169 to +172

// Add logging flags.
opts.Options.AddFlags(fs)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Be consistent in use of comments and empty whitespace.

Suggested change
// 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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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]>
@yehuditkerido yehuditkerido force-pushed the refactor/extract-logging-options branch from ba66186 to 94092b0 Compare March 4, 2026 09:50
@elevran
Copy link
Copy Markdown
Contributor

elevran commented Mar 4, 2026

/lgtm
leaving approval and additional feedback to @nirrozenbaum discretion.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 4, 2026
Copy link
Copy Markdown
Contributor

@nirrozenbaum nirrozenbaum left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

Thanks!

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[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

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 6, 2026
@k8s-ci-robot k8s-ci-robot merged commit a538240 into kubernetes-sigs:main Mar 6, 2026
11 checks passed
@yehuditkerido yehuditkerido deleted the refactor/extract-logging-options branch March 8, 2026 06:18
RyanRosario pushed a commit to RyanRosario/gateway-api-inference-extension that referenced this pull request Mar 9, 2026
…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]>
BizerNotNull pushed a commit to BizerNotNull/gateway-api-inference-extension that referenced this pull request Mar 15, 2026
…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]>
elevran pushed a commit to llm-d/llm-d-inference-scheduler that referenced this pull request Apr 23, 2026
…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]>
nirrozenbaum pushed a commit to llm-d/llm-d-inference-payload-processor that referenced this pull request Apr 28, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extract Common Logging Configuration to Shared Package

4 participants