Skip to content

Conversation

@omkarK06
Copy link
Contributor

@omkarK06 omkarK06 commented Nov 7, 2024

#5010

Summary by CodeRabbit

  • New Features

    • Introduced new methods for enhanced log data handling, including quoteTableNameDirectly, getRegionInfo, and addTraceId.
  • Improvements

    • Enhanced error handling and state management for better user experience.
    • Refined query construction logic to optimize performance.
    • Updated list presentations in configuration components for improved styling.
  • Style

    • Improved formatting and readability in the JsonPreview, KubernetesConfig, LinuxConfig, and WindowsConfig components, enhancing code maintainability.
    • Added SCSS support for styling in KubernetesConfig.
  • Localization

    • Added a new label for the search functionality: "Original".

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

coderabbitai bot commented Nov 7, 2024

Walkthrough

The pull request introduces significant enhancements to the useLogs composable in web/src/composables/useLogs.ts, including new methods for SQL query handling and trace ID management, as well as refactoring existing methods for improved readability and efficiency. Additionally, error handling and state management have been enhanced, particularly for log data and histogram processing. Minor adjustments were made to the JsonPreview.vue component for formatting and readability without altering its core functionality. Changes were also made to several configuration components, primarily involving list formatting and styling updates.

Changes

File Change Summary
web/src/composables/useLogs.ts - Added methods: quoteTableNameDirectly, getRegionInfo, addTraceId.
- Updated methods: loadLogsData, handleRunQuery, refreshData, getPaginatedData, getHistogramQueryData, extractFields, buildSearch, generateHistogramData.
- Enhanced error handling and state management.
web/src/plugins/logs/JsonPreview.vue - Adjusted formatting, logic, and error handling for improved readability.
- Updated variable type declaration for unflattendData and changed tab label from t("search.unflattened") to t("search.original").
web/src/components/ingestion/recommended/KubernetesConfig.vue - Changed ordered lists to unordered lists for improved styling.
- Added kubernetes-config-section class to the root <div> and updated styles to SCSS.
web/src/components/ingestion/recommended/LinuxConfig.vue - Changed ordered list to unordered list for improved styling.
web/src/components/ingestion/recommended/WindowsConfig.vue - Changed ordered list to unordered list for improved styling.
web/src/locales/languages/en.json - Added key-value pair: "original": "Original" in the "search" section.
web/src/stores/index.ts - Changed keys traceId and spanId to trace_id and span_id in organizationSettings for consistency.
web/src/test/unit/helpers/store.ts - Updated field names in organizationSettings from traceId to trace_id and spanId to span_id.

Possibly related PRs

Suggested labels

🧹 Updates

Suggested reviewers

  • 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.

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

374-382: Enhance error notification with error code

The error notification implementation has been improved but could be enhanced further.

Consider adding error codes for better error tracking:

-          $q.notify({
-            message:
-              err.response?.data?.message || "Failed to get the Original data",
-            color: "negative",
-            position: "bottom",
-            timeout: 1500,
-          });
+          $q.notify({
+            message: `Error [OZ-${err.response?.status || 500}]: ${
+              err.response?.data?.message || "Failed to get the Original data"
+            }`,
+            color: "negative",
+            position: "bottom",
+            timeout: 1500,
+          });

434-445: Consider memoizing filtered tabs computation

The filteredTabs computed property contains multiple conditions that could impact performance if recomputed frequently.

Consider breaking down the conditions into separate computed properties for better maintainability and performance:

-    const filteredTabs = computed(() => {
-      return tabs.filter((tab) => {
-        if (
-          props.value._o2_id == undefined ||
-          searchAggData.hasAggregation ||
-          searchObj.data.stream.selectedStream.length > 1
-        ) {
-          return false;
-        }
-        return true;
-      });
-    });
+    const isValidForUnflattenedView = computed(() => {
+      return (
+        props.value._o2_id != undefined &&
+        !searchAggData.hasAggregation &&
+        searchObj.data.stream.selectedStream.length === 1
+      );
+    });
+
+    const filteredTabs = computed(() => {
+      return isValidForUnflattenedView.value ? tabs : [];
+    });
web/src/composables/useLogs.ts (5)

Line range hint 4028-4039: Fix variable scoping issue in getRegionInfo

The variable regionObj is declared outside the for...in loop and is reused in each iteration. This leads to all elements in clusterData referencing the same object due to JavaScript's object reference behavior. Declare regionObj within the loop to ensure each element is a distinct object.

Apply this diff to fix the issue:

 const getRegionInfo = () => {
   searchService.get_regions().then((res) => {
     const clusterData = [];
-    let regionObj: any = {};
     const apiData = res.data;
     for (const region in apiData) {
+      let regionObj: any = {
+        label: region,
+        children: [],
+      };
-      regionObj = {
-        label: region,
-        children: [],
-      };
       for (const cluster of apiData[region]) {
         regionObj.children.push({ label: cluster });
       }
       clusterData.push(regionObj);
     }

     store.dispatch("setRegionInfo", clusterData);
   });
 };

Line range hint 4031-4038: Escape streamName to prevent regex injection in quoteTableNameDirectly

The function quoteTableNameDirectly uses new RegExp with streamName, which may contain special regex characters. This could lead to unintended matches or security vulnerabilities. Consider escaping streamName before using it in the regular expression.

Apply this diff to fix the issue:

 function quoteTableNameDirectly(sql: string, streamName: string) {
+  const escapedStreamName = streamName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
-  const regex = new RegExp(`FROM\\s+${streamName}`, "gi");
+  const regex = new RegExp(`FROM\\s+${escapedStreamName}`, "gi");
   const modifiedSql = sql.replace(regex, `FROM "${streamName}"`);
   return modifiedSql;
 }

Line range hint 3994-3999: Use Set for efficient trace ID management

Currently, searchRequestTraceIds is an array, and methods addTraceId and removeTraceId perform linear searches, which can be inefficient with large numbers of trace IDs. Using a Set will improve performance with constant-time insertion and deletion.

Apply this diff to refactor:

- searchObj.data.searchRequestTraceIds = [];
+ searchObj.data.searchRequestTraceIds = new Set<string>();

 const addTraceId = (traceId: string) => {
-  if (searchObj.data.searchRequestTraceIds.includes(traceId)) {
+  if (searchObj.data.searchRequestTraceIds.has(traceId)) {
     return;
   }
-  searchObj.data.searchRequestTraceIds.push(traceId);
+  searchObj.data.searchRequestTraceIds.add(traceId);
 };

 const removeTraceId = (traceId: string) => {
-  searchObj.data.searchRequestTraceIds =
-    searchObj.data.searchRequestTraceIds.filter(
-      (id: string) => id !== traceId,
-    );
+  searchObj.data.searchRequestTraceIds.delete(traceId);
 };

Line range hint 2805-3184: Refactor extractFields function to improve readability

The extractFields function is lengthy and complex, spanning over 300 lines. This makes it difficult to maintain and understand. Consider breaking it down into smaller, reusable helper functions to enhance readability and maintainability.


Line range hint 3460-3480: Ensure intervals are cleared properly in refreshData

In refreshData, when searchObj.meta.refreshInterval is zero or negative, clearInterval is called without checking if store.state.refreshIntervalID is defined. This could lead to unexpected behavior. Consider adding a check before calling clearInterval.

Apply this diff to improve error handling:

 else {
-  clearInterval(store.state.refreshIntervalID);
+  if (store.state.refreshIntervalID) {
+    clearInterval(store.state.refreshIntervalID);
+    store.dispatch("setRefreshIntervalID", null);
+  }
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between edbb812 and 57dc606.

📒 Files selected for processing (2)
  • web/src/composables/useLogs.ts (3 hunks)
  • web/src/plugins/logs/JsonPreview.vue (9 hunks)
🔇 Additional comments (3)
web/src/plugins/logs/JsonPreview.vue (3)

101-101: LGTM: Template structure follows Vue.js best practices

The v-show directive is properly implemented for conditional rendering of the unflattened view.


476-484: LGTM: Styles are well-structured

The Monaco editor styling follows CSS best practices with proper use of CSS variables and responsive dimensions.


358-366: ⚠️ Potential issue

Verify SQL query parameters and add input validation

The SQL query construction uses template literals with direct value interpolation, which could be risky if the values aren't properly sanitized.

Consider using parameterized queries or adding input validation for _o2_id and _timestamp values.

@omkarK06 omkarK06 force-pushed the fix/logs_expand_log_issue branch from 305b38f to f25789b Compare November 7, 2024 12:10
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 (8)
web/src/components/ingestion/recommended/LinuxConfig.vue (1)

56-56: Consider adding error handling for undefined values.

While the formatting looks good, the template literal could fail if props.currUserEmail or store.state.organizationData.organizationPasscode are undefined. Consider adding null checks or default values.

-    `${props.currUserEmail}:${store.state.organizationData.organizationPasscode}`,
+    `${props.currUserEmail || ''}:${store.state.organizationData?.organizationPasscode || ''}`,
web/src/components/ingestion/recommended/KubernetesConfig.vue (3)

Line range hint 97-138: Consider improving list indentation for better readability.

While the conversion to unordered lists and Tailwind styling is good, the nested list indentation could be more consistent. Consider adjusting the indentation of nested <ul> elements to better reflect the hierarchy.

-          <ul class="tw-list-disc tw-ml-5">
+            <ul class="tw-list-disc tw-ml-5">

222-222: Remove empty style block.

The style block is empty and includes SCSS support that isn't being used. Consider removing it entirely unless you plan to add styles in the near future.

-<style scoped lang="scss"></style>

Looking at the code, I can now generate the final response since I have found that the component actually has the necessary code to generate the Basic Auth token but doesn't use it in the helm commands.

Basic Auth token placeholder should be replaced with computed accessKey

The component already computes the correct Basic Auth token using the accessKey computed property, which base64 encodes the user email and organization passcode. However, this computed value isn't being used in the helm commands where [BASIC_PASSCODE] appears. The helm commands should use ${accessKey.value} instead of the static placeholder.

  • In collectorCmd computed property, replace:

    --set exporters."otlphttp/openobserve".headers.Authorization="Basic [BASIC_PASSCODE]"

    with:

    --set exporters."otlphttp/openobserve".headers.Authorization="Basic ${accessKey.value}"
  • Make the same replacement in collectorCmdThisCluster computed property.

🔗 Analysis chain

Line range hint 201-211: Add instructions for handling the Basic Auth token.

The helm commands include a placeholder [BASIC_PASSCODE] for the Authorization header, but there are no instructions for users on how to replace it securely. Consider adding a note explaining how to generate and use the correct Basic Auth token.


Let me gather more context about any existing documentation or instructions regarding the Basic Auth token.


Let me check if there are any related instructions or comments in the Vue component itself or nearby files.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if there are any actual credentials accidentally committed
rg -i 'authorization.*basic.*[a-zA-Z0-9+/]{20,}' || echo "No hardcoded Basic Auth tokens found."

Length of output: 2286


Script:

#!/bin/bash
# Check for any documentation or comments about Basic Auth token generation
rg -i -A 3 -B 3 'basic.*auth|basic.*token|basicauth' web/src/components/ingestion/

# Also check for any related documentation in markdown files
fd -e md -x rg -i 'basic.*auth|basic.*token|basicauth' {}

Length of output: 792


Script:

#!/bin/bash
# Check the content of the Kubernetes config component and surrounding files
cat web/src/components/ingestion/recommended/KubernetesConfig.vue

# Check for any related components that might contain instructions
fd -t f . web/src/components/ingestion/recommended/ -x cat {}

Length of output: 27875

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

Line range hint 4095-4106: Improve SQL table name quoting robustness.

The current regex-based approach for quoting table names has potential issues:

  1. It may fail with special characters in stream names
  2. Case-insensitive matching could cause issues with case-sensitive databases
  3. Global replacement could affect substrings in complex queries

Consider this safer implementation:

-  const regex = new RegExp(`FROM\\s+${streamName}`, "gi");
-  const modifiedSql = sql.replace(regex, `FROM "${streamName}"`);
+  // Escape special regex characters in streamName
+  const escapedStreamName = streamName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
+  const regex = new RegExp(
+    `(FROM|JOIN)\\s+(${escapedStreamName})(?![a-zA-Z0-9_"])`,
+    'g'
+  );
+  const modifiedSql = sql.replace(regex, `$1 "${streamName}"`);

Line range hint 4095-4143: Enhance error handling in filter expression generation.

The current error handling silently logs errors and returns a potentially unsafe default expression. This could mask issues and lead to incorrect filter behavior.

Consider this improved error handling:

   } catch (e: any) {
-    console.log("Error while getting filter expression by field type", e);
-    return `${field} ${operator} '${field_value}'`;
+    const errorMsg = `Error generating filter expression for field "${field}": ${e.message}`;
+    console.error(errorMsg, e);
+    // Return a safe default or throw based on field_value type
+    if (typeof field_value === 'number' || typeof field_value === 'boolean') {
+      return `${field} ${operator} ${field_value}`;
+    }
+    return `${field} ${operator} '${field_value?.toString().replace(/'/g, "''")}'`;
   }

Line range hint 2919-2947: Optimize performance in record processing.

The current implementation processes records individually and performs multiple array operations, which could be optimized for better performance.

Consider these optimizations:

-  const recordwithMaxAttribute =
-    searchObj.data.queryResults.hits[maxAttributesIndex];
-
-  for (const key of Object.keys(recordwithMaxAttribute)) {
-    if (key == "_o2_id" || key == "_original") {
-      continue;
-    }
-    if (key == store.state.zoConfig.timestamp_column) {
-      searchObj.data.hasSearchDataTimestampField = true;
-    }
-    if (
-      !schemaFields.includes(key) &&
-      !commonSchemaFields.includes(key) &&
-      key != "_stream_name"
-    ) {
-      fieldObj = {
-        name: key,
-        type: "Utf8",
-        ftsKey: false,
-        group: stream.name,
-        isSchemaField: false,
-        showValues: false,
-        isInterestingField:
-          searchObj.data.stream.interestingFieldList.includes(key)
-            ? true
-            : false,
-        streams: [],
-      };
-      schemaMaps.push(fieldObj);
-      schemaFields.push(key);
-    }
+  // Create sets for faster lookups
+  const schemaFieldSet = new Set(schemaFields);
+  const commonSchemaFieldSet = new Set(commonSchemaFields);
+  const interestingFieldSet = new Set(searchObj.data.stream.interestingFieldList);
+  
+  // Process all keys at once
+  const recordKeys = Object.keys(recordwithMaxAttribute);
+  const newFields = recordKeys.filter(key => {
+    if (key === "_o2_id" || key === "_original" || key === "_stream_name") {
+      return false;
+    }
+    if (key === store.state.zoConfig.timestamp_column) {
+      searchObj.data.hasSearchDataTimestampField = true;
+      return false;
+    }
+    return !schemaFieldSet.has(key) && !commonSchemaFieldSet.has(key);
+  });
+
+  // Batch create field objects
+  const newFieldObjects = newFields.map(key => ({
+    name: key,
+    type: "Utf8",
+    ftsKey: false,
+    group: stream.name,
+    isSchemaField: false,
+    showValues: false,
+    isInterestingField: interestingFieldSet.has(key),
+    streams: [],
+  }));
+
+  schemaMaps.push(...newFieldObjects);
+  schemaFields.push(...newFields);

Line range hint 4095-4143: Enhance trace ID management robustness.

The trace ID management could be improved with validation and optimized array operations.

Consider these improvements:

+  const validateTraceId = (traceId: string): boolean => {
+    return /^[0-9a-f]{32}$/.test(traceId);
+  };
+
   const addTraceId = (traceId: string) => {
+    if (!validateTraceId(traceId)) {
+      console.warn(`Invalid trace ID format: ${traceId}`);
+      return;
+    }
     if (searchObj.data.searchRequestTraceIds.includes(traceId)) {
       return;
     }
     searchObj.data.searchRequestTraceIds.push(traceId);
   };
 
   const removeTraceId = (traceId: string) => {
-    searchObj.data.searchRequestTraceIds =
-      searchObj.data.searchRequestTraceIds.filter(
-        (id: string) => id !== traceId,
-      );
+    const index = searchObj.data.searchRequestTraceIds.indexOf(traceId);
+    if (index > -1) {
+      searchObj.data.searchRequestTraceIds.splice(index, 1);
+    }
   };
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 57dc606 and f25789b.

📒 Files selected for processing (8)
  • web/src/components/ingestion/recommended/KubernetesConfig.vue (6 hunks)
  • web/src/components/ingestion/recommended/LinuxConfig.vue (2 hunks)
  • web/src/components/ingestion/recommended/WindowsConfig.vue (2 hunks)
  • web/src/composables/useLogs.ts (3 hunks)
  • web/src/locales/languages/en.json (1 hunks)
  • web/src/plugins/logs/JsonPreview.vue (10 hunks)
  • web/src/stores/index.ts (2 hunks)
  • web/src/test/unit/helpers/store.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • web/src/plugins/logs/JsonPreview.vue
🔇 Additional comments (7)
web/src/components/ingestion/recommended/LinuxConfig.vue (1)

9-12: LGTM! Styling changes align with design consistency.

The switch to an unordered list with Tailwind styling matches the pattern used in other configuration components, improving visual consistency across the application.

web/src/components/ingestion/recommended/WindowsConfig.vue (2)

13-16: LGTM! Consistent list styling across config components.

The change from ordered to unordered list with Tailwind styling aligns with the styling updates made in other ingestion configuration components.


60-60: LGTM! Clean string interpolation.

The string interpolation formatting is clean and consistent.

web/src/components/ingestion/recommended/KubernetesConfig.vue (1)

3-3: LGTM: Class addition follows naming conventions.

The addition of the kubernetes-config-section class provides better styling organization and scope.

web/src/stores/index.ts (2)

30-33: LGTM! Improved indentation for better readability.

The adjusted indentation better reflects the nested structure of the conditional logic.


48-49: Verify all references to the renamed trace and span ID fields.

The change from camelCase to snake_case aligns with common observability system conventions. However, this is a breaking change that requires verification of all references.

Let's verify all references to these fields:

✅ Verification successful

Field name changes have been properly updated throughout the codebase

The change from camelCase to snake_case for trace and span ID fields has been consistently implemented across the codebase. The search results confirm:

  1. The new snake_case field names are properly set in the store configuration:
trace_id_field_name: "trace_id",
span_id_field_name: "span_id",
  1. All references to these fields have been updated to use the new snake_case format in:
  • Frontend components and views
  • Backend services and handlers
  • API endpoints and data models
  • Configuration files and settings

The changes align with common observability system conventions and have been thoroughly propagated through the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining camelCase versions that might have been missed
echo "Searching for old camelCase versions..."
rg -i "traceId|spanId" --type ts --type vue

# Search for new snake_case versions to ensure consistent usage
echo -e "\nVerifying new snake_case versions..."
rg -i "trace_id|span_id" --type ts --type vue

Length of output: 327


Script:

#!/bin/bash
# Search for any remaining camelCase versions that might have been missed
echo "Searching for old camelCase versions..."
rg -i "traceId|spanId" --type typescript --type javascript

# Search for new snake_case versions to ensure consistent usage
echo -e "\nVerifying new snake_case versions..."
rg -i "trace_id|span_id" --type typescript --type javascript

Length of output: 371


Script:

#!/bin/bash
# Search for any remaining camelCase versions that might have been missed
echo "Searching for old camelCase versions..."
rg -i "traceId|spanId"

# Search for new snake_case versions to ensure consistent usage
echo -e "\nVerifying new snake_case versions..."
rg -i "trace_id|span_id"

Length of output: 121518

web/src/locales/languages/en.json (1)

131-131: LGTM! The new translation key follows established conventions.

The addition of the "original" translation key is well-placed within the "search" section and follows the existing naming and capitalization patterns.

@omkarK06 omkarK06 merged commit 0bdbced into main Nov 7, 2024
29 checks passed
@omkarK06 omkarK06 deleted the fix/logs_expand_log_issue branch November 7, 2024 12:57
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