fix(metricprovider): respect --logformat json for metric plugin process logger - #5000
sujanchalla0510 wants to merge 1 commit into
Conversation
…ss logger The metric provider plugin client (metricproviders/plugin/client/client.go) constructed its go-plugin ClientConfig without setting Logger, so go-plugin always fell back to its own hardcoded unstructured-text hclog logger for the plugin's handshake/lifecycle logs and stderr relay - regardless of the controller's own --logformat setting. When the controller is run with --logformat json, every other component logs JSON except metric plugin logs, which stay plain text and can't be parsed the same way downstream. Add newPluginLogger(), which mirrors the controller's own logrus formatter: when the standard logger is configured with logrus.JSONFormatter, build an hclog.Logger with JSONFormat: true (keeping go-plugin's other defaults - Trace level, "plugin" name, DefaultOutput - unchanged); otherwise return nil so go-plugin's own default logger is used exactly as before, preserving existing behavior for the common (non-JSON) case. Fixes argoproj#4408 Signed-off-by: Sujan Reddy <sujanchalla0510@gmail.com>
3968eda to
ec0584f
Compare
|
Published E2E Test Results 4 files 4 suites 4h 10m 58s ⏱️ For more details on these failures, see this check. Results for commit ec0584f. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5000 +/- ##
==========================================
+ Coverage 85.15% 85.17% +0.01%
==========================================
Files 166 166
Lines 19453 19465 +12
==========================================
+ Hits 16566 16580 +14
+ Misses 2032 2031 -1
+ Partials 855 854 -1
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:
|
Published Unit Test Results2 628 tests 2 628 ✅ 3m 29s ⏱️ Results for commit ec0584f. |



Problem
Fixes #4408.
The metric provider plugin client (
metricproviders/plugin/client/client.go) builds itsgo-pluginClientConfigwithout ever settingLogger:hashicorp/go-plugin's ownStart()explicitly falls back to its own hardcoded, unstructuredhcloglogger wheneverLoggerisnil:This means every log line related to the metric plugin's handshake/lifecycle, and the relayed stderr of the plugin subprocess itself, is always emitted in
go-plugin's own fixed text format (argo-rollouts 2025-08-18T09:53:56.003Z [DEBUG] plugin.my-plugin: ...) — regardless of the controller's own--logformat jsonflag. Every other controller log line respects--logformat; this is the one place that doesn't, which breaks structured-log parsing/ingestion pipelines built around the controller's JSON output.Verification the bug is real and current
Confirmed directly against current
master(4e6a27986, 2026-08-25):metricproviders/plugin/client/client.go'sClientConfigliteral has noLoggerfield, exactly as described in the issue.go-plugin(v1.8.0, this repo's current pinned version) still has theif config.Logger == nil { ... }fallback quoted above (hashicorp/go-plugin@v1.8.0/client.go:417).git log -- metricproviders/plugin/client/client.goshows no related change).Loggerset) also exists inrollout/trafficrouting/plugin/client/client.goandrollout/steps/plugin/client/client.go, which are out of scope for this PR — it's scoped narrowly to the metric provider plugin client, matching the issue title/report. Happy to open follow-up PRs for the other two plugin types if maintainers want the same treatment there.Fix
Added
newPluginLogger()(and a testablenewPluginLoggerWithOutput()helper) inmetricproviders/plugin/client/client.go:logruslogger is configured withlogrus.JSONFormatter(i.e. the controller was started with--logformat json, whichcmd/rollouts-controller/main.goapplies vialog.SetFormatter(...)on the same package-levellogrusstandard logger), build anhclog.LoggerwithJSONFormat: true, keeping every other option (Tracelevel,"plugin"name,hclog.DefaultOutput) identical togo-plugin's own default so nothing else about the logger's behavior changes.nil, which is exactly what was passed implicitly before this change —go-pluginfalls back to its own default (unstructured) logger, so behavior for the default/text-format case (the overwhelming majority of current deployments) is completely unchanged.This is a minimal, additive, non-breaking change: it only changes plugin logger output format, never plugin behavior, and only takes effect when the operator has already opted into
--logformat json.Test
Added
metricproviders/plugin/client/client_test.go(this package had no test file at all before this PR):newPluginLogger()returnsnilwhen the controller's logger is the defaultlogrus.TextFormatter— preservinggo-plugin's own default logger.newPluginLoggerWithOutput()(used to capture output without writing to the realhclog.DefaultOutput/stderr in the test) returns a non-nil logger that emits a single valid JSON object per log line when the controller's logger islogrus.JSONFormatter, verified by unmarshaling the captured output and asserting the@messagefield.Revert-and-reconfirm proof: reverted
metricproviders/plugin/client/client.goalone (kept the new test file andgo.mod) and re-ran the test:Restored the fix and confirmed:
Full verification before submission:
go build ./...— clean.go vet ./...— clean.go test ./metricproviders/...— all packages pass except a pre-existing, unrelated failure inmetricproviders/datadog(TestRunSuite/TestRunSuiteV2), which I confirmed also fails identically on unmodifiedupstream/masterbefore this change (JSON error-message field-casing mismatch, apparently due to a newer Go toolchain's stdlibencoding/jsonerror text in my local environment — unrelated to this PR's package).gofmt -l metricproviders/plugin/client/— no output (clean).Scope note
go.modmovesgithub.com/hashicorp/go-hclogfrom an indirect to a direct requirement (it was already present transitively viago-plugin, version unchanged atv1.6.3) since this PR now imports it directly. No other dependency changes.