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

refactor: how dashboards are handled #1173

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

Conversation

de-sh
Copy link
Contributor

@de-sh de-sh commented Feb 7, 2025

  • generate ids if not provided
  • set default value
  • improve error response(404)
  • improve method signature

Fixes #XXXX.

Description


This PR has:

  • been tested to ensure log ingestion and log query works.
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added documentation for new or modified features or behaviors.

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced error responses for dashboard operations, now returning a clear "Not Found" status when a dashboard is unavailable.
  • Refactor

    • Streamlined how dashboard and tile identifiers, as well as version information, are generated and handled.
    • Updated operation naming for dashboard actions to ensure clearer and more consistent behavior.

* generate ids if not provided
* set default value
* improve error response(404)
* improve method signature
@de-sh de-sh marked this pull request as draft February 8, 2025 17:06
@de-sh de-sh marked this pull request as ready for review February 8, 2025 17:06
Copy link

coderabbitai bot commented Feb 19, 2025

Walkthrough

The pull request refactors dashboard handling and data struct definitions. In the HTTP handler, the retrieval method has been altered from get_dashboard to get, and error reporting now uses a dedicated DashboardDoesNotExist variant with a NOT_FOUND status. In the dashboard module, several struct fields have been updated from optional to non-optional strings with default value generators. Additionally, method names have been simplified (e.g., delete_dashboard to delete), and helper functions for generating IDs and versions have been added.

Changes

File(s) Change Summary
src/handlers/.../dashboards.rs - Changed dashboard retrieval method from get_dashboard to get.
- Updated error handling to use DashboardDoesNotExist with a NOT_FOUND response.
- Removed code for generating unique IDs for dashboards and tiles.
src/users/dashboards.rs - Updated Tiles and Dashboard struct fields from Option<String> to String with default generators.
- Renamed methods: get_dashboardget and delete_dashboarddelete.
- Added helper functions: gen_tile_id, default_version, and gen_dashboard_id for default value generation.

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant H as HTTP Handler
    participant D as Dashboard Service

    C->>H: Request dashboard (dashboard_id, user_id)
    H->>D: Call get(dashboard_id, get_hash(user_id))
    alt Dashboard exists
        D-->>H: Dashboard Data
        H-->>C: Return dashboard info (200 OK)
    else Dashboard missing
        D-->>H: None
        H-->>C: Return error DashboardDoesNotExist (404 NOT FOUND)
    end
Loading

Poem

I hop through lines of freshly tuned code,
Where dashboards retrieve by a simpler mode.
New IDs and errors now clearly defined,
In each refactor, neat logic we find.
This rabbit cheers with a joyful nod,
For changes that keep our code on the right track! 🐇✨


🪧 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. (Beta)
  • @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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/users/dashboards.rs (2)

37-46: LGTM! Consider adding a constant for the random string length.

The implementation ensures uniqueness through a combination of random string and microsecond timestamp.

Consider extracting the magic number 8 into a named constant for better maintainability:

+const TILE_ID_RANDOM_LENGTH: usize = 8;
+
 fn gen_tile_id() -> String {
     get_hash(
         format!(
             "{}{}",
-            rand::distributions::Alphanumeric.sample_string(&mut rand::thread_rng(), 8),
+            rand::distributions::Alphanumeric.sample_string(&mut rand::thread_rng(), TILE_ID_RANDOM_LENGTH),
             Utc::now().timestamp_micros()
         )
         .as_str(),
     )
 }

112-118: LGTM! Consider adding documentation for these helper functions.

The implementation is clean and straightforward. The functions serve their purpose well as default value generators.

Consider adding documentation to explain the purpose and behavior of these functions:

+/// Returns the current dashboard version string.
 fn default_version() -> String {
     CURRENT_DASHBOARD_VERSION.to_owned()
 }

+/// Generates a unique dashboard ID using microsecond timestamp.
 fn gen_dashboard_id() -> String {
     get_hash(Utc::now().timestamp_micros().to_string().as_str())
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e1e2f2a and 58c6b70.

📒 Files selected for processing (2)
  • src/handlers/http/users/dashboards.rs (7 hunks)
  • src/users/dashboards.rs (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: Build Default aarch64-apple-darwin
  • GitHub Check: Build Default x86_64-apple-darwin
  • GitHub Check: Build Kafka aarch64-apple-darwin
  • GitHub Check: Quest Smoke and Load Tests for Distributed deployments
  • GitHub Check: Build Default x86_64-unknown-linux-gnu
  • GitHub Check: coverage
  • GitHub Check: Build Kafka x86_64-unknown-linux-gnu
  • GitHub Check: Quest Smoke and Load Tests for Standalone deployments
🔇 Additional comments (8)
src/users/dashboards.rs (4)

51-52: LGTM! Good use of serde's default attribute.

The change from Option<String> to String with a default generator simplifies the code by eliminating the need for Option handling.


122-127: LGTM! Good use of default value generators.

The change from Option<String> to String with default generators for both version and dashboard_id fields simplifies the code and ensures these essential fields are always present.


211-214: LGTM! Method name and implementation are now more concise.

The simplified comparison logic aligns well with the non-optional dashboard_id field.


216-223: LGTM! Good use of is_some_and for cleaner Option handling.

The method name is more concise, and the comparison logic is more elegant using is_some_and.

src/handlers/http/users/dashboards.rs (4)

50-50: LGTM! Improved error handling with specific error variant.

The method call aligns with the renamed method, and the error handling is now more specific and descriptive.

Also applies to: 54-54


86-87: LGTM! Consistent error handling.

The error handling is consistent with other methods and uses the specific error variant.


111-112: LGTM! Consistent error handling.

The error handling is consistent with other methods and uses the specific error variant.


131-132: LGTM! Improved error reporting with specific variant and status code.

The new error variant and its status code mapping improve the clarity of error reporting.

Also applies to: 143-143

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