@@ -3,7 +3,7 @@ import { describe, expect, test } from 'bun:test'
33import {
44 KV_BLOCKS_DEGRADED_FRACTION ,
55 KV_BLOCKS_UNHEALTHY_FRACTION ,
6- PREFILL_QUEUE_DEGRADED_MS ,
6+ PREFILL_QUEUE_P90_DEGRADED_MS ,
77 classify ,
88} from '../fireworks-health'
99
@@ -19,20 +19,22 @@ function kvBlocks(value: number): PromSample {
1919 }
2020}
2121
22- /** Emit a minimal cumulative-counts histogram for prefill queue where every
23- * event lands in exactly one bucket `le`. */
24- function prefillQueueBuckets ( p50Ms : number ) : PromSample [ ] {
22+ /** Emit a cumulative-counts histogram for prefill queue where the p90
23+ * percentile falls in the bucket with le ≥ p90Ms (i.e. p90 ≥ p90Ms).
24+ * Uses 10 total events all landing in that bucket, so the 90th-percentile
25+ * interpolates within the bucket above the bucket boundary. */
26+ function prefillQueueBuckets ( p90Ms : number ) : PromSample [ ] {
2527 const les = [ 50 , 150 , 300 , 500 , 750 , 1000 , 1500 , 3000 , 5000 , 7500 , 10000 ]
2628 const name = 'latency_prefill_queue_ms_bucket:sum_by_deployment'
27- // cumulative count = 0 below p50, 1 at and above p50
29+ const total = 10
2830 return les . map ( ( le ) => ( {
2931 name,
3032 labels : { deployment_id : DEPLOY , le : String ( le ) } ,
31- value : le >= p50Ms ? 1 : 0 ,
33+ value : le >= p90Ms ? total : 0 ,
3234 } ) ) . concat ( {
3335 name,
3436 labels : { deployment_id : DEPLOY , le : '+Inf' } ,
35- value : 1 ,
37+ value : total ,
3638 } )
3739}
3840
@@ -58,10 +60,10 @@ describe('fireworks health classifier', () => {
5860 expect ( classify ( samples , [ DEPLOY ] ) ) . toBe ( 'healthy' )
5961 } )
6062
61- test ( 'degraded when prefill queue p50 exceeds the threshold' , ( ) => {
63+ test ( 'degraded when prefill queue p90 exceeds the threshold' , ( ) => {
6264 const samples : PromSample [ ] = [
6365 kvBlocks ( 0.5 ) ,
64- ...prefillQueueBuckets ( PREFILL_QUEUE_DEGRADED_MS + 500 ) ,
66+ ...prefillQueueBuckets ( PREFILL_QUEUE_P90_DEGRADED_MS + 500 ) ,
6567 ]
6668 expect ( classify ( samples , [ DEPLOY ] ) ) . toBe ( 'degraded' )
6769 } )
@@ -110,7 +112,7 @@ describe('fireworks health classifier', () => {
110112 const other = 'other123'
111113 const samples : PromSample [ ] = [
112114 kvBlocks ( 0.5 ) ,
113- ...prefillQueueBuckets ( PREFILL_QUEUE_DEGRADED_MS + 500 ) ,
115+ ...prefillQueueBuckets ( PREFILL_QUEUE_P90_DEGRADED_MS + 500 ) ,
114116 {
115117 name : 'generator_kv_blocks_fraction:avg_by_deployment' ,
116118 labels : { deployment_id : other } ,
0 commit comments