Skip to content

[addon-operator] propagate module context to nelm logs#801

Open
diyliv wants to merge 1 commit into
mainfrom
fix/nelm-module-log-context
Open

[addon-operator] propagate module context to nelm logs#801
diyliv wants to merge 1 commit into
mainfrom
fix/nelm-module-log-context

Conversation

@diyliv

@diyliv diyliv commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Overview

Propagate the module name into the nelm logger context so nelm log lines for release operations carry a module attribute and can be filtered by module.

What this PR does / why we need it

Nelm client calls (ReleaseGet/ReleaseInstall/ReleaseUninstall/ChartRender) in pkg/helm/nelm/nelm.go were passing context.TODO() / context.Background(), so the nelm logger never had a module attribute for these operations, making it impossible to filter nelm logs by module.

Changes:

  • pkg/helm/nelm/nelm.go
    • Add private moduleCtxKey with helpers contextWithModule(ctx, module) / moduleFromContext(ctx).
    • Propagate a context carrying the release name as module in all NelmClient methods: GetReleaseLabels, LastReleaseStatus, UpgradeRelease, GetReleaseValues, GetReleaseChecksum, DeleteRelease, Render.
    • Move global nelmLog.Default init out of NewNelmClient into exported InitDefaultLogger(logger) guarded by sync.Once, so the global logger is set once at startup rather than lazily on first client construction.
  • pkg/helm/nelm/logger.go
    • Add NelmLogger.moduleAttr(ctx) returning slog.String(pkg.LogKeyModule, m) when a module is present in the context; append it to all Trace/Debug/Info/Warn/Error/*Push/InfoBlock* methods.
  • pkg/helm/helm.go
    • Call nelm.InitDefaultLogger(helmopts.Logger) once in InitHelmClientFactory for the Nelm backend.
  • pkg/helm/nelm/nelm_test.go
    • Test_NewNelmClient: assert NewNelmClient does not override the global nelm logger and InitDefaultLogger is idempotent.
    • Test_NelmLogger_ModuleFromContext: assert the module attribute is emitted only when present in the context.

@diyliv diyliv changed the title propagate module context to nelm logs [addon-operator] propagate module context to nelm logs Jul 14, 2026
@diyliv diyliv self-assigned this Jul 14, 2026
@diyliv diyliv marked this pull request as draft July 14, 2026 10:02
@diyliv diyliv added bug Something isn't working go Pull requests that update Go code labels Jul 14, 2026
Signed-off-by: diyliv <onlogn081@gmail.com>

Copilot AI left a comment

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.

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 by sync.Once and invoked it during Helm client factory initialization for the Nelm backend.
  • Extended the nelm logger adapter to emit a module attribute 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.

@diyliv diyliv marked this pull request as ready for review July 14, 2026 10:47
@diyliv diyliv requested a review from ldmonster July 14, 2026 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update Go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants