fix(metrics,retry): address gold standard code review
Prometheus Metrics: - Add METRICS_LABELS fallback for defaultLabels env config - Separate includeSystem from collectDefaultMetrics with own env var - Parse URL in /metrics endpoint to support querystrings and trailing slashes - Sort keys in labelsToKey for stable/deterministic lookups - Update documentation with all environment variables Retry Utils: - Remove abort listener on sleep completion to prevent memory leak - Apply maxDelay cap AFTER jitter to guarantee max delay limit - Validate/normalize attempt parameter in calculateDelay - Count retries only when attempt > 1 (actual retry, not first try) - Use metrics.retryExhausted instead of generic errors for exhausted retries Tests: - Add consistency tests to verify retryConfigs.rsocket matches constants
This commit is contained in:
@@ -16,6 +16,8 @@ import {
|
||||
retryConfigs,
|
||||
getRetryDelayWithJitter,
|
||||
getAllRetryDelaysWithJitter,
|
||||
RETRY_BACKOFF_DELAYS,
|
||||
RETRY_JITTER_FACTOR,
|
||||
type RetryContext,
|
||||
} from '../../Utils/retry-utils.js'
|
||||
|
||||
@@ -615,3 +617,29 @@ describe('getAllRetryDelaysWithJitter', () => {
|
||||
expect(allSame).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('retryConfigs.rsocket consistency', () => {
|
||||
/**
|
||||
* This test ensures the hardcoded values in retryConfigs.rsocket
|
||||
* stay synchronized with RETRY_BACKOFF_DELAYS and RETRY_JITTER_FACTOR.
|
||||
*
|
||||
* The values are hardcoded to avoid ESM initialization order issues,
|
||||
* but this test will fail if someone updates the constants without
|
||||
* updating retryConfigs.rsocket.
|
||||
*/
|
||||
it('should have maxAttempts equal to RETRY_BACKOFF_DELAYS.length', () => {
|
||||
expect(retryConfigs.rsocket.maxAttempts).toBe(RETRY_BACKOFF_DELAYS.length)
|
||||
})
|
||||
|
||||
it('should have baseDelay equal to RETRY_BACKOFF_DELAYS[0]', () => {
|
||||
expect(retryConfigs.rsocket.baseDelay).toBe(RETRY_BACKOFF_DELAYS[0])
|
||||
})
|
||||
|
||||
it('should have maxDelay equal to last RETRY_BACKOFF_DELAYS element', () => {
|
||||
expect(retryConfigs.rsocket.maxDelay).toBe(RETRY_BACKOFF_DELAYS[RETRY_BACKOFF_DELAYS.length - 1])
|
||||
})
|
||||
|
||||
it('should have jitter equal to RETRY_JITTER_FACTOR', () => {
|
||||
expect(retryConfigs.rsocket.jitter).toBe(RETRY_JITTER_FACTOR)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user