Skip to content

feat(log-collector): implement stream error handling with process failure#1715

Merged
ygrishajev merged 3 commits intomainfrom
feat/log-collector
Jul 22, 2025
Merged

feat(log-collector): implement stream error handling with process failure#1715
ygrishajev merged 3 commits intomainfrom
feat/log-collector

Conversation

@ygrishajev
Copy link
Contributor

@ygrishajev ygrishajev commented Jul 22, 2025

  • Add stream event handlers for proper lifecycle management
  • Implement custom Promise to handle stream errors and propagate failures
  • Enable "let it fail" strategy for automatic recovery via Kubernetes restarts
  • Fix test coverage for new error handling logic

Resolves hanging issues when log streams terminate unexpectedly.

Summary by CodeRabbit

  • Documentation

    • Updated development workflow instructions in the Log Collector README, correcting the Docker environment file path and flag usage.
  • Bug Fixes

    • Improved error handling and logging for log stream events in the log collection service.
  • Tests

    • Enhanced test coverage for log stream error scenarios and event handling in the log collector service.
  • Chores

    • Added a shared release configuration for the Log Collector app.

…lure

- Add stream event handlers for proper lifecycle management
- Implement custom Promise to handle stream errors and propagate failures
- Enable "let it fail" strategy for automatic recovery via Kubernetes restarts
- Fix test coverage for new error handling logic

Resolves hanging issues when log streams terminate unexpectedly.
@ygrishajev ygrishajev requested a review from a team as a code owner July 22, 2025 09:56
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 22, 2025

Walkthrough

A .release-it.js file was added to the log-collector app to delegate release configuration to a shared module. The README was updated to correct the Docker environment file path and flag. The k8s-log-collector service and its tests were enhanced for better log stream event handling and error propagation.

Changes

File(s) Change Summary
apps/log-collector/.release-it.js Added file to delegate release-it configuration to @akashnetwork/releaser.
apps/log-collector/README.md Updated Docker command: corrected .env.local path and fixed --env-file flag.
apps/log-collector/src/services/k8s-log-collector/k8s-log-collector.service.ts Refactored log stream handling to use event-driven resolution and explicit error propagation.
apps/log-collector/src/services/k8s-log-collector/k8s-log-collector.service.spec.ts Enhanced tests: added stream event mocks and new test for error propagation and logging.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant K8sLogCollectorService
    participant LogStream
    participant LogDestinationService

    Client->>K8sLogCollectorService: collectLogs(namespace, podName, logDestination)
    K8sLogCollectorService->>LogStream: createLogStream(podName, namespace, logDestination)
    K8sLogCollectorService->>LogStream: startKubernetesLogStream(...)
    Note right of LogStream: Emits "end" or "error" events
    LogStream-->>K8sLogCollectorService: "end" event
    K8sLogCollectorService-->>Client: resolve Promise
    LogStream-->>K8sLogCollectorService: "error" event
    K8sLogCollectorService-->>Client: reject Promise, propagate error
    K8sLogCollectorService->>LogDestinationService: Forward logs, log events
Loading

Estimated code review effort

2 (~15 minutes)

Possibly related PRs

Suggested reviewers

  • baktun14

Poem

In the cluster where logs do flow,
Now streams are watched as errors show.
With Docker flags and paths made right,
And releases handled out of sight,
The log collector hops ahead—
Eventful journeys lie ahead! 🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-07-22T10_00_16_878Z-debug-0.log


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fee8013 and a8c0aba.

📒 Files selected for processing (4)
  • apps/log-collector/.release-it.js (1 hunks)
  • apps/log-collector/README.md (1 hunks)
  • apps/log-collector/src/services/k8s-log-collector/k8s-log-collector.service.spec.ts (3 hunks)
  • apps/log-collector/src/services/k8s-log-collector/k8s-log-collector.service.ts (2 hunks)
📓 Path-based instructions (3)
**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/general.mdc)

Never use type any or cast to type any. Always define the proper TypeScript types.

Files:

  • apps/log-collector/src/services/k8s-log-collector/k8s-log-collector.service.spec.ts
  • apps/log-collector/src/services/k8s-log-collector/k8s-log-collector.service.ts
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/general.mdc)

**/*.{js,jsx,ts,tsx}: Never use deprecated methods from libraries.
Don't add unnecessary comments to the code

Files:

  • apps/log-collector/src/services/k8s-log-collector/k8s-log-collector.service.spec.ts
  • apps/log-collector/src/services/k8s-log-collector/k8s-log-collector.service.ts
**/*.spec.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/no-jest-mock.mdc)

Don't use jest.mock() to mock dependencies in test files. Instead, use jest-mock-extended to create mocks and pass mocks as dependencies to the service under test.

**/*.spec.{ts,tsx}: Use setup function instead of beforeEach in test files
setup function must be at the bottom of the root describe block in test files
setup function creates an object under test and returns it
setup function should accept a single parameter with inline type definition
Don't use shared state in setup function
Don't specify return type of setup function

Files:

  • apps/log-collector/src/services/k8s-log-collector/k8s-log-collector.service.spec.ts
🧠 Learnings (1)
apps/log-collector/src/services/k8s-log-collector/k8s-log-collector.service.spec.ts (4)

Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/no-jest-mock.mdc:0-0
Timestamp: 2025-07-21T08:24:24.269Z
Learning: Applies to **/*.spec.{ts,tsx} : Don't use jest.mock() to mock dependencies in test files. Instead, use jest-mock-extended to create mocks and pass mocks as dependencies to the service under test.

Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : setup function creates an object under test and returns it

Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : Don't use shared state in setup function

Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : Use setup function instead of beforeEach in test files

🧬 Code Graph Analysis (2)
apps/log-collector/src/services/k8s-log-collector/k8s-log-collector.service.spec.ts (2)
apps/log-collector/test/seeders/config.seeder.ts (1)
  • seedConfigTestData (15-27)
apps/log-collector/test/seeders/k8s-log-collector.seeder.ts (1)
  • seedK8sTestData (13-59)
apps/log-collector/src/services/k8s-log-collector/k8s-log-collector.service.ts (1)
packages/logging/src/servicies/logger/logger.service.ts (1)
  • error (107-109)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/general.mdc)

Never use type any or cast to type any. Always define the proper TypeScript types.

Files:

  • apps/log-collector/src/services/k8s-log-collector/k8s-log-collector.service.spec.ts
  • apps/log-collector/src/services/k8s-log-collector/k8s-log-collector.service.ts
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/general.mdc)

**/*.{js,jsx,ts,tsx}: Never use deprecated methods from libraries.
Don't add unnecessary comments to the code

Files:

  • apps/log-collector/src/services/k8s-log-collector/k8s-log-collector.service.spec.ts
  • apps/log-collector/src/services/k8s-log-collector/k8s-log-collector.service.ts
**/*.spec.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/no-jest-mock.mdc)

Don't use jest.mock() to mock dependencies in test files. Instead, use jest-mock-extended to create mocks and pass mocks as dependencies to the service under test.

**/*.spec.{ts,tsx}: Use setup function instead of beforeEach in test files
setup function must be at the bottom of the root describe block in test files
setup function creates an object under test and returns it
setup function should accept a single parameter with inline type definition
Don't use shared state in setup function
Don't specify return type of setup function

Files:

  • apps/log-collector/src/services/k8s-log-collector/k8s-log-collector.service.spec.ts
🧠 Learnings (1)
apps/log-collector/src/services/k8s-log-collector/k8s-log-collector.service.spec.ts (4)

Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/no-jest-mock.mdc:0-0
Timestamp: 2025-07-21T08:24:24.269Z
Learning: Applies to **/*.spec.{ts,tsx} : Don't use jest.mock() to mock dependencies in test files. Instead, use jest-mock-extended to create mocks and pass mocks as dependencies to the service under test.

Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : setup function creates an object under test and returns it

Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : Don't use shared state in setup function

Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : Use setup function instead of beforeEach in test files

🧬 Code Graph Analysis (2)
apps/log-collector/src/services/k8s-log-collector/k8s-log-collector.service.spec.ts (2)
apps/log-collector/test/seeders/config.seeder.ts (1)
  • seedConfigTestData (15-27)
apps/log-collector/test/seeders/k8s-log-collector.seeder.ts (1)
  • seedK8sTestData (13-59)
apps/log-collector/src/services/k8s-log-collector/k8s-log-collector.service.ts (1)
packages/logging/src/servicies/logger/logger.service.ts (1)
  • error (107-109)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: validate / validate-app
🔇 Additional comments (8)
apps/log-collector/README.md (1)

165-165: Documentation correction looks good!

The Docker flag syntax has been corrected from -env-file to the proper --env-file, and the environment file path has been updated to reflect the new location in the env/ subdirectory.

apps/log-collector/.release-it.js (1)

1-1: LGTM! Clean delegation to shared release configuration.

This follows best practices by centralizing release configuration in the shared @akashnetwork/releaser module, promoting consistency across projects.

apps/log-collector/src/services/k8s-log-collector/k8s-log-collector.service.ts (3)

155-165: Excellent refactoring to event-driven stream handling!

The change from directly awaiting startKubernetesLogStream to returning a Promise that resolves/rejects based on stream events is a solid architectural improvement. This properly handles the asynchronous nature of streams and enables better error propagation.


168-168: Good error propagation pattern.

Re-throwing the error after logging ensures proper error handling up the call stack while maintaining visibility of issues in logs.


186-196: Well-implemented stream lifecycle management.

The event listeners for 'end', 'error', and 'close' events provide comprehensive logging of stream states, which will be valuable for debugging and monitoring stream behavior.

apps/log-collector/src/services/k8s-log-collector/k8s-log-collector.service.spec.ts (3)

3-4: Proper import usage following coding guidelines.

Good use of jest-mock-extended for mocking and explicit type import for PassThrough, adhering to the project's testing standards.


28-36: Well-crafted stream mock for event-driven testing.

The mock implementation correctly simulates the asynchronous "end" event behavior, aligning with the service's new event-driven approach. The use of setTimeout ensures the handler is called in the next tick, properly testing the Promise resolution.


106-133: Excellent test coverage for error handling.

This test properly verifies the new error propagation mechanism by:

  • Simulating a stream error event
  • Confirming the error is properly propagated up the call stack
  • Verifying error logging occurs as expected

The test structure and mocking approach are consistent with the existing test patterns.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

@ygrishajev ygrishajev changed the title feat(log-collector): implement stream error handling with process fai… feat(log-collector): implement stream error handling with process failure Jul 22, 2025
@codecov
Copy link

codecov bot commented Jul 22, 2025

Codecov Report

Attention: Patch coverage is 46.15385% with 7 lines in your changes missing coverage. Please review.

Project coverage is 72.52%. Comparing base (b15370f) to head (54fa4a7).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ces/k8s-log-collector/k8s-log-collector.service.ts 46.15% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1715      +/-   ##
==========================================
+ Coverage   72.41%   72.52%   +0.10%     
==========================================
  Files         607      607              
  Lines       14162    14081      -81     
  Branches     2406     2401       -5     
==========================================
- Hits        10256    10212      -44     
- Misses       3586     3653      +67     
+ Partials      320      216     -104     
Flag Coverage Δ *Carryforward flag
api 80.13% <ø> (+0.02%) ⬆️ Carriedforward from a8c0aba
deploy-web 56.49% <ø> (+0.11%) ⬆️ Carriedforward from a8c0aba
log-collector 83.83% <46.15%> (-5.92%) ⬇️
notifications 87.25% <ø> (ø) Carriedforward from a8c0aba
provider-console 80.95% <ø> (ø) Carriedforward from a8c0aba
provider-proxy 84.35% <ø> (ø) Carriedforward from a8c0aba

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
...ces/k8s-log-collector/k8s-log-collector.service.ts 75.70% <46.15%> (-8.68%) ⬇️

... and 45 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ygrishajev ygrishajev merged commit 80e5be9 into main Jul 22, 2025
62 checks passed
@ygrishajev ygrishajev deleted the feat/log-collector branch July 22, 2025 10:27
@anilmurty anilmurty added this to the Log Forwarding milestone Jul 28, 2025
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.

3 participants

Comments