Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging improvements #63

Merged
merged 5 commits into from
Jun 28, 2024
Merged

Logging improvements #63

merged 5 commits into from
Jun 28, 2024

Conversation

eriktaubeneck
Copy link
Member

@eriktaubeneck eriktaubeneck commented Jun 27, 2024

This fixes #45, sorting logs by the timestamp provided by the server.

Addtionally, it addresses #46 allowing for downloading log files from each server.

Finally, it also allows for filtering of displayed logs by each server.

image

Summary by CodeRabbit

  • New Features

    • Introduced timestamp and server name display in log entries.
    • Added checkbox UI elements for selecting remote servers and displaying logs.
  • Improvements

    • Enhanced log handling and parsing for better clarity and retention.
    • Updated log generation to include URLs for easier access.
    • Improved log formatting with serialization for consistency.
  • Bug Fixes

    • Fixed issues with logs being shown twice by refining logic in the kill function and useEffect.
  • API Updates

    • Added a new endpoint to retrieve log files associated with a query ID.

Copy link

vercel bot commented Jun 27, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
draft ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 27, 2024 7:01am

@eriktaubeneck eriktaubeneck requested a review from akoshelev June 27, 2024 07:01
Copy link
Contributor

coderabbitai bot commented Jun 27, 2024

Walkthrough

The recent changes address the sorting issue of logs after a page refresh by adding timestamp fields to log entries, enhancing log parsing, and modifying the log rendering logic in the LogViewer component. The introduction of methods to generate log URLs and retrieve log files, along with adjustments to log handling in WebSocket events, ensures consistent and correct ordering of logs across different components.

Changes

File/Path Summary
server/app/query/servers.tsx Added timestamp field to ServerLog interface, log URL generation method, and parsing enhancements.
server/app/query/view/[id]/components.tsx Updated LogViewer component rendering logic to include timestamps and server names.
server/app/query/view/[id]/page.tsx Added server selection UI, new state for query and selected logs, and modified useEffect, kill function, and handleCheckbox function.
sidecar/app/query/base.py Changed logger format parameter to serialize=True in BaseQuery class.
sidecar/app/routes/start.py Added imports and new endpoint to retrieve log files associated with query IDs.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant LogViewer
    participant RemoteServer
    participant WebSocket
    participant Logger

    User->>LogViewer: Refresh page
    LogViewer->>WebSocket: Request logs
    WebSocket->>RemoteServer: Fetch logs with timestamps
    RemoteServer-->>WebSocket: Return logs
    WebSocket->>LogViewer: Deliver logs
    LogViewer->>Logger: Order logs chronologically
    Logger-->>LogViewer: Return ordered logs
    LogViewer-->>User: Display ordered logs
Loading

Assessment against linked issues

Objective Addressed Explanation
Investigate Clock Skew (#45)
Examine Software Bug (#45)
Improve Log Ordering (#45)
Testing and Validation (#45)

Poem

In the world of logs, we fixed the sort,
Timestamps added, a new report.
Servers log with better style,
Now refresh brings a sorted smile.
No more chaos, logs are neat,
Consistent order, quite the feat.


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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c1b5674 and 376cef4.

Files selected for processing (5)
  • server/app/query/servers.tsx (3 hunks)
  • server/app/query/view/[id]/components.tsx (1 hunks)
  • server/app/query/view/[id]/page.tsx (5 hunks)
  • sidecar/app/query/base.py (1 hunks)
  • sidecar/app/routes/start.py (2 hunks)
Additional context used
Ruff
sidecar/app/query/base.py

18-18: Remove quotes from type annotation

Remove quotes

(UP037)


29-29: Use X | Y for type annotations

Convert to X | Y

(UP007)


31-31: Use X | Y for type annotations

Convert to X | Y

(UP007)


32-32: Use X | Y for type annotations

Convert to X | Y

(UP007)


68-68: Use X | Y for type annotations

Convert to X | Y

(UP007)


68-68: Remove quotes from type annotation

Remove quotes

(UP037)


161-164: Use contextlib.suppress(ValueError) instead of try-except-pass

Replace with contextlib.suppress(ValueError)

(SIM105)

Biome
server/app/query/servers.tsx

[error] 33-35: This else clause can be omitted because previous branches break early.

Unsafe fix: Omit the else clause.

(lint/style/noUselessElse)


[error] 155-167: This else clause can be omitted because previous branches break early.

Unsafe fix: Omit the else clause.

(lint/style/noUselessElse)

server/app/query/view/[id]/page.tsx

[error] 229-229: Using the role attribute 'list' on the 'ul' element is redundant, because it is implied by the semantic 'ul' element.

Unsafe fix: Remove the role attribute.

(lint/a11y/noRedundantRoles)


[error] 38-38: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.

See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.

(lint/suspicious/noGlobalIsNan)


[error] 140-143: Provide an explicit type prop for the button element.

The default type of a button is submit, which causes the submission of a form when placed inside a form element. This is likely not the behaviour that you want inside a React application.
Allowed button types are: submit, button or reset

(lint/a11y/useButtonType)


[error] 188-191: Provide an explicit type prop for the button element.

The default type of a button is submit, which causes the submission of a form when placed inside a form element. This is likely not the behaviour that you want inside a React application.
Allowed button types are: submit, button or reset

(lint/a11y/useButtonType)


[error] 236-236: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

Additional comments not posted (5)
server/app/query/view/[id]/components.tsx (1)

91-91: Updated LogViewer component to handle logs with timestamps and server names.

The implementation of the LogViewer component now includes handling for logs with timestamps and server names, aligning with the PR's objectives to enhance log management. The use of clsx for conditional styling and sourceCodePro font is noted, enhancing the visual presentation of logs.

  • Correctness: The conversion from timestamp to ISO string (date.toISOString()) ensures that logs are displayed with a standardized datetime format, which is crucial for consistency across different systems and locales.
  • Performance: Consider implementing a virtualized list if the number of logs can be very large to improve rendering performance and scroll handling.
  • Security: Ensure that any user-generated content within logs is properly sanitized before display to prevent XSS attacks.

Also applies to: 96-129

sidecar/app/routes/start.py (1)

93-123: Introduced new API endpoint for log file retrieval.

The new endpoint get_ipa_helper_log_file retrieves log files associated with a query ID. This implementation uses StreamingResponse to stream log files, which is efficient for handling potentially large log files.

  • Correctness: The endpoint correctly handles cases where the query is not found by returning a HTTPException with a 404 status code, which is good practice for REST APIs.
  • Performance: Streaming log files is a good approach as it avoids loading the entire file into memory. Ensure that file handles are properly closed after streaming.
  • Security: Consider implementing rate limiting and authentication for this endpoint to prevent abuse.
sidecar/app/query/base.py (1)

46-46: Enabled serialization of log entries in Query class.

The serialization of log entries is enabled to improve the structure and queryability of logs. This change aligns with the PR's objectives to enhance logging capabilities.

  • Correctness: The filter condition ensures that only logs related to the specific query ID are processed, which is crucial to avoid cluttering the log file with irrelevant entries.
  • Performance: Monitor the performance impact of serialization, as it might increase the processing time for each log entry.
  • Security: Ensure that sensitive information is not inadvertently logged, especially since serialized logs can be easier to access and manipulate.
server/app/query/servers.tsx (1)

13-13: Enhancements in log handling and WebSockets in server/app/query/servers.tsx.

The addition of a timestamp field to the ServerLog interface and the new logURL method in the RemoteServer class support the PR's objectives of improving log management. The WebSocket handling for logs is also enhanced to manage log ordering and retention.

  • Correctness: The use of timestamps to order logs is a critical improvement. The handling of WebSocket messages ensures that logs are processed and displayed in real-time.
  • Performance: The implementation limits the number of retained logs to 10,000, which is a good practice to prevent memory overflow. However, consider implementing more sophisticated log rotation or archiving strategies for long-term log management.
  • Security: Ensure that the WebSocket connection is secure and that appropriate authentication and authorization checks are in place to prevent unauthorized access to logs.

Also applies to: 90-93, 130-168

server/app/query/view/[id]/page.tsx (1)

14-14: State management and UI enhancements in server/app/query/view/[id]/page.tsx.

The introduction of new state variables and functions for handling log filtering and display significantly enhances the user's ability to interact with log data. The use of WebSockets for real-time updates is effectively implemented.

  • Correctness: The state management for logs, status, and statistics is well-handled, ensuring that the UI is responsive and accurate.
  • Performance: The use of WebSockets for real-time updates is efficient, but ensure that the WebSocket connections are properly managed and closed to avoid memory leaks.
  • Security: Implement CSRF protection for the form handling and ensure that all user inputs are validated and sanitized to prevent XSS and SQL injection attacks.

Also applies to: 31-40, 61-77, 96-275

@akoshelev
Copy link
Collaborator

wow this is lovely, thank you!

@@ -87,6 +90,38 @@ def get_ipa_helper_status(
return {"status": query.status.name}


@router.get("/{query_id}/log-file")
def get_ipa_helper_log_file(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would recommend to guarantee ordering on the server side. JS operates in my browser and it is busy with other things, so we should delegate hard work to server side. Besides that, it also makes API consistent

Copy link
Collaborator

Choose a reason for hiding this comment

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

btw can you point me to the file where traces are written out of order? I'd like to take a look and see if we may have an issue on the MPC side

Copy link
Member Author

Choose a reason for hiding this comment

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

oh I don't think they should ever be out of order on the server side. they are only out of order when merging the 4 files together. for example a log from Helper 1 might arrive after a log from Helper 2, but have an earlier timestamp.

this is particularly true when we're refreshing later and just consuming the file in it's entirety.

let me point you to where the ordering happens. It should be pretty efficient.


// only retain last 10,000 logs
const maxNumLogs = 10000;
setLogs((prevLogs) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

@akoshelev this is where the ordering happens. if the new log is already the last, it is just appended. if not, it uses lastIndexOf to find the right spot. this should be O(n) and I would imagine starts from the end of the list, where it will most likely find the right position.

the other performance knob here is the max lines kept. I upped it to 10k, but we could lower that now that the download option is available.

Copy link
Collaborator

Choose a reason for hiding this comment

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

is it server side or client side?

Copy link
Member Author

Choose a reason for hiding this comment

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

client side. client connects directly via websocket to logs from every helper.

I don't think it would be possible to do server side while they query is running, because a stale log from one helper could always arrive after other logs have reached the client.

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.

After refresh, logs appear to be sorted in random order
2 participants