|
7 | 7 | use Generator; |
8 | 8 | use Mockery; |
9 | 9 | use PHPUnit\Framework\TestCase; |
| 10 | +use Psr\Log\NullLogger; |
| 11 | +use Zlodes\PrometheusClient\Collector\ByType\CounterCollector; |
10 | 12 | use Zlodes\PrometheusClient\Fetcher\DTO\FetchedMetric; |
11 | 13 | use Zlodes\PrometheusClient\Fetcher\StoredMetricsFetcher; |
12 | 14 | use Zlodes\PrometheusClient\Metric\Counter; |
|
22 | 24 | use Zlodes\PrometheusClient\Storage\DTO\MetricNameWithLabels; |
23 | 25 | use Zlodes\PrometheusClient\Storage\DTO\MetricValue; |
24 | 26 | use Zlodes\PrometheusClient\Storage\DTO\SummaryMetricValue; |
| 27 | +use Zlodes\PrometheusClient\Storage\InMemory\InMemoryCounterStorage; |
| 28 | +use Zlodes\PrometheusClient\Tests\Stubs\GaugeStorageStub; |
| 29 | +use Zlodes\PrometheusClient\Tests\Stubs\HistogramStorageStub; |
| 30 | +use Zlodes\PrometheusClient\Tests\Stubs\SummaryStorageStub; |
25 | 31 |
|
26 | 32 | /** |
27 | 33 | * Kinda stupid test to check that the fetcher return metric as expected: with correct values and order |
@@ -108,7 +114,7 @@ public function testFetch(): void |
108 | 114 |
|
109 | 115 | $summaryStorageMock |
110 | 116 | ->expects('fetchSummaries') |
111 | | - ->andReturnUsing(static function(): Generator { |
| 117 | + ->andReturnUsing(static function (): Generator { |
112 | 118 | yield new SummaryMetricValue( |
113 | 119 | new MetricNameWithLabels('memory_usage'), |
114 | 120 | [300, 500, 200, 500, 400] |
@@ -245,4 +251,34 @@ public function testFetch(): void |
245 | 251 | self::assertSame([], $fetchedSummary->values[3]->metricNameWithLabels->labels); |
246 | 252 | self::assertSame(5, $fetchedSummary->values[3]->value); |
247 | 253 | } |
| 254 | + |
| 255 | + /** |
| 256 | + * Storage can return metric that was removed from the registry, it shouldn't break the fetcher |
| 257 | + */ |
| 258 | + public function testRemovedMetricExistsInStorage(): void |
| 259 | + { |
| 260 | + $counterStorage = new InMemoryCounterStorage(); |
| 261 | + |
| 262 | + $counter = new Counter('foo_counter', 'help'); |
| 263 | + |
| 264 | + $counterCollector = new CounterCollector( |
| 265 | + $counter, |
| 266 | + $counterStorage, |
| 267 | + new NullLogger(), |
| 268 | + ); |
| 269 | + |
| 270 | + $counterCollector->increment(); |
| 271 | + |
| 272 | + $fetcher = new StoredMetricsFetcher( |
| 273 | + registry: new ArrayRegistry(), |
| 274 | + counterStorage: $counterStorage, |
| 275 | + gaugeStorage: new GaugeStorageStub(), |
| 276 | + histogramStorage: new HistogramStorageStub(), |
| 277 | + summaryStorage: new SummaryStorageStub(), |
| 278 | + ); |
| 279 | + |
| 280 | + $fetched = [...$fetcher->fetch()]; |
| 281 | + |
| 282 | + self::assertEmpty($fetched); |
| 283 | + } |
248 | 284 | } |
0 commit comments