Improve JpaRolloutHandler logging (#1801)

Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2024-08-02 16:17:01 +03:00
committed by GitHub
parent 0afd7e8036
commit 3002b50807
2 changed files with 37 additions and 4 deletions

View File

@@ -64,12 +64,12 @@ public class JpaRolloutHandler implements RolloutHandler {
@Override
public void handleAll() {
final List<Long> rollouts = rolloutManagement.findActiveRollouts();
if (rollouts.isEmpty()) {
return;
}
final String handlerId = createRolloutLockKey(tenantAware.getCurrentTenant());
final String tenant = tenantAware.getCurrentTenant();
final String handlerId = createRolloutLockKey(tenant);
final Lock lock = lockRegistry.obtain(handlerId);
if (!lock.tryLock()) {
if (log.isTraceEnabled()) {
@@ -79,13 +79,16 @@ public class JpaRolloutHandler implements RolloutHandler {
}
try {
log.trace("Trigger handling {} rollouts.", rollouts.size());
log.debug("[{}] Trigger handling {} rollouts.", tenant, rollouts.size());
rollouts.forEach(rolloutId -> {
try {
log.debug("[{}] Handling rollout {}", tenant, rolloutId);
handleRolloutInNewTransaction(rolloutId, handlerId);
log.debug("[{}] Rollout {} processed", tenant, rolloutId);
} catch (final Throwable throwable) {
log.error("Failed to process rollout with id {}", rolloutId , throwable);
log.error("[{}] Failed to process rollout with id {}", tenant, rolloutId , throwable);
}});
log.debug("[{}] Finished handling of the rollouts.", tenant);
} finally {
if (log.isTraceEnabled()) {
log.trace("Unlock lock {}", lock);

View File

@@ -382,6 +382,36 @@ class RolloutManagementFlowTest extends AbstractJpaIntegrationTest {
assertGroup(dynamic2, true, RolloutGroupStatus.RUNNING, 4); // assign the target created when paused
}
@Test
@Description("Verifies a simple rollout flow")
void rollout0ThresholdFlow() {
final String rolloutName = "rollout-std-0threshold";
final int amountGroups = 5; // static only
final String targetPrefix = "controller-rollout-std-0threshold-";
final DistributionSet distributionSet = testdataFactory.createDistributionSet("dsFor" + rolloutName);
testdataFactory.createTargets(targetPrefix, 0, amountGroups * 3);
final Rollout rollout = testdataFactory.createRolloutByVariables(rolloutName, rolloutName, amountGroups,
"controllerid==" + targetPrefix + "*", distributionSet, "0", "25", false, false);
final List<RolloutGroup> groups = rolloutGroupManagement.findByRollout(
new OffsetBasedPageRequest(0, amountGroups + 10, Sort.by(Direction.ASC, "id")),
rollout.getId()).getContent();
// start rollout
rolloutManagement.start(rollout.getId());
// handleStartingRollout (no handleRunning called yet)
rolloutHandler.handleAll();
assertRollout(rollout, false, RolloutStatus.RUNNING, amountGroups, amountGroups * 3);
for (int step = 1; step <= amountGroups; step++) {
for (int i = 0; i < amountGroups; i++) {
assertGroup(groups.get(i), false, i < step ? RolloutGroupStatus.RUNNING : RolloutGroupStatus.SCHEDULED, 3);
}
// starting the next group
rolloutHandler.handleAll();
}
}
private void executeStaticWithoutOneTargetFromTheLastGroupAndHandleAll(
final List<RolloutGroup> groups,
final Rollout rollout, final int amountGroups) {