Repository navigation
fix(server): config precedence, boolean switches, and docs for what exists - #1944
Conversation
08cee5c to
43be82a
Compare
5eb2cb7 to
ebb0ef8
Compare
b33a9d0 to
fa53edf
Compare
e7ffbd8 to
b51f9af
Compare
b51f9af to
b958f29
Compare
b958f29 to
29d8c4a
Compare
29d8c4a to
cba69a1
Compare
cba69a1 to
55bf523
Compare
5929335 to
28ab9a1
Compare
1265f26 to
fe054bf
Compare
a7610b1 to
d41223a
Compare
d41223a to
3f56048
Compare
Many operations, API and troubleshooting docs showed server flags that do not exist (--port, --storage, --data-dir, S3/DynamoDB flags, --tls-*, --require-auth, rate limiting, CORS allow-lists, size limits per request kind) and ran the server as a bare binary. Every example now uses `fluree server run`, passing flags it does not take itself after `--`, and maps each invented flag to the real one (--listen-addr, --storage-path, --connection-config, --body-limit, --cache-max-mb, the --*-auth-mode flags) or says plainly that the capability belongs in a reverse proxy. Also documented: `fluree server run` overrides FLUREE_STORAGE_PATH, the boolean switches can only be turned off by env var or config file, the oidc feature needs a custom CLI build, and Raft runs only in the standalone fluree-server binary.
…ig files `fluree server run` passed a default `--storage-path` whenever none was given, so the flag beat `FLUREE_STORAGE_PATH` and any profile's `storage_path`. It now leaves the storage path to the server's precedence (flag, env var, profile, config file) and fills in the project's `.fluree/storage` only when none of those set one. An explicit config file (`fluree server run --config <file>`, `fluree-server --config-file <file>`) was never loaded: the path check tested `is_dir()` twice instead of `is_file()`, logged a warning and carried on with defaults. It is loaded now, and a named config file that doesn't exist is an error, as the configuration docs already said.
…parse IPFS storage is reachable only through `FlureeBuilder::build_ipfs`, which keeps the nameservice in memory, so ledgers do not survive a restart. The docs presented it as a server storage mode configured through a connection config (`ipfsApiUrl`, `ipfsPinOnPut`, env var indirection), none of which is parsed. Worse, such a config silently became memory storage. The IPFS guide, storage modes page and connection config reference now describe what exists, and a storage node with `ipfsApiUrl` is rejected with an error pointing to the Rust API. Connection config examples whose Connection node had no `@id` failed with "No Connection node found" (the config graph indexes nodes by `@id`); the storage encryption examples and the Rust encryption example now carry one, and the `addressIdentifiers` fragment is a complete config. Every connection config example in the docs was run through `FlureeBuilder::from_json_ld`.
Both default to on, and as plain clap switches they could only be turned on: `--cors-enabled=false` was rejected, so switching them off took an env var or the config file. They now take an optional value (`--cors-enabled=false`, `=0`, `=off`); the bare flag still means true. The value parser is clap's boolish one, so existing `FLUREE_*=0` style env settings keep working.
3f56048 to
741fd78
Compare
aaj3f
left a comment
There was a problem hiding this comment.
@bplatz 👍 🚀 -- I do think there's maybe 2 things from your "Found, not changed here" list that I, personally, would still advocate do get changed/done here, and I've included those below, but otherwise full agreement & looks good. Entire review below for your consideration:
The resolve_config_path find is the kind of thing that hides forever: is_dir() twice where the first should have been is_file(), so --config <file> was ignored outright and --config <dir> resolved to a path that couldn't load. That's been broken since the v4 baseline and nothing surfaced it. The storage-path fix is the right shape too — taking the CLI out of the precedence ladder rather than teaching it to imitate the server's, so there's one resolver instead of two that can disagree.
I verified the substance rather than reading it: all four new tests pass in a clean worktree, and I mutation-checked them — reverting is_file() back to is_dir() turns both explicit_config_file_is_loaded_or_fails and the CLI's storage_path_precedence red, so they're non-vacuous. I also traced the ValueSource gating in apply_to_server_config (config_file.rs:508) to satisfy myself that the documented flag > env > profile > file > default order is the implemented one, checked that default_storage_path() and the server's config-file discovery read the same [server].storage_path from the same .fluree/ walk so the handoff loses nothing, and swept every consumer of the two boolean flags — including build_child_args — for a space-separated form that require_equals would now break. There isn't one.
Two things I'd like folded in, both from your own "Found, not changed here" list, and both stronger than they look because of how this PR works:
fluree-db-server/src/config.rs:498—--helpstill says--cache-max-mbis 50% of RAM at ≥8GB; the code is 35% (fluree-db-connection/src/cache.rs:35) and the docs you're shipping say 35% in five places. You validated the docs against--help, so this merges as the one artifact that disagrees with the corrected docs. It's a50%→35%edit in a file you're already in.docs/api/headers.md—X-Fluree-Fuel-Limit,X-Fluree-TimeoutandX-Response-Timeare still documented, and I confirmed zero.rshits for all three. It's the file the finding lives in and you're editing it; the same treatment you gave TLS and rate limiting would drop right in.
Beyond those: the doc comment above the new IPFS_API_URL const (fluree-db-connection/src/config.rs:485) picked up parse_storage_node's /// line, so the const is documented and the function isn't — one-line move. And two notes rather than asks: FLUREE_STORAGE_PATH beginning to take effect deserves an upgrade note, since a stale one in someone's environment now silently moves their storage directory; and the boolean change is a bigger win than the body says — I probed it, and the old definition rejected FLUREE_CORS_ENABLED=0 / =off / =no with a hard startup error rather than honoring them, so you've fixed that too.
The silent-memory-storage bug is the sharpest thing in here and the body undersells it — a user who configured ipfsApiUrl got a server that looked healthy and lost everything on restart. Nice catch.
Adherence to repo commitments
- Patterns / abstractions — ✔ with one ⚪: extends
ServerConfig's existing clap surface and the establishedis_default/ValueSourcemerge rather than adding a parallel path; the CLI correctly stops duplicating the server's resolver. The bareIPFS_API_URLconst sidesteps thevocab::FIELD_*convention two lines below it. - Performance (speed first, memory second) — ✔ No performance-degradation risk. Everything touched runs at process start (clap parse, config-file read, connection-config parse) or in the CLI. No query, transaction, or index path; no allocation, clone, lock, or
.collect()added to any loop. The one new probe (node.get(IPFS_API_URL)) runs once per storage node at connection build. - Testing — ✔ four new tests, all wired into crate targets that run, all passing, and mutation-checked non-vacuous.
storage_path_precedencecovers the full ladder against a real config file, which is the right level for this fix. - Conventions — ✔ self-describing subjects with substantive multi-line bodies; fmt and clippy clean per CI on
741fd78be(16 checks, all non-skipped green); docs updated in step with the behavior, including the boolean forms the final commit enables.
Approving so you can merge when ready — but I'd really like the two --help / headers.md items in before it lands, since they're the two places this PR's own premise doesn't quite close. Happy to talk through any of these.
| } | ||
|
|
||
| /// Parse storage config from a resolved JSON-LD node | ||
| /// Recognized only to reject it: see [`parse_storage_node`]. |
There was a problem hiding this comment.
🔵 LOW-1 — the new const absorbed parse_storage_node's doc comment
I think the insertion landed one line too high here — /// Parse storage config from a resolved JSON-LD node was parse_storage_node's doc comment, and now it documents IPFS_API_URL instead, so the const has a two-line doc that reads as a contradiction and the function has none:
/// Parse storage config from a resolved JSON-LD node
/// Recognized only to reject it: see [`parse_storage_node`].
const IPFS_API_URL: &str = "https://ns.flur.ee/system#ipfsApiUrl";
fn parse_storage_node(graph: &ConfigGraph, node: &JsonValue) -> Result<StorageConfig> {Both are private so nothing catches it, but it's a one-move fix:
/// Recognized only to reject it: see [`parse_storage_node`].
const IPFS_API_URL: &str = "https://ns.flur.ee/system#ipfsApiUrl";
/// Parse storage config from a resolved JSON-LD node
fn parse_storage_node(graph: &ConfigGraph, node: &JsonValue) -> Result<StorageConfig> {(Shown as a block rather than a suggestion because it spans several lines and the anchor is single-line — applying it as a one-click suggestion would duplicate the surrounding code.)
|
|
||
| /// Parse storage config from a resolved JSON-LD node | ||
| /// Recognized only to reject it: see [`parse_storage_node`]. | ||
| const IPFS_API_URL: &str = "https://ns.flur.ee/system#ipfsApiUrl"; |
There was a problem hiding this comment.
⚪ NIT-2 — IPFS_API_URL sits outside the vocab::FIELD_* convention
More of a question than a suggestion: every other field IRI in this file comes through the vocab module — the very next line of parse_storage_node reads resolve_string(graph, node, vocab::FIELD_ADDRESS_IDENTIFIER). I wonder if this one wants to be vocab::FIELD_IPFS_API_URL too, so there's one place to look when the system vocab moves. It genuinely may not be worth it given the constant exists only to be rejected — happy to be told that's the point.
| }); | ||
| } | ||
|
|
||
| // IPFS storage is not built from connection configs (only the Rust API's |
There was a problem hiding this comment.
⚪ NIT-3 — a node with ipfsApiUrl and a real backend silently ignores the IPFS key
The check sits after the S3/file/DynamoDB branches and just before the memory fallback, which is exactly right for the bug you're fixing (IPFS → silent memory). It does mean a node carrying both s3Bucket and ipfsApiUrl parses as S3 and drops the IPFS key without a word. That's a strictly better outcome than today and I don't think it's worth restructuring for — noting it only so the placement is a decision rather than an accident.
There was a problem hiding this comment.
Deliberate. Rejecting every node that carries ipfsApiUrl would turn a working S3, file or DynamoDB config with a leftover key into a startup failure on upgrade. The bug this fixes, IPFS silently becoming memory storage, only happens when no real backend is configured, which is where the check sits.
| ```bash | ||
| ./fluree-db-server --cors-origin "*" | ||
| ``` | ||
| CORS is either on or off. It is on by default; disable it with `--cors-enabled=false`, |
There was a problem hiding this comment.
🔵 LOW-5 — headers.md keeps three headers the server doesn't implement
Same "found, not changed" bucket, and same argument: this is the file the finding is in, and you're editing it in this PR. I grepped the workspace for the three you named and confirmed it — X-Fluree-Fuel-Limit, X-Fluree-Timeout and X-Response-Time have zero hits in any .rs file, and X-Fluree-Timeout is also still in docs/troubleshooting/common-errors.md.
Given the PR is titled "docs for what exists", leaving three invented headers documented in the headers reference is the one place the thesis doesn't hold. The treatment you already applied to TLS, rate limiting and CORS allow-lists — say it doesn't exist, point at the reverse proxy where that fits — would drop straight in here. If the compression row needs more thought than a sentence, that half is a fair thing to separate; the three header names aren't.
| eprintln!("{} config file: {e}", "warning:".yellow().bold()); | ||
| } | ||
|
|
||
| // Nothing named a storage location: use the project's `.fluree/storage`. |
There was a problem hiding this comment.
⚪ INFO-6 — FLUREE_STORAGE_PATH starting to work is a behavior change worth a release note
Not asking for a code change — the new behavior is the documented one and the old one was the bug. But it seems worth calling out wherever release notes get written, because the failure mode is quiet: anyone who has FLUREE_STORAGE_PATH set in their environment today (left over, or set for the standalone fluree-server binary, or exported for a different tool) has been getting it ignored under fluree server run. After this, it wins, and the server comes up pointed at a different directory with no ledgers in it. Same for a profile's storage_path, which also could not take effect before.
The upgrade note more or less writes itself from your own precedence line: fluree server run now honors FLUREE_STORAGE_PATH and profile storage_path, which it previously overrode. If you have either set and did not expect it to apply, unset it before upgrading.
|
|
||
| /// Enable CORS (Cross-Origin Resource Sharing) | ||
| #[arg(long, env = "FLUREE_CORS_ENABLED", default_value_t = server_defaults::DEFAULT_CORS_ENABLED)] | ||
| /// Enable CORS (Cross-Origin Resource Sharing). On by default; |
There was a problem hiding this comment.
⚪ INFO-7 — the boolean fix is worth more than the body claims
Small correction for the description rather than the code. The body says "Clap's boolish parser keeps existing FLUREE_*=0-style env settings working" — I built a standalone clap 4.5.58 probe with the old and new arg definitions side by side, and the old definition didn't accept those at all. FLUREE_CORS_ENABLED=0, =off, =no, =1, and even =FALSE all came back ErrorKind::InvalidValue, i.e. the server refused to start. Only exactly true / false parsed.
So this isn't compatibility preservation, it's a second bug fixed: anyone who wrote FLUREE_INDEXING_ENABLED=0 in a compose file got a startup failure, and now gets what they meant. Worth saying out loud in the body, and arguably worth a line in the docs table at docs/operations/configuration.md:949 noting the accepted spellings.
`--help` said the cache budget defaults to 50% of RAM at 8GB and above; the code and docs use 35%. The IPFS field IRI moves into `vocab` beside the other storage fields, which also returns `parse_storage_node` its doc comment.
The headers reference described request and response headers the server never reads or sends: X-Fluree-Fuel-Limit, X-Fluree-Timeout, X-Fluree-Policy, X-Fluree-T, X-Fluree-Commit, X-Response-Time, an echoed X-Request-ID, ETag and Cache-Control on queries, and compression. It now lists the fluree-* request headers and x-fdb-* tracking headers the server does handle, and says which of the rest to get from a reverse proxy. The query timeout is `FLUREE_QUERY_TIMEOUT_MS`, not a header, and the boolean server switches list the spellings they accept.
Docs: server flags and capabilities that exist
Many operations, API and troubleshooting docs described server flags that don't exist and started the server as a bare binary. I checked every flag against
fluree server run --help, the server'sconfig.rs(including feature-gated flags) and the CLI source, and ran several of the changed commands against the built binaries.fluree server run. Server flags thatrundoesn't take itself go after--, e.g.fluree server run --storage-path /var/lib/fluree -- --cache-max-mb 4096.quickstart-server.mdanddocker.mdwere missing the--and would have failed.fluree-serverbinary is kept only where it's required (Raft) or where the doc is about building from source.--port→--listen-addr--storage file --data-dir→--storage-path--connection-config--body-limit--cache-size-mb→--cache-max-mb--require-auth→ the--*-auth-modeflags--log-format→LOG_FORMATX-RateLimitheaders, CORS allow-lists (CORS is on/off and allows any origin), response size limits.FLUREE_REINDEX_MIN_BYTESdefault;/healthand/statsresponse shapes;.fluree/);--cors-enabled,--indexing-enabled) can only be turned off by env var or config file;oidcfeature needs a custom CLI build;26 docs changed. The full list is in the first commit.
Fix: config precedence
The docs promise flag > env var > profile > config file > default. Two bugs broke that for the storage path and for explicit config files:
FLUREE_STORAGE_PATHand profilestorage_pathwere ignored underfluree server run. The CLI always passed a default--storage-path, which beat both. It now leaves the storage path to the server's own precedence and fills in.fluree/storageonly when nothing else set one.fluree server run --config <file>andfluree-server --config-file <file>were affected.resolve_config_pathtestedis_dir()twice where the first check should have beenis_file(), so it logged "not found" and carried on with defaults. This has been the case since the v4 baseline. The file is loaded now, and a named config file that doesn't exist is an error, which both entry points already treat as fatal (and which the docs already promised).Fix:
--cors-enabled/--indexing-enabledaccept=falseBoth default to on, and as plain clap switches they could only turn things on:
--cors-enabled=falsewas rejected. They now take an optional value (--cors-enabled=false,=0,=off), and the bare flag still means true. This also fixes the env vars: the old definition accepted exactlytrueorfalse, soFLUREE_INDEXING_ENABLED=0(or=off,=no) stopped the server from starting. Clap's boolish parser now accepts1/0,yes/no,on/offand the like, in any case.The other boolean flags default to off, so I left them unchanged.
Docs: IPFS is Rust-API-only; connection config examples that parse
FlureeBuilder::build_ipfs, which keeps the nameservice in memory: the blocks persist, but ledgers don't survive a restart.ipfsApiUrl,ipfsPinOnPut, env var indirection). None of that is parsed.ipfsApiUrlis rejected with an error that points to the Rust API.build_ipfs's rustdoc said to composeIpfsStoragewith a persistent nameservice viabuild_with. That can't work:IpfsStoragedoesn't implementStorage. The rustdoc now says so.@id, so a Connection node without one fails with "No Connection node found". That affected the storage encryption examples (file and S3) and the Rust encryption example; all now carry one. TheaddressIdentifiersfragment is now a complete config.FlureeBuilder::from_json_ld. All parse.Testing
fluree-db-cli:storage_path_precedencechecks flag > env > profile > config file > default throughbuild_server_config, against a real config file.fluree-db-server:explicit_config_file_is_loaded_or_fails;default_on_switches_take_an_explicit_value.fluree-db-connection:ipfs_storage_node_is_rejected_not_memory.cargo fmt --all --check;cargo clippy -p fluree-db-connection -p fluree-db-server -p fluree-db-api -p fluree-db-cli --all-features --all-targets -- -D warnings;fluree-db-clisuite (442 tests).fluree-db-connectionandfluree-db-server, their 242 lib tests, andmdbook build.Review follow-ups
--cache-max-mbhelp said 50% of RAM at ≥8GB; it now says 35%, matching the code and the docs.docs/api/headers.mddocumented headers the server never reads or sends. It now lists thefluree-*request headers andx-fdb-*tracking headers that exist, and says the server has none of these:X-Fluree-Fuel-Limit(it'sfluree-max-fuel),X-Fluree-Policy(fluree-policy),X-Response-Time(x-fdb-time, when tracked);X-Fluree-Timeout— the query timeout is server-wide,FLUREE_QUERY_TIMEOUT_MS, whichcommon-errors.mdnow uses too;X-Fluree-T,X-Fluree-Commit, an echoedX-Request-ID, andETag/Cache-Control/conditional requests on queries;vocabasFIELD_IPFS_API_URL, andparse_storage_nodegot its doc comment back.docs/operations/configuration.mdlists the spellingsFLUREE_CORS_ENABLED/FLUREE_INDEXING_ENABLEDand their flags accept.ipfsApiUrlstill parses as that backend: rejecting it would turn a working config with a leftover key into a startup failure.Upgrade note
fluree server runnow honorsFLUREE_STORAGE_PATHand a profile'sstorage_path; before, it overrode both with.fluree/storage. If either is set in your environment or profile and you did not expect it to apply, unset it before upgrading, or the server starts against that directory instead.