Add RetryPolicy CRUD service and queue attachment validation - #5000
Add RetryPolicy CRUD service and queue attachment validation#5000dejanzele wants to merge 2 commits into
Conversation
Greptile SummaryThis PR implements the
Confidence Score: 5/5Safe to merge; the new service is well-structured, auth-gated, and has solid unit and integration test coverage. The implementation follows established patterns in the codebase, the migration is consistent with existing schema, auth checks are in place for all mutating operations, and read paths are intentionally unauthenticated in line with GetQueue. The two findings are minor efficiency/consistency nits that do not affect correctness or security. internal/server/retrypolicy/repository.go — nil vs empty slice on GetAllRetryPolicies and the full-fetch in RetryPolicyExists are worth a second look before broader rollout. Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant QueueServer
participant RetryPolicyServer
participant PostgresRetryPolicyRepo
participant PostgresQueueRepo
Note over Client,PostgresQueueRepo: CreateQueue / UpdateQueue flow
Client->>QueueServer: CreateQueue(req)
QueueServer->>QueueServer: authorize(CreateQueue)
QueueServer->>QueueServer: queue.NewQueue(req)
loop for each RetryPolicy name
QueueServer->>PostgresRetryPolicyRepo: RetryPolicyExists(name)
PostgresRetryPolicyRepo-->>QueueServer: (bool, err)
end
QueueServer->>PostgresQueueRepo: CreateQueue(queue)
PostgresQueueRepo-->>QueueServer: ok
QueueServer-->>Client: "Empty{}"
Note over Client,PostgresQueueRepo: DeleteRetryPolicy flow
Client->>RetryPolicyServer: DeleteRetryPolicy(req)
RetryPolicyServer->>RetryPolicyServer: authorize(DeleteRetryPolicy)
RetryPolicyServer->>PostgresQueueRepo: GetAllQueues()
PostgresQueueRepo-->>RetryPolicyServer: []Queue
RetryPolicyServer->>RetryPolicyServer: check referencing queues
alt queues still reference policy
RetryPolicyServer-->>Client: FailedPrecondition
else no references
RetryPolicyServer->>PostgresRetryPolicyRepo: DeleteRetryPolicy(name)
PostgresRetryPolicyRepo-->>RetryPolicyServer: ok
RetryPolicyServer-->>Client: "Empty{}"
end
Reviews (32): Last reviewed commit: "Add RetryPolicy CRUD service and queue a..." | Re-trigger Greptile |
f796a82 to
77bdd4d
Compare
37e060a to
3b1f6f2
Compare
b1b9ef3 to
85bf359
Compare
dc56181 to
93322e2
Compare
f5fefac to
7bfc8f3
Compare
8b63ef2 to
85bef9c
Compare
85bef9c to
9760ff7
Compare
Signed-off-by: Dejan Zele Pejchev <pejcev.dejan@gmail.com>
Signed-off-by: Dejan Zele Pejchev <pejcev.dejan@gmail.com>
9760ff7 to
e493f4d
Compare
Implements the `RetryPolicyService` whose proto was defined in #4998: create, get, list, update, and delete for retry policies, backed by a Postgres repository. Adds `create_retry_policy`, `update_retry_policy`, and `delete_retry_policy` permissions and maps them in the local development server configs. Creating a policy that already exists replaces it, the same as `create queue`, so a pipeline that creates policies can be re-run. Updating one that does not exist still returns `NotFound`. Queue attachments are stored relationally rather than inside the serialized queue definition. Migration 035 adds the `retry_policy` table together with a `queue_retry_policy` join table, where each row records the position its policy held in the submitted list so that a queue reads its policies back in the order they were given. The queue repository rewrites those rows on every queue write and composes `RetryPolicies` from them on every read, so the serialized definition never carries the names. A foreign key on `policy_name` is what prevents a queue referencing a policy that does not exist. A queue write also looks the names up first, so the error can say which ones are missing, returned as `InvalidArgument`. In the narrow case where a policy is deleted between that lookup and the write, the foreign key rejects the write with a less specific message. Deleting a policy removes its attachment rows and then the policy itself, returning the queues it detached for the service to log. The migration names that constraint explicitly because the repository matches on it. Both tables are queried through sqlc, generated into `internal/server/queryapi/database`, matching the pattern the scheduler already uses. The queue table's own statements are unchanged. Independent of #5047 and #5048, any merge order works. Two notes on the seams: the `RetryPolicies` field on the client queue type also appears in #5048 as an identical hunk, since both PRs need it to compile on their own, and it merges cleanly from either direction. The retry policy service tests define their own gRPC status helper, which can switch to the shared one from #5047 once both are in. Replaces #5000, which carried all of this plus the client and armadactl work in one PR. Signed-off-by: Dejan Zele Pejchev <pejcev.dejan@gmail.com>
Implements the
RetryPolicyServicewhose proto was defined in #4998: create, get, update, and delete for retry policies, backed by a Postgres repository and a lookout schema migration for theretry_policytable. Referential integrity is enforced in both directions. Deleting a policy is rejected while any queue still references it, and creating or updating a queue is rejected if it references a policy that does not exist. Addscreate_retry_policy,update_retry_policy, anddelete_retry_policypermissions.Stacked on #5047, which moves a shared gRPC test helper into
servertest. Its commit shows in this diff until it merges. The client package and armadactl commands are split into #5048.