@@ -156,7 +156,7 @@ public function updateHistogram(array $data): void
156156 ,
157157 [
158158 $ this ->toMetricKey ($ data ),
159- self ::$ prefix. Histogram::TYPE . self ::PROMETHEUS_METRIC_KEYS_SUFFIX ,
159+ self ::$ prefix . Histogram::TYPE . self ::PROMETHEUS_METRIC_KEYS_SUFFIX ,
160160 json_encode (['b ' => 'sum ' , 'labelValues ' => $ data ['labelValues ' ]]),
161161 json_encode (['b ' => $ bucketToIncrease , 'labelValues ' => $ data ['labelValues ' ]]),
162162 $ data ['value ' ],
@@ -176,16 +176,16 @@ public function updateSummary(array $data): void
176176 $ this ->redis ->ensureOpenConnection ();
177177
178178 // store meta
179- $ summaryKey = self ::$ prefix. Summary::TYPE . self ::PROMETHEUS_METRIC_KEYS_SUFFIX ;
180- $ metaKey = $ summaryKey. ': ' . $ this ->metaKey ($ data );
179+ $ summaryKey = self ::$ prefix . Summary::TYPE . self ::PROMETHEUS_METRIC_KEYS_SUFFIX ;
180+ $ metaKey = $ summaryKey . ': ' . $ this ->metaKey ($ data );
181181 $ json = json_encode ($ this ->metaData ($ data ));
182182 if ($ json === false ) {
183183 throw new RuntimeException (json_last_error_msg ());
184184 }
185185 $ this ->redis ->setNx ($ metaKey , $ json );
186186
187187 // store value key
188- $ valueKey = $ summaryKey. ': ' . $ this ->valueKey ($ data );
188+ $ valueKey = $ summaryKey . ': ' . $ this ->valueKey ($ data );
189189 $ json = json_encode ($ this ->encodeLabelValues ($ data ['labelValues ' ]));
190190 if ($ json === false ) {
191191 throw new RuntimeException (json_last_error_msg ());
@@ -195,7 +195,7 @@ public function updateSummary(array $data): void
195195 // trick to handle uniqid collision
196196 $ done = false ;
197197 while (! $ done ) {
198- $ sampleKey = $ valueKey. ': ' . uniqid ('' , true );
198+ $ sampleKey = $ valueKey . ': ' . uniqid ('' , true );
199199 $ done = $ this ->redis ->set ($ sampleKey , $ data ['value ' ], ['NX ' , 'EX ' => $ data ['maxAgeSeconds ' ]]);
200200 }
201201 }
@@ -229,7 +229,7 @@ public function updateGauge(array $data): void
229229 ,
230230 [
231231 $ this ->toMetricKey ($ data ),
232- self ::$ prefix. Gauge::TYPE . self ::PROMETHEUS_METRIC_KEYS_SUFFIX ,
232+ self ::$ prefix . Gauge::TYPE . self ::PROMETHEUS_METRIC_KEYS_SUFFIX ,
233233 $ this ->getRedisCommand ($ data ['command ' ]),
234234 json_encode ($ data ['labelValues ' ]),
235235 $ data ['value ' ],
@@ -261,7 +261,7 @@ public function updateCounter(array $data): void
261261 ,
262262 [
263263 $ this ->toMetricKey ($ data ),
264- self ::$ prefix. Counter::TYPE . self ::PROMETHEUS_METRIC_KEYS_SUFFIX ,
264+ self ::$ prefix . Counter::TYPE . self ::PROMETHEUS_METRIC_KEYS_SUFFIX ,
265265 $ this ->getRedisCommand ($ data ['command ' ]),
266266 $ data ['value ' ],
267267 json_encode ($ data ['labelValues ' ]),
@@ -288,7 +288,7 @@ protected function metaData(array $data): array
288288 */
289289 protected function collectHistograms (): array
290290 {
291- $ keys = $ this ->redis ->sMembers (self ::$ prefix. Histogram::TYPE . self ::PROMETHEUS_METRIC_KEYS_SUFFIX );
291+ $ keys = $ this ->redis ->sMembers (self ::$ prefix . Histogram::TYPE . self ::PROMETHEUS_METRIC_KEYS_SUFFIX );
292292 sort ($ keys );
293293 $ histograms = [];
294294 foreach ($ keys as $ key ) {
@@ -329,15 +329,15 @@ protected function collectHistograms(): array
329329 $ bucketKey = json_encode (['b ' => $ bucket , 'labelValues ' => $ labelValues ]);
330330 if (! isset ($ raw [$ bucketKey ])) {
331331 $ histogram ['samples ' ][] = [
332- 'name ' => $ histogram ['name ' ]. '_bucket ' ,
332+ 'name ' => $ histogram ['name ' ] . '_bucket ' ,
333333 'labelNames ' => ['le ' ],
334334 'labelValues ' => array_merge ($ labelValues , [$ bucket ]),
335335 'value ' => $ acc ,
336336 ];
337337 } else {
338338 $ acc += $ raw [$ bucketKey ];
339339 $ histogram ['samples ' ][] = [
340- 'name ' => $ histogram ['name ' ]. '_bucket ' ,
340+ 'name ' => $ histogram ['name ' ] . '_bucket ' ,
341341 'labelNames ' => ['le ' ],
342342 'labelValues ' => array_merge ($ labelValues , [$ bucket ]),
343343 'value ' => $ acc ,
@@ -347,15 +347,15 @@ protected function collectHistograms(): array
347347
348348 // Add the count
349349 $ histogram ['samples ' ][] = [
350- 'name ' => $ histogram ['name ' ]. '_count ' ,
350+ 'name ' => $ histogram ['name ' ] . '_count ' ,
351351 'labelNames ' => [],
352352 'labelValues ' => $ labelValues ,
353353 'value ' => $ acc ,
354354 ];
355355
356356 // Add the sum
357357 $ histogram ['samples ' ][] = [
358- 'name ' => $ histogram ['name ' ]. '_sum ' ,
358+ 'name ' => $ histogram ['name ' ] . '_sum ' ,
359359 'labelNames ' => [],
360360 'labelValues ' => $ labelValues ,
361361 'value ' => $ raw [json_encode (['b ' => 'sum ' , 'labelValues ' => $ labelValues ])],
@@ -381,9 +381,9 @@ protected function removePrefixFromKey(string $key): string
381381 */
382382 protected function collectSummaries (): array
383383 {
384- $ math = new Math ;
385- $ summaryKey = self ::$ prefix. Summary::TYPE . self ::PROMETHEUS_METRIC_KEYS_SUFFIX ;
386- $ keys = $ this ->redis ->keys ($ summaryKey. ':*:meta ' );
384+ $ math = new Math () ;
385+ $ summaryKey = self ::$ prefix . Summary::TYPE . self ::PROMETHEUS_METRIC_KEYS_SUFFIX ;
386+ $ keys = $ this ->redis ->keys ($ summaryKey . ':*:meta ' );
387387
388388 $ summaries = [];
389389 foreach ($ keys as $ metaKeyWithPrefix ) {
@@ -404,7 +404,7 @@ protected function collectSummaries(): array
404404 'samples ' => [],
405405 ];
406406
407- $ values = $ this ->redis ->keys ($ summaryKey. ': ' . $ metaData ['name ' ]. ':*:value ' );
407+ $ values = $ this ->redis ->keys ($ summaryKey . ': ' . $ metaData ['name ' ] . ':*:value ' );
408408 foreach ($ values as $ valueKeyWithPrefix ) {
409409 $ valueKey = $ this ->removePrefixFromKey ($ valueKeyWithPrefix );
410410 $ rawValue = $ this ->redis ->get ($ valueKey );
@@ -416,7 +416,7 @@ protected function collectSummaries(): array
416416 $ decodedLabelValues = $ this ->decodeLabelValues ($ encodedLabelValues );
417417
418418 $ samples = [];
419- $ sampleValues = $ this ->redis ->keys ($ summaryKey. ': ' . $ metaData ['name ' ]. ': ' . $ encodedLabelValues. ':value:* ' );
419+ $ sampleValues = $ this ->redis ->keys ($ summaryKey . ': ' . $ metaData ['name ' ] . ': ' . $ encodedLabelValues . ':value:* ' );
420420 foreach ($ sampleValues as $ sampleValueWithPrefix ) {
421421 $ sampleValue = $ this ->removePrefixFromKey ($ sampleValueWithPrefix );
422422 $ samples [] = (float ) $ this ->redis ->get ($ sampleValue );
@@ -445,15 +445,15 @@ protected function collectSummaries(): array
445445
446446 // Add the count
447447 $ data ['samples ' ][] = [
448- 'name ' => $ metaData ['name ' ]. '_count ' ,
448+ 'name ' => $ metaData ['name ' ] . '_count ' ,
449449 'labelNames ' => [],
450450 'labelValues ' => $ decodedLabelValues ,
451451 'value ' => count ($ samples ),
452452 ];
453453
454454 // Add the sum
455455 $ data ['samples ' ][] = [
456- 'name ' => $ metaData ['name ' ]. '_sum ' ,
456+ 'name ' => $ metaData ['name ' ] . '_sum ' ,
457457 'labelNames ' => [],
458458 'labelValues ' => $ decodedLabelValues ,
459459 'value ' => array_sum ($ samples ),
@@ -479,7 +479,7 @@ protected function collectSummaries(): array
479479 */
480480 protected function collectGauges (bool $ sortMetrics = true ): array
481481 {
482- $ keys = $ this ->redis ->sMembers (self ::$ prefix. Gauge::TYPE . self ::PROMETHEUS_METRIC_KEYS_SUFFIX );
482+ $ keys = $ this ->redis ->sMembers (self ::$ prefix . Gauge::TYPE . self ::PROMETHEUS_METRIC_KEYS_SUFFIX );
483483 sort ($ keys );
484484 $ gauges = [];
485485 foreach ($ keys as $ key ) {
@@ -521,7 +521,7 @@ protected function collectGauges(bool $sortMetrics = true): array
521521 */
522522 protected function collectCounters (bool $ sortMetrics = true ): array
523523 {
524- $ keys = $ this ->redis ->sMembers (self ::$ prefix. Counter::TYPE . self ::PROMETHEUS_METRIC_KEYS_SUFFIX );
524+ $ keys = $ this ->redis ->sMembers (self ::$ prefix . Counter::TYPE . self ::PROMETHEUS_METRIC_KEYS_SUFFIX );
525525 sort ($ keys );
526526 $ counters = [];
527527 foreach ($ keys as $ key ) {
@@ -620,7 +620,7 @@ protected function decodeLabelValues(string $values): array
620620 protected function throwMetricJsonException (string $ redisKey , ?string $ metricName = null ): void
621621 {
622622 $ metricName = $ metricName ?? 'unknown ' ;
623- $ message = 'Json error: ' . json_last_error_msg (). ' redis key : ' . $ redisKey. ' metric name: ' . $ metricName ;
623+ $ message = 'Json error: ' . json_last_error_msg () . ' redis key : ' . $ redisKey . ' metric name: ' . $ metricName ;
624624 throw new MetricJsonException ($ message , 0 , null , $ metricName );
625625 }
626626}
0 commit comments