Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow configuring crawler statistics #2213

Merged
merged 13 commits into from
Dec 20, 2023
Merged

Conversation

foxt451
Copy link
Collaborator

@foxt451 foxt451 commented Nov 30, 2023

Allow disabling automatic persistence in Statistics and SessionPool.
Add additional methods for manual disabling in case it's needed, but just not the automatic one
Closes #1789

@foxt451 foxt451 requested a review from B4nan November 30, 2023 14:17
@foxt451 foxt451 changed the title Feat/statistics config feat/statistics config Nov 30, 2023
@foxt451 foxt451 changed the title feat/statistics config feat/statistics-config Nov 30, 2023
@foxt451 foxt451 changed the title feat/statistics-config feat(core,basic-crawler)/statistics-config Nov 30, 2023
@foxt451 foxt451 changed the title feat(core,basic-crawler)/statistics-config feat(core,basic-crawler): statistics-config Nov 30, 2023
@B4nan B4nan changed the title feat(core,basic-crawler): statistics-config feat: allow configuring crawler statistics Dec 7, 2023
@B4nan B4nan requested a review from metalwarrior665 December 7, 2023 14:12
packages/core/src/crawlers/statistics.ts Outdated Show resolved Hide resolved
/**
* Manually reset KV store entry for the statistics, ignoring the {@apilink StatisticsOptions.enablePersistence} flag
*/
async resetStoreForce() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need a separate method for this? i'd probably prefer force parameter here

/**
* Same as {@apilink Statistics.persistState}, but ignores the {@apilink StatisticsOptions.enablePersistence} flag
*/
async persistStateForce() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Member

@metalwarrior665 metalwarrior665 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just Banan's comments

@foxt451 foxt451 requested a review from B4nan December 7, 2023 15:57
@@ -159,17 +159,15 @@ export class Statistics {
this._teardown();
}

async resetStore() {
if (!this.enablePersistence) {
async resetStore(opts?: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please create a new interface for this

packages/core/src/crawlers/statistics.ts Outdated Show resolved Hide resolved
async persistState() {
// this might be called before startCapturing was called without using await, should not crash
if (!this.enablePersistence || !this.keyValueStore) {
async persistState(opts?: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, you can use the same interface (try to find some generic name that would fit both methods)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, added. I'm not really sure though whether it would be better to add the interface locally to each file or create a shared one

packages/core/src/crawlers/statistics.ts Outdated Show resolved Hide resolved
if (!this.enablePersistence) {
async resetStore(opts?: {
/**
* If true, manually reset KV store entry for the statistics, ignoring the {@apilink StatisticsOptions.enablePersistence} flag
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about the word "manually" here. If you call this method, its always manual usage, regardless of the options.

@@ -309,17 +307,15 @@ export class SessionPool extends EventEmitter {
return this._createSession();
}

async resetStore() {
if (!this.enablePersistence) {
async resetStore(opts?: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

@@ -339,17 +335,15 @@ export class SessionPool extends EventEmitter {
* Persists the current state of the `SessionPool` into the default {@apilink KeyValueStore}.
* The state is persisted automatically in regular intervals.
*/
async persistState(): Promise<void> {
if (!this.enablePersistence) {
async persistState(opts?: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

packages/core/src/session_pool/session_pool.ts Outdated Show resolved Hide resolved
packages/core/src/session_pool/session_pool.ts Outdated Show resolved Hide resolved
foxt451 and others added 5 commits December 7, 2023 18:08
Co-authored-by: Martin Adámek <banan23@gmail.com>
Co-authored-by: Martin Adámek <banan23@gmail.com>
Co-authored-by: Martin Adámek <banan23@gmail.com>
Co-authored-by: Martin Adámek <banan23@gmail.com>
}) {
if (!this.enablePersistence && !opts?.force) {
async resetStore(opts?: PersistenceOptionsOverrides) {
if (!(this.enablePersistence || opts?.enablePersistence)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please apply this change to all the occurrences

Suggested change
if (!(this.enablePersistence || opts?.enablePersistence)) {
if (!this.enablePersistence && !opts?.enablePersistence) {

@foxt451 foxt451 requested a review from B4nan December 8, 2023 11:34
@mtrunkat mtrunkat added the t-tooling Issues with this label are in the ownership of the tooling team. label Dec 11, 2023
Copy link
Member

@B4nan B4nan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just few comments for now

force?: boolean;
}) {
if (!this.enablePersistence && !opts?.force) {
async resetStore(opts?: PersistenceOptionsOverrides) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets not use abbreviations unless needed (e.g. when there is a collision)

Suggested change
async resetStore(opts?: PersistenceOptionsOverrides) {
async resetStore(options?: PersistenceOptionsOverrides) {

async resetStore(opts?: PersistenceOptionsOverrides) {
if (!this.enablePersistence && !opts?.enablePersistence) {
return;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i like to keep one blank line after control statements like if/for/while/etc, this applies to other places in the PR too (e.g. the persistState method), take it as a rule of thumb

Suggested change
}
}

/**
* Override persistence-related options provided in {@apilink SessionPoolOptions} for a single method call
*/
interface PersistenceOptionsOverrides {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to have a single interface for both since it's exactly the same. Let's export it and reuse it instead of creating two local implementations.

I also don't like the name very much, will try to come up with something else, I don't have any ideas right now :]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've restructured it a bit, so that the same interface is used in the constructor and options parameter. Does that look okay?

I'm also not sure where to actually put this interface in the project hierarchy. I don't see a matching module for utilities/types shared by both statistics and session pool

@foxt451 foxt451 requested a review from B4nan December 12, 2023 18:04
@B4nan
Copy link
Member

B4nan commented Dec 20, 2023

FYI the tests are failing, so if you are waiting for my review - its actually me who is waiting for you to fix them first :]

@foxt451 foxt451 requested review from B4nan and removed request for B4nan December 20, 2023 13:57
Copy link
Member

@B4nan B4nan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@B4nan B4nan merged commit 9fd60e4 into master Dec 20, 2023
8 checks passed
@B4nan B4nan deleted the feat/statistics-config branch December 20, 2023 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t-tooling Issues with this label are in the ownership of the tooling team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose config option to not persist SessionPool and Statistics
4 participants