File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed
tests/Test/Prometheus/Storage Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -396,6 +396,9 @@ private function collectHistograms(): array
396
396
$ histograms = [];
397
397
foreach ($ keys as $ key ) {
398
398
$ raw = $ this ->redis ->hGetAll (str_replace ($ this ->redis ->_prefix ('' ), '' , $ key ));
399
+ if (!isset ($ raw ['__meta ' ])) {
400
+ continue ;
401
+ }
399
402
$ histogram = json_decode ($ raw ['__meta ' ], true );
400
403
unset($ raw ['__meta ' ]);
401
404
$ histogram ['samples ' ] = [];
@@ -576,6 +579,9 @@ private function collectGauges(): array
576
579
$ gauges = [];
577
580
foreach ($ keys as $ key ) {
578
581
$ raw = $ this ->redis ->hGetAll (str_replace ($ this ->redis ->_prefix ('' ), '' , $ key ));
582
+ if (!isset ($ raw ['__meta ' ])) {
583
+ continue ;
584
+ }
579
585
$ gauge = json_decode ($ raw ['__meta ' ], true );
580
586
unset($ raw ['__meta ' ]);
581
587
$ gauge ['samples ' ] = [];
@@ -605,6 +611,9 @@ private function collectCounters(): array
605
611
$ counters = [];
606
612
foreach ($ keys as $ key ) {
607
613
$ raw = $ this ->redis ->hGetAll (str_replace ($ this ->redis ->_prefix ('' ), '' , $ key ));
614
+ if (!isset ($ raw ['__meta ' ])) {
615
+ continue ;
616
+ }
608
617
$ counter = json_decode ($ raw ['__meta ' ], true );
609
618
unset($ raw ['__meta ' ]);
610
619
$ counter ['samples ' ] = [];
Original file line number Diff line number Diff line change @@ -146,4 +146,33 @@ public function itShouldOnlyConnectOnceForInjectedRedisConnectionOnSubsequentCal
146
146
$ this ->redisConnection ->rawCommand ('client ' , 'list ' )
147
147
);
148
148
}
149
+
150
+ /**
151
+ * @test
152
+ */
153
+ public function itShouldCollectMetricsAndIgnoreInvalidMetricsWithoutMetaData (): void
154
+ {
155
+ $ redisConnection = $ this ->createMock (\Redis::class);
156
+ $ redisConnection ->method ('isConnected ' )->willReturn (true );
157
+ $ redisConnection ->method ('_prefix ' )->willReturnArgument (0 );
158
+ $ redisConnection ->method ('keys ' )->with ('PROMETHEUS_summary_METRIC_KEYS:*:meta ' )->willReturn ([]);
159
+ $ redisConnection ->method ('sMembers ' )
160
+ ->withConsecutive (
161
+ ['PROMETHEUS_histogram_METRIC_KEYS ' ],
162
+ ['PROMETHEUS_gauge_METRIC_KEYS ' ],
163
+ ['PROMETHEUS_counter_METRIC_KEYS ' ]
164
+ )
165
+ ->willReturnOnConsecutiveCalls (
166
+ ['key_histogramm ' ],
167
+ ['key_gauge ' ],
168
+ ['key_counter ' ],
169
+ )
170
+ ;
171
+ $ redisConnection ->method ('hGetAll ' )->willReturn (['any_invalid_data ' => '' ]);
172
+
173
+ $ redis = Redis::fromExistingConnection ($ redisConnection );
174
+ $ metrics = $ redis ->collect ();
175
+
176
+ self ::assertEquals ([], $ metrics );
177
+ }
149
178
}
You can’t perform that action at this time.
0 commit comments