From f3c5d819393ea71ff8f2017d14a392e8a4c4e503 Mon Sep 17 00:00:00 2001 From: "C. Scott Ananian" Date: Thu, 17 Oct 2024 18:49:50 -0400 Subject: [PATCH] Slightly simplify SiteConfig metrics implementation & improve doc Document that ::observeTiming takes an argument *in milliseconds* (not seconds). Use the new Metric::setLabels() method to simplify the implementation a bit as well. Change-Id: I374ff380466cfc5c12abb24793e8a4ed195db382 --- includes/parser/Parsoid/Config/SiteConfig.php | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/includes/parser/Parsoid/Config/SiteConfig.php b/includes/parser/Parsoid/Config/SiteConfig.php index d038f2c4d51..3ac11cd0f58 100644 --- a/includes/parser/Parsoid/Config/SiteConfig.php +++ b/includes/parser/Parsoid/Config/SiteConfig.php @@ -264,16 +264,14 @@ class SiteConfig extends ISiteConfig { /** * Record a timing metric * @param string $name - * @param float $value + * @param float $value A time value in milliseconds * @param array $labels * @return void */ public function observeTiming( string $name, float $value, array $labels ) { - $metric = $this->prefixedStatsFactory()->getTiming( $name ); - foreach ( $labels as $labelKey => $labelValue ) { - $metric->setLabel( $labelKey, $labelValue ); - } - $metric->observe( $value ); + $this->prefixedStatsFactory()->getTiming( $name ) + ->setLabels( $labels ) + ->observe( $value ); } /** @@ -284,11 +282,9 @@ class SiteConfig extends ISiteConfig { * @return void */ public function incrementCounter( string $name, array $labels, float $amount = 1 ) { - $metric = $this->prefixedStatsFactory()->getCounter( $name ); - foreach ( $labels as $labelKey => $labelValue ) { - $metric->setLabel( $labelKey, $labelValue ); - } - $metric->incrementBy( $amount ); + $this->prefixedStatsFactory()->getCounter( $name ) + ->setLabels( $labels ) + ->incrementBy( $amount ); } public function galleryOptions(): array {