Skip to content

Conversation

MichaelBuessemeyer
Copy link
Contributor

Seems like #8249 did not fully fix the issue. I still cannot reproduce the error locally (even when working a very similar scenario to what caused the first error).

URL of deployed dev instance (used for testing):

  • https://___.webknossos.xyz

Steps to test:

should not be necessary; but in case you want to: Spin up a local serve, request http://localhost:9000/api/datasets?isActive=false => the server console should show more extensive logging

@MichaelBuessemeyer MichaelBuessemeyer self-assigned this Nov 29, 2024
Copy link
Contributor

coderabbitai bot commented Nov 29, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in this pull request primarily focus on enhancing error handling and logging in the DatasetController, Dataset, and DatasetService classes. Modifications include the addition of logging statements to improve traceability during dataset operations, more descriptive error messages for various parsing and retrieval processes, and refined error handling to provide clearer context during failures. Overall, the changes aim to improve the maintainability and debuggability of the code without altering the fundamental logic of the existing methods.

Changes

File Path Change Summary
app/controllers/DatasetController.scala Added logging to list and listGrouped methods; refined error handling with descriptive messages.
app/models/dataset/Dataset.scala Improved error handling and logging in parsing functions and dataset retrieval methods.
app/models/dataset/DatasetService.scala Enhanced error messages in the publicWrites method for better traceability during failures.

Possibly related PRs

Suggested labels

bug, urgent, frontend

Suggested reviewers

  • fm3

Poem

🐇 In the fields where datasets play,
Logging brightens up the way.
Errors now with messages clear,
Helping us to persevere.
With each change, we hop and cheer,
For better code is always near! 🌼


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.

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

🧹 Outside diff range and nitpick comments (6)
app/models/dataset/DatasetService.scala (2)

352-352: LGTM! Enhanced error messages improve debugging capabilities.

The addition of dataset IDs to error messages significantly improves traceability and debugging capabilities. This aligns well with the PR's objective of enhancing debug logging for dataset listing operations.

Consider extracting the dataset ID error context into a helper method to maintain DRY principles:

+ private def withDatasetContext(message: String, datasetId: ObjectId): String = 
+   s"$message for dataset $datasetId"

- ?~> s"fetching data store failed for dataset ${dataset._id}"
+ ?~> withDatasetContext("fetching data store failed", dataset._id)

Also applies to: 354-362


352-364: Consider adding structured logging for better observability.

While the current changes improve error messages, structured logging would provide even better debugging capabilities.

Consider adding structured logging using the LazyLogging trait that's already mixed in:

// Add at the beginning of publicWrites
logger.debug(
  s"Fetching public writes for dataset",
  Map(
    "datasetId" -> dataset._id.toString,
    "organization" -> dataset._organization.toString,
    "requestingUser" -> requestingUserOpt.map(_._id.toString).getOrElse("none")
  )
)
app/controllers/DatasetController.scala (3)

203-203: Remove unnecessary Fox.successful call

This line doesn't serve any purpose and can be safely removed.

-            _ <- Fox.successful(())

204-205: Improve logging structure for better parsing

Consider using structured logging with key-value pairs for better log parsing and analysis.

-            _ = logger.info(
-              s"Requesting listing datasets with isActive '$isActive', isUnreported '$isUnreported', organizationId '$organizationIdOpt', folderId '$folderIdValidated', uploaderId '$uploaderIdValidated', searchQuery '$searchQuery', recursive '$recursive', limit '$limit'")
+            _ = logger.info("Requesting listing datasets",
+              "isActive" -> isActive,
+              "isUnreported" -> isUnreported,
+              "organizationId" -> organizationIdOpt,
+              "folderId" -> folderIdValidated,
+              "uploaderId" -> uploaderIdValidated,
+              "searchQuery" -> searchQuery,
+              "recursive" -> recursive,
+              "limit" -> limit)

-            _ = logger.info(s"Found ${datasets.size} datasets successfully")
+            _ = logger.info("Dataset listing completed", "count" -> datasets.size)

Also applies to: 214-214


227-227: Remove unnecessary Fox.successful calls

These lines don't serve any purpose and can be safely removed.

-      _ <- Fox.successful(())
-      _ <- Fox.successful(())

Also applies to: 238-238

app/models/dataset/Dataset.scala (1)

223-227: Consider enhancing the second log message.

While the first log message provides valuable debugging information about selection predicates, the second log message "Requesting datasets with query" could be more informative.

Consider adding more context to the second log message, for example:

- _ = logger.info("Requesting datasets with query")
+ _ = logger.info(s"Executing dataset query with limit ${limitOpt.getOrElse("none")}")
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ec72322 and 08678ab.

📒 Files selected for processing (3)
  • app/controllers/DatasetController.scala (1 hunks)
  • app/models/dataset/Dataset.scala (2 hunks)
  • app/models/dataset/DatasetService.scala (1 hunks)
🔇 Additional comments (2)
app/models/dataset/DatasetService.scala (1)

364-364: LGTM! Consistent error handling for storage operations.

The error message enhancement for storage operations maintains consistency with the other improvements.

app/models/dataset/Dataset.scala (1)

118-125: LGTM! Enhanced error messages improve debugging capabilities.

The added error messages for parsing operations are clear and specific, making it easier to identify and diagnose parsing issues.

Comment on lines +227 to +228
_ <- Fox.successful(())
_ = logger.info(s"datasets: $datasets, requestingUser: ${requestingUser.map(_._id)}")
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Avoid logging sensitive information

The logging statements include sensitive information like user IDs and dataset details. Consider:

  1. Masking or truncating sensitive IDs
  2. Reducing the verbosity of dataset information
  3. Moving detailed logging to DEBUG level
-      _ = logger.info(s"datasets: $datasets, requestingUser: ${requestingUser.map(_._id)}")
+      _ = logger.debug("Processing datasets",
+        "datasetCount" -> datasets.size,
+        "hasRequestingUser" -> requestingUser.isDefined)

-      _ = logger.info(s"byOrgaTuple orga: ${byOrgaTuple._1}, datasets: ${byOrgaTuple._2}")
+      _ = logger.debug("Processing organization datasets",
+        "organizationId" -> byOrgaTuple._1,
+        "datasetCount" -> byOrgaTuple._2.size)

-              logger.info(s"datastore: ${byDataStoreTuple._1}, datasets: ${byDataStoreTuple._2}")
+              logger.debug("Processing datastore datasets",
+                "datastoreName" -> byDataStoreTuple._1,
+                "datasetCount" -> byDataStoreTuple._2.size)

Also applies to: 238-239, 244-244

Michael Büßemeyer added 2 commits December 2, 2024 09:51
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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 08678ab and 932c473.

📒 Files selected for processing (1)
  • app/controllers/DatasetController.scala (1 hunks)
🔇 Additional comments (1)
app/controllers/DatasetController.scala (1)

228-228: 🛠️ Refactor suggestion

Reduce logging verbosity in listGrouped method

The previous comment about logging sensitive information applies here as well.

Additionally, consider consolidating these debug statements into a single, structured log entry at the end of the grouping process.

-      _ = logger.info(s"datasets: $datasets, requestingUser: ${requestingUser.map(_._id)}")
-      _ = logger.info(
-        s"requestingUserTeamManagerMemberships: ${requestingUserTeamManagerMemberships.map(_.map(_.toString))}")
-      _ = logger.info(s"byOrgaTuple orga: ${byOrgaTuple._1}, datasets: ${byOrgaTuple._2}")
-      _ = logger.info(s"datastore: ${byDataStoreTuple._1}, datasets: ${byDataStoreTuple._2}")
+      _ = logger.debug("Dataset grouping completed",
+        "totalDatasets" -> datasets.size,
+        "hasRequestingUser" -> requestingUser.isDefined,
+        "organizationCount" -> groupedByOrga.size,
+        "datastoreCount" -> groupedByDataStore.size)

Also applies to: 233-234, 239-239, 244-244

Comment on lines +204 to +205
_ = logger.info(
s"Requesting listing datasets with isActive '$isActive', isUnreported '$isUnreported', organizationId '$organizationIdOpt', folderId '$folderIdValidated', uploaderId '$uploaderIdValidated', searchQuery '$searchQuery', recursive '$recursive', limit '$limit'")
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider adjusting log levels and format for production use

The logging statements provide valuable debugging information but consider:

  1. Moving detailed parameter logging to DEBUG level
  2. Using structured logging format for better parsing
  3. Avoiding logging sensitive IDs in production
-            _ = logger.info(
-              s"Requesting listing datasets with isActive '$isActive', isUnreported '$isUnreported', organizationId '$organizationIdOpt', folderId '$folderIdValidated', uploaderId '$uploaderIdValidated', searchQuery '$searchQuery', recursive '$recursive', limit '$limit'")
+            _ = logger.debug("Requesting dataset listing",
+              "isActive" -> isActive,
+              "isUnreported" -> isUnreported,
+              "hasOrganizationId" -> organizationIdOpt.isDefined,
+              "hasFolderId" -> folderIdValidated.isDefined,
+              "hasUploaderId" -> uploaderIdValidated.isDefined,
+              "hasSearchQuery" -> searchQuery.isDefined,
+              "recursive" -> recursive,
+              "limit" -> limit)

-            _ = logger.info(s"Found ${datasets.size} datasets successfully")
+            _ = logger.debug("Dataset listing completed", "count" -> datasets.size)

Also applies to: 214-214

Copy link
Member

@fm3 fm3 left a comment

Choose a reason for hiding this comment

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

This time, let’s leave this in until after the bugfix is tested in production 😅

Also, some of the ?~>error messages may actually be nice to keep in afterwards

@MichaelBuessemeyer MichaelBuessemeyer enabled auto-merge (squash) December 2, 2024 10:54
@MichaelBuessemeyer MichaelBuessemeyer merged commit 0a2afa4 into master Dec 2, 2024
3 checks passed
@MichaelBuessemeyer MichaelBuessemeyer deleted the add-debug-logging-for-ds-listing branch December 2, 2024 11:07
MichaelBuessemeyer added a commit that referenced this pull request Dec 2, 2024
MichaelBuessemeyer added a commit that referenced this pull request Dec 5, 2024
* Revert "Re-Add debug logging for ds listing (#8251)"

This reverts commit 0a2afa4.

* add some error message

* Update app/models/dataset/DataStore.scala

Co-authored-by: Florian M <[email protected]>

---------

Co-authored-by: Michael Büßemeyer <[email protected]>
Co-authored-by: Florian M <[email protected]>
@coderabbitai coderabbitai bot mentioned this pull request Dec 9, 2024
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants