Repository navigation
chore: absorb usage into packages/usage - #13956
Conversation
…ods; update ClickHouse and Database adapters to support new query types and improve handling of array values
…Equal query types
- Introduced logCounter method to log individual usage counter metrics with upsert behavior. - Added logBatchCounter method to log multiple usage counter metrics in batch, allowing for individual entries without aggregation. - Updated logBatch method to accept a batch size parameter for better control over batch processing. - Enhanced Usage class to support new logging methods and batch size functionality. - Implemented tests for new methods, including scenarios for batch sizes, counter behavior, and metrics with tags.
…remove ClickHouseBatchTest
… Adapter and Database classes
… for improved efficiency.
…s, update parsing logic, and add comprehensive tests.
…nd OFFSET application; update test documentation
…se method for improved readability and maintainability
…od for cleaner code
…atus and server info
…TP request timeout
… in ClickHouse adapter
…ickHouse operations
- Introduced increment and set methods for metrics, replacing log and logCounter. - Added in-memory buffers for increment and counter metrics with automatic flushing. - Implemented collect and collectSet methods for deferred metric accumulation. - Enhanced flush logic to handle both increment and set metrics, clearing buffers post-flush. - Added configuration options for flush thresholds and intervals. - Updated tests to reflect changes in metric logging and buffer management.
…858a) The prior commit inadvertently committed a locally-regenerated lock that resolved a broken utopia-php/client combination (undefined array_last() in the Curl adapter). Restore the lock to its pre-session state. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01QssJBktSLWpuEuWzVB23do
…ith ZSTD These store raw, un-normalized caller input (full Accept/Accept-Language headers, arbitrary query-key names), so their distinct count is unbounded. Revert them from LowCardinality + set(0) back to Nullable(String) + bloom_filter (equality lookups without a cardinality bet) and add CODEC(ZSTD(3)) to compress the high-entropy text. protocol/timeZone/ weatherCode remain LowCardinality + set(0) (genuinely bounded). Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01QssJBktSLWpuEuWzVB23do
Adds an ipReputation dimension to the events schema, ready to populate later. It holds a bounded IP-reputation verdict (clean/low/suspicious/block), so it is typed LowCardinality(Nullable(String)) with a set(0) equality index, like protocol/country. Column is nullable and unpopulated until the producer is ready. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01QssJBktSLWpuEuWzVB23do
feat(tests): add tests for low and high cardinality request attribute…
client 0.5 moved Utopia\Client under Utopia\Client\Client and keeps the old name only as an alias until its next major. Require ^0.5 and import the new name so client can drop the alias.
refactor: use utopia-php/client 0.5's names
🟢 Tier S · Ready to merge
This PR moves Utopia Usage into Latest changes: The newest commits add Audit source and test autoload mappings, replace the external Audit dependency, and document Audit’s five PHPStan baseline findings.
📂 Walkthrough · 7
Reviewed the commits since |
|
| namespace: 'utopia_usage_coltype', | ||
| ); | ||
|
|
||
| $this->getColumnType = new ReflectionMethod(ClickHouseAdapter::class, 'getColumnType'); |
There was a problem hiding this comment.
Tests depend on private implementation The new unit test calls the adapter’s private
getColumnType() method and checks exact SQL type strings. A harmless internal refactor could break it without changing the schema ClickHouse creates. The same pattern appears in MetricTest, which derives an expected count from Metric::EVENT_COLUMNS, and UsageQueryTest, which asserts configuration constants. The repository requires tests of observable behavior and leaves syntax and schema checks to linters. Please satisfy that requirement before merging.
Context Used: Call out and harshly judge implementation-coupled tests. We don't mirror source code, configuration, or version pins in assertions. We test observable behavior; use linters for syntax and schema checks. (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/usage/tests/Adapter/ClickHouseColumnTypeTest.php
Line: 32
Comment:
**Tests depend on private implementation** The new unit test calls the adapter’s private `getColumnType()` method and checks exact SQL type strings. A harmless internal refactor could break it without changing the schema ClickHouse creates. The same pattern appears in `MetricTest`, which derives an expected count from `Metric::EVENT_COLUMNS`, and `UsageQueryTest`, which asserts configuration constants. The repository requires tests of observable behavior and leaves syntax and schema checks to linters. Please satisfy that requirement before merging.
**Context Used:** Call out and harshly judge implementation-coupled tests. We don't mirror source code, configuration, or version pins in assertions. We test observable behavior; use linters for syntax and schema checks. ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.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!
| ports: | ||
| - "13316:3306" |
There was a problem hiding this comment.
Test databases exposed on network If a developer or CI host is reachable from another machine and its firewall permits these ports, the unrestricted MariaDB and ClickHouse port bindings let a peer connect using the fixed passwords in this file and read or modify test data. Bind both published ports to loopback for host-run tests.
How this was verified: Both database ports have unrestricted host bindings, and the same Compose file supplies their login credentials.
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/usage/docker-compose.yml
Line: 6-7
Comment:
**Test databases exposed on network** If a developer or CI host is reachable from another machine and its firewall permits these ports, the unrestricted MariaDB and ClickHouse port bindings let a peer connect using the fixed passwords in this file and read or modify test data. Bind both published ports to loopback for host-run tests.
**How this was verified:** Both database ports have unrestricted host bindings, and the same Compose file supplies their login credentials.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
# Conflicts: # composer.lock
| } | ||
|
|
||
| foreach ($entries as $entry) { | ||
| if (preg_match('/^[a-f0-9]{32}:[a-f0-9]{64}:[a-f0-9]{64}$/', $entry) !== 1) { |
There was a problem hiding this comment.
Prohibited regular expressions The watermark validation uses
preg_match(). The repository instruction says not to add regular expressions; use string functions or an existing validator unless the PR explains why neither works. The ClickHouse adapter also uses regular expressions for identifier validation and SQL rewriting. Please satisfy this requirement before merging.
Context Used: CLAUDE.md (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/usage/src/SampleWatermark.php
Line: 29
Comment:
**Prohibited regular expressions** The watermark validation uses `preg_match()`. The repository instruction says not to add regular expressions; use string functions or an existing validator unless the PR explains why neither works. The ClickHouse adapter also uses regular expressions for identifier validation and SQL rewriting. Please satisfy this requirement before merging.
**Context Used:** CLAUDE.md ([source](https://github.com/appwrite/appwrite/blob/main/CLAUDE.md))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.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!
utopia-php/usage#42 moved usage onto utopia-php/database 8: typed Attribute and Index models for the schema, the event ordinal dimension, PHP 8.5. Main absorbed usage into packages/usage (#13956) and the mirror closed #42 in favour of a change here, so this applies #42's final head (bf9ab997fa) to the package: every line it changed, in the package layout, with its tests. The package requires database ^8.0 with dev stability until 8.0.0 is tagged, because bin/monorepo check and test resolve it from Packagist, where it exists only as 8.0.x-dev; the mirror's branch alias does not apply to a split package. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Moves
utopia-php/usageintopackages/usageso Appwrite loads it directly. Wave 4 of #13828, following the playbook inrfc/monorepo.md.usageis a standalone repository, so it gets the full playbook. The mirror head (6340f12) is the0.16.6release Appwrite already locks, so there is no version gap and Appwrite runs the same code.Important
Merge with a merge commit, not a squash. A squash drops the
git-subtree-*annotation and orphans the package from its mirror.Commits
Add 'packages/usage/' from commit '6340f12…'mainwith full historychore(usage): mirror plumbingmirror.ymlreplacestests.yml,linter.yml,codeql-analysis.yml;pint.jsonandcomposer.lockremoved; hoisted QA stripped fromcomposer.json; README banner;CONTRIBUTING.mdnow points at appwrite/appwriterefactor: load usage from packages/What changed
composer.jsonreplaceentries added;utopia-php/usage: ^0.16.6removed fromrequirepsr/http-clientis already in the rootrequire;clientandqueryare inpackages/;databaseis still vendored and required by the root. Noext-*requirement (ext-curlis only asuggest, and the root already requires it)composer.lockutopia-php/usageremoved (+1/−54, content hash)src/src/Usage/*moved up tosrc/. Otherwise Pint only: import order,new Foo()->bar(), andreturn null;→return;inSQL::getAttribute()tests/Accumulator,Metric,Sample,SampleWatermark,Tenant,UsageQuery,Adapter/ClickHouseColumnType) underUtopia\Usage\Tests\tests/E2E/DatabaseTest, theUsageBasetrait), underUtopia\Usage\Tests\E2E\. The ClickHouse benchmark harness moves totests/E2E/Benchmark(ownbenchsuite, excluded frome2e)Utopia\Tests\{Usage,Adapter,Benchmark}→Utopia\Usage\Tests\…; eight@dataProviderannotations become#[DataProvider]attributes (PHPUnit 12 ignores the annotations, which upstream's PHPUnit 9 read); Rector and Pint cleanupsphpunit.xmlunit,e2eandbenchsuites;envdefaults point the e2e tier at the compose host portsdocker-compose.ymlutopia-usage, services only (MariaDB13316, ClickHouse HTTP18223), tmpfs storage. The in-containerusageapp service and itsDockerfileare gone: the e2e tier runs on the host, and the Dockerfile copied the removedcomposer.lockphpstan.neonsrcandtests, withphpstan-baseline.neonholding 1 finding: the Pintreturn;above against?array. Added to the RFC phase 8 listrector.phpsrc(constructor promotion, readonly, typed constants, closure and arrow-fn types,str_contains,array_any,??, catch variables,newwithout parentheses), scoped tosrconlyAppwrite uses the package in
app/init/resources/request.php,Usage/Http/{Action,Events/XList,Gauges/XList}.php,Workers/{Deletes,StatsResources,StatsUsage}.php,Appwrite/Usage/{Concurrency,Connection}.phpandtests/unit/Usage/ConcurrencyTest.php.Validation
bin/monorepo validatebin/monorepo check usagebin/monorepo test usageunitbin/monorepo test usagee2eUsageBaseexercises the deprecatedQuery::contains(), as upstream does)vendor/bin/phpunit --testsuite packagesinappwrite/appwrite:2.3.0usage: 5agentsDiffCheckTest(the worktree's.gitis outside the container mount) and 1clientSwoole connection-reset flake… --testsuite packages --filter 'Utopia\\Usage\\Tests'inappwrite/appwrite:2.3.0vendor/bin/phpunit tests/unit/Usageinappwrite/appwrite:2.3.0Utopia\Usage\Adapter\ClickHouseresolves topackages/usage/src/Adapter/ClickHouse.php; novendor/utopia-php/usagecomposer validate --no-check-publishutopia-php/platformexact-version warning)composer lintbin/monorepo split usage --dry-runacbaa10, fast-forward of the mirror head6340f12(+2 commits)git diff --checkThe benchmark harness (
composer bench, not part of either tier) does not pass upstream either:GaugesBenchseeds aresourcecolumn the gauges table no longer has, andEventsBenchexpectsdailyrouting where the adapter now pickssplit. Left as imported.Mirror state
mainruleset (id22178136) had org admins and repo role5as bypass actors and required 1 approval, so the split app could not push.absorbnormalised it: the split app (4016286) is now the only always-bypass actor and 0 approvals are requiredmainSplitshould push without interventionAfter merge
Splitrun forusageis green and the mirror fast-forwards from6340f12usagenever lived inutopia-php/monorepoOpen on utopia-php/usage:
🤖 Generated with Claude Code