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

[WIP] Feat/analytics clickhouse db #150

Open
wants to merge 24 commits into
base: main
Choose a base branch
from

Conversation

Tim-53
Copy link
Collaborator

@Tim-53 Tim-53 commented Jul 28, 2024

Summary by CodeRabbit

  • New Features

    • Introduced functionality for creating and interacting with a ClickHouse database.
    • Added scripts for database migration and creation in the application.
    • Enhanced editor customization with new spell-checker settings for specific terminology.
    • Established foundational structure for the bullmq-receiver project with essential metadata and dependencies.
  • Bug Fixes

    • Enhanced error handling during data fetching and insertion processes.
  • Documentation

    • Updated and added documentation to reflect changes in event handling and database interactions.
  • Chores

    • Streamlined import statements across files to reduce complexity.
  • Style

    • Improved code readability and maintainability through refactoring and clearer data flow.

Copy link

vercel bot commented Jul 28, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
abby-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 2, 2024 10:29pm
abby-opensource ❌ Failed (Inspect) Aug 2, 2024 10:29pm

Copy link
Contributor

coderabbitai bot commented Jul 28, 2024

Walkthrough

The recent changes enrich the application's functionality by providing better integration with a ClickHouse database. New scripts facilitate database management tasks, while updates to components enhance clarity and efficiency in data handling. The introduction of custom words for spell checking and basic logging capabilities further supports a smoother development experience. Overall, the modifications aim to improve performance and maintainability across the codebase.

Changes

Files Changed Change Summary
.vscode/settings.json Added custom words for spell checking to enhance editor functionality.
apps/bullmq-receiver/package.json, apps/bullmq-receiver/src/index.ts Introduced a new package configuration and a basic logging entry point, establishing foundational elements for the application.
apps/web/package.json New scripts for ClickHouse migration and creation, along with the addition of the @clickhouse/client dependency.
apps/web/src/api/routes/v1_event.ts Imports reduced, suggesting a streamlined event handling process.
apps/web/src/components/Test/*.tsx Changes to various components simplify data processing by consolidating props into a single visitData parameter for better efficiency and clarity.
apps/web/src/lib/events.ts Modifications to the SpecialTimeInterval enum and related functions improve clarity in time interval representation.
apps/web/src/pages/projects/[projectId]/index.tsx, apps/web/src/pages/projects/[projectId]/tests/[testId].tsx Updates in rendering logic enhance clarity and maintainability in project and test detail pages.
apps/web/server/queue/*.ts, apps/web/server/services/ClickHouseEventService.ts Transitioned from EventService to ClickHouseEventService for event management, reflecting a shift in data handling methods.
docker-compose.yaml New ClickHouse service added to the Docker setup.
generate_csv/*.js, generate_csv/*.ts Introduced scripts for generating CSV files and inserting data into ClickHouse, enhancing testing capabilities.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ClickHouseClient
    participant ClickHouseEventService
    participant Database

    User->>ClickHouseClient: Request data insertion
    ClickHouseClient->>ClickHouseEventService: Process event data
    ClickHouseEventService->>Database: Insert event records
    Database-->>ClickHouseEventService: Confirm insertion
    ClickHouseEventService-->>ClickHouseClient: Return success
    ClickHouseClient-->>User: Notify insertion complete
Loading

🐰 In a world of data, hopping around,
New ClickHouse features have come to abound!
With events now flowing, so swift and so neat,
Our code is much clearer, and oh, what a feat!
From CSVs to metrics, we dance with delight,
This rabbit is thrilled—it all feels just right! 🥕✨


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 Configuration 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
Contributor

@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: 21

Outside diff range, codebase verification and nitpick comments (9)
apps/web/src/api/routes/v1_event.ts (1)

2-2: The removal of RequestCache is not correct.

The RequestCache is still being used in multiple files across the codebase. Removing it from apps/web/src/api/routes/v1_event.ts without proper refactoring will likely break existing functionality. Here are some of the files where RequestCache is still in use:

  • apps/web/src/server/queue/event.ts
  • apps/web/src/server/queue/AfterDataRequest.ts
  • apps/web/src/server/services/ClickHouseEventService.ts
  • apps/web/src/server/services/RequestCache.ts
  • apps/web/src/pages/api/stripe.ts
  • apps/web/src/pages/api/invalidate-limits.ts

Please review these instances and ensure that the removal of RequestCache is handled appropriately.

Analysis chain

Ensure the removal of RequestCache is correct.

Verify that the removal of RequestCache does not break any existing functionality and that it is no longer needed in this file.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `RequestCache`.

# Test: Search for the usage of `RequestCache` in the codebase. Expect: No usage in the current file.
rg --type typescript -A 5 $'RequestCache'

Length of output: 75


Script:

#!/bin/bash
# Description: Verify the usage of `RequestCache`.

# Test: Search for the usage of `RequestCache` in the codebase. Expect: No usage in the current file.
rg 'RequestCache' --glob '*.ts' -A 5

Length of output: 6206

apps/web/clickhouse/createDatabase.ts (1)

9-38: Remove or clarify commented-out code.

Commented-out code can clutter the codebase. If this code is not needed, consider removing it. If it is temporarily commented out, add a TODO comment explaining why.

generate_csv/generate_csv.ts (2)

12-20: LGTM! Consider simplifying the date format.

The randomDate function is well-implemented. You can simplify the date format by using toISOString directly.

-  return randomTime.toISOString().replace("T", " ").substring(0, 23);
+  return randomTime.toISOString().slice(0, 19).replace("T", " ");

38-66: LGTM! Remove the commented-out line.

The generateCSV function is well-implemented. Chunk writing is a good practice to avoid memory issues. Consider removing the commented-out line for project IDs.

-      //   projectIds[Math.floor(Math.random() * PROJECT_COUNT)],
apps/web/src/pages/projects/[projectId]/index.tsx (1)

13-13: LGTM! Consider removing unused import.

The import statement for AbbyEventType is added but not used in the current code. Consider removing it if not intended for future use.

apps/web/src/lib/events.ts (1)

Line range hint 63-66:
Update case to use SpecialTimeInterval enum.

The case for "30d" should be updated to use SpecialTimeInterval.Last30DAYS for consistency.

-    case "30d": {
+    case SpecialTimeInterval.Last30DAYS: {
apps/web/src/pages/projects/[projectId]/tests/[testId].tsx (1)

122-137: Computation approved.

The viewEvents variable correctly derives its dataset from the events array.

Remove console.log statement if not needed.

The console.log statement may be unnecessary for production code.

-              console.log("Label", date, event.startTime);
generate_csv/insertInBatch.ts (1)

24-126: Consider removing or justifying commented-out project IDs.

The projectIds array contains many commented-out IDs. If they are not needed, consider removing them to clean up the code. Otherwise, provide a justification for keeping them commented out.

generate_csv/insertInBatch.js (1)

57-159: Consider removing or justifying commented-out project IDs.

The projectIds array contains many commented-out IDs. If they are not needed, consider removing them to clean up the code. Otherwise, provide a justification for keeping them commented out.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 40055b1 and 1adaa80.

Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing (24)
  • apps/web/clickhouse/createDatabase.ts (1 hunks)
  • apps/web/package.json (1 hunks)
  • apps/web/src/api/routes/v1_event.ts (1 hunks)
  • apps/web/src/components/Test/Metrics.tsx (3 hunks)
  • apps/web/src/components/Test/Section.tsx (5 hunks)
  • apps/web/src/components/Test/Serves.tsx (2 hunks)
  • apps/web/src/lib/events.ts (4 hunks)
  • apps/web/src/pages/projects/[projectId]/index.tsx (2 hunks)
  • apps/web/src/pages/projects/[projectId]/tests/[testId].tsx (3 hunks)
  • apps/web/src/server/db/clickhouseClient.ts (1 hunks)
  • apps/web/src/server/queue/AfterDataRequest.ts (2 hunks)
  • apps/web/src/server/queue/event.ts (2 hunks)
  • apps/web/src/server/services/ClickHouseEventService.ts (1 hunks)
  • apps/web/src/server/services/RequestService.ts (1 hunks)
  • apps/web/src/server/trpc/router/events.ts (3 hunks)
  • apps/web/src/server/trpc/router/project.ts (3 hunks)
  • apps/web/src/server/trpc/router/tests.ts (1 hunks)
  • docker-compose.yaml (1 hunks)
  • generate_csv/generate_csv.js (1 hunks)
  • generate_csv/generate_csv.ts (1 hunks)
  • generate_csv/insertInBatch.js (1 hunks)
  • generate_csv/insertInBatch.ts (1 hunks)
  • generate_csv/package.json (1 hunks)
  • generate_csv/tsconfig.json (1 hunks)
Files skipped from review due to trivial changes (3)
  • apps/web/src/server/trpc/router/tests.ts
  • generate_csv/package.json
  • generate_csv/tsconfig.json
Additional context used
Biome
apps/web/src/server/db/clickhouseClient.ts

[error] 10-10: Shouldn't redeclare 'clickhouseClient'. Consider to delete it or rename it.

'clickhouseClient' is defined here:

(lint/suspicious/noRedeclare)

apps/web/src/server/services/RequestService.ts

[error] 7-7: Unexpected empty object pattern.

(lint/correctness/noEmptyPattern)

apps/web/src/server/services/ClickHouseEventService.ts

[error] 30-200: Avoid classes that contain only static members.

Prefer using simple functions instead of classes with only static members.

(lint/complexity/noStaticOnlyClass)


[error] 108-108: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

generate_csv/generate_csv.js

[error] 1-1: Redundant use strict directive.

The entire contents of JavaScript modules are automatically in strict mode, with no statement needed to initiate it.
Safe fix: Remove the redundant use strict directive.

(lint/suspicious/noRedundantUseStrict)


[error] 12-12: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 30-30: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 50-50: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 52-54: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 64-64: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 64-64: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 67-67: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 69-74: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 73-73: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 75-75: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 78-78: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 98-98: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

generate_csv/insertInBatch.js

[error] 1-1: Redundant use strict directive.

The entire contents of JavaScript modules are automatically in strict mode, with no statement needed to initiate it.
Safe fix: Remove the redundant use strict directive.

(lint/suspicious/noRedundantUseStrict)


[error] 4-4: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 8-8: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 13-13: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 13-13: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 17-17: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 17-17: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 18-18: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 18-18: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 18-18: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 18-18: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 19-19: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 26-26: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

Additional comments not posted (63)
apps/web/src/server/db/clickhouseClient.ts (3)

1-3: LGTM!

The import statements are necessary and correctly imported.


5-8: Caution: Global variable declaration.

Declaring global variables can lead to conflicts and unintended side effects. Ensure this is necessary and handled carefully.

Do you need this global variable for specific reasons? If so, ensure it's managed properly.


12-14: LGTM!

The environment check and global assignment logic are sound.

apps/web/src/server/services/RequestService.ts (2)

1-3: LGTM!

The import statements are necessary and correctly imported.


13-21: LGTM!

The ClickHouse insertion logic is sound and correctly targets the abby.Event table.

docker-compose.yaml (1)

37-43: LGTM!

The ClickHouse service definition is correct and necessary for integrating ClickHouse into the Docker setup.

apps/web/src/server/trpc/router/events.ts (5)

6-6: Ensure the SpecialTimeInterval enum is correctly defined.

Verify that the SpecialTimeInterval enum is correctly defined and imported.

Verification successful

The SpecialTimeInterval enum is correctly defined and imported.

The SpecialTimeInterval enum is defined in apps/web/src/lib/events.ts and includes the expected values.

  • Definition found:
    export enum SpecialTimeInterval {
      DAY = "day",
      Last30DAYS = "30d",
      ALL_TIME = "all",
    }
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the definition of `SpecialTimeInterval`.

# Test: Search for the definition of `SpecialTimeInterval`. Expect: Correct definition and import.
rg --type typescript -A 5 $'enum SpecialTimeInterval'

Length of output: 89


Script:

#!/bin/bash
# Description: Verify the definition of `SpecialTimeInterval`.

# Test: Search for the definition of `SpecialTimeInterval`. Expect: Correct definition and import.
rg --type ts -A 5 $'enum SpecialTimeInterval'

Length of output: 302


5-5: Ensure ClickHouseEventService is correctly integrated.

Verify that the ClickHouseEventService is correctly configured and integrated within the application.

Verification successful

The ClickHouseEventService is correctly integrated.

The ClickHouseEventService is defined in apps/web/src/server/services/ClickHouseEventService.ts and is used in multiple files, including events.ts, project.ts, event.ts, and AfterDataRequest.ts. This indicates that the service is properly configured and integrated within the application.

  • apps/web/src/server/services/ClickHouseEventService.ts
  • apps/web/src/server/trpc/router/events.ts
  • apps/web/src/server/trpc/router/project.ts
  • apps/web/src/server/queue/event.ts
  • apps/web/src/server/queue/AfterDataRequest.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the integration of `ClickHouseEventService`.

# Test: Search for the definition and usage of `ClickHouseEventService`.
rg --type typescript -A 5 $'ClickHouseEventService'

Length of output: 85


Script:

#!/bin/bash
# Description: Verify the integration of `ClickHouseEventService`.

# Test: Search for the definition and usage of `ClickHouseEventService`.
rg --type ts -A 5 'ClickHouseEventService'

Length of output: 5558


48-48: Verify the correctness of the new service call.

Ensure that the getEventsByTestId method in ClickHouseEventService is correctly implemented and returns the expected results.

Verification successful

The getEventsByTestId method in ClickHouseEventService is correctly implemented.

The method getEventsByTestId in ClickHouseEventService is properly defined and includes logic to query the ClickHouse database for events based on the provided testId. The method constructs a query to retrieve event data grouped by startTime, selectedVariant, and type, and orders the results by startTime.

  • Method Signature:

    static async getEventsByTestId(
      testId: string,
      timeInterval: SpecialTimeInterval
    ) {
      const computedBucketSize = this.computeBucketSize(timeInterval);
    
      try {
        const result = await clickhouseClient.query({
          query: `
          SELECT
          ${computedBucketSize} AS startTime,
          Count(selectedVariant) AS count, 
          selectedVariant,
          type
          FROM abby.Event
          WHERE testName = '${testId}'
          GROUP BY startTime, selectedVariant, type
          ORDER BY startTime ASC;
          `,
        });
  • Implementation Details:

    • Computes the bucket size based on the provided timeInterval.
    • Executes a query on the abby.Event table in ClickHouse to fetch and group event data.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of `getEventsByTestId` in `ClickHouseEventService`.

# Test: Search for the method implementation. Expect: Correct implementation of the method.
ast-grep --lang typescript --pattern $'class ClickHouseEventService {
  $$$
  static async getEventsByTestId($_, $_) {
    $$$
  }
  $$$  
}'

Length of output: 142


Script:

#!/bin/bash
# Search for the ClickHouseEventService class definition in the codebase
ast-grep --lang typescript --pattern 'class ClickHouseEventService { $$$ }'

# Search for the getEventsByTestId method definition in the codebase
rg 'getEventsByTestId'

Length of output: 510


Script:

#!/bin/bash
# Extract the implementation of the getEventsByTestId method from ClickHouseEventService.ts
ast-grep --lang typescript --pattern $'class ClickHouseEventService {
  $$$
  static async getEventsByTestId(testId, options) {
    $$$
  }
  $$$  
}' apps/web/src/server/services/ClickHouseEventService.ts

Length of output: 206


Script:

#!/bin/bash
# Extract the implementation of the getEventsByTestId method from ClickHouseEventService.ts using ripgrep
rg 'static async getEventsByTestId' -A 20 apps/web/src/server/services/ClickHouseEventService.ts

Length of output: 641


27-27: Ensure the input schema change is correctly handled.

Verify that the change from z.string() to z.nativeEnum(SpecialTimeInterval) is correctly handled and does not break any existing functionality.


21-21: Verify the correctness of the new service call.

Ensure that the getEventsByProjectId method in ClickHouseEventService is correctly implemented and returns the expected results.

apps/web/src/api/routes/v1_event.ts (3)

2-2: Ensure the removal of AbbyEventType is correct.

Verify that the removal of AbbyEventType does not break any existing functionality and that it is no longer needed in this file.


2-2: Ensure the removal of EventService is correct.

Verify that the removal of EventService does not break any existing functionality and that it is no longer needed in this file.

Verification successful

The removal of EventService from apps/web/src/api/routes/v1_event.ts is correct.

  • The search results confirm that EventService is not used in apps/web/src/api/routes/v1_event.ts.
  • ClickHouseEventService is present in other parts of the codebase, indicating a possible replacement or renaming.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `EventService`.

# Test: Search for the usage of `EventService` in the codebase. Expect: No usage in the current file.
rg --type typescript -A 5 $'EventService'

Length of output: 75


Script:

#!/bin/bash
# Description: Verify the usage of `EventService` in the specific file and across the codebase.

# Test 1: Search for the usage of `EventService` in the specific file `apps/web/src/api/routes/v1_event.ts`.
rg 'EventService' apps/web/src/api/routes/v1_event.ts

# Test 2: Search for the usage of `EventService` across the codebase.
rg --type ts -A 5 'EventService'

Length of output: 5602


2-2: Ensure the removal of RequestService is correct.

Verify that the removal of RequestService does not break any existing functionality and that it is no longer needed in this file.

Verification successful

The removal of RequestService is correct.

The RequestService is not used in apps/web/src/api/routes/v1_event.ts, so its removal does not break any existing functionality.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `RequestService`.

# Test: Search for the usage of `RequestService` in the codebase. Expect: No usage in the current file.
rg --type typescript -A 5 $'RequestService'

Length of output: 77


Script:

#!/bin/bash
# Description: Verify the usage of `RequestService`.

# Find all TypeScript files and search for the usage of `RequestService`.
fd --extension ts --exec rg 'RequestService' {}

Length of output: 290


Script:

#!/bin/bash
# Description: Verify the usage of `RequestService` in `apps/web/src/api/routes/v1_event.ts`.

# Search for the usage of `RequestService` in the specific file.
rg 'RequestService' apps/web/src/api/routes/v1_event.ts

Length of output: 55

apps/web/src/components/Test/Metrics.tsx (4)

45-45: Ensure the prop change is correctly handled.

Verify that the change from pingEvents and options to visitData is correctly handled and does not break any existing functionality.

Verification successful

The prop change is correctly handled.

The change from pingEvents and options to visitData in the Metrics component is correctly implemented and does not break any existing functionality.

  • apps/web/src/components/Test/Metrics.tsx
  • apps/web/src/components/Test/Section.tsx
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the `Metrics` component.

# Test: Search for the usage of the `Metrics` component in the codebase. Expect: Correct handling of the new `visitData` prop.
rg --type typescript -A 5 $'Metrics'

Length of output: 70


Script:

#!/bin/bash
# Description: Verify the usage of the `Metrics` component.

# Test: Search for the usage of the `Metrics` component in .tsx files. Expect: Correct handling of the new `visitData` prop.
rg --glob '*.tsx' -A 5 'Metrics'

Length of output: 1458


33-33: Ensure the y scale configuration is correct.

Verify that setting the y scale to begin at zero is correct and does not break any existing functionality.

Verification successful

The y scale configuration is correct.

The beginAtZero: true configuration in Metrics.tsx ensures that the y-axis starts at zero and does not break any existing functionality.

  • apps/web/src/components/Test/Metrics.tsx: beginAtZero: true is correctly set.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the `OPTIONS` object.

# Test: Search for the usage of the `OPTIONS` object in the codebase. Expect: Correct handling of the `y` scale configuration.
rg --type typescript -A 5 $'OPTIONS'

Length of output: 70


Script:

#!/bin/bash
# Description: Verify the usage of the `OPTIONS` object.

# Test: Search for the usage of the `OPTIONS` object in the codebase. Expect: Correct handling of the `y` scale configuration.
rg --type ts -A 5 $'OPTIONS'

Length of output: 2989


51-52: Ensure the logic change is correctly handled.

Verify that the change in the logic for calculating absPings is correctly handled and does not break any existing functionality.

Verification successful

The logic change for calculating absPings in Metrics.tsx is correctly handled and consistent with its usage in the component.

  • absPings is calculated using visitData.reduce((accumulator, value) => accumulator + value.actEventCount, 0);.
  • It is used in a console.log statement and within the data mapping for a Bar component.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the logic change in the `Metrics` component.

# Test: Search for the usage of `absPings` in the component. Expect: Correct handling of the new logic.
rg --type typescript -A 5 $'absPings'

Length of output: 71


Script:

#!/bin/bash
# Description: Verify the logic change in the `Metrics` component.

# Test: Search for the usage of `absPings` in the component. Expect: Correct handling of the new logic.
rg --type ts -A 5 'absPings'

Length of output: 2731


67-73: Ensure the dataset change is correctly handled.

Verify that the change in the dataset for the bar chart is correctly handled and does not break any existing functionality.

Verification successful

The dataset change is correctly handled.

The definitions and usages of visitData and absPings in the Metrics.tsx component are appropriate, and the mapping functions do not introduce any errors.

  • visitData is correctly defined and used.
  • absPings is correctly calculated and used.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the dataset change in the `Metrics` component.

# Test: Search for the usage of the dataset in the component. Expect: Correct handling of the new dataset logic.
rg --type typescript -A 5 $'datasets'

Length of output: 71


Script:

#!/bin/bash
# Description: Verify the dataset change in the `Metrics` component.

# Test: Search for the usage of the dataset in the Metrics.tsx component. Expect: Correct handling of the new dataset logic.
rg --type ts -A 5 'datasets' apps/web/src/components/Test/Metrics.tsx

Length of output: 244


Script:

#!/bin/bash
# Description: Verify the definitions and usages of `visitData` and `absPings` in the `Metrics` component.

# Test: Search for the definitions and usages of `visitData` and `absPings` in the Metrics.tsx component.
rg --type ts 'visitData|absPings' apps/web/src/components/Test/Metrics.tsx

Length of output: 439

apps/web/clickhouse/createDatabase.ts (2)

1-3: Imports look good!

The imported modules are necessary for the functionality provided in this file.


64-64: Invocation of insertEvents looks good.

The function is invoked correctly. Ensure this is the intended behavior.

apps/web/src/server/queue/AfterDataRequest.ts (3)

8-8: Import statement looks good!

The import for ClickHouseEventService is necessary for the new functionality.


Line range hint 22-55:
Logic for plan overage tracking and request storage looks good!

The logic correctly handles plan overage tracking and request storage.


20-20: Usage of ClickHouseEventService looks good!

The service is correctly used to fetch events for the current period. Ensure that all function calls to getEventsForCurrentPeriod are correct.

Verification successful

Usage of ClickHouseEventService looks good!

The service is correctly used to fetch events for the current period in the following files:

  • apps/web/src/server/trpc/router/project.ts
  • apps/web/src/server/queue/AfterDataRequest.ts
  • apps/web/src/server/queue/event.ts

All function calls to getEventsForCurrentPeriod are correct.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `ClickHouseEventService.getEventsForCurrentPeriod`.

# Test: Search for the function usage. Expect: Only occurrences of the correct usage.
rg --type typescript -A 5 $'ClickHouseEventService.getEventsForCurrentPeriod'

Length of output: 111


Script:

#!/bin/bash
# Description: Verify all function calls to `ClickHouseEventService.getEventsForCurrentPeriod`.

# Test: Search for the function usage. Expect: Only occurrences of the correct usage.
rg --glob "*.ts" --glob "*.tsx" -A 5 $'ClickHouseEventService.getEventsForCurrentPeriod'

Length of output: 1591

apps/web/src/components/Test/Serves.tsx (4)

Line range hint 1-13:
Imports look good!

The imported modules are necessary for the functionality provided in this file.


60-63: Props and types for Serves component look good!

The new visitData prop simplifies the data structure and is correctly used.


64-66: Logic for deriving labels and absPings looks good!

The logic correctly uses visitData to derive labels and absPings.


Line range hint 70-88:
Rendering logic for Bar component looks good!

The Bar component correctly uses visitData for the datasets.

generate_csv/generate_csv.ts (1)

1-10: LGTM! Imports and constants are well-defined.

The imports and constants are necessary for the functionality of the script.

apps/web/src/server/queue/event.ts (3)

9-9: LGTM! Import statement is necessary.

The import statement for ClickHouseEventService is necessary for the new event handling logic.


27-28: LGTM! Verify ClickHouseEventService implementation.

The change to use ClickHouseEventService for event creation is necessary. Ensure that ClickHouseEventService is correctly implemented and tested.

Verification successful

Let's verify the existence and implementation of the ClickHouseEventService class and its createEvent method.


LGTM! Verify ClickHouseEventService implementation.

The change to use ClickHouseEventService for event creation is necessary. The ClickHouseEventService class and its createEvent method are correctly implemented to handle event creation by inserting events into a ClickHouse table.

  • apps/web/src/server/services/ClickHouseEventService.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of `ClickHouseEventService`.

# Test: Search for the implementation of `createEvent` method. Expect: Correct implementation and tests.
ast-grep --lang typescript --pattern $'class ClickHouseEventService {
  $$$
  static async createEvent($_) {
    $$$
  }
  $$$  
}'

Length of output: 132


Script:

#!/bin/bash
# Search for the ClickHouseEventService class definition
rg 'class ClickHouseEventService' -A 10

# Search for the createEvent method definition within the codebase
rg 'createEvent' -A 5 -B 5

Length of output: 10205


38-38: LGTM! Verify ClickHouseEventService implementation.

The change to use ClickHouseEventService for event retrieval is necessary. Ensure that ClickHouseEventService is correctly implemented and tested.

Verification successful

LGTM! Verify ClickHouseEventService implementation.

The ClickHouseEventService class and its getEventsForCurrentPeriod method are correctly implemented and integrated into the system.

  • Located in: apps/web/src/server/services/ClickHouseEventService.ts
  • Used in:
    • apps/web/src/server/queue/event.ts
    • apps/web/src/server/trpc/router/project.ts
    • apps/web/src/server/queue/AfterDataRequest.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of `ClickHouseEventService`.

# Test: Search for the implementation of `getEventsForCurrentPeriod` method. Expect: Correct implementation and tests.
ast-grep --lang typescript --pattern $'class ClickHouseEventService {
  $$$
  static async getEventsForCurrentPeriod($_) {
    $$$
  }
  $$$  
}'

Length of output: 146


Script:

#!/bin/bash
# Description: Locate the ClickHouseEventService class and verify the implementation of getEventsForCurrentPeriod method.

# Step 1: Locate the ClickHouseEventService class definition.
ast-grep --lang typescript --pattern 'class ClickHouseEventService { $$$ }'

# Step 2: Search for the getEventsForCurrentPeriod method within the located ClickHouseEventService class.
ast-grep --lang typescript --pattern 'class ClickHouseEventService {
  $$$
  static async getEventsForCurrentPeriod($_) {
    $$$
  }
  $$$  
}'

Length of output: 224


Script:

#!/bin/bash
# Description: Broaden the search to locate ClickHouseEventService class and getEventsForCurrentPeriod method.

# Step 1: Search for the definition of ClickHouseEventService class.
rg 'class ClickHouseEventService' -t typescript -A 10

# Step 2: Search for any definition or usage of getEventsForCurrentPeriod method.
rg 'getEventsForCurrentPeriod' -t typescript -A 5 -B 5

Length of output: 180


Script:

#!/bin/bash
# Description: Broaden the search to locate ClickHouseEventService class and getEventsForCurrentPeriod method.

# Step 1: Search for the definition of ClickHouseEventService class.
rg 'class ClickHouseEventService' -t ts -A 10

# Step 2: Search for any definition or usage of getEventsForCurrentPeriod method.
rg 'getEventsForCurrentPeriod' -t ts -A 5 -B 5

Length of output: 4533

apps/web/src/pages/projects/[projectId]/index.tsx (1)

62-71: LGTM! Improved readability.

The change to the rendering logic for mapping data?.project?.tests improves code clarity and maintainability without altering functionality.

apps/web/src/lib/events.ts (3)

6-6: Enum value update approved.

The SpecialTimeInterval enum has been updated with Last30DAYS replacing MONTH_TO_DATE. Ensure consistent usage across the codebase.


46-47: Function update approved.

The getMSFromSpecialTimeInterval function correctly handles the Last30DAYS case.


74-95: Function refactor approved.

The getLabelsByInterval function has been refactored to return an object containing both labels and dates, enhancing its output.

apps/web/package.json (3)

17-17: Script approved.

The clickhouse:migrate script is correctly configured for ClickHouse database migration.


18-18: Script approved.

The clickhouse:create script is correctly configured for ClickHouse database creation.


25-25: Dependency approved.

The @clickhouse/client dependency is necessary for integrating ClickHouse client functionality into the application.

apps/web/src/pages/projects/[projectId]/tests/[testId].tsx (2)

Line range hint 104-115:
Component refactor approved.

The TestDetailPage component has been refactored to simplify event data fetching and processing, improving readability and reducing complexity.


142-154: Computation approved.

The actEvents variable correctly derives its dataset from the events array.

apps/web/src/server/services/ClickHouseEventService.ts (4)

10-14: LGTM! Schema definition is correct.

The GroupedTestQueryResultSchema is correctly defined using Zod.


16-19: LGTM! Schema definition is correct.

The GroupedTestQueryResultSchemaWithTimeSchema is correctly defined using Zod.


21-23: LGTM! Schema definition is correct.

The EventCurrentPeriodQueryResultSchema is correctly defined using Zod.


25-28: LGTM! Type definitions are correct.

The types GroupedTestQueryResultSchemaWithTime and GroupedTestQueryResult are correctly inferred from the Zod schemas.

apps/web/src/components/Test/Section.tsx (3)

21-41: LGTM! Function refactoring is correct.

The getBestVariant function has been correctly refactored to accept a single parameter visitData. The logic for determining the best variant is clear and concise.


127-136: LGTM! Type definition is correct.

The VisitData type is correctly defined and ensures type safety and clarity in the component's API.


Line range hint 140-224: LGTM! Component updates are correct.

The Section component has been correctly updated to reflect the new structure of data being passed to getBestVariant. The usage of visitData enhances clarity and reduces complexity.

generate_csv/generate_csv.js (1)

98-98: Refactor assignment in expression.

The assignment should not be in an expression to improve readability.

- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
+   _.label = op[1];
+   break;
+ }

Likely invalid or redundant comment.

Tools
Biome

[error] 98-98: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

generate_csv/insertInBatch.ts (6)

1-2: LGTM! Import statements are necessary and correct.

The import statements for uuid and @clickhouse/client are appropriate for the functionality provided in the file.


4-4: LGTM! ClickHouse client creation is correct.

The clickhouseClient is correctly created using createClient from @clickhouse/client.


6-11: LGTM! Constants are well-defined and necessary.

The constants for NUM_ENTRIES, PROJECT_COUNT, API_VERSION, TYPES, and BATCH_SIZE are appropriately defined for the functionality of the file.


13-22: LGTM! randomDate function is well-implemented.

The randomDate function correctly generates a random date between today and one year ago.


128-139: LGTM! insertBatch function is well-implemented.

The insertBatch function correctly inserts a batch of records into the ClickHouse database with proper error handling.


173-175: LGTM! Error handling is appropriate.

The error handling in the generateAndInsertRecords function ensures that errors are logged appropriately.

apps/web/src/server/trpc/router/project.ts (3)

Line range hint 1-16: LGTM! Import statements are necessary and correct.

The import statements for necessary modules and services, including the new ClickHouseEventService, are appropriate for the functionality provided in the file.


Line range hint 87-228: LGTM! Other procedures are consistent and correct.

The other procedures in the projectRouter are consistent and correct. No modifications are needed.


Line range hint 17-86: LGTM! Enhanced functionality in getProjectData procedure.

The changes to the getProjectData procedure enhance the functionality and detail of the data returned. Ensure that the new ClickHouseEventService integration is correct and efficient.

generate_csv/insertInBatch.js (6)

2-37: LGTM! Async helper functions are necessary.

The async helper functions generated by TypeScript are necessary for async/await functionality in older environments.

Tools
Biome

[error] 4-4: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 8-8: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 13-13: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 13-13: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 17-17: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 17-17: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 18-18: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 18-18: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 18-18: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 18-18: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 19-19: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 26-26: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


39-42: LGTM! ClickHouse client creation is correct.

The clickhouseClient is correctly created using createClient from @clickhouse/client.


43-48: LGTM! Constants are well-defined and necessary.

The constants for NUM_ENTRIES, PROJECT_COUNT, API_VERSION, TYPES, and BATCH_SIZE are appropriately defined for the functionality of the file.


49-56: LGTM! randomDate function is well-implemented.

The randomDate function correctly generates a random date between today and one year ago.


160-180: LGTM! insertBatch function is well-implemented.

The insertBatch function correctly inserts a batch of records into the ClickHouse database with proper error handling.


230-232: LGTM! Error handling is appropriate.

The error handling in the generateAndInsertRecords function ensures that errors are logged appropriately.

var clickhouseClient: NodeClickHouseClient | undefined;
}

export const clickhouseClient = global.clickhouseClient || createClient();
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid redeclaring clickhouseClient.

Redeclaring clickhouseClient can lead to issues. Consider using a different approach to avoid redeclaration.

- export const clickhouseClient = global.clickhouseClient || createClient();
+ const client = global.clickhouseClient || createClient();
+ export { client as clickhouseClient };
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const clickhouseClient = global.clickhouseClient || createClient();
const client = global.clickhouseClient || createClient();
export { client as clickhouseClient };
Tools
Biome

[error] 10-10: Shouldn't redeclare 'clickhouseClient'. Consider to delete it or rename it.

'clickhouseClient' is defined here:

(lint/suspicious/noRedeclare)

...request,
},
});
const {} = await Promise.all([
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove the empty object pattern.

The empty object pattern in the Promise.all result is unnecessary and can be removed.

- const {} = await Promise.all([
+ await Promise.all([
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const {} = await Promise.all([
await Promise.all([
Tools
Biome

[error] 7-7: Unexpected empty object pattern.

(lint/correctness/noEmptyPattern)

Comment on lines 22 to 36
// Generate project IDs
const projectIds = ["clvh4sv5n0001furg6tj08z63"];

// Setup CSV writer
const csvWriter = createObjectCsvWriter({
path: "ApiRequest.csv",
header: [
{ id: "id", title: "id" },
{ id: "createdAt", title: "createdAt" },
{ id: "type", title: "type" },
{ id: "durationInMs", title: "durationInMs" },
{ id: "apiVersion", title: "apiVersion" },
{ id: "projectId", title: "projectId" },
],
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider making project IDs configurable.

Hardcoding project IDs might limit flexibility. Consider making them configurable.

- const projectIds = ["clvh4sv5n0001furg6tj08z63"];
+ const projectIds = process.env.PROJECT_IDS ? process.env.PROJECT_IDS.split(",") : ["clvh4sv5n0001furg6tj08z63"];

LGTM! CSV writer setup is correct.

The CSV writer setup with the necessary headers is well-defined.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Generate project IDs
const projectIds = ["clvh4sv5n0001furg6tj08z63"];
// Setup CSV writer
const csvWriter = createObjectCsvWriter({
path: "ApiRequest.csv",
header: [
{ id: "id", title: "id" },
{ id: "createdAt", title: "createdAt" },
{ id: "type", title: "type" },
{ id: "durationInMs", title: "durationInMs" },
{ id: "apiVersion", title: "apiVersion" },
{ id: "projectId", title: "projectId" },
],
});
// Generate project IDs
const projectIds = process.env.PROJECT_IDS ? process.env.PROJECT_IDS.split(",") : ["clvh4sv5n0001furg6tj08z63"];
// Setup CSV writer
const csvWriter = createObjectCsvWriter({
path: "ApiRequest.csv",
header: [
{ id: "id", title: "id" },
{ id: "createdAt", title: "createdAt" },
{ id: "type", title: "type" },
{ id: "durationInMs", title: "durationInMs" },
{ id: "apiVersion", title: "apiVersion" },
{ id: "projectId", title: "projectId" },
],
});

Comment on lines +5 to +7
const client = createClient({
url: "http://localhost:8123",
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Use environment variables for the ClickHouse client URL.

Hardcoding URLs can cause issues when deploying to different environments. Consider using environment variables for better flexibility.

- const client = createClient({
-   url: "http://localhost:8123",
- });
+ const client = createClient({
+   url: process.env.CLICKHOUSE_URL || "http://localhost:8123",
+ });
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const client = createClient({
url: "http://localhost:8123",
});
const client = createClient({
url: process.env.CLICKHOUSE_URL || "http://localhost:8123",
});

Comment on lines +40 to +61
async function insertEvents() {
const projectId = "clvh4sv5n0001furg6tj08z63";
const testName = "clyetopos0001yd6wa4yybkvw";

for (let i = 0; i < 100_000; i++) {
await client.insert({
table: "abby.Event",
format: "JSONEachRow",
values: [
{
project_id: projectId,
testName: testName,
type: Math.random() < 0.5 ? AbbyEventType.PING : AbbyEventType.ACT,
selectedVariant:
Math.random() < 0.5 ? "New Variant 1" : "New Variant 2",
createdAt:
Math.floor(Date.now() / 1000) -
Math.floor(Math.random() * 24 * 60 * 60),
},
],
});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Handle potential errors and rate limits in insertEvents.

Inserting 100,000 events without error handling or rate limiting can lead to issues. Consider adding error handling and rate limiting.

async function insertEvents() {
  const projectId = "clvh4sv5n0001furg6tj08z63";
  const testName = "clyetopos0001yd6wa4yybkvw";

  for (let i = 0; i < 100_000; i++) {
    try {
      await client.insert({
        table: "abby.Event",
        format: "JSONEachRow",
        values: [
          {
            project_id: projectId,
            testName: testName,
            type: Math.random() < 0.5 ? AbbyEventType.PING : AbbyEventType.ACT,
            selectedVariant:
              Math.random() < 0.5 ? "New Variant 1" : "New Variant 2",
            createdAt:
              Math.floor(Date.now() / 1000) -
              Math.floor(Math.random() * 24 * 60 * 60),
          },
        ],
      });
    } catch (error) {
      console.error("Error inserting event:", error);
    }

    // Optional: Add rate limiting
    if (i % 1000 === 0) {
      await new Promise((resolve) => setTimeout(resolve, 100)); // Rate limit
    }
  }
}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async function insertEvents() {
const projectId = "clvh4sv5n0001furg6tj08z63";
const testName = "clyetopos0001yd6wa4yybkvw";
for (let i = 0; i < 100_000; i++) {
await client.insert({
table: "abby.Event",
format: "JSONEachRow",
values: [
{
project_id: projectId,
testName: testName,
type: Math.random() < 0.5 ? AbbyEventType.PING : AbbyEventType.ACT,
selectedVariant:
Math.random() < 0.5 ? "New Variant 1" : "New Variant 2",
createdAt:
Math.floor(Date.now() / 1000) -
Math.floor(Math.random() * 24 * 60 * 60),
},
],
});
}
async function insertEvents() {
const projectId = "clvh4sv5n0001furg6tj08z63";
const testName = "clyetopos0001yd6wa4yybkvw";
for (let i = 0; i < 100_000; i++) {
try {
await client.insert({
table: "abby.Event",
format: "JSONEachRow",
values: [
{
project_id: projectId,
testName: testName,
type: Math.random() < 0.5 ? AbbyEventType.PING : AbbyEventType.ACT,
selectedVariant:
Math.random() < 0.5 ? "New Variant 1" : "New Variant 2",
createdAt:
Math.floor(Date.now() / 1000) -
Math.floor(Math.random() * 24 * 60 * 60),
},
],
});
} catch (error) {
console.error("Error inserting event:", error);
}
// Optional: Add rate limiting
if (i % 1000 === 0) {
await new Promise((resolve) => setTimeout(resolve, 100)); // Rate limit
}
}
}

while ((g && ((g = 0), op[0] && (_ = 0)), _))
try {
if (
((f = 1),
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactor assignment in expression.

The assignment should not be in an expression to improve readability.

- if (((f = 1), y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
+ f = 1;
+ if (y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
((f = 1),
f = 1;
if (y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
Tools
Biome

[error] 67-67: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

Comment on lines 52 to 54
(g[Symbol.iterator] = function () {
return this;
}),
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactor assignment in expression.

The assignment should not be in an expression to improve readability.

- typeof Symbol === "function" &&
- (g[Symbol.iterator] = function () {
-   return this;
- });
+ if (typeof Symbol === "function") {
+   g[Symbol.iterator] = function () {
+     return this;
+   };
+ }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
(g[Symbol.iterator] = function () {
return this;
}),
if (typeof Symbol === "function") {
g[Symbol.iterator] = function () {
return this;
};
}
Tools
Biome

[error] 52-54: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

Comment on lines 165 to 210
function generateCSV() {
return __awaiter(this, void 0, void 0, function () {
var records, i, record;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
records = [];
i = 0;
_a.label = 1;
case 1:
if (!(i < NUM_ENTRIES)) return [3 /*break*/, 4];
record = {
id: (0, uuid_1.v4)(),
createdAt: randomDate(),
type: TYPES[Math.floor(Math.random() * TYPES.length)],
durationInMs: Math.floor(Math.random() * 1000) + 1,
apiVersion: API_VERSION,
projectId: "clvh4sv5n0001furg6tj08z63",
// projectIds[Math.floor(Math.random() * PROJECT_COUNT)],
};
records.push(record);
if (!(records.length === 100000)) return [3 /*break*/, 3];
return [4 /*yield*/, csvWriter.writeRecords(records)];
case 2:
_a.sent();
records.length = 0; // Clear the array
_a.label = 3;
case 3:
i++;
return [3 /*break*/, 1];
case 4:
if (!(records.length > 0)) return [3 /*break*/, 6];
return [4 /*yield*/, csvWriter.writeRecords(records)];
case 5:
_a.sent();
_a.label = 6;
case 6:
console.log("CSV file generated successfully!");
return [2 /*return*/];
}
});
});
}
generateCSV().catch(function (err) {
console.error("Error generating CSV:", err);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Use projectIds array for generating projectIds.

The projectId generation is currently hardcoded. Consider using the projectIds array for generating projectIds.

- projectId: "clvh4sv5n0001furg6tj08z63",
+ projectId: projectIds[Math.floor(Math.random() * projectIds.length)],
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function generateCSV() {
return __awaiter(this, void 0, void 0, function () {
var records, i, record;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
records = [];
i = 0;
_a.label = 1;
case 1:
if (!(i < NUM_ENTRIES)) return [3 /*break*/, 4];
record = {
id: (0, uuid_1.v4)(),
createdAt: randomDate(),
type: TYPES[Math.floor(Math.random() * TYPES.length)],
durationInMs: Math.floor(Math.random() * 1000) + 1,
apiVersion: API_VERSION,
projectId: "clvh4sv5n0001furg6tj08z63",
// projectIds[Math.floor(Math.random() * PROJECT_COUNT)],
};
records.push(record);
if (!(records.length === 100000)) return [3 /*break*/, 3];
return [4 /*yield*/, csvWriter.writeRecords(records)];
case 2:
_a.sent();
records.length = 0; // Clear the array
_a.label = 3;
case 3:
i++;
return [3 /*break*/, 1];
case 4:
if (!(records.length > 0)) return [3 /*break*/, 6];
return [4 /*yield*/, csvWriter.writeRecords(records)];
case 5:
_a.sent();
_a.label = 6;
case 6:
console.log("CSV file generated successfully!");
return [2 /*return*/];
}
});
});
}
generateCSV().catch(function (err) {
console.error("Error generating CSV:", err);
});
function generateCSV() {
return __awaiter(this, void 0, void 0, function () {
var records, i, record;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
records = [];
i = 0;
_a.label = 1;
case 1:
if (!(i < NUM_ENTRIES)) return [3 /*break*/, 4];
record = {
id: (0, uuid_1.v4)(),
createdAt: randomDate(),
type: TYPES[Math.floor(Math.random() * TYPES.length)],
durationInMs: Math.floor(Math.random() * 1000) + 1,
apiVersion: API_VERSION,
projectId: projectIds[Math.floor(Math.random() * projectIds.length)],
// projectIds[Math.floor(Math.random() * PROJECT_COUNT)],
};
records.push(record);
if (!(records.length === 100000)) return [3 /*break*/, 3];
return [4 /*yield*/, csvWriter.writeRecords(records)];
case 2:
_a.sent();
records.length = 0; // Clear the array
_a.label = 3;
case 3:
i++;
return [3 /*break*/, 1];
case 4:
if (!(records.length > 0)) return [3 /*break*/, 6];
return [4 /*yield*/, csvWriter.writeRecords(records)];
case 5:
_a.sent();
_a.label = 6;
case 6:
console.log("CSV file generated successfully!");
return [2 /*return*/];
}
});
});
}
generateCSV().catch(function (err) {
console.error("Error generating CSV:", err);
});

Comment on lines 185 to 232
function generateAndInsertRecords() {
return __awaiter(this, void 0, void 0, function () {
var records, batchCount, i, record;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
records = [];
batchCount = 0;
i = 0;
_a.label = 1;
case 1:
if (!(i < NUM_ENTRIES)) return [3 /*break*/, 4];
record = {
id: (0, uuid_1.v4)(),
createdAt: randomDate(),
type: TYPES[Math.floor(Math.random() * TYPES.length)],
durationInMs: Math.floor(Math.random() * 1000) + 1,
apiVersion: API_VERSION,
projectId: projectIds[Math.floor(Math.random() * PROJECT_COUNT)],
};
records.push(record);
if (!(records.length >= BATCH_SIZE)) return [3 /*break*/, 3];
console.log("Inserting batch ".concat(++batchCount));
return [4 /*yield*/, insertBatch(records)];
case 2:
_a.sent();
records.length = 0; // Clear the array
_a.label = 3;
case 3:
i++;
return [3 /*break*/, 1];
case 4:
if (!(records.length > 0)) return [3 /*break*/, 6];
console.log("Inserting final batch ".concat(++batchCount));
return [4 /*yield*/, insertBatch(records)];
case 5:
_a.sent();
_a.label = 6;
case 6:
console.log("Data insertion completed successfully!");
return [2 /*return*/];
}
});
});
}
generateAndInsertRecords().catch(function (err) {
console.error("Error generating or inserting records:", err);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding progress logging.

The generateAndInsertRecords function is well-implemented. However, adding progress logging (e.g., percentage completed) can help monitor the progress of the record generation and insertion process.

@@ -0,0 +1,232 @@
"use strict";
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove redundant use strict directive.

The use strict directive is redundant in JavaScript modules and can be removed.

- "use strict";
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"use strict";
Tools
Biome

[error] 1-1: Redundant use strict directive.

The entire contents of JavaScript modules are automatically in strict mode, with no statement needed to initiate it.
Safe fix: Remove the redundant use strict directive.

(lint/suspicious/noRedundantUseStrict)

Copy link
Contributor

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1adaa80 and 14a492c.

Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing (4)
  • .vscode/settings.json (1 hunks)
  • apps/bullmq-receiver/package.json (1 hunks)
  • apps/bullmq-receiver/src/index.ts (1 hunks)
  • apps/web/package.json (1 hunks)
Files skipped from review due to trivial changes (3)
  • .vscode/settings.json
  • apps/bullmq-receiver/package.json
  • apps/bullmq-receiver/src/index.ts
Files skipped from review as they are similar to previous changes (1)
  • apps/web/package.json

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.

1 participant