(1/7) Give acquired slots an optional expiry

What does this MR do?

Adds WithAcquisitionTTL(ttl), a new AcquireOption. Acquire(ctx, key, opts...) stamps the slot with ExpiresAt = now + ttl. The expiry is persisted with the slot and never changed by suspend or resume. Slots acquired without a TTL never expire.

Nothing reads the expiry yet. The following MRs in the stack expire, free and clean up slots past it.

Why was this MR needed?

GitLab Runner stamps a suspended environment's expiry when it is created, and every resume and cleanup compares against that stamp (review discussion). For docker-autoscaler and instance environments, the slot is what taskscaler tracks, so the expiry has to live on the slot and survive a manager restart.

This was one large MR. It is now split into a stack of seven; this is part 1.

What's the best way to test this MR?

go test -race ./.... TestAssignSlotSetsExpiresAt, the "keeps the expiry" cases in TestSuspendSlot/TestResumeSlot, TestAcquireRejectsNegativeTTL and TestAcquireStampsExpiryFromClock.

What are the relevant issue numbers?

Used by gitlab-org/gitlab-runner!7646 (merged) and its follow-ups.

MR stack

Merge in order:

  1. (1/7) Give acquired slots an optional expiry (!117 - merged) • Ashvin Sharma (this MR)
  2. (2/7) Let an instance mark a suspended slot exp... (!119 - merged) • Ashvin Sharma
  3. (3/7) Expire suspended slots past their expiry (!120 - merged) • Ashvin Sharma
  4. (4/7) Expose connect info for an expired slot's... (!121 - merged) • Ashvin Sharma
  5. (5/7) Free expired slots once their workload is... (!122 - merged) • Ashvin Sharma
  6. (6/7) Remove stopped instances whose slots have... (!123 - merged) • Ashvin Sharma
  7. (7/7) Refuse to resume a suspended slot past it... (!118 - merged) • Ashvin Sharma
Edited by Ashvin Sharma

Merge request reports

Loading
Loading