@crawlee/core 4.0.0-beta.17 → 4.0.0-beta.170
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -14
- package/autoscaling/autoscaled_pool.d.ts +73 -177
- package/autoscaling/autoscaled_pool.js +182 -329
- package/autoscaling/concurrency_system.d.ts +268 -0
- package/autoscaling/concurrency_system.js +364 -0
- package/autoscaling/cpu_load_signal.d.ts +43 -0
- package/autoscaling/cpu_load_signal.js +47 -0
- package/autoscaling/event_loop_load_signal.d.ts +51 -0
- package/autoscaling/event_loop_load_signal.js +60 -0
- package/autoscaling/index.d.ts +6 -1
- package/autoscaling/index.js +6 -1
- package/autoscaling/load_signal.d.ts +98 -0
- package/autoscaling/load_signal.js +103 -0
- package/autoscaling/memory_load_signal.d.ts +47 -0
- package/autoscaling/memory_load_signal.js +106 -0
- package/autoscaling/snapshotter.d.ts +58 -163
- package/autoscaling/snapshotter.js +45 -263
- package/autoscaling/storage_backend_load_signal.d.ts +56 -0
- package/autoscaling/storage_backend_load_signal.js +73 -0
- package/autoscaling/system_status.d.ts +70 -92
- package/autoscaling/system_status.js +92 -122
- package/autoscaling/weighted_avg.d.ts +5 -0
- package/autoscaling/weighted_avg.js +14 -0
- package/byte_utils.d.ts +17 -0
- package/byte_utils.js +42 -0
- package/configuration.d.ts +96 -223
- package/configuration.js +170 -222
- package/cookie_utils.d.ts +3 -2
- package/cookie_utils.js +18 -7
- package/crawlers/context_pipeline.d.ts +10 -1
- package/crawlers/context_pipeline.js +31 -8
- package/crawlers/crawler_commons.d.ts +128 -124
- package/crawlers/crawler_commons.js +1 -108
- package/crawlers/error_snapshotter.d.ts +2 -5
- package/crawlers/error_snapshotter.js +5 -6
- package/crawlers/error_tracker.d.ts +0 -1
- package/crawlers/error_tracker.js +0 -1
- package/crawlers/index.d.ts +1 -3
- package/crawlers/index.js +0 -3
- package/crawlers/internals/types.d.ts +0 -1
- package/crawlers/internals/types.js +0 -1
- package/crawlers/statistics.d.ts +194 -79
- package/crawlers/statistics.js +382 -201
- package/debug.d.ts +36 -0
- package/debug.js +70 -0
- package/enqueue_links/enqueue_links.d.ts +61 -154
- package/enqueue_links/enqueue_links.js +40 -232
- package/enqueue_links/index.d.ts +0 -1
- package/enqueue_links/index.js +0 -1
- package/enqueue_links/shared.d.ts +55 -28
- package/enqueue_links/shared.js +116 -69
- package/errors.d.ts +82 -4
- package/errors.js +101 -5
- package/events/event_manager.d.ts +35 -9
- package/events/event_manager.js +12 -13
- package/events/index.d.ts +0 -1
- package/events/index.js +0 -1
- package/events/local_event_manager.d.ts +15 -3
- package/events/local_event_manager.js +39 -13
- package/http.d.ts +9 -0
- package/http.js +28 -0
- package/index.d.ts +7 -5
- package/index.js +8 -4
- package/iterables.d.ts +79 -0
- package/iterables.js +134 -0
- package/log.d.ts +77 -1
- package/log.js +134 -1
- package/memory-storage/consts.d.ts +4 -0
- package/memory-storage/consts.js +4 -0
- package/memory-storage/index.d.ts +1 -0
- package/memory-storage/index.js +1 -0
- package/memory-storage/memory-storage.d.ts +44 -0
- package/memory-storage/memory-storage.js +160 -0
- package/memory-storage/resource-clients/common/base-client.d.ts +4 -0
- package/memory-storage/resource-clients/common/base-client.js +6 -0
- package/memory-storage/resource-clients/dataset.d.ts +40 -0
- package/memory-storage/resource-clients/dataset.js +106 -0
- package/memory-storage/resource-clients/key-value-store.d.ts +63 -0
- package/memory-storage/resource-clients/key-value-store.js +199 -0
- package/memory-storage/resource-clients/request-queue.d.ts +77 -0
- package/memory-storage/resource-clients/request-queue.js +414 -0
- package/memory-storage/utils.d.ts +16 -0
- package/memory-storage/utils.js +41 -0
- package/owned_or_injected.d.ts +58 -0
- package/owned_or_injected.js +98 -0
- package/package.json +17 -16
- package/proxy_configuration.d.ts +22 -128
- package/proxy_configuration.js +32 -144
- package/recoverable_state.d.ts +84 -51
- package/recoverable_state.js +175 -72
- package/request.d.ts +57 -16
- package/request.js +130 -69
- package/router.d.ts +193 -21
- package/router.js +188 -43
- package/serialization.d.ts +0 -1
- package/serialization.js +15 -15
- package/service_locator.d.ts +165 -0
- package/service_locator.js +253 -0
- package/session_pool/consts.d.ts +1 -2
- package/session_pool/consts.js +1 -2
- package/session_pool/errors.d.ts +0 -1
- package/session_pool/errors.js +0 -1
- package/session_pool/fingerprint.d.ts +9 -0
- package/session_pool/fingerprint.js +30 -0
- package/session_pool/index.d.ts +0 -2
- package/session_pool/index.js +0 -2
- package/session_pool/session.d.ts +40 -90
- package/session_pool/session.js +103 -160
- package/session_pool/session_pool.d.ts +85 -101
- package/session_pool/session_pool.js +254 -210
- package/storages/batched_adds.d.ts +37 -0
- package/storages/batched_adds.js +73 -0
- package/storages/dataset.d.ts +114 -56
- package/storages/dataset.js +292 -149
- package/storages/index.d.ts +9 -9
- package/storages/index.js +7 -9
- package/storages/key_value_store.d.ts +186 -48
- package/storages/key_value_store.js +452 -170
- package/storages/key_value_store_codec.d.ts +32 -0
- package/storages/key_value_store_codec.js +113 -0
- package/storages/request_dedup_cache.d.ts +22 -0
- package/storages/request_dedup_cache.js +48 -0
- package/storages/request_list.d.ts +54 -129
- package/storages/request_list.js +272 -245
- package/storages/request_loader.d.ts +133 -0
- package/storages/request_loader.js +36 -0
- package/storages/request_manager.d.ts +109 -0
- package/storages/request_manager.js +1 -0
- package/storages/request_manager_tandem.d.ts +55 -23
- package/storages/request_manager_tandem.js +139 -57
- package/storages/request_queue.d.ts +286 -48
- package/storages/request_queue.js +757 -218
- package/storages/{sitemap_request_list.d.ts → sitemap_request_loader.d.ts} +43 -91
- package/storages/sitemap_request_loader.js +439 -0
- package/storages/storage_instance_manager.d.ts +87 -0
- package/storages/storage_instance_manager.js +256 -0
- package/storages/storage_stats.d.ts +48 -0
- package/storages/storage_stats.js +29 -0
- package/storages/throttling_request_manager.d.ts +223 -0
- package/storages/throttling_request_manager.js +835 -0
- package/storages/transaction.d.ts +260 -0
- package/storages/transaction.js +287 -0
- package/storages/utils.d.ts +59 -11
- package/storages/utils.js +75 -15
- package/system-info/cpu-info.d.ts +67 -0
- package/system-info/cpu-info.js +216 -0
- package/system-info/memory-info.d.ts +31 -0
- package/system-info/memory-info.js +115 -0
- package/system-info/ps-tree.d.ts +17 -0
- package/system-info/ps-tree.js +144 -0
- package/system-info/runtime.d.ts +14 -0
- package/system-info/runtime.js +80 -0
- package/typedefs.d.ts +0 -6
- package/typedefs.js +0 -1
- package/url.d.ts +9 -0
- package/url.js +11 -0
- package/validators.d.ts +23 -18
- package/validators.js +14 -18
- package/autoscaling/autoscaled_pool.d.ts.map +0 -1
- package/autoscaling/autoscaled_pool.js.map +0 -1
- package/autoscaling/index.d.ts.map +0 -1
- package/autoscaling/index.js.map +0 -1
- package/autoscaling/snapshotter.d.ts.map +0 -1
- package/autoscaling/snapshotter.js.map +0 -1
- package/autoscaling/system_status.d.ts.map +0 -1
- package/autoscaling/system_status.js.map +0 -1
- package/configuration.d.ts.map +0 -1
- package/configuration.js.map +0 -1
- package/cookie_utils.d.ts.map +0 -1
- package/cookie_utils.js.map +0 -1
- package/crawlers/context_pipeline.d.ts.map +0 -1
- package/crawlers/context_pipeline.js.map +0 -1
- package/crawlers/crawler_commons.d.ts.map +0 -1
- package/crawlers/crawler_commons.js.map +0 -1
- package/crawlers/crawler_utils.d.ts +0 -10
- package/crawlers/crawler_utils.d.ts.map +0 -1
- package/crawlers/crawler_utils.js +0 -12
- package/crawlers/crawler_utils.js.map +0 -1
- package/crawlers/error_snapshotter.d.ts.map +0 -1
- package/crawlers/error_snapshotter.js.map +0 -1
- package/crawlers/error_tracker.d.ts.map +0 -1
- package/crawlers/error_tracker.js.map +0 -1
- package/crawlers/index.d.ts.map +0 -1
- package/crawlers/index.js.map +0 -1
- package/crawlers/internals/types.d.ts.map +0 -1
- package/crawlers/internals/types.js.map +0 -1
- package/crawlers/statistics.d.ts.map +0 -1
- package/crawlers/statistics.js.map +0 -1
- package/enqueue_links/enqueue_links.d.ts.map +0 -1
- package/enqueue_links/enqueue_links.js.map +0 -1
- package/enqueue_links/index.d.ts.map +0 -1
- package/enqueue_links/index.js.map +0 -1
- package/enqueue_links/shared.d.ts.map +0 -1
- package/enqueue_links/shared.js.map +0 -1
- package/errors.d.ts.map +0 -1
- package/errors.js.map +0 -1
- package/events/event_manager.d.ts.map +0 -1
- package/events/event_manager.js.map +0 -1
- package/events/index.d.ts.map +0 -1
- package/events/index.js.map +0 -1
- package/events/local_event_manager.d.ts.map +0 -1
- package/events/local_event_manager.js.map +0 -1
- package/http_clients/base-http-client.d.ts +0 -140
- package/http_clients/base-http-client.d.ts.map +0 -1
- package/http_clients/base-http-client.js +0 -40
- package/http_clients/base-http-client.js.map +0 -1
- package/http_clients/form-data-like.d.ts +0 -67
- package/http_clients/form-data-like.d.ts.map +0 -1
- package/http_clients/form-data-like.js +0 -5
- package/http_clients/form-data-like.js.map +0 -1
- package/http_clients/got-scraping-http-client.d.ts +0 -20
- package/http_clients/got-scraping-http-client.d.ts.map +0 -1
- package/http_clients/got-scraping-http-client.js +0 -85
- package/http_clients/got-scraping-http-client.js.map +0 -1
- package/http_clients/index.d.ts +0 -3
- package/http_clients/index.d.ts.map +0 -1
- package/http_clients/index.js +0 -3
- package/http_clients/index.js.map +0 -1
- package/index.d.ts.map +0 -1
- package/index.js.map +0 -1
- package/log.d.ts.map +0 -1
- package/log.js.map +0 -1
- package/proxy_configuration.d.ts.map +0 -1
- package/proxy_configuration.js.map +0 -1
- package/recoverable_state.d.ts.map +0 -1
- package/recoverable_state.js.map +0 -1
- package/request.d.ts.map +0 -1
- package/request.js.map +0 -1
- package/router.d.ts.map +0 -1
- package/router.js.map +0 -1
- package/serialization.d.ts.map +0 -1
- package/serialization.js.map +0 -1
- package/session_pool/consts.d.ts.map +0 -1
- package/session_pool/consts.js.map +0 -1
- package/session_pool/errors.d.ts.map +0 -1
- package/session_pool/errors.js.map +0 -1
- package/session_pool/events.d.ts +0 -3
- package/session_pool/events.d.ts.map +0 -1
- package/session_pool/events.js +0 -3
- package/session_pool/events.js.map +0 -1
- package/session_pool/index.d.ts.map +0 -1
- package/session_pool/index.js.map +0 -1
- package/session_pool/session.d.ts.map +0 -1
- package/session_pool/session.js.map +0 -1
- package/session_pool/session_pool.d.ts.map +0 -1
- package/session_pool/session_pool.js.map +0 -1
- package/storages/access_checking.d.ts +0 -13
- package/storages/access_checking.d.ts.map +0 -1
- package/storages/access_checking.js +0 -14
- package/storages/access_checking.js.map +0 -1
- package/storages/dataset.d.ts.map +0 -1
- package/storages/dataset.js.map +0 -1
- package/storages/index.d.ts.map +0 -1
- package/storages/index.js.map +0 -1
- package/storages/key_value_store.d.ts.map +0 -1
- package/storages/key_value_store.js.map +0 -1
- package/storages/request_list.d.ts.map +0 -1
- package/storages/request_list.js.map +0 -1
- package/storages/request_list_adapter.d.ts +0 -58
- package/storages/request_list_adapter.d.ts.map +0 -1
- package/storages/request_list_adapter.js +0 -81
- package/storages/request_list_adapter.js.map +0 -1
- package/storages/request_manager_tandem.d.ts.map +0 -1
- package/storages/request_manager_tandem.js.map +0 -1
- package/storages/request_provider.d.ts +0 -371
- package/storages/request_provider.d.ts.map +0 -1
- package/storages/request_provider.js +0 -585
- package/storages/request_provider.js.map +0 -1
- package/storages/request_queue.d.ts.map +0 -1
- package/storages/request_queue.js.map +0 -1
- package/storages/request_queue_v2.d.ts +0 -87
- package/storages/request_queue_v2.d.ts.map +0 -1
- package/storages/request_queue_v2.js +0 -438
- package/storages/request_queue_v2.js.map +0 -1
- package/storages/sitemap_request_list.d.ts.map +0 -1
- package/storages/sitemap_request_list.js +0 -430
- package/storages/sitemap_request_list.js.map +0 -1
- package/storages/storage_manager.d.ts +0 -58
- package/storages/storage_manager.d.ts.map +0 -1
- package/storages/storage_manager.js +0 -105
- package/storages/storage_manager.js.map +0 -1
- package/storages/utils.d.ts.map +0 -1
- package/storages/utils.js.map +0 -1
- package/typedefs.d.ts.map +0 -1
- package/typedefs.js.map +0 -1
- package/validators.d.ts.map +0 -1
- package/validators.js.map +0 -1
package/crawlers/statistics.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
1
|
+
import type { CrawleeLogger } from '../log.js';
|
|
2
|
+
import type { SyncStateConversion } from '../recoverable_state.js';
|
|
3
3
|
import { KeyValueStore } from '../storages/key_value_store.js';
|
|
4
4
|
import { ErrorTracker } from './error_tracker.js';
|
|
5
5
|
/**
|
|
@@ -12,96 +12,142 @@ export interface PersistenceOptions {
|
|
|
12
12
|
*/
|
|
13
13
|
enable?: boolean;
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* The statistics surface a crawler depends on: recording per-request outcomes, tracking errors, and driving the
|
|
17
|
+
* capture lifecycle for a run. Injected via the crawler's `statistics` option, so a custom implementation can be
|
|
18
|
+
* plugged in without subclassing the crawler.
|
|
19
|
+
*
|
|
20
|
+
* `StateExtension` describes the custom fields tracked alongside the built-in {@link StatisticState} ones - see
|
|
21
|
+
* {@link StatisticsOptions.stateExtension}.
|
|
22
|
+
*
|
|
23
|
+
* The owned-only mutators the crawler uses to *own* a default it built - `reset()`/`resetStore()` - are deliberately
|
|
24
|
+
* absent: an injected instance is borrowed, and the crawler never wipes it. Those live on the concrete
|
|
25
|
+
* {@link Statistics} only.
|
|
26
|
+
*
|
|
27
|
+
* @category Crawlers
|
|
28
|
+
*/
|
|
29
|
+
export interface IStatistics<StateExtension extends object = {}> {
|
|
30
|
+
/** Tracker for errors on the final retry of a request. */
|
|
31
|
+
readonly errorTracker: ErrorTracker;
|
|
32
|
+
/** Tracker for errors on retries prior to the final one. */
|
|
33
|
+
readonly errorTrackerRetry: ErrorTracker;
|
|
34
|
+
/** The live statistics state the crawler reads for status messages and the final summary. */
|
|
35
|
+
readonly state: StatisticState & StateExtension;
|
|
36
|
+
/** Retries histogram - index `i` holds the number of requests that settled after `i` retries. */
|
|
37
|
+
readonly requestRetryHistogram: number[];
|
|
38
|
+
/** Marks a request as started, so its duration can be measured on success/failure. */
|
|
39
|
+
recordRequestStart(id: number | string): void;
|
|
40
|
+
/** Marks a started request as succeeded, updating the succeeded counters and durations. */
|
|
41
|
+
recordRequestSuccess(id: number | string, retryCount: number): void;
|
|
42
|
+
/** Marks a started request as failed, updating the failed counters and durations. */
|
|
43
|
+
recordRequestFailure(id: number | string, retryCount: number): void;
|
|
44
|
+
/** Drops a started request without counting it as succeeded or failed (e.g. skipped by robots.txt). */
|
|
45
|
+
discardRequestRecord(id: number | string): void;
|
|
46
|
+
/** Increments the counter for the given HTTP status code. */
|
|
47
|
+
registerStatusCode(code: number): void;
|
|
48
|
+
/** Computes the derived aggregates (averages, per-minute rates, totals) from the current state. */
|
|
49
|
+
calculate(): CalculatedStatistics;
|
|
50
|
+
/** Begins a capture window: loads any persisted state, subscribes to persistence events, starts periodic logging. */
|
|
51
|
+
startCapturing(): Promise<void>;
|
|
52
|
+
/** Ends the capture window: stops logging, unsubscribes, and persists the final state. */
|
|
53
|
+
stopCapturing(): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Persists the current state to the key-value store. Optional - the crawler calls it on migration, but a backend
|
|
56
|
+
* with no persistence of its own can omit it.
|
|
57
|
+
*/
|
|
58
|
+
persistState?(): Promise<void>;
|
|
59
|
+
}
|
|
60
|
+
/** The derived aggregates computed by {@link IStatistics.calculate} from the current {@link StatisticState}. */
|
|
61
|
+
export interface CalculatedStatistics {
|
|
62
|
+
/** Mean duration of a failed request, in milliseconds; `Infinity` when nothing has failed. */
|
|
63
|
+
requestAvgFailedDurationMillis: number;
|
|
64
|
+
/** Mean duration of a succeeded request, in milliseconds; `Infinity` when nothing has succeeded. */
|
|
65
|
+
requestAvgSucceededDurationMillis: number;
|
|
66
|
+
/** Requests succeeded per minute over the run so far. */
|
|
67
|
+
requestsSucceededPerMinute: number;
|
|
68
|
+
/** Requests failed per minute over the run so far. */
|
|
69
|
+
requestsFailedPerMinute: number;
|
|
70
|
+
/** Combined duration of all succeeded and failed requests, in milliseconds. */
|
|
71
|
+
requestTotalDurationMillis: number;
|
|
72
|
+
/** Total number of settled requests (succeeded plus failed). */
|
|
73
|
+
requestsTotal: number;
|
|
74
|
+
/** Wall-clock runtime since capturing started, in milliseconds. */
|
|
75
|
+
crawlerRuntimeMillis: number;
|
|
76
|
+
}
|
|
15
77
|
/**
|
|
16
78
|
* The statistics class provides an interface to collecting and logging run
|
|
17
79
|
* statistics for requests.
|
|
18
80
|
*
|
|
19
81
|
* All statistic information is saved on key value store
|
|
20
|
-
* under the key `
|
|
82
|
+
* under the key `CRAWLEE_CRAWLER_STATISTICS_*`, persists between
|
|
21
83
|
* migrations and abort/resurrect
|
|
22
84
|
*
|
|
85
|
+
* Custom fields are tracked by passing {@link StatisticsOptions.stateExtension|`stateExtension`} - the extra fields are then part
|
|
86
|
+
* of {@link Statistics.state|`state`}, persisted and restored along with the built-in ones.
|
|
87
|
+
*
|
|
23
88
|
* @category Crawlers
|
|
24
89
|
*/
|
|
25
|
-
export declare class Statistics {
|
|
26
|
-
private
|
|
90
|
+
export declare class Statistics<StateExtension extends object = {}, PersistedStateExtension extends object = StateExtension> implements IStatistics<StateExtension> {
|
|
91
|
+
#private;
|
|
27
92
|
/**
|
|
28
93
|
* An error tracker for final retry errors.
|
|
29
94
|
*/
|
|
30
|
-
errorTracker: ErrorTracker;
|
|
95
|
+
readonly errorTracker: ErrorTracker;
|
|
31
96
|
/**
|
|
32
97
|
* An error tracker for retry errors prior to the final retry.
|
|
33
98
|
*/
|
|
34
|
-
errorTrackerRetry: ErrorTracker;
|
|
99
|
+
readonly errorTrackerRetry: ErrorTracker;
|
|
35
100
|
/**
|
|
36
101
|
* Statistic instance id.
|
|
37
102
|
*/
|
|
38
|
-
readonly id:
|
|
103
|
+
readonly id: string;
|
|
104
|
+
private readonly log;
|
|
39
105
|
/**
|
|
40
106
|
* Current statistic state used for doing calculations on {@link Statistics.calculate} calls
|
|
41
107
|
*/
|
|
42
|
-
state: StatisticState;
|
|
108
|
+
get state(): StatisticState & StateExtension;
|
|
43
109
|
/**
|
|
44
110
|
* Contains the current retries histogram. Index 0 means 0 retries, index 2, 2 retries, and so on
|
|
45
111
|
*/
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Contains the associated Configuration instance
|
|
49
|
-
*/
|
|
50
|
-
private readonly config;
|
|
51
|
-
protected keyValueStore?: KeyValueStore;
|
|
52
|
-
protected persistStateKey: string;
|
|
53
|
-
private logIntervalMillis;
|
|
54
|
-
private logMessage;
|
|
55
|
-
private listener;
|
|
56
|
-
private requestsInProgress;
|
|
57
|
-
private readonly log;
|
|
58
|
-
private instanceStart;
|
|
59
|
-
private logInterval;
|
|
60
|
-
private events;
|
|
61
|
-
private persistenceOptions;
|
|
112
|
+
get requestRetryHistogram(): number[];
|
|
62
113
|
/**
|
|
63
|
-
*
|
|
114
|
+
* Construct a statistics instance to pass to a crawler via its `statistics` option, e.g. to preconfigure
|
|
115
|
+
* persistence or error snapshots, share it across sequential runs, or track extra fields via `state`.
|
|
64
116
|
*/
|
|
65
|
-
constructor(options?: StatisticsOptions);
|
|
117
|
+
constructor(options?: StatisticsOptions<StateExtension, PersistedStateExtension>);
|
|
66
118
|
/**
|
|
67
|
-
* Set the current statistic instance to pristine values
|
|
119
|
+
* Set the current statistic instance to pristine values.
|
|
120
|
+
*
|
|
121
|
+
* The persisted record is left alone - use {@link Statistics.resetStore} to clear that as well.
|
|
68
122
|
*/
|
|
69
123
|
reset(): void;
|
|
70
124
|
/**
|
|
71
|
-
*
|
|
125
|
+
* Clear the persisted statistics record, leaving the in-memory state alone.
|
|
126
|
+
*
|
|
127
|
+
* Throws while capturing - the next PERSIST_STATE event would write the record straight back.
|
|
72
128
|
*/
|
|
73
|
-
resetStore(
|
|
129
|
+
resetStore(): Promise<void>;
|
|
74
130
|
/**
|
|
75
131
|
* Increments the status code counter.
|
|
76
132
|
*/
|
|
77
133
|
registerStatusCode(code: number): void;
|
|
134
|
+
/** @ignore */
|
|
135
|
+
recordRequestStart(id: number | string): void;
|
|
136
|
+
/** @ignore */
|
|
137
|
+
recordRequestSuccess(id: number | string, retryCount: number): void;
|
|
138
|
+
/** @ignore */
|
|
139
|
+
recordRequestFailure(id: number | string, retryCount: number): void;
|
|
78
140
|
/**
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
|
|
82
|
-
startJob(id: number | string): void;
|
|
83
|
-
/**
|
|
84
|
-
* Mark job as finished and sets the state
|
|
141
|
+
* Discards a started request without affecting the succeeded/failed counters, e.g. when a request
|
|
142
|
+
* turns out to be skipped (robots.txt, enqueue strategy) after `recordRequestStart` was already
|
|
143
|
+
* called for it.
|
|
85
144
|
* @ignore
|
|
86
145
|
*/
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Mark job as failed and sets the state
|
|
90
|
-
* @ignore
|
|
91
|
-
*/
|
|
92
|
-
failJob(id: number | string, retryCount: number): void;
|
|
146
|
+
discardRequestRecord(id: number | string): void;
|
|
93
147
|
/**
|
|
94
148
|
* Calculate the current statistics
|
|
95
149
|
*/
|
|
96
|
-
calculate():
|
|
97
|
-
requestAvgFailedDurationMillis: number;
|
|
98
|
-
requestAvgFinishedDurationMillis: number;
|
|
99
|
-
requestsFinishedPerMinute: number;
|
|
100
|
-
requestsFailedPerMinute: number;
|
|
101
|
-
requestTotalDurationMillis: number;
|
|
102
|
-
requestsTotal: number;
|
|
103
|
-
crawlerRuntimeMillis: number;
|
|
104
|
-
};
|
|
150
|
+
calculate(): CalculatedStatistics;
|
|
105
151
|
/**
|
|
106
152
|
* Initializes the key value store for persisting the statistics,
|
|
107
153
|
* displaying the current state in predefined intervals
|
|
@@ -111,27 +157,24 @@ export declare class Statistics {
|
|
|
111
157
|
* Stops logging and remove event listeners, then persist
|
|
112
158
|
*/
|
|
113
159
|
stopCapturing(): Promise<void>;
|
|
114
|
-
|
|
160
|
+
private saveRetryCountForRequest;
|
|
115
161
|
/**
|
|
116
|
-
* Persist internal state to the key value store
|
|
117
|
-
*
|
|
162
|
+
* Persist internal state to the key value store.
|
|
163
|
+
*
|
|
164
|
+
* Statistics are bookkeeping - a store that refuses the write is worth a warning, not a failed crawl. The
|
|
165
|
+
* crawler calls this from its migration handler, where a rejection would go unhandled.
|
|
118
166
|
*/
|
|
119
|
-
persistState(
|
|
120
|
-
/**
|
|
121
|
-
* Loads the current statistic from the key value store if any
|
|
122
|
-
*/
|
|
123
|
-
protected _maybeLoadStatistics(): Promise<void>;
|
|
124
|
-
protected _teardown(): void;
|
|
167
|
+
persistState(): Promise<void>;
|
|
125
168
|
/**
|
|
126
169
|
* Make this class serializable when called with `JSON.stringify(statsInstance)` directly
|
|
127
170
|
* or through `keyValueStore.setValue('KEY', statsInstance)`
|
|
128
171
|
*/
|
|
129
|
-
toJSON(): StatisticPersistedState;
|
|
172
|
+
toJSON(): StatisticPersistedState & PersistedStateExtension;
|
|
130
173
|
}
|
|
131
174
|
/**
|
|
132
175
|
* Configuration for the {@link Statistics} instance used by the crawler
|
|
133
176
|
*/
|
|
134
|
-
export interface StatisticsOptions {
|
|
177
|
+
export interface StatisticsOptions<StateExtension extends object = {}, PersistedStateExtension extends object = StateExtension> {
|
|
135
178
|
/**
|
|
136
179
|
* Interval in seconds to log the current statistics
|
|
137
180
|
* @default 60
|
|
@@ -146,17 +189,12 @@ export interface StatisticsOptions {
|
|
|
146
189
|
* Parent logger instance, the statistics will create a child logger from this.
|
|
147
190
|
* @default crawler.log
|
|
148
191
|
*/
|
|
149
|
-
log?:
|
|
192
|
+
log?: CrawleeLogger;
|
|
150
193
|
/**
|
|
151
194
|
* Key value store instance to persist the statistics.
|
|
152
195
|
* If not provided, the default one will be used when capturing starts
|
|
153
196
|
*/
|
|
154
197
|
keyValueStore?: KeyValueStore;
|
|
155
|
-
/**
|
|
156
|
-
* Configuration instance to use
|
|
157
|
-
* @default Configuration.getGlobalConfig()
|
|
158
|
-
*/
|
|
159
|
-
config?: Configuration;
|
|
160
198
|
/**
|
|
161
199
|
* Control how and when to persist the statistics.
|
|
162
200
|
*/
|
|
@@ -166,33 +204,104 @@ export interface StatisticsOptions {
|
|
|
166
204
|
* @default false
|
|
167
205
|
*/
|
|
168
206
|
saveErrorSnapshots?: boolean;
|
|
207
|
+
/**
|
|
208
|
+
* A unique identifier for this statistics instance. This ID is used for persistence
|
|
209
|
+
* to the key value store, ensuring the same statistics can be loaded after script restarts.
|
|
210
|
+
*
|
|
211
|
+
* If not provided, an auto-incremented ID will be used for backward compatibility.
|
|
212
|
+
* This means statistics may not persist correctly across script restarts
|
|
213
|
+
* if crawler creation order changes.
|
|
214
|
+
*/
|
|
215
|
+
id?: string;
|
|
216
|
+
/**
|
|
217
|
+
* Custom fields to track alongside the built-in {@link StatisticState} ones. They become part of
|
|
218
|
+
* {@link Statistics.state|`state`} (typed as such), are persisted with the rest of the state, and are
|
|
219
|
+
* restored on migration or resurrect.
|
|
220
|
+
*
|
|
221
|
+
* ```ts
|
|
222
|
+
* const statistics = new Statistics({ stateExtension: { defaultState: { productsFound: 0 } } });
|
|
223
|
+
* statistics.state.productsFound++;
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
stateExtension?: StatisticStateExtensionOptions<StateExtension, PersistedStateExtension>;
|
|
169
227
|
}
|
|
170
228
|
/**
|
|
171
|
-
*
|
|
229
|
+
* How the custom fields of {@link StatisticsOptions.stateExtension} are initialized and converted to and from the
|
|
230
|
+
* persisted record - the same three things {@link RecoverableStateOptions} asks for, scoped to the custom half
|
|
231
|
+
* of the statistics state.
|
|
172
232
|
*/
|
|
173
|
-
export interface
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
233
|
+
export interface StatisticStateExtensionOptions<StateExtension extends object, PersistedStateExtension extends object = StateExtension> {
|
|
234
|
+
/**
|
|
235
|
+
* The values the fields start with, and the ones {@link Statistics.reset} restores. A plain value is
|
|
236
|
+
* deep-copied with `structuredClone` each time it is used; pass a factory for a state `structuredClone` cannot
|
|
237
|
+
* rebuild.
|
|
238
|
+
*
|
|
239
|
+
* Can be omitted when `deserialize` supplies its own defaults, which is then the single place the fields are
|
|
240
|
+
* declared - see the example on {@link StatisticStateExtensionOptions.deserialize|`deserialize`}.
|
|
241
|
+
*/
|
|
242
|
+
defaultState?: StateExtension | (() => StateExtension);
|
|
243
|
+
/**
|
|
244
|
+
* Rebuilds the custom fields from the persisted record, and the place to validate them before trusting them.
|
|
245
|
+
* Receives the whole record, so it has to supply a value for every field - `.default()` in a schema, or
|
|
246
|
+
* {@link StatisticStateExtensionOptions.defaultState|`defaultState`} alongside a conversion that copes with
|
|
247
|
+
* a missing field itself.
|
|
248
|
+
*
|
|
249
|
+
* ```ts
|
|
250
|
+
* const statistics = new Statistics({
|
|
251
|
+
* stateExtension: { deserialize: z.object({ productsFound: z.number().default(0) }) },
|
|
252
|
+
* });
|
|
253
|
+
* ```
|
|
254
|
+
*
|
|
255
|
+
* Without it, the declared fields are restored as they were persisted - which is a record off the key-value
|
|
256
|
+
* store taken at its word, `productsFound` included in whatever type it happens to hold.
|
|
257
|
+
*
|
|
258
|
+
* A conversion that rejects the record costs the custom fields their persisted values (they start from the
|
|
259
|
+
* defaults, with a warning) and nothing else.
|
|
260
|
+
*/
|
|
261
|
+
deserialize?: SyncStateConversion<unknown, StateExtension>;
|
|
262
|
+
/**
|
|
263
|
+
* Converts the custom fields to the JSON-serializable form they are persisted in. Not needed for fields that
|
|
264
|
+
* already are one - pair it with `deserialize` for the fields that are not.
|
|
265
|
+
*/
|
|
266
|
+
serialize?: SyncStateConversion<StateExtension, PersistedStateExtension>;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Format of the persisted stats.
|
|
270
|
+
*
|
|
271
|
+
* The `null`s are `Infinity` on the way out - JSON has no infinity, so a record written before anything
|
|
272
|
+
* succeeded or failed carries a `null` in its place.
|
|
273
|
+
*/
|
|
274
|
+
export interface StatisticPersistedState extends Omit<StatisticState, 'statsPersistedAt' | 'crawlerStartedAt' | 'crawlerFinishedAt' | 'requestMinDurationMillis' | 'requestsFailedPerMinute' | 'requestsSucceededPerMinute' | 'requestRetryHistogram' | 'instanceStart'> {
|
|
275
|
+
statsId: string;
|
|
276
|
+
requestsFailedPerMinute: number | null;
|
|
277
|
+
requestsSucceededPerMinute: number | null;
|
|
278
|
+
/** ISO strings - the live state keeps these as `Date`s. */
|
|
279
|
+
crawlerStartedAt: string | null;
|
|
280
|
+
crawlerFinishedAt: string | null;
|
|
281
|
+
statsPersistedAt: string;
|
|
282
|
+
requestMinDurationMillis: number | null;
|
|
283
|
+
/** A retry count that no request ever reached leaves a `null` here. */
|
|
284
|
+
requestRetryHistogram: (number | null)[];
|
|
285
|
+
requestAvgFailedDurationMillis: number | null;
|
|
286
|
+
requestAvgSucceededDurationMillis: number | null;
|
|
178
287
|
requestTotalDurationMillis: number;
|
|
179
288
|
requestsTotal: number;
|
|
289
|
+
/** {@link StatisticState.instanceStart} of the run that wrote the record. */
|
|
180
290
|
crawlerLastStartTimestamp: number;
|
|
181
|
-
statsPersistedAt: string;
|
|
182
291
|
}
|
|
183
292
|
/**
|
|
184
293
|
* Contains the statistics state
|
|
185
294
|
*/
|
|
186
295
|
export interface StatisticState {
|
|
187
|
-
|
|
296
|
+
requestsSucceeded: number;
|
|
188
297
|
requestsFailed: number;
|
|
189
298
|
requestsRetries: number;
|
|
190
299
|
requestsFailedPerMinute: number;
|
|
191
|
-
|
|
300
|
+
requestsSucceededPerMinute: number;
|
|
192
301
|
requestMinDurationMillis: number;
|
|
193
302
|
requestMaxDurationMillis: number;
|
|
194
303
|
requestTotalFailedDurationMillis: number;
|
|
195
|
-
|
|
304
|
+
requestTotalSucceededDurationMillis: number;
|
|
196
305
|
crawlerStartedAt: Date | string | null;
|
|
197
306
|
crawlerFinishedAt: Date | string | null;
|
|
198
307
|
crawlerRuntimeMillis: number;
|
|
@@ -200,5 +309,11 @@ export interface StatisticState {
|
|
|
200
309
|
errors: Record<string, unknown>;
|
|
201
310
|
retryErrors: Record<string, unknown>;
|
|
202
311
|
requestsWithStatusCode: Record<string, number>;
|
|
312
|
+
/** Retries histogram - index `i` holds the number of requests that settled after `i` retries. */
|
|
313
|
+
requestRetryHistogram: number[];
|
|
314
|
+
/**
|
|
315
|
+
* When the current capture window started, as a `Date.now()` timestamp. Rebased on load so that the runtime
|
|
316
|
+
* reported by {@link Statistics.calculate} spans a migration rather than restarting from zero.
|
|
317
|
+
*/
|
|
318
|
+
instanceStart: number;
|
|
203
319
|
}
|
|
204
|
-
//# sourceMappingURL=statistics.d.ts.map
|