Skip to content

PMM-15201 Correct status after change valkey in PMM admin. - #5714

Open
JiriCtvrtka wants to merge 10 commits into
mainfrom
PMM-15201-change-valkey
Open

PMM-15201 Correct status after change valkey in PMM admin.#5714
JiriCtvrtka wants to merge 10 commits into
mainfrom
PMM-15201-change-valkey

Conversation

@JiriCtvrtka

@JiriCtvrtka JiriCtvrtka commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

PMM-15201

Problem

valkey_exporter parses its command line with the standard library flag package, not
kingpin like the rest of the exporters. pmm-managed was still building its args with the
shared withLogLevel() helper, which appends --log.level=<level>. The exporter rejected
the unknown flag, printed its usage and exited with code 2 immediately after start, so the
agent ended up reported as DONE instead of RUNNING.
The bug is hit whenever a log level is stored for a Valkey exporter, i.e. both
pmm-admin inventory add agent valkey-exporter --log-level=... and
pmm-admin inventory change-agent valkey-exporter --log-level=....
On top of that, the change-agent valkey-exporter command accepted --log-level=fatal
while add agent valkey-exporter did not — valkey_exporter has no fatal level and
silently falls back to info.

Solution

  • Split withLogLevel() into a shared withLogLevelFlag() and add withValkeyLogLevel(),
    which emits --log-level=<level> for valkey_exporter. valkeyExporterConfig() now uses it.
  • A stored fatal is translated to error for Valkey (same fallback the other exporters
    without a fatal level already use), so existing agents keep working after upgrade.
  • pmm-admin inventory change-agent valkey-exporter switches from
    LogLevelFatalChangeFlags to LogLevelNoFatalChangeFlags, so --log-level=fatal is
    rejected consistently with the corresponding add agent command.

Tests

  • New managed/services/agents/log_level_test.go covering the kingpin helper (fatal
    fallback, empty level, pmm-agent older than 2.28, arg appending) and the Valkey helper
    (flag spelling and fatal fallback).
  • TestValkeyExporterConfig extended with a per-level matrix asserting --log-level= is
    produced and --log.level never is, plus a case with no log level set.
  • TestValkeyExporterChangeAgent extended with a case asserting --log-level=fatal is
    rejected by the parser.

Summary by CodeRabbit

  • Bug Fixes

    • Improved log-level handling for Valkey exporters.
    • Ensured supported log levels use the correct exporter flag format.
    • Automatically falls back from fatal to error when necessary.
    • Prevented unsupported log-level flags from being passed to older versions.
  • Tests

    • Expanded coverage for valid, invalid, unsupported, and version-dependent log-level configurations.

@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 43.53%. Comparing base (31318c7) to head (b77af62).
⚠️ Report is 87 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5714      +/-   ##
==========================================
- Coverage   43.59%   43.53%   -0.07%     
==========================================
  Files         415      303     -112     
  Lines       43134    32669   -10465     
==========================================
- Hits        18804    14222    -4582     
+ Misses      22454    16965    -5489     
+ Partials     1876     1482     -394     
Flag Coverage Δ
admin 34.96% <ø> (+0.17%) ⬆️
agent ?
managed 45.01% <100.00%> (+2.03%) ⬆️
vmproxy ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JiriCtvrtka

Copy link
Copy Markdown
Contributor Author

@copilot review

@JiriCtvrtka
JiriCtvrtka marked this pull request as ready for review July 30, 2026 16:12
@JiriCtvrtka
JiriCtvrtka requested a review from a team as a code owner July 30, 2026 16:12
@JiriCtvrtka
JiriCtvrtka requested review from 4nte, ademidoff and maxkondr and removed request for a team July 30, 2026 16:12
@ademidoff
ademidoff requested a review from Copilot July 31, 2026 12:37

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

Fixes Valkey exporter log-level argument handling so pmm-managed generates the correct flag form (--log-level=... instead of --log.level=...) and aligns pmm-admin inventory change-agent valkey-exporter log-level validation with add agent behavior, preventing valkey_exporter from exiting early and incorrectly landing the agent in DONE.

Changes:

  • Introduces a shared log-level arg helper (withLogLevelFlag) plus a Valkey-specific helper (withValkeyLogLevel) emitting --log-level=... and translating stored fatalerror.
  • Updates Valkey exporter config generation to use the Valkey-specific flag spelling.
  • Tightens pmm-admin inventory change-agent valkey-exporter to reject --log-level=fatal and adds/extends tests for the new behaviors.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
managed/services/agents/valkey.go Switch Valkey exporter arg generation to --log-level via withValkeyLogLevel.
managed/services/agents/valkey_test.go Add a per-level matrix test ensuring --log-level is used and --log.level is never emitted.
managed/services/agents/log_level.go Refactor log-level arg building into a reusable helper and add Valkey-specific behavior.
managed/services/agents/log_level_test.go New unit tests for kingpin-style and Valkey-style log level arg generation and fallback behavior.
admin/commands/inventory/change_agent_valkey_exporter.go Change CLI flags to reject fatal for Valkey exporter log level.
admin/commands/inventory/change_agent_valkey_exporter_test.go Add parser test ensuring --log-level=fatal is rejected.
Suppressed comments (1)

managed/services/agents/log_level_test.go:103

  • Same parallel subtest capture issue here: name/tc from the range loop are referenced inside a t.Parallel() subtest, which can lead to using the wrong iteration’s values. Shadow both variables inside the loop before calling t.Run.
	} {
		t.Run(name, func(t *testing.T) {
			t.Parallel()

			actual := withValkeyLogLevel(nil, tc.level, supported)
			assert.Equal(t, tc.expected, actual)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread managed/services/agents/valkey_test.go
Comment thread managed/services/agents/log_level_test.go
Keep log_level.go exporter-agnostic: the valkey flag spelling now lives at its
only call site in valkey.go. Drop the test cases that duplicated the coverage
already provided by TestValkeyExporterConfig and DefaultTimeoutUsesFlag.
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: dfdb4a66-0e53-472e-8ec9-3f25e051bd84

📥 Commits

Reviewing files that changed from the base of the PR and between 8dc3d6c and fd15603.

📒 Files selected for processing (1)
  • managed/services/agents/log_level_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • managed/services/agents/log_level_test.go

Walkthrough

The change adds reusable log-level flag construction, applies the standard --log-level flag to Valkey exporters, and rejects fatal in the Valkey exporter change command.

Changes

Valkey log-level handling

Layer / File(s) Summary
Reusable log-level flag construction
managed/services/agents/log_level.go, managed/services/agents/log_level_test.go
withLogLevelFlag supports configurable flag names, version checks, empty values, and fatal fallback. Tests cover supported and unsupported versions.
Valkey exporter flag integration
managed/services/agents/valkey.go, managed/services/agents/valkey_test.go
Valkey exporters now use --log-level. Tests cover info, fatal fallback, and omission of --log.level.
Admin command log-level restrictions
admin/commands/inventory/change_agent_valkey_exporter.go, admin/commands/inventory/change_agent_valkey_exporter_test.go
The command uses non-fatal log-level flags. Tests reject invalid and fatal values.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: 4nte, maxkondr

Poem

A rabbit checks each flag in line,
--log-level now works fine.
Fatal changes into error’s flow,
Older versions answer no.
Tests confirm the paths below.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title identifies the PMM admin Valkey status issue addressed by the changes.
Description check ✅ Passed The description clearly documents the problem, solution, affected commands, and tests, with the ticket number included.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch PMM-15201-change-valkey

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants