-
Notifications
You must be signed in to change notification settings - Fork 48
fix error removing policy from policy engine if no policies for existing deployment. #1060
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
WalkthroughRefactors policy removal on API update to derive a dedicated policy ID, call RemovePolicy(policyID), and classify missing policies via a new storage sentinel error; updates logging to include api_id, policy_id, and correlation_id; adds tests and a mock policy manager. Changes
Sequence Diagram(s)sequenceDiagram
participant PlatformAPI as Platform API
participant ControlPlane as Gateway ControlPlane
participant PolicyMgr as Policy Manager
participant Storage as Storage
PlatformAPI->>ControlPlane: Deploy API (update)
ControlPlane->>ControlPlane: derive policyID = storedConfig.ID + "-policies"
ControlPlane->>PolicyMgr: RemovePolicy(policyID)
alt Remove returns ErrPolicyNotFound
PolicyMgr->>ControlPlane: error (policy not found)
ControlPlane->>ControlPlane: log debug (api_id, policy_id, correlation_id)
else Remove returns other error
PolicyMgr->>ControlPlane: error (storage error)
ControlPlane->>ControlPlane: log error (api_id, policy_id, correlation_id)
else Remove succeeds
PolicyMgr->>ControlPlane: success
ControlPlane->>ControlPlane: log success (api_id, policy_id, correlation_id)
end
ControlPlane->>Storage: update stored policy snapshot (if applicable)
Storage->>ControlPlane: ack
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 🧹 Recent nitpick comments
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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Fixes noisy errors during API redeployments when the initial deployment had no attached policies, by avoiding (or reducing) attempts to remove non-existent derived policy configurations from the policy engine (issue #1041).
Changes:
- Adds
correlation_id(andpolicy_id) to policy-engine-related logs for better traceability. - On update events with no derived policies, checks for policy existence before attempting removal and logs successful removals.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
gateway/gateway-controller/pkg/api/handlers/handlers.go (1)
803-812:⚠️ Potential issue | 🟡 MinorInconsistent error handling:
UpdateAPIswallows allRemovePolicyerrors at debug level.In
CreateAPI(Lines 282-290), you now differentiateErrPolicyNotFound(debug) from other errors (error level). However,UpdateAPIstill logs allRemovePolicyerrors at debug level, silently swallowing real storage/snapshot failures. The same applies toUpdateLLMProvider(Line 1377),UpdateLLMProxy(Line 1628), andUpdateMCPProxy(Line 2001).Apply the same differentiated handling from
CreateAPIto these update paths.♻️ Suggested fix for UpdateAPI (apply similar pattern to other update methods)
} else { // API no longer has policies, remove the existing policy configuration policyID := existing.ID + "-policies" if err := s.policyManager.RemovePolicy(policyID); err != nil { - // Log at debug level since policy may not exist if API never had policies - log.Debug("No policy configuration to remove", slog.String("policy_id", policyID)) + if errors.Is(err, storage.ErrPolicyNotFound) { + log.Debug("No policy configuration to remove", slog.String("policy_id", policyID)) + } else { + log.Error("Failed to remove policy configuration", + slog.Any("error", err), + slog.String("policy_id", policyID)) + } } else {
🧹 Nitpick comments (1)
gateway/gateway-controller/pkg/storage/errors.go (1)
28-29: Consider adding anIsPolicyNotFoundErrorhelper for consistency.Other sentinel errors in this file (
ErrNotFound,ErrConflict,ErrDatabaseUnavailable,ErrOperationNotAllowed) all have correspondingIs*Error()helper functions.ErrPolicyNotFoundlacks one, while callers useerrors.Is()directly. This is a minor inconsistency.♻️ Suggested addition
+// IsPolicyNotFoundError checks if an error is a policy not found error +func IsPolicyNotFoundError(err error) bool { + return errors.Is(err, ErrPolicyNotFound) +}
Fixing #1041
Summary by CodeRabbit
Bug Fixes
Chores
Tests