Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RHCLOUD-35454 | feature: enhance logging for the Kessel assets migration #3166

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 batch of %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 batch of % 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", finalOffset, fetchedEndpoints.getFirst().getId(), fetchedEndpoints.getLast().getId());
}

@Override
public void onCompleted() {
Log.infof("[offset: %s][first_integration: %s][last_integration: %s] Sent % integrations to Kessel", finalOffset, fetchedEndpoints.getFirst().getId(), fetchedEndpoints.getLast().getId(), fetchedEndpoints.size());
Log.trace("Calling onCompleted");
Log.infof("[offset: %s][first_integration: %s][last_integration: %s] Sent batch of % 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
Loading