Skip to content

PMM-15285 Remove dead supervisord event-scraping code - #5723

Open
ademidoff wants to merge 2 commits into
mainfrom
PMM-15285-remove-redundant-go-maintail
Open

PMM-15285 Remove dead supervisord event-scraping code#5723
ademidoff wants to merge 2 commits into
mainfrom
PMM-15285-remove-redundant-go-maintail

Conversation

@ademidoff

@ademidoff ademidoff commented Aug 2, 2026

Copy link
Copy Markdown
Member

Ticket number: PMM-15285

Feature build: Percona-Lab/pmm-submodules#4503

What

pmm-managed ran a goroutine that shelled out to supervisorctl maintail -f, scanned every line of supervisord's main log against eight regexes, and dispatched typed events to subscribers.

There are no subscribers. PMM-14132 (#4110) removed subscribe and UpdateRunning — the only writer to subs and the only reader of lastEvents — but left the entire producer side in place. parseStatus is likewise referenced only by its own test.

This removes managed/services/supervisord/maintail.go and its test, the Run loop, the subs/lastEvents/eventsM fields, the sub type and parseStatus, plus the call sites in managed/cmd/pmm-managed/main.go and managed/services/supervisord/devcontainer_test.go.

Beyond deleting a permanently running subprocess that feeds nothing, this drops the only place PMM depended on supervisord's log text — which would otherwise have to be ported to any process-manager replacement.

Folded-in cleanups

1. The pmm.ini TODO at managed/services/supervisord/pmm_config.go:88[unix_http_server] and [supervisorctl] are removed from the generated pmm.ini, which is what the TODO asked for.

The [supervisorctl] section was a pure duplicate of /etc/supervisord.conf. The [unix_http_server] section was not quite: besides chmod = 0700 (which is supervisord's own default) it carried the dummy credentials that enable server-side HTTP Basic auth on the control socket. Removing it alone would therefore have disabled that auth.

So the credentials are moved rather than dropped: build/ansible/roles/supervisord/tasks/main.yml now sets them on [unix_http_server] in /etc/supervisord.conf, alongside the [supervisorctl] pair already set there. Net effect is that both halves of the auth config live in one static file instead of being re-emitted into a generated per-boot file, with no behaviour change. Verified — see the comparison comment below.

2. supervisorctl argv in the encryption rotation helpers — the program name is now its own argv element.

This is not a bug fix. Verified against supervisorctl 4.2.4 in a running percona/pmm-server:3.9.0: the single-string form works, because supervisorctl rejoins its argv and re-parses through Python's cmd module. supervisorctl "stop pmm-managed" exits 0 and does stop the program. It works only by accident of that quirk and breaks under any CLI that parses argv normally, so it is a latent portability hazard, not a defect.

Verification

Feature build perconalab/pmm-server-fb:PR-4503-3385efb compared against stock percona/pmm-server:3.9.0 on a running container — identical on every probe: control-socket auth (401 without credentials, 200 with, 401 with wrong), socket mode 700 pmm:root, non-owner UID unable to connect, 10 programs RUNNING plus pmm-init EXITED, and readyz 200. Details in the comment below.

Also:

  • Config reload path exercised: 20 reload entries in pmm-managed.log, no supervisord errors or warnings.
  • Golden-file tests updated and passing; go build ./... and go vet clean.
  • Lint via --new-from-rev (what CI enforces): 0 issues. Touching the three exec.Command lines made them count as new, hence //nolint:noctx, matching the existing directive on the same call in managed/services/supervisord/supervisord.go. Threading a real context would have changed the exported RotateEncryptionKey signature — out of scope here.

TestDevContainer and TestEncryptionRotation cannot run outside the dev container and fail identically on main (they need supervisorctl on PATH, and Postgres plus a live supervisord, respectively).

Net: 370 deletions, 4 insertions across 11 files in the Go change, plus 14 lines in the ansible role.

  • API Docs updated

pmm-managed ran a goroutine that shelled out to `supervisorctl maintail -f`,
scanned every line of supervisord's main log against eight regexes and
dispatched typed events to subscribers. There were no subscribers: PMM-14132
(#4110) removed `subscribe` and `UpdateRunning`, the only writer to `subs` and
the only reader of `lastEvents`, but left the producer side in place.

Remove maintail.go and its test, the `Run` loop, the `subs`/`lastEvents`/
`eventsM` fields, the `sub` type and `parseStatus`, plus the call sites in
pmm-managed's main and the devcontainer test.

This also drops the only place PMM depended on supervisord's log text, which
would otherwise have to be ported to any process-manager replacement.

Folded in two adjacent cleanups:

- Remove [unix_http_server] and [supervisorctl] from the generated pmm.ini
  (existing TODO). Both duplicate /etc/supervisord.conf; the removed
  `chmod = 0700` is supervisord's default, verified identical (0700 pmm:root)
  on a running container built with this change.
- Pass the program name to supervisorctl as its own argv element in the
  encryption rotation helpers. This is not a live bug — supervisorctl rejoins
  its argv, so the single-string form works today — but it only works by
  accident of that quirk and breaks under any other CLI.
@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Supervisord event monitoring and status parsing were removed. Control configuration was simplified. supervisorctl arguments were separated. Application startup and the devcontainer test no longer launch the supervisord runtime loop.

Changes

Supervisord simplification

Layer / File(s) Summary
Remove event monitoring
managed/services/supervisord/maintail.go, managed/services/supervisord/maintail_test.go, managed/services/supervisord/supervisord.go, managed/services/supervisord/supervisord_test.go
The maintail parser, event subscription state, runtime loop, status parser, and related tests were removed.
Update supervisor control interface
managed/services/supervisord/pmm_config.go, build/ansible/roles/supervisord/tasks/main.yml, managed/testdata/supervisord.d/*, managed/services/encryption/encryption_rotation.go
Control sections were removed from templates and fixtures. Ansible adds dummy Unix HTTP credentials. supervisorctl now receives actions and service names as separate arguments.
Clean up startup wiring
managed/cmd/pmm-managed/main.go, managed/services/supervisord/devcontainer_test.go
Application startup and the devcontainer test no longer launch the supervisord runtime loop.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: 4nte, maxkondr

Poem

A rabbit trims the supervisor trail,
Removes old events and stale detail.
Commands hop clean with arguments wide,
While startup loops no longer hide.
Configuration rests neat and light.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.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
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.
Title check ✅ Passed The title clearly identifies the removal of dead supervisord event-scraping code, which is the main change.
Description check ✅ Passed The description includes the ticket, feature build, detailed scope, verification results, and the API documentation checklist.
✨ 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-15285-remove-redundant-go-maintail

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

@codecov

codecov Bot commented Aug 2, 2026

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5723      +/-   ##
==========================================
+ Coverage   43.59%   45.35%   +1.76%     
==========================================
  Files         415      417       +2     
  Lines       43134    43253     +119     
==========================================
+ Hits        18804    19618     +814     
+ Misses      22454    21698     -756     
- Partials     1876     1937      +61     
Flag Coverage Δ
admin 34.96% <ø> (+0.17%) ⬆️
agent 51.00% <ø> (+1.96%) ⬆️
managed 44.92% <100.00%> (+1.93%) ⬆️
vmproxy 72.22% <ø> (ø)

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.


// TODO: remove [unix_http_server] and [supervisorctl] as they duplicate supervisord.conf.
var pmmTemplate = template.Must(template.New("").Option("missingkey=error").Parse(`[unix_http_server]
chmod = 0700

@ademidoff ademidoff Aug 2, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

2 issues:

  1. these were duplicating the default values of /etc/supervisord.conf.
  2. pmm.conf is a wrong place to configure these values.

@ademidoff
ademidoff marked this pull request as ready for review August 2, 2026 18:22
@ademidoff
ademidoff requested a review from a team as a code owner August 2, 2026 18:22
@ademidoff
ademidoff requested review from 4nte, JiriCtvrtka and maxkondr and removed request for a team and JiriCtvrtka August 2, 2026 18:22
@ademidoff

ademidoff commented Aug 2, 2026

Copy link
Copy Markdown
Member Author

Updated 2026-08-02 — supersedes the original table below, which was measured before 13e79a883 moved the credentials into /etc/supervisord.conf.

Compared stock percona/pmm-server:3.9.0 against feature build perconalab/pmm-server-fb:PR-4503-3385efb, both probed on a running healthy container.

Probe Stock 3.9.0 FB PR-4503-3385efb
[unix_http_server] / [supervisorctl] in pmm.ini present, dummy/dummy absent
auth in /etc/supervisord.conf [unix_http_server] absent present
XML-RPC over socket, no credentials 401 401
XML-RPC over socket, dummy:dummy 200 200
XML-RPC over socket, wrong credentials 401 401
Control socket 700 pmm:root 700 pmm:root
/run/supervisor dir 770 pmm:root 770 pmm:root
Connect as non-owner uid 1001 cannot connect cannot connect
supervisorctl status works works
Programs 1 EXITED + 10 RUNNING 1 EXITED + 10 RUNNING
/v1/server/readyz 200 200

No observable difference. The credentials moved out of the generated per-boot pmm.ini into the static /etc/supervisord.conf; the duplication the TODO complained about is gone and auth behaviour is preserved exactly.

Probe method: curl --unix-socket /run/supervisor/supervisor.sock posting a read-only supervisor.getState XML-RPC call, rather than supervisorctl — the latter always supplies credentials from [supervisorctl], so it cannot reveal whether the server is enforcing anything.

@theTibi

theTibi commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@build/ansible/roles/supervisord/tasks/main.yml`:
- Around line 29-42: Remove the hard-coded username and password from the two
“Modify supervisord.conf” ini_file tasks. Use the repository’s approved
protected configuration mechanism for Supervisord credentials, or remove the
unix_http_server authentication options when socket permissions are the intended
access boundary.
- Around line 29-42: Remove the duplicate Supervisord control configuration
sections from pmm.ini, including the unix_http_server and supervisorctl
settings; eliminate the corresponding Modify supervisord.conf tasks rather than
maintaining overlapping entries.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 306077f8-148d-4acf-890c-c98d35cdb5ad

📥 Commits

Reviewing files that changed from the base of the PR and between dcb2ce3 and 13e79a8.

📒 Files selected for processing (1)
  • build/ansible/roles/supervisord/tasks/main.yml

Comment thread build/ansible/roles/supervisord/tasks/main.yml

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
build/ansible/roles/supervisord/tasks/main.yml (1)

29-42: 🔒 Security & Privacy | 🟠 Major

Remove the hard-coded Supervisord credentials.

These tasks write dummy as both the unix_http_server username and password. The generated configuration is world-readable, so these values do not provide a meaningful access boundary. Remove these tasks, or load credentials from the approved protected configuration mechanism if authentication is required.

As per coding guidelines, files under build/**/* must not add secrets or credentials to build scripts or Dockerfiles.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@build/ansible/roles/supervisord/tasks/main.yml` around lines 29 - 42, Remove
the two ini_file tasks that set hard-coded username and password values under
the unix_http_server section; if authentication is required, source both
credentials from the approved protected configuration mechanism instead, without
adding secrets to build configuration.

Source: Coding guidelines

🧹 Nitpick comments (1)
managed/services/encryption/encryption_rotation.go (1)

74-74: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy lift

Propagate cancellation context to supervisor commands.

Replace signal.Ignore with signal.NotifyContext, pass the context through the rotation helpers, use exec.CommandContext, and make retry waits context-aware. Remove the inline //nolint:noctx suppressions.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@managed/services/encryption/encryption_rotation.go` at line 74, Update the
encryption rotation flow to use signal.NotifyContext instead of signal.Ignore,
propagate the resulting context through the rotation helper methods, and replace
supervisor command execution with exec.CommandContext. Make retry waits honor
context cancellation, remove the inline noctx suppressions, and preserve
existing rotation behavior when the context remains active.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@build/ansible/roles/supervisord/tasks/main.yml`:
- Around line 29-42: Remove the two ini_file tasks that set hard-coded username
and password values under the unix_http_server section; if authentication is
required, source both credentials from the approved protected configuration
mechanism instead, without adding secrets to build configuration.

---

Nitpick comments:
In `@managed/services/encryption/encryption_rotation.go`:
- Line 74: Update the encryption rotation flow to use signal.NotifyContext
instead of signal.Ignore, propagate the resulting context through the rotation
helper methods, and replace supervisor command execution with
exec.CommandContext. Make retry waits honor context cancellation, remove the
inline noctx suppressions, and preserve existing rotation behavior when the
context remains active.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: cbfc99ed-a20d-4d2d-83a2-4b422fae7767

📥 Commits

Reviewing files that changed from the base of the PR and between a50c452 and 13e79a8.

📒 Files selected for processing (12)
  • build/ansible/roles/supervisord/tasks/main.yml
  • managed/cmd/pmm-managed/main.go
  • managed/services/encryption/encryption_rotation.go
  • managed/services/supervisord/devcontainer_test.go
  • managed/services/supervisord/maintail.go
  • managed/services/supervisord/maintail_test.go
  • managed/services/supervisord/pmm_config.go
  • managed/services/supervisord/supervisord.go
  • managed/services/supervisord/supervisord_test.go
  • managed/testdata/supervisord.d/pmm-ch_low_memory.ini
  • managed/testdata/supervisord.d/pmm-db_disabled.ini
  • managed/testdata/supervisord.d/pmm-db_enabled.ini
💤 Files with no reviewable changes (9)
  • managed/testdata/supervisord.d/pmm-ch_low_memory.ini
  • managed/services/supervisord/supervisord_test.go
  • managed/services/supervisord/maintail.go
  • managed/services/supervisord/devcontainer_test.go
  • managed/testdata/supervisord.d/pmm-db_enabled.ini
  • managed/cmd/pmm-managed/main.go
  • managed/testdata/supervisord.d/pmm-db_disabled.ini
  • managed/services/supervisord/maintail_test.go
  • managed/services/supervisord/supervisord.go

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