Skip to content

feat: logs page v2#2701

Merged
chronark merged 52 commits intomainfrom
logs-page-v2
Dec 5, 2024
Merged

feat: logs page v2#2701
chronark merged 52 commits intomainfrom
logs-page-v2

Conversation

@ogzhanolguncu
Copy link
Contributor

@ogzhanolguncu ogzhanolguncu commented Dec 4, 2024

What does this PR do?

Fixes # (issue)

If there is not an issue for this, please create one first. This is used to tracking purposes and also helps use understand why this PR exists

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Chore (refactoring code, technical debt, workflow improvements)
  • Enhancement (small improvements)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How should this be tested?

  • Test A
  • Test B

Checklist

Required

  • Filled out the "How to test" section in this PR
  • Read Contributing Guide
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand areas
  • Ran pnpm build
  • Ran pnpm fmt
  • Checked for warnings, there are none
  • Removed all console.logs
  • Merged the latest changes from main onto my branch with git pull origin main
  • My changes don't cause any responsiveness issues

Appreciated

  • If a UI change was made: Added a screen recording or screenshots to this PR
  • Updated the Unkey Docs if changes were necessary

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a LogsChart component for visualizing log data with a bar chart.
    • Added a DatePickerWithRange component for selecting custom date ranges.
    • Implemented a ResponseStatus filter component for managing HTTP response status filters.
    • Launched a SearchCombobox for enhanced log search capabilities.
    • Added a Timeline component for selecting time ranges for log filtering.
    • Introduced a LogsFilters component to streamline log entry filtering.
    • New LogFooter, LogHeader, LogMetaSection, and LogSection components for detailed log entry views.
    • Added a LoadingRow component to display loading states in the logs table.
    • Introduced a ResizablePanel for improved log detail views.
    • Added a TimestampInfo component for enhanced timestamp displays.
    • New Calendar component for date selection integrated with the UI.
    • Added a ButtonGroup component for grouping buttons in the UI.
  • Improvements

    • Enhanced log querying capabilities with new search parameters and error handling.
    • Updated the LogsTable for better performance with large datasets.
  • Bug Fixes

    • Fixed issues related to log fetching and display, ensuring accurate representation of log data.
  • Documentation

    • Updated documentation to reflect new components and features introduced in this release.

ogzhanolguncu and others added 30 commits September 26, 2024 15:57
Add virtual list to table to prevent rendering lots of items at once.

Since we store items in the memory as we fetch more item, list might get
big enough to slow the page down, thats why we have to partially show
them.
Add debounce to combobox filters and add shortcut del/backspace to
remove combobox filters when focused
@chronark
Copy link
Collaborator

chronark commented Dec 4, 2024

CleanShot 2024-12-04 at 16 33 25@2x
the separators are sometimes full width and sometimes not

@chronark
Copy link
Collaborator

chronark commented Dec 4, 2024

CleanShot 2024-12-04 at 16 34 15@2x
meta field has weird corners, probably missing an overflow-hidden

Copy link
Collaborator

@chronark chronark left a comment

Choose a reason for hiding this comment

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

CleanShot 2024-12-04 at 16 43 11@2x

We should not parse the body into key-values, and more importantly we should't uppercase their keys, it loses the information that this was actually json, and while we always expect json, the user might mess up and send us something invalid.

I'm good with optimistically calling JSON.stringify(JSON.parse(body), null, 2) in a try catch to try and format it nicely but falling back to displaying the raw string

@ogzhanolguncu
Copy link
Contributor Author

CleanShot 2024-12-04 at 16 43 11@2x

We should not parse the body into key-values, and more importantly we should't uppercase their keys, it loses the information that this was actually json, and while we always expect json, the user might mess up and send us something invalid.

I'm good with optimistically calling JSON.stringify(JSON.parse(body), null, 2) in a try catch to try and format it nicely but falling back to displaying the raw string

I agree, yeah. Let's do this.

@ogzhanolguncu
Copy link
Contributor Author

CleanShot 2024-12-04 at 16 33 25@2x the separators are sometimes full width and sometimes not

Those are actually padded from left on purpose, but we can change that if we are not happy.

@chronark
Copy link
Collaborator

chronark commented Dec 4, 2024

CleanShot 2024-12-04 at 16 33 25@2x the separators are sometimes full width and sometimes not

Those are actually padded from left on purpose, but we can change that if we are not happy.

It looks a bit off and unintentional, but maybe that's just me
It's a nitpick really and might change with vitors design anyways

let's keep it as is for now to move quickly

This PR also adds escape listener when you navigating table with
keyboard
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: 4

🧹 Outside diff range and nitpick comments (2)
apps/dashboard/app/(app)/logs/components/log-details/components/log-section.tsx (2)

3-9: Extract props interface for better maintainability.

Consider extracting the props interface to improve code organization and reusability.

+interface LogSectionProps {
+  details: string | string[];
+  title: string;
+}
+
-export const LogSection = ({
-  details,
-  title,
-}: {
-  details: string | string[];
-  title: string;
-}) => {
+export const LogSection = ({ details, title }: LogSectionProps) => {

11-14: Consider using design tokens for measurements.

Replace hardcoded pixel values with design system tokens for better maintainability and consistency.

-<div className="px-3 flex flex-col gap-[2px]">
-  <span className="text-sm text-content/65 font-sans">{title}</span>
-  <Card className="rounded-[5px] bg-background-subtle">
-    <CardContent className="p-2 text-[12px]">
+<div className="px-3 flex flex-col gap-1">
+  <span className="text-sm text-content/65 font-sans">{title}</span>
+  <Card className="rounded-md bg-background-subtle">
+    <CardContent className="p-2 text-xs">
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9d10310 and c97487b.

📒 Files selected for processing (6)
  • apps/dashboard/app/(app)/logs/components/log-details/components/log-footer.tsx (1 hunks)
  • apps/dashboard/app/(app)/logs/components/log-details/components/log-meta.tsx (1 hunks)
  • apps/dashboard/app/(app)/logs/components/log-details/components/log-section.tsx (1 hunks)
  • apps/dashboard/app/(app)/logs/components/log-details/index.tsx (1 hunks)
  • apps/dashboard/app/(app)/logs/components/logs-table.tsx (1 hunks)
  • apps/dashboard/app/(app)/logs/utils.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • apps/dashboard/app/(app)/logs/components/log-details/components/log-meta.tsx
  • apps/dashboard/app/(app)/logs/components/log-details/index.tsx
  • apps/dashboard/app/(app)/logs/components/logs-table.tsx
  • apps/dashboard/app/(app)/logs/components/log-details/components/log-footer.tsx
🔇 Additional comments (4)
apps/dashboard/app/(app)/logs/components/log-details/components/log-section.tsx (1)

18-19: ⚠️ Potential issue

Improve header parsing logic.

The current splitting logic might break for headers containing multiple colons.

-const [key, ...valueParts] = header.split(":");
-const value = valueParts.join(":").trim();
+const colonIndex = header.indexOf(':');
+const key = colonIndex > -1 ? header.slice(0, colonIndex) : header;
+const value = colonIndex > -1 ? header.slice(colonIndex + 1).trim() : '';
apps/dashboard/app/(app)/logs/utils.ts (3)

1-11: LGTM! Well-structured error handling implementation.

The custom error class follows TypeScript best practices with proper type safety and immutable context.


13-48: ⚠️ Potential issue

Add input validation and structured logging

Several security and robustness improvements are needed:

 export const extractResponseField = <K extends keyof ResponseBody>(
   log: Log,
   fieldName: K,
 ): ResponseBody[K] | null => {
+  // Validate fieldName
+  if (typeof fieldName !== 'string' && typeof fieldName !== 'number' && typeof fieldName !== 'symbol') {
+    console.error('[extractResponseField] Invalid fieldName type', { fieldName });
+    return null;
+  }
+
   if (!log?.response_body) {
-    console.error("Invalid log or missing response_body");
+    console.error("[extractResponseField] Invalid log or missing response_body", { logId: log?.request_id });
     return null;
   }

+  // Validate response body size
+  const MAX_RESPONSE_BODY_SIZE = 1024 * 1024; // 1MB
+  if (log.response_body.length > MAX_RESPONSE_BODY_SIZE) {
+    console.error("[extractResponseField] Response body exceeds size limit", {
+      logId: log.request_id,
+      size: log.response_body.length
+    });
+    return null;
+  }

   try {
     const parsedBody = JSON.parse(log.response_body) as ResponseBody;

1-84: Verify usage patterns and error handling consistency

Let's verify how these utilities are used across the codebase to ensure consistent error handling patterns.

✅ Verification successful

Consistent error handling and usage patterns verified

Based on the search results, I can confirm:

  1. The utility functions are used consistently across the logs feature:

    • extractResponseField is used in log details components for parsing meta, code, and permissions
    • getRequestHeader is used for extracting user-agent information
    • safeParseJson is used for safely displaying request and response bodies
  2. Error handling patterns are consistent:

    • All functions properly handle edge cases with appropriate error logging
    • Error messages are descriptive and include relevant context
    • Console logging follows a consistent pattern across the codebase
  3. The implementation aligns with the codebase's error handling practices:

    • Uses console.error for critical failures
    • Uses console.warn for non-critical issues
    • Includes contextual information in error messages
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check usage patterns of the utility functions

# Check for usage of extractResponseField
echo "Checking extractResponseField usage:"
rg "extractResponseField" -A 2

# Check for usage of getRequestHeader
echo "Checking getRequestHeader usage:"
rg "getRequestHeader" -A 2

# Check for usage of safeParseJson
echo "Checking safeParseJson usage:"
rg "safeParseJson" -A 2

# Check for consistent error logging patterns
echo "Checking error logging patterns:"
rg "console\.(error|warn)" --type ts

Length of output: 15622

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants