@@ -324,11 +324,11 @@ public function testSetAndGetGauge(): void
324324 public function testSetGaugeReplaces (): void
325325 {
326326 $ this ->usage ->setGauges ([
327- ['metric ' => 'storage.bytes ' , 'value ' => 1000 , ' period ' => ' 1d ' ],
327+ ['metric ' => 'storage.bytes ' , 'value ' => 1000 ],
328328 ]);
329329
330330 $ this ->usage ->setGauges ([
331- ['metric ' => 'storage.bytes ' , 'value ' => 2000 , ' period ' => ' 1d ' ],
331+ ['metric ' => 'storage.bytes ' , 'value ' => 2000 ],
332332 ]);
333333
334334 $ value = $ this ->usage ->getGauge ('storage.bytes ' );
@@ -338,27 +338,24 @@ public function testSetGaugeReplaces(): void
338338 public function testQueryGauges (): void
339339 {
340340 $ this ->usage ->setGauges ([
341- ['metric ' => 'projects.count ' , 'value ' => 10 , ' period ' => ' 1d ' ],
342- ['metric ' => 'databases.count ' , 'value ' => 5 , ' period ' => ' 1d ' ],
343- ['metric ' => 'functions.count ' , 'value ' => 3 , ' period ' => ' 1d ' ],
341+ ['metric ' => 'projects.count ' , 'value ' => 10 ],
342+ ['metric ' => 'databases.count ' , 'value ' => 5 ],
343+ ['metric ' => 'functions.count ' , 'value ' => 3 ],
344344 ]);
345345
346- $ results = $ this ->usage ->queryGauges (
347- period: '1d ' ,
348- );
346+ $ results = $ this ->usage ->queryGauges ();
349347
350348 $ this ->assertCount (3 , $ results );
351349 }
352350
353351 public function testQueryGaugesGroupByMetric (): void
354352 {
355353 $ this ->usage ->setGauges ([
356- ['metric ' => 'projects.count ' , 'value ' => 10 , ' period ' => ' 1d ' ],
357- ['metric ' => 'databases.count ' , 'value ' => 5 , ' period ' => ' 1d ' ],
354+ ['metric ' => 'projects.count ' , 'value ' => 10 ],
355+ ['metric ' => 'databases.count ' , 'value ' => 5 ],
358356 ]);
359357
360358 $ results = $ this ->usage ->queryGauges (
361- period: '1d ' ,
362359 groupBy: ['metric ' ],
363360 );
364361
@@ -368,34 +365,33 @@ public function testQueryGaugesGroupByMetric(): void
368365 public function testGaugeWithResource (): void
369366 {
370367 $ this ->usage ->setGauges ([
371- ['metric ' => 'storage.bytes ' , 'value ' => 1000 , 'resource ' => 'bucket-1 ' , ' period ' => ' 1d ' ],
372- ['metric ' => 'storage.bytes ' , 'value ' => 2000 , 'resource ' => 'bucket-2 ' , ' period ' => ' 1d ' ],
368+ ['metric ' => 'storage.bytes ' , 'value ' => 1000 , 'resource ' => 'bucket-1 ' ],
369+ ['metric ' => 'storage.bytes ' , 'value ' => 2000 , 'resource ' => 'bucket-2 ' ],
373370 ]);
374371
375372 $ value = $ this ->usage ->getGauge ('storage.bytes ' , ['resource ' => 'bucket-1 ' ]);
376373 $ this ->assertEquals (1000 , $ value );
377374 }
378375
379- public function testGaugeHourlyAndDaily (): void
376+ public function testGaugeLatestValueReturned (): void
380377 {
381378 $ this ->usage ->setGauges ([
382- ['metric ' => 'active.users ' , 'value ' => 100 , 'period ' => '1h ' ],
383- ['metric ' => 'active.users ' , 'value ' => 500 , 'period ' => '1d ' ],
379+ ['metric ' => 'active.users ' , 'value ' => 100 ],
384380 ]);
385381
386- $ hourlyResults = $ this ->usage ->queryGauges (
387- filters: ['metric ' => 'active.users ' ],
388- period: '1h ' ,
389- );
390- $ dailyResults = $ this ->usage ->queryGauges (
382+ // Second write with a newer timestamp
383+ usleep (10_000 ); // 10ms to ensure different timestamp
384+ $ this ->usage ->setGauges ([
385+ ['metric ' => 'active.users ' , 'value ' => 500 ],
386+ ]);
387+
388+ $ value = $ this ->usage ->getGauge ('active.users ' );
389+ $ this ->assertEquals (500 , $ value );
390+
391+ $ results = $ this ->usage ->queryGauges (
391392 filters: ['metric ' => 'active.users ' ],
392- period: '1d ' ,
393393 );
394-
395- $ this ->assertCount (1 , $ hourlyResults );
396- $ this ->assertCount (1 , $ dailyResults );
397- $ this ->assertEquals (100 , $ hourlyResults [0 ]['value ' ]);
398- $ this ->assertEquals (500 , $ dailyResults [0 ]['value ' ]);
394+ $ this ->assertGreaterThanOrEqual (1 , count ($ results ));
399395 }
400396
401397 public function testSetGaugesEmpty (): void
@@ -437,7 +433,7 @@ public function testPurgeEventsWithFilter(): void
437433 public function testPurgeGauges (): void
438434 {
439435 $ this ->usage ->setGauges ([
440- ['metric ' => 'projects.count ' , 'value ' => 10 , ' period ' => ' 1d ' ],
436+ ['metric ' => 'projects.count ' , 'value ' => 10 ],
441437 ]);
442438
443439 $ this ->assertTrue ($ this ->usage ->purgeGauges ());
@@ -449,7 +445,7 @@ public function testPurgeGauges(): void
449445 public function testPurgeAll (): void
450446 {
451447 $ this ->usage ->addEvents ([['metric ' => 'test ' , 'value ' => 1 ]]);
452- $ this ->usage ->setGauges ([['metric ' => 'test.gauge ' , 'value ' => 1 , ' period ' => ' 1d ' ]]);
448+ $ this ->usage ->setGauges ([['metric ' => 'test.gauge ' , 'value ' => 1 ]]);
453449
454450 $ this ->assertTrue ($ this ->usage ->purge ());
455451
@@ -478,8 +474,8 @@ public function testCollectEventAndFlush(): void
478474
479475 public function testCollectGaugeAndFlush (): void
480476 {
481- $ this ->usage ->collectGauge (['metric ' => 'projects.count ' , 'value ' => 10 , ' period ' => ' 1d ' ]);
482- $ this ->usage ->collectGauge (['metric ' => 'projects.count ' , 'value ' => 20 , ' period ' => ' 1d ' ]);
477+ $ this ->usage ->collectGauge (['metric ' => 'projects.count ' , 'value ' => 10 ]);
478+ $ this ->usage ->collectGauge (['metric ' => 'projects.count ' , 'value ' => 20 ]);
483479
484480 $ this ->assertEquals (2 , $ this ->usage ->getBufferCount ());
485481 $ this ->assertEquals (1 , $ this ->usage ->getBufferSize ());
@@ -493,7 +489,7 @@ public function testCollectGaugeAndFlush(): void
493489 public function testMixedCollectAndFlush (): void
494490 {
495491 $ this ->usage ->collectEvent (['metric ' => 'api.request ' , 'value ' => 1 ]);
496- $ this ->usage ->collectGauge (['metric ' => 'projects.count ' , 'value ' => 5 , ' period ' => ' 1d ' ]);
492+ $ this ->usage ->collectGauge (['metric ' => 'projects.count ' , 'value ' => 5 ]);
497493
498494 $ this ->assertEquals (2 , $ this ->usage ->getBufferSize ());
499495
@@ -661,10 +657,10 @@ public function testAnalyticsTopPaths(): void
661657 public function testGaugeResourceInventory (): void
662658 {
663659 $ this ->usage ->setGauges ([
664- ['metric ' => 'projects.count ' , 'value ' => 15 , ' period ' => ' 1d ' ],
665- ['metric ' => 'databases.count ' , 'value ' => 42 , ' period ' => ' 1d ' ],
666- ['metric ' => 'functions.count ' , 'value ' => 8 , ' period ' => ' 1d ' ],
667- ['metric ' => 'storage.bytes ' , 'value ' => 1073741824 , ' period ' => ' 1d ' ],
660+ ['metric ' => 'projects.count ' , 'value ' => 15 ],
661+ ['metric ' => 'databases.count ' , 'value ' => 42 ],
662+ ['metric ' => 'functions.count ' , 'value ' => 8 ],
663+ ['metric ' => 'storage.bytes ' , 'value ' => 1073741824 ],
668664 ]);
669665
670666 $ this ->assertEquals (15 , $ this ->usage ->getGauge ('projects.count ' ));
@@ -676,8 +672,8 @@ public function testGaugeResourceInventory(): void
676672 public function testGaugePerResourceCounts (): void
677673 {
678674 $ this ->usage ->setGauges ([
679- ['metric ' => 'databases.count ' , 'value ' => 3 , 'resource ' => 'proj-a ' , ' period ' => ' 1d ' ],
680- ['metric ' => 'databases.count ' , 'value ' => 7 , 'resource ' => 'proj-b ' , ' period ' => ' 1d ' ],
675+ ['metric ' => 'databases.count ' , 'value ' => 3 , 'resource ' => 'proj-a ' ],
676+ ['metric ' => 'databases.count ' , 'value ' => 7 , 'resource ' => 'proj-b ' ],
681677 ]);
682678
683679 $ projA = $ this ->usage ->getGauge ('databases.count ' , ['resource ' => 'proj-a ' ]);
@@ -730,29 +726,28 @@ public function testSharedTablesIsolation(): void
730726 $ usage ->purge ();
731727 }
732728
733- // ─── Infinite Period (lifetime totals) ─────────────────────────
729+ // ─── Gauge: Multiple Metrics ─────────── ─────────────────────────
734730
735- public function testGaugeInfinitePeriod (): void
731+ public function testGaugeMultipleMetrics (): void
736732 {
737733 $ this ->usage ->setGauges ([
738- ['metric ' => 'databases ' , 'value ' => 5 , ' period ' => ' inf ' ],
739- ['metric ' => 'collections ' , 'value ' => 20 , ' period ' => ' inf ' ],
734+ ['metric ' => 'databases ' , 'value ' => 5 ],
735+ ['metric ' => 'collections ' , 'value ' => 20 ],
740736 ]);
741737
742- $ results = $ this ->usage ->queryGauges (
743- period: 'inf ' ,
744- );
738+ $ results = $ this ->usage ->queryGauges ();
745739
746740 $ this ->assertCount (2 , $ results );
747741 }
748742
749- public function testGaugeInfinitePeriodReplace (): void
743+ public function testGaugeGetLatestAfterMultipleWrites (): void
750744 {
751745 $ this ->usage ->setGauges ([
752- ['metric ' => 'databases ' , 'value ' => 5 , ' period ' => ' inf ' ],
746+ ['metric ' => 'databases ' , 'value ' => 5 ],
753747 ]);
748+ usleep (10_000 );
754749 $ this ->usage ->setGauges ([
755- ['metric ' => 'databases ' , 'value ' => 8 , ' period ' => ' inf ' ],
750+ ['metric ' => 'databases ' , 'value ' => 8 ],
756751 ]);
757752
758753 $ value = $ this ->usage ->getGauge ('databases ' );
0 commit comments