Skip to content

fix(observability): prevent reserved cache counter registration as Gauge - #367

Merged
voidvec merged 6 commits into
masterfrom
fix/cache-counter-reserved-gauge
Nov 24, 2026
Merged

voidvec merged 6 commits into
masterfrom
fix/cache-counter-reserved-gauge

Conversation

@voidvec

@voidvec voidvec commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Summary

When PromExporter is enabled but the fulla_cache_total collector is missing, DrogonMetrics::setGauge could 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 /metrics export 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

  • Independent plan and final implementation reviews passed.
  • RED: the unchanged adapter with the new test failed in the missing-collector process at the collector-identity assertion after setGauge created an unexpected collector.
  • GREEN: the same test and missing configuration passed after the guard. All four actual schema processes passed: 21 / 14 / 15 / 14 assertions. They verify generic peer metrics through HTTP; the default profile requires a real configured Counter and exact cache increment.
  • Complete adapter binary: 18 tests passed. The dedicated real-Session target's five cases also ran successfully in the full suite.
  • 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.
  • Thirteen local static/API/architecture/migration/naming/macro/parity/spec/OpenAPI/doc-link checks passed.
  • Release / C++17 / WERROR, all optional features enabled; local resource override -O1 -DNDEBUG, examples disabled. Fixed dependencies came from the offline lock/cache; the existing system CMake platform-tool exception is recorded.
  • Rebased onto master 324fdf16; published tree b7d35a14d9f25947ceba53764000494faa01e5cb matches 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 head 4ab99cd5; 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

  • Bug fix, non-breaking

Checklist

  • Regression demonstrates the failure and passes with the fix
  • Complete relevant library/main/endpoint suites passed locally
  • CHANGELOG updated
  • Public API/schema/SDK inputs unchanged

Final merge review

All current checks on 4ab99cd5 completed 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.

@voidvec
voidvec force-pushed the fix/cache-counter-reserved-gauge branch from d8f4fb9 to 4ab99cd Compare November 20, 2026 03:26
@voidvec
voidvec marked this pull request as ready for review November 20, 2026 03:27
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T03:27:53.722945Z 4ab99cd Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@voidvec voidvec left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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 voidvec left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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, so lookup() == configured fails.
  • 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 registers fulla_cache_total as 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)

  1. Unit-level pin (cheapest): extract the reservation decision into a small testable helper in CacheCounter.h (e.g. detail::isReservedCacheFamily(name) used by both setGauge and incrementCacheCounter) and unit-test the rejection semantics directly, plus assert the reserved literal is duplicated nowhere else.
  2. CI profile job: generate (or commit) a test-only config registering fulla_cache_total as a gauge, and run the suite once with FULLA_TEST_CACHE_SCHEMA=gauge (and once with missing). This is the only option that pins the running-adapter behavior end to end.
  3. 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).

@voidvec
voidvec force-pushed the fix/cache-counter-reserved-gauge branch from 4ab99cd to efc8f4c Compare November 23, 2026 05:13
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.
@voidvec
voidvec force-pushed the fix/cache-counter-reserved-gauge branch from c46e587 to f1deb1f Compare November 24, 2026 06:36
@voidvec
voidvec merged commit 8dbce17 into master Nov 24, 2026
18 checks passed
@voidvec
voidvec deleted the fix/cache-counter-reserved-gauge branch December 2, 2026 04:43
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.

2 participants