Skip to content

feat: add outcome sort to ratelimit overview#2981

Merged
chronark merged 3 commits intomainfrom
add-outcome-sort-to-ratelimit-overview
Mar 18, 2025
Merged

feat: add outcome sort to ratelimit overview#2981
chronark merged 3 commits intomainfrom
add-outcome-sort-to-ratelimit-overview

Conversation

@ogzhanolguncu
Copy link
Contributor

@ogzhanolguncu ogzhanolguncu commented Mar 18, 2025

What does this PR do?

Fixes # (issue)

If there is not an issue for this, please create one first. This is used to tracking purposes and also helps use understand why this PR exists

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Chore (refactoring code, technical debt, workflow improvements)
  • Enhancement (small improvements)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How should this be tested?

  • Test A
  • Test B

Checklist

Required

  • Filled out the "How to test" section in this PR
  • Read Contributing Guide
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand areas
  • Ran pnpm build
  • Ran pnpm fmt
  • Checked for warnings, there are none
  • Removed all console.logs
  • Merged the latest changes from main onto my branch with git pull origin main
  • My changes don't cause any responsiveness issues

Appreciated

  • If a UI change was made: Added a screen recording or screenshots to this PR
  • Updated the Unkey Docs if changes were necessary

Summary by CodeRabbit

  • New Features
    • Enhanced logs table interactivity by enabling sorting on "passed" and "blocked" request counts.
    • Expanded query logs sorting options to include additional criteria, offering users more granular data analysis.
    • Improved pagination handling for rate limit overview logs based on new sorting options.

@changeset-bot
Copy link

changeset-bot bot commented Mar 18, 2025

⚠️ No Changeset found

Latest commit: 6331350

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 Mar 18, 2025

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 Mar 18, 2025 0:37am
engineering ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 18, 2025 0:37am
play ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 18, 2025 0:37am
www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 18, 2025 0:37am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 18, 2025

📝 Walkthrough

Walkthrough

The changes add sorting functionality for the "passed" and "blocked" columns in the rate limit logs overview. A new sort property is defined for these columns, and sorting callbacks are implemented. Additionally, the supported sort fields in the query logs schema have been expanded, and the backend parameters and mappings in the Clickhouse integration have been updated to handle the new sort options.

Changes

File(s) Change Summary
apps/dashboard/app/(app)/ratelimits/[namespaceId]/_overview/components/table/logs-table.tsx
apps/dashboard/app/(app)/ratelimits/[namespaceId]/_overview/components/table/query-logs.schema.ts
Added a sort object to the "passed" and "blocked" columns in the logs table component for sorting; extended the sortFields enum in the query logs schema to include "blocked" and "passed".
internal/clickhouse/src/ratelimits.ts Updated the ratelimitOverviewLogsParams to allow sorting by "passed" and "blocked"; modified the getRatelimitOverviewLogs function by mapping "passed" to "passed_count" and "blocked" to "blocked_count".

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Table as RatelimitOverviewLogsTable
    participant API as getRatelimitOverviewLogs
    participant DB as Clickhouse

    User->>Table: Click "passed"/"blocked" column header
    Table->>Table: Execute onSort (calls toggleSort)
    Table->>API: Send updated sort parameters (e.g., column "passed")
    API->>DB: Query logs sorted by "passed_count" (or "blocked_count")
    DB-->>API: Return sorted logs data
    API-->>Table: Send sorted logs data
    Table-->>User: Display sorted logs
Loading

Possibly related PRs

Suggested labels

🕹️ oss.gg, :joystick: 150 points

Suggested reviewers

  • mcstepp
  • chronark
  • perkinsjr
  • MichaelUnkey
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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 generate docstrings to generate docstrings for this 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 Mar 18, 2025

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

Copy link
Contributor Author

don't merge it

Copy link
Collaborator

ok

Copy link
Contributor Author

i'll tell you 😄

Copy link
Collaborator

then make it a draft

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

🧹 Nitpick comments (3)
apps/dashboard/app/(app)/ratelimits/[namespaceId]/_overview/components/table/logs-table.tsx (1)

55-61: Clarify the default sort direction for "passed".
It’s not immediately clear why toggleSort("passed", false) is set to false. Consider documenting or renaming this parameter to improve clarity of the logic (e.g., specifying isAscending vs. isDescending).

internal/clickhouse/src/ratelimits.ts (2)

537-543: Consider unifying the detection of custom sorts.
Having multiple checks for hasAvgLatencySort, hasP99LatencySort, etc. is fine, but you can unify them into a single function that inspects each sort rule, which might reduce repetition and simplify future expansions.


607-607: Check dynamic insertion of cursorCondition.
Confirm that string interpolation of ${cursorCondition} is reliable and that special characters or spacing do not interrupt the query. It might be safer to build the full query outside the template literal.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b577b40 and 6331350.

📒 Files selected for processing (2)
  • apps/dashboard/app/(app)/ratelimits/[namespaceId]/_overview/components/table/logs-table.tsx (3 hunks)
  • internal/clickhouse/src/ratelimits.ts (5 hunks)
🧰 Additional context used
🧠 Learnings (1)
internal/clickhouse/src/ratelimits.ts (1)
Learnt from: ogzhanolguncu
PR: unkeyed/unkey#2896
File: internal/clickhouse/src/ratelimits.ts:468-592
Timestamp: 2025-03-12T13:07:07.472Z
Learning: The cursor logic in getRatelimitOverviewLogs query uses (time, request_id) < (cursorTime, cursorRequestId) comparison which works well with descending order but may need adjustment for ascending sorts based on real usage patterns.
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: Test Packages / Test ./packages/cache
  • GitHub Check: Test Packages / Test ./packages/api
  • GitHub Check: Test Packages / Test ./internal/clickhouse
  • GitHub Check: Test Packages / Test ./internal/hash
  • GitHub Check: Test Agent Local / test_agent_local
  • GitHub Check: Test Go API Local / Test
  • GitHub Check: Test API / API Test Local
  • GitHub Check: Build / Build
  • GitHub Check: autofix
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (6)
apps/dashboard/app/(app)/ratelimits/[namespaceId]/_overview/components/table/logs-table.tsx (2)

88-94: Extend test coverage for "blocked" column sorting.
Similar to "passed", ensure that the new sorting capability for "blocked" is tested to avoid regressions. Verifying that sorting is correct for both ascending and descending orders would be helpful.


175-175: Confirm consistent sorting approach for "time".
Previously, the time sort might have used a different default direction. Verify that setting false aligns with the intended default (ascending or descending) to maintain consistency across columns.

internal/clickhouse/src/ratelimits.ts (4)

437-437: Validate additional sort fields in the schema.
Adding "blocked" and "passed" to the z.enum is correct. Please confirm there are no other fields (e.g., "avg_latency") missing that might need to be included.


517-518: Ensure column mapping is correct for "passed" and "blocked".
The new mappings "passed" -> "passed_count" and "blocked" -> "blocked_count" appear logically sound. Verify that these fields exist and return accurate counts in all usage scenarios.


547-553: Revisit defaulting to "ASC" for custom sorts.
The code enforces ascending order if any of the custom sort columns are present. Verify that this matches the intended UX, as some users might expect descending order (show highest counts first).


566-592: Verify cursor pagination logic for both ascending and descending sorts.
The new conditions properly distinguish between ascending and descending to compare request timestamps and IDs. Given prior learnings about cursor usage, ensure real usage patterns behave as expected.

Copy link
Contributor Author

we'll merge this first then api-overview feel free to merge it after you check

@chronark chronark added this pull request to the merge queue Mar 18, 2025
Merged via the queue into main with commit efe7661 Mar 18, 2025
29 of 30 checks passed
@chronark chronark deleted the add-outcome-sort-to-ratelimit-overview branch March 18, 2025 12:44
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