Skip to content

Commit 864d0cb

Browse files
committed
feat: add logCounter and logBatchCounter methods for usage metrics
- 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.
1 parent b6c260d commit 864d0cb

6 files changed

Lines changed: 874 additions & 159 deletions

File tree

src/Usage/Adapter.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,24 @@ abstract public function log(string $metric, int $value, string $period = Usage:
2525
* Log multiple metrics in batch
2626
*
2727
* @param array<array{metric: string, value: int, period?: string, tags?: array<string,mixed>}> $metrics
28+
* @param int $batchSize Maximum number of metrics per INSERT statement
2829
*/
29-
abstract public function logBatch(array $metrics): bool;
30+
abstract public function logBatch(array $metrics, int $batchSize = 1000): bool;
31+
32+
/**
33+
* Log usage counter metric (individual entry without aggregation)
34+
*
35+
* @param array<string,mixed> $tags
36+
*/
37+
abstract public function logCounter(string $metric, int $value, string $period = Usage::PERIOD_1H, array $tags = []): bool;
38+
39+
/**
40+
* Log multiple counter metrics in batch (individual entries without aggregation)
41+
*
42+
* @param array<array{metric: string, value: int, period?: string, tags?: array<string,mixed>}> $metrics
43+
* @param int $batchSize Maximum number of metrics per INSERT statement
44+
*/
45+
abstract public function logBatchCounter(array $metrics, int $batchSize = 1000): bool;
3046

3147
/**
3248
* Get usage metrics by period

0 commit comments

Comments
 (0)