Skip to content

Commit dbcfe6d

Browse files
author
dezone
authored
Merge pull request #6 from evgeek/master
Added count to counter
2 parents f4ac794 + 719ab15 commit dbcfe6d

File tree

7 files changed

+17
-7
lines changed

7 files changed

+17
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/.idea
22
/vendor/
33
/.ecs_cache
4+
.phpunit.result.cache

src/Repositories/PrometheusRepository/NullPrometheusRepository.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ public function getMetrics(): array
1111
return [];
1212
}
1313

14-
public function writeCounter(string $measurement, array $trackerLabels = []): void
14+
/**
15+
* @param float|int $count
16+
*/
17+
public function writeCounter(string $measurement, array $trackerLabels = [], $count = 1): void
1518
{
1619
}
1720

src/Repositories/PrometheusRepository/PrometheusRepository.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@ public function getMetrics(): array
2222
return $this->registry->getMetricFamilySamples();
2323
}
2424

25-
public function writeCounter(string $measurement, array $trackerLabels = []): void
25+
/**
26+
* @param float|int $count
27+
*/
28+
public function writeCounter(string $measurement, array $trackerLabels = [], $count = 1): void
2629
{
2730
$labels = $this->labels($trackerLabels);
2831

2932
$this->registry->getOrRegisterCounter($this->namespace(), $measurement, '', array_keys($labels))
30-
->inc($labels);
33+
->incBy($count, $labels);
3134
}
3235

3336
public function writeGauge(string $measurement, $value, array $trackerLabels = []): void

src/Repositories/PrometheusRepository/PrometheusRepositoryContract.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
interface PrometheusRepositoryContract
88
{
99
public function getMetrics(): array;
10-
public function writeCounter(string $measurement, array $trackerLabels): void;
10+
/**
11+
* @param float|int $count
12+
*/
13+
public function writeCounter(string $measurement, array $trackerLabels, $count): void;
1114
public function writeGauge(string $measurement, $value, array $trackerLabels): void;
1215
public function writeHistogram(string $measurement, $value, array $trackerLabels, array $buckets): void;
1316
public function writeSummary(

src/Services/Adapters/PrometheusCounterAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ class PrometheusCounterAdapter extends BasePrometheusAdapter
88
{
99
public function write(string $measurement, $value = null, array $tags = []): void
1010
{
11-
$this->repository->writeCounter($measurement, $tags);
11+
$this->repository->writeCounter($measurement, $tags, $value);
1212
}
1313
}

src/Trackers/JobsLog/JobsLogTracker.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function write(Job $job, string $eventName): void
2727
return;
2828
}
2929

30-
$this->adapter->write($this->metricConfig['measurement'], '', [
30+
$this->adapter->write($this->metricConfig['measurement'], 1, [
3131
'jobName' => $job->resolveName(),
3232
'eventName' => $eventName,
3333
]);

tests/Unit/Trackers/JobsLog/JobsLogTrackerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function correctWrite(): void
4444
$eventAdapter
4545
->expects($this->once())
4646
->method('write')
47-
->with($measurement, '', [
47+
->with($measurement, 1, [
4848
'eventName' => 'processing',
4949
'jobName' => $jobName,
5050
]);

0 commit comments

Comments
 (0)