feat: add dedicated slow query logging to ClickHouse adapter#112
feat: add dedicated slow query logging to ClickHouse adapter#112lohanidamodar wants to merge 3 commits intomainfrom
Conversation
Allow configuring the table name used by the ClickHouse adapter, enabling use cases like a dedicated slow query log table alongside the default audits table. Follows the same setter/getter pattern as setDatabase, setNamespace, and setTenant. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Greptile SummaryThis PR's title and description state it adds The new methods follow established patterns in the adapter (identifier escaping, tenant filtering, namespace prefixing) and the implementation looks functionally correct. The one minor inconsistency is that Confidence Score: 4/5Safe to merge functionally, but the PR description should be corrected to accurately reflect the slow-query logging feature that was actually implemented. The implementation follows the adapter's existing patterns and is functionally correct. The score is 4 rather than 5 because the PR title and description completely misrepresent the changes (claiming setTable/getTable when slow-query logging was actually added), which makes the PR difficult to review or reason about historically. src/Audit/Adapter/ClickHouse.php — verify the slow-query feature is what was intended, and update the PR title/description accordingly. Important Files Changed
Reviews (3): Last reviewed commit: "feat: add dedicated slow query logging m..." | Re-trigger Greptile |
Replace mutable setTable()/getTable() with an immutable constructor parameter to prevent accidental table name changes on a shared adapter instance. The table name defaults to 'audits' for backward compatibility. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace the generic setTable/getTable approach with purpose-built slow query methods: setupSlowQueries(), createSlowQuery(), findSlowQueries(), and cleanupSlowQueries(). The slow_queries table has its own schema with indexed durationMs (UInt32), LowCardinality method/action/plan, and UInt16 statusCode — optimized for analytical queries without JSON extraction. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
slow_queriestable schemaUInt32for duration,UInt16for status code,LowCardinality(String)for method/action/plan) instead of stuffing everything into a generic auditdataJSON blobminmaxskip-index ondurationMsfor efficient threshold-based filteringChanges
src/Audit/Adapter/ClickHouse.php:setupSlowQueries()— creates{namespace}_slow_queriestable with the dedicated schemacreateSlowQuery(array $data)— type-safe insert for a single slow query rowfindSlowQueries(?DateTime, ?DateTime, limit, offset)— time-range query with tenant isolationcleanupSlowQueries(DateTime $before)— deletes rows older than a given date$tableconstructor parameter (replaced by dedicated methods instead of generic table-swapping)Slow queries table schema
Verification
composer check): No errorscomposer lint): PassTest plan
setupSlowQueries()createsconsole_slow_queriesandprojects_slow_queriestables in ClickHousecreateSlowQuery()inserts a row with correct types (durationMs as UInt32, statusCode as UInt16)findSlowQueries()returns results filtered by time range and tenantcleanupSlowQueries()deletes rows older than the given datetimesetup(),create(),find()) are unaffected