Add nd analyze to trigger an assurance analysis on demand - #5
Open
noppanut15 wants to merge 1 commit into
Open
Conversation
Nexus Dashboard collects online fabrics every 2-4 hours, so a pipeline that pins `snapshots latest` before a change and compares against `latest` after can resolve both selectors to the same record and see no delta at all. `nd analyze` posts to /api/v1/analyze/jobs/assuranceAnalysis, waits for the job, and prints the ID of the snapshot it produced, so a push can be bracketed by two real snapshots. The wait is two-phase because no snapshot is visible until the job is terminal: the job is polled first (by ID only -- jobType varies between ONLINE-ANALYSIS, -ACI and -NX), then the snapshot list. A failed job reports the API's own errorMessage rather than timing out silently. Matching a job to its snapshot needs both an analysisJobId match and a collectionTimestamp newer than the pre-trigger baseline. analysisJobId is not unique -- the recurring scheduled analysis keeps one ID across cycles -- so the newest match wins, and a snapshot that already existed can never be reported as this run's result. Triggering requires the super-admin, fabric-admin or support-engineer role; an observer account is refused with HTTP 403, which surfaces as an AuthError naming the roles. --no-wait prints the job ID instead, and its help says plainly that this is not a snapshot ID. Verified against a live ND 4.2.1 cluster: the returned jobId reappears verbatim as the snapshot's analysisJobId, and the status path is SCHEDULED -> RUNNING -> COMPLETE.
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.
Add
nd analyze: trigger an assurance analysis on demandWhy
Nexus Dashboard collects online fabrics on its own schedule, depending on fabric size. A pipeline that pins
snapshots latestbefore a change and compares againstlatestafterwards races that schedule: if no collection happened in between, both selectors resolve to the same record anddeltareports nothing.This repo has been read-only with respect to snapshots —
snapshotsresolveslatest/latest-N/ an explicit ID out of what already exists, and nothing asks ND to collect one.What
nac-analytics nd analyzeposts toPOST /api/v1/analyze/jobs/assuranceAnalysis, waits for the resulting snapshot and prints its ID, so a configuration push can be bracketed by two real snapshots. Here is an example use case:--no-waitprints the analysis job ID instead and skips all polling; its help text says plainly that this is not a snapshot ID and cannot be passed todelta.-o json|yamlemits the whole snapshot record, including theanalysisJobIdthat ties it back to the trigger.Unlike
snapshots, this command takes real--timeout/--poll-intervalvalues (ND_JOB_TIMEOUT_MINUTES/ND_POLL_INTERVAL), since collection time scales with fabric size. No new configuration settings: the request body carries only the fabric name, which already flows through--fabric/ND_FABRIC.Changes
products/nexus_dashboard/client.pytrigger_assurance_analysis(),wait_for_analysis_snapshot(),latest_collection_timestamp(); pure helpersanalysis_job_id(),snapshot_for_job(),snapshot_newer_than();ANALYSIS_SUCCEEDED/ANALYSIS_FAILEDproducts/nexus_dashboard/cli.pyanalyzecommand;_emit_notices()(also now used bysnapshots) and_analysis_trigger_error()tests/unit/test_analyze.pydocs/commands/nexus-dashboard/analyze.md; verb tables incommands/README.md,commands/nexus-dashboard/README.md,nexus-dashboard.md; cross-reference fromsnapshots.mdNo new exit codes: trigger failure → 1 (
ApiError) or 5 (AuthError), timeout / missing job ID / failed job → 2 (JobError), bad input → 4.Testing
ruff check,ruff format --check,mypy(24 source files) andpytest(218 passed) all clean.The 23 new tests cover the trigger body and job-ID parsing, ID matching (including the shared-job-ID and stale-baseline cases), every job status branch, the absence window for a job
/jobs/summarynever reports, the timeout, the unmatched-snapshot warning, and four end-to-end CLI runs — text output, JSON output,--no-waitissuing no polling at all, and a 403 naming the roles.Verified against a live ND 4.2.1 cluster before implementation: the returned
jobIdreappears verbatim as the snapshot'sanalysisJobId, and the status path isSCHEDULED → RUNNING → COMPLETE.