[addon-operator] propagate module context to nelm logs#801
Open
diyliv wants to merge 1 commit into
Open
Conversation
Signed-off-by: diyliv <onlogn081@gmail.com>
099713c to
d582982
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Propagates module context into the nelm logging pipeline so nelm release-operation log lines consistently include a module attribute (derived from the release name), enabling log filtering by module. It also moves global nelm logger initialization to a one-time startup hook rather than implicit initialization during client construction.
Changes:
- Added a private context key + helpers and now attach
module(release name) to contexts used for nelm release operations. - Introduced
nelm.InitDefaultLogger(...)guarded bysync.Onceand invoked it during Helm client factory initialization for the Nelm backend. - Extended the nelm logger adapter to emit a
moduleattribute when present in context, and added tests for idempotent logger init + module attribute emission.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/helm/nelm/nelm.go | Adds module context helpers, propagates module-bearing context into nelm action calls, and introduces InitDefaultLogger for one-time global nelm logger setup. |
| pkg/helm/nelm/logger.go | Appends a module slog attribute (when available in context) to all nelm logger methods. |
| pkg/helm/helm.go | Initializes the global nelm logger once during Nelm backend factory setup. |
| pkg/helm/nelm/nelm_test.go | Adds tests asserting logger init idempotency / non-overriding behavior and verifying conditional module emission. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Propagate the module name into the nelm logger context so nelm log lines for release operations carry a
moduleattribute and can be filtered by module.What this PR does / why we need it
Nelm client calls (
ReleaseGet/ReleaseInstall/ReleaseUninstall/ChartRender) inpkg/helm/nelm/nelm.gowere passingcontext.TODO()/context.Background(), so the nelm logger never had amoduleattribute for these operations, making it impossible to filter nelm logs by module.Changes:
pkg/helm/nelm/nelm.gomoduleCtxKeywith helperscontextWithModule(ctx, module)/moduleFromContext(ctx).NelmClientmethods:GetReleaseLabels,LastReleaseStatus,UpgradeRelease,GetReleaseValues,GetReleaseChecksum,DeleteRelease,Render.nelmLog.Defaultinit out ofNewNelmClientinto exportedInitDefaultLogger(logger)guarded bysync.Once, so the global logger is set once at startup rather than lazily on first client construction.pkg/helm/nelm/logger.goNelmLogger.moduleAttr(ctx)returningslog.String(pkg.LogKeyModule, m)when a module is present in the context; append it to allTrace/Debug/Info/Warn/Error/*Push/InfoBlock*methods.pkg/helm/helm.gonelm.InitDefaultLogger(helmopts.Logger)once inInitHelmClientFactoryfor theNelmbackend.pkg/helm/nelm/nelm_test.goTest_NewNelmClient: assertNewNelmClientdoes not override the global nelm logger andInitDefaultLoggeris idempotent.Test_NelmLogger_ModuleFromContext: assert themoduleattribute is emitted only when present in the context.