Skip to content

Conversation

@bjp232004
Copy link
Contributor

@bjp232004 bjp232004 commented Oct 19, 2024

fixed #4788 #4033

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced filtering capabilities for logs with new methods for constructing filter expressions based on field types and values.
  • Improvements

    • Updated search term handling across various components to accept more detailed parameters, allowing for more structured filtering.
    • Improved pagination logic to ensure better user experience when navigating search results.
  • Bug Fixes

    • Enhanced error handling in search term addition to notify users of any issues with filter expression generation.

@bjp232004 bjp232004 linked an issue Oct 19, 2024 that may be closed by this pull request
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 19, 2024

Walkthrough

The pull request introduces significant modifications across multiple components related to log filtering functionality. A new method getFilterExpressionByFieldType is added to the useLogs composable to enhance filter expression construction based on field types. Several components, including DetailTable, IndexList, JsonPreview, TenstackTable, CellActions, and SearchResult, are updated to accommodate new method signatures that allow for more detailed search term handling. These changes collectively improve the flexibility and complexity of log filtering and search term management.

Changes

File Change Summary
web/src/composables/useLogs.ts - Added method: `getFilterExpressionByFieldType(field: string
web/src/plugins/logs/DetailTable.vue - Updated method signatures for toggleIncludeSearchTerm and toggleExcludeSearchTerm to accept three parameters: field, field_value, and action.
web/src/plugins/logs/IndexList.vue - Updated method signature for addSearchTerm to accept three parameters: field, field_value, and action.
- Integrated getFilterExpressionByFieldType in addSearchTerm.
web/src/plugins/logs/JsonPreview.vue - Updated method signature for addSearchTerm to accept three parameters: field, field_value, and action.
web/src/plugins/logs/TenstackTable.vue - Updated method signature for addSearchTerm to accept three parameters: field, field_value, and action.
- Modified handleDragEnd to manage timestamp_column arrangement.
web/src/plugins/logs/data-table/CellActions.vue - Updated method signature for addSearchTerm to accept three parameters: field, field_value, and action.
web/src/plugins/logs/SearchResult.vue - Updated method signature for addSearchTerm to accept three parameters: field, field_value, and action.
- Enhanced pagination logic in getPageData.

Possibly related PRs

Suggested labels

✏️ Feature

Suggested reviewers

  • omkarK06
  • nikhilsaikethe

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.

@github-actions github-actions bot added the ☢️ Bug Something isn't working label Oct 19, 2024
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: 3

🧹 Outside diff range and nitpick comments (9)
web/src/plugins/logs/data-table/CellActions.vue (2)

66-71: LGTM: Enhanced addSearchTerm function with improved type safety

The updated addSearchTerm function signature and implementation are well-designed. The changes provide better type safety and more flexibility in handling different field types. This modification aligns perfectly with the template changes and improves the overall functionality of the component.

Consider adding JSDoc comments to the addSearchTerm function to document the purpose of each parameter and the function itself. This would enhance code readability and maintainability. For example:

/**
 * Emits an event to add a search term based on the given field, value, and action.
 * @param {string} field - The field to search in.
 * @param {string | number | boolean} field_value - The value to search for.
 * @param {string} action - The action to perform ('include' or 'exclude').
 */
const addSearchTerm = (
  field: string,
  field_value: string | number | boolean,
  action: string,
) => {
  emit("addSearchTerm", field, field_value, action);
};

Inconsistent Usage of addSearchTerm Detected

The addSearchTerm method is being called with differing numbers of arguments across the codebase:

  • 0 Arguments:
    • web/components/rum/SearchBar.vue
    • web/plugins/traces/SearchBar.vue
    • web/plugins/logs/SearchBar.vue
    • web/plugins/logs/IndexList.vue
  • 1 Argument:
    • web/plugins/traces/fields-sidebar/BasicValuesFilter.vue
    • web/components/common/sidebar/FieldList.vue
  • 3 Arguments (Correct Usage):
    • web/plugins/logs/JsonPreview.vue
    • web/plugins/logs/data-table/CellActions.vue

This inconsistency may lead to unexpected behavior and should be addressed to ensure that all addSearchTerm calls adhere to the expected three-parameter structure.

🔗 Analysis chain

Line range hint 1-78: Summary: Improved search term handling in CellActions component

The changes made to the CellActions.vue component successfully enhance its functionality and flexibility in handling search terms. The modifications in both the template and script sections are consistent and well-implemented. Key improvements include:

  1. More granular control over search term addition in the template.
  2. Enhanced type safety and flexibility in the addSearchTerm function.
  3. Better alignment between the template and script sections.

These changes contribute to a more robust and maintainable component, which should improve the overall user experience when working with log data tables.

To ensure that these changes are consistent with the rest of the codebase, please run the following verification script:

This script will help identify any potential inconsistencies in how the addSearchTerm event or method is used across the project.


To address the issues encountered with the previous verification scripts, please run the following updated scripts:

[/run_scripts]


To further investigate the inconsistent usage of addSearchTerm, please run the following scripts to identify the number of arguments in each addSearchTerm call:

[/run_scripts]

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of addSearchTerm event across the codebase

# Test: Search for components that listen to the addSearchTerm event
# Expect: Components using this event should handle three parameters
rg --type vue -A 5 '@addSearchTerm'

# Test: Search for other occurrences of addSearchTerm method
# Expect: No inconsistent usage of addSearchTerm method
rg --type vue -A 5 'addSearchTerm'

Length of output: 126


Script:

#!/bin/bash
# Description: Verify the usage of addSearchTerm event across the codebase

# Test: Search for components that listen to the addSearchTerm event
# Expect: Components using this event should handle three parameters
rg '@addSearchTerm' --glob '*.vue' -A 5

# Test: Search for other occurrences of addSearchTerm method
# Expect: No inconsistent usage of addSearchTerm method
rg 'addSearchTerm' --glob '*.vue' -A 5

Length of output: 18918


Script:

#!/bin/bash
# Description: Find all addSearchTerm calls and count the number of arguments

# Extract all lines with addSearchTerm calls in .vue files
rg 'addSearchTerm\s*\(' --glob '*.vue' > addSearchTerm_calls.txt

# Count the number of arguments in each call
while IFS= read -r line; do
  # Extract the part inside the parentheses
  args=$(echo "$line" | grep -oP '(?<=addSearchTerm\().*(?=\))')
  # Count the number of commas to determine the number of arguments
  if [ -z "$args" ]; then
    count=0
  else
    count=$(echo "$args" | awk -F',' '{print NF}')
  fi
  echo "Arguments count in line: $count"
done < addSearchTerm_calls.txt

Length of output: 6190

web/src/plugins/logs/DetailTable.vue (2)

163-163: LGTM! Consider using constants for action strings.

The changes to toggleIncludeSearchTerm and toggleExcludeSearchTerm method calls are correct and align with the updated method signatures. They now pass the field name, field value, and action type.

Consider defining constants for the action strings "include" and "exclude" to improve maintainability and reduce the risk of typos. For example:

const INCLUDE_ACTION = 'include';
const EXCLUDE_ACTION = 'exclude';

// Then use them in the template
@click="toggleIncludeSearchTerm(value, key, INCLUDE_ACTION)"
@click="toggleExcludeSearchTerm(value, key, EXCLUDE_ACTION)"

Also applies to: 193-193


389-395: LGTM! Consider unifying the method implementations.

The updates to toggleIncludeSearchTerm and toggleExcludeSearchTerm methods are well-implemented. They now use getFilterExpressionByFieldType to construct search expressions based on field type, which should provide more accurate and flexible filtering.

Since both methods have identical implementations except for the action parameter, consider unifying them into a single method to reduce code duplication:

toggleSearchTerm(field: string|number, field_value: string|number|boolean, action: 'include' | 'exclude') {
  const searchExpression = getFilterExpressionByFieldType(
    field,
    field_value,
    action,
  );
  this.$emit("add:searchterm", searchExpression);
}

Then update the template to use this unified method:

@click="toggleSearchTerm(value, key, 'include')"
@click="toggleSearchTerm(value, key, 'exclude')"

This approach would make the code more DRY and easier to maintain.

Also applies to: 397-403

web/src/plugins/logs/TenstackTable.vue (1)

Line range hint 1-621: Consider adding type information for addSearchTerm emit

The addSearchTerm emit is declared in the emits array, but it doesn't specify the structure of the emitted event. To improve code clarity and maintainability, consider adding a comment or using TypeScript to define the structure of the emitted event.

You could add a comment like this:

const emits = defineEmits<{
  // Other emits...
  (e: 'addSearchTerm', field: string, field_value: string | number | boolean, action: string): void
  // Other emits...
}>()

This will provide better type checking and auto-completion for components using this emit.

web/src/composables/useLogs.ts (1)

245-246: Consider using a more widely supported method for object property checks.

The selectedStreamFieldType variable is a good addition for caching field types. However, be aware that Object.hasOwn() used in the getFilterExpressionByFieldType function is a relatively new method and might not be supported in all JavaScript environments.

Consider using the more widely supported Object.prototype.hasOwnProperty.call(obj, prop) or prop in obj for better compatibility:

if (Object.prototype.hasOwnProperty.call(stream, "schema") && 
    !Object.prototype.hasOwnProperty.call(selectedStreamFieldType, stream.name)) {
  // ...
}
web/src/plugins/logs/IndexList.vue (3)

440-442: Maintain Consistent Formatting in Function Calls

In the addSearchTerm function call, the arguments are formatted across multiple lines. For consistency and readability, ensure that similar function calls follow the same formatting style.


457-457: Maintain Consistent Formatting in Function Calls

The addSearchTerm function call here is formatted differently compared to the previous call. For improved readability, consider formatting the arguments across multiple lines, similar to the previous instance.

Apply this diff to align the formatting:

- addSearchTerm(
-     props.row.name,value.key, 'exclude',
- )
+ addSearchTerm(
+     props.row.name,
+     value.key,
+     'exclude',
+ )

1019-1019: Remove Unnecessary Commented Code

The line // searchObj.meta.showDetailTab = false; is commented out. If this code is no longer needed, consider removing it to keep the codebase clean and maintainable.

Apply this diff to remove the commented line:

- // searchObj.meta.showDetailTab = false;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 6714d26 and 48ef66a.

📒 Files selected for processing (6)
  • web/src/composables/useLogs.ts (4 hunks)
  • web/src/plugins/logs/DetailTable.vue (4 hunks)
  • web/src/plugins/logs/IndexList.vue (4 hunks)
  • web/src/plugins/logs/JsonPreview.vue (3 hunks)
  • web/src/plugins/logs/TenstackTable.vue (1 hunks)
  • web/src/plugins/logs/data-table/CellActions.vue (3 hunks)
🧰 Additional context used
🔇 Additional comments (11)
web/src/plugins/logs/data-table/CellActions.vue (1)

19-19: LGTM: Improved flexibility in search term handling

The changes to the @click event handlers for the include and exclude buttons are well-implemented. By passing separate arguments for the field, value, and action, the component now provides more granular control over search term addition. This change aligns well with the updated addSearchTerm function signature and enhances the overall flexibility of the component.

Also applies to: 30-30

web/src/plugins/logs/JsonPreview.vue (3)

144-144: LGTM: Template changes for addSearchTerm look good

The template has been updated correctly to use the new addSearchTerm method signature. The changes properly pass the field (key), field value (value[key]), and action ('include' or 'exclude') as parameters. This modification aligns well with the enhanced search term functionality.

Also applies to: 172-172


311-316: LGTM: addSearchTerm method updated correctly

The addSearchTerm method has been properly updated to accept three parameters: field, field_value, and action. This change aligns with the modifications in the template and enhances the search term functionality by allowing more specific control over include/exclude actions.


Line range hint 1-577: Summary: Enhanced search term functionality with minor query

The changes in this file successfully implement a more granular search term functionality by updating the addSearchTerm method to include 'include' and 'exclude' actions. The modifications are consistent across both the template and script sections, improving the component's capability to handle more specific search queries.

The implementation is clean and aligns well with the intended functionality. However, there's one minor query regarding an unused import (getFilterExpressionByFieldType) that needs clarification or removal if not needed.

Overall, these changes enhance the component's functionality and maintain good code quality.

web/src/plugins/logs/DetailTable.vue (2)

421-421: LGTM! Correct import of the new utility function.

The addition of getFilterExpressionByFieldType to the destructured import from useLogs is correct and necessary for the updated implementations of the search term toggle methods.


Line range hint 1-580: Overall, the changes improve search term handling and align with PR objectives.

The modifications to DetailTable.vue enhance the flexibility of search term handling by incorporating field types into the filter expression generation. The changes are well-implemented and consistent throughout the component.

Key improvements:

  1. Updated method signatures for toggleIncludeSearchTerm and toggleExcludeSearchTerm.
  2. Integration of getFilterExpressionByFieldType for type-specific filter expressions.
  3. Consistent updates in both the template and script sections.

Consider the suggested minor improvements to further enhance code maintainability:

  1. Using constants for action strings in the template.
  2. Unifying the toggle methods to reduce code duplication.

These changes successfully address the PR objective of improving include/exclude search based on data type.

web/src/plugins/logs/TenstackTable.vue (3)

Line range hint 1-1000: Summary of changes and next steps

The main change in this file is the update to the addSearchTerm function, which now accepts more specific parameters for improved search functionality. This change enhances the flexibility and precision of the search feature.

To ensure the changes are fully integrated:

  1. Update parent components that listen to the "addSearchTerm" event.
  2. Review and update the JsonPreview and CellActions components to use the new addSearchTerm signature correctly.
  3. Consider adding type information or comments for the addSearchTerm emit to improve code clarity.

These changes represent a positive improvement to the search functionality, but require careful integration to maintain consistency across the application.


Line range hint 1-621: Verify JsonPreview and CellActions components

The addSearchTerm function is passed as a prop to both the json-preview and cell-actions components. Given the changes to the addSearchTerm function signature, these components may need to be updated to provide the correct parameters when invoking the function.

Please review and update the JsonPreview and CellActions components to ensure they call addSearchTerm with the correct parameters (field, field_value, and action). Run the following script to locate these components:

#!/bin/bash
# Description: Locate JsonPreview and CellActions components and check their usage of addSearchTerm

# Find JsonPreview component
echo "Checking JsonPreview component:"
rg --type vue "export default.*JsonPreview" -l | xargs rg --type vue "addSearchTerm" -C 3

echo "\nChecking CellActions component:"
# Find CellActions component
rg --type vue "export default.*CellActions" -l | xargs rg --type vue "addSearchTerm" -C 3

622-627: Improved addSearchTerm function signature

The addSearchTerm function has been updated to accept more specific parameters (field, field_value, and action), which allows for more precise search term handling. This change enhances the flexibility and functionality of the search feature.

Please ensure that any parent components listening to the "addSearchTerm" event are updated to handle these new parameters. Run the following script to check for potential usage:

✅ Verification successful

Please run the following corrected script to verify potential usages of the addSearchTerm event in parent components:


Verification Successful

No existing parent components are using the @addSearchTerm event. The updated addSearchTerm function does not impact any current implementations.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find potential usages of addSearchTerm event in parent components

# Search for components that import TenstackTable
rg --type vue "import.*TenstackTable.*from" -l | while read -r file; do
  # Check if the file contains @addSearchTerm event listener
  if rg --type vue "@addSearchTerm" "$file" > /dev/null; then
    echo "Potential usage found in: $file"
    rg --type vue "@addSearchTerm" -C 3 "$file"
  fi
done

Length of output: 584


Script:

#!/bin/bash
# Description: Find potential usages of addSearchTerm event in parent components

# Search for .vue files that import TenstackTable
fd -e vue . | while read -r file; do
  if rg "@addSearchTerm" "$file" > /dev/null; then
    echo "Potential usage found in: $file"
    rg "@addSearchTerm" -C 3 "$file"
  fi
done

Length of output: 22251

web/src/composables/useLogs.ts (1)

4288-4288: LGTM: Exported getFilterExpressionByFieldType from useLogs.

The addition of getFilterExpressionByFieldType to the return object of useLogs is appropriate. This makes the new function available for use in other parts of the application that import useLogs, allowing for wider use of the new filtering functionality.

web/src/plugins/logs/IndexList.vue (1)

705-705: Importing getFilterExpressionByFieldType

Good job on importing getFilterExpressionByFieldType from useLogs(). This enhances modularity and reusability by utilizing a shared function for generating filter expressions based on field types.

emit("addFieldToTable", value);
};
const { searchObj,searchAggData } = useLogs();
const { searchObj,searchAggData, getFilterExpressionByFieldType } = useLogs();
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Unused import getFilterExpressionByFieldType found

The getFilterExpressionByFieldType function is imported from useLogs but is not used in JsonPreview.vue. Please remove the unused import to maintain clean and efficient code.

🔗 Analysis chain

Query: Unused import getFilterExpressionByFieldType

The getFilterExpressionByFieldType function is imported from the useLogs composable but doesn't appear to be used within the visible part of the script. Could you clarify the intended use of this imported function or remove it if it's not needed?

To check for any usage of getFilterExpressionByFieldType in the entire file, you can run:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

rg "getFilterExpressionByFieldType" web/src/plugins/logs/JsonPreview.vue

Length of output: 155

Comment on lines 4190 to 4295
const getFilterExpressionByFieldType = (
field: string,
field_value: string|number|boolean,
action: string,
) => {
let operator = action == "include" ? "=" : "!=";
try {
let fieldTypeList: any = {};
let fieldType: string = "utf8";
searchObj.data.streamResults.list.forEach((stream: any) => {
if (searchObj.data.stream.selectedStream.includes(stream.name)) {
if (
Object.hasOwn(stream, "schema") &&
!Object.hasOwn(selectedStreamFieldType, stream.name)
) {
selectedStreamFieldType[stream.name] = {};
stream.schema.forEach((schema: any) => {
selectedStreamFieldType[stream.name][schema.name] = schema.type;
});
fieldTypeList = {
...fieldTypeList,
...selectedStreamFieldType[stream.name],
};
} else {
if (Object.hasOwn(selectedStreamFieldType, stream.name)) {
fieldTypeList = {
...fieldTypeList,
...selectedStreamFieldType[stream.name],
};
}
}
}
});

if (Object.hasOwn(fieldTypeList, field)) {
fieldType = fieldTypeList[field];
}

if (field_value == "null" || field_value == "NULL" || field_value == "") {
operator = action == "include" ? "is" : "is not";
field_value = "null";
}
let expression = field_value == "null" ? `${field} ${operator} ${field_value}` : `${field} ${operator} '${field_value}'`;

if (
fieldType.toLowerCase() == "int64" ||
fieldType.toLowerCase() == "float64"
) {
expression = `${field} ${operator} ${field_value}`;
} else if (fieldType.toLowerCase() == "boolean") {
operator = action == "include" ? "is" : "is not";
expression = `${field} ${operator} ${field_value}`;
}

return expression;
} catch (e: any) {
console.log("Error while getting filter expression by field type", e);
return `${field} ${operator} '${field_value}'`;
}
};
Copy link
Contributor

@coderabbitai coderabbitai bot Oct 19, 2024

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance error handling and consider potential side effects in getFilterExpressionByFieldType.

The getFilterExpressionByFieldType function is a valuable addition for constructing type-specific filter expressions. However, there are a few areas that could be improved:

  1. Error handling: The current catch-all error handling might mask specific issues. Consider adding more granular error handling.

  2. Global state mutation: The function mutates the global selectedStreamFieldType object, which could lead to unexpected behavior in concurrent scenarios.

  3. Type handling: The function uses string comparison for type checking, which might be case-sensitive and error-prone.

Consider the following improvements:

  1. Enhance error handling:
try {
  // ... existing code ...
} catch (e: any) {
  console.error("Error in getFilterExpressionByFieldType:", e.message);
  // Consider throwing a custom error or returning a specific error value
  throw new Error(`Failed to generate filter expression: ${e.message}`);
}
  1. Avoid mutating global state:
const getStreamFieldTypes = (stream: any) => {
  if (!stream.schema) return {};
  return Object.fromEntries(stream.schema.map((schema: any) => [schema.name, schema.type]));
};

const fieldTypeList = searchObj.data.streamResults.list
  .filter((stream: any) => searchObj.data.stream.selectedStream.includes(stream.name))
  .reduce((acc: any, stream: any) => ({...acc, ...getStreamFieldTypes(stream)}), {});
  1. Use a more robust type checking mechanism:
const isNumericType = (type: string) => ['int64', 'float64'].includes(type.toLowerCase());
const isBooleanType = (type: string) => type.toLowerCase() === 'boolean';

// Then in your switch statement:
if (isNumericType(fieldType)) {
  expression = `${field} ${operator} ${field_value}`;
} else if (isBooleanType(fieldType)) {
  // ... existing boolean handling ...
}

These changes will make the function more robust, easier to maintain, and less prone to unexpected behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

suggestion considered and implemented

Copy link
Contributor

Choose a reason for hiding this comment

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

@bjp232004, glad to hear that you've considered and implemented the suggestion!

(\ (\
( ^.^)
o_(")(")


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!

Comment on lines 1015 to 1026
const addSearchTerm = (
field: string,
field_value: string | number | boolean,
action: string,
) => {
// searchObj.meta.showDetailTab = false;
searchObj.data.stream.addToFilter = term;
const expression = getFilterExpressionByFieldType(
field,
field_value,
action,
);
searchObj.data.stream.addToFilter = expression;
Copy link
Contributor

@coderabbitai coderabbitai bot Oct 19, 2024

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add Error Handling in addSearchTerm Function

Consider adding error handling to the addSearchTerm function to manage cases where getFilterExpressionByFieldType might return an undefined value or throw an error. This will enhance the robustness of the function.

You can apply this diff to include basic error handling:

const addSearchTerm = (
  field: string,
  field_value: string | number | boolean,
  action: string,
) => {
- // searchObj.meta.showDetailTab = false;
  const expression = getFilterExpressionByFieldType(
    field,
    field_value,
    action,
  );
+ if (expression) {
    searchObj.data.stream.addToFilter = expression;
+ } else {
+   console.error('Failed to generate filter expression');
+ }
};
📝 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
const addSearchTerm = (
field: string,
field_value: string | number | boolean,
action: string,
) => {
// searchObj.meta.showDetailTab = false;
searchObj.data.stream.addToFilter = term;
const expression = getFilterExpressionByFieldType(
field,
field_value,
action,
);
searchObj.data.stream.addToFilter = expression;
const addSearchTerm = (
field: string,
field_value: string | number | boolean,
action: string,
) => {
const expression = getFilterExpressionByFieldType(
field,
field_value,
action,
);
if (expression) {
searchObj.data.stream.addToFilter = expression;
} else {
console.error('Failed to generate filter expression');
}
};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

considered and fixed

Copy link
Contributor

Choose a reason for hiding this comment

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

@bjp232004 Thank you for addressing the issue! 🐰🎉


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!

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)
web/src/plugins/logs/IndexList.vue (1)

1015-1030: Improved search term handling with type-specific filtering

The addSearchTerm function has been refactored to use a new getFilterExpressionByFieldType function, which should provide more accurate filtering based on the field type. This is a good improvement for type-specific search capabilities.

However, there are a couple of points to consider:

  1. The error handling could be more informative.
  2. The function doesn't handle the case where expression is an empty string.

Consider enhancing the error handling and empty string case:

 const addSearchTerm = (
   field: string,
   field_value: string | number | boolean,
   action: string,
 ) => {
   const expression = getFilterExpressionByFieldType(
     field,
     field_value,
     action,
   );

-  if (expression) {
+  if (expression && expression.trim() !== '') {
     searchObj.data.stream.addToFilter = expression;
   } else {
-    console.error("Failed to generate filter expression");
+    console.error(`Failed to generate filter expression for field: ${field}, value: ${field_value}, action: ${action}`);
+    // Optionally, you could notify the user here
   }
 };
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 48ef66a and 177f174.

📒 Files selected for processing (3)
  • web/src/composables/useLogs.ts (4 hunks)
  • web/src/plugins/logs/IndexList.vue (4 hunks)
  • web/src/plugins/logs/JsonPreview.vue (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • web/src/composables/useLogs.ts
  • web/src/plugins/logs/JsonPreview.vue
🧰 Additional context used
🔇 Additional comments (3)
web/src/plugins/logs/IndexList.vue (3)

Line range hint 1-1452: Summary of changes and suggestions

The changes in this file primarily focus on improving the search functionality by introducing type-specific filtering through the getFilterExpressionByFieldType function. This is a positive enhancement that should provide more accurate search results.

Key points and suggestions:

  1. The addSearchTerm function has been refactored to use the new filtering method.
  2. Error handling in addSearchTerm could be improved to be more informative and handle empty expressions.
  3. Usage of addSearchTerm in the template seems correct, but parameter types should be verified.
  4. The implementation of getFilterExpressionByFieldType in the useLogs composable should be reviewed to ensure it handles all necessary field types correctly.

Overall, these changes appear to be a step in the right direction for improving search capabilities. Implementing the suggested refinements will further enhance the robustness of the search functionality.


705-705: Verify implementation of getFilterExpressionByFieldType

The getFilterExpressionByFieldType function is imported from the useLogs composable. Ensure that this function is properly implemented to handle different field types and generate appropriate filter expressions.

To verify the implementation of getFilterExpressionByFieldType, run the following script:

#!/bin/bash
# Description: Check the implementation of getFilterExpressionByFieldType in useLogs composable

# Test: Look for the getFilterExpressionByFieldType function definition
echo "Searching for getFilterExpressionByFieldType implementation:"
rg -A 20 'const getFilterExpressionByFieldType = ' src/composables/useLogs.ts

# Note: Adjust the file path if necessary

This will help ensure that the function is correctly implemented and handles various field types appropriately.


440-442: Verify parameters passed to addSearchTerm

The addSearchTerm function is correctly used in the template with the updated parameter list. However, ensure that props.row.name, value.key, and the action ('include' or 'exclude') are the correct types expected by the function.

To confirm the types of the passed parameters, you can run the following script:

Also applies to: 457-457

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 (2)
src/common/infra/wal.rs (2)

410-410: LGTM. Consider adding more context to the log message.

The addition of this log statement improves traceability for WAL file lock requests.

Consider including the number of files being locked in the log message for additional context:

log::info!("[trace_id {}] lock_request for {} wal files", trace_id, files.len());

Line range hint 419-419: LGTM. Consider adding more context and ensuring consistency with lock_request.

The addition of this log statement improves traceability for WAL file lock release requests.

For consistency with the lock_request function and to provide more context, consider modifying the log message as follows:

let files = locker.remove(trace_id);
log::info!("[trace_id {}] release_request for {} wal files", trace_id, files.as_ref().map_or(0, |f| f.len()));

This change adds the number of files being released to the log message, providing more context and maintaining consistency with the lock_request logging style.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 177f174 and aacc2e3.

📒 Files selected for processing (2)
  • src/common/infra/wal.rs (1 hunks)
  • src/job/files/parquet.rs (3 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/common/infra/wal.rs (1)

Pattern **/*.rs: You are a smart rustlang pull request reviewer.
You are going to review all the rustlang files.
Be concise, and add a brief explanation to your suggestions

Make sure the responses are not too verbose and keep the suggestions to the point i.e. actionable.

src/job/files/parquet.rs (1)

Pattern **/*.rs: You are a smart rustlang pull request reviewer.
You are going to review all the rustlang files.
Be concise, and add a brief explanation to your suggestions

Make sure the responses are not too verbose and keep the suggestions to the point i.e. actionable.

🔇 Additional comments (2)
src/common/infra/wal.rs (1)

410-410: Overall improvements in WAL operation logging

The changes in this file enhance the traceability of WAL (Write-Ahead Logging) file locking operations by adding logging statements to both lock_request and release_request functions. These additions will significantly improve debugging and monitoring capabilities without altering the core functionality of the WAL system.

Also applies to: 419-419

src/job/files/parquet.rs (1)

90-91: Appropriate addition of SKIPPED_LOCK_FILES

The static variable SKIPPED_LOCK_FILES is correctly declared to track files that are locked and should be skipped during processing.

Comment on lines 474 to 495
let mut need_skip = true;
// wait for 5s
for _ in 0..50 {
if wal::lock_files_exists(&file.key) {
log::warn!(
"[INGESTER:JOB:{thread_id}] the file is still in use, waiting for a few ms: {}",
file.key
);
time::sleep(time::Duration::from_millis(100)).await;
} else {
need_skip = false;
break;
}
}
if need_skip {
log::warn!(
"[INGESTER:JOB:{thread_id}] the file is still in use, add it to the skip_list: {}",
file.key
);
SKIPPED_LOCK_FILES.write().await.insert(file.key.clone());
continue;
}
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 using tokio::time::timeout for waiting

Instead of manually looping and sleeping to wait for the file to be released, you could use tokio::time::timeout to simplify the code and improve readability.

Apply this diff to refactor the waiting mechanism:

-let mut need_skip = true;
-// wait for 5s
-for _ in 0..50 {
-    if wal::lock_files_exists(&file.key) {
-        log::warn!(
-            "[INGESTER:JOB:{thread_id}] the file is still in use, waiting for a few ms: {}",
-            file.key
-        );
-        time::sleep(time::Duration::from_millis(100)).await;
-    } else {
-        need_skip = false;
-        break;
-    }
-}
-if need_skip {
+if let Err(_) = tokio::time::timeout(time::Duration::from_secs(5), async {
+    while wal::lock_files_exists(&file.key) {
+        log::warn!(
+            "[INGESTER:JOB:{thread_id}] the file is still in use, waiting: {}",
+            file.key
+        );
+        time::sleep(time::Duration::from_millis(100)).await;
+    }
+})
+.await
{
    log::warn!(
        "[INGESTER:JOB:{thread_id}] the file is still in use, add it to the skip_list: {}",
        file.key
    );
    SKIPPED_LOCK_FILES.write().await.insert(file.key.clone());
    continue;
}
📝 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
let mut need_skip = true;
// wait for 5s
for _ in 0..50 {
if wal::lock_files_exists(&file.key) {
log::warn!(
"[INGESTER:JOB:{thread_id}] the file is still in use, waiting for a few ms: {}",
file.key
);
time::sleep(time::Duration::from_millis(100)).await;
} else {
need_skip = false;
break;
}
}
if need_skip {
log::warn!(
"[INGESTER:JOB:{thread_id}] the file is still in use, add it to the skip_list: {}",
file.key
);
SKIPPED_LOCK_FILES.write().await.insert(file.key.clone());
continue;
}
if let Err(_) = tokio::time::timeout(time::Duration::from_secs(5), async {
while wal::lock_files_exists(&file.key) {
log::warn!(
"[INGESTER:JOB:{thread_id}] the file is still in use, waiting: {}",
file.key
);
time::sleep(time::Duration::from_millis(100)).await;
}
})
.await
{
log::warn!(
"[INGESTER:JOB:{thread_id}] the file is still in use, add it to the skip_list: {}",
file.key
);
SKIPPED_LOCK_FILES.write().await.insert(file.key.clone());
continue;
}

Comment on lines 226 to 245
// check if the file is still locking
if SKIPPED_LOCK_FILES.read().await.contains(&file_key)
&& !wal::lock_files_exists(&file_key)
{
log::warn!(
"[INGESTER:JOB] the file was released, delete it: {}",
file_key
);
if tokio::fs::remove_file(&wal_dir.join(&file_key))
.await
.is_ok()
{
// delete metadata from cache
WAL_PARQUET_METADATA.write().await.remove(&file_key);
// need release all the files
PROCESSING_FILES.write().await.remove(&file_key);
// delete from skip list
SKIPPED_LOCK_FILES.write().await.remove(&file_key);
}
}
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

Handle potential errors when removing files

When attempting to remove the file with tokio::fs::remove_file, consider handling the Err case to log any errors that might occur during file deletion. This ensures that any issues are not silently ignored.

Apply this diff to handle the error:

if tokio::fs::remove_file(&wal_dir.join(&file_key))
    .await
    .is_ok()
{
    // existing code...
} else {
    log::error!(
        "[INGESTER:JOB] Failed to remove file: {}",
        file_key
    );
}
📝 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
// check if the file is still locking
if SKIPPED_LOCK_FILES.read().await.contains(&file_key)
&& !wal::lock_files_exists(&file_key)
{
log::warn!(
"[INGESTER:JOB] the file was released, delete it: {}",
file_key
);
if tokio::fs::remove_file(&wal_dir.join(&file_key))
.await
.is_ok()
{
// delete metadata from cache
WAL_PARQUET_METADATA.write().await.remove(&file_key);
// need release all the files
PROCESSING_FILES.write().await.remove(&file_key);
// delete from skip list
SKIPPED_LOCK_FILES.write().await.remove(&file_key);
}
}
// check if the file is still locking
if SKIPPED_LOCK_FILES.read().await.contains(&file_key)
&& !wal::lock_files_exists(&file_key)
{
log::warn!(
"[INGESTER:JOB] the file was released, delete it: {}",
file_key
);
if tokio::fs::remove_file(&wal_dir.join(&file_key))
.await
.is_ok()
{
// delete metadata from cache
WAL_PARQUET_METADATA.write().await.remove(&file_key);
// need release all the files
PROCESSING_FILES.write().await.remove(&file_key);
// delete from skip list
SKIPPED_LOCK_FILES.write().await.remove(&file_key);
} else {
log::error!(
"[INGESTER:JOB] Failed to remove file: {}",
file_key
);
}
}

@bjp232004 bjp232004 force-pushed the 4033-interacting-with-boolean-data-causes-queries-to-become-unresponsive branch from aacc2e3 to 9c7a6b0 Compare October 21, 2024 10:22
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 (2)
web/src/composables/useLogs.ts (2)

2709-2709: Remove debugging console.log statement.

This console.log statement appears to be a debugging artifact. It's generally a good practice to remove such statements before committing code to production.

- console.log("stream", stream)

4236-4297: Approve implementation with suggestions for improvement.

The getFilterExpressionByFieldType function is a valuable addition for constructing type-specific filter expressions. Here are some suggestions for improvement:

  1. Consider using a type union for the field_value parameter instead of separate types.
  2. The fieldType variable could be initialized with a more specific type.
  3. Consider using a switch statement for better readability when handling different field types.

Here's a refactored version incorporating these suggestions:

const getFilterExpressionByFieldType = (
  field: string | number,
  field_value: string | number | boolean | null,
  action: 'include' | 'exclude'
): string => {
  let operator = action === 'include' ? '=' : '!=';
  try {
    let fieldType: 'utf8' | 'int64' | 'float64' | 'boolean' = 'utf8';

    // ... (rest of the code remains the same until the type checking)

    switch (true) {
      case field_value === null || field_value === '':
        operator = action === 'include' ? 'is' : 'is not';
        return `${field} ${operator} null`;
      case isNumericType(fieldType):
        return `${field} ${operator} ${field_value}`;
      case isBooleanType(fieldType):
        operator = action === 'include' ? 'is' : 'is not';
        return `${field} ${operator} ${field_value}`;
      default:
        return `${field} ${operator} '${field_value}'`;
    }
  } catch (e: any) {
    console.error("Error in getFilterExpressionByFieldType:", e.message);
    return `${field} ${operator} '${field_value}'`;
  }
};
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between aacc2e3 and 9c7a6b0.

📒 Files selected for processing (7)
  • web/src/composables/useLogs.ts (4 hunks)
  • web/src/plugins/logs/DetailTable.vue (3 hunks)
  • web/src/plugins/logs/IndexList.vue (4 hunks)
  • web/src/plugins/logs/JsonPreview.vue (3 hunks)
  • web/src/plugins/logs/SearchResult.vue (2 hunks)
  • web/src/plugins/logs/TenstackTable.vue (1 hunks)
  • web/src/plugins/logs/data-table/CellActions.vue (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • web/src/plugins/logs/DetailTable.vue
  • web/src/plugins/logs/JsonPreview.vue
  • web/src/plugins/logs/data-table/CellActions.vue
🧰 Additional context used
🔇 Additional comments (8)
web/src/plugins/logs/IndexList.vue (3)

440-442: Improved search term addition flexibility

The addSearchTerm method has been updated to accept three parameters (field, value, and action) instead of a single term. This change enhances the flexibility and precision of the search functionality, allowing for more specific include/exclude operations.

Also applies to: 457-457


1015-1040: Enhanced addSearchTerm function with improved type handling and error management

The addSearchTerm function has been significantly improved:

  1. It now uses getFilterExpressionByFieldType to generate filter expressions based on the field type, improving type safety and flexibility.
  2. Error handling has been added to notify users when filter expression generation fails.

These changes enhance the robustness and user-friendliness of the search functionality.


705-705: Improved code organization with getFilterExpressionByFieldType

The getFilterExpressionByFieldType function has been added to the imported functions from the useLogs composable. This change improves code organization by centralizing the filter expression generation logic, making it reusable across different components.

web/src/composables/useLogs.ts (1)

4340-4340: Approve addition of getFilterExpressionByFieldType to the return object.

The inclusion of getFilterExpressionByFieldType in the return object of the useLogs composable is correct. This makes the new function accessible to components that use this composable, allowing them to generate filter expressions based on field types.

web/src/plugins/logs/TenstackTable.vue (1)

623-628: LGTM!

The addSearchTerm function has been updated correctly to accept the new parameters and emit the event accordingly.

web/src/plugins/logs/SearchResult.vue (3)

384-384: Import getFilterExpressionByFieldType is properly added

The function getFilterExpressionByFieldType is now imported from useLogs(). This ensures that it can be used within this component.


Line range hint 579-586: Ensure consistency in method calls within TenstackTable component

In the <tenstack-table> component, there is an event listener for @add-search-term="addSearchTerm". Verify that the emitted event provides the necessary parameters to addSearchTerm based on its new signature.

Run the following script to locate and review the event emissions for add-search-term:

#!/bin/bash
# Description: Find all emissions of the `add-search-term` event and display their arguments.

rg "@add-search-term" -A 5 -B 5

Line range hint 523-535: Update event emission in <DetailTable> component

In the <DetailTable> component within the template, the event names have been updated to match the new addSearchTerm function signature:

@add:searchterm="addSearchTerm"
@remove:searchterm="removeSearchTerm"

Ensure that these events emit the correct parameters (field, field_value, action) to align with the updated addSearchTerm function.

Run the following script to inspect the event emissions related to add:searchterm:

#!/bin/bash
# Description: Find all emissions of the `add:searchterm` event and display their arguments.

rg "@add:searchterm" -A 5 -B 5

Comment on lines 250 to 251
const selectedStreamFieldType:any = {};

Copy link
Contributor

@coderabbitai coderabbitai bot Oct 21, 2024

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider using a more specific type for selectedStreamFieldType.

Instead of using any, consider defining a more specific type or interface for selectedStreamFieldType. This would improve type safety and make the code more self-documenting.

interface StreamFieldTypes {
  [fieldName: string]: string;
}

const selectedStreamFieldType: StreamFieldTypes = {};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

code removed

Copy link
Contributor

Choose a reason for hiding this comment

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

@bjp232004, understood. Since selectedStreamFieldType has been removed, the previous suggestion is no longer applicable.

(ಥ﹏ಥ)


✏️ Learnings added
Learnt from: bjp232004
PR: openobserve/openobserve#4841
File: web/src/composables/useLogs.ts:0-0
Timestamp: 2024-10-21T11:15:45.924Z
Learning: In `web/src/composables/useLogs.ts`, the variable `selectedStreamFieldType` has been removed.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Comment on lines +445 to +455
const addSearchTerm = (
field: string | number,
field_value: string | number | boolean,
action: string,
) => {
const searchExpression = getFilterExpressionByFieldType(
field,
field_value,
action,
);
searchObj.data.stream.addToFilter = searchExpression;
Copy link
Contributor

@coderabbitai coderabbitai bot Oct 21, 2024

Choose a reason for hiding this comment

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

💡 Codebase verification

Verification of addSearchTerm Updates Needed

Several calls to addSearchTerm do not match the updated function signature and need to be reviewed:

  • BasicValuesFilter.vue

    • addSearchTerm(${row.name}='${value.key}')
    • addSearchTerm(${row.name}!='${value.key}')
  • FieldList.vue

    • addSearchTerm(${props.row.name}='')
    • addSearchTerm(${props.row.name}='${value.key}')
    • addSearchTerm(${props.row.name}!='${value.key}')
  • SearchBar.vue and rum/SearchBar.vue

    • addSearchTerm is defined as a method and may require alignment with the new signature.

Please update these instances to match the new addSearchTerm function signature.

🔗 Analysis chain

Update addSearchTerm function signature and implementation

The addSearchTerm function has been updated to accept field, field_value, and action parameters. It now constructs the search expression using getFilterExpressionByFieldType and assigns it to searchObj.data.stream.addToFilter. This implementation appears correct.

However, please verify that all calls to addSearchTerm within this component and other components have been updated to match the new signature.

Run the following script to find usages of addSearchTerm and check their parameters:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all calls to `addSearchTerm` and display their parameter lists.

# Search for all occurrences of `addSearchTerm(` and display the lines with context.
rg --glob '!SearchResult.vue' 'addSearchTerm\(' -A 1 -B 1

Length of output: 1124


Script:

#!/bin/bash
# Description: Correctly find all calls to `addSearchTerm` and display their parameter lists, excluding SearchResult.vue.

rg --glob '!web/src/plugins/logs/SearchResult.vue' 'addSearchTerm\(' -A 1 -B 1

Length of output: 4830


Script:

#!/bin/bash
# Description: Find all calls to `addSearchTerm` and display their parameter lists, excluding SearchResult.vue.

rg --glob '!web/src/plugins/logs/SearchResult.vue' 'addSearchTerm\(' -A 1 -B 1

Length of output: 4830

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not required.

Copy link
Contributor

Choose a reason for hiding this comment

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

@bjp232004, understood. Thank you for the clarification.

(;へ:)


✏️ Learnings added
Learnt from: bjp232004
PR: openobserve/openobserve#4841
File: web/src/plugins/logs/SearchResult.vue:445-455
Timestamp: 2024-10-21T11:16:45.535Z
Learning: In the OpenObserve project, changes to the `addSearchTerm` function's signature in `web/src/plugins/logs/SearchResult.vue` do not require updating its usage in other components such as `BasicValuesFilter.vue`, `FieldList.vue`, or `SearchBar.vue`.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

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)
web/src/composables/useLogs.ts (1)

4234-4295: New function getFilterExpressionByFieldType added

A new function getFilterExpressionByFieldType has been implemented to generate filter expressions based on field types. This function enhances the flexibility of query building by considering the data type of fields when constructing filter expressions.

Key points:

  1. The function handles different data types (numeric, boolean, and string).
  2. It includes special handling for null values.
  3. It dynamically determines the field type based on the stream schema.
  4. The function uses a more robust type checking mechanism with isNumericType and isBooleanType helper functions.

Suggestions for improvement:

  1. Consider adding input validation for the action parameter to ensure it's either "include" or "exclude".
  2. The error handling could be more specific, logging the exact nature of the error rather than a generic message.

Consider the following improvements:

  1. Add input validation:
if (action !== "include" && action !== "exclude") {
  throw new Error("Invalid action. Must be either 'include' or 'exclude'.");
}
  1. Enhance error logging:
} catch (e: any) {
  console.error("Error in getFilterExpressionByFieldType:", e.message);
  console.error("Inputs:", { field, field_value, action });
  return `${field} ${operator} '${field_value}'`;
}

These changes will make the function more robust and easier to debug.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 9c7a6b0 and 3e911f4.

📒 Files selected for processing (3)
  • web/src/composables/useLogs.ts (3 hunks)
  • web/src/plugins/logs/DetailTable.vue (3 hunks)
  • web/src/plugins/logs/IndexList.vue (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • web/src/plugins/logs/DetailTable.vue
🧰 Additional context used
📓 Learnings (1)
web/src/plugins/logs/IndexList.vue (1)
Learnt from: bjp232004
PR: openobserve/openobserve#4841
File: web/src/plugins/logs/SearchResult.vue:445-455
Timestamp: 2024-10-21T11:16:45.923Z
Learning: In the OpenObserve project, changes to the `addSearchTerm` function's signature in `web/src/plugins/logs/SearchResult.vue` do not require updating its usage in other components such as `BasicValuesFilter.vue`, `FieldList.vue`, or `SearchBar.vue`.
🔇 Additional comments (4)
web/src/plugins/logs/IndexList.vue (2)

1015-1034: Improved addSearchTerm function with better flexibility and error handling.

The changes to the addSearchTerm function are well-implemented:

  1. The new function signature with field, field_value, and action parameters allows for more precise and flexible search term addition.
  2. The use of getFilterExpressionByFieldType suggests a more type-aware approach to generating filter expressions.
  3. The added error handling with user notification improves the robustness of the function.

These changes should lead to a more reliable and user-friendly search experience.


440-442: Correct usage of the updated addSearchTerm function.

The calls to addSearchTerm have been properly updated to match its new signature:

  1. Line 440-442: addSearchTerm(props.row.name, value.key, 'include')
  2. Line 457: addSearchTerm(props.row.name,value.key, 'exclude')

These changes correctly implement the new function signature, passing the field name, value, and action (include/exclude) as separate parameters.

Also applies to: 457-457

web/src/composables/useLogs.ts (2)

4338-4338: Updated return statement to include new function

The getFilterExpressionByFieldType function has been added to the return statement of the useLogs composable. This makes the function available for use by components that import this composable.

This change is correct and necessary to expose the new functionality.


Line range hint 1-4339: Summary of changes

The main modification to this file is the addition of the getFilterExpressionByFieldType function, which enhances the log querying capabilities by generating type-specific filter expressions. This function has been properly integrated into the useLogs composable by including it in the return statement.

The implementation is solid, with room for minor improvements in error handling and input validation. Overall, these changes should positively impact the flexibility and accuracy of log filtering operations in the application.

@bjp232004 bjp232004 force-pushed the 4033-interacting-with-boolean-data-causes-queries-to-become-unresponsive branch from 3e911f4 to 7d99dfa Compare October 21, 2024 11:21
@bjp232004 bjp232004 merged commit f13f557 into main Oct 21, 2024
@bjp232004 bjp232004 deleted the 4033-interacting-with-boolean-data-causes-queries-to-become-unresponsive branch October 21, 2024 11:44
@coderabbitai coderabbitai bot mentioned this pull request Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

☢️ Bug Something isn't working

Projects

None yet

2 participants