Fix metric name for gauge, improve typehints

This commit is contained in:
Daniil Gentili 2024-05-09 21:10:21 +02:00
parent 99f8d9435a
commit f0eb82c76a
5 changed files with 11 additions and 8 deletions

View File

@ -5,6 +5,9 @@ $config = new class extends Amp\CodeStyle\Config {
{
return array_merge(parent::getRules(), [
'void_return' => true,
'phpdoc_to_param_type' => true,
'phpdoc_to_return_type' => true,
'phpdoc_to_property_type' => true,
]);
}
};

View File

@ -87,7 +87,7 @@ final class BetterCollectorRegistry
*
* @throws MetricsRegistrationException
*/
public function registerGauge(string $namespace, string $name, string $help, $labels = []): BetterGauge
public function registerGauge(string $namespace, string $name, string $help, array $labels = []): BetterGauge
{
$metricIdentifier = "$namespace:$name";
if (isset($this->gauges[$metricIdentifier])) {
@ -123,7 +123,7 @@ final class BetterCollectorRegistry
*
* @throws MetricsRegistrationException
*/
public function getOrRegisterGauge(string $namespace, string $name, string $help, $labels = []): BetterGauge
public function getOrRegisterGauge(string $namespace, string $name, string $help, array $labels = []): BetterGauge
{
try {
$gauge = $this->getGauge($namespace, $name);
@ -141,7 +141,7 @@ final class BetterCollectorRegistry
*
* @throws MetricsRegistrationException
*/
public function registerCounter(string $namespace, string $name, string $help, $labels = []): BetterCounter
public function registerCounter(string $namespace, string $name, string $help, array $labels = []): BetterCounter
{
$metricIdentifier = "$namespace:$name";
if (isset($this->counters[$metricIdentifier])) {
@ -178,7 +178,7 @@ final class BetterCollectorRegistry
*
* @throws MetricsRegistrationException
*/
public function getOrRegisterCounter(string $namespace, string $name, string $help, $labels = []): BetterCounter
public function getOrRegisterCounter(string $namespace, string $name, string $help, array $labels = []): BetterCounter
{
try {
$counter = $this->getCounter($namespace, $name);

View File

@ -36,7 +36,7 @@ final class BetterGauge extends BetterCollector
$labels = $this->labels + $labels;
$this->storageAdapter->updateGauge(
[
'name' => $this->name,
'name' => $this->metricName,
'help' => $this->help,
'type' => self::TYPE,
'labelNames' => \array_keys($labels),

View File

@ -79,7 +79,7 @@ final class BetterHistogram extends BetterCollector
}
/**
* @param double $value e.g. 123
* @param double|int $value e.g. 123
* @param array<string, string> $labels e.g. ['status' => '201', 'opcode' => 'SOME_OP']
*/
public function observe(float|int $value, array $labels = []): void

View File

@ -93,10 +93,10 @@ final class BetterSummary extends BetterCollector
}
/**
* @param double $value e.g. 123
* @param double|int $value e.g. 123
* @param array<string, string> $labels e.g. ['status' => '404', 'opcode' => 'SOME_OP']
*/
public function observe(float $value, array $labels = []): void
public function observe(float|int $value, array $labels = []): void
{
self::assertValidLabels($labels);
$labels = $this->labels + $labels;