Skip to content

fix: verification_v2 mvs are missing outcome in sort key#2724

Merged
chronark merged 7 commits intomainfrom
verification_v3_mvs
Dec 9, 2024
Merged

fix: verification_v2 mvs are missing outcome in sort key#2724
chronark merged 7 commits intomainfrom
verification_v3_mvs

Conversation

@chronark
Copy link
Collaborator

@chronark chronark commented Dec 9, 2024

Summary by CodeRabbit

  • New Features

    • Introduced new tables and materialized views for aggregating key verifications by hour, day, and month in the database.
    • Added an optional tags property to key verification requests for enhanced filtering and aggregation.
  • Bug Fixes

    • Updated API documentation to clarify key response approximations.
  • Tests

    • Added a new test suite for verifying aggregation of outcomes in the ClickHouse database.
  • Chores

    • Modified Vitest configuration to stop test execution after the first failure.

@changeset-bot
Copy link

changeset-bot bot commented Dec 9, 2024

⚠️ No Changeset found

Latest commit: 42cb06d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Dec 9, 2024

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

Name Status Preview Comments Updated (UTC)
dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 9, 2024 2:05pm
engineering ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 9, 2024 2:05pm
play ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 9, 2024 2:05pm
www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 9, 2024 2:05pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 9, 2024

Warning

Rate limit exceeded

@chronark has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 17 minutes and 32 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 347cbe5 and 42cb06d.

📒 Files selected for processing (5)
  • apps/api/src/routes/v1_keys_verifyKey.ts (0 hunks)
  • packages/api/package.json (1 hunks)
  • packages/hono/package.json (1 hunks)
  • packages/nextjs/package.json (1 hunks)
  • packages/ratelimit/package.json (1 hunks)
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

This pull request introduces several SQL files that create new tables and materialized views in the ClickHouse verifications schema, specifically for aggregating key verification data on an hourly, daily, and monthly basis. It also modifies the ClickHouse client configuration by removing specific settings and updates SQL queries in the codebase to reference the new table versions. Additionally, a new test suite is added to validate the aggregation logic, and the Vitest configuration is updated to improve test execution feedback. Lastly, the OpenAPI definitions are enhanced with a new optional tags property for verification requests.

Changes

File Path Change Summary
internal/clickhouse/schema/036_create_verifications.key_verifications_per_hour_v3.sql Created table key_verifications_per_hour_v3 with specified columns and SummingMergeTree engine.
internal/clickhouse/schema/037_create_verifications.key_verifications_per_hour_mv_v3.sql Created materialized view key_verifications_per_hour_mv_v3 aggregating data from raw_key_verifications_v1.
internal/clickhouse/schema/038_create_verifications.key_verifications_per_day_v3.sql Created table key_verifications_per_day_v3 with specified columns and SummingMergeTree engine.
internal/clickhouse/schema/039_create_verifications.key_verifications_per_day_mv_v3.sql Created materialized view key_verifications_per_day_mv_v3 aggregating data from raw_key_verifications_v1.
internal/clickhouse/schema/040_create_verifications.key_verifications_per_month_v3.sql Created table key_verifications_per_month_v3 with specified columns and SummingMergeTree engine.
internal/clickhouse/schema/041_create_verifications.key_verifications_per_month_mv_v3.sql Created materialized view key_verifications_per_month_mv_v3 aggregating data from raw_key_verifications_v1.
internal/clickhouse/src/client/client.ts Removed async_insert and wait_for_async_insert settings from clickhouse_settings in createClient.
internal/clickhouse/src/verification_outcomes_propagate_correctly.test.ts Introduced a new test suite for verifying aggregation of outcomes in ClickHouse.
internal/clickhouse/src/verifications.ts Updated SQL queries in getVerificationsPerHour, getVerificationsPerDay, and getVerificationsPerMonth to reference version 3 tables.
internal/clickhouse/vitest.config.ts Added bail: 1 property to Vitest configuration to stop on the first test failure.
packages/api/src/openapi.d.ts Added optional tags property to V1KeysVerifyKeyRequest interface and updated listKeys response documentation.

Possibly related PRs

Suggested labels

Bug, 🕹️ oss.gg, :joystick: 150 points

Suggested reviewers

  • mcstepp
  • perkinsjr
  • MichaelUnkey

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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2024

Thank you for following the naming conventions for pull request titles! 🙏

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

🧹 Outside diff range and nitpick comments (2)
internal/clickhouse/src/verification_outcomes_propagate_correctly.test.ts (1)

86-105: Enhance test coverage with edge cases

While the test covers basic aggregation validation, consider adding edge cases:

  • Verifications exactly at bucket boundaries
  • Empty buckets within the time range
  • All verifications having the same outcome
internal/clickhouse/src/verifications.ts (1)

Line range hint 63-135: Consider adding ORDER BY clause in materialized views

The queries rely on sorted results (ORDER BY time ASC), but it's more efficient to maintain this order in the materialized views rather than sorting on each query.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a7a2e62 and 7202b90.

📒 Files selected for processing (11)
  • internal/clickhouse/schema/036_create_verifications.key_verifications_per_hour_v3.sql (1 hunks)
  • internal/clickhouse/schema/037_create_verifications.key_verifications_per_hour_mv_v3.sql (1 hunks)
  • internal/clickhouse/schema/038_create_verifications.key_verifications_per_day_v3.sql (1 hunks)
  • internal/clickhouse/schema/039_create_verifications.key_verifications_per_day_mv_v3.sql (1 hunks)
  • internal/clickhouse/schema/040_create_verifications.key_verifications_per_month_v3.sql (1 hunks)
  • internal/clickhouse/schema/041_create_verifications.key_verifications_per_month_mv_v3.sql (1 hunks)
  • internal/clickhouse/src/client/client.ts (0 hunks)
  • internal/clickhouse/src/verification_outcomes_propagate_correctly.test.ts (1 hunks)
  • internal/clickhouse/src/verifications.ts (3 hunks)
  • internal/clickhouse/vitest.config.ts (1 hunks)
  • x.json (1 hunks)
💤 Files with no reviewable changes (1)
  • internal/clickhouse/src/client/client.ts
✅ Files skipped from review due to trivial changes (2)
  • internal/clickhouse/schema/038_create_verifications.key_verifications_per_day_v3.sql
  • internal/clickhouse/schema/036_create_verifications.key_verifications_per_hour_v3.sql
🔇 Additional comments (6)
internal/clickhouse/vitest.config.ts (1)

5-5: LGTM: Appropriate test configuration for database schema changes

Setting bail: 1 is a good choice here as it will stop the test suite on the first failure, which is particularly useful for database schema tests where subsequent tests may depend on the success of previous ones.

internal/clickhouse/schema/040_create_verifications.key_verifications_per_month_v3.sql (1)

13-14: LGTM: Correctly includes outcome in ORDER BY clause

The table definition properly includes outcome in the ORDER BY clause, which addresses the issue mentioned in the PR title. The SummingMergeTree engine with this ordering will enable efficient querying of verification data by all key dimensions including outcome.

internal/clickhouse/schema/037_create_verifications.key_verifications_per_hour_mv_v3.sql (2)

1-23: LGTM! Materialized view properly includes outcome field

The materialized view correctly includes the outcome field in both SELECT and GROUP BY clauses, which addresses the missing outcome issue mentioned in the PR title.


26-46: Consider uncommenting the data population script if migration is needed

The commented data population script could be useful for migrating existing data to the new materialized view. Consider uncommenting it if historical data needs to be preserved.

Let's check if there's existing data that needs migration:

internal/clickhouse/schema/041_create_verifications.key_verifications_per_month_mv_v3.sql (1)

1-23: LGTM! Monthly materialized view properly includes outcome field

The materialized view correctly includes the outcome field and uses appropriate monthly time aggregation.

internal/clickhouse/src/verification_outcomes_propagate_correctly.test.ts (1)

49-50: Consider uncommenting the delay for materialized view propagation

The commented delay might be necessary to ensure materialized views are properly populated before querying. Without it, tests might be flaky if ClickHouse hasn't processed all insertions.

Let's check if there are any timing-related test failures:

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