Skip to content

Conversation

aaguiarz
Copy link
Member

@aaguiarz aaguiarz commented Jul 7, 2025

Summary

  • add persistent success-log and failure-log flags
  • support success/failure logging in tuple import
  • flush logs after each tuple operation
  • allow suppressing stdout when logs are enabled

Testing

  • make test-unit
  • go build ./...

https://chatgpt.com/codex/tasks/task_e_686c2ec5a4b48322adc0e1ba7263f18e

Summary by CodeRabbit

  • New Features

    • Added support for logging successful and failed tuple operations to separate log files using new command-line flags.
    • Log files can be generated in CSV, YAML, or JSON formats, depending on the file extension provided.
    • CLI output for successful or failed tuples is suppressed if corresponding log files are specified, reducing duplicate reporting.
  • Documentation

    • Updated command-line help to include new flags for logging tuple operation results.

@aaguiarz aaguiarz requested a review from a team as a code owner July 7, 2025 21:25
Copy link
Contributor

coderabbitai bot commented Jul 7, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This change adds support for logging successful and failed tuple write and delete operations to separate files in various formats (CSV, YAML, JSON/JSONL) via new CLI flags. The logging is managed by a new TupleLogger type, and context is used to pass loggers through the import and process flows. CLI output is suppressed for logged results.

Changes

File(s) Change Summary
cmd/tuple/tuple.go Added persistent flags --success-log and --failure-log to specify log file paths for successful/failed ops.
cmd/tuple/write.go, cmd/tuple/delete.go Integrated new logging flags; created and injected TupleLogger instances into context; suppressed CLI output if logging.
internal/tuple/import.go Updated processing functions to accept context and use loggers for writing successes/failures during tuple import.
internal/tuple/logger.go Introduced TupleLogger type for logging tuple results in multiple formats; added context helpers for loggers.
internal/tuple/import_test.go Updated tests to pass context to processWrites and processDeletes.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant TupleLogger
    participant Importer

    User->>CLI: Run tuple write/delete with --success-log/--failure-log
    CLI->>TupleLogger: Create TupleLogger(s) for provided log paths
    CLI->>Importer: Pass context with loggers to import function
    Importer->>TupleLogger: Log successes and failures during processing
    Importer->>CLI: Return results
    CLI-->>User: Output (suppressed if logging enabled)
Loading

Suggested reviewers

  • Siddhant-K-code

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

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)
internal/tuple/logger.go (2)

63-79: Consider error handling for marshaling operations.

The LogSuccess method handles multiple formats well, but ignores marshaling errors. While this might be acceptable for logging to avoid disrupting the main flow, consider at least logging marshal failures.

 case ".yaml", ".yml":
-	b, _ := yaml.Marshal(key)
+	b, err := yaml.Marshal(key)
+	if err != nil {
+		// Could log marshal error or use a fallback
+		return
+	}
 	l.writer.Write(b)

82-98: Same marshaling concern applies to LogFailure.

Similar to LogSuccess, consider handling marshaling errors more explicitly to improve robustness.

internal/tuple/import.go (1)

330-337: Consider consistency in variable naming.

The variable failed is used in both processWrites and processDeletes functions. Consider using more descriptive names like failedWrite and failedDelete to improve code clarity, especially since these are in different contexts.

# In processWrites function:
-			failed := failedWriteResponse{
+			failedWrite := failedWriteResponse{
				TupleKey: write.TupleKey,
				Reason:   reason,
			}
-			failedWrites = append(failedWrites, failed)
+			failedWrites = append(failedWrites, failedWrite)
			if failureLogger != nil {
-				failureLogger.LogFailure(failed)
+				failureLogger.LogFailure(failedWrite)
			}

# In processDeletes function:
-			failed := failedWriteResponse{
+			failedDelete := failedWriteResponse{
				TupleKey: deletedTupleKey,
				Reason:   reason,
			}
-			failedDeletes = append(failedDeletes, failed)
+			failedDeletes = append(failedDeletes, failedDelete)
			if failureLogger != nil {
-				failureLogger.LogFailure(failed)
+				failureLogger.LogFailure(failedDelete)
			}

Also applies to: 370-377

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 61d20f9 and 57c2a6e.

📒 Files selected for processing (6)
  • cmd/tuple/delete.go (3 hunks)
  • cmd/tuple/tuple.go (1 hunks)
  • cmd/tuple/write.go (3 hunks)
  • internal/tuple/import.go (4 hunks)
  • internal/tuple/import_test.go (3 hunks)
  • internal/tuple/logger.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
cmd/tuple/delete.go (2)
internal/tuple/logger.go (4)
  • TupleLogger (18-24)
  • NewTupleLogger (27-46)
  • WithSuccessLogger (121-123)
  • WithFailureLogger (125-127)
internal/tuple/import.go (1)
  • ImportTuplesWithoutRampUp (85-90)
cmd/tuple/write.go (1)
internal/tuple/logger.go (4)
  • TupleLogger (18-24)
  • NewTupleLogger (27-46)
  • WithSuccessLogger (121-123)
  • WithFailureLogger (125-127)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: Tests
  • GitHub Check: Test Release Process
  • GitHub Check: Lints
  • GitHub Check: Analyze (go)
  • GitHub Check: Analyze (actions)
🔇 Additional comments (17)
cmd/tuple/tuple.go (1)

41-42: LGTM! Clean flag implementation.

The new persistent flags for success and failure logging are well-defined and follow the existing pattern. The descriptive names and help text make their purpose clear.

internal/tuple/import_test.go (3)

4-4: LGTM! Appropriate context import.

The context import is necessary for the updated function signatures.


27-27: LGTM! Correct context usage in tests.

Using context.Background() is the appropriate choice for unit tests where no specific context behavior is needed.


49-49: LGTM! Consistent context usage.

The context parameter is consistently applied to both test functions.

cmd/tuple/delete.go (3)

52-68: LGTM! Proper logger setup and resource management.

The logger creation follows good practices:

  • Proper error handling for logger instantiation
  • Appropriate resource cleanup with deferred Close() calls
  • Conditional creation based on flag values

The ignored errors from flag.GetString() are acceptable since these are optional flags that won't fail parsing.


90-93: LGTM! Clean context propagation.

The loggers are properly attached to the context and passed to the import function, enabling logging throughout the tuple processing pipeline.


105-111: LGTM! Smart output suppression logic.

The conditional output suppression prevents duplicate information when logging is enabled, improving user experience by avoiding redundant console output.

cmd/tuple/write.go (3)

236-254: LGTM! Consistent logger implementation.

The logger setup follows the same excellent pattern as in the delete command:

  • Proper conditional creation based on flag values
  • Good error handling for logger instantiation
  • Appropriate resource cleanup with deferred Close() calls

Consistency across commands enhances maintainability.


266-267: LGTM! Proper context setup.

The loggers are correctly attached to the context, enabling the logging functionality throughout the import process.


282-288: LGTM! Thoughtful output management.

The conditional suppression of successful and failed tuples in the console output when logging is enabled prevents information duplication and improves the user experience.

internal/tuple/logger.go (4)

27-46: LGTM! Robust file handling and logger initialization.

The constructor properly handles file creation, permission setting (0o600 is appropriate for log files), and tracks existing file size to determine header status. Error handling is comprehensive with proper resource cleanup.


48-60: LGTM! Proper resource cleanup and data persistence.

The Close and flush methods ensure data integrity by flushing buffers and syncing to disk. The nil check in Close prevents panics.


116-137: LGTM! Clean context utilities implementation.

The context key approach using a custom type prevents key collisions, and the getter functions safely handle type assertions. This provides a clean API for logger injection and retrieval.


100-112: CSV escaping is handled by encoding/csv — no action needed

Go’s encoding/csv.Writer automatically follows RFC 4180, quoting fields containing commas, quotes, or newlines and doubling any embedded quotes. Your use of csv.NewWriter with a simple Write(...) call correctly handles all necessary escaping.

internal/tuple/import.go (3)

143-143: Context parameter integration looks consistent.

The context parameter has been properly added to all the process functions and their call sites. The changes maintain consistency across the codebase.

Also applies to: 218-219, 301-301, 304-305, 311-311


325-327: Logging integration follows good practices.

The conditional logging implementation is well-structured:

  • Loggers are checked for nil before use
  • Success and failure cases are handled appropriately
  • The logging doesn't interfere with the main business logic

The pattern of creating the failed variable before appending and logging (lines 330-337, 370-377) is a good refactor that makes the code more readable.

Also applies to: 335-337, 365-367, 375-377


319-320: Logger helpers are defined in internal/tuple/logger.go
The functions getSuccessLogger and getFailureLogger exist at lines 129–137 in internal/tuple/logger.go. No further changes are needed here.

Copy link
Member

@rhamzeh rhamzeh left a comment

Choose a reason for hiding this comment

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

Code looks good - in the morning, I'd like to test it quickly before merging.

Later, for us: we should create a ticket to consolidate our outputs, we write yaml ans csv and json in various places.

Having an output manager that deals with this would be a good idea

@aaguiarz
Copy link
Member Author

aaguiarz commented Jul 8, 2025

@rhamzeh the main issue with this approach is that we can't know why a tuple failed to write. Maybe we need to output a "reason" field on the error logs and ignore that field when importing..

@aaguiarz aaguiarz marked this pull request as draft September 18, 2025 10:38
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