Repository navigation
fix(logging): clear the selector sampler override when its handle is emptied (#7750) - #7766
Conversation
Aias00
left a comment
There was a problem hiding this comment.
LGTM. Small change, but I checked the two things that would make it silently wrong.
Evidence
- Key symmetry:
handlerSelectorstores withSELECT_API_CONFIG_MAP.put(selectorData.getId(), ...)(AbstractLogPluginDataHandler.java:139) andremoveSelectorremoves with the same key (:146), soremove(selectorData.getId())in the empty branch is literally the same operation as the existing delete path. - The fallback chain the issue depends on exists:
LogCollectConfigUtils.isSampled(:106-113) prefersgetSelectApiConfigMap().get(selectorData.getId()), then falls back togetPluginGlobalConfigMap().get(selectorData.getPluginId()), thentrue. Dropping the entry therefore restores global sampling rather than disabling logging. getSelectApiConfigMap()already existed in master, so the test needs no API widening, and it clears the static maps in@AfterEach— correct hygiene for singleton state.
Non-blocking
- The empty-handle branch now has a side effect.
handlerPlugin's disabled branch does the same kind of "undo" (logCollector().close()+ map removal), so it is consistent with the class, but a short javadoc line onhandlerSelectorstating that an empty handle clears the override would help. - If you retouch this,
removeSelector(selectorData)reads better than an inlineremove, and keeps the two "delete" paths from drifting apart.
CI note: pr_build is green. The only red job is e2e-case (e2e-logging-rocketmq-compose), failing on Failed to consume RocketMQ access log; the same case fails on unrelated PRs today (#7780, which only touches InstanceCheckService), so it is the known flake and not this handler.
|
Approved, but the e2e checks are red on infrastructure, not on this change: The A re-run (or a rebase, since this is 6 days old) should clear it. Ping me if it reproduces after a fresh run. |
|
/retest |
|
@konlue This PR is approved, but 2 checks are red: I inspected these lanes today and they fail for infrastructure reasons rather than on the diff — the Please rebase onto |
4dcbd99 to
e3db77a
Compare
|
Rebased onto the latest master to re-trigger the checks. |
Fixes #7750.
Summary
Clearing a selector's logging configuration (empty or
{}handle) left the previous entry inSELECT_API_CONFIG_MAP, and becauseisSampledprefers the per-selector sampler over the global one, the stale rate kept applying after the operator cleared the override.Modifications
handlerSelector, the empty/{}handle branch now removes the selector's entry fromSELECT_API_CONFIG_MAP(same semantics asremoveSelector), so sampling falls back to the global/default configuration.AbstractLogPluginDataHandlerTestwith a minimal concrete subclass:{}and blank handles clear the stale entry; a configured handle is still stored (regression).Verifying this change
Red-green: with the removal line removed,
testHandlerSelectorClearsStaleEntryOnEmptyHandlefails (the stale entry survives); with the fix, 3/3 pass.Full module tests pass:
./mvnw -B -ntp -pl shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-common testfull module green, no regressions.
Checkstyle passes:
clean.
Notes
Before this change, "clearing the override" was a no-op on the data-sync path; now it restores global sampling, which is the behaviour the issue expects. Client-resource lifecycle is untouched —
logCollector().close()remains confined to the plugin-enabled branch, so sampling-map cleanup and collector ownership stay decoupled.