Skip to content

refactor(api,executor): drive retries with Spring's RetryTemplate - #4057

Open
Macbet wants to merge 5 commits into
refactor/redis-boot-autoconfigfrom
refactor/spring-core-retry
Open

Macbet wants to merge 5 commits into
refactor/redis-boot-autoconfigfrom
refactor/spring-core-retry

Conversation

@Macbet

@Macbet Macbet commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

What changed and why?

Part 3 of #4052. Stacked on the Redis pull request.

Six hand-written retry loops slept and counted attempts on their own: the storage backends in both modules, the TerrakubeClient proxy, job context patches, version pinning and the final plan / apply snapshot. They now use RetryTemplate from spring-core, with no new dependency.

Attempt counts, delays, which failures are retried, the exceptions callers see and the Micrometer metrics are unchanged. That includes the InterruptedException cause when a backoff is interrupted, which the AWS and Azure state backends rely on to tell "storage unavailable" from "not found".

@Retryable does not fit here: TerrakubeClient comes from an external jar, and most loops retry on a returned value rather than an exception. StructuredOutputPersistenceQueue keeps its own loop, because it carries on after an interrupt and RetryTemplate always stops on one.

Testing

Ran: mvn -pl executor test -> 915 tests, 0 failures, 1 skipped (skipped before too). mvn -pl api test for the storage tests -> 180 tests, 0 failures. Full api suite before the last interrupt-path fix -> 3577 tests, 0 failures.
Checked: new tests pin the delay sequences (200/500 ms for storage, 1 s/2 s for the client proxy) and the interrupt paths, including "404 then interrupt during backoff" on AWS. That scenario has no Azure test.

@Macbet
Macbet added this pull request to stack #4056 November 29, 2026 00:11
@github-actions github-actions Bot added terrakube-api terrakube-executor author/contributor Authored by a returning contributor size/L 250-999 lines changed type/refactor Refactor, performance or style change labels Nov 29, 2026
@Macbet
Macbet force-pushed the refactor/spring-core-retry branch 2 times, most recently from 08d467d to f27410a Compare November 29, 2026 01:17
@github-actions github-actions Bot added documentation Improvements or additions to documentation size/XL 1000 or more lines changed, consider splitting and removed size/L 250-999 lines changed labels Nov 29, 2026
@Macbet
Macbet force-pushed the refactor/spring-core-retry branch from f27410a to f1e7c5e Compare November 29, 2026 01:37
@Macbet
Macbet force-pushed the refactor/spring-core-retry branch 2 times, most recently from 32bb3de to dd5e077 Compare November 29, 2026 10:05
@Macbet
Macbet force-pushed the refactor/spring-core-retry branch from dd5e077 to 44138d4 Compare November 29, 2026 10:32
@Macbet
Macbet force-pushed the refactor/spring-core-retry branch from 44138d4 to 56a7e09 Compare November 29, 2026 12:58
@alfespa17 alfespa17 self-assigned this Nov 29, 2026
@Macbet
Macbet force-pushed the refactor/spring-core-retry branch from 56a7e09 to d15f476 Compare November 29, 2026 19:29
Six hand-written retry loops (storage backends in both modules, the
TerrakubeClient proxy, job context patches, version pinning and the
final plan/apply snapshot) slept and counted attempts on their own. They
now use RetryTemplate from spring-core, with no new dependency.

Attempt counts, delays, which failures are retried, the exceptions
callers see (including an InterruptedException cause when a backoff is
interrupted) and the Micrometer metrics are unchanged; new tests pin the
delay sequences and the interrupt paths.

@retryable does not fit here: TerrakubeClient comes from an external jar
and most loops retry on a returned value rather than an exception.
StructuredOutputPersistenceQueue keeps its own loop, because it carries
on after an interrupt and RetryTemplate always stops on one.

Refs #4052
…pply

Plan and apply each carried the same retry setup for the final snapshot
patch. It now lives in FinalSnapshotPatcher, with the same three
attempts and 200 ms / 400 ms delays.

Also do the retry-count arithmetic in long and use unnamed patterns for
unused catch parameters, as SonarCloud flagged.

Refs #4052
StorageRetryMetrics existed twice, differing only in metric prefix and
exception type. The logic now lives in common as StorageRetrySupport;
both modules keep their StorageRetryMetrics class, metric names and
exception types.

Refs #4052
StorageRetrySupport is abstract, and its javadoc no longer suggests the
executor's http backend uses it.

Refs #4052
Drops the RetryableCall interface whose throws Exception Sonar flagged (java:S112);
java.util.concurrent.Callable has the same shape.
@Macbet
Macbet force-pushed the refactor/spring-core-retry branch from d15f476 to dea1751 Compare November 29, 2026 19:34
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author/contributor Authored by a returning contributor documentation Improvements or additions to documentation size/XL 1000 or more lines changed, consider splitting terrakube-api terrakube-executor type/refactor Refactor, performance or style change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants