RED-5223: Added tracing for scheduled analysis, and add fileId on upload to trace #266

Merged
dominique.eiflaender1 merged 1 commits from RED-5223 into master 2023-12-14 14:04:40 +01:00
3 changed files with 43 additions and 22 deletions

View File

@ -27,6 +27,7 @@ import com.iqser.red.storage.commons.service.StorageService;
import com.knecon.fforesight.keycloakcommons.security.KeycloakSecurity;
import com.knecon.fforesight.tenantcommons.TenantContext;
import io.micrometer.observation.ObservationRegistry;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@ -41,6 +42,7 @@ public class UploadService {
private final AuditPersistenceService auditPersistenceService;
private final FileAttributesManagementService fileAttributesManagementService;
private final StorageService storageService;
private final ObservationRegistry observationRegistry;
@PreAuthorize("hasAuthority('" + WRITE_FILE_ATTRIBUTES + "')")
@ -67,6 +69,8 @@ public class UploadService {
dossierManagementService.getDossierById(dossierId, false, false);
var fileId = generateFileId(fileName, dossierId);
addFileIdToTrace(fileId);
var storageId = StorageIdUtils.getStorageId(dossierId, fileId, FileType.UNTOUCHED);
try {
@ -88,7 +92,6 @@ public class UploadService {
.build());
return FileUploadResult.builder().fileIds(Collections.singletonList(fileId)).build();
}
@ -97,4 +100,11 @@ public class UploadService {
return hashFunction.hashBytes((fileName + dossierId).getBytes(StandardCharsets.UTF_8)).toString();
}
private void addFileIdToTrace(String fileId){
if(observationRegistry.getCurrentObservation() != null){
observationRegistry.getCurrentObservation().highCardinalityKeyValue("fileId", fileId);
}
}
}

View File

@ -17,8 +17,9 @@ import com.iqser.red.service.persistence.management.v1.processor.utils.TenantUti
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.dossier.file.FileModel;
import com.knecon.fforesight.tenantcommons.TenantContext;
import com.knecon.fforesight.tenantcommons.TenantProvider;
import com.knecon.fforesight.tenantcommons.model.UpdateDetailsRequest;
import io.micrometer.observation.Observation;
import io.micrometer.observation.ObservationRegistry;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
@ -32,6 +33,7 @@ public class AutomaticAnalysisJob implements Job {
private final FileManagementServiceSettings fileManagementServiceSettings;
private final FileStatusService fileStatusService;
private final TenantProvider tenantProvider;
private final ObservationRegistry observationRegistry;
@Setter
private boolean schedulingStopped;
@ -79,13 +81,7 @@ public class AutomaticAnalysisJob implements Job {
var next = allStatusesIterator.next();
// in case the file doesn't have numberOfPages set, we assume an average.
if (next.isFullAnalysisRequired()) {
log.info("[Tenant:{}] Queued file: {} for automatic full analysis! ", TenantContext.getTenantId(), next.getFilename());
fileStatusService.setStatusFullReprocess(next.getDossierId(), next.getId(), false, false);
} else if (next.isReanalysisRequired()) {
log.info("[Tenant:{}] Queued file: {} for automatic reanalysis! ", TenantContext.getTenantId(), next.getFilename());
fileStatusService.setStatusReprocess(next.getDossierId(), next.getId(), false);
}
reanalyseFile(next);
queuedFiles++;
}
@ -99,17 +95,41 @@ public class AutomaticAnalysisJob implements Job {
}
private void reanalyseFile(FileModel file) {
Observation.createNotStarted("AutomaticAnalysisJob", observationRegistry)
.contextualName("scheduled-analysis")
.highCardinalityKeyValue("dossierTemplateId", file.getDossierTemplateId())
.highCardinalityKeyValue("dossierId", file.getDossierId())
.highCardinalityKeyValue("fileId", file.getId())
.lowCardinalityKeyValue("tenantId", TenantContext.getTenantId())
.observe(() -> {
if (file.isFullAnalysisRequired()) {
log.info("[Tenant:{}] Queued file: {} for automatic full analysis! ", TenantContext.getTenantId(), file.getFilename());
fileStatusService.setStatusFullReprocess(file.getDossierId(), file.getId(), false, false);
} else if (file.isReanalysisRequired()) {
log.info("[Tenant:{}] Queued file: {} for automatic reanalysis! ", TenantContext.getTenantId(), file.getFilename());
fileStatusService.setStatusReprocess(file.getDossierId(), file.getId(), false);
}
});
}
private List<FileModel> getAllRelevantStatuses() {
return fileStatusService.getAllRelevantStatusesForReanalysisScheduler();
}
public void stopForTenant(String tenantId){
public void stopForTenant(String tenantId) {
stoppedTenants.add(tenantId);
}
public void startForTenant(String tenantId){
public void startForTenant(String tenantId) {
stoppedTenants.remove(tenantId);
}

View File

@ -132,13 +132,7 @@ public class Application implements ApplicationContextAware {
@Override
public KeyValues getLowCardinalityKeyValues(ServerRequestObservationContext context) {
// Make sure that KeyValues entries are already sorted by name for better performance
return super.getLowCardinalityKeyValues(context)
.and(getValueFromPathVariableOrRequestParam(context, "dossierId"),
getValueFromPathVariableOrRequestParam(context, "dossierTemplateId"),
getValueFromPathVariableOrRequestParam(context, "fileId"),
KeyValue.of("kubernetes.namespace", namespace),
KeyValue.of("service.version", version),
tenantId(context));
return super.getLowCardinalityKeyValues(context).and(KeyValue.of("kubernetes.namespace", namespace), KeyValue.of("service.version", version), tenantId(context));
}
@ -148,10 +142,7 @@ public class Application implements ApplicationContextAware {
return super.getHighCardinalityKeyValues(context)
.and(getValueFromPathVariableOrRequestParam(context, "dossierId"),
getValueFromPathVariableOrRequestParam(context, "dossierTemplateId"),
getValueFromPathVariableOrRequestParam(context, "fileId"),
KeyValue.of("kubernetes.namespace", namespace),
KeyValue.of("service.version", version),
tenantId(context));
getValueFromPathVariableOrRequestParam(context, "fileId"));
}