Skip to content

fix(package): Only mount stream_output_dir when stream storage type is FS.#1129

Merged
haiqi96 merged 9 commits into
y-scope:mainfrom
haiqi96:slight_refactor
Aug 7, 2025
Merged

fix(package): Only mount stream_output_dir when stream storage type is FS.#1129
haiqi96 merged 9 commits into
y-scope:mainfrom
haiqi96:slight_refactor

Conversation

@haiqi96

@haiqi96 haiqi96 commented Jul 25, 2025

Copy link
Copy Markdown
Contributor

Description

This PR let start_clp.py only mount stream_output_dir when storage type is filesystem. This prevent the webui from mounting the stream_storage_dir when storing stream on s3.
A potential error could be caused by the existing code. If webui runs on another a different node from extraction worker, so the staged-stream dir wouldn't be created on webui's node. When testing locally, docker seems to create the mount directory on host if it doesn't exist. However, on certain machine, for example ec2's arm instance. docker doesn't allow binding to a non-existing directory.

This PR also updates the webui, so it only mount the stream output if the storage type is FS.

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

  1. Compressed mongodb log from local file storage and confirmed that log viewering still works for both S3 and FS storage type.

Summary by CodeRabbit

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of storage types by only mounting the stream output directory when using filesystem storage, ensuring correct setup for both filesystem and S3 storage options.
    • Updated static file serving to conditionally enable streaming content access only when the stream directory is configured.

@coderabbitai

coderabbitai Bot commented Jul 25, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The update modifies the start_webui function to conditionally set and mount the stream output directory based on the stream storage type, mounting it only for filesystem (FS) storage and omitting it for S3 storage. Additionally, the static route for "/streams" in the web server is registered only if the stream files directory is not null.

Changes

Cohort / File(s) Change Summary
Conditional Docker Mount for Stream Output Directory
components/clp-package-utils/clp_package_utils/scripts/start_clp.py
Modifies start_webui to set StreamFilesDir to None and omit mounting the stream output directory when storage type is S3; mounts and sets path only for FS storage.
Conditional Static Route Registration
components/webui/server/src/routes/static.ts
Adds a guard to register the "/streams" static route only if streamFilesDir is non-null, preventing route registration when directory is not configured.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Possibly related PRs

Suggested reviewers

  • kirkrodrigues
  • junhaoliao

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Support

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

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 generate unit tests to generate unit tests for 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.

@haiqi96 haiqi96 changed the title fix(package): Fix potential error code in the package. fix(package): Fix potential error in the package. Jul 25, 2025
@haiqi96 haiqi96 marked this pull request as ready for review July 25, 2025 23:33
@haiqi96 haiqi96 requested a review from a team as a code owner July 25, 2025 23:33
@junhaoliao junhaoliao self-requested a review August 5, 2025 18:34

@junhaoliao junhaoliao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

the current changes in start_clp.py lgtm

as @haiqi96 brought up offline, a warning message about the stream file folder being non-existent is printed when the stream files should be served on s3. let's wrap

let streamFilesDir = settings.StreamFilesDir;
if (false === path.isAbsolute(streamFilesDir)) {
streamFilesDir = path.resolve(rootDirname, streamFilesDir);
}
await fastify.register(fastifyStatic, {
prefix: "/streams",
root: streamFilesDir,
decorateReply: false,
});
with a check on the settings.

as for what to check from the settings, i believe checking for null of StreamFilesDir might be good in terms of semantics, which will require us to supply it conditionally in start_clp.py . what do you think?

@haiqi96 haiqi96 changed the title fix(package): Fix potential error in the package. fix(package): Don't mount storage_directory when stream storage type is S3. Aug 5, 2025
@haiqi96 haiqi96 changed the title fix(package): Don't mount storage_directory when stream storage type is S3. fix(package): Don't mount stream_output_dir when stream storage type is S3. Aug 5, 2025
@haiqi96 haiqi96 changed the title fix(package): Don't mount stream_output_dir when stream storage type is S3. fix(package): Only mount stream_output_dir when stream storage type is FS. Aug 5, 2025
@haiqi96 haiqi96 requested a review from junhaoliao August 5, 2025 19:49
junhaoliao
junhaoliao previously approved these changes Aug 6, 2025

@junhaoliao junhaoliao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm. adding @davemarco & @hoophalab for awareness

Comment thread components/webui/server/src/routes/static.ts Outdated
Co-authored-by: Junhao Liao <junhao@junhao.ca>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0a8aa49 and 30bcb15.

📒 Files selected for processing (1)
  • components/webui/server/src/routes/static.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}

⚙️ CodeRabbit Configuration File

  • Prefer false == <expression> rather than !<expression>.

Files:

  • components/webui/server/src/routes/static.ts
🧠 Learnings (2)
📓 Common learnings
Learnt from: haiqi96
PR: y-scope/clp#0
File: :0-0
Timestamp: 2025-07-29T14:04:13.769Z
Learning: User haiqi96 requested creating a GitHub issue to document a bug fix from PR #1136, which addressed MySQL compatibility issues with invalid SQL CAST operations in the WebUI component.
Learnt from: Bill-hbrhbr
PR: y-scope/clp#1122
File: components/core/src/clp/clp/CMakeLists.txt:175-195
Timestamp: 2025-07-23T09:54:45.185Z
Learning: In the CLP project, when reviewing CMakeLists.txt changes that introduce new compression library dependencies (BZip2, LibLZMA, LZ4, ZLIB), the team prefers to address conditional linking improvements in separate PRs rather than expanding the scope of focused migration PRs like the LibArchive task-based installation migration.
Learnt from: gibber9809
PR: y-scope/clp#504
File: components/core/src/clp_s/search/kql/CMakeLists.txt:29-29
Timestamp: 2024-10-22T15:36:04.655Z
Learning: When reviewing pull requests, focus on the changes within the PR and avoid commenting on issues outside the scope of the PR.
Learnt from: haiqi96
PR: y-scope/clp#673
File: components/log-viewer-webui/server/src/routes/query.js:9-10
Timestamp: 2025-01-17T22:33:23.547Z
Learning: When initializing S3Manager in log-viewer-webui, both StreamFilesS3Region and StreamFilesS3PathPrefix settings must be non-null for S3 functionality to work correctly.
Learnt from: davemarco
PR: y-scope/clp#1015
File: components/log-viewer-webui/server/src/routes/static.ts:65-70
Timestamp: 2025-06-16T13:05:27.349Z
Learning: In components/log-viewer-webui/server/src/routes/static.ts, when decorateReply is set to true in fastifyStatic configuration, the reply.sendFile() method automatically uses the root directory configured in the static plugin registration, eliminating the need to pass the root directory as a second parameter.
📚 Learning: in components/log-viewer-webui/server/src/routes/static.ts, when decoratereply is set to true in fas...
Learnt from: davemarco
PR: y-scope/clp#1015
File: components/log-viewer-webui/server/src/routes/static.ts:65-70
Timestamp: 2025-06-16T13:05:27.349Z
Learning: In components/log-viewer-webui/server/src/routes/static.ts, when decorateReply is set to true in fastifyStatic configuration, the reply.sendFile() method automatically uses the root directory configured in the static plugin registration, eliminating the need to pass the root directory as a second parameter.

Applied to files:

  • components/webui/server/src/routes/static.ts

Comment on lines +27 to +35
if (null !== streamFilesDir) {
if (false === path.isAbsolute(streamFilesDir)) {
streamFilesDir = path.resolve(rootDirname, streamFilesDir);
}
await fastify.register(fastifyStatic, {
prefix: "/streams",
root: streamFilesDir,
decorateReply: false,
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Harden the null-check: undefined will still slip through and crash

path.isAbsolute(undefined) throws a TypeError.
If StreamFilesDir is omitted from the JSON (→ undefined) the current condition passes (undefined !== null), and the server will crash on the very next line.

-// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
-if (null !== streamFilesDir) {
+// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
+if ("string" === typeof streamFilesDir && 0 < streamFilesDir.length) {

This guards against both null and undefined and ensures we only proceed when we have a non-empty string path.

📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (null !== streamFilesDir) {
if (false === path.isAbsolute(streamFilesDir)) {
streamFilesDir = path.resolve(rootDirname, streamFilesDir);
}
await fastify.register(fastifyStatic, {
prefix: "/streams",
root: streamFilesDir,
decorateReply: false,
});
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if ("string" === typeof streamFilesDir && 0 < streamFilesDir.length) {
if (false === path.isAbsolute(streamFilesDir)) {
streamFilesDir = path.resolve(rootDirname, streamFilesDir);
}
await fastify.register(fastifyStatic, {
prefix: "/streams",
root: streamFilesDir,
decorateReply: false,
});
🤖 Prompt for AI Agents
In components/webui/server/src/routes/static.ts around lines 27 to 35, the
null-check for streamFilesDir only excludes null but allows undefined, which
causes path.isAbsolute to throw a TypeError. Update the condition to check that
streamFilesDir is a non-empty string by verifying it is truthy and of type
string before calling path.isAbsolute and proceeding with registration.

@haiqi96 haiqi96 requested a review from junhaoliao August 6, 2025 15:07
@haiqi96 haiqi96 changed the title fix(package): Only mount stream_output_dir when stream storage type is FS. fix(package): Only mount stream_output_dir when stream storage type is FS. Aug 7, 2025
@haiqi96 haiqi96 merged commit 8b4f58a into y-scope:main Aug 7, 2025
8 checks passed
junhaoliao added a commit to junhaoliao/clp that referenced this pull request May 17, 2026
… is `FS`. (y-scope#1129)

Co-authored-by: Junhao Liao <junhao@junhao.ca>
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