diff --git a/.gitignore b/.gitignore index 4a728ec..70cbee0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /.idea /vendor/ /.ecs_cache +.phpunit.result.cache \ No newline at end of file diff --git a/src/Repositories/PrometheusRepository/NullPrometheusRepository.php b/src/Repositories/PrometheusRepository/NullPrometheusRepository.php index 6f691ee..8d1d890 100644 --- a/src/Repositories/PrometheusRepository/NullPrometheusRepository.php +++ b/src/Repositories/PrometheusRepository/NullPrometheusRepository.php @@ -11,7 +11,10 @@ public function getMetrics(): array return []; } - public function writeCounter(string $measurement, array $trackerLabels = []): void + /** + * @param float|int $count + */ + public function writeCounter(string $measurement, array $trackerLabels = [], $count = 1): void { } diff --git a/src/Repositories/PrometheusRepository/PrometheusRepository.php b/src/Repositories/PrometheusRepository/PrometheusRepository.php index 7c92544..b343c6d 100644 --- a/src/Repositories/PrometheusRepository/PrometheusRepository.php +++ b/src/Repositories/PrometheusRepository/PrometheusRepository.php @@ -22,12 +22,15 @@ public function getMetrics(): array return $this->registry->getMetricFamilySamples(); } - public function writeCounter(string $measurement, array $trackerLabels = []): void + /** + * @param float|int $count + */ + public function writeCounter(string $measurement, array $trackerLabels = [], $count = 1): void { $labels = $this->labels($trackerLabels); $this->registry->getOrRegisterCounter($this->namespace(), $measurement, '', array_keys($labels)) - ->inc($labels); + ->incBy($count, $labels); } public function writeGauge(string $measurement, $value, array $trackerLabels = []): void diff --git a/src/Repositories/PrometheusRepository/PrometheusRepositoryContract.php b/src/Repositories/PrometheusRepository/PrometheusRepositoryContract.php index e6d1635..ecff191 100644 --- a/src/Repositories/PrometheusRepository/PrometheusRepositoryContract.php +++ b/src/Repositories/PrometheusRepository/PrometheusRepositoryContract.php @@ -7,7 +7,10 @@ interface PrometheusRepositoryContract { public function getMetrics(): array; - public function writeCounter(string $measurement, array $trackerLabels): void; + /** + * @param float|int $count + */ + public function writeCounter(string $measurement, array $trackerLabels, $count): void; public function writeGauge(string $measurement, $value, array $trackerLabels): void; public function writeHistogram(string $measurement, $value, array $trackerLabels, array $buckets): void; public function writeSummary( diff --git a/src/Services/Adapters/PrometheusCounterAdapter.php b/src/Services/Adapters/PrometheusCounterAdapter.php index a7eba64..11e3233 100644 --- a/src/Services/Adapters/PrometheusCounterAdapter.php +++ b/src/Services/Adapters/PrometheusCounterAdapter.php @@ -8,6 +8,6 @@ class PrometheusCounterAdapter extends BasePrometheusAdapter { public function write(string $measurement, $value = null, array $tags = []): void { - $this->repository->writeCounter($measurement, $tags); + $this->repository->writeCounter($measurement, $tags, $value); } } diff --git a/src/Trackers/JobsLog/JobsLogTracker.php b/src/Trackers/JobsLog/JobsLogTracker.php index 2a26975..3dd92e9 100644 --- a/src/Trackers/JobsLog/JobsLogTracker.php +++ b/src/Trackers/JobsLog/JobsLogTracker.php @@ -27,7 +27,7 @@ public function write(Job $job, string $eventName): void return; } - $this->adapter->write($this->metricConfig['measurement'], '', [ + $this->adapter->write($this->metricConfig['measurement'], 1, [ 'jobName' => $job->resolveName(), 'eventName' => $eventName, ]); diff --git a/tests/Unit/Trackers/JobsLog/JobsLogTrackerTest.php b/tests/Unit/Trackers/JobsLog/JobsLogTrackerTest.php index a5d4d86..a3643e6 100644 --- a/tests/Unit/Trackers/JobsLog/JobsLogTrackerTest.php +++ b/tests/Unit/Trackers/JobsLog/JobsLogTrackerTest.php @@ -44,7 +44,7 @@ public function correctWrite(): void $eventAdapter ->expects($this->once()) ->method('write') - ->with($measurement, '', [ + ->with($measurement, 1, [ 'eventName' => 'processing', 'jobName' => $jobName, ]);