Skip to content

Commit 2c83f65

Browse files
committed
fix: correct tenant key reference and update health check logic for empty collections
1 parent 88cdebe commit 2c83f65

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

src/Usage/Adapter/ClickHouse.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,7 @@ private function validateMetricsBatch(array $metrics): void
13171317

13181318
// Validate tenant when provided (metric-level tenant overrides adapter tenant)
13191319
if (array_key_exists('tenant', $metricData)) {
1320-
$tenantValue = $metricData['$tenant'];
1320+
$tenantValue = $metricData['tenant'];
13211321

13221322
if ($tenantValue !== null) {
13231323
if (is_int($tenantValue)) {
@@ -1753,6 +1753,7 @@ private function parseQueries(array $queries): array
17531753
$this->validateAttributeName($attribute);
17541754
$escapedAttr = $this->escapeIdentifier($attribute);
17551755
$paramName = 'param_' . $paramCounter++;
1756+
$singleValue = null;
17561757
if ($attribute === 'time') {
17571758
if (is_array($values)) {
17581759
/** @var \DateTime|string|null $singleValue */
@@ -1774,6 +1775,7 @@ private function parseQueries(array $queries): array
17741775
$this->validateAttributeName($attribute);
17751776
$escapedAttr = $this->escapeIdentifier($attribute);
17761777
$paramName = 'param_' . $paramCounter++;
1778+
$singleValue = null;
17771779
if ($attribute === 'time') {
17781780
if (is_array($values)) {
17791781
/** @var \DateTime|string|null $singleValue */

src/Usage/Adapter/Database.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ public function healthCheck(): array
4545

4646
// Check if collection exists
4747
$collectionName = $this->collection ?? 'usage';
48-
if (!$this->db->getCollection($collectionName)->isEmpty()) {
48+
if ($this->db->getCollection($collectionName)->isEmpty()) {
4949
return [
50-
'healthy' => true,
50+
'healthy' => false,
5151
'database' => $databaseName,
52-
'collection' => $collectionName
52+
'collection' => $collectionName,
53+
'error' => "Collection '{$collectionName}' is missing or empty in database '{$databaseName}'"
5354
];
5455
}
5556

0 commit comments

Comments
 (0)