Skip to content

Commit 9963157

Browse files
authored
feat: rename KVS objects from SDK_ to CRAWLEE_ (#3783)
Drops the `SDK_` prefix (replaces w/ `CRAWLEE_`) on multiple spots in the codebase. Closes #1729
1 parent 13976b3 commit 9963157

9 files changed

Lines changed: 30 additions & 24 deletions

File tree

docs/guides/configuration.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ crawler.router.addDefaultHandler(async ({ request }) => {
5757
await crawler.run(['https://www.example.com/1']);
5858
```
5959

60-
If you run this example (assuming you placed the `crawlee.json` file with `persistStateIntervalMillis` and `logLevel` specified there in the root of your project), you will find the `SDK_CRAWLER_STATISTICS` file in default Key-Value store,
60+
If you run this example (assuming you placed the `crawlee.json` file with `persistStateIntervalMillis` and `logLevel` specified there in the root of your project), you will find the `CRAWLEE_CRAWLER_STATISTICS` file in default Key-Value store,
6161
which would show, that there's 1 finished request and crawler runtime was ~10 seconds.
6262
This confirms that the state was persisted after 10 seconds, as it was set in `crawlee.json`.
6363
Besides, you should see `DEBUG` logs in addition to `INFO` ones in your terminal, as `logLevel` was set to `DEBUG` in the `crawlee.json`, meaning Crawlee picked both provided options correctly.
@@ -174,14 +174,14 @@ crawler.router.addDefaultHandler(async ({ request }) => {
174174
await crawler.run(['https://www.example.com/1']);
175175
```
176176

177-
If you run this example - you will find the `SDK_CRAWLER_STATISTICS` file in default Key-Value store,
177+
If you run this example - you will find the `CRAWLEE_CRAWLER_STATISTICS` file in default Key-Value store,
178178
which would show the same number of finished requests (one) and the same crawler runtime (~10 seconds).
179179
This confirms that provided parameters worked: the state was persisted after 10 seconds, as it was set in the configuration.
180180

181181
:::note
182182

183183
After running the same example without the custom configuration, there will be
184-
no `SDK_CRAWLER_STATISTICS` file stored in the default Key-Value store:
184+
no `CRAWLEE_CRAWLER_STATISTICS` file stored in the default Key-Value store:
185185
as we did not change the `persistStateIntervalMillis`, Crawlee used the default value of 60 seconds,
186186
and the crawler was forcefully aborted after ~15 seconds of run time before it persisted the state for the first time.
187187

@@ -222,13 +222,13 @@ await crawler.run(['https://www.example.com/1']);
222222
```
223223

224224
If you run this example - it would work exactly the same as before,
225-
with the same `SDK_CRAWLER_STATISTICS` file in default Key-Value store after the run,
225+
with the same `CRAWLEE_CRAWLER_STATISTICS` file in default Key-Value store after the run,
226226
showing the same number of finished requests and the same crawler run time.
227227

228228
:::note
229229

230230
If you would not pass the configuration to the crawler, there again will be
231-
no `SDK_CRAWLER_STATISTICS` file stored in the default Key-Value store, this time for a different reason though.
231+
no `CRAWLEE_CRAWLER_STATISTICS` file stored in the default Key-Value store, this time for a different reason though.
232232
Since we did not pass the configuration to the crawler,
233233
the crawler will use the global configuration, which is using the default `persistStateIntervalMillis`.
234234
So again, the run was aborted before the state was persisted for the first time.

docs/upgrading/upgrading_v4.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,10 @@ The protected `HttpCrawler._applyCookies` method is removed. If you were overrid
504504

505505
The `persistCookiesPerSession` crawler option has been renamed to `saveResponseCookies` on both `HttpCrawler` (and its subclasses like `CheerioCrawler`, `JSDOMCrawler`, etc.) and `BrowserCrawler`. The behavior is unchanged - when enabled (the default), response `Set-Cookie` headers are stored in the session's cookie jar so they're sent on subsequent requests using the same session. Rename the option in your crawler constructor options to migrate.
506506

507+
## Internal KVS keys renamed
508+
509+
Several internal Crawlee keys were prefixed with the `SDK_` prefix for legacy reasons - these keys now start with `CRAWLEE_` instead. These are, e.g., `CRAWLEE_SESSION_POOL_STATE` or `CRAWLEE_CRAWLER_STATISTICS_{n}`.
510+
507511
## `StorageClient` interface simplified
508512

509513
The `StorageClient` interface (from `@crawlee/types`) has been redesigned to match the simplified architecture from Crawlee for Python. A new storage backend now needs **4 classes** instead of the previous 7.

packages/core/src/crawlers/statistics.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export interface PersistenceOptions {
4949
* statistics for requests.
5050
*
5151
* All statistic information is saved on key value store
52-
* under the key `SDK_CRAWLER_STATISTICS_*`, persists between
52+
* under the key `CRAWLEE_CRAWLER_STATISTICS_*`, persists between
5353
* migrations and abort/resurrect
5454
*
5555
* @category Crawlers
@@ -130,7 +130,7 @@ export class Statistics {
130130
} = options;
131131

132132
this.id = id ?? String(Statistics.id++);
133-
this.persistStateKey = `SDK_CRAWLER_STATISTICS_${this.id}`;
133+
this.persistStateKey = `CRAWLEE_CRAWLER_STATISTICS_${this.id}`;
134134

135135
this.log = (options.log ?? serviceLocator.getLogger()).child({ prefix: 'Statistics' });
136136
this.errorTracker = new ErrorTracker({ ...errorTrackerConfig, saveErrorSnapshots });
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export const BLOCKED_STATUS_CODES = [401, 403, 429];
2-
export const PERSIST_STATE_KEY = 'SDK_SESSION_POOL_STATE';
2+
export const PERSIST_STATE_KEY = 'CRAWLEE_SESSION_POOL_STATE';
33
export const MAX_POOL_SIZE = 1000;

packages/core/src/session_pool/session_pool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export interface SessionPoolOptions {
4848

4949
/**
5050
* Session pool persists its state under this key in Key value store.
51-
* @default SDK_SESSION_POOL_STATE_{id}
51+
* @default CRAWLEE_SESSION_POOL_STATE_{id}
5252
*/
5353
persistStateKey?: string;
5454

packages/core/src/storages/request_list.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,8 @@ export class RequestList implements IRequestLoader {
332332
}),
333333
);
334334

335-
this.persistStateKey = persistStateKey ? `SDK_${persistStateKey}` : persistStateKey;
336-
this.persistRequestsKey = persistRequestsKey ? `SDK_${persistRequestsKey}` : persistRequestsKey;
335+
this.persistStateKey = persistStateKey ? `CRAWLEE_${persistStateKey}` : persistStateKey;
336+
this.persistRequestsKey = persistRequestsKey ? `CRAWLEE_${persistRequestsKey}` : persistRequestsKey;
337337
this.initialState = state;
338338
this.httpClient = httpClient;
339339

test/core/crawlers/statistics.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe('Statistics', () => {
3636
// @ts-expect-error Accessing private prop
3737
expect(Statistics.id).toEqual(1);
3838
// @ts-expect-error Accessing private prop
39-
expect(stats.persistStateKey).toEqual('SDK_CRAWLER_STATISTICS_0');
39+
expect(stats.persistStateKey).toEqual('CRAWLEE_CRAWLER_STATISTICS_0');
4040
const [n1, n2] = [new Statistics(), new Statistics()];
4141
expect(n1.id).toEqual('1');
4242
expect(n2.id).toEqual('2');

test/core/request_list.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -566,15 +566,15 @@ describe('RequestList', () => {
566566
const setValueSpy = vitest.spyOn(KeyValueStore.prototype, 'setValue');
567567

568568
const name = 'xxx';
569-
const SDK_KEY = `SDK_${name}`;
569+
const CRAWLEE_KEY = `CRAWLEE_${name}`;
570570
const sources = [{ url: 'https://example.com' }];
571571

572572
const rl = await RequestList.open(name, sources);
573573
expect(rl).toBeInstanceOf(RequestList);
574574
// @ts-expect-error accessing private var
575-
expect(rl.persistStateKey.startsWith(SDK_KEY)).toBe(true);
575+
expect(rl.persistStateKey.startsWith(CRAWLEE_KEY)).toBe(true);
576576
// @ts-expect-error accessing private var
577-
expect(rl.persistRequestsKey.startsWith(SDK_KEY)).toBe(true);
577+
expect(rl.persistRequestsKey.startsWith(CRAWLEE_KEY)).toBe(true);
578578
// @ts-expect-error accessing private var
579579
expect(rl.sources).toEqual([]);
580580
// @ts-expect-error accessing private var
@@ -589,16 +589,16 @@ describe('RequestList', () => {
589589
const setValueSpy = vitest.spyOn(KeyValueStore.prototype, 'setValue');
590590

591591
const name = 'xxx';
592-
const SDK_KEY = `SDK_${name}`;
592+
const CRAWLEE_KEY = `CRAWLEE_${name}`;
593593
const sources = ['https://example.com'];
594594
const requests = sources.map((url) => ({ url, uniqueKey: url }));
595595

596596
const rl = await RequestList.open(name, sources);
597597
expect(rl).toBeInstanceOf(RequestList);
598598
// @ts-expect-error accessing private var
599-
expect(rl.persistStateKey.startsWith(SDK_KEY)).toBe(true);
599+
expect(rl.persistStateKey.startsWith(CRAWLEE_KEY)).toBe(true);
600600
// @ts-expect-error accessing private var
601-
expect(rl.persistRequestsKey.startsWith(SDK_KEY)).toBe(true);
601+
expect(rl.persistRequestsKey.startsWith(CRAWLEE_KEY)).toBe(true);
602602
expect(rl.requests).toEqual(requests);
603603
// @ts-expect-error accessing private var
604604
expect(rl.isInitialized).toBe(true);
@@ -612,7 +612,7 @@ describe('RequestList', () => {
612612
const setValueSpy = vitest.spyOn(KeyValueStore.prototype, 'setValue');
613613

614614
const name = 'xxx';
615-
const SDK_KEY = `SDK_${name}`;
615+
const CRAWLEE_KEY = `CRAWLEE_${name}`;
616616
let counter = 0;
617617
const sources = [{ url: 'https://example.com' }];
618618
const requests = sources.map(({ url }) => ({ url, uniqueKey: `${url}-${counter++}` }));
@@ -624,9 +624,9 @@ describe('RequestList', () => {
624624
const rl = await RequestList.open(name, sources, options);
625625
expect(rl).toBeInstanceOf(RequestList);
626626
// @ts-expect-error accessing private var
627-
expect(rl.persistStateKey.startsWith(SDK_KEY)).toBe(true);
627+
expect(rl.persistStateKey.startsWith(CRAWLEE_KEY)).toBe(true);
628628
// @ts-expect-error accessing private var
629-
expect(rl.persistRequestsKey.startsWith(SDK_KEY)).toBe(true);
629+
expect(rl.persistRequestsKey.startsWith(CRAWLEE_KEY)).toBe(true);
630630
expect(rl.requests).toEqual(requests);
631631
// @ts-expect-error accessing private var
632632
expect(rl.isInitialized).toBe(true);

test/e2e/tools.mjs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function execSync(command, options) {
2222
/**
2323
* @param {string} name
2424
*/
25-
const isPrivateEntry = (name) => name === 'SDK_CRAWLER_STATISTICS_0' || name === 'SDK_SESSION_POOL_STATE';
25+
const isPrivateEntry = (name) => name === 'CRAWLEE_CRAWLER_STATISTICS_0' || name === 'CRAWLEE_SESSION_POOL_STATE';
2626

2727
export const SKIPPED_TEST_CLOSE_CODE = 404;
2828

@@ -49,7 +49,7 @@ export function getStorage(dirName) {
4949
*/
5050
export async function getStats(dirName) {
5151
const dir = getStorage(dirName);
52-
const path = join(dir, `key_value_stores/default/SDK_CRAWLER_STATISTICS_0.json`);
52+
const path = join(dir, `key_value_stores/default/CRAWLEE_CRAWLER_STATISTICS_0.json`);
5353

5454
if (!existsSync(path)) {
5555
return false;
@@ -208,7 +208,9 @@ export async function runActor(dirName, memory = 4096) {
208208
const runTook = (runFinishedAt.getTime() - runStartedAt.getTime()) / 1000;
209209
console.log(`[run] View run: https://console.apify.com/view/runs/${runId} [run took ${runTook}s]`);
210210

211-
const statsRecord = await client.keyValueStore(defaultKeyValueStoreId).getRecord('SDK_CRAWLER_STATISTICS_0');
211+
const statsRecord = await client
212+
.keyValueStore(defaultKeyValueStoreId)
213+
.getRecord('CRAWLEE_CRAWLER_STATISTICS_0');
212214
stats = statsRecord?.value;
213215

214216
const { items } = await client.dataset(defaultDatasetId).listItems();

0 commit comments

Comments
 (0)