Repository navigation
fix(observability): prevent reserved cache counter registration as Gauge - #367
Conversation
d8f4fb9 to
4ab99cd
Compare
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
voidvec
left a comment
There was a problem hiding this comment.
Final review passed on this exact head. The reserved cache Counter name cannot be registered/changed through Gauge API, while generic metric exporting and independent logging remain intact. The regression demonstrates the original missing-collector failure and passes with the guard in configured/missing/reversed/Gauge profiles. Independent review and complete674 CTest/main765/62833 plus real endpoints passed locally; the rebase preserves the stable patch-id and byte-identical product/test files. All current exact-head CI, full-stack SDK and manually dispatched client-SDK checks pass, with configured strict/nightly skips and baseline #365/#366 limitations explicitly retained. No unresolved blocking code findings. This author-account COMMENT records review, not approval; genuine external approval is still required.
voidvec
left a comment
There was a problem hiding this comment.
Review — P2: the new regression fixture cannot fail in CI (at 4ab99cd5)
The fix itself is correct: setGauge now short-circuits the reserved name before resolveCollector, so the reserved family is never registered or mutated through the Gauge API, while incrementCounter's whitelist path, the [METRIC] log line, pre-startup and exporter-missing behavior are unchanged. grep confirms no production caller does setGauge("fulla_cache_total", ...), so this is defense-in-depth with no observable interface change.
The problem is the verification gap, not the code.
Why the fixture cannot catch the regression today
FULLA_TEST_CACHE_SCHEMA defaults to configured, and nothing in the repository or CI sets it (verified: only the test file references the variable). In the configured profile the collector is already a Counter, so pre-fix setGauge also failed the dynamic_pointer_cast<Gauge> and was a no-op — every assertion in that branch passes on 4ab99cd5^ as well. The CacheCounterTest addition only asserts EXPECT_NO_THROW, which is equally true before and after.
The profiles that would actually go red on the pre-fix code are never executed:
missing(L104): pre-fix registers a new Gauge, solookup() == configuredfails.gauge(L111): pre-fix mutates the misconfigured Gauge with arbitrary labels, so the unchanged-snapshot assertion fails — but this profile additionally requires a custom config that registersfulla_cache_totalas a gauge, and no such config exists in-repo.
Consequently the CHANGELOG line "Add running-adapter regression coverage" describes coverage that CI does not enforce: a future change that drops the guard at DrogonMetrics.cc:181 or re-adds a registration/mutation path would merge green.
Suggested fix (choose one, or combine)
- Unit-level pin (cheapest): extract the reservation decision into a small testable helper in
CacheCounter.h(e.g.detail::isReservedCacheFamily(name)used by bothsetGaugeandincrementCacheCounter) and unit-test the rejection semantics directly, plus assert the reserved literal is duplicated nowhere else. - CI profile job: generate (or commit) a test-only config registering
fulla_cache_totalas a gauge, and run the suite once withFULLA_TEST_CACHE_SCHEMA=gauge(and once withmissing). This is the only option that pins the running-adapter behavior end to end. - If neither is in scope yet: delete the unreachable profile branches and soften the CHANGELOG wording to "adds profile-gated fixture coverage; enabled via
FULLA_TEST_CACHE_SCHEMA" so the claim matches what CI proves. Then track 1 or 2 as a follow-up.
Separately (already known): the branch needs a rebase — the only conflict against current master is the CHANGELOG.md ### Fixed block (new #360 entry).
4ab99cd to
efc8f4c
Compare
Prevent optional cache collectors from being dynamically registered or modified as Gauge families. Add a running-adapter regression for bounded routing and generic metric export, with missing and malformed collector profiles. Refs #345
setGauge() previously created a Gauge collector on first use, so a deployment missing the configured fulla_cache_total Counter would get a Gauge family with arbitrary labels under the same name, and the prometheus scrape would silently change shape. Move the gauge apply path into detail::setGaugeSample(), which rejects the reserved name before any lookup: missing collectors are never registered and an existing collector of any type is never mutated. The label-name/value helpers move next to the cache whitelist so both paths share one implementation.
Cover the three collector states the reserved family can be in (missing, counter, misconfigured gauge) plus the generic-gauge and wrong-type paths. The missing-collector case is the regression pin: with the reserved-name check removed, the test registers a Gauge and fails.
Drive the running-adapter fixture only against the configured profile: assert the real Counter schema, whitelist rejections, no-op Gauge calls for the reserved family, and fulla_test_peer counter/gauge registration, then observe the values through an actual /metrics scrape. The previous env-gated missing/reversed/gauge branches were unreachable in CI; those states are covered as unit tests instead.
State in the metric reference that setGauge() is a no-op for fulla_cache_total in every collector state, and align the changelog bullet with the coverage the tests now prove.
c46e587 to
f1deb1f
Compare
Summary
When PromExporter is enabled but the
fulla_cache_totalcollector is missing,DrogonMetrics::setGaugecould dynamically register a Gauge under that reserved Counter name with arbitrary labels. Subsequent bounded Counter writes then encounter the wrong collector type.Keep that name out of the Gauge export path while preserving independent logging and all other generic metric behavior. Add a running-adapter regression for configured, missing, reversed-label and Gauge collectors, bounded cache increments, invalid inputs, and real
/metricsexport alongside generic Counter/Gauge peers. Extend the existing pre-start adapter case with both Gauge calls.Four-file follow-up to #345. The Counter helper, original generic exporter test, public headers, plugin lifecycle, authentication/storage, configuration and schema remain unchanged.
Refs #345
Validation
setGaugecreated an unexpected collector.manage.sh test-backend: all 674 CTest entries passed; complete main binary without-r: 765 cases / 62,833 assertions. Real PostgreSQL/Redis, out-of-process endpoints, feature-surface and social-login-state checks ran. Endpoint scripts reported OAuth 62/63 with 0 failed and admin 61/61 with 0 failed.-O1 -DNDEBUG, examples disabled. Fixed dependencies came from the offline lock/cache; the existing system CMake platform-tool exception is recorded.324fdf16; published treeb7d35a14d9f25947ceba53764000494faa01e5cbmatches the reviewed native tree. Stable patch-id is unchanged; all product/library/test files are byte-identical to the fully tested previous head (base additions are Go dependency and workflow-only changes).Existing validation limits: the CSP broker-profile sub-branch is skipped in this wiring, and the wrapper's second memory-config round is skipped because its nested staged-config path is absent. Four isolated memory schema processes are specialized coverage, not a full memory-suite result. Manually dispatched client-SDK drift passed on
d8f4fb97(run). Fresh three-platform/SDK-consumer/ASan checks and a manually dispatched client-SDK run are required on updated head4ab99cd5; the previous head's passes are not substitutes for these checks. External approval is also required before rebase merge.The same base already has scheduled strict storage-memory coverage and TSan failures, tracked separately in #365 and #366. This patch does not claim to fix those failures or change their thresholds, baselines or suppressions.
Type of change
Checklist
Final merge review
All current checks on
4ab99cd5completed successfully, including three platforms and full-stack SDK; configured strict/nightly skips remain as documented. Fresh client-SDK run 44667720835 passed. Final code review has no unresolved blocking findings. Genuine external approval remains required by author/last-push protection.