Make the Nexus Dashboard HTTP request timeout configurable - #22
Open
noppanut15 wants to merge 1 commit into
Open
noppanut15 wants to merge 1 commit into
noppanut15 wants to merge 1 commit into
Conversation
The ND client's httpx timeout was hard-coded to 60 seconds in _build_config, so a cluster that answered slowly failed every command with httpx.ReadTimeout and the operator had no way to raise the ceiling. Expose it the same three ways as poll_interval: --request-timeout, ND_REQUEST_TIMEOUT_SECONDS, and request_timeout_seconds under the nexus_dashboard YAML section, defaulting to 60 seconds. It is typed as an int like the other timing settings, so it shares their env coercion. Every ND command gets the flag, including doctor and snapshots, since both reach the fabric inventory before doing anything else. A non-positive value is rejected as InputError (exit 4) rather than handed to httpx, which reads 0 as "fail immediately".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The ND client's httpx timeout was hard-coded to 60 seconds, with no flag, environment
variable, or YAML key able to reach it. This exposes it as
request_timeout_secondsunder the
nexus_dashboard:section — reachable the same three ways aspoll_interval— keeping 60 seconds as the default.
Why
GET /api/v1/manage/fabricsnormally answers in well under a second. On a cluster whereat least one site is down, it still returns HTTP 200 but takes roughly 64 seconds
to do so.
Every ND command reaches that endpoint before doing anything useful
(
validate_fabric→aci_fabric_names→list_fabrics), so on such a cluster the rundied with
httpx.ReadTimeoutseconds before the response landed.nd prechangewaswhere this bit us in practice — an upload that should have kicked off an analysis
instead failed at the inventory lookup.
What changed
--request-timeoutND_REQUEST_TIMEOUT_SECONDSnexus_dashboard:)request_timeout_seconds60secondsconfig.py—DEFAULT_REQUEST_TIMEOUT_SECONDS = 60as the single source of truthfor both the dataclass field and the CLI option default.
__post_init__rejects anon-positive value alongside the existing
poll_interval_secondsandjob_timeout_minutesguards.commands/_helpers.py— new sharedRequestTimeoutOpt, and_build_configtakesrequest_timeoutinstead of hard-coding60.0.doctorandsnapshotscarry no other timing flagstoday, but both hit the fabric inventory, so both get this one.
settings.py— the key joinsKNOWN_KEYS/ENV_MAPand the existing integercoercion set, so a YAML value reaches the environment the same way
poll_intervaldoes.
ND_HELP,docs/nexus-dashboard.md,docs/configuration.md,both
config.example.yamlcopies, bothenv.examplecopies, and the CHANGELOG. Thealigned columns were re-padded because
ND_REQUEST_TIMEOUT_SECONDSis wider than anyprevious variable name, which is most of the diff noise in those files.
Usage
Precedence is unchanged: CLI flag → environment variable → YAML → default.
Validation
--request-timeout 0exits 4 (InputError) with--request-timeout must be greater than 0 seconds.rather than reaching httpx, because:timeout=0makes httpx fail the connection instantly — it means "give the request zerotime," not "no timeout," so every command would fail instantly.
timeout=-1raisesValueErrorinside the httpx constructor, which would surface as araw traceback and exit 1.
Testing
241 passed— ruff, ruff format, and mypy clean. New coverage:tests/unit/test_config.py— non-positive values rejected; the default is 60.tests/unit/test_settings.py— a YAML value reachesND_REQUEST_TIMEOUT_SECONDS, andthe key is recognised (no "Ignoring unknown config key" warning).
tests/unit/test_cli_commands.py— parametrised over flag / env var / default /flag-beats-env, asserting the value that lands on
Config; a separate test asserts theconfigured value reaches
httpx.Client.timeout, and one asserts the exit-4 path.The
use_labfixture injects its ownhttpx.Client, so it cannot observe the timeout —those assertions are made on
Configand on a directly constructedNDClientinstead.Verified manually with ND 4.3.