Skip to content

Conversation

@bjp232004
Copy link
Contributor

@bjp232004 bjp232004 commented May 28, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced SQL query manipulation and result processing in the logs functionality.
    • Improved handling of aggregation flags in the logs.
  • Bug Fixes

    • Adjusted logic for calculating total query results to ensure accurate data representation.
  • Tests

    • Added UI tests for resetting filters, refreshing the page, and interacting with elements in SQL mode.
  • Chores

    • Commented out loadLogsData() function call in the logs module to optimize performance.

@github-actions github-actions bot added the ☢️ Bug Something isn't working label May 28, 2024
@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 28, 2024

Walkthrough

The recent changes involve enhancements to the useLogs function for better SQL query manipulation and result processing, updates to UI testing scripts to include additional interactions, and a minor adjustment in the Index.vue file to conditionally comment out a function call. These modifications aim to improve data handling, testing robustness, and conditional loading of logs data.

Changes

Files/Modules Change Summary
web/src/composables/useLogs.ts Enhanced useLogs function for SQL parsing, result processing, and aggregation flag handling. Added fnHistogramParsedSQL function.
tests/ui-testing/playwright-tests/sanity.spec.js Added interactions for resetting filters, refreshing page, and displaying results in SQL mode.
web/src/plugins/logs/Index.vue Commented out loadLogsData() function call within a conditional block.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant User
    participant UI as User Interface
    participant LogsComposable as useLogs
    participant SQLParser as fnHistogramParsedSQL

    User ->> UI: Interact with Logs UI
    UI ->> LogsComposable: Call useLogs function
    LogsComposable ->> SQLParser: Parse SQL query
    SQLParser -->> LogsComposable: Return parsed results
    LogsComposable ->> UI: Return processed logs data
    UI -->> User: Display logs data
Loading

This diagram illustrates the high-level interaction between the user interface, the useLogs function, and the fnHistogramParsedSQL function for handling SQL query parsing and logs data processing.


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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)
tests/ui-testing/playwright-tests/sanity.spec.js (2)

Line range hint 3-3: Consider using the node: protocol when importing Node.js built-in modules for clarity and to avoid potential resolution issues in different environments.

- import { log } from "console";
+ import { log } from "node:console";

Line range hint 10-10: Simplify the computed expressions by removing unnecessary string literals.

- const folderName = `Folder ${Date.now()}`
+ const folderName = 'Folder' + Date.now()

Also applies to: 15-15, 20-20, 63-63, 66-66, 70-70, 97-97

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

Line range hint 128-128: Specify more precise types instead of any.

The use of any type is found extensively throughout the useLogs function. Using any bypasses TypeScript's type checking, which can lead to runtime errors. Where possible, replace any with more specific types to enhance code reliability and maintainability.

Also applies to: 129-129, 139-139, 143-143, 146-146, 151-151, 153-153, 154-154, 155-155, 156-156, 157-157, 169-169, 170-170, 175-175, 176-176, 186-186, 187-187, 223-223, 235-235, 236-236

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 83305a2 and e593e65.
Files selected for processing (2)
  • tests/ui-testing/playwright-tests/sanity.spec.js (2 hunks)
  • web/src/composables/useLogs.ts (3 hunks)
Additional Context Used
Biome (30)
tests/ui-testing/playwright-tests/sanity.spec.js (10)

3-3: A Node.js builtin module should be imported with the node: protocol.


10-10: The computed expression can be simplified without the use of a string literal.


15-15: The computed expression can be simplified without the use of a string literal.


20-20: The computed expression can be simplified without the use of a string literal.


37-37: Unexpected control character(s) in regular expression: \x00


63-63: The computed expression can be simplified without the use of a string literal.


66-66: The computed expression can be simplified without the use of a string literal.


66-66: The computed expression can be simplified without the use of a string literal.


70-70: The computed expression can be simplified without the use of a string literal.


97-97: The computed expression can be simplified without the use of a string literal.

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

128-128: Unexpected any. Specify a different type.


129-129: Unexpected any. Specify a different type.


139-139: Unexpected any. Specify a different type.


143-143: Unexpected any. Specify a different type.


146-146: Unexpected any. Specify a different type.


151-151: Unexpected any. Specify a different type.


153-153: Unexpected any. Specify a different type.


154-154: Unexpected any. Specify a different type.


155-155: Unexpected any. Specify a different type.


156-156: Unexpected any. Specify a different type.


157-157: Unexpected any. Specify a different type.


169-169: Unexpected any. Specify a different type.


170-170: Unexpected any. Specify a different type.


175-175: Unexpected any. Specify a different type.


176-176: Unexpected any. Specify a different type.


186-186: Unexpected any. Specify a different type.


187-187: Unexpected any. Specify a different type.


223-223: Unexpected any. Specify a different type.


235-235: Unexpected any. Specify a different type.


236-236: Unexpected any. Specify a different type.

Additional comments not posted (3)
tests/ui-testing/playwright-tests/sanity.spec.js (3)

Line range hint 37-37: The regular expression used to remove UTF characters might include unexpected control characters. Ensure the regex pattern is correctly specified.

Verification successful

The regex pattern [^\x00-\x7F] correctly matches non-ASCII characters, including control characters outside the ASCII range (0x80 to 0x9F). This confirms that the pattern is functioning as intended and does not inadvertently include unexpected control characters.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the regex pattern for removing UTF characters.
echo "Testing regex pattern..."
echo "Sample text with special characters: ñ, é, ü" | grep -P "[^\x00-\x7F]"

Length of output: 182



Script:

#!/bin/bash
# Description: Verify the regex pattern for removing UTF characters, including control characters outside the ASCII range.
echo "Testing regex pattern with control characters outside ASCII range..."
# Create a string with control characters outside the ASCII range (0x80 to 0x9F)
control_chars=$(printf '\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F')
echo "Control characters: $control_chars" | grep -P "[^\x00-\x7F]"

Length of output: 575


195-198: Ensure that the reset and refresh interactions are functioning as intended, especially since these are new additions according to the PR summary.

Verification successful

The locators for the reset and refresh buttons are correctly identified and interacted with in the test file. The interactions are present at the specified lines, confirming that the buttons are being clicked as intended.

  • Line 195: Reset button interaction
  • Line 197: Refresh button interaction
  • Additional refresh button interactions at lines 202 and 433
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the reset and refresh button functionality in the UI.
echo "Manual verification needed: Check the reset and refresh interactions on the UI."

Length of output: 168



Script:

#!/bin/bash
# Search for the reset button interaction in the test file
ast-grep --lang javascript --pattern $'await page.locator(\'[data-test="logs-search-bar-reset-filters-btn"]\').click()' tests/ui-testing/playwright-tests/sanity.spec.js

# Search for the refresh button interaction in the test file
ast-grep --lang javascript --pattern $'await page.locator(\'[data-test="logs-search-bar-refresh-btn"]\').click()' tests/ui-testing/playwright-tests/sanity.spec.js

Length of output: 859


425-444: The new interactions to display the histogram in SQL mode seem to be implemented correctly. However, ensure that the histogram displays accurately and that no errors are thrown when toggling SQL mode.

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

Line range hint 128-128: Replace any type with more specific types to improve type safety.

- let parser: any;
+ let parser: SQLParserType; // Assuming SQLParserType is the correct type

- const fieldValues = ref();
+ const fieldValues = ref<FieldValueType>(); // Replace FieldValueType with the actual type

// Apply similar changes to all other instances where `any` is used.

Also applies to: 129-129, 139-139, 143-143, 146-146, 151-151, 153-153, 154-154, 155-155, 156-156, 157-157, 169-169, 170-170, 175-175, 176-176, 186-186, 187-187, 223-223, 235-235, 236-236

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between e593e65 and e0d64df.
Files selected for processing (1)
  • web/src/composables/useLogs.ts (9 hunks)
Additional Context Used
Biome (20)
web/src/composables/useLogs.ts (20)

128-128: Unexpected any. Specify a different type.


129-129: Unexpected any. Specify a different type.


139-139: Unexpected any. Specify a different type.


143-143: Unexpected any. Specify a different type.


146-146: Unexpected any. Specify a different type.


151-151: Unexpected any. Specify a different type.


153-153: Unexpected any. Specify a different type.


154-154: Unexpected any. Specify a different type.


155-155: Unexpected any. Specify a different type.


156-156: Unexpected any. Specify a different type.


157-157: Unexpected any. Specify a different type.


169-169: Unexpected any. Specify a different type.


170-170: Unexpected any. Specify a different type.


175-175: Unexpected any. Specify a different type.


176-176: Unexpected any. Specify a different type.


186-186: Unexpected any. Specify a different type.


187-187: Unexpected any. Specify a different type.


223-223: Unexpected any. Specify a different type.


235-235: Unexpected any. Specify a different type.


236-236: Unexpected any. Specify a different type.

Additional comments not posted (3)
web/src/composables/useLogs.ts (3)

632-647: Refactor SQL manipulation to use helper functions.


1407-1423: Introduce error handling in fnHistogramParsedSQL.


826-826: Ensure proper handling of non-aggregated queries.

Comment on lines +632 to +647
req.aggs.histogram = req.aggs.histogram.replace(
"[INDEX_NAME]",
searchObj.data.stream.selectedStream.value
);

req.aggs.histogram = req.aggs.histogram.replace("[WHERE_CLAUSE]", "");

searchObj.data.query = query;
const parsedSQL: any = fnParsedSQL();
const histogramParsedSQL: any = fnHistogramParsedSQL(req.aggs.histogram);

histogramParsedSQL.where = parsedSQL.where;

let histogramQuery = parser.sqlify(histogramParsedSQL)
histogramQuery = histogramQuery.replace(/`/g, '"');
req.aggs.histogram = histogramQuery;
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactor complex SQL string manipulations in buildSearch.

- req.aggs.histogram = req.aggs.histogram.replace("[INDEX_NAME]", searchObj.data.stream.selectedStream.value);
- req.aggs.histogram = req.aggs.histogram.replace("[WHERE_CLAUSE]", "");
+ req.aggs.histogram = replaceIndexName(req.aggs.histogram, searchObj.data.stream.selectedStream.value);
+ req.aggs.histogram = replaceWhereClause(req.aggs.histogram, "");

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.

Suggested change
req.aggs.histogram = req.aggs.histogram.replace(
"[INDEX_NAME]",
searchObj.data.stream.selectedStream.value
);
req.aggs.histogram = req.aggs.histogram.replace("[WHERE_CLAUSE]", "");
searchObj.data.query = query;
const parsedSQL: any = fnParsedSQL();
const histogramParsedSQL: any = fnHistogramParsedSQL(req.aggs.histogram);
histogramParsedSQL.where = parsedSQL.where;
let histogramQuery = parser.sqlify(histogramParsedSQL)
histogramQuery = histogramQuery.replace(/`/g, '"');
req.aggs.histogram = histogramQuery;
req.aggs.histogram = replaceIndexName(req.aggs.histogram, searchObj.data.stream.selectedStream.value);
req.aggs.histogram = replaceWhereClause(req.aggs.histogram, "");
searchObj.data.query = query;
const parsedSQL: any = fnParsedSQL();
const histogramParsedSQL: any = fnHistogramParsedSQL(req.aggs.histogram);
histogramParsedSQL.where = parsedSQL.where;
let histogramQuery = parser.sqlify(histogramParsedSQL)
histogramQuery = histogramQuery.replace(/`/g, '"');
req.aggs.histogram = histogramQuery;

@bjp232004 bjp232004 force-pushed the sql-mode-histogram-error branch from f4ec88f to a1be890 Compare May 29, 2024 07:04
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)
tests/ui-testing/playwright-tests/sanity.spec.js (1)

Line range hint 3-3: Consider using the node: protocol when importing Node.js built-in modules for clarity and to avoid potential issues with module resolution.

- import { log } from "console";
+ import { log } from "node:console";
web/src/composables/useLogs.ts (1)

Line range hint 128-128: Consider replacing any type with more specific types to improve type safety and code maintainability.

Also applies to: 129-129, 139-139, 143-143, 146-146, 151-151, 153-153, 154-154, 155-155, 156-156, 157-157, 169-169, 170-170, 175-175, 176-176, 186-186, 187-187, 223-223, 235-235, 236-236

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between e0d64df and a1be890.
Files selected for processing (3)
  • tests/ui-testing/playwright-tests/sanity.spec.js (2 hunks)
  • web/src/composables/useLogs.ts (10 hunks)
  • web/src/plugins/logs/Index.vue (1 hunks)
Additional Context Used
Biome (30)
tests/ui-testing/playwright-tests/sanity.spec.js (10)

3-3: A Node.js builtin module should be imported with the node: protocol.


10-10: The computed expression can be simplified without the use of a string literal.


15-15: The computed expression can be simplified without the use of a string literal.


20-20: The computed expression can be simplified without the use of a string literal.


37-37: Unexpected control character(s) in regular expression: \x00


63-63: The computed expression can be simplified without the use of a string literal.


66-66: The computed expression can be simplified without the use of a string literal.


66-66: The computed expression can be simplified without the use of a string literal.


70-70: The computed expression can be simplified without the use of a string literal.


97-97: The computed expression can be simplified without the use of a string literal.

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

128-128: Unexpected any. Specify a different type.


129-129: Unexpected any. Specify a different type.


139-139: Unexpected any. Specify a different type.


143-143: Unexpected any. Specify a different type.


146-146: Unexpected any. Specify a different type.


151-151: Unexpected any. Specify a different type.


153-153: Unexpected any. Specify a different type.


154-154: Unexpected any. Specify a different type.


155-155: Unexpected any. Specify a different type.


156-156: Unexpected any. Specify a different type.


157-157: Unexpected any. Specify a different type.


169-169: Unexpected any. Specify a different type.


170-170: Unexpected any. Specify a different type.


175-175: Unexpected any. Specify a different type.


176-176: Unexpected any. Specify a different type.


186-186: Unexpected any. Specify a different type.


187-187: Unexpected any. Specify a different type.


223-223: Unexpected any. Specify a different type.


235-235: Unexpected any. Specify a different type.


236-236: Unexpected any. Specify a different type.

Additional comments not posted (5)
tests/ui-testing/playwright-tests/sanity.spec.js (2)

448-467: Ensure that the histogram displays correctly in SQL mode and handles errors gracefully.


196-199: Ensure proper refresh and reset functionality.

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

432-432: Clarify the impact of commenting out loadLogsData() on the application's behavior.

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

632-647: Refactor complex SQL string manipulations in buildSearch.

- req.aggs.histogram = req.aggs.histogram.replace("[INDEX_NAME]", searchObj.data.stream.selectedStream.value);
- req.aggs.histogram = req.aggs.histogram.replace("[WHERE_CLAUSE]", "");
+ req.aggs.histogram = replaceIndexName(req.aggs.histogram, searchObj.data.stream.selectedStream.value);
+ req.aggs.histogram = replaceWhereClause(req.aggs.histogram, "");

1407-1423: Optimize SQL parsing in fnHistogramParsedSQL.

- const filteredQuery = query
-   .split("\n")
-   .filter((line: string) => !line.trim().startsWith("--"))
-   .join("\n");
+ const filteredQuery = query.replace(/^--.*$/gm, ''); // Use regex to remove comments more efficiently

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

Line range hint 128-236: Consider replacing any type with more specific types to improve type safety.

- let parser: any;
+ let parser: SQLParserType; // Assuming SQLParserType is the correct type, replace with actual type if different

- const fieldValues = ref();
+ const fieldValues = ref<FieldType[]>(); // Replace FieldType with the actual expected type

- const initialQueryPayload: Ref<LogsQueryPayload | null> = ref(null);
+ const initialQueryPayload: Ref<LogsQueryPayload> = ref(); // Specify the type directly in the ref declaration

// Apply similar changes to other instances where `any` is used.

Consider defining specific types for variables currently typed as any. This will enhance the code's type safety and maintainability, making it easier to understand and less prone to runtime errors.

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between a1be890 and 8599a1b.
Files selected for processing (2)
  • tests/ui-testing/playwright-tests/sanity.spec.js (3 hunks)
  • web/src/composables/useLogs.ts (10 hunks)
Additional Context Used
Biome (30)
tests/ui-testing/playwright-tests/sanity.spec.js (10)

3-3: A Node.js builtin module should be imported with the node: protocol.


10-10: The computed expression can be simplified without the use of a string literal.


15-15: The computed expression can be simplified without the use of a string literal.


20-20: The computed expression can be simplified without the use of a string literal.


37-37: Unexpected control character(s) in regular expression: \x00


63-63: The computed expression can be simplified without the use of a string literal.


66-66: The computed expression can be simplified without the use of a string literal.


66-66: The computed expression can be simplified without the use of a string literal.


70-70: The computed expression can be simplified without the use of a string literal.


97-97: The computed expression can be simplified without the use of a string literal.

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

128-128: Unexpected any. Specify a different type.


129-129: Unexpected any. Specify a different type.


139-139: Unexpected any. Specify a different type.


143-143: Unexpected any. Specify a different type.


146-146: Unexpected any. Specify a different type.


151-151: Unexpected any. Specify a different type.


153-153: Unexpected any. Specify a different type.


154-154: Unexpected any. Specify a different type.


155-155: Unexpected any. Specify a different type.


156-156: Unexpected any. Specify a different type.


157-157: Unexpected any. Specify a different type.


169-169: Unexpected any. Specify a different type.


170-170: Unexpected any. Specify a different type.


175-175: Unexpected any. Specify a different type.


176-176: Unexpected any. Specify a different type.


186-186: Unexpected any. Specify a different type.


187-187: Unexpected any. Specify a different type.


223-223: Unexpected any. Specify a different type.


235-235: Unexpected any. Specify a different type.


236-236: Unexpected any. Specify a different type.

Additional comments not posted (3)
tests/ui-testing/playwright-tests/sanity.spec.js (1)

196-199: Ensure consistent use of UI interactions.

Verification successful

The verification process has shown that interactions involving the reset filters button and the refresh button are used consistently across different tests. The specific interactions in the sanity.spec.js file align with similar interactions found in other test files.

  • Interactions with the reset filters button were found only in sanity.spec.js.
  • Interactions with the refresh button were found in multiple test files, including sanity.spec.js, functions.spec.js, variable.spec.js, region.spec.js, reports.spec.js, logsquickmode.spec.js, pipeline.spec.js, logsqueries.spec.js, indexquery.spec.js, logspage.spec.js, dashboardtype.spec.js, alerts.spec.js, and schema.spec.js.

This consistency indicates that the UI interactions for resetting filters and refreshing the page are uniformly implemented across the test suite.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the interactions for resetting filters and refreshing the page are consistent across different tests.

# Test: Search for similar interactions in other tests. Expect: Consistent usage.
rg --type js $'page.locator.*click.*refresh'

Length of output: 45



Script:

#!/bin/bash
# Description: Verify that the interactions for resetting filters and refreshing the page are consistent across different tests.

# Test: Search for interactions involving the reset filters button.
rg --type js 'page.locator.*reset-filters.*click'

# Test: Search for interactions involving the refresh button.
rg --type js 'page.locator.*refresh.*click'

Length of output: 5153

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

632-647: Refactor complex SQL string manipulations in buildSearch.


1407-1423: Optimize SQL parsing in fnHistogramParsedSQL.

@bjp232004 bjp232004 force-pushed the sql-mode-histogram-error branch from ba8a83e to 8d66728 Compare May 29, 2024 09:04
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)
tests/ui-testing/playwright-tests/sanity.spec.js (2)

Line range hint 3-3: Consider using the node: protocol when importing Node.js built-in modules.

- import { log } from "console";
+ import { log } from "node:console";

Line range hint 37-37: Remove unexpected control characters in the regular expression.

- return text.replace(/[^\x00-\x7F]/g, " ");
+ return text.replace(/[^\x00-\x7F]/g, ""); // Removed the space in the replacement string
Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 8599a1b and ba8a83e.
Files selected for processing (2)
  • tests/ui-testing/playwright-tests/sanity.spec.js (3 hunks)
  • web/src/composables/useLogs.ts (11 hunks)
Additional Context Used
Biome (30)
tests/ui-testing/playwright-tests/sanity.spec.js (10)

3-3: A Node.js builtin module should be imported with the node: protocol.


10-10: The computed expression can be simplified without the use of a string literal.


15-15: The computed expression can be simplified without the use of a string literal.


20-20: The computed expression can be simplified without the use of a string literal.


37-37: Unexpected control character(s) in regular expression: \x00


63-63: The computed expression can be simplified without the use of a string literal.


66-66: The computed expression can be simplified without the use of a string literal.


66-66: The computed expression can be simplified without the use of a string literal.


70-70: The computed expression can be simplified without the use of a string literal.


97-97: The computed expression can be simplified without the use of a string literal.

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

128-128: Unexpected any. Specify a different type.


129-129: Unexpected any. Specify a different type.


139-139: Unexpected any. Specify a different type.


143-143: Unexpected any. Specify a different type.


146-146: Unexpected any. Specify a different type.


151-151: Unexpected any. Specify a different type.


153-153: Unexpected any. Specify a different type.


154-154: Unexpected any. Specify a different type.


155-155: Unexpected any. Specify a different type.


156-156: Unexpected any. Specify a different type.


157-157: Unexpected any. Specify a different type.


169-169: Unexpected any. Specify a different type.


170-170: Unexpected any. Specify a different type.


175-175: Unexpected any. Specify a different type.


176-176: Unexpected any. Specify a different type.


186-186: Unexpected any. Specify a different type.


187-187: Unexpected any. Specify a different type.


223-223: Unexpected any. Specify a different type.


235-235: Unexpected any. Specify a different type.


236-236: Unexpected any. Specify a different type.

Additional comments not posted (3)
tests/ui-testing/playwright-tests/sanity.spec.js (1)

449-468: Ensure error handling is consistent across similar test cases.

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

632-647: Ensure consistent SQL string manipulation.

The changes made here to replace the SQL string manipulations with function calls are good for maintainability and readability. This should help prevent errors and make the code easier to manage.


Line range hint 128-128: Specify explicit types instead of any.
[REFACTOR_SUGGESTion]
Using any type defeats the purpose of TypeScript's static type checking. Where possible, replace any with more specific types to improve code safety and clarity.

- let parser: any;
+ let parser: SQLParserType; // Assuming SQLParserType is an appropriate type

- const fieldValues = ref();
+ const fieldValues = ref<Record<string, unknown>>(); // Adjust the generic parameter as needed

Also applies to: 129-129, 139-139, 143-143, 146-146, 151-151, 153-153, 154-154, 155-155, 156-156, 157-157, 169-169, 170-170, 175-175, 176-176, 186-186, 187-187, 223-223, 235-235, 236-236

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 (4)
tests/ui-testing/playwright-tests/sanity.spec.js (3)

Line range hint 3-3: Consider using the node: protocol when importing Node.js built-in modules.

- import { log } from "console";
+ import { log } from "node:console";

Line range hint 10-10: Simplify computed expressions to enhance readability and performance.

- const folderName = `Folder ${Date.now()}`
+ const folderName = 'Folder' + Date.now();

Also applies to: 15-15, 20-20, 63-63, 66-66, 70-70, 97-97


Line range hint 37-37: Ensure that the regular expression does not contain unexpected control characters.

Please verify and correct the regular expression used in the removeUTFCharacters function to ensure it behaves as expected.

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

Line range hint 128-128: Replace any type with more specific types to improve type safety.

- let parser: any;
+ let parser: SQLParser;

- const fieldValues = ref();
+ const fieldValues = ref<Record<string, unknown>>();

- const initialQueryPayload: Ref<LogsQueryPayload | null> = ref(null);
+ const initialQueryPayload: Ref<LogsQueryPayload> = ref<LogsQueryPayload>({});

- const useSqlParser: any = await import("@/composables/useParser");
+ const useSqlParser: { sqlParser: () => SQLParser } = await import("@/composables/useParser");

- const { sqlParser }: any = useSqlParser.default();
+ const { sqlParser }: { sqlParser: () => SQLParser } = useSqlParser.default();

- const streamData: any = await getStream(streamName, searchObj.data.stream.streamType || "logs", true);
+ const streamData: StreamData = await getStream(streamName, searchObj.data.stream.streamType || "logs", true);

- const parsedSQL: any = fnParsedSQL();
+ const parsedSQL: ParsedSQL = fnParsedSQL();

- const itemObj: {
+ const itemObj: StreamItem = {
    name: any;
    args: string;
  };

- const schemaFields: any = [];
+ const schemaFields: string[] = [];

- let userDefineSchemaSettings: any = [];
+ let userDefine

Also applies to: 129-129, 139-139, 143-143, 146-146, 151-151, 153-153, 154-154, 155-155, 156-156, 157-157, 169-169, 170-170, 175-175, 176-176, 186-186, 187-187, 223-223, 235-235, 236-236

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 8599a1b and 4ab8357.
Files selected for processing (3)
  • tests/ui-testing/playwright-tests/sanity.spec.js (2 hunks)
  • web/src/composables/useLogs.ts (11 hunks)
  • web/src/plugins/logs/Index.vue (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • web/src/plugins/logs/Index.vue
Additional Context Used
Biome (30)
tests/ui-testing/playwright-tests/sanity.spec.js (10)

3-3: A Node.js builtin module should be imported with the node: protocol.


10-10: The computed expression can be simplified without the use of a string literal.


15-15: The computed expression can be simplified without the use of a string literal.


20-20: The computed expression can be simplified without the use of a string literal.


37-37: Unexpected control character(s) in regular expression: \x00


63-63: The computed expression can be simplified without the use of a string literal.


66-66: The computed expression can be simplified without the use of a string literal.


66-66: The computed expression can be simplified without the use of a string literal.


70-70: The computed expression can be simplified without the use of a string literal.


97-97: The computed expression can be simplified without the use of a string literal.

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

128-128: Unexpected any. Specify a different type.


129-129: Unexpected any. Specify a different type.


139-139: Unexpected any. Specify a different type.


143-143: Unexpected any. Specify a different type.


146-146: Unexpected any. Specify a different type.


151-151: Unexpected any. Specify a different type.


153-153: Unexpected any. Specify a different type.


154-154: Unexpected any. Specify a different type.


155-155: Unexpected any. Specify a different type.


156-156: Unexpected any. Specify a different type.


157-157: Unexpected any. Specify a different type.


169-169: Unexpected any. Specify a different type.


170-170: Unexpected any. Specify a different type.


175-175: Unexpected any. Specify a different type.


176-176: Unexpected any. Specify a different type.


186-186: Unexpected any. Specify a different type.


187-187: Unexpected any. Specify a different type.


223-223: Unexpected any. Specify a different type.


235-235: Unexpected any. Specify a different type.


236-236: Unexpected any. Specify a different type.

Additional comments not posted (2)
web/src/composables/useLogs.ts (2)

632-647: Refactor complex SQL string manipulations in buildSearch.

- req.aggs.histogram = req.aggs.histogram.replace("[INDEX_NAME]", searchObj.data.stream.selectedStream.value);
- req.aggs.histogram = req.aggs.histogram.replace("[WHERE_CLAUSE]", "");
+ req.aggs.histogram = replaceIndexName(req.aggs.histogram, searchObj.data.stream.selectedStream.value);
+ req.aggs.histogram = replaceWhereClause(req.aggs.histogram, "");

826-826: Consider checking for aggregation in SQL queries to optimize performance.

Verification successful

The search results indicate that there are indeed checks for SQL aggregation in the codebase, specifically within the useLogs.ts and useQuery.ts files. The presence of the isNonAggregatedQuery function and SQL aggregation keywords like GROUP BY and COUNT suggests that the code is handling aggregation checks.

  • web/src/composables/useLogs.ts: Contains the isNonAggregatedQuery function and multiple references to it.
  • web/src/composables/useQuery.ts: Contains SQL aggregation keywords.

Given this context, it appears that the code is already considering SQL aggregation checks.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify if SQL queries are properly handling aggregation checks.

# Test: Search for SQL aggregation checks. Expect: Proper handling of aggregation checks.
rg --type typescript $'isNonAggregatedQuery'

Length of output: 78



Script:

#!/bin/bash
# Description: Verify if SQL queries are properly handling aggregation checks.

# Test: Search for SQL aggregation checks. Expect: Proper handling of aggregation checks.
rg --type ts 'isNonAggregatedQuery|GROUP BY|SUM|COUNT|AVG|MIN|MAX'

Length of output: 1187

Comment on lines +449 to +468
test(' should display histogram in sql mode', async ({ page }) => {
await page.locator('[data-test="logs-search-result-bar-chart"] canvas').click({
position: {
x: 182,
y: 66
}
});
await page.getByLabel('SQL Mode').locator('div').nth(2).click();
await page.locator('[data-test="logs-search-bar-refresh-btn"]').click();
// await page.getByRole('heading', { name: 'Error while fetching' }).click();

await expect(page.getByRole('heading', { name: 'Error while fetching' })).not.toBeVisible();
await page.locator('[data-test="logs-search-result-bar-chart"] canvas').click({
position: {
x: 182,
y: 66
}
});

});
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Ensure consistent error handling in histogram display logic.

  • The sanity.spec.js file includes a check to ensure 'Error while fetching' is not visible.
  • The logspage.spec.js file lacks similar error handling checks.

Please add error handling in logspage.spec.js to ensure consistency.

Analysis chain

Ensure consistent error handling in histogram display logic.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the histogram display logic in SQL mode is correctly implemented and does not cause errors.

# Test: Search for similar logic in other parts of the codebase. Expect: No errors related to histogram display.
rg --type js $'page.locator.*logs-search-result-bar-chart.*click'

Length of output: 598



Script:

#!/bin/bash
# Extract relevant parts of logspage.spec.js to review error handling in histogram display logic

# Display lines around the found occurrences to understand the context
rg --type js --context 10 'page.locator.*logs-search-result-bar-chart.*click' tests/ui-testing/playwright-tests/logspage.spec.js

Length of output: 1739

Comment on lines +1406 to +1422
const fnHistogramParsedSQL = (query: string) => {
try {
const filteredQuery = query
.split("\n")
.filter((line: string) => !line.trim().startsWith("--"))
.join("\n");
return parser.astify(filteredQuery);
} catch (e: any) {
return {
columns: [],
orderby: null,
limit: null,
groupby: null,
where: null,
};
}
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Introduce error handling for SQL parsing in fnHistogramParsedSQL.

- return parser.astify(filteredQuery);
+ try {
+   return parser.astify(filteredQuery);
+ } catch (e) {
+   console.error("Failed to parse SQL in fnHistogramParsedSQL", e);
+   return {
+     columns: [],
+     orderby: null,
+     limit: null,
+     groupby: null,
+     where: null,
+   };
+ }

Committable suggestion was skipped due low confidence.

@bjp232004 bjp232004 merged commit d502edc into main May 29, 2024
@bjp232004 bjp232004 deleted the sql-mode-histogram-error branch May 29, 2024 10:53
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

Development

Successfully merging this pull request may close these issues.

3 participants