PMM-1519 Change QAN-PGSM fix for internal error. - #5703
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5703 +/- ##
==========================================
+ Coverage 43.59% 45.19% +1.59%
==========================================
Files 415 218 -197
Lines 43134 27858 -15276
==========================================
- Hits 18804 12590 -6214
+ Misses 22454 13919 -8535
+ Partials 1876 1349 -527
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@copilot review |
|
@copilot review |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
WalkthroughThe change adds tri-state boolean environment lookup and moves internal PostgreSQL QAN environment enforcement into the transactional agent-change flow. Rejected enablement changes roll back. Tests cover routing, rollback, allowed updates, and invalid values. ChangesInternal PostgreSQL QAN guard
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant ChangeQANPostgreSQLPgStatementsAgent
participant executeAgentChange
participant checkInternalPgQANEnvOverride
participant env.LookupBool
ChangeQANPostgreSQLPgStatementsAgent->>executeAgentChange: request agent change
executeAgentChange->>checkInternalPgQANEnvOverride: validate internal QAN enablement
checkInternalPgQANEnvOverride->>env.LookupBool: read PMM_ENABLE_INTERNAL_PG_QAN
env.LookupBool-->>checkInternalPgQANEnvOverride: parsed state or nil
checkInternalPgQANEnvOverride-->>executeAgentChange: allow or failed-precondition error
executeAgentChange-->>ChangeQANPostgreSQLPgStatementsAgent: commit result or rollback error
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
PMM-15191
What is done
Reworks the guard that protects the QAN agent of PMM's internal PostgreSQL server when its
enabled state is pinned by the
PMM_ENABLE_INTERNAL_PG_QANenvironment variable.The previous implementation lived at the end of
ChangeQANPostgreSQLPgStatementsAgent, afterexecuteAgentChangehad already committed the update. It had several problems:had been committed, so the caller saw a failure while the agent had already been modified.
Change*Agentmethod from the requestpayload, not from the type of the agent being changed, so pointing any other
Change*Agentmethod at the internal QAN agent skipped the check entirely.
pmm_agent_id, so any change to any agentrunning under PMM Server's pmm-agent (postgres_exporter, node_exporter, vmagent, ...) was
refused with a message about QAN. Changes unrelated to the enabled state (e.g. custom labels,
max query length) were refused as well.
PMM_ENABLE_INTERNAL_PG_QAN=falsebehaved like a pin too, because the value was onlychecked for being non-empty, and the raw string was interpolated into the error message.
New behaviour
checkInternalPgQANEnvOverridenow runs insideexecuteAgentChange, on the updated agent row andbefore the transaction is committed, so a rejected request rolls back and leaves the agent
untouched. It rejects a request only when all of the following hold:
enableis set),qan_postgresql_pgstatements_agentbelonging to PMM Server's pmm-agent,PMM_ENABLE_INTERNAL_PG_QANparses as a boolean and the requested state differs from it.Everything else stays changeable, and a non-boolean value in the variable pins nothing (invalid
values are already reported by the env parser during startup).
Also adds
env.LookupBool, which returns*boolso callers can tell "not configured" apart from"configured as false";
env.GetBoolis now a thin wrapper over it.Tests
managed/services/inventory/agents_test.gocovers the guard: rejection leaves the agent intact,rejection also happens when the change is requested through the params of another agent type, and
requests are accepted for parameters unrelated to the enabled state, when the requested state
matches the variable, for QAN agents outside of PMM Server, for other agent types of PMM Server,
and when the variable holds a non-boolean value.
Summary by CodeRabbit