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(clp-s): Add command line options for stubbed out kv-pair-IR ingestion. #618

Merged

Conversation

AVMatthews
Copy link
Contributor

@AVMatthews AVMatthews commented Dec 2, 2024

Description

Added command line interface needed for compressing IRv2 to archive.

  • added the --file-type flag to the c compression option of the clp-s command line interface
  • this new flag determine which parsing function will get called and there is error checking to make sure the --stucturize-arrrays isn't used in conjunction with incorrect file types.

Validation performed

Called the corresponding command line options (e.g. ./clp-s c test-archive test_ir.ir --file-type IR )to see that the command line options called the correct function paths.

Called ./clp-s c test-archive test_ir.ir --file-type IR --structurize-arrays to see the an error message is produced.

Called ./clp-s c test-archive test_json.json && ./clp-s c test-archive test_json.json --structurize-arrays to make sure both of these command result in the expected normal opperation.

Called ./clp-s c --help to see the correct usage message was printed including the new flag option.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced a new command-line option for specifying the file type during compression (e.g., Json or KeyValueIr).
    • Added a method to retrieve the specified file type from command-line arguments.
    • Enhanced the JsonParser to specify the type of input file it processes.
  • Bug Fixes

    • Improved error handling for invalid file type combinations in the compression process.
  • Documentation

    • Updated help messages to include information about the new file-type option and its usage in compression commands.

Copy link
Contributor

coderabbitai bot commented Dec 2, 2024

Walkthrough

The changes in this pull request introduce a new command-line option file-type in the CommandLineArguments class, allowing users to specify the type of file being compressed (e.g., json or kv-ir). This option is integrated into the command parsing logic, accompanied by a new member variable m_file_type. Additionally, a new enumeration FileType is added to represent valid file types, and a method get_file_type() is introduced for retrieval. The compress function is updated to handle the new file type, with error handling and help messages also revised accordingly.

Changes

File Path Change Summary
components/core/src/clp_s/CommandLineArguments.cpp Added a new command-line option file-type, integrated it into command parsing, and updated error handling and help messages.
components/core/src/clp_s/CommandLineArguments.hpp Added enumeration FileType, method get_file_type(), and member variable m_file_type initialized to FileType::Json.
components/core/src/clp_s/clp-s.cpp Introduced handling for input_file_type in the compress function, with a placeholder for future IRv2 parsing.
components/core/src/clp_s/JsonParser.hpp Added member variable input_file_type to JsonParserOption, initialized to FileType::Json.

Possibly related PRs

Suggested reviewers

  • haiqi96

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

🧹 Outside diff range and nitpick comments (3)
components/core/src/clp_s/clp-s.cpp (1)

131-171: Consider enhancing error handling in database configuration.

While the function effectively consolidates common compression setup logic, the database configuration section could benefit from additional error handling.

Consider wrapping the database configuration in a try-catch block:

     if (db_config_container.has_value()) {
+        try {
             auto const& db_config = db_config_container.value();
             option.metadata_db = std::make_shared<clp::GlobalMySQLMetadataDB>(
                     db_config.get_metadata_db_host(),
                     db_config.get_metadata_db_port(),
                     db_config.get_metadata_db_username(),
                     db_config.get_metadata_db_password(),
                     db_config.get_metadata_db_name(),
                     db_config.get_metadata_table_prefix()
             );
+        } catch (const std::exception& e) {
+            SPDLOG_ERROR("Failed to configure metadata database - {}", e.what());
+            return false;
+        }
     }
components/core/src/clp_s/CommandLineArguments.cpp (1)

957-959: Consolidate usage printing functions

The print_ir_compression_usage function added in lines 957-959 is very similar to print_compression_usage. It would be beneficial to parameterize these functions or create a common function to avoid code duplication.

components/core/src/clp_s/CommandLineArguments.hpp (1)

29-30: Ensure consistency in enum documentation

To maintain consistency, consider adding documentation or comments for the new IrCompress command in the Command enum, similar to the existing commands.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 88d83bf and 60af455.

📒 Files selected for processing (3)
  • components/core/src/clp_s/CommandLineArguments.cpp (4 hunks)
  • components/core/src/clp_s/CommandLineArguments.hpp (2 hunks)
  • components/core/src/clp_s/clp-s.cpp (3 hunks)
🔇 Additional comments (2)
components/core/src/clp_s/clp-s.cpp (2)

53-58: LGTM! Function declaration is well-documented.

The declaration follows consistent style and includes proper documentation.


355-358: LGTM! Command handling is properly integrated.

The new command case follows the existing pattern and error handling approach consistently.

components/core/src/clp_s/clp-s.cpp Outdated Show resolved Hide resolved
components/core/src/clp_s/CommandLineArguments.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@gibber9809 gibber9809 left a comment

Choose a reason for hiding this comment

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

Changing the approach to just adding a new file-type option to the c flow per side-discussion.

IR ingestion supports almost all of the same options now (except for --structurize-arrays), so it will be simpler and more maintainable to have IR and jsonl ingestion under the same top-level flow.

In the future we also plan to detect file-type automatically, at which point IR and jsonl ingestion will need to be under the same flow, and the --file-type option will no longer be required.

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

🧹 Outside diff range and nitpick comments (2)
components/core/src/clp_s/clp-s.cpp (2)

75-79: Enhance file type validation with enum and improved error messaging

Consider using an enum class for file types instead of string literals to prevent typos and improve type safety. Also, enhance the error message to list valid options.

+enum class FileType {
+    IR,
+    Json
+};
+
+static auto string_to_file_type(std::string const& type) -> std::optional<FileType> {
+    if (type == "IR") return FileType::IR;
+    if (type == "Json") return FileType::Json;
+    return std::nullopt;
+}
+
 auto file_type = command_line_arguments.get_file_type();
-if ("IR" != file_type && "Json" != file_type) {
-    SPDLOG_ERROR("File Type specified is Invalid");
+auto parsed_type = string_to_file_type(file_type);
+if (!parsed_type) {
+    SPDLOG_ERROR("Invalid file type '{}'. Valid options are: IR, Json", file_type);
     return false;
 }

80-83: Consider moving IR file type validation to CommandLineArguments

The validation of incompatible options should ideally be performed during argument parsing in the CommandLineArguments class. This would catch invalid combinations earlier and maintain better separation of concerns.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2734aa0 and 9909190.

📒 Files selected for processing (1)
  • components/core/src/clp_s/clp-s.cpp (2 hunks)
🔇 Additional comments (1)
components/core/src/clp_s/clp-s.cpp (1)

126-134: ⚠️ Potential issue

Adjust interim behaviour until implementation is complete

The function currently succeeds silently without performing any actual IR file processing, which could be misleading to callers.

 if ("IR" == file_type) {
-    // Functionality Coming in later PR
-    //  -->Call new parsing function in Json Parser to parse IRv2 to archive
-    //  -->Check for error from parsing function
+    SPDLOG_ERROR("IR file processing not yet implemented");
+    return false;
 } else {

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

🧹 Outside diff range and nitpick comments (1)
components/core/src/clp_s/CommandLineArguments.cpp (1)

271-278: Consider enhancing the error message

While the error message is clear, it could be more helpful by explaining why these options are incompatible.

Apply this change to improve the error message:

-                        SPDLOG_ERROR(
-                                "Invalid combination of arguments; --file-type {} and "
-                                "--structurize-arrays can't be used together",
-                                cKeyValueIrFileType
-                        );
+                        SPDLOG_ERROR(
+                                "Invalid combination of arguments; --file-type {} and "
+                                "--structurize-arrays can't be used together as key-value IR "
+                                "format does not support array structuring",
+                                cKeyValueIrFileType
+                        );
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9909190 and 2f3365f.

📒 Files selected for processing (4)
  • components/core/src/clp_s/CommandLineArguments.cpp (3 hunks)
  • components/core/src/clp_s/CommandLineArguments.hpp (3 hunks)
  • components/core/src/clp_s/JsonParser.hpp (2 hunks)
  • components/core/src/clp_s/clp-s.cpp (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/core/src/clp_s/clp-s.cpp
🔇 Additional comments (8)
components/core/src/clp_s/JsonParser.hpp (2)

15-15: LGTM: Include directive is correctly placed

The addition of CommandLineArguments.hpp is necessary for using the FileType enum.


33-33: LGTM: Member variable is properly initialized

The input_file_type member is correctly initialized with FileType::Json as the default value, maintaining backward compatibility.

components/core/src/clp_s/CommandLineArguments.hpp (3)

39-42: LGTM: FileType enum is well-defined

The enum class is correctly scoped and uses uint8_t as the underlying type, which is memory efficient.


124-124: LGTM: get_file_type method is properly defined

The method is correctly marked with [[nodiscard]] and returns the FileType enum.


194-194: LGTM: Member variable is properly initialized

The m_file_type member is correctly initialized with FileType::Json as the default value.

components/core/src/clp_s/CommandLineArguments.cpp (3)

151-151: LGTM: Command-line option is well-defined

The file-type option is properly added with a clear description and appropriate value name.

Also applies to: 206-209


263-265: LGTM: Constants are properly defined

The file type string constants are correctly defined as constexpr string_view.


266-282: LGTM: Validation logic is thorough

The validation logic:

  • Properly handles both supported file types
  • Includes error checking for invalid combinations
  • Provides clear error messages
  • Throws appropriate exceptions for unknown file types

@AVMatthews AVMatthews requested a review from gibber9809 December 4, 2024 22:27
components/core/src/clp_s/CommandLineArguments.cpp Outdated Show resolved Hide resolved
components/core/src/clp_s/CommandLineArguments.cpp Outdated Show resolved Hide resolved
components/core/src/clp_s/CommandLineArguments.cpp Outdated Show resolved Hide resolved
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 (2)
components/core/src/clp_s/CommandLineArguments.cpp (2)

208-211: Enhance the help message for the --file-type option.

Consider making the help message more informative by including the default value.

-                    "The type of file being compressed (json or kv-ir)"
+                    "The type of file being compressed (json or kv-ir, defaults to json)"

265-281: Refactor the file type parsing logic to reduce nesting.

The current implementation can be made more maintainable by reducing nesting and using early returns.

             if (parsed_command_line_options.count("file-type") > 0) {
-                if (cJsonFileType == file_type) {
-                    m_file_type = FileType::Json;
-                } else if (cKeyValueIrFileType == file_type) {
-                    m_file_type = FileType::KeyValueIr;
-                    if (m_structurize_arrays) {
-                        SPDLOG_ERROR(
-                                "Invalid combination of arguments; --file-type {} and "
-                                "--structurize-arrays can't be used together",
-                                cKeyValueIrFileType
-                        );
-                        return ParsingResult::Failure;
-                    }
-                } else {
-                    throw std::invalid_argument("Unknown FILE_TYPE: " + file_type);
-                }
+                if (cJsonFileType == file_type) {
+                    m_file_type = FileType::Json;
+                    return ParsingResult::Success;
+                }
+                
+                if (cKeyValueIrFileType == file_type) {
+                    if (m_structurize_arrays) {
+                        SPDLOG_ERROR(
+                                "Invalid combination of arguments; --file-type {} and "
+                                "--structurize-arrays can't be used together",
+                                cKeyValueIrFileType
+                        );
+                        return ParsingResult::Failure;
+                    }
+                    m_file_type = FileType::KeyValueIr;
+                    return ParsingResult::Success;
+                }
+                
+                throw std::invalid_argument("Unknown FILE_TYPE: " + file_type);
             }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2f3365f and 02159d9.

📒 Files selected for processing (2)
  • components/core/src/clp_s/CommandLineArguments.cpp (3 hunks)
  • components/core/src/clp_s/clp-s.cpp (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/core/src/clp_s/clp-s.cpp
🔇 Additional comments (1)
components/core/src/clp_s/CommandLineArguments.cpp (1)

151-153: LGTM! Constants and default value are well-defined.

The use of string_view for constants and the naming convention with 'c' prefix follow good practices.

components/core/src/clp_s/CommandLineArguments.cpp Outdated Show resolved Hide resolved
@AVMatthews AVMatthews requested a review from gibber9809 December 5, 2024 16:05
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

🧹 Outside diff range and nitpick comments (2)
components/core/src/clp_s/CommandLineArguments.cpp (2)

208-211: Enhance the help text for the --file-type option.

While the option is well-integrated, the help text could be more descriptive about the purpose and implications of each file type.

Consider this improved help text:

-                    "The type of file being compressed (json or kv-ir)"
+                    "The type of file being compressed: json (JSON logs) or kv-ir (key-value IR format). Note: kv-ir is incompatible with --structurize-arrays"

265-279: LGTM! Consider extracting validation to a separate method.

The validation logic is comprehensive and handles all cases appropriately. However, for better maintainability as more file types are added, consider extracting this validation into a separate method.

Consider this refactor:

+    FileType validate_and_get_file_type(std::string const& file_type, bool structurize_arrays) {
+        if (cJsonFileType == file_type) {
+            return FileType::Json;
+        }
+        if (cKeyValueIrFileType == file_type) {
+            if (structurize_arrays) {
+                SPDLOG_ERROR(
+                        "Invalid combination of arguments; --file-type {} and "
+                        "--structurize-arrays can't be used together",
+                        cKeyValueIrFileType
+                );
+                throw std::invalid_argument("Invalid combination of arguments");
+            }
+            return FileType::KeyValueIr;
+        }
+        throw std::invalid_argument("Unknown FILE_TYPE: " + file_type);
+    }
+
-    if (cJsonFileType == file_type) {
-        m_file_type = FileType::Json;
-    } else if (cKeyValueIrFileType == file_type) {
-        m_file_type = FileType::KeyValueIr;
-        if (m_structurize_arrays) {
-            SPDLOG_ERROR(
-                    "Invalid combination of arguments; --file-type {} and "
-                    "--structurize-arrays can't be used together",
-                    cKeyValueIrFileType
-            );
-            return ParsingResult::Failure;
-        }
-    } else {
-        throw std::invalid_argument("Unknown FILE_TYPE: " + file_type);
-    }
+    try {
+        m_file_type = validate_and_get_file_type(file_type, m_structurize_arrays);
+    } catch (std::invalid_argument const&) {
+        return ParsingResult::Failure;
+    }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 02159d9 and 1a8e372.

📒 Files selected for processing (2)
  • components/core/src/clp_s/CommandLineArguments.cpp (3 hunks)
  • components/core/src/clp_s/clp-s.cpp (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/core/src/clp_s/clp-s.cpp
🔇 Additional comments (1)
components/core/src/clp_s/CommandLineArguments.cpp (1)

151-153: LGTM! Well-defined constants and default value.

The constants are appropriately defined as string_view for compile-time optimization, and the default file type is sensibly set to "json".

Copy link
Contributor

@gibber9809 gibber9809 left a comment

Choose a reason for hiding this comment

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

LGTM.

@gibber9809
Copy link
Contributor

LGTM.

How about feat(clp-s): Add command line options for stubbed out kv-pair-IR ingestion. for the PR title?

@AVMatthews AVMatthews changed the title feat(clp-s): IRv2 to archive CLI changes feat(clp-s): Add command line options for stubbed out kv-pair-IR ingestion. Dec 9, 2024
@gibber9809 gibber9809 merged commit 2160362 into y-scope:main Dec 9, 2024
21 checks passed
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