@@ -18,6 +18,7 @@ const MAX_GITHUB_COUNT = 10_000_000_000;
1818const MAX_DURATION_MS = 90 * 24 * 60 * 60 * 1000 ;
1919const MAX_GITHUB_ROLLUP_ROWS = 2_000 ;
2020const MAX_GITHUB_RATE_LIMIT_ROWS = 256 ;
21+ const MAX_GITHUB_THROTTLE_ROWS = 7 * 24 * GITHUB_EGRESS_POOL_CLASSES . length * 2 ;
2122
2223const REVIEW_RANGES = [ "6h" , "24h" , "7d" ] as const ;
2324const REVIEW_LANES = [ "exact_event" , "hot_intake" , "normal_backfill" , "recovery" ] as const ;
@@ -860,6 +861,118 @@ function publicGithubRateLimits(value: unknown) {
860861 } ;
861862}
862863
864+ function publicGithubThrottleSeries (
865+ value : unknown ,
866+ hours : number ,
867+ bucketMinutes : number ,
868+ generatedAt : string ,
869+ rollupWindowComplete : boolean ,
870+ wireAttemptTotal : number ,
871+ incompleteTotal : number ,
872+ ) {
873+ if ( value === undefined ) return undefined ;
874+ const source = objectValue ( value ) ;
875+ const rawRows = Array . isArray ( source ?. rows ) ? source . rows : null ;
876+ const closedThrough = timestamp ( source ?. closed_through ) ;
877+ const firstAvailableBucketStart = nullableTimestamp ( source ?. first_available_bucket_start ) ;
878+ const excludedIncompleteCount = count ( source ?. excluded_incomplete_count , MAX_GITHUB_COUNT ) ;
879+ if (
880+ ! source ||
881+ source . unit !== "wire_attempt" ||
882+ ! rawRows ||
883+ rawRows . length > MAX_GITHUB_THROTTLE_ROWS ||
884+ ! closedThrough ||
885+ firstAvailableBucketStart === undefined ||
886+ excludedIncompleteCount === null ||
887+ excludedIncompleteCount > incompleteTotal ||
888+ typeof source . rows_truncated !== "boolean" ||
889+ typeof source . coverage_complete !== "boolean" ||
890+ typeof source . complete !== "boolean" ||
891+ ( source . rows_truncated && rawRows . length !== MAX_GITHUB_THROTTLE_ROWS )
892+ ) {
893+ return null ;
894+ }
895+ const bucketMs = bucketMinutes * 60_000 ;
896+ const generatedMs = Date . parse ( generatedAt ) ;
897+ const closedMs = Date . parse ( closedThrough ) ;
898+ const firstAvailableMs =
899+ firstAvailableBucketStart === null ? null : Date . parse ( firstAvailableBucketStart ) ;
900+ const windowStart = Math . floor ( ( generatedMs - hours * 3_600_000 ) / bucketMs ) * bucketMs ;
901+ if (
902+ closedMs !== Math . floor ( generatedMs / bucketMs ) * bucketMs ||
903+ ( firstAvailableMs !== null &&
904+ ( firstAvailableMs % bucketMs !== 0 || firstAvailableMs > closedMs ) )
905+ ) {
906+ return null ;
907+ }
908+ const rows = [ ] ;
909+ const seen = new Set < string > ( ) ;
910+ let total = 0 ;
911+ let earliestRow = Number . POSITIVE_INFINITY ;
912+ for ( const entry of rawRows ) {
913+ const row = objectValue ( entry ) ;
914+ const bucketStart = timestamp ( row ?. bucket_start ) ;
915+ const rowCount = positiveCount ( row ?. count , MAX_GITHUB_COUNT ) ;
916+ if (
917+ ! row ||
918+ ! bucketStart ||
919+ ! member ( GITHUB_EGRESS_POOL_CLASSES , row . pool_class ) ||
920+ ! member ( [ "403" , "429" ] , row . status_bucket ) ||
921+ rowCount === null
922+ ) {
923+ return null ;
924+ }
925+ const bucketStartMs = Date . parse ( bucketStart ) ;
926+ const key = `${ bucketStart } |${ row . pool_class } |${ row . status_bucket } ` ;
927+ total += rowCount ;
928+ if (
929+ bucketStartMs % bucketMs !== 0 ||
930+ bucketStartMs < windowStart ||
931+ bucketStartMs >= closedMs ||
932+ seen . has ( key ) ||
933+ total > wireAttemptTotal
934+ ) {
935+ return null ;
936+ }
937+ seen . add ( key ) ;
938+ earliestRow = Math . min ( earliestRow , bucketStartMs ) ;
939+ rows . push ( {
940+ bucket_start : bucketStart ,
941+ pool_class : row . pool_class ,
942+ status_bucket : row . status_bucket ,
943+ count : rowCount ,
944+ } ) ;
945+ }
946+ if (
947+ ( rows . length > 0 && firstAvailableMs === null ) ||
948+ ( firstAvailableMs !== null && firstAvailableMs > earliestRow )
949+ ) {
950+ return null ;
951+ }
952+ const coverageComplete = firstAvailableMs !== null && firstAvailableMs < windowStart ;
953+ const complete =
954+ ! source . rows_truncated &&
955+ excludedIncompleteCount === 0 &&
956+ rollupWindowComplete &&
957+ coverageComplete ;
958+ if ( source . coverage_complete !== coverageComplete || source . complete !== complete ) return null ;
959+ rows . sort ( ( left , right ) =>
960+ `${ left . bucket_start } |${ left . pool_class } |${ left . status_bucket } ` . localeCompare (
961+ `${ right . bucket_start } |${ right . pool_class } |${ right . status_bucket } ` ,
962+ ) ,
963+ ) ;
964+ return {
965+ unit : "wire_attempt" ,
966+ closed_through : closedThrough ,
967+ first_available_bucket_start : firstAvailableBucketStart ,
968+ rows,
969+ rows_truncated : source . rows_truncated ,
970+ excluded_incomplete_count : excludedIncompleteCount ,
971+ coverage_complete : coverageComplete ,
972+ complete,
973+ } ;
974+ }
975+
863976export function publicGithubEgressObservabilityProjection ( value : unknown ) {
864977 const source = objectValue ( value ) ;
865978 const privacySource = objectValue ( source ?. privacy ) ;
@@ -892,7 +1005,7 @@ export function publicGithubEgressObservabilityProjection(value: unknown) {
8921005 if (
8931006 source . version !== 2 ||
8941007 ! generatedAt ||
895- ! member ( [ 0.25 , 1 , 6 , 24 ] , hours ) ||
1008+ ! member ( [ 0.25 , 1 , 6 , 24 , 168 ] , hours ) ||
8961009 window . bucket_minutes !== ( Number ( hours ) <= 6 ? 5 : 60 )
8971010 ) {
8981011 return null ;
@@ -963,13 +1076,25 @@ export function publicGithubEgressObservabilityProjection(value: unknown) {
9631076 ( alreadyPublic
9641077 ? rateLimits . total === MAX_GITHUB_RATE_LIMIT_ROWS
9651078 : rawRateLimits ?. length === MAX_GITHUB_RATE_LIMIT_ROWS ) ;
1079+ const throttleSeries = publicGithubThrottleSeries (
1080+ source . throttle_series ,
1081+ Number ( hours ) ,
1082+ Number ( window . bucket_minutes ) ,
1083+ generatedAt ,
1084+ completenessSource . rollup_window_complete ,
1085+ units . wire_attempt ,
1086+ incompleteCount ,
1087+ ) ;
1088+ const rateLimitDetailHours = retentionSource . rate_limit_detail_hours ;
9661089 if (
9671090 completenessSource . observed !== expectedObserved ||
9681091 completenessSource . telemetry_complete !== expectedTelemetryComplete ||
9691092 completenessSource . query_complete !== expectedQueryComplete ||
9701093 unitTotal !== completenessTotal ||
9711094 ! rowsConserved ||
972- ! rateLimitTruncationValid
1095+ ! rateLimitTruncationValid ||
1096+ throttleSeries === null ||
1097+ ( rateLimitDetailHours !== undefined && rateLimitDetailHours !== 24 )
9731098 ) {
9741099 return null ;
9751100 }
@@ -980,7 +1105,9 @@ export function publicGithubEgressObservabilityProjection(value: unknown) {
9801105 units,
9811106 rows,
9821107 rate_limits : rateLimits ,
1108+ ...( throttleSeries === undefined ? { } : { throttle_series : throttleSeries } ) ,
9831109 retention : {
1110+ ...( rateLimitDetailHours === undefined ? { } : { rate_limit_detail_hours : 24 } ) ,
9841111 rollup_evicted_rows_total : rollupEvictedRows ,
9851112 rollup_eviction_count_exact : retentionSource . rollup_eviction_count_exact ,
9861113 rate_limit_evicted_rows_total : rateLimitEvictedRows ,
0 commit comments