Skip to content

Add sdk and sdkVersion columns to audit logs#130

Merged
lohanidamodar merged 2 commits into
mainfrom
CLO-4553-audit-sdk-columns
Jul 13, 2026
Merged

Add sdk and sdkVersion columns to audit logs#130
lohanidamodar merged 2 commits into
mainfrom
CLO-4553-audit-sdk-columns

Conversation

@lohanidamodar

Copy link
Copy Markdown
Contributor

Summary

Adds two new optional columns to the ClickHouse audit logs table (Linear CLO-4553, audit half):

  • sdk — SDK name (e.g. web, flutter, console, cli). Low-cardinality, stored as LowCardinality(Nullable(String)), with a bloom-filter index _key_sdk.
  • sdkVersion — SDK version (e.g. 14.0.0). High-cardinality, stored as plain Nullable(String) (no index, not added to LOW_CARDINALITY_COLUMNS).

Both columns are optional (required = false), so createBatch() never throws when a caller omits them.

Changes

  • src/Audit/Adapter/ClickHouse.php
    • getAttributes(): append sdk and sdkVersion attribute blocks after hostname.
    • LOW_CARDINALITY_COLUMNS: add sdk only.
    • getIndexes(): add _key_sdk bloom-filter index on sdk.
  • src/Audit/Log.php: add getSdk() and getSdkVersion() string getters (empty-string fallback).
  • tests/Audit/Adapter/ClickHouseTest.php: assert sdk / sdkVersion attributes and _key_sdk index.
  • CHANGELOG.md: new 2.7.0 section.

getColumnDefinition() is unchanged — it derives the column type generically from required + LOW_CARDINALITY_COLUMNS membership, yielding sdk LowCardinality(Nullable(String)) and sdkVersion Nullable(String).

Testing

  • composer lint (pint): pass
  • phpstan --level max: no errors
  • Schema logic verified standalone (attributes, index, column definitions, and Log getters).
  • Full ClickHouseTest suite requires a live ClickHouse server (its setUp() connects), so those cases were not run in CI here.

@greptile-apps

greptile-apps Bot commented Jul 12, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds two optional ClickHouse columns (sdk as LowCardinality(Nullable(String)) and sdkVersion as Nullable(String)) to capture the SDK name and version on audit log entries, along with a bloom-filter index on sdk. Corresponding Log::getSdk() / Log::getSdkVersion() getters return ?string, consistent with the other nullable actor fields.

  • Schema: sdk is added to LOW_CARDINALITY_COLUMNS and gets a _key_sdk bloom-filter index; sdkVersion is intentionally unindexed (high-cardinality). Both attributes use Database::LENGTH_KEY for size, matching every other string attribute in getAttributes().
  • API: getSdk() and getSdkVersion() return null when the field was never recorded — consistent with getActorId() / getActorInternalId() — avoiding the empty-string ambiguity for absent vs. stored-null values.
  • Migration note: The CHANGELOG correctly documents that setup() only issues CREATE TABLE IF NOT EXISTS, so existing tables require a manual ALTER TABLE … ADD COLUMN IF NOT EXISTS migration.

Confidence Score: 5/5

The change is additive and backward-compatible — both columns are optional, existing call sites are unaffected, and the schema additions follow established conventions throughout the adapter.

All three issues raised in the previous review pass have been resolved: the CHANGELOG now correctly distinguishes new-table creation from existing-table migration, the getters return ?string matching the nullable-column contract, and the attribute size fields use Database::LENGTH_KEY consistently. No new issues were found.

No files require special attention.

Important Files Changed

Filename Overview
src/Audit/Adapter/ClickHouse.php Adds sdk to LOW_CARDINALITY_COLUMNS, two new attributes (sdk, sdkVersion) using consistent Database::LENGTH_KEY size, and a bloom-filter _key_sdk index — all matching the existing schema conventions.
src/Audit/Log.php Adds getSdk(): ?string and getSdkVersion(): ?string with null fallback, now consistent with the other nullable actor getters (getActorId, getActorInternalId).
tests/Audit/Adapter/ClickHouseTest.php Extends attribute and index assertion lists to cover sdk, sdkVersion, and _key_sdk — no logic concerns.
CHANGELOG.md New 2.7.0 section documents both columns and explicitly warns operators that existing tables need a manual ALTER TABLE … ADD COLUMN IF NOT EXISTS migration.

Reviews (2): Last reviewed commit: "Address review: nullable sdk getters, LE..." | Re-trigger Greptile

Comment thread CHANGELOG.md Outdated
Comment thread src/Audit/Log.php Outdated
Comment thread src/Audit/Adapter/ClickHouse.php
@lohanidamodar lohanidamodar merged commit 9a32692 into main Jul 13, 2026
4 checks passed
@lohanidamodar lohanidamodar deleted the CLO-4553-audit-sdk-columns branch July 13, 2026 03:55
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