@@ -709,6 +709,65 @@ describe('HTTP request handler', () => {
709
709
] )
710
710
} )
711
711
} )
712
+
713
+ describe ( 'miner retrieval time stats' , ( ) => {
714
+ beforeEach ( async ( ) => {
715
+ // before the range
716
+ await givenRetrievalTimes ( pgPools . evaluate , { day : '2024-01-09' , minerId : 'f1one' , taskId : 'cidone::f1one::0' , timeToFirstByteP50 : 1000 } )
717
+ await givenRetrievalTimes ( pgPools . evaluate , { day : '2024-01-09' , minerId : 'f1two' , taskId : 'cidone::f1two::0' , timeToFirstByteP50 : 1000 } )
718
+ // in the range
719
+ await givenRetrievalTimes ( pgPools . evaluate , { day : '2024-01-20' , minerId : 'f1one' , taskId : 'cidone::f1one::1' , timeToFirstByteP50 : 1000 } )
720
+ await givenRetrievalTimes ( pgPools . evaluate , { day : '2024-01-20' , minerId : 'f1two' , taskId : 'cidone::f1two::1' , timeToFirstByteP50 : 1000 } )
721
+
722
+ await givenRetrievalTimes ( pgPools . evaluate , { day : '2024-01-10' , minerId : 'f1one' , taskId : 'cidone::f1one::2' , timeToFirstByteP50 : 3000 } )
723
+ await givenRetrievalTimes ( pgPools . evaluate , { day : '2024-01-10' , minerId : 'f1two' , taskId : 'cidone::f1two::2' , timeToFirstByteP50 : 3000 } )
724
+ await givenRetrievalTimes ( pgPools . evaluate , { day : '2024-01-10' , minerId : 'f1one' , taskId : 'cidone::f1one::3' , timeToFirstByteP50 : 1000 } )
725
+ await givenRetrievalTimes ( pgPools . evaluate , { day : '2024-01-10' , minerId : 'f1two' , taskId : 'cidone::f1two::3' , timeToFirstByteP50 : 1000 } )
726
+ // after the range
727
+ await givenRetrievalTimes ( pgPools . evaluate , { day : '2024-01-21' , minerId : 'f1one' , taskId : 'cidone::f1one::4' , timeToFirstByteP50 : 1000 } )
728
+ await givenRetrievalTimes ( pgPools . evaluate , { day : '2024-01-21' , minerId : 'f1two' , taskId : 'cidone::f1two::4' , timeToFirstByteP50 : 1000 } )
729
+ } )
730
+
731
+ it ( 'lists daily retrieval times in given date range' , async ( ) => {
732
+ const res = await fetch (
733
+ new URL (
734
+ '/retrieval-times/daily?from=2024-01-10&to=2024-01-20' ,
735
+ baseUrl
736
+ ) , {
737
+ redirect : 'manual'
738
+ }
739
+ )
740
+ await assertResponseStatus ( res , 200 )
741
+
742
+ const stats = /** @type {{ day: string, success_rate: number }[] } */ (
743
+ await res . json ( )
744
+ )
745
+ assert . deepStrictEqual ( stats , [
746
+ { day : '2024-01-10' , ttfb_p50 : 2000 } ,
747
+ { day : '2024-01-20' , ttfb_p50 : 1000 }
748
+ ] )
749
+ } )
750
+
751
+ it ( 'lists daily retrieval times summary for specified miner in given date range' , async ( ) => {
752
+ const res = await fetch (
753
+ new URL (
754
+ '/miner/f1one/retrieval-times/summary?from=2024-01-10&to=2024-01-20' ,
755
+ baseUrl
756
+ ) , {
757
+ redirect : 'manual'
758
+ }
759
+ )
760
+ await assertResponseStatus ( res , 200 )
761
+
762
+ const stats = /** @type {{ day: string, success_rate: number }[] } */ (
763
+ await res . json ( )
764
+ )
765
+ assert . deepStrictEqual ( stats , [
766
+ { day : '2024-01-10' , miner_id : 'f1one' , ttfb_p50 : 2000 } ,
767
+ { day : '2024-01-20' , miner_id : 'f1one' , ttfb_p50 : 1000 }
768
+ ] )
769
+ } )
770
+ } )
712
771
} )
713
772
714
773
/**
@@ -784,3 +843,19 @@ const givenDailyDealStats = async (pgPool, {
784
843
retrievable
785
844
] )
786
845
}
846
+
847
+ /**
848
+ *
849
+ * @param {import('../lib/platform-stats-fetchers.js').Queryable } pgPool
850
+ * @param {object } data
851
+ * @param {string } data.day
852
+ * @param {string } data.minerId
853
+ * @param {string } data.taskId
854
+ * @param {number } data.timeToFirstByteP50
855
+ */
856
+ const givenRetrievalTimes = async ( pgPool , { day, minerId, taskId, timeToFirstByteP50 } ) => {
857
+ await pgPool . query (
858
+ 'INSERT INTO retrieval_times (day, miner_id, task_id, time_to_first_byte_p50) VALUES ($1, $2, $3, $4)' ,
859
+ [ day , minerId ?? 'f1test' , taskId ?? 'cidone::f1test::0' , timeToFirstByteP50 ]
860
+ )
861
+ }
0 commit comments