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

Add SDK support for web scraping #30

Merged
merged 2 commits into from
Jul 15, 2024
Merged

Add SDK support for web scraping #30

merged 2 commits into from
Jul 15, 2024

Conversation

EvanBoyle
Copy link
Member

@EvanBoyle EvanBoyle commented Jul 13, 2024

Nothing fancy, just what it says on the box. I did add e2e tests, but left them turned off by default. Given that scraping is async, it could take multiple minutes for scraping to actually happen if there are a lot of documents already in the queue (like we might see in production). Running these tests against the API dev stack takes less than a minute.

Summary by CodeRabbit

  • New Features

    • Added support for URL and sitemap content types in batch processing.
    • Introduced new tests for scraping URLs and sitemaps in different environments.
  • Bug Fixes

    • Enhanced error handling when mixing different content types in batch upsert operations.
  • Chores

    • Updated .npmignore to exclude images and .github directories.
    • Added specific test scripts for development and production environments in package.json.

Copy link

coderabbitai bot commented Jul 13, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

This update introduces significant enhancements to URL and sitemap handling in the catalog system, adds new test scripts for scraping, and introduces scraping.test.ts for comprehensive scraping tests. Changes also include improved error handling and new content types, ensuring robust document processing.

Changes

Files/Paths Change Summary
.npmignore Added images and .github; corrected vitest* typo.
catalog.ts Added flags and updated logic for url and sitemap-url; improved error handling and upsert logic.
document.ts Introduced new types UrlContentType, SitemapContentType, UrlDocument, SitemapDocument.
package.json Added new test scripts for scraping in development and production.
scraping.test.ts Introduced new tests for scraping URLs, sitemaps, and multiple catalogs concurrently.

Poem

In the code, new types arise,
URLs and sitemaps, a surprise!
Tests for scraping, now so grand,
Catalogs enhanced, perfectly planned.
With each update, steps we take,
To ensure a robust, seamless make. 🌐✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (4)
scraping.test.ts (4)

8-8: Add a comment explaining the choice of the value 4.

It would be helpful to add a comment explaining why the value 4 is chosen for expectedSitemapUrls.

+ // The value 4 is chosen because <explanation>
const expectedSitemapUrls = 4;

10-49: Add more detailed logging for debugging purposes.

The test for scraping a single URL is correctly implemented, but adding more detailed logging would help in debugging.

+ console.log(`Configured catalog: ${catalogName}`);
+ console.log(`Upserted document: ${docs[0].url}`);
while (!docsFound) {
  const docCount = await catalog.documentCount();
  if (docCount === 1) {
    docsFound = true;
  } else {
    console.log("no docs found. sleeping...");
    await sleep(5000);
  }
}
+ console.log(`Document count after upsert: ${docCount}`);

51-87: Add more detailed logging for debugging purposes.

The test for scraping a sitemap is correctly implemented, but adding more detailed logging would help in debugging.

+ console.log(`Configured catalog: ${catalogName}`);
+ console.log(`Upserted sitemap document: ${docs[0].sitemapUrl}`);
while (!docsFound) {
  const docCount = await catalog.documentCount();
  if (docCount === expectedSitemapUrls) {
    docsFound = true;
  } else {
    console.log(`${docCount} docs found. sleeping...`);
    await sleep(5000);
  }
}
+ console.log(`Document count after upsert: ${docCount}`);

89-151: Add more detailed logging for debugging purposes.

The test for isolation of scraping multiple catalogs at once is correctly implemented, but adding more detailed logging would help in debugging.

+ console.log(`Configured catalogs: ${catalogName1}, ${catalogName2}, ${catalogName3}, ${catalogName4}, ${catalogName5}`);
+ console.log(`Upserted sitemap document: ${docs[0].sitemapUrl}`);
while (!docsFound) {
  const catalog1Count = await catalog1.documentCount();
  const catalog2Count = await catalog2.documentCount();
  const catalog3Count = await catalog3.documentCount();
  const catalog4Count = await catalog4.documentCount();
  const catalog5Count = await catalog5.documentCount();
  if (
    [
      catalog1Count,
      catalog2Count,
      catalog3Count,
      catalog4Count,
      catalog5Count,
    ].every((e) => e === 4)
  ) {
    docsFound = true;
  } else {
    await sleep(5000);
  }
}
+ console.log(`Document counts after upsert: ${catalog1Count}, ${catalog2Count}, ${catalog3Count}, ${catalog4Count}, ${catalog5Count}`);
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 29ca780 and a83e617.

Files selected for processing (5)
  • .npmignore (1 hunks)
  • catalog.ts (5 hunks)
  • document.ts (2 hunks)
  • package.json (1 hunks)
  • scraping.test.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • .npmignore
Additional comments not posted (17)
package.json (3)

38-38: LGTM!

The script for running scraping tests in the development environment is correctly configured.


39-39: LGTM!

The script for running scraping tests in the production environment is correctly configured.


37-37: LGTM!

The script for running indexer tests in the development environment is correctly configured.

document.ts (6)

4-4: LGTM!

The type definition for UrlContentType is correct.


5-5: LGTM!

The type definition for SitemapContentType is correct.


10-15: LGTM!

The type definition for ContentType is correctly extended to include UrlContentType and SitemapContentType.


17-20: LGTM!

The type definition for UrlDocument is correct.


22-25: LGTM!

The type definition for SitemapDocument is correct.


51-56: LGTM!

The type definition for DocumentBatch is correctly extended to include arrays of UrlDocument and SitemapDocument.

scraping.test.ts (2)

6-6: LGTM!

The variable runScraperTests is correctly set based on the environment variable RUN_SCRAPER_TESTS.


154-158: LGTM!

The utility function sleep is correctly implemented.

catalog.ts (6)

139-140: LGTM!

The variables hasUrl and hasSitemapUrl are correctly added to the Catalog class.


153-155: LGTM!

The case for url content type is correctly added to the batch processing logic.


156-158: LGTM!

The case for sitemap-url content type is correctly added to the batch processing logic.


167-172: LGTM!

The conditional for mixed content types is correctly updated to include url and sitemap-url content types.


195-195: LGTM!

The conditional for upsert success is correctly updated to check if the response status is greater than 202.


292-303: LGTM!

The function mapBatch is correctly updated to handle url and sitemap-url content types.

Copy link
Contributor

@chaosrealm chaosrealm left a comment

Choose a reason for hiding this comment

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

LGTM, just left a comment / question.

@@ -1,11 +1,28 @@
import { CortexApiClient } from "./api-client.js";
import { Catalog } from "./catalog.js";

export type UrlContentType = "url";
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be better for discoverability / intellisense experience to use ContentTypeXYZ naming pattern?

Copy link
Member Author

Choose a reason for hiding this comment

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

In hindsight yes. Probably a change we should make at some point, but for now I'm just pattern matching against the existing content types.

@EvanBoyle EvanBoyle merged commit b2783a4 into main Jul 15, 2024
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants