@@ -25,7 +25,7 @@ const REPLICA_REQUEST_TIMEOUT_MS = 30_000;
25
25
/**
26
26
* This package canary monitors the availability of the versions of a specified
27
27
* package in the ConstructHub catalog. It publishes metrics that help
28
- * understand how much time passes between a pakcage appearing in the public
28
+ * understand how much time passes between a package appearing in the public
29
29
* registry and it's availability in the ConstructHub instance.
30
30
*
31
31
* From the moment a package has been published, and until it appeared in
@@ -74,8 +74,6 @@ export async function handler(event: unknown): Promise<void> {
74
74
updateLatestIfNeeded ( state , latest ) ;
75
75
76
76
try {
77
- const replicaLag = await stateService . npmReplicaLagSeconds ( packageName ) ;
78
-
79
77
await metricScope ( ( metrics ) => async ( ) => {
80
78
// Clear out default dimensions as we don't need those. See https://github.com/awslabs/aws-embedded-metrics-node/issues/73.
81
79
metrics . setDimensions ( { } ) ;
@@ -89,16 +87,6 @@ export async function handler(event: unknown): Promise<void> {
89
87
( await stateService . isNpmReplicaDown ( ) ) ? 1 : 0 ,
90
88
Unit . None
91
89
) ;
92
-
93
- // If we weren't able to calculate the replica's lag, then simply
94
- // don't report the metric.
95
- if ( replicaLag !== undefined ) {
96
- metrics . putMetric (
97
- MetricName . NPM_REPLICA_LAG ,
98
- replicaLag ,
99
- Unit . Seconds
100
- ) ;
101
- }
102
90
} ) ( ) ;
103
91
104
92
for ( const versionState of [
@@ -384,63 +372,6 @@ export class CanaryStateService {
384
372
}
385
373
}
386
374
387
- /**
388
- * Estimate how far behind the NPM replica is compared to the live NPM
389
- * registry. If the NPM replica is down, return undefined.
390
- */
391
- public async npmReplicaLagSeconds (
392
- packageName : string
393
- ) : Promise < number | undefined > {
394
- const encodedPackageName = encodeURIComponent ( packageName ) ;
395
-
396
- console . log ( `Measuring NPM replica lag using ${ packageName } ...` ) ;
397
-
398
- const primaryDate = await getModifiedTimestamp ( `registry.npmjs.org` ) ;
399
-
400
- let replicaDate ;
401
- try {
402
- replicaDate = await getModifiedTimestamp (
403
- `replicate.npmjs.com/registry` ,
404
- REPLICA_REQUEST_TIMEOUT_MS
405
- ) ;
406
- } catch ( e ) {
407
- if ( e instanceof Error && e . message . includes ( 'HTTP 504' ) ) {
408
- console . log (
409
- `Warning: error fetching replicate.npmjs.com: ${ e . toString ( ) } `
410
- ) ;
411
- // There is no value to report
412
- return undefined ;
413
- } else {
414
- throw e ;
415
- }
416
- }
417
-
418
- const deltaMs = primaryDate . getTime ( ) - replicaDate . getTime ( ) ;
419
-
420
- console . log ( `Timestamp on primary: ${ primaryDate . toISOString ( ) } ` ) ;
421
- console . log (
422
- `Timestamp on replica: ${ replicaDate . toISOString ( ) } (${
423
- deltaMs / 3_600_000
424
- } hours behind)`
425
- ) ;
426
-
427
- // We return in seconds... The millisecond resolution is silly here since the probe package is
428
- // only published approximately once every three hours. We use seconds only because this is the
429
- // largest available time unit in CloudWatch.
430
- return deltaMs / 1_000 ;
431
-
432
- async function getModifiedTimestamp (
433
- baseUrl : string ,
434
- timeoutMillis ?: number
435
- ) {
436
- const isoDate = await getJSON (
437
- `https://${ baseUrl } /${ encodedPackageName } ` ,
438
- { jsonPath : [ 'time' , 'modified' ] , timeoutMillis }
439
- ) ;
440
- return new Date ( isoDate ) ;
441
- }
442
- }
443
-
444
375
private key ( packageName : string ) : string {
445
376
return `${ ObjectKey . STATE_PREFIX } ${ packageName } ${ ObjectKey . STATE_SUFFIX } ` ;
446
377
}
@@ -534,6 +465,7 @@ function getJSON(
534
465
headers : {
535
466
Accept : 'application/json' ,
536
467
'Accept-Encoding' : 'identity' ,
468
+ 'npm-replication-opt-in' : 'true' , // can be deleted after May 29: https://github.com/orgs/community/discussions/152515
537
469
} ,
538
470
timeout : timeoutMillis ,
539
471
} ,
0 commit comments