diff --git a/src/Usage/Adapter/ClickHouse.php b/src/Usage/Adapter/ClickHouse.php index c905006..51ca399 100644 --- a/src/Usage/Adapter/ClickHouse.php +++ b/src/Usage/Adapter/ClickHouse.php @@ -1436,6 +1436,8 @@ private function getColumnType(string $id, string $type = 'event'): string 'clientType', 'clientCode', 'clientName', 'clientVersion', 'clientEngine', 'clientEngineVersion', 'deviceName', 'deviceBrand', 'deviceModel', + // metric-scoped dimensions; small closed value spaces per metric + 'category', 'outcome', 'hostname', 'ip', // premium geo (lower-cardinality only; city/isp/AS org/connection org // are high-cardinality and intentionally fall through to Nullable(String)) diff --git a/src/Usage/Metric.php b/src/Usage/Metric.php index 6c1eff9..6f93382 100644 --- a/src/Usage/Metric.php +++ b/src/Usage/Metric.php @@ -64,6 +64,11 @@ class Metric extends ArrayObject // sdk identity 'sdk', 'sdkVersion', 'deviceName', 'deviceBrand', 'deviceModel', + // metric-scoped: what the row is about, and how it ended. + // Named `category`, not `type`: the SQL adapter already writes a `type` + // column holding 'event'/'gauge', and a dimension of that name silently + // overwrote it through array_merge. + 'category', 'outcome', ]; /** @@ -670,6 +675,13 @@ public static function getEventSchema(): array // sdk identity $stringColumn('sdk', 256), $stringColumn('sdkVersion', 255), + // metric-scoped dimensions. `category` is whatever the metric is + // broken down by — a messaging channel, a calling code — and + // `outcome` is how the attempt ended. Both are read with `metric` + // pinned, so the same column carries different value spaces across + // metrics, the way resourceId already carries ids of every kind. + $stringColumn('category', 64), + $stringColumn('outcome', 32), $stringColumn('deviceName', 256), $stringColumn('deviceBrand', 256), $stringColumn('deviceModel', 255), @@ -756,6 +768,7 @@ public static function getSchema(): array public static function getEventIndexes(): array { $indexed = [ + 'category', 'outcome', 'path', 'method', 'status', 'service', 'resourceType', 'resourceId', 'resourceInternalId', 'teamId', 'teamInternalId', @@ -763,7 +776,7 @@ public static function getEventIndexes(): array 'osName', 'clientType', 'clientName', 'deviceName', ]; - $setIndexed = ['status', 'method', 'country', 'service', 'clientType', 'osName']; + $setIndexed = ['status', 'method', 'country', 'service', 'clientType', 'osName', 'category', 'outcome']; return array_map( static function (string $col) use ($setIndexed): array { diff --git a/tests/Usage/Adapter/ClickHouseSchemaTest.php b/tests/Usage/Adapter/ClickHouseSchemaTest.php index 4829c27..7943dcd 100644 --- a/tests/Usage/Adapter/ClickHouseSchemaTest.php +++ b/tests/Usage/Adapter/ClickHouseSchemaTest.php @@ -275,6 +275,7 @@ private function expectedDimAssertions(array $columns, string $type): array 'connectionUsageType', 'autonomousSystemNumber', 'sdk', 'sdkVersion', 'ordinal', + 'category', 'outcome', ]; $baseKey = ['id', 'metric', 'value', 'time', 'tenant']; diff --git a/tests/Usage/MetricTest.php b/tests/Usage/MetricTest.php index fa7e3e6..9a0d69d 100644 --- a/tests/Usage/MetricTest.php +++ b/tests/Usage/MetricTest.php @@ -617,6 +617,7 @@ public function testEventColumnsConstant(): void 'clientEngine', 'clientEngineVersion', 'sdk', 'sdkVersion', 'deviceName', 'deviceBrand', 'deviceModel', + 'category', 'outcome', ]; $this->assertSame($expected, Metric::EVENT_COLUMNS); }