Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(ai-research): remove Redis crawl history fallback (#85931)

Robbie7698a364dea0
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/README.md b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/README.md
index 246d784c16a4..4712a02cff04 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/README.md
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/README.md
@@ -15,7 +15,7 @@ code is written against. Where the code and this file disagree, one of them is a
| Frontier | The topic `session_replay_image_fetch`. It holds the URLs waiting to be fetched. |
| Back queue | The URLs of one registrable domain. The topic key is the domain, so a partition holds whole back queues. |
| Pass | The fetching for one Kafka poll batch. Every back queue in the batch runs at the same time, and wall time bounds the pass rather than work. |
-| Crawl history | The shared record of URLs this lane has finished with, whatever the outcome. A table setting selects DynamoDB; otherwise the lane uses Redis. |
+| Crawl history | The DynamoDB record of URLs this lane has finished with, whatever the outcome. Entries have a 30-day TTL. |
| Host budget | The token bucket, connection limit, and circuit breaker for one registrable domain. The rate moves by AIMD: a failure halves it, and success raises it slowly. |
| Hop | One trip a URL makes back through Kafka. The lane spends a hop when it puts a URL back: a retry, a redirect that left the domain, or a URL that arrived before its wait ended. A redirect the lane follows in place costs no hop. |
| Hop budget | The number of hops one URL may make before the lane gives up. |
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/crawl-history.test.ts b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/crawl-history.test.ts
deleted file mode 100644
index 39b145e10aa9..000000000000
--- a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/crawl-history.test.ts
+++ /dev/null
@@ -1,120 +0,0 @@
-import { CrawlHistory, CrawlHistoryRedis, CrawlHistoryRedisPool } from './crawl-history'
-
-/** Above one round trip's key limit, so every test crosses a chunk boundary. */
-const KEYS = Array.from({ length: 600 }, (_value, index) => `k${index}`)
-const NOW_MS = 1_700_000_000_000
-
-type ExecResult = [Error | null, unknown][] | null
-
-class FakeClient implements CrawlHistoryRedis {
- public readonly pipelined: string[] = []
- constructor(
- private readonly behavior: {
- mget?: (keys: string[]) => (string | null)[] | Promise<(string | null)[]>
- exec?: (keys: string[]) => ExecResult
- }
- ) {}
-
- mget(...keys: string[]): Promise<(string | null)[]> {
- return Promise.resolve(this.behavior.mget?.(keys) ?? keys.map(() => null))
- }
-
- pipeline(): { set: (key: string) => void; exec: () => Promise<ExecResult> } {
- const keys: string[] = []
- return {
- set: (key: string) => {
- keys.push(key)
- this.pipelined.push(key)
- },
- exec: () =>
- Promise.resolve(
- 'exec' in this.behavior ? this.behavior.exec!(keys) : keys.map(() => [null, 'OK'] as [null, string])
- ),
- }
- }
-}
-
-function poolOf(client: FakeClient): CrawlHistoryRedisPool {
- return {
- acquire: () => Promise.resolve(client),
- release: () => Promise.resolve(),
- destroy: () => Promise.resolve(),
- }
-}
-
-describe('CrawlHistory', () => {
- const build = (client: FakeClient, budgetMs = 60_000): CrawlHistory =>
- new CrawlHistory(poolOf(client), 1_000, budgetMs)
-
- it('reports the index of every key that exists, across chunk boundaries', async () => {
- // The caller maps these indexes back onto its own candidate list, so an off-by-one skips the
- // wrong URL and nothing reports it.
- const present = new Set(['k0', 'k255', 'k256', 'k599'])
- const client = new FakeClient({ mget: (keys) => keys.map((key) => (present.has(key) ? '{}' : null)) })
-
- const result = await build(client).read(KEYS, NOW_MS)
-
- expect([...result.known].sort((a, b) => a - b)).toEqual([0, 255, 256, 599])
- expect(result.failed.size).toBe(0)
- })
-
- it('reports the index of every key in a chunk that threw, rather than calling them absent', async () => {
- const client = new FakeClient({
- mget: (keys) => {
- if (keys.includes('k256')) {
- throw new Error('redis down')
- }
- return keys.map(() => null)
- },
- })
-
- const result = await build(client).read(KEYS, NOW_MS)
-
- // The caller drops these rather than fetches them, so it needs which keys, not how many.
- expect(result.failed.size).toBe(256)
- expect(result.failed.has(256)).toBe(true)
- expect(result.failed.has(255)).toBe(false)
- expect(result.known.size).toBe(0)
- })
-
- it('reports the index of a single command that failed inside a write pipeline', async () => {
- const client = new FakeClient({
- exec: (keys) => keys.map((key) => (key === 'k300' ? [new Error('nope'), null] : [null, 'OK'])),
- })
-
- const { failed } = await build(client).record(KEYS, 1, 60)
-
- expect([...failed]).toEqual([300])
- })
-
- it('treats a pipeline that answers with nothing as a whole failed chunk', async () => {
- const client = new FakeClient({ exec: () => null })
-
- const { failed } = await build(client).record(KEYS, 1, 60)
-
- expect(failed.size).toBe(KEYS.length)
- })
-
- it('stops issuing round trips once the batch budget is spent', async () => {
- // A batch that runs past the heartbeat restarts the pod onto the same offsets, so the lane
- // sheds the rest of the work instead.
- const client = new FakeClient({
- mget: async (keys) => {
- await new Promise((resolve) => setTimeout(resolve, 20))
- return keys.map(() => null)
- },
- })
-
- const result = await build(client, 30).read(KEYS, NOW_MS)
-
- expect(result.failed.size).toBeGreaterThan(0)
- })
-
- it('writes every key exactly once', async () => {
- const client = new FakeClient({})
-
- await build(client).record(KEYS, 1, 60)
-
- expect(client.pipelined).toEqual(KEYS)
- })
-})
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/crawl-history.ts b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/crawl-history.ts
index 354f795c1b1f..5420762f950a 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/crawl-history.ts
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/crawl-history.ts
@@ -1,173 +1,15 @@
-import { Pool } from 'generic-pool'
-
-/**
- * The keyspace of the URL-seen test, asked before every fetch. An entry means this lane finished
- * with the URL, whatever the outcome, so a URL the site refused sits beside one it served.
- *
- * The entry says nothing about the bytes, which live under their own keys once a later lane writes
- * them. One keyspace for both would leave whoever enables fetching with a month of entries that look
- * like completed downloads, and the lane would skip every URL behind them with no error.
- */
const CRAWL_HISTORY_PREFIX = 'imgfetch:seen'
-/** Bounds one round trip. A poll batch can carry thousands of URLs, and one pipeline holding all of them times out as a unit. */
-const MAX_KEYS_PER_ROUND_TRIP = 256
-
export function crawlHistoryKey(pseudoTeam: string, urlHash: string): string {
return `${CRAWL_HISTORY_PREFIX}:${pseudoTeam}:${urlHash}`
}
-function chunk<T>(items: T[], size: number): T[][] {
- const out: T[][] = []
- for (let i = 0; i < items.length; i += size) {
- out.push(items.slice(i, i + size))
- }
- return out
-}
-
export interface CrawlHistoryReadResult {
- /** Indexes of the keys the store already holds. */
known: Set<number>
- /** Indexes whose read did not complete. The caller knows nothing about these, which is not the same as knowing they are absent. */
failed: Set<number>
}
-/**
- * Narrower than `Redis`, so a test supplies exactly these commands, and a command added here must
- * reach the fake before this compiles.
- */
-export interface CrawlHistoryRedis {
- mget(...keys: string[]): Promise<(string | null)[]>
- pipeline(): {
- set(key: string, value: string, expiryMode: 'EX', seconds: number): unknown
- exec(): Promise<[Error | null, unknown][] | null>
- }
-}
-
-/** Narrow, so a test supplies these operations without a cast. */
-export type CrawlHistoryRedisPool = Pick<Pool<CrawlHistoryRedis>, 'acquire' | 'release' | 'destroy'>
-
-/** What the consumer needs of the store, so its tests exercise the real contract rather than a cast. */
export interface CrawlHistoryStore {
read(keys: string[], nowMs: number): Promise<CrawlHistoryReadResult>
record(keys: string[], nowMs: number, ttlSeconds: number): Promise<{ failed: Set<number> }>
}
-
-/**
- * Every pod shares this store. The in-memory cache in front of it holds only what one pod saw since
- * it started, so a rebalance or a restart would otherwise count every URL again. A lost store costs
- * an overstated measurement now, and outbound requests once fetching is on. It never costs
- * correctness.
- *
- * Both methods stop early once the batch budget is spent and report the rest as failed. Kafka evicts
- * a pod whose batch runs past max.poll.interval.ms, and the next pod replays that partition and
- * takes just as long, so offered load rises while throughput falls.
- */
-export class CrawlHistory implements CrawlHistoryStore {
- constructor(
- private readonly pool: CrawlHistoryRedisPool,
- private readonly commandTimeoutMs: number,
- private readonly batchBudgetMs: number
- ) {}
-
- public async read(keys: string[], _nowMs: number): Promise<CrawlHistoryReadResult> {
- const known = new Set<number>()
- const failed = new Set<number>()
- await this.forEachChunk(keys, {
- onChunk: async (client, batch, base) => {
- const values = await client.mget(...batch)
- values.forEach((value, index) => {
- if (value !== null) {
- known.add(base + index)
- }
- })
- },
- onChunkFailed: (batch, base) => {
- batch.forEach((_key, index) => failed.add(base + index))
- },
- })
- return { known, failed }
- }
-
- public async record(keys: string[], nowMs: number, ttlSeconds: number): Promise<{ failed: Set<number> }> {
- const failed = new Set<number>()
- const value = JSON.stringify({ seenAtMs: nowMs })
- await this.forEachChunk(keys, {
- onChunk: async (client, batch, base) => {
- const pipeline = client.pipeline()
- for (const key of batch) {
- // One command, so a key can never sit without its expiry. A separate EXPIRE can
- // be the command that fails, and Redis never reclaims the key it leaves behind.
- pipeline.set(key, value, 'EX', ttlSeconds)
- }
- const results = (await pipeline.exec()) as [Error | null, unknown][] | null
- batch.forEach((_key, index) => {
- const result = results?.[index]
- if (!result || result[0]) {
- failed.add(base + index)
- }
- })
- },
- onChunkFailed: (batch, base) => {
- batch.forEach((_key, index) => failed.add(base + index))
- },
- })
- return { failed }
- }
-
- private async forEachChunk(
- keys: string[],
- handlers: {
- onChunk: (client: CrawlHistoryRedis, batch: string[], base: number) => Promise<void>
- onChunkFailed: (batch: string[], base: number) => void
- }
- ): Promise<void> {
- const startedAt = process.hrtime.bigint()
- const spentMs = (): number => Number(process.hrtime.bigint() - startedAt) / 1e6
- let base = 0
- for (const batch of chunk(keys, MAX_KEYS_PER_ROUND_TRIP)) {
- const at = base
- base += batch.length
- if (spentMs() > this.batchBudgetMs) {
- handlers.onChunkFailed(batch, at)
- continue
- }
- try {
- await this.withClient((client) => handlers.onChunk(client, batch, at))
- } catch {
- handlers.onChunkFailed(batch, at)
- }
- }
- }
-
- /**
- * The pool rejects rather than queues once its own acquire timeout passes, so this never races
- * `acquire()`. generic-pool cannot cancel an acquire, and it still hands the next free connection
- * to a caller that walked away, and still counts that caller as a borrower.
- *
- * This destroys a connection whose command it abandoned rather than returns it, because the
- * reply is still in flight and would read as the answer to whichever command borrows it next.
- */
- private async withClient(run: (client: CrawlHistoryRedis) => Promise<void>): Promise<void> {
- const client = await this.pool.acquire()
- let timer: NodeJS.Timeout | undefined
- try {
- await Promise.race([
- run(client),
- new Promise<never>((_resolve, reject) => {
- timer = setTimeout(
- () => reject(new Error('crawl history command timed out')),
- this.commandTimeoutMs
- )
- timer.unref()
- }),
- ])
- } catch (error) {
- await this.pool.destroy(client).catch(() => undefined)
- throw error
- } finally {
- clearTimeout(timer)
- }
- await this.pool.release(client)
- }
-}
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/url-fetch-consumer.test.ts b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/url-fetch-consumer.test.ts
index 2f70a271505d..04f1dc474989 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/url-fetch-consumer.test.ts
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/url-fetch-consumer.test.ts
@@ -143,7 +143,7 @@ describe('UrlFetchConsumer', () => {
seenTtlSeconds,
dryRun: true,
})
- ).toThrow('SESSION_RECORDING_ML_IMAGE_FETCH_SEEN_TTL_SECONDS')
+ ).toThrow('AI_RESEARCH_IMAGE_FETCH_CRAWL_HISTORY_TTL_SECONDS')
})
it('writes one ledger entry per URL it would fetch', async () => {
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/url-fetch-consumer.ts b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/url-fetch-consumer.ts
index d0ca7998e4f1..783331842ab4 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/url-fetch-consumer.ts
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/url-fetch-consumer.ts
@@ -51,7 +51,7 @@ export class UrlFetchConsumer {
// a 7-second TTL empties the ledger as fast as it fills, so nothing dedups.
if (!Number.isInteger(options.seenTtlSeconds) || options.seenTtlSeconds < 60 * 60) {
throw new Error(
- `SESSION_RECORDING_ML_IMAGE_FETCH_SEEN_TTL_SECONDS must be an integer of at least 3600, got ` +
+ `AI_RESEARCH_IMAGE_FETCH_CRAWL_HISTORY_TTL_SECONDS must be an integer of at least 3600, got ` +
`${options.seenTtlSeconds} (a unit suffix like "7d" parses as 7: give the value in seconds)`
)
}
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror/config.ts b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror/config.ts
index 850aa90aebe8..a73b2511bf51 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror/config.ts
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror/config.ts
@@ -85,22 +85,8 @@ export type MlMirrorConfig = {
SESSION_RECORDING_ML_IMAGE_FETCH_BATCH_SIZE: number
/** A URL older than this is dropped, so a lane with a backlog sheds work rather than fetching stale work. */
SESSION_RECORDING_ML_IMAGE_FETCH_MAX_AGE_MS: number
- /** Capacity of the per-pod seen-ref cache that sits in front of the shared crawl history. */
+ /** Capacity of the per-pod seen-ref cache that sits in front of the crawl history. */
SESSION_RECORDING_ML_IMAGE_FETCH_DEDUP_MAX_REFS: number
- /**
- * TTL on each crawl history entry, so it is both the recrawl interval and the ledger's Redis
- * footprint: the key count converges on the distinct-URL count of this window, which is the
- * number that sizes the Redis. An env var because it is the main memory lever for that cluster,
- * and memory pressure moves faster than a deploy.
- *
- * 7 days measures the dry-run dedup hit rate over a window the cluster can hold. Once fetching
- * is on, this is also how often a recurring image is refetched from the customer's site, so
- * raising it back up trades Redis memory for outbound politeness.
- */
- SESSION_RECORDING_ML_IMAGE_FETCH_SEEN_TTL_SECONDS: number
- /** Bounds one round trip to the crawl history, including waiting for a pooled connection, so a Redis stall cannot hold the poll loop. */
- SESSION_RECORDING_ML_IMAGE_FETCH_REDIS_TIMEOUT_MS: number
- /** An empty table name keeps the Redis crawl-history backend active. */
AI_RESEARCH_IMAGE_FETCH_DYNAMODB_TABLE: string
/** Bounds one DynamoDB request so an unavailable store cannot hold the poll loop. */
AI_RESEARCH_IMAGE_FETCH_DYNAMODB_TIMEOUT_MS: number
@@ -257,8 +243,6 @@ export function getDefaultMlMirrorConfig(): MlMirrorConfig {
SESSION_RECORDING_ML_IMAGE_FETCH_BATCH_SIZE: 500,
SESSION_RECORDING_ML_IMAGE_FETCH_MAX_AGE_MS: 6 * 60 * 60 * 1000,
SESSION_RECORDING_ML_IMAGE_FETCH_DEDUP_MAX_REFS: 500_000,
- SESSION_RECORDING_ML_IMAGE_FETCH_SEEN_TTL_SECONDS: 7 * 24 * 60 * 60,
- SESSION_RECORDING_ML_IMAGE_FETCH_REDIS_TIMEOUT_MS: 5_000,
AI_RESEARCH_IMAGE_FETCH_DYNAMODB_TABLE: '',
AI_RESEARCH_IMAGE_FETCH_DYNAMODB_TIMEOUT_MS: 5_000,
AI_RESEARCH_IMAGE_FETCH_CRAWL_HISTORY_TTL_SECONDS: 30 * 24 * 60 * 60,
diff --git a/nodejs/src/servers/ingestion-session-replay-ml-image-fetch-server.ts b/nodejs/src/servers/ingestion-session-replay-ml-image-fetch-server.ts
index 9dfd991ad9d7..edc184a172fa 100644
--- a/nodejs/src/servers/ingestion-session-replay-ml-image-fetch-server.ts
+++ b/nodejs/src/servers/ingestion-session-replay-ml-image-fetch-server.ts
@@ -11,13 +11,8 @@ import {
import { KafkaConsumer, KafkaConsumerConfig } from '~/common/kafka/consumer/consumer-v1'
import { KafkaProducerWrapper } from '~/common/kafka/producer'
import { KafkaProducerRegistry } from '~/common/outputs/kafka-producer-registry'
-import { createRedisPoolFromConfig } from '~/common/utils/db/redis'
import { logger } from '~/common/utils/logger'
import { SessionReplayProducerName } from '~/ingestion/pipelines/sessionreplay/config'
-import {
- CrawlHistory,
- CrawlHistoryStore,
-} from '~/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/crawl-history'
import { DynamoDBCrawlHistory } from '~/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/dynamodb-crawl-history'
import { FetchRunner } from '~/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/fetch-runner'
import { FrontierPublisher } from '~/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/frontier-publisher'
@@ -26,11 +21,9 @@ import { HttpImageFetcher } from '~/ingestion/pipelines/sessionreplay/ml-mirror-
import { assertUrlPolicyLoaded } from '~/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/politeness-key'
import { UrlFetchConsumer } from '~/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/url-fetch-consumer'
import { createWebBotAuthRequestSigner } from '~/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/web-bot-auth'
-import { resolveMlMirrorRedisConnection } from '~/ingestion/pipelines/sessionreplay/ml-mirror/config'
import { createProducerRegistry } from '~/ingestion/pipelines/sessionreplay/outputs/producer-registry'
import { INGESTION_SESSIONREPLAY_ML_IMAGE_FETCH_PRODUCER } from '~/ingestion/pipelines/sessionreplay/shared/outputs/producer-config'
-import { RedisPool } from '../types'
import { CleanupResources, NodeServer, ServerLifecycle } from './base-server'
import {
IngestionSessionReplayMlMirrorServerConfig,
@@ -133,7 +126,6 @@ export function buildImageFetchConsumerConfig(config: IngestionSessionReplayMlMi
export class IngestionSessionReplayMlImageFetchServer implements NodeServer {
readonly lifecycle: ServerLifecycle
private config: IngestionSessionReplayMlMirrorServerConfig
- private crawlHistoryPool?: RedisPool
private crawlHistoryClient?: DynamoDBClient
private producerRegistry?: KafkaProducerRegistry<SessionReplayProducerName>
@@ -167,46 +159,29 @@ export class IngestionSessionReplayMlImageFetchServer implements NodeServer {
)
}
- let crawlHistory: CrawlHistoryStore
- let crawlHistoryTtlSeconds: number
const tableName = this.config.AI_RESEARCH_IMAGE_FETCH_DYNAMODB_TABLE
- if (tableName) {
- const dynamoDBTimeoutMs = this.config.AI_RESEARCH_IMAGE_FETCH_DYNAMODB_TIMEOUT_MS
- if (!Number.isFinite(dynamoDBTimeoutMs) || dynamoDBTimeoutMs <= 0) {
- throw new Error(
- `AI_RESEARCH_IMAGE_FETCH_DYNAMODB_TIMEOUT_MS must be a positive number, got ${dynamoDBTimeoutMs}`
- )
- }
- this.crawlHistoryClient = new DynamoDBClient({
- region: this.config.SESSION_RECORDING_V2_S3_REGION || 'us-east-1',
- endpoint: this.config.SESSION_RECORDING_DYNAMODB_ENDPOINT,
- maxAttempts: 5,
- requestHandler: new NodeHttpHandler(),
- })
- const dynamoDBCrawlHistory = new DynamoDBCrawlHistory(
- this.crawlHistoryClient,
- tableName,
- dynamoDBTimeoutMs,
- STORE_BATCH_BUDGET_MS
+ if (!tableName) {
+ throw new Error('AI_RESEARCH_IMAGE_FETCH_DYNAMODB_TABLE must be set for the image-fetch consumer')
+ }
+ const dynamoDBTimeoutMs = this.config.AI_RESEARCH_IMAGE_FETCH_DYNAMODB_TIMEOUT_MS
+ if (!Number.isFinite(dynamoDBTimeoutMs) || dynamoDBTimeoutMs <= 0) {
+ throw new Error(
+ `AI_RESEARCH_IMAGE_FETCH_DYNAMODB_TIMEOUT_MS must be a positive number, got ${dynamoDBTimeoutMs}`
)
- await dynamoDBCrawlHistory.validateAccess(Date.now())
- crawlHistory = dynamoDBCrawlHistory
- crawlHistoryTtlSeconds = this.config.AI_RESEARCH_IMAGE_FETCH_CRAWL_HISTORY_TTL_SECONDS
- } else {
- const connection = resolveMlMirrorRedisConnection(this.config)
- if (!connection) {
- throw new Error('SESSION_RECORDING_ML_REDIS_HOST must be set for the image-fetch consumer')
- }
- const redisTimeoutMs = this.config.SESSION_RECORDING_ML_IMAGE_FETCH_REDIS_TIMEOUT_MS
- this.crawlHistoryPool = createRedisPoolFromConfig({
- connection: { ...connection, options: { ...connection.options, commandTimeout: redisTimeoutMs } },
- poolMinSize: this.config.REDIS_POOL_MIN_SIZE,
- poolMaxSize: this.config.REDIS_POOL_MAX_SIZE,
- acquireTimeoutMillis: redisTimeoutMs,
- })
- crawlHistory = new CrawlHistory(this.crawlHistoryPool, redisTimeoutMs, STORE_BATCH_BUDGET_MS)
- crawlHistoryTtlSeconds = this.config.SESSION_RECORDING_ML_IMAGE_FETCH_SEEN_TTL_SECONDS
}
+ this.crawlHistoryClient = new DynamoDBClient({
+ region: this.config.SESSION_RECORDING_V2_S3_REGION || 'us-east-1',
+ endpoint: this.config.SESSION_RECORDING_DYNAMODB_ENDPOINT,
+ maxAttempts: 5,
+ requestHandler: new NodeHttpHandler(),
+ })
+ const crawlHistory = new DynamoDBCrawlHistory(
+ this.crawlHistoryClient,
+ tableName,
+ dynamoDBTimeoutMs,
+ STORE_BATCH_BUDGET_MS
+ )
+ await crawlHistory.validateAccess(Date.now())
// Built even in dry run, so the wiring is exercised by every start rather than only by the
// one that clears the flag.
@@ -221,7 +196,7 @@ export class IngestionSessionReplayMlImageFetchServer implements NodeServer {
{
maxAgeMs: this.config.SESSION_RECORDING_ML_IMAGE_FETCH_MAX_AGE_MS,
dedupMaxRefs: this.config.SESSION_RECORDING_ML_IMAGE_FETCH_DEDUP_MAX_REFS,
- seenTtlSeconds: crawlHistoryTtlSeconds,
+ seenTtlSeconds: this.config.AI_RESEARCH_IMAGE_FETCH_CRAWL_HISTORY_TTL_SECONDS,
dryRun,
},
dryRun ? undefined : buildFetchRunner(this.config, publisher)
@@ -244,7 +219,7 @@ export class IngestionSessionReplayMlImageFetchServer implements NodeServer {
private getCleanupResources(): CleanupResources {
return {
kafkaProducers: [],
- redisPools: this.crawlHistoryPool ? [this.crawlHistoryPool] : [],
+ redisPools: [],
additionalCleanup: async () => {
this.crawlHistoryClient?.destroy()
await this.producerRegistry?.disconnectAll()