Skip to content

Commit

Permalink
Merge pull request #6 from evgeek/master
Browse files Browse the repository at this point in the history
Added count to counter
  • Loading branch information
dezone authored Mar 16, 2023
2 parents f4ac794 + 719ab15 commit dbcfe6d
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.idea
/vendor/
/.ecs_cache
.phpunit.result.cache
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/Services/Adapters/PrometheusCounterAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion src/Trackers/JobsLog/JobsLogTracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Trackers/JobsLog/JobsLogTrackerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function correctWrite(): void
$eventAdapter
->expects($this->once())
->method('write')
->with($measurement, '', [
->with($measurement, 1, [
'eventName' => 'processing',
'jobName' => $jobName,
]);
Expand Down

0 comments on commit dbcfe6d

Please sign in to comment.