Repository navigation
feat(nautobotop): per-item sync resilience for vlan groups and vlans - #2558
geetikabatra wants to merge 1 commit into
Conversation
603c94b to
7068001
Compare
| if err == nil { | ||
| continue | ||
| } | ||
| var de *syncerr.DataError |
There was a problem hiding this comment.
SyncItems can only isolate errors that have already been wrapped as DataError, but I only see HTTP response classification in VlanGroupService.Create and Update. The other migrated services still return raw SDK errors, so a 400 from clusters, devices, locations, tenants, etc. reaches the infrastructure-error path below and stops reconciliation. Could we classify create/update responses for every migrated resource, ideally through a shared client helper, and add at least one test at a real service boundary rather than injecting NewDataError directly?
There was a problem hiding this comment.
Good catch, I agree. I am adding a shared helper method in the client package so every mitigated service's Create/update maps 4XX(excluding 403,401/429) to DataError, while 5XX and transport errors stay infra I am also adding boundary tests using an httptest server returning 400 against real services(devices, clustersm tenants) to verify that one bad item doesn't halt reconcillation.
| return err | ||
| } | ||
|
|
||
| prune(ctx, syncedIDs) |
There was a problem hiding this comment.
I think pruning from only syncedIDs makes a partial failure destructive. If an existing, operator-owned prefix gets a data error during update, its ID is not added to this map, and deleteObsoletePrefixes will treat that desired prefix as obsolete and destroy it. Could we preserve IDs for all resolved desired prefixes, or skip pruning when any item fails? It would also be good for the partial-failure test to verify that the failed desired prefix is retained.
| // given Nautobot CR. A count of zero clears the gauge entry so recovered | ||
| // resource types no longer show (and any alert on them resolves). | ||
| func setSyncItemFailuresGauge(crName, resource string, count int) { | ||
| syncItemFailuresGauge.WithLabelValues(crName, resource).Set(float64(count)) |
There was a problem hiding this comment.
How will this label set be removed when the Nautobot CR is deleted? Reconcile currently returns immediately on IgnoreNotFound, so a CR deleted while this gauge is nonzero will leave a stale series and the alert can continue firing for an object that no longer exists. I think the deletion/NotFound path should remove the CR labels, for example with DeletePartialMatch. Also, Set(0) resolves the alert but does not actually clear the gauge entry as the comment says.
There was a problem hiding this comment.
Yep, correct. I am adding deleteIteFailure when CR is absent.
| setSyncItemFailuresGauge(nautobotCR.Name, res.name, len(partial.Failures)) | ||
| totalItemFailures += len(partial.Failures) | ||
| // Do not advance SyncHash: retry this resource next reconcile. | ||
| continue |
There was a problem hiding this comment.
The controller has an explicit dependency graph, but this continue still lets transitive dependents run after a prerequisite only partially synced. For example, if a new vlanGroup is rejected, vlan runs next and buildVlanGroupReference silently returns an empty reference, so we can create or update a VLAN without its requested group. The same risk applies to the other dependency edges. Could we continue independent branches but skip resources whose dependency had a partial failure, and add a controller test for that behavior?
cardoe
left a comment
There was a problem hiding this comment.
Stepping back, I think the test changes need a refactor before this is ready. This PR adds 2,118 lines of tests, but most of the per-resource apply* tests repeat the same three cases against injected callbacks: one data error continues, one infrastructure error aborts, and all items succeed. That repetition makes the PR much harder to review without giving us confidence at the production boundary—the current tests all manufacture DataError directly, which is why they did not catch that only VLAN groups classify real SDK responses.
I would concentrate the generic continuation/abort coverage in SyncItems, then keep focused coverage for the genuinely different paths: one real HTTP/service-boundary test for classification, one flat resource integration path, one recursive tree path, the prefix pruning special case, and controller tests for dependency skipping, hashes, status, and metrics. If every resource still needs a smoke test, a shared/table-driven harness would make that intent much clearer than 17 copies of the same tests.
The earlier threads about missing production classification, destructive prefix pruning, and stale metric labels are still unresolved on this commit. I have also added an inline comment about not running transitive dependents after a prerequisite partially fails. Given those correctness issues, I do not think the current size is justified yet.
e98f224 to
ad3bd39
Compare
- Add syncerr to sort Nautobot errors into data errors (4xx) and infrastructure errors - Add SyncItems helper that skips items with data errors and stops on infrastructure errors - Classify vlan and vlanGroup service errors with syncerr.Classify at the service boundary - Use per-item handling in the vlan and vlanGroup syncs - Continue across resource types after a partial failure and advance SyncHash only on clean syncs - Skip resource types whose dependency partially failed, including transitive dependents - Clear SyncHash of failed and skipped types so the next reconcile retries them - Save status, report and SyncItemFailures on partial and aborted runs - Return non-NotFound Get errors from Reconcile instead of reconciling an empty CR - Add the nautobotop_sync_item_failures gauge, published from Status.SyncItemFailures - Clear counts for recovered and unconfigured resources and keep the last count for skipped or aborted ones - Remove a CR's gauge series when it is deleted or disabled - Add a PrometheusRule that alerts on item failures that persist - Expose operator metrics in the Helm chart with a metrics Service, ServiceMonitor and token-check RBAC - Add SyncItemFailures to the CRD status and regenerate deepcopy - Add an httptest-based service classification test helper with vlan and vlanGroup cases - Add controller tests for dependency skipping, hashes, status message and gauge lifecycle - Drop apply tests that repeat SyncItems coverage - Fix configmap_watch and dag tests and lint issues - Add the sync resilience design doc with follow-up task map and a dev testing guide
0c261a0 to
6932d64
Compare
The operator previously stopped at the first item Nautobot rejected within a resource type, and stopped at the first resource type that failed in the reconcile loop. A single bad VLAN group (e.g. a 400 because a range cannot be shrunk while VLANs exist in it) would skip every other VLAN group, every later resource type, and leave no lasting record in status.
This change makes the sync carry on past per-item data errors, surface them in status and metrics, and retry them on the next reconcile pass.
What changed
Error classification (#1)
Sort each error from the Nautobot client into one of two kinds:
New package: internal/nautobot/syncerr
Item-loop helper (#2)
Add syncItems (and exported SyncItems for sub-packages) in internal/nautobot/sync/helpers.go. Loops over items, isolates data errors, stops on infra errors, returns collected failures + any stopping error.
Per-item isolation in every sync plugin (#3, 8a–8n) Port all 17 SyncAll methods to the syncItems helper. Each plugin now wraps its loop in an apply* orchestrator method (e.g. applyClusters, applyVlans) that is independently unit-testable:
cluster, clusterGroup, clusterType, device, devicetype,
namespace, prefix, rack, rir, role, tenant, tenantGroup,
vlan, vlanGroup, admin/permissionGroup
Special cases:
deleteObsolete* still runs after a partial failure so that items which did apply are still authoritative for the prune.
Continue reconcile across resource types on partial failure (#4) The reconcile loop in internal/controller/nautobot_controller.go no longer returns on the first resource type that fails. A type that returned a PartialSyncError is noted and the loop continues to the next type. Infrastructure errors still return immediately so backoff still works. A type's SyncHash is only advanced when the type finishes cleanly, so types with failures are retried on the next reconcile pass.
Status and metrics (#5)
Docs
Expanded go/nautobotop/docs/vlan-group-sync-resilience.md task map with individual checkbox tasks for each plugin (§8a–8n flat, §9a–9c recursive).
Tests
Every ported plugin has three unit tests exercising the apply* method directly (no live Nautobot required):
What does this change do?
Upgrade impact
upgrade-impactlabel and a release note: runscriv createfrom therepository root and describe the required action in the generated
changelog.d/file. See RELEASING.md.Operator action means anything a deployment has to do beyond a normal resync:
deploy repo or values changes, new or removed secrets, enabling or disabling a
component, or a manual one-time step.