Skip to content

Keep the tenant a string when sampling concurrency - #13595

Merged
lohanidamodar merged 1 commit into
mainfrom
fix/concurrency-tenant-string
Sep 10, 2026
Merged

lohanidamodar merged 1 commit into
mainfrom
fix/concurrency-tenant-string

Conversation

@lohanidamodar

Copy link
Copy Markdown
Member

Follow-up to #13520, which is live and currently sampling nothing.

What is happening in production

Every stats-resources run since the deploy has logged:

stats resources: concurrency sample failed, continuing: Metric #0: 'tenant' is required (non-empty string) when shared tables are enabled

So Concurrency::sample() throws before addBatch, no gauge sample is written, and the newest realtime.connections sample is the last one the old carried fold left behind. Billing takes max() over the cycle, so it still reads the inflated carried peak — in fra1 the gauge sits at 28,988 against 1,930 connections actually open, and 699 is what the windowed fold would write for the current bucket.

Cause

A tenant is a project sequence — a numeric string like 356187. Grouping deltas per tenant:

$deltas[$tenant][$bucket] = ...;      // PHP casts "356187" to int(356187)
foreach ($deltas as $tenant => $byBucket) {
    ...
    $samples[] = ['tenant' => $tenant, ...];   // int, and the adapter wants a string
}

Adapter\ClickHouse::addBatch() requires a non-empty string and throws. The carried fold read the tenant off the row inside the loop and never had an array key to be cast, which is why this only appeared with the paging refactor.

Fixed by casting once at the top of the loop.

Why the tests missed it, and what changed

Two failures of fidelity, both now closed:

  • The double was laxer than the store. The stub's addBatch recorded whatever it was handed. It now rejects a non-string or empty tenant with the adapter's own message, so any test would catch this.
  • The fixtures used a shape production cannot produce. Tenants were 't1', 't2' — non-numeric, so PHP keeps them as string keys and the cast never happens. They are now real project sequences (356187, 478539, 605738).

Verified: with the cast, 7 tests / 7 assertions green. Without it, the suite fails with the identical message the pods logged.

Deploying this

Cloud needs a composer.lock bump to pick it up. Until then the realtime concurrency gauge does not advance at all, and the billing peak stays on pre-fix values.

A tenant is a project sequence, so grouping deltas into $deltas[$tenant]
turned every key into an int, and the store rejects a tenant that is not
a non-empty string. Production has logged nothing but

  concurrency sample failed, continuing: Metric #0: 'tenant' is
  required (non-empty string) when shared tables are enabled

on every run since the deploy, so the gauge is frozen on the samples the
old carried fold left behind and billing still reads their peak.

The carried fold took the tenant off the row and never had a key to cast.
Two reasons the tests missed it: the double accepted any tenant where
the adapter refuses a non-string, and the fixtures used 't1', which PHP
keeps as a string key. Both now match production, and the suite fails
with the same message the pods logged.
@greptile-apps

greptile-apps Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

The runtime fix appears correct, but the PR should not merge until the implementation-coupled adapter validation is removed from the unit test.

Fix All in Claude CodeFindings

  1. P2 Test Mirrors Adapter Internals ▶
Fix with agent prompt
### Issue 1
tests/unit/Usage/ConcurrencyTest.php:184-191
This callback duplicates the ClickHouse adapter’s tenant validation and exact exception wording instead of testing `Concurrency` through its observable output. The repository requires tests not to mirror source code, configuration, or schema checks because such copies can drift while still giving false confidence. This requirement must be satisfied before merging: remove the copied validation, keep assertions on the rows passed to `addBatch`, and cover the storage contract at the adapter boundary.

```suggestion

```

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

  • Casts grouped tenant keys back to strings before constructing gauge samples.
  • Replaces synthetic tenant fixtures with realistic numeric project sequences.
  • Adds adapter-specific validation to the unit double, which violates the repository’s observable-behavior testing rule.

Reviews (1) · Last reviewed commit: "fix(usage): keep the tenant a string whe..."

Comment thread tests/unit/Usage/ConcurrencyTest.php Resolved
@lohanidamodar
lohanidamodar merged commit 907f60b into main Sep 10, 2026
45 of 47 checks passed
@github-actions

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/concurrency-tenant-string (after).

Metric Before After Change
🚀 Requests/sec 260.21 270.69 ⚪ +4%
⏱️ Latency P50 67.38 ms 65.54 ms ⚪ -2.7%
⏱️ Latency P95 157.87 ms 146.83 ms 🟢 -7%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 65.54 146.83 16,986 270.69 -11.04
Account 127.45 217.7 894 14.86 -21.21
TablesDB 63.81 113.09 9,238 149.97 -2.9
Storage 59.55 126.97 4,470 74.38 -7.21
Functions 96.52 171.21 2,384 40.32 -22.49

Top API waits (after)

API request Max wait (ms)
functions.variables.update 365.67
account.name.update 327.25
functions.variables.create 300.12
storage.files.create 287.92
account.prefs.update 284.32

@ChiragAgg5k ChiragAgg5k mentioned this pull request Sep 10, 2026
2 of 4 tasks
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.

1 participant