Skip to content

fix(clp-rust-utils): Make api_server and log_ingestor config values optional (fixes #1911).#1927

Merged
hoophalab merged 7 commits into
y-scope:mainfrom
hoophalab:null-fix
Jan 28, 2026
Merged

fix(clp-rust-utils): Make api_server and log_ingestor config values optional (fixes #1911).#1927
hoophalab merged 7 commits into
y-scope:mainfrom
hoophalab:null-fix

Conversation

@hoophalab

@hoophalab hoophalab commented Jan 28, 2026

Copy link
Copy Markdown
Contributor

Description

  • Make api_server and log_ingestor fields optional in Config struct to allow null values.
  • Update all usages in api-server and log-ingestor to handle Option with explicit panics when config is missing.

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. Set log_ingestor: null in clp-config.yaml. The package starts correctly after the fix.
  2. Successfully ingested logs using log ingestor and submited queries using the api server

Summary by CodeRabbit

  • Bug Fixes

    • Improved configuration error messaging, added a new error for missing API config, and added explicit fail-fast checks when required server/ingestor sections are absent.
  • Refactor

    • Made server and ingestor configuration fields optional and adjusted default initializations to reflect potentially absent components.
  • Documentation

    • Clarified panic/failure conditions and documented the new missing-configuration behavior.

✏️ Tip: You can customize this high-level summary in your review settings.

@hoophalab hoophalab requested a review from a team as a code owner January 28, 2026 06:39
@coderabbitai

coderabbitai Bot commented Jan 28, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

api_server and log_ingestor config fields changed to Option<T>. Call sites now either assert presence with as_ref().expect(...) or return ClientError::ConfigIsNone. API server and client use guarded api_server_config for host/port and defaults; log ingestor init now expects log_ingestor.

Changes

Cohort / File(s) Summary
Config struct update
components/clp-rust-utils/src/clp_config/package/config.rs
Config.api_server and Config.log_ingestor changed from concrete types to Option<...>; Default now initializes them to None.
API server binary
components/api-server/src/bin/api_server.rs
Reworded config load error; adds api_server_config = config.api_server.as_ref().expect(...) and uses api_server_config.host / api_server_config.port for address binding.
API server client
components/api-server/src/client.rs
Adds private get_api_server_config() (panics if missing); connect returns ClientError::ConfigIsNone when config missing; submit_query and fetch_results derive defaults/backoffs from guarded config.
Client error variants
components/api-server/src/error.rs
Adds ClientError::ConfigIsNone variant with message "api_server configuration is missing".
Log ingestor initialization
components/log-ingestor/src/ingestion_job_manager.rs
from_config now panics if log_ingestor is missing via as_ref().expect(...); introduces log_ingestor_config binding and uses it for buffer/time/channel settings.
Manifest
Cargo.toml
Minor manifest changes referenced in diff.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Title check ✅ Passed The pull request title clearly and concisely describes the main change: making api_server and log_ingestor config fields optional, with a reference to the issue it fixes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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

Comment @coderabbitai help to get the list of available commands and usage tips.

@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

🤖 Fix all issues with AI agents
In `@components/api-server/src/client.rs`:
- Around line 137-142: In submit_query, extract the api_server config to a local
variable like you do in fetch_results instead of using the long chained call;
e.g., create a local api_server_config =
self.config.api_server.as_ref().expect("api_server configuration is missing")
and then set search_job_config.max_num_results =
api_server_config.default_max_num_query_results so the access pattern matches
fetch_results and improves readability and consistency across the codebase.

Comment thread components/api-server/src/client.rs Outdated
Comment thread components/api-server/src/bin/api_server.rs Outdated
Comment thread components/api-server/src/client.rs Outdated
hoophalab and others added 2 commits January 28, 2026 11:32
Co-authored-by: Lin Zhihao <59785146+LinZhihao-723@users.noreply.github.com>

@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: 2

🤖 Fix all issues with AI agents
In `@components/api-server/src/client.rs`:
- Around line 109-115: Validate the API server configuration before creating any
database clients: call get_api_server_config() (or otherwise check that
config.api_server is Some) at the start of the constructor/initializer that
builds Self, and return an error (or propagate Result) if missing, instead of
constructing mongodb_client and sql_pool first; move the validation out of the
post-construction call and perform it before allocating mongo_client/sql_pool so
resources aren't wasted when api_server is None.
- Around line 460-473: The method get_api_server_config is incorrectly marked
const fn despite taking &self (not usable in const contexts); remove the const
qualifier so the signature becomes a normal fn, keeping the same receiver
(&self), return type (&clp_rust_utils::clp_config::package::config::ApiServer)
and the same body (using self.config.as_ref().expect(...)) so callers and
behavior are unchanged.

Comment thread components/api-server/src/client.rs Outdated
Comment on lines +460 to +473

/// Returns a reference to the API server configuration.
///
/// # Panics
///
/// Panics if `self.config.api_server` is `None`.
const fn get_api_server_config(
&self,
) -> &clp_rust_utils::clp_config::package::config::ApiServer {
self.config
.api_server
.as_ref()
.expect("api_server configuration is missing")
}

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 | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Find rust-toolchain or MSRV settings
echo "=== Looking for Rust version specification ==="
fd -t f "rust-toolchain" . --max-depth 3 2>/dev/null | head -5
echo "---"
fd -t f "Cargo.toml" . --max-depth 2 2>/dev/null | xargs grep -l "rust-version\|msrv" 2>/dev/null || echo "No MSRV found"
echo "---"
# Check the root Cargo.toml
cat Cargo.toml 2>/dev/null | grep -A 2 -B 2 "rust-version\|msrv" || echo "No rust-version in root Cargo.toml"

Repository: y-scope/clp

Length of output: 158


🏁 Script executed:

#!/bin/bash
# Check CI workflows for Rust version
echo "=== Checking CI workflows for Rust version ==="
fd -t f "\.yml\|\.yaml" .github/workflows/ 2>/dev/null | head -5 | xargs grep -h "toolchain\|rust" 2>/dev/null | grep -i "1\.[0-9]\+" | head -10 || echo "No Rust version found in CI"

Repository: y-scope/clp

Length of output: 101


🏁 Script executed:

#!/bin/bash
# Check if const fn with &self is actually valid in the codebase
echo "=== Checking other const fn methods with &self ==="
rg -n "const fn.*&self" components/api-server/src/ || echo "No other const fn with &self found"

Repository: y-scope/clp

Length of output: 140


🌐 Web query:

When was Option::expect stabilized as const fn in Rust

💡 Result:

Option::expect was const-stabilized in Rust 1.83.0 (released November 28, 2024). It is marked #[rustc_const_stable(... since = "1.83.0")] in core::option::Option. [1], [2]


Remove the unnecessary const fn marker.

This method takes &self and cannot practically be used in const contexts. While Option::expect is now const-evaluable (Rust 1.83.0+), marking an &self method as const fn is misleading since such methods cannot be evaluated at compile time in normal usage. The const fn provides no practical benefit here.

♻️ Suggested simplification
-    const fn get_api_server_config(
+    fn get_api_server_config(
         &self,
     ) -> &clp_rust_utils::clp_config::package::config::ApiServer {
         self.config
             .api_server
             .as_ref()
             .expect("api_server configuration is missing")
     }
📝 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
/// Returns a reference to the API server configuration.
///
/// # Panics
///
/// Panics if `self.config.api_server` is `None`.
const fn get_api_server_config(
&self,
) -> &clp_rust_utils::clp_config::package::config::ApiServer {
self.config
.api_server
.as_ref()
.expect("api_server configuration is missing")
}
/// Returns a reference to the API server configuration.
///
/// # Panics
///
/// Panics if `self.config.api_server` is `None`.
fn get_api_server_config(
&self,
) -> &clp_rust_utils::clp_config::package::config::ApiServer {
self.config
.api_server
.as_ref()
.expect("api_server configuration is missing")
}
🤖 Prompt for AI Agents
In `@components/api-server/src/client.rs` around lines 460 - 473, The method
get_api_server_config is incorrectly marked const fn despite taking &self (not
usable in const contexts); remove the const qualifier so the signature becomes a
normal fn, keeping the same receiver (&self), return type
(&clp_rust_utils::clp_config::package::config::ApiServer) and the same body
(using self.config.as_ref().expect(...)) so callers and behavior are unchanged.

Comment thread components/api-server/src/client.rs Outdated
sql_pool,
})
};
client.get_api_server_config();

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.

I agree with the rabbit. I think we should make the check explicit and return as an error maybe?

Comment thread components/api-server/src/client.rs Outdated
Comment on lines +130 to +133
///
/// # Panics
///
/// Panics if `self.config.api_server` is `None`.

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.

I don't think we need to document the implicit panics because it can easily get convoluted...
Let's drop them all except for get_api_server_config.

@LinZhihao-723 LinZhihao-723 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.

One more nit fix and we should be good to go.

Comment thread components/api-server/src/client.rs Outdated
Co-authored-by: Lin Zhihao <59785146+LinZhihao-723@users.noreply.github.com>

@LinZhihao-723 LinZhihao-723 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.

For the PR title, how about:

fix(clp-rust-utils): Make `api_server` and `log_ingestor` config values optional (fixes #1911).

It looks like the value is optional, not the field, lol

@hoophalab hoophalab changed the title fix(clp-rust-utils): Make api_server and log_ingestor config fields optional (fixes #1911). fix(clp-rust-utils): Make api_server and log_ingestor config values optional (fixes #1911). Jan 28, 2026
@hoophalab hoophalab merged commit 5583221 into y-scope:main Jan 28, 2026
24 checks passed
@junhaoliao junhaoliao added this to the January 2026 milestone Jan 30, 2026
junhaoliao pushed a commit to junhaoliao/clp that referenced this pull request May 17, 2026
…es optional (fixes y-scope#1911). (y-scope#1927)

Co-authored-by: Lin Zhihao <59785146+LinZhihao-723@users.noreply.github.com>
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