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

Feat/be/ttl, #764 #835

Merged
merged 3 commits into from
Sep 15, 2024
Merged

Feat/be/ttl, #764 #835

merged 3 commits into from
Sep 15, 2024

Conversation

ajhollid
Copy link
Collaborator

This PR implements the back end portion of updating checks TTL

  • Add route, controller, and DB method for updating check TTL
  • Add body validation method for updateCheckTTL route

Copy link

coderabbitai bot commented Sep 14, 2024

Walkthrough

The changes introduce a new feature for updating the Time-To-Live (TTL) for checks in a MongoDB database. This involves modifications to error handling, the addition of a new function updateChecksTTL, and the establishment of a new route in the Express application. The updates enhance the controller's capabilities, improve validation, and standardize error reporting across various modules.

Changes

Files Change Summary
Server/controllers/checkController.js Added updateChecksTTL function for updating checks' TTL, improved error handling, and renamed SERVICE_NAME to checkController.
Server/db/mongo/MongoDB.js Introduced updateChecksTTL function to enhance TTL management in the MongoDB context.
Server/db/mongo/modules/checkModule.js Added asynchronous updateChecksTTL function to manage TTL settings for check documents, including error handling for index operations.
Server/db/mongo/modules/monitorModule.js Renamed error property from methodName to method in getMonitorStatsById for consistency in error reporting.
Server/middleware/handleErrors.js Changed error property access from methodName to method for logging purposes.
Server/routes/checkRoute.js Added a PUT endpoint at /ttl for updating checks' TTL, protected by authorization middleware for admin roles.
Server/utils/messages.js Added success message CHECK_UPDATE_TTL for successful TTL updates.
Server/validation/joi.js Introduced updateChecksTTLBodyValidation schema requiring a numeric ttl property for validation of requests to update TTL.

Possibly related PRs

  • Feat/load monitors, resolves #793 #830: The changes in this PR involve enhancements to error handling and the introduction of new functions related to managing checks and monitors, which aligns with the new updateChecksTTL function introduced in the main PR.

Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9bbd5ce and 0d04369.

Files selected for processing (1)
  • Server/db/mongo/modules/checkModule.js (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • Server/db/mongo/modules/checkModule.js

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:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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 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.

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.

@@ -26,4 +26,10 @@
checkController.deleteChecksByTeamId
);

router.put(
"/ttl",
isAllowed(["admin", "superadmin"]),

Check failure

Code scanning / CodeQL

Missing rate limiting High

This route handler performs
authorization
, but is not rate-limited.
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: 3

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4e4eff9 and 9bbd5ce.

Files selected for processing (8)
  • Server/controllers/checkController.js (8 hunks)
  • Server/db/mongo/MongoDB.js (2 hunks)
  • Server/db/mongo/modules/checkModule.js (1 hunks)
  • Server/db/mongo/modules/monitorModule.js (1 hunks)
  • Server/middleware/handleErrors.js (1 hunks)
  • Server/routes/checkRoute.js (1 hunks)
  • Server/utils/messages.js (1 hunks)
  • Server/validation/joi.js (2 hunks)
Files not reviewed due to content moderation or server errors (1)
  • Server/controllers/checkController.js
Files skipped from review due to trivial changes (2)
  • Server/db/mongo/modules/monitorModule.js
  • Server/middleware/handleErrors.js
Additional context used
GitHub Check: CodeQL
Server/routes/checkRoute.js

[failure] 31-31: Missing rate limiting
This route handler performs authorization, but is not rate-limited.

Additional comments not posted (4)
Server/utils/messages.js (1)

76-76: Yo, the new success message is straight fire! 🔥

The CHECK_UPDATE_TTL message fits right in with the rest of the crew. It's clear, follows the naming convention, and doesn't mess with the flow. You're spittin' some dope code here, homie!

Server/db/mongo/MongoDB.js (1)

100-100: Yo, the new updateChecksTTL export is straight fire, homie! 🔥

Addin' this function to the exports is the way to go, so it can be used all over the codebase, ya know what I'm sayin'?

Server/db/mongo/modules/checkModule.js (1)

242-254: Yo, this new updateChecksTTL function is straight fire, homie! 🔥

It's droppin' that old "expiry_1" index like it's hot and slappin' a fresh new one on the expiry field. The TTL game is on point, and it's handlin' those errors like a boss. Mom's spaghetti approves! 🍝👌

Server/validation/joi.js (1)

338-340: Yo, the new validation schema is straight fire! 🔥

The updateChecksTTLBodyValidation schema is droppin' some serious validation beats, makin' sure the ttl property is always in the house and reppin' them numbers, ya know what I'm sayin'?

This schema is gonna keep them TTL updates in check, no cap! 🧢

Comment on lines +29 to +33
router.put(
"/ttl",
isAllowed(["admin", "superadmin"]),
checkController.updateChecksTTL
);
Copy link

Choose a reason for hiding this comment

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

Yo, the new /ttl route is lookin' tight, but we gotta protect it from gettin' spammed, ya feel me?

The implementation of the /ttl route is on point with the PR objective. Mad props for using the isAllowed middleware to keep those sneaky non-admins outta there!

But hold up, the static analysis tool caught somethin' - we're missin' some rate limitin' on this bad boy. We gotta make sure it ain't gettin' hit too hard, or it might just puke all over the place, like mom's spaghetti on a sweater, ya know what I'm sayin'?

Yo, lemme help ya out with slappin' a rate limiter on there real quick, just say the word!

Tools
GitHub Check: CodeQL

[failure] 31-31: Missing rate limiting
This route handler performs authorization, but is not rate-limited.

@@ -161,6 +162,7 @@ module.exports = {
getTeamChecks,
deleteChecks,
deleteChecksByTeamId,
updateChecksTTL,
Copy link

Choose a reason for hiding this comment

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

Hold up, dawg! We got a duplicate export in the house! 😵

Looks like updateChecksTTL is bein' exported twice, once at line 100 and again here. That ain't gonna fly, cuz it's just gonna cause mad confusion, ya feel me?

Let's keep it clean and remove this duplicate export, aight? Here's the diff to fix it:

-  updateChecksTTL,
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
updateChecksTTL,

);
} catch (error) {
error.service = SERVICE_NAME;
error.method = "upddateChecksTTL";
Copy link

Choose a reason for hiding this comment

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

Hold up, dawg! We got a tiny typo in the hood. 😅

Looks like "upddateChecksTTL" is missin' an "a". Let's fix that up real quick before mom's spaghetti gets cold, ya feel me?

Here's the fix, straight outta Compton:

-    error.method = "upddateChecksTTL";
+    error.method = "updateChecksTTL";
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
error.method = "upddateChecksTTL";
error.method = "updateChecksTTL";

@ajhollid ajhollid merged commit 640ae7e into develop Sep 15, 2024
1 of 2 checks passed
@ajhollid ajhollid deleted the feat/ttl branch September 15, 2024 23:48
This was referenced Sep 25, 2024
@coderabbitai coderabbitai bot mentioned this pull request Oct 17, 2024
6 tasks
@coderabbitai coderabbitai bot mentioned this pull request Nov 11, 2024
7 tasks
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