feat(cookieless): Change cookieless constants to assume up to 72 hour ingestion lag (#41489)

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
This commit is contained in:
Robbie
2025-11-14 00:43:18 +00:00
committed by GitHub
parent 35cc7e06e5
commit fac3adf0ae
6 changed files with 76 additions and 16 deletions

View File

@@ -299,11 +299,11 @@ export function getDefaultConfig(): PluginsServerConfig {
COOKIELESS_FORCE_STATELESS_MODE: false,
COOKIELESS_DISABLED: false,
COOKIELESS_DELETE_EXPIRED_LOCAL_SALTS_INTERVAL_MS: 60 * 60 * 1000, // 1 hour
COOKIELESS_SESSION_TTL_SECONDS: 60 * 60 * 24, // 24 hours
COOKIELESS_SALT_TTL_SECONDS: 60 * 60 * 24, // 24 hours
COOKIELESS_SESSION_TTL_SECONDS: 60 * 60 * (72 + 24), // 96 hours (72 ingestion lag + 24 validity)
COOKIELESS_SALT_TTL_SECONDS: 60 * 60 * (72 + 24), // 96 hours (72 ingestion lag + 24 validity)
COOKIELESS_SESSION_INACTIVITY_MS: 30 * 60 * 1000, // 30 minutes
COOKIELESS_IDENTIFIES_TTL_SECONDS:
(24 + // max supported ingestion lag
(72 + // max supported ingestion lag in hours
12 + // max negative timezone in the world*/
14 + // max positive timezone in the world */
24) * // amount of time salt is valid in one timezone

View File

@@ -22,6 +22,7 @@ import {
extractRootDomain,
getRedisIdentifiesKey,
hashToDistinctId,
isCalendarDateValid,
sessionStateToBuffer,
toYYYYMMDDInTimezoneSafe,
} from './cookieless-manager'
@@ -113,6 +114,59 @@ describe('CookielessManager', () => {
})
})
describe('isCalendarDateValid', () => {
const fixedTime = new Date('2025-11-13T12:00:00Z')
beforeEach(() => {
jest.useFakeTimers({ now: fixedTime })
})
afterEach(() => {
jest.useRealTimers()
})
it('should accept today', () => {
// Fixed time: 2025-11-13 12:00 UTC
expect(isCalendarDateValid('2025-11-13')).toBe(true)
})
it('should accept yesterday', () => {
// Salt window for 2025-11-12: Nov 11 12:00 to Nov 15 14:00
// NOW (Nov 13 12:00) is within window
expect(isCalendarDateValid('2025-11-12')).toBe(true)
})
it('should accept 3 days ago (within 72h + timezone buffer)', () => {
// Salt window for 2025-11-10: Nov 9 12:00 to Nov 13 14:00
// NOW (Nov 13 12:00) is within window
expect(isCalendarDateValid('2025-11-10')).toBe(true)
})
it('should reject 4 days ago (salt window expired)', () => {
// Salt window for 2025-11-09: Nov 8 12:00 to Nov 12 14:00
// NOW (Nov 13 12:00) is after window ended
expect(isCalendarDateValid('2025-11-09')).toBe(false)
})
it('should reject 5 days ago (salt window expired)', () => {
// Salt window for 2025-11-08: Nov 7 12:00 to Nov 11 14:00
// NOW (Nov 13 12:00) is well after window ended
expect(isCalendarDateValid('2025-11-08')).toBe(false)
})
it('should reject tomorrow-ish dates', () => {
// Salt window for 2025-11-08: Nov 7 12:00 to Nov 11 14:00
// NOW (Nov 13 12:00) is well after window ended
expect(isCalendarDateValid('2025-11-15')).toBe(false)
})
it('should reject invalid date format', () => {
expect(isCalendarDateValid('not-a-date')).toBe(false)
expect(isCalendarDateValid('2025/01/01')).toBe(false)
expect(isCalendarDateValid('2025-13-01')).toBe(false)
})
})
describe('pipeline step', () => {
let hub: Hub
let organizationId: string

View File

@@ -83,6 +83,7 @@ export const COOKIELESS_MODE_FLAG_PROPERTY = '$cookieless_mode'
export const COOKIELESS_EXTRA_HASH_CONTENTS_PROPERTY = '$cookieless_extra'
const MAX_NEGATIVE_TIMEZONE_HOURS = 12
const MAX_POSITIVE_TIMEZONE_HOURS = 14
const MAX_SUPPORTED_INGESTION_LAG_HOURS = 72 // if changing this, you will also need to change the TTLs
interface CookielessConfig {
disabled: boolean
@@ -683,7 +684,7 @@ export function isCalendarDateValid(yyyymmdd: string): boolean {
startOfDayMinus12.setUTCHours(-MAX_NEGATIVE_TIMEZONE_HOURS) // Start at UTC12
const endOfDayPlus14 = new Date(utcDate)
endOfDayPlus14.setUTCHours(MAX_POSITIVE_TIMEZONE_HOURS + 24) // End at UTC+14
endOfDayPlus14.setUTCHours(MAX_POSITIVE_TIMEZONE_HOURS + MAX_SUPPORTED_INGESTION_LAG_HOURS) // End at UTC+14 (72h ingestion lag buffer)
const isGteMinimum = nowUTC >= startOfDayMinus12
const isLtMaximum = nowUTC < endOfDayPlus14