Skip to content

Commit

Permalink
feature: enhance logging for the Kessel assets migration
Browse files Browse the repository at this point in the history
Having traces will allow us to know what is exactly happening when we
run the migrations.

RHCLOUD-35454
  • Loading branch information
MikelAlejoBR committed Dec 4, 2024
1 parent 2d15c81 commit d8b512e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ public UUID getDefaultWorkspaceId(final String orgId) {
throw new UnauthorizedException();
}

Log.debugf("[org_id: %s][workspace_id: %s] Fetched default workspace from RBAC", orgId, rbacWorkspace.id());

return rbacWorkspace.id();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,46 +59,64 @@ public class KesselAssetsMigrationService {
@Path("/kessel/migrate-assets")
@POST
public void migrateAssets() {
Log.info("Kessel assets' migration begins");

int fetchedEndpointsSize = 0;
int offset = 0;
int traceLoops = 0;
do {
Log.tracef("[loops: %s] Loops", traceLoops);

final List<Endpoint> fetchedEndpoints = this.endpointRepository.getNonSystemEndpointsWithLimitAndOffset(this.backendConfig.getKesselMigrationBatchSize(), offset);
Log.debugf("[offset: %s][first_integration: %s][last_integration: %s] Fetched %s integrations", offset, (fetchedEndpoints.isEmpty()) ? "none" : fetchedEndpoints.getFirst().getId(), (fetchedEndpoints.isEmpty()) ? "none" : fetchedEndpoints.getLast().getId(), fetchedEndpoints.size());

// If for some reason we have fetched full pages from the database
// all the time, the last one might be empty, so there is no need
// to attempt calling Kessel.
if (fetchedEndpoints.isEmpty()) {
Log.trace("Breaking the do-while loop because the size of the fetched integrations is zero");
break;
}

final CreateTuplesRequest request = this.createTuplesRequest(fetchedEndpoints);
Log.tracef("Generated a \"CreateTuplesRequest\": %s", request);

final int finalOffset = offset;
this.relationTuplesClient.createTuples(request, new StreamObserver<>() {
@Override
public void onNext(final CreateTuplesResponse createTuplesResponse) {
Log.trace("Calling onNext");
Log.infof("[offset: %s][first_integration: %s][last_integration: %s] Sent % integrations to Kessel", finalOffset, fetchedEndpoints.getFirst().getId(), fetchedEndpoints.getLast().getId(), fetchedEndpoints.size());
}

@Override
public void onError(final Throwable throwable) {
Log.errorf(throwable, "[offset: %s][first_integration: %s][last_integration: %s] Unable to send batch of tuples to Kessel with offset %s", finalOffset, fetchedEndpoints.getFirst().getId(), fetchedEndpoints.getLast().getId());
Log.trace("Calling onError");
Log.errorf(throwable, "[offset: %s][first_integration: %s][last_integration: %s] Unable to send batch of tuples to Kessel with offset", finalOffset, fetchedEndpoints.getFirst().getId(), fetchedEndpoints.getLast().getId());
}

@Override
public void onCompleted() {
Log.trace("Calling onCompleted");
Log.infof("[offset: %s][first_integration: %s][last_integration: %s] Sent % integrations to Kessel", finalOffset, fetchedEndpoints.getFirst().getId(), fetchedEndpoints.getLast().getId(), fetchedEndpoints.size());
}
});

fetchedEndpointsSize = fetchedEndpoints.size();
offset += fetchedEndpoints.size();
traceLoops += 1;

Log.tracef("[fetchedEndpointsSize: %s][kesselMigrationBatchSize: %s][offset: %s] do-while loop condition", fetchedEndpointsSize, offset, this.backendConfig.getKesselMigrationBatchSize());
} while (fetchedEndpointsSize == this.backendConfig.getKesselMigrationBatchSize());

Log.infof("Finished migrating integrations to the Kessel inventory");
Log.info("Finished migrating integrations to the Kessel inventory");
}

@Path("/kessel/migrate-assets/async")
@POST
public void migrateAssetsAsync() {
Log.info("Kessel assets' migration begins");

final int limit = this.backendConfig.getKesselMigrationBatchSize();

final AtomicInteger offsetContainer = new AtomicInteger(0);
Expand Down
1 change: 1 addition & 0 deletions backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ quarkus.unleash.active=false
quarkus.unleash.url=http://localhost:4242

# Kessel
quarkus.log.category."com.redhat.cloud.notifications.routers.internal.kessel.KesselAssetsMigrationService".min-level=TRACE
quarkus.log.category."com.redhat.cloud.notifications.auth.kessel".min-level=TRACE

inventory-api.authn.client.id=insights-notifications
Expand Down

0 comments on commit d8b512e

Please sign in to comment.